Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to use javascript and dojo to add and remove layers.

share|improve this question

Use esri.Map's addLayer and removeLayer methods. Both take the layer to add or remove from the map as an argument. You might also be interested in map.removeAllLayers() and map.reorderLayer.

Finally, one thing that sometimes trips people up is getting a reference to layers in the map. The recommended approach is to assign an ID to your layers when you create them. If you don't manually assign an ID, the map assigns one for you. You can get these id's by looking at map.layerIds and map.graphicsLayerIds. Both are arrays of strings. Once you have an ID, get the associated layer using map.getLayer("some_layer_id").

share|improve this answer
it might also be constructive to say that layers in the js api are map services (a group of arc map data layers) not the individual data layers within the map service. Currently you can't modify what layers are in that map service but I think that is changing at 10.1 – Steve Feb 23 '12 at 20:42
Derek, Upon your suggestion, I tried the following ways to remove a layer (mapservice) from the map: 1. map.removeAllLayers(); 2. for (var j = 0; j < map.layerIds.length; j++) { var layer = map.getLayer(map.layerIds[j]); map.removeLayer(layer); } I had NO success removing the mapservices from the Map. After executing the code above, I could still see the mapservices. Any ideas? – user6755 Apr 4 '12 at 21:35
@LearningGIS24 can you post this as a separate question? Comments on an answer aren't really the place for new discussion. – Derek Swingley Apr 6 '12 at 16:07

Your Answer


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.