Ejemplo n.º 1
0
        public static void SetZoomToPoint(Map map, Point point, int zoomAdjustment)
        {
            ICoordinateService coordinateService = CoordinateServiceProvider.GetService(map);
            Point      center        = map.SpatialReference.GeographicToLogical(map.Center);
            Location   newCenter     = map.Center;
            IMapSource mode          = map.Provider.CurrentSource;
            Point      sourceLogical = coordinateService.PixelToLogical(point);
            Location   sourcePoint   = coordinateService.PixelToGeographic(point);

            map.ZoomLevel += zoomAdjustment;
            Point    currentLogical = coordinateService.PixelToLogical(point);
            Location currentPoint   = coordinateService.PixelToGeographic(point);

            if (mode == map.Provider.CurrentSource)
            {
                Point shift = new Point(sourceLogical.X - currentLogical.X, sourceLogical.Y - currentLogical.Y);
                center.X += shift.X;
                center.Y += shift.Y;

                newCenter = map.SpatialReference.LogicalToGeographic(center);
            }
            else
            {
                if (map.Center.Longitude < sourcePoint.Longitude)
                {
                    newCenter.Longitude = map.Center.Longitude + sourcePoint.Longitude - currentPoint.Longitude;
                }
                else
                {
                    newCenter.Longitude = map.Center.Longitude - currentPoint.Longitude + sourcePoint.Longitude;
                }

                if (map.Center.Latitude < sourcePoint.Latitude)
                {
                    newCenter.Latitude = map.Center.Latitude + sourcePoint.Latitude - currentPoint.Latitude;
                }
                else
                {
                    newCenter.Latitude = map.Center.Latitude - currentPoint.Latitude + sourcePoint.Latitude;
                }
            }

            map.Center = newCenter;
        }