Scale the map

May 12, 2010 at 9:08 AM

Now, i created a class to scale map.

but i think there are some better way to do it.

i'll very happy if you give me some nice suggest.thank you!

i'll show code before:

    public class ScaleExtend
    {
        private Map m_Map;

        public ScaleExtend(Map pMap)
        {
            this.m_Map = pMap;
        }


        public int Scale
        {
            get
            {
                if (m_Map.Layers.Count < 1)
                    return (100000);
               
                return Convert.ToInt32((UnitMeterConversion() * m_Map.Envelope.Width * 39.3700787 * 100D) / m_Map.MapFrame.View.Width);
            }
            set
            {
                if (m_Map.Layers.Count < 1)
                    return;
                IEnvelope tempEnv = m_Map.Envelope;

                double xtl = tempEnv.X;
                double ytl = tempEnv.Y;

                Coordinate vCenterLonlat = tempEnv.Center();

                tempEnv.Width = (value * m_Map.MapFrame.View.Width) / (UnitMeterConversion() * 39.3700787 * 100D);
                tempEnv.Height = (value * m_Map.MapFrame.View.Height) / (UnitMeterConversion() * 39.3700787 * 100D);

                tempEnv.SetCenter(vCenterLonlat);


                m_Map.MapFrame.Extents = tempEnv;
            }
        }

        private double UnitMeterConversion()
        {
            if (m_Map == null)
            {
                return 1;
            }

            if (m_Map.Layers.Count == 0)
            {
                return 1;
            }
           
            if (m_Map.Layers[0].DataSet == null)
            {
                return 1;
            }
           
            if (m_Map.Layers[0].DataSet.Projection == null)
            {
                return 1;
            }
           
            if (m_Map.Layers[0].DataSet.Projection.IsLatLon)
            {
                //m_Map.Layers[0].DataSet.Projection.GeographicInfo.Unit.Radians=π/180
                //6354101.943=Radius
                return m_Map.Layers[0].DataSet.Projection.GeographicInfo.Unit.Radians * 6354101.943;
            }
            else
            {
                return m_Map.Layers[0].DataSet.Projection.Unit.Meters;
            }
        }
    }