Ejemplo n.º 1
0
        public void ZoomToBox(GeoCoordinateBox box, float maxZoom = 19)
        {
            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.Invoke(() => ZoomToBox(box, maxZoom));
                return;
            }

            SuspendNotifyMapViewChanged();

            var currentView      = _mapSceneManager.CreateView();
            var currentPerimeter = currentView.Width * 2 + currentView.Height * 2;

            var topLeft         = _mapSceneManager.Map.Projection.ToPixel(box.TopLeft);
            var bottomRight     = _mapSceneManager.Map.Projection.ToPixel(box.BottomRight);
            var newPerimeter    = (bottomRight[0] - topLeft[0]) * 2 + (bottomRight[1] - topLeft[1]) * 2;
            var perimeterFactor = newPerimeter / currentPerimeter;

            MapCenter = box.Center;
            if (perimeterFactor > 3 || perimeterFactor < 1 / 3f)
            {
                MapZoom = System.Math.Min(box.GetZoomLevel(), maxZoom);
            }

            ResumeNotifyMapViewChanged();
        }