Abstraction for index numbers to select specific feature layers in a mapservice

689
3
08-26-2013 09:10 AM
BrianPangtay
Occasional Contributor
If an MXD is modified, the index number for a layer in a mapservice may change since it just a relative number derived from the order in which the layers were added to an MXD. When that happens, the developer needs to track down all relevant code that specifies that index number and correct the index number to new modified index number.

Is there a different method that does not use index numbers to specify the layer desired from a mapservice?
0 Kudos
3 Replies
ReneRubalcava
Frequent Contributor
This is currently listed as "under consideration" on the ideas site.
http://ideas.arcgis.com/ideaView?id=08730000000brPPAAY

If you need to make a lot of updates when map services change, you can try creating a dictionary of layers to indexes.

You'd basically do a request for the map service data
http://gisserver:6080/arcgis/rest/services/MyService/MapServer?f=json

Iterate over the results like so,

var indexLayers = {},
    layers = result.layers;
for (var i = 0, len = layers.length;, i < len, i++) {
  var layer = layers;
  indexLayers[layer.name] = layer.id;  
}
// now you can use indexLayers in your app to do the correct referencing
// when needed

layer.setVisibleLayers([indexLayers.Parcels, indexLayers['Building Footprints']]);
0 Kudos
BrianPangtay
Occasional Contributor
That is what I was looking for. Is there an example online with source code that implements that method?

Thanks for the info.
0 Kudos
TimCollyer
Occasional Contributor
I've have worked around this by having my server-side code supply the layer id to my client-side code.

In my situation I'm using java/spring on the server, so I have a "layer" object (a bean) which contains some properties such as the map service layer id and this object is configured via xml.

It's not perfect in that if the map service layer id does change I need to change the property in the xml configuration, but other than that it doesn't require any code changes.
0 Kudos