ali7789v4

Switching between layers in different MSDs

Discussion created by ali7789v4 on Mar 2, 2012
Latest reply on Mar 5, 2012 by ali7789v4
Hello

I have my layers spread across several MSDs due to the amount of data I'm dealing with.

So I need the user to be able to switch between the different MSD documents, and load the different layers onto the map. However this doesnt appear to be easy.

The code i've experimented with is below. It works, except that Firebug is reporting the following error (which is fairly meaningless to me)
"this._map is null"
I assume during the switch it's lost it's reference to what map it is using?

In my init function I have:

//Create new map extent
var extent = new esri.geometry.Extent({"xmin":-1165908.3243762157,"ymin":6596317.879631129,"xmax":546281.1092112772,"ymax":7819310.332193623,"spatialReference":{"wkid":102100}});
map = new esri.Map("gisMap",{extent:extent,logo:false});

//Add Bing maps as the tile layer  
map.addLayer(veTileLayer);

//Call my custom function
updateSelectedLayer('init');

 


(map is a global var)

function updateSelectedLayer(layerId) {
 
 if (layerId == 'init') {
  layerId = 'defaultlayername';
 
 } else {
 
   for(var j = 1; j < map.layerIds.length; j++) {
  var layer = map.getLayer(map.layerIds[j]);
  //Layer may not exist if we've removed it so check
  if (layer) {   
   map.removeLayer(layer);
  }
 }
  
 }

 dynamicLayer = '';
 var overlayURL= globals.layers[layerId];//this is a reference to a url held in an array

 dynamicLayer = new esri.layers.ArcGISDynamicMapServiceLayer(overlayURL);
 dynamicLayer.setOpacity(0.6);        
 map.addLayer(dynamicLayer);
 
 
}




Am I approaching this in completely the wrong way?
I would be grateful for any help you can give.

Thanks

Outcomes