1

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked May 14, 2013 at 16:06
1
  • 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? Commented May 15, 2013 at 14:48

3 Answers 3

5

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);
answered May 15, 2013 at 14:53
0
2

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.

Source

answered Jan 17, 2022 at 8:14
1
  • 1
    perfect this is what I'm looking for Commented Jan 17, 2022 at 15:47
1

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

  1. get the current DynamicLayerInfos from map.
  2. generated a new ArcGISDynamicMapServiceLayer of the MapLayer I wanted to insert (remember to use unique id)
  3. Add layer to map with app.map.addLayer(...)
  4. Then I created DynamicLayerInfos with createDynamicLayerInfosFromLayerInfos()
  5. Extract individual DynamicLayerInfo
  6. push the new DynamicLayerInfo to the current DynamicLayerInfos list with DynamicLayerInfos.push(...)
answered May 15, 2013 at 17:33
1
  • 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. Commented May 15, 2013 at 19:59

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.