Select to view content in your preferred language

Move or reorder layers in mapview

3654
5
07-31-2012 11:43 AM
LukeCatania
Occasional Contributor
Is there a way to move or reorder layers in a mapview?  I have a list of map layers with a check box next to each along with up and down arrows.  I want to give the user the ability to move a layer up or down so they appear over or the current map or pushed under the current map.  At the moment I am trying to add a listener to each arrow that would remove the layer and add the layer back into the mapview into a different position.  Anyone have a better solution.  Would be nice to have a moveUp and moveDown method on a layer or mapview.

I am also running into the issue that I build the menu as the layers are read off the sdcard but I also add the layers as they are read, so the menu built shows the layer in reverse order.  That is the top most layer shown in the list is actually the bottom layer in the mapview.  I need it reversed, so the layer listed at the top is topmost layer in the mapview.
0 Kudos
5 Replies
NicoTek
Occasional Contributor
Anybody with good hints or tips regarding how to re-order layers?


I want to be able to have an option that changes the base-map, and at the moment I'm thinking I will need to remove all layers, add the new base map and then add all other layers again.

Any better ideas?
0 Kudos
SimonKlein
Regular Contributor
I did the same in my app. I couldn't think of any other solution. I did it with v1.1 of the SDK. In the changelog for v2 it says there is a way to change the basemap, but so far I didn't see anything.
You can get the basemaps of a webmap, but there is no good way (at least for my use case) to easily add a new basemap to an existing webmap.
0 Kudos
AndyGup
Esri Regular Contributor
Did you look at the addLayer(Layer layer, int index)  method? You can add a layer using an index. Conversely, you can also remove a layer using removeLayer(int index).

-Andy
0 Kudos
LukeCatania
Occasional Contributor
Did you look at the addLayer(Layer layer, int index)  method? You can add a layer using an index. Conversely, you can also remove a layer using removeLayer(int index).

-Andy


Yes.  I am using those methods.  I have the map index and name saved as a tag on the arrow, so I know which layer to remove and add back in.  Just need to work out the logic.  It works one time, but the next time I move a layer it is moved two layers down rather than one.  So need to figure what I am doing wrong in the code.
0 Kudos
AndyGup
Esri Regular Contributor
Not sure if this will help or not since it's not the exact code you are asking about. However, this snippet shows one example for iterating through the layers and work with the various properties:

Layer[] layerArr = map.getLayers();
for(Layer layer : layerArr)
{
 Boolean visible = layer.isVisible();
 if(layer instanceof ArcGISTiledMapServiceLayer && visible == true){
  ArcGISTiledMapServiceLayer tempMap = (ArcGISTiledMapServiceLayer) layer;
  ArcGISLayerInfo[] info = tempMap.getLayers();
  Log.d("test","Layer name= " + tempMap.getName() + ", " + info[0].getName());
  String name = info[0].getName().toLowerCase();
  Boolean vis = info[0].isVisible();

  if(name.equals("world street map")){
   layerButton.setText("Topo");
   streetLayer.setVisible(false);
   topoLayer.setVisible(true);
  }
  if(name.equals("topographic info")){
   layerButton.setText("Streets");
   streetLayer.setVisible(true);
   topoLayer.setVisible(false);
  }
  
 }
}


-Andy
0 Kudos