Getting the parameters of a map |
Through the result of Getting Map List, we know that the URI of the WorldMap resource is http://localhost:8090/iserver/services/components-rest/rest/maps/WorldMap.json. We can perform a set of operations on WorldMap through REST API.
Through the introduction to the GET request on SuperMap iServer Help/REST APIs/map page, we can see the response of the WorldMap contains the name, viewbounds, viewer, scale, etc.
Note that viewBounds is in Rectangle2D and viewer is in Rectangle. For detailed information on the two types, please refer to com.supermap.services.components.commontypes. Please refer to Rectangle2D and Rectangle for the structures of Rectangle2D and Rectangle.
To perform the GET request on http://localhost:8090/iserver/services/components-rest/rest/maps/WorldMap.json and get the result by parsing the JSON string returned from the server, use the following code.
//Get the name, viewbounds, viewer, and scale of WorldMap
function GetMap()
{
var commit=getcommit();
var uri="http://localhost:8090/iserver/services/components-rest/rest/maps/WordMap.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
container.innerHTML="";
container.innerHTML += '<p>Map name: ' + response.name +'</p>';
container.innerHTML += '<p>Display bounds: <li>leftBottom: ' + toJSON(response.bounds.leftBottom) +'</li>'+'<li>rightTop: '+toJSON(response.bounds.rightTop)+'</p>';
container.innerHTML += '<p>Viewer bounds: <li>leftTop: ' + toJSON(response.viewer.leftTop) +'</li>'+'<li>rightBottom: '+toJSON(response.viewer.rightBottom)+'</p>';
container.innerHTML += '<p>Scale: 1: ' + Math.round(1/response.scale) +'</p>';
}
The result is as below.
Note: The unit of the map viewBounds is identical to map unit and here it is degrees. The viewer of the map is in pixles.