Esempio n. 1
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;
        }
        protected override void SetParentMap(MapBase parentMap)
        {
            if (GetBindingExpression(ForegroundProperty) != null)
            {
                ClearValue(ForegroundProperty);
            }

            if (GetBindingExpression(StrokeProperty) != null)
            {
                ClearValue(StrokeProperty);
            }

            if (parentMap != null)
            {
                if (Foreground == null)
                {
                    SetBinding(ForegroundProperty, new Binding
                    {
                        Source = parentMap,
                        Path   = new PropertyPath("Foreground")
                    });
                }

                if (Stroke == null)
                {
                    SetBinding(StrokeProperty, new Binding
                    {
                        Source = parentMap,
                        Path   = new PropertyPath("Foreground")
                    });
                }
            }

            base.SetParentMap(parentMap);
        }
Esempio n. 3
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;
        }
        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);
        }
        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);
            }
        }
        protected override void SetParentMap(MapBase map)
        {
            base.SetParentMap(map);

            line.SetBinding(Shape.StrokeProperty, this.GetOrCreateBinding(StrokeProperty, nameof(Stroke)));
            line.SetBinding(Shape.StrokeThicknessProperty, this.GetOrCreateBinding(StrokeThicknessProperty, nameof(StrokeThickness)));

#if WINUI || UWP
            label.SetBinding(TextBlock.ForegroundProperty, this.GetOrCreateBinding(ForegroundProperty, nameof(Foreground)));
#endif
        }
Esempio n. 7
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;
        }
Esempio n. 8
0
        protected override void SetParentMap(MapBase map)
        {
            if (map != null)
            {
                // If this.Forground is not explicitly set, bind it to map.Foreground
                this.SetBindingOnUnsetProperty(ForegroundProperty, map, MapBase.ForegroundProperty, nameof(Foreground));

                // If this.Stroke is not explicitly set, bind it to this.Foreground
                this.SetBindingOnUnsetProperty(StrokeProperty, this, ForegroundProperty, nameof(Foreground));
            }

            base.SetParentMap(map);
        }
        protected override void SetParentMap(MapBase parentMap)
        {
            if (parentMap != null && Foreground == null)
            {
                SetBinding(ForegroundProperty, new Binding
                {
                    Source = parentMap,
                    Path   = new PropertyPath("Foreground")
                });
            }

            base.SetParentMap(parentMap);
        }
Esempio n. 10
0
        protected virtual void SetParentMap(MapBase map)
        {
            if (parentMap != null && parentMap != this)
            {
                parentMap.ViewportChanged -= OnViewportChanged;
            }

            parentMap = map;

            if (parentMap != null && parentMap != this)
            {
                parentMap.ViewportChanged += OnViewportChanged;
                OnViewportChanged(new ViewportChangedEventArgs());
            }
        }
Esempio n. 11
0
        protected virtual void SetParentMapOverride(MapBase map)
        {
            if (parentMap != null && parentMap != this)
            {
                parentMap.ViewportChanged -= OnViewportChanged;
            }

            parentMap = map;

            if (parentMap != null && parentMap != this)
            {
                parentMap.ViewportChanged += OnViewportChanged;
                OnViewportChanged();
            }
        }
Esempio n. 12
0
        private static void SetViewportPosition(UIElement element, MapBase parentMap, Location location)
        {
            var viewportPosition = new Point();

            if (parentMap != null && location != null)
            {
                var mapPosition = parentMap.MapTransform.Transform(location, parentMap.Center.Longitude); // nearest to center longitude

                viewportPosition = parentMap.ViewportTransform.Transform(mapPosition);

                if ((bool)element.GetValue(FrameworkElement.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;
        }
Esempio n. 13
0
        private static MapBase FindParentMap(UIElement element)
        {
            MapBase parentMap     = null;
            var     parentElement = VisualTreeHelper.GetParent(element) as UIElement;

            if (parentElement != null)
            {
                parentMap = parentElement as MapBase;

                if (parentMap == null)
                {
                    parentMap = GetParentMap(parentElement);
                }
            }

            return(parentMap);
        }
Esempio n. 14
0
        private static void SetViewportPosition(UIElement element, MapBase parentMap, Location location)
        {
            Point viewportPosition;

            if (parentMap != null && location != null)
            {
                // keep viewport position near map center
                var mapPosition = parentMap.MapTransform.Transform(location, parentMap.Center.Longitude);
                viewportPosition = parentMap.ViewportTransform.Transform(mapPosition);
                element.SetValue(ViewportPositionProperty, viewportPosition);
            }
            else
            {
                viewportPosition = new Point();
                element.ClearValue(ViewportPositionProperty);
            }

            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;
        }
Esempio n. 15
0
        protected override void SetParentMap(MapBase map)
        {
            if (map != null)
            {
                if (Foreground == null)
                {
                    SetBinding(ForegroundProperty,
                               map.GetBindingExpression(MapBase.ForegroundProperty)?.ParentBinding ??
                               new Binding {
                        Source = map, Path = new PropertyPath("Foreground")
                    });
                }

                if (Stroke == null)
                {
                    SetBinding(StrokeProperty, GetBinding(ForegroundProperty, nameof(Foreground)));
                }
            }

            base.SetParentMap(map);
        }
Esempio n. 16
0
        protected override void SetParentMapOverride(MapBase parentMap)
        {
            if (foregroundBinding != null)
            {
                foregroundBinding = null;
                ClearValue(ForegroundProperty);
            }

            if (strokeBinding != null)
            {
                strokeBinding = null;
                ClearValue(StrokeProperty);
            }

            if (parentMap != null)
            {
                if (Foreground == null)
                {
                    foregroundBinding = new Binding
                    {
                        Source = parentMap,
                        Path   = new PropertyPath("Foreground")
                    };
                    SetBinding(ForegroundProperty, foregroundBinding);
                }

                if (Stroke == null)
                {
                    strokeBinding = new Binding
                    {
                        Source = parentMap,
                        Path   = new PropertyPath("Foreground")
                    };
                    SetBinding(StrokeProperty, strokeBinding);
                }
            }

            base.SetParentMapOverride(parentMap);
        }
        protected override void SetParentMapOverride(MapBase parentMap)
        {
            if (foregroundBinding != null)
            {
                foregroundBinding = null;
                ClearValue(ForegroundProperty);
            }

            if (strokeBinding != null)
            {
                strokeBinding = null;
                ClearValue(StrokeProperty);
            }

            if (parentMap != null)
            {
                if (Foreground == null)
                {
                    foregroundBinding = new Binding
                    {
                        Source = parentMap,
                        Path = new PropertyPath("Foreground")
                    };
                    SetBinding(ForegroundProperty, foregroundBinding);
                }

                if (Stroke == null)
                {
                    strokeBinding = new Binding
                    {
                        Source = parentMap,
                        Path = new PropertyPath("Foreground")
                    };
                    SetBinding(StrokeProperty, strokeBinding);
                }
            }

            base.SetParentMapOverride(parentMap);
        }
Esempio n. 18
0
        private static void SetViewportPosition(UIElement element, MapBase parentMap, Location location)
        {
            var viewportPosition = new Point();

            if (parentMap != null && location != null)
            {
                var mapPosition = parentMap.MapTransform.Transform(location, parentMap.Center.Longitude); // nearest to center longitude

                viewportPosition = parentMap.ViewportTransform.Transform(mapPosition);

                if ((bool)element.GetValue(FrameworkElement.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;
        }
Esempio n. 19
0
        protected virtual void SetParentMapOverride(MapBase map)
        {
            if (parentMap != null && parentMap != this)
            {
                parentMap.ViewportChanged -= OnViewportChanged;
            }

            parentMap = map;

            if (parentMap != null && parentMap != this)
            {
                parentMap.ViewportChanged += OnViewportChanged;
                OnViewportChanged();
            }
        }
Esempio n. 20
0
 void IMapElement.SetParentMap(MapBase map)
 {
     SetParentMapOverride(map);
 }
Esempio n. 21
0
        private static void SetViewportPosition(UIElement element, MapBase parentMap, Location location)
        {
            Point viewportPosition;

            if (parentMap != null && location != null)
            {
                var mapPosition = parentMap.MapTransform.Transform(location, parentMap.Center.Longitude); // nearest to center longitude
                viewportPosition = parentMap.ViewportTransform.Transform(mapPosition);
                element.SetValue(ViewportPositionProperty, viewportPosition);
            }
            else
            {
                viewportPosition = new Point();
                element.ClearValue(ViewportPositionProperty);
            }

            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;
        }
Esempio n. 22
0
 void IMapElement.SetParentMap(MapBase map)
 {
     parentMap = map;
     UpdateData();
 }