Take the tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
 
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 May 15 at 14:48
add comment

2 Answers

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);
share|improve this answer
add comment

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(...)
share|improve this answer
 
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 May 15 at 19:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.