Failed to add an operational layer.

563
3
Jump to solution
01-24-2014 08:08 AM
ShaningYu
Frequent Contributor
I created a mayservice (containing only 1 layer) a couple of days ago, and I could add it as a operational layer by:
var operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer(serverURL, { "opacity": 0.5 } );
...
map.addLayers([basemap, operationalLayer, featureLayer]);
After I updated the mapservice to hold multiple layers.  Then I revised the code as
var operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer(serverURL + "/0", { "opacity": 0.5 } );
where the '/0' points to the layer to be added.  However, in this way, the operational layer is not added or displayed.  What's wrong I did here?  Thanks if you can point out.
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
To show some of the layers for a ArcGISDynamicMapServiceLayer, you have to use the setVisibleLayers method. Using the "/0" at the end of the URL is for FeatureLayers.

var operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer(serverURL, { "opacity": 0.5 } ); operationalLayer.setVisibleLayers([0]);

View solution in original post

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor
To show some of the layers for a ArcGISDynamicMapServiceLayer, you have to use the setVisibleLayers method. Using the "/0" at the end of the URL is for FeatureLayers.

var operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer(serverURL, { "opacity": 0.5 } ); operationalLayer.setVisibleLayers([0]);
0 Kudos
ShaningYu
Frequent Contributor
kenbuja:  Thanks for your response.  Your answer has been credited.  However, I also got another solution by loading the TOC component sourced from http://gmaps-utility-gis.googlecode.com/svn/tags/agsjs/2.04/examples/toc.html
0 Kudos
KenBuja
MVP Esteemed Contributor
The TOC is a remarkable tool and I salute NLui for developing it.

However, when using Dynamic Layers, you'll always have to set the visible layers somehow, either with setVisibleLayers or a tool like this. If you delve into the code for NLui's TOC or Matt Driscoll's Layer Legend Widget, you'll see that they use setVisibleLayers.
0 Kudos