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

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 Answers 2


See this sample:


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;

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

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
    Commented May 16, 2014 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
    Commented May 17, 2014 at 22:19

This should accomplish what what you want to do.

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

  • Thanks. That would create a FeatureLayer.. I would like to stick with dynamically generated tiles.
    – Matej
    Commented May 16, 2014 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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