Select to view content in your preferred language

How to read the current scale of a Map?

2875
3
04-19-2011 09:55 AM
SuiHuang
Frequent Contributor
Hi Everybody:

    I am writing a Silverlight program that reads a ArcGIS Server 10 map service feature layer (such as http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/MapServer/80).
    When this layer is displayed on the map I want to find a method to read the current display scale, because I want to zoom out to make sure the scale number is larger than "Min. Scale" of the map service, and then I can check whether the map is displayed when the scale is out of the range defined by "Min. Scale" and "Max. Scale".
    However, I haven't found the method to get the exact number. The Scalebar control give a good scale legend, but not the exact number to compare with "Min. Scale" of the map service. In the Map control I haven't found a property to return that value neither.
    Any idea how I can get the nubmer?
    Thank you.


My development environment:
-- .NET 4
-- C# and Visual Studio 2010
-- Silverlight 4
-- ESRI ArcGIS API for Microsoft Silverlight/WPF
-- ArcGIS server 10.01 map services
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
The ScaleBar has a ScaleValue property: http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.ScaleBar~S... which is calculated based on the Map.Resolution.
0 Kudos
SuiHuang
Frequent Contributor
Thank you jenniferdnery! I will try.

The ScaleBar has a ScaleValue property: http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.ScaleBar~S... which is calculated based on the Map.Resolution.
0 Kudos
vipulsoni
Regular Contributor
Thank you jenniferdnery! I will try.


Take this code.. might help you.

  #region getMapScale
        /// <summary>
        /// getMapScale
        /// </summary>
        /// <param name="esriMap"></param>
        /// <returns></returns>
        public double getMapScale(Map esriMap)
        {
            double dpi = 96; //screen resolution: pixels per inch
            double screenUnitsPerMapUnit = 39.37; //inches per meter
            double mapResolution = esriMap.Resolution;
            double scale = (dpi * screenUnitsPerMapUnit * mapResolution);
            return scale;
        }
        #endregion

#region MAP SCALE CHANGE
        /// <summary>
        /// MAP SCALE CHANGED
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Map_ExtentChanged(object sender, ExtentEventArgs e)
        {
            double Map_Scale = getMapScale(Map);

            int scaled = Convert.ToInt32(Math.Round(Map_Scale));

            MapScale.Text = "1 : " + scaled;
        }
        #endregion
0 Kudos