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
objMap.removeAllLayers();
objMap.removeLayer(objMap.getLayer('myLayerID'));
Solved! Go to Solution.
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.
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.
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?
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?
The problem is, the map not get zoomed after Zoom-Level-5.
Yes both layer's spatialReferences are different.
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.