Select to view content in your preferred language

Problem Switching between maps with different Spatial Refrence

596
3
04-11-2012 06:11 PM
TylerRothermund
Emerging Contributor
When I switch between maps that have a different spatial reference I get an exception that the Layers have to be cleared first.   So I cleared the layers and add a new ArcGISTiledMapServiceLayer, but nothing gets displayed and no exceptions.  Any Ideas? 


private void SetMapUrl(string mapUrl)
        {
            MyMap.Layers.Remove(ServiceLayer);
            ArcGISTiledMapServiceLayer serviceLayer = Resources["ServiceLayer"] as ArcGISTiledMapServiceLayer;
            serviceLayer.Url = mapUrl;
            MyMap.Layers.Insert(0, serviceLayer);
            
            if (UseMapProxy(mapUrl))
            {
                string proxyUrl = BaseUrl + "/ArcGisMapProxyHandler.ashx";
                serviceLayer.ProxyURL = proxyUrl;
            }
            else
                serviceLayer.ProxyURL = "";
            
        }
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
Might be an extent issue. You can't keep the current map extent whan changing the map spatialreference.

Try :
private void SetMapUrl(string mapUrl)
{
   MyMap.Layers.Clear();
   MyMap.Extent = null;
   ArcGISTiledMapServiceLayer serviceLayer = Resources["ServiceLayer"] as ArcGISTiledMapServiceLayer;
   serviceLayer.Url = mapUrl;
   MyMap.Layers.Insert(0, serviceLayer);
......
0 Kudos
TylerRothermund
Emerging Contributor
That worked, Thanks

Is there a way I can restore the current extent so the user is still zoomed in to the same location?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
That worked, Thanks

Is there a way I can restore the current extent so the user is still zoomed in to the same location?


Sure but, as the Spatial Reference is no more the same, you will have to project the old extent in the new SR (at server side with a geometry service or at client side for basic cases).
0 Kudos