/// <summary> /// Calculates the ViewPortTransfrom for the Current Heading and ViewPortCenter. /// Invalidates the ViewPort to schedule a redraw. /// </summary> protected virtual void UpdateViewPortTransform() { if (ViewPortTransform == null) { return; } double scaleFactor = ViewPortProjection.GetZoomFactor(ZoomLevel); double w2 = ActualWidth / 2d; double h2 = ActualHeight / 2d; MatrixDouble vpCenterTranslation = MatrixDouble.CreateTranslation(w2, h2); MatrixDouble scale = MatrixDouble.CreateScale(scaleFactor); MatrixDouble mapCenterTranslation = MatrixDouble.CreateTranslation(-ViewPortCenter.X, -ViewPortCenter.Y); double heading = Heading * Math.PI / 180.0; Point center = new Point(ViewPortCenter.X, ViewPortCenter.Y); MatrixDouble mapRotation = MatrixDouble.CreateRotation(heading, center); MatrixDouble objectRotation = MatrixDouble.CreateRotation(heading); ViewPortTransform.Matrix = (mapRotation * mapCenterTranslation * scale * vpCenterTranslation).ToXamlMatrix(); ScaleRotateTransform.Matrix = (objectRotation * scale).ToXamlMatrix(); ScaleTransform.Matrix = scale.ToXamlMatrix(); RotateTransform.Matrix = objectRotation.ToXamlMatrix(); TranslationTransform.Matrix = (mapCenterTranslation * vpCenterTranslation).ToXamlMatrix(); InvalidateArrange(); OnViewPortChangedEvent(); }
public CartesianPoint GetCartesianFromPoint(Point point) { double zoomFactor = 1 / ViewPortProjection.GetZoomFactor(ZoomLevel); double x = (point.X - RenderSize.Width / 2d) * zoomFactor + ViewPortCenter.X; double y = (point.Y - RenderSize.Height / 2d) * zoomFactor + ViewPortCenter.Y; MatrixDouble reverseRotationMatrix = MatrixDouble.CreateRotation(-TransformHelper.DegToRad(Heading), ViewPortCenter.ToPoint()); return(new CartesianPoint(reverseRotationMatrix.Transform(new Point(x, y)))); }
private void OnManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e) { _headingBeforeManipulation = _map.Heading; _zoomFactorBeforeManipulation = _map.ViewPortProjection.GetZoomFactor(_map.ZoomLevel); _viewPortCenterBeforeManipulation = _map.ViewPortCenter.ToPoint(); _reverseRotationMatrix = MatrixDouble.CreateRotation(-TransformHelper.DegToRad(_headingBeforeManipulation), _viewPortCenterBeforeManipulation); _manipulationStartPoint = _map.GetCartesianFromPoint(e.Position).ToPoint(); e.Handled = true; }
protected virtual void UpdateManipulation(ManipulationDelta delta) { double newHeading = _headingBeforeManipulation; double newZoomFact = _zoomFactorBeforeManipulation * delta.Scale; MatrixDouble m = MatrixDouble.Identity; if (TranslationEnabled) { m = MatrixDouble.CreateTranslation(-(delta.Translation.X / _zoomFactorBeforeManipulation), -(delta.Translation.Y / _zoomFactorBeforeManipulation)); m = m * _reverseRotationMatrix; } if (ZoomEnabled) { double scaleFactor = _zoomFactorBeforeManipulation / newZoomFact; m = m * MatrixDouble.CreateScale(scaleFactor, _manipulationStartPoint); } if ((delta.Rotation != 0.0) && RotationEnabled) { //Add the Rotation from the Manipulation MatrixDouble rotation = MatrixDouble.CreateRotation(-TransformHelper.DegToRad(delta.Rotation), _manipulationStartPoint); m = m * rotation; newHeading = (_headingBeforeManipulation + delta.Rotation) % 360; if (newHeading < 0) { newHeading += 360; } } double zoomLevel = _map.ViewPortProjection.GetZoomLevel(newZoomFact); CartesianPoint viewPortCenter = new CartesianPoint(m.Transform(_viewPortCenterBeforeManipulation)); if (Update != null) { TouchMapEventArgs eventArgs = new TouchMapEventArgs(); eventArgs.Heading = newHeading; eventArgs.ZoomLevel = zoomLevel; eventArgs.ViewPortCenter = viewPortCenter; OnUpdate(eventArgs); } if (AutoUpdateMap) { _map.Heading = newHeading; _map.ZoomLevel = zoomLevel; _map.ViewPortCenter = viewPortCenter; } }