Example #1
0
        /// <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();
        }
Example #2
0
        protected virtual void UpdateZoomOnlyManipulation(double zoomDelta, Point position)
        {
            Point zoomCenter = _map.GetCartesianFromPoint(position).ToPoint();

            double oldZoomLevel = _map.ZoomLevel;
            double newZoomLevel = oldZoomLevel + zoomDelta;
            double scaleFactor  = 1 / (_map.ViewPortProjection.GetZoomFactor(newZoomLevel) / _map.ViewPortProjection.GetZoomFactor(oldZoomLevel));

            MatrixDouble scale = MatrixDouble.CreateScale(scaleFactor, zoomCenter);

            _map.ViewPortCenter = new CartesianPoint(scale.Transform(_map.ViewPortCenter.ToPoint()));
            _map.ZoomLevel      = newZoomLevel;
        }
Example #3
0
        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;
            }
        }