[GIS] ArcGIS javascript api – layer reordering – how to add new layers

arcgis-javascript-apiarcgis-serverjavascript

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?

Best Answer

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);
Related Question