Select to view content in your preferred language

create new map instance (change projection)

1909
12
01-18-2011 03:10 AM
DmitryAleshkovsky
Deactivated User
I have problem with creating new map instance.
I have 2 tiled layers with different spatial reference (102100 and 54004)
i try to change my map baselayer from one layer to another one.
So I try to create new instance of the map with new extent and spatial reference. But layer no visible in new map (resolution = NaN)
my code:
lyr - is new layer

                
                Map.Layers.Clear();
                collLayers.Remove(collLayers["BaseLayer"]);//layers collection
                
                Map.UpdateLayout();
                lyr.ID = "BaseLayer";
                Map = new ESRI.ArcGIS.Client.Map() 
                { 
                    Extent = lyr.FullExtent, 
                    MaximumResolution=((TiledMapServiceLayer)lyr).TileInfo.Lods[0].Resolution ,
                    MinimumResolution = ((TiledMapServiceLayer)lyr).TileInfo.Lods[((TiledMapServiceLayer)lyr).TileInfo.Lods.Length-1].Resolution 
                };
                Map.Layers.Add(lyr);// add new base layer first
                foreach (Layer l in collLayers) // restore other layers
                {
                    Map.Layers.Add(l);
                }
                Map.UpdateLayout();


what's wrong?
0 Kudos
12 Replies
DominiqueBroux
Esri Frequent Contributor
I have no direct answer to your question, but the following info can be useful : from version 2.1 (or 2.0 I am not sure), you can change the spatialreference of a map if there is no layer in the map.

So to change the url of the basemap layer (supposed to be the first layer in this sample), you can use code like:
LayerCollection layerCollection = MyMap.Layers;
MyMap.Layers = null;
MyMap.Extent = null;
(layerCollection[0] as ArcGISTiledMapServiceLayer).Url = myNewBaseLayerUrl;
MyMap.Layers = layerCollection;


Keeping the same map avoids the issues with bindings, events, behaviors that you could have by cloning.
0 Kudos
DmitryAleshkovsky
Deactivated User
excellent solution!
I've read in on-line help "...If you need to change spatial reference on the fly, you can instead create a new map instance, move the layers to this map, and replace the previous map instance..."
It has misled me

set extent =null and  layers=null is enough
0 Kudos
dotMorten_esri
Esri Notable Contributor
map.resolution will be NaN until the map and layers has been initialized. This won't happen until shortly after you added the map to the UI.
0 Kudos