Select to view content in your preferred language

map.removeAllLayers() doesnot remove mapservices

1018
1
04-04-2012 02:08 PM
SowjanyaSunkara
Emerging Contributor
Has anyone successfully removed a mapservice using map.removeAllLayers()?
I'm using version 2.7 of the API and have also tried the code below to remove mapservices.

        for (var j = 0; j < map.layerIds.length; j++) {
            var layer = map.getLayer(map.layerIds);
            map.removeLayer(layer);

        }

but none of these remove the mapservices. Any help is appreciated.
0 Kudos
1 Reply
ShreyasVakil
Frequent Contributor
Yes you can remove all the layers using map.removeAllLayers() .

You can remove individual layers using:
function removeMe()
   {
  map.removeLayer(referenceLayer);
  map.removeLayer(basemap);
   }


All layers at once using:
function removeMe()
   {
  map.removeAllLayers();
   }

Or else you can remove all layers in a loop using:
function removeMe()
  {
  var count = map.layerIds.length;
  var array = [];
  for(var i=0;i<count;i++)
  {
  array = map.layerIds;
  }
 for(var j=0; j<count; j++){
  var layer = map.getLayer(array);
  map.removeLayer(layer);
 } 
  }
0 Kudos