0

I have a ArcGISDynamicMapServiceLayer containing many layers. I'd need to add only individual layers to the map, like layers 2,5 and 10.

The following code would add all the layers to the map:

url = "http://...MapServer";
mapServiceLayer = new ArcGISDynamicMapServiceLayer(url, {
     className: layer,
     opacity: opacity
});
map.addLayer(mapServiceLayer);

How can I add only i.e. layer 5 to the map? (.../MapServer/5)

There is a similar question here but answers seem not to be helpful for the front end solution.

2

See this sample:

http://developers.arcgis.com/javascript/sandbox/sandbox.html?sample=map_explicitlayerlist

To set which layers are visible before the layer loads that it uses ImageParameters:

//Use the ImageParameters to set the visibleLayerIds layers in the map service during ArcGISDynamicMapServiceLayer construction.
      var imageParameters = new ImageParameters();
      imageParameters.layerIds = [1,2];
      imageParameters.layerOption = ImageParameters.LAYER_OPTION_SHOW;
      //can also be: LAYER_OPTION_EXCLUDE, LAYER_OPTION_HIDE, LAYER_OPTION_INCLUDE

      layer = new ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer",
        {"imageParameters": imageParameters});
      map.addLayer(layer);

Once the layer is added to the map you can use setVisibleLayers() and pass in an array of layer indexes (i.e. [5]) to turn layers off/on.

  • Yes, that's exactly what I was looking for! Also, I'm wondering if excluded layers would appear in the Table of Contents widget: arcgis.com/home/item.html?id=9b6280a6bfb0430f8d1ebc969276b109 – Matej May 16 '14 at 20:16
  • Unfortunately, my TOC widget (link above) does not honor the imageParameters property and displays all the layers within ArcGISDynamicMapServiceLayer regardless of the imageParameters settings – Matej May 17 '14 at 22:19
1

This should accomplish what what you want to do.

Layer = new esri.layers.FeatureLayer("yoururl/MapServer/5",);

map.addLayer(Layer);
  • Thanks. That would create a FeatureLayer.. I would like to stick with dynamically generated tiles. – Matej May 16 '14 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.