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?

5
  • No. Loading each layer as a service would be extremely wasteful of Server resources, and result in awful performance.
    – Vince
    Commented May 30, 2018 at 10:56
  • I don't understand. You have to remove all layers just to turn one off?
    – Dowlers
    Commented May 30, 2018 at 16:33
  • @Dowlers Is there another way?
    – Leeloo
    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/…
    – Dowlers
    Commented May 30, 2018 at 20:58
  • @Dowlers Could you write in answer form?
    – Leeloo
    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);
  ...
});
6
  • How to define layers? var layer = new ArcGISDynamicMapServiceLayer( ... ); What is in the brackets?
    – Leeloo
    Commented May 31, 2018 at 6:47
  • Also, is says, ArcGISDynamicMapServiceLayer is not defined
    – Leeloo
    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/…
    – Dowlers
    Commented May 31, 2018 at 14:31
  • What about SetLayers from esri.github.io/esri-leaflet/api-reference/layers/… ?
    – Leeloo
    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.
    – Dowlers
    Commented May 31, 2018 at 14:37

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.