Working with 2 DynamicMapServiceLayers

599
2
Jump to solution
10-26-2012 07:07 AM
CraigMcDade
Occasional Contributor III
I have two dynamic layers I need to add to my map. Both draw, but one (a parcel layer) is drawing underneath the zoning layer. I'd like them to draw so that both are visible. The parcels layer is outline only symbology so that shouldn't be the dealbreaker.

Here is what I have, with my legend code mixed in. I haven't changed the legend code to add the parcels layer yet as I'm just focusing on seeing both layers at the same time.

    layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://gisprod2/ArcGIS/rest/services/Dynamic/Zoning/MapServer");     parcellayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://gisprod2/ArcGIS/rest/services/Dynamic/Parcels/MapServer");      //Add the Legend     legendLayers.push({layer:layer,title:''});     dojo.connect(map,'onLayersAddResult',function(results){           var legend = new esri.dijit.Legend({             map:map,             layerInfos:legendLayers           },"legendDiv");           legend.startup();         });     map.addLayers([parcellayer,layer]);            if (layer.loaded) {           buildLayerList(layer);         }         else {           dojo.connect(layer, "onLoad", buildLayerList);         }
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
There are several things you can try here:

- Switch the order the layers are listed in your map.addLayers() statement.
- Use map.addLayer separately for each layer, adding the zoning layer first then the parcel layer.
- Use map.reorderLayer() to change the layer order in the map after they have both been added.

All are valid methods, though the first is easiest and results in less code.  In any instance, I would encourage you to get familiar with the map control's layer properties by using a debugging tool like Firebug or Chrome dev tools.  You can put in a statement to log the map control object to the consol - console.log(map); - and use the console to inspect the maps layerIDs and other properties. Once you are familiar with how the map control deals with layers, it will be much easier for you to manipulate them to match what your users need in your application.

Cheers,

Jeff

View solution in original post

0 Kudos
2 Replies
by Anonymous User
Not applicable
There are several things you can try here:

- Switch the order the layers are listed in your map.addLayers() statement.
- Use map.addLayer separately for each layer, adding the zoning layer first then the parcel layer.
- Use map.reorderLayer() to change the layer order in the map after they have both been added.

All are valid methods, though the first is easiest and results in less code.  In any instance, I would encourage you to get familiar with the map control's layer properties by using a debugging tool like Firebug or Chrome dev tools.  You can put in a statement to log the map control object to the consol - console.log(map); - and use the console to inspect the maps layerIDs and other properties. Once you are familiar with how the map control deals with layers, it will be much easier for you to manipulate them to match what your users need in your application.

Cheers,

Jeff
0 Kudos
CraigMcDade
Occasional Contributor III
Jeff,

Thanks for your feedback. I wound up using map.addLayer() to add the layers seperately, however, it wouldn't work until I also added the layer within the code I have that builds a layer list. Now it works like I'd like. Thanks again.

Craig
0 Kudos