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?

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

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.