I am learning ArcGIS javascript API and wanted to make a reordering panel for my webapp. I looked through the ArcGIS sample.
but I'm stuck at addLake()
function. If I'm understand the sample correctly, to add the new lake layer
1. get the existing DynamicLayerInfos from the current map
2. create a new DynamicLayerInfo for the new layer
3. push to the DynamicLayerInfos
4. set the new DynamicLayerInfos to the map
The example uses LayerDataSource
that reference a table as the new data source for the layer.
And how do you add a new layer from a public layer on a MapServer/FeatureServer. Can someone give me an example?
-
I think you are looking at the wrong example. The example you have linked to, deals with reordering layers within a dynamic map service, and not reordering various layers in your JSAPI web app. Which of the two do you want to do?Devdatta Tengshe– Devdatta Tengshe2013年05月15日 14:48:26 +00:00Commented May 15, 2013 at 14:48
3 Answers 3
Have you looked at the reorder function on the map object?
Suppose your map already has 2 layers, and you want to add a new layer in between them, you could use the following code:
var LouisvilleLayer=new esri.layers.ArcGISDynamicMapServiceLayer(
"http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/MapServer",
{useMapImage:true});
map.addLayer(LouisvilleLayer);
map.reorderLayer(LouisvilleLayer,1);
In ArcGIS JS API version 4.22, you can give layer index while adding layer.
map.add(layer, 0);
The index "0" defines the lowest layer.
-
1perfect this is what I'm looking forGobinath– Gobinath2022年01月17日 15:47:00 +00:00Commented Jan 17, 2022 at 15:47
So I still don't really understand the part about LayerDataSource but I did manage to add layer successfully while updating the switchable layered list.
What I did was I used I
- get the current DynamicLayerInfos from map.
- generated a new ArcGISDynamicMapServiceLayer of the MapLayer I wanted to insert (remember to use unique id)
- Add layer to map with app.map.addLayer(...)
- Then I created DynamicLayerInfos with createDynamicLayerInfosFromLayerInfos()
- Extract individual DynamicLayerInfo
- push the new DynamicLayerInfo to the current DynamicLayerInfos list with DynamicLayerInfos.push(...)
-
Also, in order for layer to actually reorder on the fly, the Server must provide "Dynamic Layer" service as a "Children Resources". To check if you have Dynamic Layer service enabled, click on a Layer group in your ArcGIS server website. It should say "Dynamic Layer" before the list of layers.swap0– swap02013年05月15日 19:59:25 +00:00Commented May 15, 2013 at 19:59
Explore related questions
See similar questions with these tags.