I have a problem related to "ArcGISTiledMapServiceLayer". I have an ArcGISTiledMapServiceLayer map service, which I have added to Map object. This service work as BaseMap. Now I want to add another ArcGISTiledMapServiceLayer map service layer to the same Map object. Before adding the new layer, I just removed the previous tiled map service layer by using method objMap.removeAllLayers(). But this method only removes the layer not the extent and it create problem when I add a new layer.

So I want to remove completely the ArcGISTiledMapServiceLayer (layer, extent, scale etc.).

I have tried all the below methods

  1. objMap.removeAllLayers();

  2. objMap.removeLayer(objMap.getLayer('myLayerID'));

Any solution?

  • After removing first layer, when I add second layer, the map not get zoom after zoom level 5. – Sanjay Gupta Jul 28 '14 at 7:02
  • 1
    @StephenLead: My comment seems to be no longer corrrect. In the 1.x & 2.x version of the API you could change the projection & lods after setting it. It does not seem to be possible in the 3.x version. Hence the answer given by janechii seems to be the best way to do this. – Devdatta Tengshe Aug 28 '14 at 2:40
  • @StephenLead: you are right. I've deleted my comments. – Devdatta Tengshe Aug 28 '14 at 6:09
  • @DevdattaTengshe thanks for elaborating. I've never worked with pre v3 versions, so it's good to make this distinction! – janechii Aug 28 '14 at 20:39

You should be able to call destroy on the current map instance then create a new esri/Map instance and load the new base map.

See: https://developers.arcgis.com/javascript/jsapi/map-amd.html#destroy

var map1 = new Map('map');
var basemap1 = new ArcGISTiledMapServiceLayer(url);
var map2 = new Map('map'); // note we load to the same html node
var basemap2 = new ArcGISTiledMapServiceLayer(url);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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