6

I have the following code fragment in an esri page to try and change basemaps, the following code works, unless the next basemap layer uses a different spatialreference.

if (baseMap)
  _map.removeLayer(baseMap);
baseMap = new esri.layers.ArcGISTiledMapServiceLayer(mapSource);
_map.addLayer(baseMap);

It seems like my only option is to destroy the map instance and start from scratch every time the user desires to change the basemap. Am I going about this the wrong way... anyone have any insight? I have seen samples of the basemapgallerywidget, but haven't used it.

So the basic question is: To change basemaps,not knowing the future basemap spatial reference, is my only option to destroy the map instance and re-create it?

2 Answers 2

6

Tiled map services added to a JS API map have to match the map's spatial reference. The map's spatial reference is set when you create the map if you specify an extent or it's set to the spatial reference of the first layer added to the map.

If you need to use tiled map services that are in different spatial references, then yes, you'll have to destroy and create a new map when you change tiled map services. Ideally, your tiled map services would all use the same spatial reference but it sounds like you might not have control over that.

2
  • what internal switches are made when the first layer is set? can't you just reset those?
    – Steve
    Dec 1, 2011 at 19:32
  • @Steve that would be more trouble than it's worth, destroying and creating a new map is the way to go if you absolutely have to use multiple tiled map services with different spatial references. Dec 1, 2011 at 21:45
0

Should you host a different instant of the tiled service that you are using as basemap on the arcgis server ? Or changing the spatial reference of the Tiled basemap via the JS api is possible and enough so as to change the projection of the map. I am considering this since I know that you are not able to change the projection of a tiled service.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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