How to remove ArcGISTiledMapServiceLayer completely

2001
5
Jump to solution
07-28-2014 12:00 AM
SanjayGupta
New Contributor

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'));
0 Kudos
1 Solution

Accepted Solutions
OwenEarley
Occasional Contributor III

I am not sure if it is possible to do this. I was under the impression that all tiled layers had to use the same spatial reference. After a bit of searching I found this:

Set custom extent and spatial reference | ArcGIS API for JavaScript

At versions 1.0 and 1.1 of the ArcGIS JavaScript API, any map service layers you used were required to correspond with the map's spatial reference. Beginning at version 1.2, you can use dynamic map services that have a different spatial reference from the map. Although this gives you more flexibility of the layers you can use, the projection on the fly negatively affects performance.

Cached (tiled) layers in your map must still match the map's spatial reference.

View solution in original post

0 Kudos
5 Replies
OwenEarley
Occasional Contributor III

You could destroy and recreate the map object to clear the basemap and all other map properties such as extent, scale, etc.

// Destroy existing map

map.destroy();

map = null;

//Create new map

map = new Map("map", {

});

Based on this sample from ESRI.

0 Kudos
SanjayGupta
New Contributor

But there is too much other properties, event assigned to the Map object, so that I cannot destroy and re-create the Map object. Any other solution?

0 Kudos
OwenEarley
Occasional Contributor III
But this method only removes the layer not the extent and it create problem when I add a new layer.

What is the problem that the previous map extent creates when adding the new basemap layer? - is the spatial reference different?

0 Kudos
SanjayGupta
New Contributor

The problem is, the map not get zoomed after Zoom-Level-5.

Yes both layer's spatialReferences are different.

0 Kudos
OwenEarley
Occasional Contributor III

I am not sure if it is possible to do this. I was under the impression that all tiled layers had to use the same spatial reference. After a bit of searching I found this:

Set custom extent and spatial reference | ArcGIS API for JavaScript

At versions 1.0 and 1.1 of the ArcGIS JavaScript API, any map service layers you used were required to correspond with the map's spatial reference. Beginning at version 1.2, you can use dynamic map services that have a different spatial reference from the map. Although this gives you more flexibility of the layers you can use, the projection on the fly negatively affects performance.

Cached (tiled) layers in your map must still match the map's spatial reference.

0 Kudos