1

I've developed an application which loads the services from the ArcGIS Server via REST API.

Each service has multiple layers, and I can check/uncheck any layer. The problem is the layers are loaded via one URL, and each time I have to remove all layers of the service and load again.

Is there a better way?

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked May 30, 2018 at 9:50
5
  • No. Loading each layer as a service would be extremely wasteful of Server resources, and result in awful performance. Commented May 30, 2018 at 10:56
  • I don't understand. You have to remove all layers just to turn one off? Commented May 30, 2018 at 16:33
  • @Dowlers Is there another way? Commented May 30, 2018 at 17:05
  • 1
    Using javascript? Yes there are several. layer.setVisibleLayers(ids, doNotRefresh?) is the easiest: developers.arcgis.com/javascript/3/jsapi/… Commented May 30, 2018 at 20:58
  • @Dowlers Could you write in answer form? Commented May 30, 2018 at 21:21

1 Answer 1

1

Individual layers within a map service can be turned on or off using the esri javascript api. Look at the setVisibleLayers method of the dynamicmaplayer class: https://developers.arcgis.com/javascript/3/jsapi/arcgisdynamicmapservicelayer-amd.html#setvisiblelayers

It takes on array of layerIDs to make visible

require([
 "esri/layers/ArcGISDynamicMapServiceLayer" ,"dojo/query", ... 
], function(ArcGISDynamicMapServiceLayer, query, ... ) {
 var layer = new ArcGISDynamicMapServiceLayer( ... );
 var inputs = query(".list_item"), input;
 visible = [];
 for (var i=0, il=inputs.length; i< il; i++) {
 if (inputs[i].checked) {
 visible.push(inputs[i].id);
 }
 }
 layer.setVisibleLayers(visible);
 ...
});
answered May 30, 2018 at 21:54
6
  • How to define layers? var layer = new ArcGISDynamicMapServiceLayer( ... ); What is in the brackets? Commented May 31, 2018 at 6:47
  • Also, is says, ArcGISDynamicMapServiceLayer is not defined Commented May 31, 2018 at 6:49
  • I think you need to go back and look at some of the samples on the javascript api website. Instantiating layers is a core part of the api and is covered in many of the samples. developers.arcgis.com/javascript/3/jssamples/… Commented May 31, 2018 at 14:31
  • What about SetLayers from esri.github.io/esri-leaflet/api-reference/layers/… ? Commented May 31, 2018 at 14:32
  • Oh you are using leaflet. I'm not as familiar with that but I think you are right. The setlayers method will take an array of layerids to show. Commented May 31, 2018 at 14:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.