Get the current zoom level and Lat/Long

6809
5
01-03-2012 04:34 PM
TylerRothermund
New Contributor II
How can I get the current zoom level and center point Lat/Long of the map?  I need to save these settings so I can restore them the next time the user hits the page.
5 Replies
SanajyJadhav
Occasional Contributor II
Can you clarify "current zoom level"?

If you mean current extent, you can get it by Map.Extent and it's center as Map.Extent.GetCenter().
0 Kudos
TylerRothermund
New Contributor II
Is MyMap.Extent.GetCenter().X , Y  = Lat / Long or are those some kind of screen coordinate?

Is there a property that tells me how far the user has zoomed (level) into the map like  a (1-9) or something?
0 Kudos
JenniferNery
Esri Regular Contributor
You can look at the following SDK samples:
Map.Extent updates on pan/zoom
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#MapExtent
Screen point can be converted to map coordinates
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#MouseCoords
You can compare Map.Resolution property against ArcGISTiledMapServiceLayer.TileInfo.Lods.Resolution to know what level you are currently zoomed in.
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ShowMapProperties
0 Kudos
TylerRothermund
New Contributor II
Shouldn't Map.Resolution = one of the LODs ? 

I'm using this map:
http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer

But Map.Resolution doesn't match any of the LODs.

  private int GetZoomLevel()
        {
            double currentRes = MyMap.Resolution;
            var lods = ((ArcGISTiledMapServiceLayer)MyMap.Layers[0]).TileInfo.Lods.ToList();
            int level = lods.IndexOf(lods.Where(l => l.Resolution == currentRes).FirstOrDefault());

            return level;
        }
0 Kudos
dotMorten_esri
Esri Notable Contributor
Unless you set SnapToLevels=true on the map, you can zoom between levels, so no there is no guarantee.
You can instead pick the closest one which should be the one currently rendering.
Scale and/or Resolution is the most precise way for determining the zoom since this is a fully linear range as opposed to zoom levels.
0 Kudos