Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="envelope"></param>
        /// <param name="rectangle"></param>
        /// <returns></returns>
        public static int DetermineZoomLevel(Envelope envelope, Rectangle rectangle)
        {
            double metersAcross = EarthRadiusKms * envelope.Width * Math.PI / 180; //find the arc length represented by the displayed map
            metersAcross *= Math.Cos(envelope.Center().Y * Math.PI / 180); //correct for the center latitude

            double metersAcrossPerPixel = metersAcross / rectangle.Width; //find the resolution in meters per pixel

            //find zoomlevel such that metersAcrossPerPix is close
            for (int i = 2; i < 19; i++)
            {
                double groundRes = GroundResolution(envelope.Center().Y, i);

                if (metersAcrossPerPixel > groundRes)
                {
                    //System.Diagnostics.Debug.WriteLine("metersPerPixel: " + metersAcrossPerPixel);
                    //System.Diagnostics.Debug.WriteLine("groundRes:      " + groundRes);
                    //double ratio = metersAcrossPerPixel / groundRes;
                    //System.Diagnostics.Debug.WriteLine("ratio: " + ratio);

                    //fix zoom level..
                    //changed to a slightly lower zoom level to increase readability
                    if (i > 2 && i < 18) return i - 1;

                    ////MessageBox.Show("MAPP: "+metersAcrossPerPixel+" , zoom: "+(i-1));
                    return i;
                }
            }

            return -1;
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="envelope"></param>
        /// <param name="rectangle"></param>
        /// <returns></returns>
        public static int DetermineZoomLevel(Envelope envelope, Rectangle rectangle)
        {
            double metersAcross = EarthRadiusKms * envelope.Width * Math.PI / 180; //find the arc length represented by the displayed map
            metersAcross *= Math.Cos(envelope.Center().Y * Math.PI / 180); //correct for the center latitude

            double metersAcrossPerPixel = metersAcross / rectangle.Width; //find the resolution in meters per pixel

            //find zoomlevel such that metersAcrossPerPix is close
            for (int i = 2; i < 19; i++)
            {
                double groundRes = GroundResolution(envelope.Center().Y, i);

                if (metersAcrossPerPixel > groundRes)
                {
                    //fix zoom level..
                    //changed to a slightly lower zoom level to increase readability
                    if (i > 2 && i < 18) return i - 1;
                    return i;
                }
            }

            return -1;
        }