Example #1
0
        public static void SetDrag(Map map, Point point, Point origin, Location mouseCenter)
        {
            MouseDragBehavior behavior = (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift ?
                                         map.MouseShiftDragMode : map.MouseDragMode;

            switch (behavior)
            {
            case MouseDragBehavior.Drag:
            {
                ICoordinateService coordinateService = CoordinateServiceProvider.GetService(map);
                Point pixelCenter = coordinateService.LogicalToPixel(map.SpatialReference.GeographicToLogical(mouseCenter));
                pixelCenter.X += origin.X - point.X;
                pixelCenter.Y += origin.Y - point.Y;

                Point offset          = map.MultiScaleImage.ViewportOrigin;
                Size  viewLogicalSize = new Size(map.MultiScaleImage.ViewportWidth,
                                                 map.MultiScaleImage.ViewportWidth * map.MultiScaleImage.ActualHeight / map.MultiScaleImage.ActualWidth);

                double pixelFactorX = viewLogicalSize.Width / map.MultiScaleImage.ActualWidth;
                double pixelFactorY = viewLogicalSize.Height / map.MultiScaleImage.ActualHeight;
                Point  logical      = new Point((pixelCenter.X * pixelFactorX) + offset.X, (pixelCenter.Y * pixelFactorY) + offset.Y);
                map.Center = coordinateService.LogicalToGeographic(logical);
            }
            break;

            case MouseDragBehavior.Select:
            {
                map.MouseControl.SelectBoxLocation = new Point(Math.Min(origin.X, point.X), Math.Min(origin.Y, point.Y));
                var newSize = new Size(Math.Abs(origin.X - point.X), Math.Abs(origin.Y - point.Y));
                map.MouseControl.SelectBoxSize = newSize;
            }
            break;
            }
        }
Example #2
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;
        }
        /// <summary>
        /// Arrange item in canvas.
        /// </summary>
        /// <param name="item">Item to arrange.</param>
        internal void ArrangeItem(UIElement element)
        {
            MapCanvasItem item = null;

            this.internalItems.TryGetValue(element.GetHashCode(), out item);

            if (item != null)
            {
                Location location = MapLayer.GetLocation(element);
                if (location.IsEmpty)
                {
                    return;
                }

                ICoordinateService coordinateService = CoordinateServiceProvider.GetService(this.Map);
                Point pixel = coordinateService.GeographicToPixel(location);
                this.SetItemPosition(item, pixel);
            }
        }