Example #1
0
        private void TargetCenterPropertyChanged(Location targetCenter)
        {
            if (!internalPropertyChange)
            {
                AdjustCenterProperty(TargetCenterProperty, ref targetCenter);

                if (!targetCenter.Equals(Center))
                {
                    if (centerAnimation != null)
                    {
                        centerAnimation.Completed -= CenterAnimationCompleted;
                    }

                    // animate private CenterPoint property by PointAnimation
                    centerAnimation = new PointAnimation
                    {
                        From           = MapTransform.Transform(Center),
                        To             = MapTransform.Transform(targetCenter, Center.Longitude),
                        Duration       = AnimationDuration,
                        EasingFunction = AnimationEasingFunction,
                        FillBehavior   = FillBehavior.HoldEnd
                    };

                    centerAnimation.Completed += CenterAnimationCompleted;
                    this.BeginAnimation(CenterPointProperty, centerAnimation);
                }
            }
        }
Example #2
0
 private void CenterPointPropertyChanged(Point centerPoint)
 {
     if (!internalPropertyChange)
     {
         centerPoint.X = Location.NormalizeLongitude(centerPoint.X);
         InternalSetValue(CenterProperty, MapTransform.Transform(centerPoint));
         ResetTransformOrigin();
         UpdateTransform();
     }
 }
Example #3
0
        private void CenterAnimationCompleted(object sender, object e)
        {
            if (centerAnimation != null)
            {
                centerAnimation.Completed -= CenterAnimationCompleted;
                centerAnimation            = null;

                InternalSetValue(CenterProperty, TargetCenter);
                InternalSetValue(CenterPointProperty, MapTransform.Transform(TargetCenter));
                RemoveAnimation(CenterPointProperty); // remove holding animation in WPF

                ResetTransformOrigin();
                UpdateTransform();
            }
        }
Example #4
0
        private void CenterPropertyChanged(Location center)
        {
            if (!internalPropertyChange)
            {
                AdjustCenterProperty(CenterProperty, ref center);
                ResetTransformOrigin();
                UpdateTransform();

                if (centerAnimation == null)
                {
                    InternalSetValue(TargetCenterProperty, center);
                    InternalSetValue(CenterPointProperty, MapTransform.Transform(center));
                }
            }
        }
Example #5
0
        /// <summary>
        /// Sets the TargetZoomLevel and TargetCenter properties such that the specified bounding box
        /// fits into the current viewport. The TargetHeading property is set to zero.
        /// </summary>
        public void ZoomToBounds(Location southWest, Location northEast)
        {
            if (southWest.Latitude < northEast.Latitude && southWest.Longitude < northEast.Longitude)
            {
                var p1       = MapTransform.Transform(southWest);
                var p2       = MapTransform.Transform(northEast);
                var lonScale = RenderSize.Width / (p2.X - p1.X) * 360d / TileSource.TileSize;
                var latScale = RenderSize.Height / (p2.Y - p1.Y) * 360d / TileSource.TileSize;
                var lonZoom  = Math.Log(lonScale, 2d);
                var latZoom  = Math.Log(latScale, 2d);

                TargetZoomLevel = Math.Min(lonZoom, latZoom);
                TargetCenter    = MapTransform.Transform(new Point((p1.X + p2.X) / 2d, (p1.Y + p2.Y) / 2d));
                TargetHeading   = 0d;
            }
        }
Example #6
0
        private void UpdateTransform(bool resetTransformOrigin = false)
        {
            var center = Center;

            SetViewportTransform(transformOrigin ?? center);

            if (transformOrigin != null)
            {
                center           = ViewportPointToLocation(new Point(RenderSize.Width / 2d, RenderSize.Height / 2d));
                center.Longitude = Location.NormalizeLongitude(center.Longitude);

                if (center.Latitude < -mapTransform.MaxLatitude || center.Latitude > mapTransform.MaxLatitude)
                {
                    center.Latitude      = Math.Min(Math.Max(center.Latitude, -mapTransform.MaxLatitude), mapTransform.MaxLatitude);
                    resetTransformOrigin = true;
                }

                InternalSetValue(CenterProperty, center);

                if (centerAnimation == null)
                {
                    InternalSetValue(TargetCenterProperty, center);
                    InternalSetValue(CenterPointProperty, MapTransform.Transform(center));
                }

                if (resetTransformOrigin)
                {
                    ResetTransformOrigin();
                    SetViewportTransform(center);
                }
            }

            CenterScale = ViewportScale * mapTransform.RelativeScale(center) / TileSource.MetersPerDegree; // Pixels per meter at center latitude

            SetTransformMatrixes();
            OnViewportChanged();
        }