Getting the sublayers list of a layer

Feedback


The layer resource contains layers and sublayers.

By implementing the GET request (with no parameters) on the layer resource, we can get the representation of the layer. The response from the server includes the information of sublayers (please refer to layer). The SubLayers field indicates the sublayers included in the layer.

In the above section, we have got the layer list of World, with the World layer included in the list. To get the sublayers of the World layer, we can implement the GET request on the World layer resource with http://localhost:8090/iserver/services/components-rest/rest/maps/WorldMap/layers/World.json.

Sample code:

//Get the sublayer list of the World layer

function getSubLayers()

{

    var commit=getcommit();

    var uri="http://localhost:8090/iserver/services/map-china400/rest/maps/China/layers/China.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');

    container.innerHTML="";

    //Determine whether the layer has sublayers

    if(toJSON(response.subLayers)==="{}")

    {

        //If the subLayers field is {} in the response, the layer has no sublayers

        container.innerHTML +='<p>Layer '+response.name+' has no sublayers.</p>'

    }else

    {

        container.innerHTML +='<p>Layer '+response.name+' has sublayers: </p>'

        //The number of sublayers

        var len=response.subLayers.layers.length;

        for(var j=0;j<len;j++)

        {

            container.innerHTML += '<li>Layer name: '+response.subLayers.layers[j].name+"; Layer caption: "+response.subLayers.layers[j].caption+'</li>' ;

        }

    }

}

In SuperMap iServer, thematic maps exist as layers.

The naming rule for the sublayer is: [layers resource URI] +'/'+ [sublayer name] + '@@' + [parent layer name] + [URI suffix]. As a sublayer of WorldMap, the URI for Capitals@world is:

http://localhost:8090/iserver/services/map-china400/rest/maps/China/layers/China_Province_R@China400@@China.json

By implementing the GET request on the above URI, we can get the representation of the sublayer Capitals@World.