Пример #1
0
        /// <summary>
        /// Zooms XamGeographicMap to a given geographic location
        /// </summary>
        /// <param name="geoMap"></param>
        /// <param name="geoLocation"></param>
        /// <param name="mapZoomScale"></param>
        public static void ZoomMapToLocation(this XamGeographicMap geoMap, GeoLocation geoLocation, double mapZoomScale = 0.1)
        {
            //validate geoMargin
            if (double.IsInfinity(mapZoomScale) || double.IsNaN(mapZoomScale))
            {
                mapZoomScale = 0.1;
            }

            mapZoomScale = System.Math.Abs(mapZoomScale);
            //// navigate to a geographic location
            //var geoRect = new Rect(geoLocation.Longitude - geoMargin, geoLocation.Latitude - geoMargin, 2 * geoMargin, 2 * geoMargin);
            ////Rect windowRect = geoMap.GetZoomFromGeographic(geoRect);
            //var geoRegion = new GeoRegion(geoLocation, geoMargin);
            //var southEast = new Point(geoLocation.Longitude - geoMargin, geoLocation.Latitude + geoMargin);
            //var northWest = new Point(geoLocation.Longitude + geoMargin, geoLocation.Latitude - geoMargin);

            //var windowRect2 = geoMap.GetZoomFromGeographic(geoRegion.NorthWest.ToPoint(), geoRegion.SouthEast.ToPoint());
            //var windowRect = geoMap.GetZoomFromGeographic(northWest, southEast);



            var longitudeOffset = (180 * 2 * mapZoomScale) / 2;
            var latitudeOffset  = (85 * 2 * mapZoomScale) / 2;


            var cartLocation  = geoMap.GetWindowPoint(geoLocation.ToPoint());
            var cartNorthWest = new Point(cartLocation.X - 50, cartLocation.Y - 50);
            var cartSouthEast = new Point(cartLocation.X + 50, cartLocation.Y + 50);

            var w = cartSouthEast.X - cartNorthWest.X;
            var h = cartSouthEast.Y - cartNorthWest.Y;

            var cartRect = new Rect(cartNorthWest.X, cartNorthWest.Y, w, h);

            DebugManager.Log("cartRect " + cartRect);
            var geoRect = geoMap.GetGeographicFromZoom(cartRect);

            DebugManager.Log("geoRect  " + geoRect);



            var northWest = new Point(geoLocation.Longitude - longitudeOffset, geoLocation.Latitude + latitudeOffset);
            var southEast = new Point(geoLocation.Longitude + longitudeOffset, geoLocation.Latitude - latitudeOffset);



            var geoRegion44 = new GeoRegion(northWest, southEast);

            northWest = geoMap.GetGeographicPoint(cartNorthWest);
            southEast = geoMap.GetGeographicPoint(cartSouthEast);
            DebugManager.Log("cartNorthWest " + cartNorthWest + " cartSouthEast " + cartSouthEast);
            DebugManager.Log("geoNorthWest  " + northWest + " geoSouthEast  " + southEast);


            var windowRect44 = geoMap.GetZoomFromGeographic(northWest, southEast);

            windowRect44 = geoMap.GetZoomFromGeographic(geoRect);


            DebugManager.Log("geoLocation " + geoLocation.ToPoint());
            DebugManager.Log("geoRegion44 " + geoRegion44.ToRect());
            //DebugManager.Log("geoRect4    " + geoRect4);
            //DebugManager.Log("windowRect4 " + windowRect4);
            DebugManager.Log("windowRect4 " + windowRect44);

            geoMap.WindowRect = windowRect44;
        }
Пример #2
0
        public static void ZoomMapToRegion(this XamGeographicMap geoMap, GeoRegion region)
        {
            var windowRect = geoMap.GetZoomFromGeographic(region.ToRect());

            geoMap.ZoomMapToWindow(windowRect);
        }