コード例 #1
0
 /// <summary>
 /// Event handler for the StylusDown event. Implements a zoom operation for a double tap.
 /// </summary>
 /// <param name="sender">Sender of the StylusDown event.</param>
 /// <param name="e">Event parameters.</param>
 void mapView_StylusDown(object sender, StylusDownEventArgs e)
 {
     if (e.TapCount == 2)
     {
         var p = MapView.CanvasToPtvMercator(MapView.GeoCanvas, e.GetPosition(MapView.GeoCanvas));
         MapView.ZoomAround(p, MapView.FinalZoom + 1, Map.UseAnimation);
         e.Handled = true;
     }
 }
コード例 #2
0
        /// <summary> Event handler for scrolling the mouse wheel. Zooms in or out the map depending on the scroll
        /// direction of the mouse wheel. </summary>
        /// <param name="sender"> Sender of the MouseWheel event. </param>
        /// <param name="e"> Event parameters. </param>
        private void source_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            e.Handled = true;

            double oldZoom = mapView.FinalZoom;

            double delta = e.Delta * Map.MouseWheelSpeed / 120;

            if (Map.InvertMouseWheel)
            {
                delta = -delta;
            }

            double newZoom = oldZoom + delta;

            Point p = mapView.CanvasToPtvMercator(mapView.GeoCanvas, e.GetPosition(mapView.GeoCanvas));

            mapView.ZoomAround(p, newZoom, Map.UseAnimation);
        }
コード例 #3
0
ファイル: MapCanvas.cs プロジェクト: kotenev/xserver.net
 /// <inheritdoc/>
 protected override Point CanvasToPtvMercator(Point canvasPoint)
 {
     return(MapView.CanvasToPtvMercator(this, canvasPoint));
 }
コード例 #4
0
        /// <summary> Event handler for pressing the mouse button. A double click with the left mouse button results in
        /// zooming in the map. A double click with the right mouse button results in zooming out the map. Pressing the
        /// left button and the shift key, the zooming rectangle is shown on the map. </summary>
        /// <param name="sender"> Sender of the MouseDown event. </param>
        /// <param name="e"> Event parameters. </param>
        private void source_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (!IsActive)
            {
                return;
            }

            mapView.Focus();

            // NEW: Skip MouseDragMode == None
            if (MouseDragMode == DragMode.None)
            {
                e.Handled = true;
                return;
            }

            if (ZoomOnDoubleClick && e.ClickCount == 2)
            {
                Point p = MapView.CanvasToPtvMercator(MapView.GeoCanvas, e.GetPosition(MapView.GeoCanvas));

                if (e.RightButton == MouseButtonState.Pressed)
                {
                    MapView.ZoomAround(p, MapView.FinalZoom + -1, Map.UseAnimation);

                    e.Handled = true;
                    return;
                }

                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    MapView.ZoomAround(p, MapView.FinalZoom + 1, Map.UseAnimation);

                    e.Handled = true;
                    return;
                }
            }

            // Save starting point, used later when determining how much to scroll.
            ScreenStartPoint = e.GetPosition(mapView);
            WorldStartPoint  = mapView.CanvasToPtvMercator(mapView, e.GetPosition(mapView));

            // NEW: check for MouseDragMode
            if (e.LeftButton == MouseButtonState.Pressed && (MouseDragMode == DragMode.Select ||
                                                             MouseDragMode == DragMode.SelectOnShift && (Keyboard.Modifiers & ModifierKeys.Shift) > 0)) // was && (Keyboard.Modifiers & ModifierKeys.Shift) > 0))
            {
                mapView.Cursor = Cursors.Arrow;

                if (dragRectangle != null)
                {
                    mapView.ForePaneCanvas.Children.Remove(dragRectangle);
                }

                dragRectangle = new Rectangle();
                dragRectangle.IsHitTestVisible = false;
                dragRectangle.Fill             = new SolidColorBrush(Color.FromArgb(0x3e, 0x11, 0x57, 0xdc));
                dragRectangle.Stroke           = new SolidColorBrush(Color.FromArgb(0x55, 0x07, 0x81, 0xf7));
                dragRectangle.StrokeDashArray  = new DoubleCollection(new double[] { 20, 8 });
                dragRectangle.StrokeEndLineCap = PenLineCap.Round;
                dragRectangle.StrokeDashCap    = PenLineCap.Round;
                dragRectangle.StrokeThickness  = 1.5;
                dragRectangle.RadiusX          = 8;
                dragRectangle.RadiusY          = 8;

                Panel.SetZIndex(dragRectangle, 266);
                Canvas.SetLeft(dragRectangle, ScreenStartPoint.X);
                Canvas.SetTop(dragRectangle, ScreenStartPoint.Y);
                mapView.ForePaneCanvas.Children.Add(dragRectangle);
                dragMode = DragMode.Select;
                mapView.CaptureMouse();
            }
            else if (e.LeftButton == MouseButtonState.Pressed && mapView.CaptureMouse())
            {
                mapView.Cursor = Cursors.Hand;
                dragMode       = DragMode.Pan;
                wasPanned      = false;
            }
        }
コード例 #5
0
        /// <summary> Event handler for releasing the mouse button. The map is zoomed to the selected section. </summary>
        /// <param name="sender"> Sender of the MouseUp event. </param>
        /// <param name="e"> Event parameters. </param>
        private void source_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (!IsActive)
            {
                return;
            }

            if (mapView.IsMouseCaptured)
            {
                // we're done.  reset the cursor and release the mouse pointer
                mapView.Cursor = Cursors.Arrow;
                mapView.ReleaseMouseCapture();
            }

            if (dragMode == DragMode.Select)
            {
                mapView.ForePaneCanvas.Children.Remove(dragRectangle);
                dragRectangle = null;

                dragMode = DragMode.None;

                var physicalPoint = e.GetPosition(mapView);

                double minx = physicalPoint.X < ScreenStartPoint.X ? physicalPoint.X : ScreenStartPoint.X;
                double miny = physicalPoint.Y < ScreenStartPoint.Y ? physicalPoint.Y : ScreenStartPoint.Y;
                double maxx = physicalPoint.X > ScreenStartPoint.X ? physicalPoint.X : ScreenStartPoint.X;
                double maxy = physicalPoint.Y > ScreenStartPoint.Y ? physicalPoint.Y : ScreenStartPoint.Y;

                if (Math.Abs(maxx - minx) < 32 && Math.Abs(maxy - miny) < 32)
                {
                    return;
                }

                Point p1 = mapView.TranslatePoint(new Point(minx, miny), mapView.GeoCanvas);
                Point p2 = mapView.TranslatePoint(new Point(maxx, maxy), mapView.GeoCanvas);

                mapView.SetEnvelope(new MapRectangle(
                                        p1.X / MapView.ZoomAdjust * MapView.LogicalSize / MapView.ReferenceSize - 1.0 / MapView.ZoomAdjust * MapView.LogicalSize / 2 - mapView.OriginOffset.X,
                                        p2.X / MapView.ZoomAdjust * MapView.LogicalSize / MapView.ReferenceSize - 1.0 / MapView.ZoomAdjust * MapView.LogicalSize / 2 - mapView.OriginOffset.X,
                                        -(p2.Y / MapView.ZoomAdjust * MapView.LogicalSize / MapView.ReferenceSize) + 1.0 / MapView.ZoomAdjust * MapView.LogicalSize / 2 + mapView.OriginOffset.Y,
                                        -(p1.Y / MapView.ZoomAdjust * MapView.LogicalSize / MapView.ReferenceSize) + 1.0 / MapView.ZoomAdjust * MapView.LogicalSize / 2 + mapView.OriginOffset.Y),
                                    Map.UseAnimation);

                e.Handled = true;
            }
            else if (!MoveWhileDragging)
            {
                mapView.ForePaneCanvas.Children.Remove(dragRectangle);
                dragRectangle = null;

                var physicalPoint = MapView.CanvasToPtvMercator(MapView, e.GetPosition(MapView));

                if (WorldStartPoint.X == physicalPoint.X && WorldStartPoint.Y == physicalPoint.Y)
                {
                    return;
                }

                double x = MapView.CurrentX + WorldStartPoint.X - physicalPoint.X;
                double y = MapView.CurrentY + WorldStartPoint.Y - physicalPoint.Y;

                MapView.SetXYZ(x, y, MapView.CurrentZoom, Map.UseAnimation);
            }


            if (!wasPanned)
            {
                return;
            }

            wasPanned = false;
            e.Handled = true;
        }