Home > Geopedia API

Geopedia API

Geopedia API is used within Geopedia Widget. It enables manipulation of GIS data that is stored inside Geopedia.

Getting started

The host must define an event listener function, which is then called when the Geopedia widget posts a message:

function gp_onMessage(event) { 
    // process event.data, which is in JSON format 
} 
window.onload = function() { 
    if (typeof window.addEventListener != 'undefined')
        { window.addEventListener('message', gp_onMessage, false); 
    } else if (typeof window.attachEvent != 'undefined')
        { window.attachEvent('onmessage', gp_onMessage); } 
}

The host can interact with the Geopedia widget by sending commands with the provided method:

// data is in JSON format 
document.getElementById('geopediaWidget').contentWindow.postMessage(data, "*");

Many of such postMessage commands will return some data, by calling gp_onMessage with the event.dataparameter representing the postMessage's response in JSON format. Some user initiated actions (like mouse click searching) can also call gp_onMessage. The event.data parameter has a "command" member, which clearly identifies which command initiated the response.

The host is responsible to build JSON commands and parse JSON responses.

To generate JSON string for postMessage from some Javascript object, use JSON.stringify(obj).To generate Javascript object from the JSON string from gp_onMessage 's event.data parameter, use JSON.parse(event.data).When manually creating JSON strings, do not forget to put the fields into the quotes. So {"command":"abc"} is valid, but {command:"abc"} is not!

URL parameters

Used for INITIAL_URL_PARAMETERS for the widget's IFrame URL, and when calling execute commands setUrlParameters or setLocation.

Parameters are underline (_) separated list of prefix letter with a following value. The prefix letters represent entities, for which the values are specified.

Prefixes:

  • T<theme ID>
  • L<table/layer ID>
  • F<table/layer ID>:<feature ID>
  • b<base table ID>
  • x<x coordinate number>
  • y<y coordinate number>
  • s<scale level>

Example:

T12_L321_F456:20_x9876.5432_y1234.5678_s10

causes the widget to show the theme 12, show the map with x, y and scale, will activate the table with ID=321, and highlight a feature with ID=20 from the table with ID=456

API references

Command

Executes a command defined by the "param" parameter
Controls a feature selection (highlight).
Requests a current map information, like position and scale.
Requests a URL that is used to retrieve a static image/document containing the current widget's content.
Requests a URL that can be used to share over the social networks or the email.
Requests a list of the tables/layers on the map (including the turned off layers)
Controls the map markers, which are symbols placed on some geographic position on the map
Sets or removes current layer filters.
Sets a current widget map position and scale.
Sets current widget settings
Toggles a visibility of elements, specified in the list of "toggleables".

Response

When an error happened. Can also be called as a response to the commands.
List of result features.
The user added a new marker by mouse click after the "execute" command with "addMarker" param.
The current position of the path follower marker.
The current status of the widget, when changed.