Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
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
                    };

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

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

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

                    centerAnimation.Completed += CenterAnimationCompleted;

                    this.BeginAnimation(CenterPointProperty, centerAnimation);
                }
            }
        }
Esempio n. 4
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);
                }
            }
        }
Esempio n. 5
0
        public override Point LocationToMap(Location location)
        {
            if (location.Equals(Center))
            {
                return(new Point());
            }

            GetAzimuthDistance(Center, location, out double azimuth, out double distance);

            var mapDistance = Math.Tan(distance / 2d) * 2d * Wgs84EquatorialRadius;

            return(new Point(mapDistance * Math.Sin(azimuth), mapDistance * Math.Cos(azimuth)));
        }
Esempio n. 6
0
        public override Point LocationToMap(Location location)
        {
            if (location.Equals(Center))
            {
                return(new Point());
            }

            double azimuth, distance;

            GetAzimuthDistance(Center, location, out azimuth, out distance);

            var mapDistance = Math.Tan(distance / 2d) * 2d * UnitsPerDegree * 180d / Math.PI;

            return(new Point(mapDistance * Math.Sin(azimuth), mapDistance * Math.Cos(azimuth)));
        }
Esempio n. 7
0
        public override Point LocationToMap(Location location)
        {
            if (location.Equals(Center))
            {
                return(new Point());
            }

            GetAzimuthDistance(Center, location, out double azimuth, out double distance);

            var mapDistance = distance < Math.PI / 2d
                ? Math.Tan(distance) * Wgs84EquatorialRadius
                : double.PositiveInfinity;

            return(new Point(mapDistance * Math.Sin(azimuth), mapDistance * Math.Cos(azimuth)));
        }
Esempio n. 8
0
        public override Point LocationToPoint(Location location)
        {
            if (location.Equals(ProjectionCenter))
            {
                return(new Point());
            }

            double azimuth, distance;

            GetAzimuthDistance(ProjectionCenter, location, out azimuth, out distance);

            distance *= TrueScale * 180d / Math.PI;

            return(new Point(distance * Math.Sin(azimuth), distance * Math.Cos(azimuth)));
        }
        public override Point LocationToMap(Location location)
        {
            if (location.Equals(Center))
            {
                return(new Point());
            }

            var lat0 = Center.Latitude * Math.PI / 180d;
            var lat  = location.Latitude * Math.PI / 180d;
            var dLon = (location.Longitude - Center.Longitude) * Math.PI / 180d;

            return(new Point(
                       Wgs84EquatorialRadius * Math.Cos(lat) * Math.Sin(dLon),
                       Wgs84EquatorialRadius * (Math.Cos(lat0) * Math.Sin(lat) - Math.Sin(lat0) * Math.Cos(lat) * Math.Cos(dLon))));
        }
Esempio n. 10
0
        public override Point LocationToPoint(Location location)
        {
            if (location.Equals(ProjectionCenter))
            {
                return(new Point());
            }

            double azimuth, distance;

            GetAzimuthDistance(ProjectionCenter, location, out azimuth, out distance);

            distance *= Wgs84EquatorialRadius;

            return(new Point(distance * Math.Sin(azimuth), distance * Math.Cos(azimuth)));
        }
Esempio n. 11
0
        public override Point LocationToPoint(Location location)
        {
            if (location.Equals(projectionCenter))
            {
                return(new Point());
            }

            double azimuth, distance;

            GetAzimuthDistance(projectionCenter, location, out azimuth, out distance);

            var mapDistance = 2d * Wgs84EquatorialRadius * Math.Tan(distance / 2d);

            return(new Point(mapDistance * Math.Sin(azimuth), mapDistance * Math.Cos(azimuth)));
        }
        public override Point LocationToPoint(Location location)
        {
            if (location.Equals(ProjectionCenter))
            {
                return(new Point());
            }

            var lat0 = ProjectionCenter.Latitude * Math.PI / 180d;
            var lat  = location.Latitude * Math.PI / 180d;
            var dLon = (location.Longitude - ProjectionCenter.Longitude) * Math.PI / 180d;
            var s    = TrueScale * 180d / Math.PI;

            return(new Point(
                       s * Math.Cos(lat) * Math.Sin(dLon),
                       s * (Math.Cos(lat0) * Math.Sin(lat) - Math.Sin(lat0) * Math.Cos(lat) * Math.Cos(dLon))));
        }
        public override Point LocationToMap(Location location)
        {
            if (location.Equals(Center))
            {
                return(new Point());
            }

            var lat0 = Center.Latitude * Math.PI / 180d;
            var lat  = location.Latitude * Math.PI / 180d;
            var dLon = (location.Longitude - Center.Longitude) * Math.PI / 180d;
            var s    = UnitsPerDegree * 180d / Math.PI;

            return(new Point(
                       s * Math.Cos(lat) * Math.Sin(dLon),
                       s * (Math.Cos(lat0) * Math.Sin(lat) - Math.Sin(lat0) * Math.Cos(lat) * Math.Cos(dLon))));
        }
        public override Point LocationToPoint(Location location)
        {
            if (location.Equals(ProjectionCenter))
            {
                return(new Point());
            }

            double azimuth, distance;

            GetAzimuthDistance(ProjectionCenter, location, out azimuth, out distance);

            var mapDistance = distance < Math.PI / 2d
                ? Math.Tan(distance) * TrueScale * 180d / Math.PI
                : double.PositiveInfinity;

            return(new Point(mapDistance * Math.Sin(azimuth), mapDistance * Math.Cos(azimuth)));
        }
Esempio n. 15
0
        protected override void OnViewportChanged(ViewportChangedEventArgs e)
        {
            if (path == null)
            {
                path = new Path
                {
                    Data = new PathGeometry()
                };

                path.SetBinding(Shape.StrokeProperty,
                                GetBindingExpression(StrokeProperty)?.ParentBinding ??
                                new Binding
                {
                    Source = this,
                    Path   = new PropertyPath("Stroke")
                });

                path.SetBinding(Shape.StrokeThicknessProperty,
                                GetBindingExpression(StrokeThicknessProperty)?.ParentBinding ??
                                new Binding
                {
                    Source = this,
                    Path   = new PropertyPath("StrokeThickness")
                });

                Children.Add(path);
            }

            var bounds       = ParentMap.ViewportTransform.Inverse.TransformBounds(new Rect(new Point(), ParentMap.RenderSize));
            var start        = ParentMap.MapTransform.Transform(new Point(bounds.X, bounds.Y));
            var end          = ParentMap.MapTransform.Transform(new Point(bounds.X + bounds.Width, bounds.Y + bounds.Height));
            var lineDistance = GetLineDistance();

            var labelStart = new Location(
                Math.Ceiling(start.Latitude / lineDistance) * lineDistance,
                Math.Ceiling(start.Longitude / lineDistance) * lineDistance);

            var labelEnd = new Location(
                Math.Floor(end.Latitude / lineDistance) * lineDistance,
                Math.Floor(end.Longitude / lineDistance) * lineDistance);

            var lineStart = new Location(
                Math.Min(Math.Max(labelStart.Latitude - lineDistance, -ParentMap.MapTransform.MaxLatitude), ParentMap.MapTransform.MaxLatitude),
                labelStart.Longitude - lineDistance);

            var lineEnd = new Location(
                Math.Min(Math.Max(labelEnd.Latitude + lineDistance, -ParentMap.MapTransform.MaxLatitude), ParentMap.MapTransform.MaxLatitude),
                labelEnd.Longitude + lineDistance);

            if (!lineStart.Equals(graticuleStart) || !lineEnd.Equals(graticuleEnd))
            {
                graticuleStart = lineStart;
                graticuleEnd   = lineEnd;

                var geometry = (PathGeometry)path.Data;
                geometry.Figures.Clear();
                geometry.Transform = ParentMap.ViewportTransform;

                for (var lat = labelStart.Latitude; lat <= end.Latitude; lat += lineDistance)
                {
                    var figure = new PathFigure
                    {
                        StartPoint = ParentMap.MapTransform.Transform(new Location(lat, lineStart.Longitude)),
                        IsClosed   = false,
                        IsFilled   = false
                    };

                    figure.Segments.Add(new LineSegment
                    {
                        Point = ParentMap.MapTransform.Transform(new Location(lat, lineEnd.Longitude)),
                    });

                    geometry.Figures.Add(figure);
                }

                for (var lon = labelStart.Longitude; lon <= end.Longitude; lon += lineDistance)
                {
                    var figure = new PathFigure
                    {
                        StartPoint = ParentMap.MapTransform.Transform(new Location(lineStart.Latitude, lon)),
                        IsClosed   = false,
                        IsFilled   = false
                    };

                    figure.Segments.Add(new LineSegment
                    {
                        Point = ParentMap.MapTransform.Transform(new Location(lineEnd.Latitude, lon)),
                    });

                    geometry.Figures.Add(figure);
                }

                var labelFormat = GetLabelFormat(lineDistance);
                var childIndex  = 1; // 0 for Path

                for (var lat = labelStart.Latitude; lat <= end.Latitude; lat += lineDistance)
                {
                    for (var lon = labelStart.Longitude; lon <= end.Longitude; lon += lineDistance)
                    {
                        TextBlock label;

                        if (childIndex < Children.Count)
                        {
                            label = (TextBlock)Children[childIndex];
                        }
                        else
                        {
                            var renderTransform = new TransformGroup();
                            renderTransform.Children.Add(new TranslateTransform());
                            renderTransform.Children.Add(ParentMap.RotateTransform);
                            renderTransform.Children.Add(new TranslateTransform());

                            label = new TextBlock
                            {
                                RenderTransform = renderTransform
                            };

                            label.SetBinding(TextBlock.ForegroundProperty,
                                             GetBindingExpression(ForegroundProperty)?.ParentBinding ??
                                             new Binding
                            {
                                Source = this,
                                Path   = new PropertyPath("Foreground")
                            });

                            Children.Add(label);
                        }

                        childIndex++;

                        if (FontFamily != null)
                        {
                            label.FontFamily = FontFamily;
                        }

                        label.FontSize    = FontSize;
                        label.FontStyle   = FontStyle;
                        label.FontStretch = FontStretch;
                        label.FontWeight  = FontWeight;
                        label.Text        = GetLabelText(lat, labelFormat, "NS") + "\n" + GetLabelText(Location.NormalizeLongitude(lon), labelFormat, "EW");
                        label.Tag         = new Location(lat, lon);
                        label.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

                        var translateTransform = (TranslateTransform)((TransformGroup)label.RenderTransform).Children[0];
                        translateTransform.X = StrokeThickness / 2d + 2d;
                        translateTransform.Y = -label.DesiredSize.Height / 2d;
                    }
                }

                while (Children.Count > childIndex)
                {
                    Children.RemoveAt(Children.Count - 1);
                }
            }

            // don't use MapPanel.Location because labels may be at more than 180° distance from map center

            for (int i = 1; i < Children.Count; i++)
            {
                var label             = (TextBlock)Children[i];
                var location          = (Location)label.Tag;
                var viewportTransform = (TranslateTransform)((TransformGroup)label.RenderTransform).Children[2];
                var viewportPosition  = ParentMap.LocationToViewportPoint(location);
                viewportTransform.X = viewportPosition.X;
                viewportTransform.Y = viewportPosition.Y;
            }

            base.OnViewportChanged(e);
        }
        protected override void OnViewportChanged()
        {
            var bounds     = ParentMap.ViewportTransform.Inverse.TransformBounds(new Rect(new Point(), ParentMap.RenderSize));
            var start      = ParentMap.MapTransform.Transform(new Point(bounds.X, bounds.Y));
            var end        = ParentMap.MapTransform.Transform(new Point(bounds.X + bounds.Width, bounds.Y + bounds.Height));
            var minSpacing = MinLineSpacing * 360d / (Math.Pow(2d, ParentMap.ZoomLevel) * 256d);
            var spacing    = LineSpacings[LineSpacings.Length - 1];

            if (spacing >= minSpacing)
            {
                spacing = LineSpacings.FirstOrDefault(s => s >= minSpacing);
            }

            var labelStart = new Location(
                Math.Ceiling(start.Latitude / spacing) * spacing,
                Math.Ceiling(start.Longitude / spacing) * spacing);

            var labelEnd = new Location(
                Math.Floor(end.Latitude / spacing) * spacing,
                Math.Floor(end.Longitude / spacing) * spacing);

            var lineStart = new Location(
                Math.Min(Math.Max(labelStart.Latitude - spacing, -ParentMap.MapTransform.MaxLatitude), ParentMap.MapTransform.MaxLatitude),
                labelStart.Longitude - spacing);

            var lineEnd = new Location(
                Math.Min(Math.Max(labelEnd.Latitude + spacing, -ParentMap.MapTransform.MaxLatitude), ParentMap.MapTransform.MaxLatitude),
                labelEnd.Longitude + spacing);

            if (!lineStart.Equals(graticuleStart) || !lineEnd.Equals(graticuleEnd))
            {
                graticuleStart = lineStart;
                graticuleEnd   = lineEnd;

                var geometry = (PathGeometry)path.Data;
                geometry.Figures.Clear();
                geometry.Transform = ParentMap.ViewportTransform;

                for (var lat = labelStart.Latitude; lat <= end.Latitude; lat += spacing)
                {
                    var figure = new PathFigure
                    {
                        StartPoint = ParentMap.MapTransform.Transform(new Location(lat, lineStart.Longitude)),
                        IsClosed   = false,
                        IsFilled   = false
                    };

                    figure.Segments.Add(new LineSegment
                    {
                        Point = ParentMap.MapTransform.Transform(new Location(lat, lineEnd.Longitude)),
                    });

                    geometry.Figures.Add(figure);
                }

                for (var lon = labelStart.Longitude; lon <= end.Longitude; lon += spacing)
                {
                    var figure = new PathFigure
                    {
                        StartPoint = ParentMap.MapTransform.Transform(new Location(lineStart.Latitude, lon)),
                        IsClosed   = false,
                        IsFilled   = false
                    };

                    figure.Segments.Add(new LineSegment
                    {
                        Point = ParentMap.MapTransform.Transform(new Location(lineEnd.Latitude, lon)),
                    });

                    geometry.Figures.Add(figure);
                }

                var childIndex = 1; // 0 for Path
                var format     = spacing < 1d ? "{0} {1}°{2:00}'" : "{0} {1}°";

                for (var lat = labelStart.Latitude; lat <= end.Latitude; lat += spacing)
                {
                    for (var lon = labelStart.Longitude; lon <= end.Longitude; lon += spacing)
                    {
                        TextBlock label;

                        if (childIndex < Children.Count)
                        {
                            label = (TextBlock)Children[childIndex];
                        }
                        else
                        {
                            var renderTransform = new TransformGroup();
                            renderTransform.Children.Add(new TranslateTransform());
                            renderTransform.Children.Add(ParentMap.RotateTransform);
                            renderTransform.Children.Add(new TranslateTransform());

                            label = new TextBlock
                            {
                                RenderTransform = renderTransform
                            };

                            label.SetBinding(TextBlock.ForegroundProperty, new Binding
                            {
                                Source = this,
                                Path   = new PropertyPath("Foreground")
                            });

                            Children.Add(label);
                        }

                        childIndex++;

                        if (FontFamily != null)
                        {
                            label.FontFamily = FontFamily;
                        }

                        label.FontSize    = FontSize;
                        label.FontStyle   = FontStyle;
                        label.FontStretch = FontStretch;
                        label.FontWeight  = FontWeight;
                        label.Text        = string.Format("{0}\n{1}", CoordinateString(lat, format, "NS"), CoordinateString(Location.NormalizeLongitude(lon), format, "EW"));
                        label.Tag         = new Location(lat, lon);
                        label.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

                        var translateTransform = (TranslateTransform)((TransformGroup)label.RenderTransform).Children[0];
                        translateTransform.X = StrokeThickness / 2d + 2d;
                        translateTransform.Y = -label.DesiredSize.Height / 2d;
                    }
                }

                while (Children.Count > childIndex)
                {
                    Children.RemoveAt(Children.Count - 1);
                }
            }

            // don't use MapPanel.Location because labels may be at more than 180° distance from map center

            for (int i = 1; i < Children.Count; i++)
            {
                var label             = (TextBlock)Children[i];
                var location          = (Location)label.Tag;
                var viewportTransform = (TranslateTransform)((TransformGroup)label.RenderTransform).Children[2];
                var viewportPosition  = ParentMap.LocationToViewportPoint(location);
                viewportTransform.X = viewportPosition.X;
                viewportTransform.Y = viewportPosition.Y;
            }

            base.OnViewportChanged();
        }