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