API controls

Knowledge Hub API

Knowledge Hub API is used within Knowledge Hub labs. It enables manipulation of GIS data that is stored inside Knowledge Hub.

Getting started

The host must define an event listener function, which is then called when the Knowledge Hub 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 Knowledge Hub by sending commands with the provided method:

// data is in JSON format 
document.getElementById('WidgetId').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.


  • 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>