Beispiel #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 = MapProjection.LocationToPoint(Center),
                        To   = MapProjection.LocationToPoint(new Location(
                                                                 targetCenter.Latitude,
                                                                 Location.NearestLongitude(targetCenter.Longitude, Center.Longitude))),
                        Duration       = AnimationDuration,
                        EasingFunction = AnimationEasingFunction
                    };

                    centerAnimation.Completed += CenterAnimationCompleted;
                    this.BeginAnimation(CenterPointProperty, centerAnimation);
                }
            }
        }
Beispiel #2
0
        private void TargetCenterPropertyChanged(Location targetCenter)
        {
            if (!internalPropertyChange)
            {
                AdjustCenterProperty(TargetCenterProperty, ref targetCenter);

                if (!targetCenter.Equals(Center))
                {
                    var targetCenterLongitude = MapProjection.IsNormalCylindrical
                        ? Location.NearestLongitude(targetCenter.Longitude, Center.Longitude)
                        : targetCenter.Longitude;

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

                    centerAnimation = new PointAnimation
                    {
                        From           = new Point(Center.Longitude, Center.Latitude),
                        To             = new Point(targetCenterLongitude, targetCenter.Latitude),
                        Duration       = AnimationDuration,
                        EasingFunction = AnimationEasingFunction
                    };

                    centerAnimation.Completed += CenterAnimationCompleted;

                    this.BeginAnimation(CenterPointProperty, centerAnimation);
                }
            }
        }
        private static Point ArrangeElementWithLocation(FrameworkElement element, MapBase parentMap, Location location)
        {
            var pos  = new Point();
            var rect = new Rect(pos, element.DesiredSize);

            if (parentMap != null)
            {
                var projection = parentMap.MapProjection;
                pos = projection.LocationToViewportPoint(location);

                if (projection.IsNormalCylindrical &&
                    (pos.X < 0d || pos.X > parentMap.RenderSize.Width ||
                     pos.Y < 0d || pos.Y > parentMap.RenderSize.Height))
                {
                    pos = projection.LocationToViewportPoint(new Location(
                                                                 location.Latitude,
                                                                 Location.NearestLongitude(location.Longitude, parentMap.Center.Longitude)));
                }

                rect.X = pos.X;
                rect.Y = pos.Y;
            }

            switch (element.HorizontalAlignment)
            {
            case HorizontalAlignment.Center:
                rect.X -= rect.Width / 2d;
                break;

            case HorizontalAlignment.Right:
                rect.X -= rect.Width;
                break;

            default:
                break;
            }

            switch (element.VerticalAlignment)
            {
            case VerticalAlignment.Center:
                rect.Y -= rect.Height / 2d;
                break;

            case VerticalAlignment.Bottom:
                rect.Y -= rect.Height;
                break;

            default:
                break;
            }

            if (element.UseLayoutRounding)
            {
                rect.X = Math.Round(rect.X);
                rect.Y = Math.Round(rect.Y);
            }

            element.Arrange(rect);
            return(pos);
        }
Beispiel #4
0
        private static void SetBoundingBoxRect(UIElement element, MapBase parentMap, BoundingBox boundingBox)
        {
            var rotation         = 0d;
            var viewportPosition = new Point();

            if (parentMap != null && boundingBox != null)
            {
                var projection = parentMap.MapProjection;
                var rect       = projection.BoundingBoxToRect(boundingBox);
                var center     = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d);

                rotation         = parentMap.Heading;
                viewportPosition = projection.ViewportTransform.Transform(center);

                if (viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width ||
                    viewportPosition.Y < 0d || viewportPosition.Y > parentMap.RenderSize.Height)
                {
                    var location = projection.PointToLocation(center);
                    location.Longitude = Location.NearestLongitude(location.Longitude, parentMap.Center.Longitude);

                    viewportPosition = projection.LocationToViewportPoint(location);
                }

                var width  = rect.Width * projection.ViewportScale;
                var height = rect.Height * projection.ViewportScale;

                if (element is FrameworkElement)
                {
                    ((FrameworkElement)element).Width  = width;
                    ((FrameworkElement)element).Height = height;
                }
                else
                {
                    element.Arrange(new Rect(-width / 2d, -height / 2d, width, height)); // ???
                }
            }

            var                transformGroup = element.RenderTransform as TransformGroup;
            RotateTransform    rotateTransform;
            TranslateTransform translateTransform;

            if (transformGroup == null ||
                transformGroup.Children.Count != 2 ||
                (rotateTransform = transformGroup.Children[0] as RotateTransform) == null ||
                (translateTransform = transformGroup.Children[1] as TranslateTransform) == null)
            {
                transformGroup     = new TransformGroup();
                rotateTransform    = new RotateTransform();
                translateTransform = new TranslateTransform();
                transformGroup.Children.Add(rotateTransform);
                transformGroup.Children.Add(translateTransform);

                element.RenderTransform       = transformGroup;
                element.RenderTransformOrigin = new Point(0.5, 0.5);
            }

            rotateTransform.Angle = rotation;
            translateTransform.X  = viewportPosition.X;
            translateTransform.Y  = viewportPosition.Y;
        }
Beispiel #5
0
        private static void SetViewportPosition(UIElement element, MapBase parentMap, Location location)
        {
            var viewportPosition = new Point();

            if (parentMap != null && location != null)
            {
                viewportPosition = parentMap.LocationToViewportPoint(location);

                if (viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width ||
                    viewportPosition.Y < 0d || viewportPosition.Y > parentMap.RenderSize.Height)
                {
                    viewportPosition = parentMap.LocationToViewportPoint(new Location(
                                                                             location.Latitude,
                                                                             Location.NearestLongitude(location.Longitude, parentMap.Center.Longitude)));
                }

                if ((bool)element.GetValue(UseLayoutRoundingProperty))
                {
                    viewportPosition.X = Math.Round(viewportPosition.X);
                    viewportPosition.Y = Math.Round(viewportPosition.Y);
                }
            }

            var translateTransform = GetTranslateTransform(element);

            translateTransform.X = viewportPosition.X;
            translateTransform.Y = viewportPosition.Y;
        }
Beispiel #6
0
        protected virtual void OnViewportChanged(ViewportChangedEventArgs e)
        {
            double longitudeScale = parentMap.MapProjection.LongitudeScale;

            if (e.ProjectionChanged)
            {
                viewportTransform.Children[1] = parentMap.MapProjection.ViewportTransform;
            }

            if (e.ProjectionChanged || double.IsNaN(longitudeScale))
            {
                UpdateData();
            }

            if (!double.IsNaN(longitudeScale)) // a normal cylindrical projection
            {
                var longitudeOffset = 0d;

                if (Location != null)
                {
                    var viewportPosition = parentMap.MapProjection.LocationToViewportPoint(Location);

                    if (viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width ||
                        viewportPosition.Y < 0d || viewportPosition.Y > parentMap.RenderSize.Height)
                    {
                        var nearestLongitude = Location.NearestLongitude(Location.Longitude, parentMap.Center.Longitude);

                        longitudeOffset = longitudeScale * (nearestLongitude - Location.Longitude);
                    }
                }

                ((TranslateTransform)viewportTransform.Children[0]).X = longitudeOffset;
            }
        }
        private static void ArrangeElementWithBoundingBox(FrameworkElement element, MapBase parentMap, BoundingBox boundingBox)
        {
            var rect     = new Rect();
            var rotation = 0d;

            if (parentMap != null)
            {
                var projection = parentMap.MapProjection;
                rect = projection.BoundingBoxToRect(boundingBox);

                var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d);
                var pos    = projection.ViewportTransform.Transform(center);

                if (projection.IsNormalCylindrical &&
                    (pos.X < 0d || pos.X > parentMap.RenderSize.Width ||
                     pos.Y < 0d || pos.Y > parentMap.RenderSize.Height))
                {
                    var location = projection.PointToLocation(center);
                    location.Longitude = Location.NearestLongitude(location.Longitude, parentMap.Center.Longitude);

                    pos = projection.LocationToViewportPoint(location);
                }

                rect.Width  *= projection.ViewportScale;
                rect.Height *= projection.ViewportScale;
                rect.X       = pos.X - rect.Width / 2d;
                rect.Y       = pos.Y - rect.Height / 2d;

                if (element.UseLayoutRounding)
                {
                    rect.X = Math.Round(rect.X);
                    rect.Y = Math.Round(rect.Y);
                }

                rotation = parentMap.Heading;
            }

            element.Width  = rect.Width;
            element.Height = rect.Height;
            element.Arrange(rect);

            var rotateTransform = element.RenderTransform as RotateTransform;

            if (rotateTransform != null)
            {
                rotateTransform.Angle = rotation;
            }
            else if (rotation != 0d)
            {
                rotateTransform = new RotateTransform {
                    Angle = rotation
                };
                element.RenderTransform       = rotateTransform;
                element.RenderTransformOrigin = new Point(0.5, 0.5);
            }
        }
Beispiel #8
0
        private void OnViewportChanged(object sender, EventArgs e)
        {
            var viewportPosition = parentMap.LocationToViewportPoint(Location);
            var longitudeOffset  = 0d;

            if (viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width ||
                viewportPosition.Y < 0d || viewportPosition.Y > parentMap.RenderSize.Height)
            {
                longitudeOffset = Location.NearestLongitude(Location.Longitude, parentMap.Center.Longitude) - Location.Longitude;
            }

            ((TranslateTransform)viewportTransform.Children[0]).X = longitudeOffset;
        }
Beispiel #9
0
        private void LocationOrViewportChanged()
        {
            longitudeOffset = 0d;

            if (parentMap != null && parentMap.MapProjection.IsNormalCylindrical && Location != null)
            {
                var viewPos = LocationToView(Location);

                if (viewPos.X < 0d || viewPos.X > parentMap.RenderSize.Width ||
                    viewPos.Y < 0d || viewPos.Y > parentMap.RenderSize.Height)
                {
                    longitudeOffset = Location.NearestLongitude(Location.Longitude, parentMap.Center.Longitude) - Location.Longitude;
                }
            }

            UpdateData();
        }
        protected double GetLongitudeOffset()
        {
            var longitudeOffset = 0d;

            if (parentMap.MapProjection.IsContinuous && Location != null)
            {
                var viewportPosition = LocationToViewportPoint(Location);

                if (viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width ||
                    viewportPosition.Y < 0d || viewportPosition.Y > parentMap.RenderSize.Height)
                {
                    var nearestLongitude = Location.NearestLongitude(Location.Longitude, parentMap.Center.Longitude);

                    longitudeOffset = nearestLongitude - Location.Longitude;
                }
            }

            return(longitudeOffset);
        }
Beispiel #11
0
        private static void SetViewportPosition(UIElement element, MapBase parentMap, Location location)
        {
            var viewportPosition = new Point();

            if (parentMap != null && location != null)
            {
                viewportPosition = parentMap.MapProjection.LocationToViewportPoint(location);

                if (parentMap.MapProjection.IsContinuous &&
                    (viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width ||
                     viewportPosition.Y < 0d || viewportPosition.Y > parentMap.RenderSize.Height))
                {
                    viewportPosition = parentMap.MapProjection.LocationToViewportPoint(new Location(
                                                                                           location.Latitude,
                                                                                           Location.NearestLongitude(location.Longitude, parentMap.Center.Longitude)));
                }

                if ((bool)element.GetValue(UseLayoutRoundingProperty))
                {
                    viewportPosition.X = Math.Round(viewportPosition.X);
                    viewportPosition.Y = Math.Round(viewportPosition.Y);
                }
            }

            var translateTransform = element.RenderTransform as TranslateTransform;

            if (translateTransform == null)
            {
                var transformGroup = element.RenderTransform as TransformGroup;

                if (transformGroup == null)
                {
                    translateTransform      = new TranslateTransform();
                    element.RenderTransform = translateTransform;
                }
                else
                {
                    if (transformGroup.Children.Count > 0)
                    {
                        translateTransform = transformGroup.Children[transformGroup.Children.Count - 1] as TranslateTransform;
                    }

                    if (translateTransform == null)
                    {
                        translateTransform = new TranslateTransform();
                        transformGroup.Children.Add(translateTransform);
                    }
                }
            }

            translateTransform.X = viewportPosition.X;
            translateTransform.Y = viewportPosition.Y;
        }