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– Vince2018年05月30日 10:56:59 +00:00Commented May 30, 2018 at 10:56
-
I don't understand. You have to remove all layers just to turn one off?Dowlers– Dowlers2018年05月30日 16:33:38 +00:00Commented May 30, 2018 at 16:33
-
@Dowlers Is there another way?Leeloo– Leeloo2018年05月30日 17:05:12 +00:00Commented May 30, 2018 at 17:05
-
1Using javascript? Yes there are several. layer.setVisibleLayers(ids, doNotRefresh?) is the easiest: developers.arcgis.com/javascript/3/jsapi/…Dowlers– Dowlers2018年05月30日 20:58:40 +00:00Commented May 30, 2018 at 20:58
-
@Dowlers Could you write in answer form?Leeloo– Leeloo2018年05月30日 21:21:15 +00:00Commented May 30, 2018 at 21:21
1 Answer 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– Leeloo2018年05月31日 06:47:30 +00:00Commented May 31, 2018 at 6:47 -
Also, is says,
ArcGISDynamicMapServiceLayer
is not definedLeeloo– Leeloo2018年05月31日 06:49:00 +00:00Commented 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– Dowlers2018年05月31日 14:31:05 +00:00Commented May 31, 2018 at 14:31
-
What about
SetLayers
from esri.github.io/esri-leaflet/api-reference/layers/… ?Leeloo– Leeloo2018年05月31日 14:32:07 +00:00Commented 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– Dowlers2018年05月31日 14:37:45 +00:00Commented May 31, 2018 at 14:37