2

I am pretty new to ArcGIS Server and am building a map applications using the Javascript API. I can easily load the map layer below by adding it as a ArcGISDynamicMapServiceLayer

http://www.parkcounty.org/ArcGIS/rest/services/Roads_Map/MapServer/

As you can see there are many layers as part of the above url. What if I just want to load the roads layer as a ArcGISDynamicMapServiceLayer? I've tried replacing the above url with the road specific URL below and that does not seem to work

http://www.parkcounty.org/ArcGIS/rest/services/Roads_Map/MapServer//2

Is there something else I can do as the front end developer or is it up to those that are hosting and managing the server to create a unique url for the roads?

0

Make use of the layers property when asking for the exportmap operation from a dynamic map service.

REST API Help on Exportmap operation.

e.g.
This service was published with 3 visible layers. However, can make a request for certain layers.

  • show: Only the layers specified in this list will be exported.
  • hide: All layers except those specified in this list will be exported.
  • include: In addition to the layers exported by default, the layers specified in this list will be exported.
  • exclude: The layers exported by default excluding those specified in this list will be exported.

http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/export?layers=show:2

Also take a look at what additional behaviour you can do with the use of dynamic layers.

  • I'm not sure if this really answers the OP question. The example above exports an image from the map service layer, though. – Matej May 15 '14 at 21:23
2

I know that this is an old question and already has an accepted answer. However, the answer goes over exporting the layer as an image. It doesn't seem to answer the OP's question. Because this is the first question that showed up when I was looking up this problem, I felt that I would add my solution here for others to try.

I first created a new ArcGISDynamicMapServiceLayer with the MapServer's URL, then used the .setVisibleLayers function to denote which layers in the MapServer should be displayed.

I can't use the OP's example MapServer because it has been taken down. But lets use esri's state, city, highway layer as an example. If I only want to show the highways on the map:

var newLayer = new ArcGISDynamicMapServiceLayer('http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer');
var layerIds = [0];
newLayer.setVisibleLayers(layerIds);
map.addLayer(newLayer);

If I wanted to show highways and states, then I would just replace the [0] with [0, 2].

1

Check out the ESRI API Reference Page for DynamicMapServiceLayer. I believe you will want to incorporate setVisibleLayers into your code.

  • I am not going to be managing the server for this project, just building the front-end. For easier management in the future would it make more sense for all the map layers to be setup/organized differently on the backend? Eventually I will build the front end to give users controls of many layers visibility, opacity etc. – jotamon Oct 29 '12 at 21:00
  • Hi Craig, the link seems to be dead? – bummi Apr 9 at 18:51

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.