Getting layers list |
To get the layer list of WorldMap, you need to perform the GET request on the layers resource, the URI for which is http://localhost:8090/iserver/services/components-rest/rest/maps/WorldMap/layers.json.
Please refer to the layers page in the REST APIs section to learn the response structure for the layers resource. Here no parameters are needed for the GET request. The code is as below.
//Get the layer list of WorldMap
function layerslist()
{
var commit=getcommit();
var uri="http://localhost:8090/iserver/services/components-rest/rest/maps/WorldMap/layers.json";
commit.open("GET",encodeURI(uri),false,"","");
commit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
commit.send(null);
//Parse the json string returned from the server to a JavaScript object
var response = json_parse(commit.responseText, null);
//Get the Div container for display
var container = document.getElementById('container');
//Output the result
//The number of layer of WorldMap
var len=response.length;
container.innerHTML="There are "+len+" layers in WorldMap, they are: ";
for(var i=0;i<len;i++)
{
container.innerHTML += '<li>Layer: ' + response[i].name + ', Type: ' + response[i].type+'</li>';
}
}
There is one layer named WorldMap of the UGC type in WorldMap, therefore, the result returned would be as below.