Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

Thanks in advance!

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
what internal switches are made when the first layer is set? can't you just reset those? –  Steve Dec 1 '11 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. –  Derek Swingley Dec 1 '11 at 21:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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