public void MapView_Touch(object sender, TouchEventArgs args) { if (_gestureDetector.OnTouchEvent(args.Event)) { return; } var touchPoints = GetMapPositions(args.Event, this); switch (args.Event.Action) { case MotionEventActions.Up: _canvas.Invalidate(); _mode = None; _map.ViewChanged(true); break; case MotionEventActions.Down: case MotionEventActions.Pointer1Down: case MotionEventActions.Pointer2Down: case MotionEventActions.Pointer3Down: if (touchPoints.Count >= 2) { (_previousCenter, _previousRadius, _previousAngle) = GetPinchValues(touchPoints); _mode = Zoom; _innerRotation = _map.Viewport.Rotation; } else { _mode = Dragging; _previousCenter = touchPoints.First(); } break; case MotionEventActions.Pointer1Up: case MotionEventActions.Pointer2Up: case MotionEventActions.Pointer3Up: // Remove the touchPoint that was released from the locations to reset the // starting points of the move and rotation touchPoints.RemoveAt(args.Event.ActionIndex); if (touchPoints.Count >= 2) { (_previousCenter, _previousRadius, _previousAngle) = GetPinchValues(touchPoints); _mode = Zoom; _innerRotation = _map.Viewport.Rotation; } else { _mode = Dragging; _previousCenter = touchPoints.First(); } break; case MotionEventActions.Move: switch (_mode) { case Dragging: { if (touchPoints.Count != 1) { return; } var touchPosition = touchPoints.First(); if (_previousCenter != null && !_previousCenter.IsEmpty()) { _map.Viewport.Transform(touchPosition.X, touchPosition.Y, _previousCenter.X, _previousCenter.Y); ViewportLimiter.LimitExtent(_map.Viewport, _map.PanMode, _map.PanLimits, _map.Envelope); _canvas.Invalidate(); } _previousCenter = touchPosition; } break; case Zoom: { if (touchPoints.Count < 2) { return; } var(prevCenter, prevRadius, prevAngle) = (_previousCenter, _previousRadius, _previousAngle); var(center, radius, angle) = GetPinchValues(touchPoints); double rotationDelta = 0; if (AllowPinchRotation) { _innerRotation += angle - prevAngle; _innerRotation %= 360; if (_innerRotation > 180) { _innerRotation -= 360; } else if (_innerRotation < -180) { _innerRotation += 360; } if (_map.Viewport.Rotation == 0 && Math.Abs(_innerRotation) >= Math.Abs(UnSnapRotationDegrees)) { rotationDelta = _innerRotation; } else if (_map.Viewport.Rotation != 0) { if (Math.Abs(_innerRotation) <= Math.Abs(ReSnapRotationDegrees)) { rotationDelta = -_map.Viewport.Rotation; } else { rotationDelta = _innerRotation - _map.Viewport.Rotation; } } } _map.Viewport.Transform(center.X, center.Y, prevCenter.X, prevCenter.Y, radius / prevRadius, rotationDelta); (_previousCenter, _previousRadius, _previousAngle) = (center, radius, angle); ViewportLimiter.Limit(_map.Viewport, _map.ZoomMode, _map.ZoomLimits, _map.Resolutions, _map.PanMode, _map.PanLimits, _map.Envelope); _canvas.Invalidate(); } break; } break; } }
/// <summary> /// Called, when mouse/finger/pen moves over map /// </summary> /// <param name="touchPoints">List of all touched points</param> private bool OnTouchMove(List <Geometries.Point> touchPoints) { var args = new TouchedEventArgs(touchPoints); TouchMove?.Invoke(this, args); if (args.Handled) { return(true); } switch (_mode) { case TouchMode.Dragging: { if (touchPoints.Count != 1) { return(false); } var touchPosition = touchPoints.First(); if (!Map.PanLock && _previousCenter != null && !_previousCenter.IsEmpty()) { _viewport.Transform(touchPosition, _previousCenter); RefreshGraphics(); } _previousCenter = touchPosition; } break; case TouchMode.Zooming: { if (touchPoints.Count != 2) { return(false); } var(prevCenter, prevRadius, prevAngle) = (_previousCenter, _previousRadius, _previousAngle); var(center, radius, angle) = GetPinchValues(touchPoints); double rotationDelta = 0; if (!Map.RotationLock) { _innerRotation += angle - prevAngle; _innerRotation %= 360; if (_innerRotation > 180) { _innerRotation -= 360; } else if (_innerRotation < -180) { _innerRotation += 360; } if (Viewport.Rotation == 0 && Math.Abs(_innerRotation) >= Math.Abs(UnSnapRotationDegrees)) { rotationDelta = _innerRotation; } else if (Viewport.Rotation != 0) { if (Math.Abs(_innerRotation) <= Math.Abs(ReSnapRotationDegrees)) { rotationDelta = -Viewport.Rotation; } else { rotationDelta = _innerRotation - Viewport.Rotation; } } } _viewport.Transform(center, prevCenter, Map.ZoomLock ? 1 : radius / prevRadius, rotationDelta); (_previousCenter, _previousRadius, _previousAngle) = (center, radius, angle); RefreshGraphics(); } break; } return(true); }
/// <summary> /// Called, when mouse/finger/pen moves over map /// </summary> /// <param name="touchPoints">List of all touched points</param> private bool OnTouchMove(List <Geometries.Point> touchPoints) { var args = new TouchedEventArgs(touchPoints); TouchMove?.Invoke(this, args); if (args.Handled) { return(true); } switch (_mode) { case TouchMode.Dragging: { if (touchPoints.Count != 1) { return(false); } var touchPosition = touchPoints.First(); if (_previousCenter != null && !_previousCenter.IsEmpty()) { _map.Viewport.Transform(touchPosition.X, touchPosition.Y, _previousCenter.X, _previousCenter.Y); ViewportLimiter.LimitExtent(_map.Viewport, _map.PanMode, _map.PanLimits, _map.Envelope); InvalidateCanvas(); } _previousCenter = touchPosition; } break; case TouchMode.Zooming: { if (touchPoints.Count < 2) { return(false); } var(prevCenter, prevRadius, prevAngle) = (_previousCenter, _previousRadius, _previousAngle); var(center, radius, angle) = GetPinchValues(touchPoints); double rotationDelta = 0; if (RotationLock) { _innerRotation += angle - prevAngle; _innerRotation %= 360; if (_innerRotation > 180) { _innerRotation -= 360; } else if (_innerRotation < -180) { _innerRotation += 360; } if (_map.Viewport.Rotation == 0 && Math.Abs(_innerRotation) >= Math.Abs(UnSnapRotationDegrees)) { rotationDelta = _innerRotation; } else if (_map.Viewport.Rotation != 0) { if (Math.Abs(_innerRotation) <= Math.Abs(ReSnapRotationDegrees)) { rotationDelta = -_map.Viewport.Rotation; } else { rotationDelta = _innerRotation - _map.Viewport.Rotation; } } } _map.Viewport.Transform(center.X, center.Y, prevCenter.X, prevCenter.Y, radius / prevRadius, rotationDelta); (_previousCenter, _previousRadius, _previousAngle) = (center, radius, angle); ViewportLimiter.Limit(_map.Viewport, _map.ZoomMode, _map.ZoomLimits, _map.Resolutions, _map.PanMode, _map.PanLimits, _map.Envelope); InvalidateCanvas(); } break; } return(true); }