예제 #1
0
        /// <summary> Builds up the layer content. Shows a pin for each geocoded address on the map. </summary>
        protected void UdpatePins()
        {
            #region doc:display pins for addresses
            ContentLayer.Shapes.Clear();

            if (Addresses == null || Addresses.Count == 0)
            {
                return;
            }

            // Add a pin to the map for each result.
            foreach (ResultAddress address in Addresses)
            {
                var pin = new Pin
                {
                    Color  = PinColor,
                    Height = 40,
                    Width  = 40
                };
                ToolTipService.SetToolTip(pin, $"{address.postCode} {address.city} {address.city2} {address.street} {address.houseNumber}");
                ShapeCanvas.SetAnchor(pin, LocationAnchor.RightBottom);
                ShapeCanvas.SetLocation(pin, new System.Windows.Point(address.coordinates.point.x, address.coordinates.point.y));
                ContentLayer.Shapes.Add(pin);
            }

            ContentLayer.Refresh();
            #endregion
        }
예제 #2
0
        /// <summary>
        /// Creates a stop.
        /// </summary>
        /// <param name="layer">Assigned route layer</param>
        /// <param name="p">Position of the way point (world coordinates)</param>
        /// <param name="style">Style of the way point</param>
        public Stop(RouteLayer layer, Point p, ShapeStyle style) : base(layer, p, style)
        {
            // add a pin
            Pin = new Pin {
                Color = style.Color, Width = style.Size, Height = style.Size
            };
            Children.Add(Pin);

            // overlay pin with a text block
            Children.Add(new TextBlock
            {
                Text            = "",
                Foreground      = new SolidColorBrush(Colors.Black),
                FontSize        = style.Size * 0.3125,
                FontWeight      = FontWeight.FromOpenTypeWeight(800),
                RenderTransform = new RotateTransform(-45),
                Effect          = new DropShadowEffect
                {
                    ShadowDepth = 0.125 * style.Size,
                    Direction   = 45,
                    Color       = Colors.White,
                    Opacity     = 0.5,
                    BlurRadius  = 0.125 * style.Size
                }
            });

            // position subordinate elements
            SetLeft(Children[1], 0.25 * style.Size);
            SetTop(Children[1], 0.4375 * style.Size);

            ShapeCanvas.SetAnchor(this, LocationAnchor.RightBottom);
            layer.Shapes.Add(this);
        }
        /// <summary> Adds a pin to the map for each way point of the example route. </summary>
        private void SetWayPointPins(Scenario scenario)

        {
            for (var i = 0; i < scenario.wayPoints.Length; ++i)
            {
                var pin = new Pin
                {
                    // Sets the color of the pin to green if it's the start waypoint. Otherwise red.
                    Color  = (i == 0) ? Colors.Green : Colors.Red,
                    Width  = 40,
                    Height = 40,
                    // Sets the name of the pin to Start it it's the start waypoint. Otherwise to End.
                    Name = (i == 0) ? "Start" : "End",
                };

                // Sets Anchor and Location of the pin.
                ShapeCanvas.SetAnchor(pin, LocationAnchor.RightBottom);
                ShapeCanvas.SetLocation(pin, new System.Windows.Point(scenario.wayPoints[i].x, scenario.wayPoints[i].y));

                // Sets tooltip of the pin to Start if it is the start waypoint. Otherwise to End.
                ToolTipService.SetToolTip(pin, pin.Name);

                // Adds the pin to the layer.
                shapeLayer.Shapes.Add(pin);
            }
        }
        /// <summary>
        /// Besides the individual customized symbols, which can be any objects of type FrameworkElement,
        /// additionally labels are added into the shape layer.
        /// </summary>
        /// <param name="frameworkElement">New shape element to insert into the shape layer.</param>
        /// <param name="animation">Optionally an animation can be specified applied to the new shape.</param>
        private void AddToLayer(FrameworkElement frameworkElement, Timeline animation = null)
        {
            #region doc:add to layer

            // Because of a different positioning of labels for objects of type MapPolylineBase compared
            // to other object types, two different implementations are available
            if (frameworkElement is MapPolylineBase)
            {
                shapeLayer.Shapes.Add(frameworkElement);
                // Create a label at the position specified in the Location property of the MapPolyline object.
                var border = CreateLabel("Hello");
                ShapeCanvas.SetLocation(border, ShapeCanvas.GetLocation(frameworkElement));
                shapeLayer.Shapes.Add(border);
            }
            else
            {
                // Arrange symbol and text label in a stack panel
                var stackPanel = new StackPanel();

                stackPanel.Children.Add(frameworkElement);
                stackPanel.Children.Add(CreateLabel("Hello"));

                // The following properties of the new object are transferred to the StackPanel for
                // correct behavior.
                ShapeCanvas.SetLocation(stackPanel, ShapeCanvas.GetLocation(frameworkElement));
                ShapeCanvas.SetAnchor(stackPanel, ShapeCanvas.GetAnchor(frameworkElement));
                ShapeCanvas.SetScale(stackPanel, ShapeCanvas.GetScale(frameworkElement));
                ShapeCanvas.SetScaleFactor(stackPanel, ShapeCanvas.GetScaleFactor(frameworkElement));

                shapeLayer.Shapes.Add(stackPanel);

                // Add the option animation
                if (animation == null)
                {
                    return;
                }

                // Set the animation to target the Center property of the stack panel object
                Storyboard.SetTarget(animation, stackPanel);
                Storyboard.SetTargetProperty(animation, new PropertyPath(ShapeCanvas.LocationProperty));

                // Create a storyboard to apply the animation.
                var sb = new Storyboard();
                sb.Children.Add(animation);
                sb.Begin();
            }
            #endregion //doc:add to layer
        }
예제 #5
0
        /// <summary>
        /// Creates a via way point.
        /// </summary>
        /// <param name="layer">Assigned route layer</param>
        /// <param name="p">Position of the way point (world coordinates)</param>
        /// <param name="style">Style of the way point</param>
        public Via(RouteLayer layer, Point p, ShapeStyle style) : base(layer, p, style)
        {
            Children.Add(new Ball
            {
                Color  = style.Color,
                Stroke = Colors.Black,
                Width  = style.Size,
                Height = style.Size
            });

            // must set a tool tip for the ToolTipOpening event to be raised.
            ToolTip              = "<null>";
            base.ToolTipOpening += ToolTipOpening;

            ShapeCanvas.SetAnchor(this, LocationAnchor.Center);
            layer.Shapes.Add(this);
        }
        /// <summary>
        /// Used to create and initialize a symbol, given a symbol name.
        /// </summary>
        /// <param name="size">The size of the symbol, in pixels.</param>
        /// <param name="argbColor">The color of the symbol, specified as string.</param>
        /// <returns>The symbol instance, returned as a FrameworkElement.
        /// The default symbol, used on any error, is a Pin.</returns>
        /// <remarks>See remarks on <see cref="AddMarker"/> for further information.</remarks>
        private static FrameworkElement CreateSymbol(int size, string argbColor)
        {
            // create the symbol
            var elem = new Pin();

            // set the color
            SetSymbolColor(elem, argbColor);

            // set the size
            elem.Width = elem.Height = size;

            // we need modify the anchor
            ShapeCanvas.SetAnchor(elem, LocationAnchor.RightBottom);

            // done
            return(elem);
        }
        /// <summary>
        /// The arrow demo is uses an adaption of Charles Petzold's WPF arrow class
        /// http://charlespetzold.com/blog/2007/04/191200.html to be used as custom MapShape
        /// </summary>
        /// <param name="layer"></param>
        public void AddPinWithLabel(ShapeLayer layer)
        {
            // text and symbol as two shapes
            Control pin = new Pin();

            pin.Width = pin.Height = 30;
            ShapeCanvas.SetLocation(pin, new Point(8.4, 49));
            ShapeCanvas.SetAnchor(pin, LocationAnchor.RightBottom);
            layer.Shapes.Add(pin);

            var textBlock = new TextBlock
            {
                Text       = "Hello",
                Background = new SolidColorBrush(Colors.White),
                Foreground = new SolidColorBrush(Colors.Black)
            };

            ShapeCanvas.SetLocation(textBlock, new Point(8.4, 49));
            ShapeCanvas.SetAnchor(textBlock, LocationAnchor.LeftTop);
            layer.Shapes.Add(textBlock);


            // text with symbol in a view box
            var grid = new Grid();

            grid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(50)
            });
            grid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(50)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(50)
            });

            var viewBox = new Viewbox {
                Stretch = Stretch.Uniform
            };

            pin           = new Cube();
            viewBox.Child = pin;
            Grid.SetRow(viewBox, 0);
            grid.Children.Add(viewBox);

            viewBox = new Viewbox {
                Stretch = Stretch.Uniform
            };
            textBlock = new TextBlock
            {
                Text       = "Hello",
                Background = new SolidColorBrush(Colors.White),
                Foreground = new SolidColorBrush(Colors.Black)
            };
            viewBox.Child = textBlock;
            Grid.SetRow(viewBox, 1);
            grid.Children.Add(viewBox);

            ShapeCanvas.SetLocation(grid, new Point(8.5, 49));
            ShapeCanvas.SetScaleFactor(grid, .1);
            layer.Shapes.Add(grid);
        }
        /// <summary> Adds elements to the map. </summary>
        private void AddElements()
        {
            #region doc:the location around which the shapes are created
            // the location in Gauss-Kruger coordinates
            var location = new Point(3565913, 5935734);
            #endregion

            #region doc:create ShapeLayer
            // create a shape layer
            shapeLayer = new ShapeLayer("DifferentShapes")
            {
                SpatialReferenceId = "EPSG:31467", // set SR to Gaus s-Kruger zone 3 (default is WGS84)
                LocalOffset        = location      // the localOffset can be used to reduce jitter at deep zoom levels
            };

            shapeLayer2 = new ShapeLayer("PieCharts")
            {
                LocalOffset = new Point(10, 53) // to reduce jitter
            };
            #endregion                          //doc:create ShapeLayer

            #region doc:add layer to map
            // add layers to map
            wpfMap.Layers.Add(shapeLayer);
            wpfMap.Layers.InsertBefore(shapeLayer2, "DifferentShapes");
            #endregion //doc:add layer to map

            #region doc:animate shape
            // create a WPF element
            var triangleUp = new TriangleUp {
                Color = Colors.Blue, Stroke = Colors.Red,
                HorizontalAlignment = HorizontalAlignment.Left,
                ToolTip             = "TriangleUp", Width = 32, Height = 32
            };

            // set geo location of the element
            triangleUp.SetValue(ShapeCanvas.LocationProperty, location);

            // add some click interaction
            triangleUp.MouseDoubleClick += (o, e) => MessageBox.Show("Hello!");

            var myPointAnimation = new PointAnimation
            {
                Duration       = TimeSpan.FromSeconds(2),
                AutoReverse    = true,
                RepeatBehavior = RepeatBehavior.Forever,
                From           = location,
                To             = new Point(location.X + 960, location.Y + 960)
            };

            // add to layer
            AddToLayer(triangleUp, myPointAnimation);


            #endregion //doc:animate shape

            #region doc:add MapPolygon
            var poly = new MapPolygon
            {
                Points = new PointCollection(new[]
                {
                    (Point)(location - new Point(-100, -100)), (Point)(location - new Point(100, -100)),
                    (Point)(location - new Point(100, 100)), (Point)(location - new Point(-100, 100))
                }),
                Fill               = new SolidColorBrush(Colors.Red),
                Opacity            = .5,
                MapStrokeThickness = 5,
                Stroke             = new SolidColorBrush(Colors.Black)
            };
            Panel.SetZIndex(poly, -1);
            AddToLayer(poly);
            #endregion //doc:add MapPolygon

            #region doc:handle MapPolygon events
            poly.MouseEnter += (o, e) => poly.Fill = new SolidColorBrush(Colors.Green);
            poly.MouseLeave += (o, e) => poly.Fill = new SolidColorBrush(Colors.Red);
            #endregion //doc:handle MapPolygon events

            #region doc:create shapes
            // Create elements
            var triangleDown = CreateElement(Symbols.TriangleDown, Colors.Black, Colors.Red) as TriangleDown;
            var star         = CreateElement(Symbols.Star, Colors.Yellow, Colors.Green) as Star;
            var pentagon     = CreateElement(Symbols.Pentagon, Colors.Red, Colors.Blue) as Pentagon;
            var hexagon      = CreateElement(Symbols.Hexagon, Colors.Orange, Colors.Navy) as Hexagon;
            var diamond      = CreateElement(Symbols.Diamond, Colors.DeepPink, Colors.Navy) as Diamond;
            var pyramid      = CreateElement(Symbols.Pyramid, Colors.Yellow, Colors.Black) as Pyramid;
            var ball         = CreateElement(Symbols.Ball, Colors.Yellow, Colors.Green) as Ball;
            ball.Width = ball.Height = 100; // Varying the default size
            var pin  = CreateElement(Symbols.Pin, Colors.Green, Colors.Black) as Pin;
            var cube = CreateElement(Symbols.Cube, Colors.Blue, Colors.Red) as Cube;
            cube.Width = cube.Height = 15; // Varying the default size
            var truck = CreateElement(Symbols.Truck, Colors.Red, Colors.Black) as Truck;
            #endregion                     //doc:create shapes

            #region doc:set position
            // set position
            triangleDown.SetValue(ShapeCanvas.LocationProperty, new Point(location.X + 320, location.Y));
            Panel.SetZIndex(triangleDown, -1);
            star.SetValue(ShapeCanvas.LocationProperty, new Point(location.X + 640, location.Y));
            Panel.SetZIndex(star, -1);
            pentagon.SetValue(ShapeCanvas.LocationProperty, new Point(location.X + 960, location.Y));
            Panel.SetZIndex(pentagon, -1);
            hexagon.SetValue(ShapeCanvas.LocationProperty, new Point(location.X, location.Y + 320));
            Panel.SetZIndex(hexagon, -1);
            diamond.SetValue(ShapeCanvas.LocationProperty, new Point(location.X + 320, location.Y + 320));
            Panel.SetZIndex(diamond, -1);
            pyramid.SetValue(ShapeCanvas.LocationProperty, new Point(location.X + 640, location.Y + 320));
            Panel.SetZIndex(pyramid, -1);
            ball.SetValue(ShapeCanvas.LocationProperty, new Point(location.X + 960, location.Y + 320));
            Panel.SetZIndex(ball, -1);
            pin.SetValue(ShapeCanvas.LocationProperty, new Point(location.X, location.Y + 640));
            ShapeCanvas.SetAnchor(pin, LocationAnchor.RightBottom);
            Panel.SetZIndex(pin, -1);
            cube.SetValue(ShapeCanvas.LocationProperty, new Point(location.X + 320, location.Y + 640));
            Panel.SetZIndex(cube, -1);
            truck.SetValue(ShapeCanvas.LocationProperty, new Point(location.X + 960, location.Y + 640));
            Panel.SetZIndex(truck, -1);
            #endregion //doc:set position

            AddToLayer(triangleDown);
            AddToLayer(star);
            AddToLayer(pentagon);
            AddToLayer(hexagon);
            AddToLayer(diamond);
            AddToLayer(pyramid);
            AddToLayer(ball);
            AddToLayer(pin);
            AddToLayer(cube);
            AddToLayer(truck);


            #region doc:sample anchor
            var pinRightBottom = CreateElement(Symbols.Pin, Colors.Green, Colors.Black) as Pin;
            if (pinRightBottom != null)
            {
                pinRightBottom.SetValue(ShapeCanvas.LocationProperty, new Point(location.X - 320, location.Y));
                pinRightBottom.ToolTip = "Pin with anchor right bottom";
                ShapeCanvas.SetAnchor(pinRightBottom, LocationAnchor.RightBottom);
                Panel.SetZIndex(pinRightBottom, -1);
                AddToLayer(pinRightBottom);
            }

            var ballRightBottom = CreateElement(Symbols.Ball, Colors.Red, Colors.Black) as Ball;
            if (ballRightBottom != null)
            {
                ballRightBottom.Width   = 10;
                ballRightBottom.Height  = 10;
                ballRightBottom.ToolTip = "Ball with same coordinates like pin";
                ballRightBottom.SetValue(ShapeCanvas.LocationProperty, new Point(location.X - 320, location.Y));
                Panel.SetZIndex(ballRightBottom, -1);
                AddToLayer(ballRightBottom);
            }

            var pinCenter = CreateElement(Symbols.Pin, Colors.Green, Colors.Black) as Pin;
            if (pinCenter != null)
            {
                pinCenter.SetValue(ShapeCanvas.LocationProperty, new Point(location.X - 320, location.Y + 150));
                pinCenter.ToolTip = "Pin with default anchor";
                Panel.SetZIndex(pinCenter, -1);
                AddToLayer(pinCenter);
            }

            var ballCenter = CreateElement(Symbols.Ball, Colors.Red, Colors.Black) as Ball;
            if (ballCenter != null)
            {
                ballCenter.Width   = 10;
                ballCenter.Height  = 10;
                ballCenter.ToolTip = "Ball with same coordinates like pin";
                ballCenter.SetValue(ShapeCanvas.LocationProperty, new Point(location.X - 320, location.Y + 150));
                Panel.SetZIndex(ballCenter, -1);
                AddToLayer(ballCenter);
            }

            #endregion // doc:sample anchor


            #region doc:sample ScaleProperty
            var starStandard = CreateElement(Symbols.Star, Colors.Green, Colors.Black) as Star;
            if (starStandard != null)
            {
                starStandard.SetValue(ShapeCanvas.LocationProperty, new Point(location.X - 100, location.Y + 960));
                starStandard.Width   = starStandard.Height = 40;
                starStandard.ToolTip = "Star with size 40 and scale 1 (standard display)";
                starStandard.SetValue(ShapeCanvas.ScaleProperty, 1.0);
                Panel.SetZIndex(starStandard, -1);
                AddToLayer(starStandard);
            }

            var starBig = CreateElement(Symbols.Star, Colors.Green, Colors.Black) as Star;
            if (starBig != null)
            {
                starBig.SetValue(ShapeCanvas.LocationProperty, new Point(location.X, location.Y + 960));
                starBig.Width   = starBig.Height = 40;
                starBig.ToolTip = "Star with size 40 and scale 3 (object bigger and border thicker)";
                starBig.SetValue(ShapeCanvas.ScaleProperty, 3.0);
                Panel.SetZIndex(starBig, -1);
                AddToLayer(starBig);
            }

            #endregion // doc:sample ScaleProperty


            #region doc:sample ScaleFactor
            var starConstant = CreateElement(Symbols.Star, Colors.Red, Colors.Black) as Star;
            if (starConstant != null)
            {
                starConstant.SetValue(ShapeCanvas.LocationProperty, new Point(location.X + 320, location.Y + 960));
                starConstant.Width   = starConstant.Height = 80;
                starConstant.ToolTip = "Star with size 80 and scale factor 0 (constant object size, standard display)";
                ShapeCanvas.SetScaleFactor(starConstant, 0);
                Panel.SetZIndex(starConstant, -1);
                AddToLayer(starConstant);
            }

            var starHalfEnlarged = CreateElement(Symbols.Star, Colors.Yellow, Colors.Black) as Star;
            if (starHalfEnlarged != null)
            {
                starHalfEnlarged.SetValue(ShapeCanvas.LocationProperty, new Point(location.X + 370, location.Y + 960));
                starHalfEnlarged.Width   = starHalfEnlarged.Height = 80;
                starHalfEnlarged.ToolTip =
                    "Star with size 80 and scale factor 0.5 (object is half enlarged if the map zooms)";
                ShapeCanvas.SetScaleFactor(starHalfEnlarged, 0.5);
                Panel.SetZIndex(starHalfEnlarged, -1);
                AddToLayer(starHalfEnlarged);
            }

            var starEnlarged = CreateElement(Symbols.Star, Colors.Green, Colors.Black) as Star;
            if (starEnlarged != null)
            {
                starEnlarged.SetValue(ShapeCanvas.LocationProperty, new Point(location.X + 420, location.Y + 960));
                starEnlarged.Width   = starEnlarged.Height = 80;
                starEnlarged.ToolTip = "Star with size 80 and scale factor 1 (object is enlarged if the map zooms)";
                ShapeCanvas.SetScaleFactor(starEnlarged, 1);
                Panel.SetZIndex(starEnlarged, -1);
                AddToLayer(starEnlarged);
            }

            #endregion // doc:sample ScaleFactor

            // our demo data
            var stores = new List <Store> {
                new Store
                {
                    Name      = "HH-South",
                    Latitude  = 53.55,
                    Longitude = 10.02,
                    Sales     = new List <Sale> {
                        new Sale {
                            Type = "Food", Amount = 30
                        },
                        new Sale {
                            Type = "Non Food", Amount = 70
                        }
                    }
                },
                new Store
                {
                    Name      = "HH-North",
                    Latitude  = 53.56,
                    Longitude = 10.02,
                    Sales     = new List <Sale> {
                        new Sale {
                            Type = "Food", Amount = 40
                        },
                        new Sale {
                            Type = "Non Food", Amount = 50
                        },
                        new Sale {
                            Type = "Pet Food", Amount = 10
                        }
                    }
                }
            };

            foreach (var store in stores)
            {
                // initialize a pie chart for each element
                var chartView = new Chart();
                chartView.BeginInit();

                chartView.Width      = 300;
                chartView.Height     = 250;
                chartView.Background = new SolidColorBrush(Color.FromArgb(192, 255, 255, 255));

                var pieSeries = new PieSeries();
                chartView.Title = store.Name;
                pieSeries.IndependentValuePath = "Type";
                pieSeries.DependentValuePath   = "Amount";
                pieSeries.ItemsSource          = store.Sales;
                pieSeries.IsSelectionEnabled   = true;
                chartView.Series.Add(pieSeries);

                chartView.EndInit();

                // Add to map
                ShapeCanvas.SetLocation(chartView, new Point(store.Longitude, store.Latitude));
                ShapeCanvas.SetAnchor(chartView, LocationAnchor.Center);
                ShapeCanvas.SetScaleFactor(chartView, .1); // adopt the element to the scale factor
                shapeLayer2.Shapes.Add(chartView);
            }

            #region doc:center map to location
            // center map to location
            wpfMap.SetMapLocation(new Point(location.X + 1000, location.Y + 650), 14.7, "EPSG:31467");
            #endregion //doc:center map to location
        }
예제 #9
0
        // Shows how to add an arbitrary controls to the map
        // As sample the pie charts series of Wpf toolkit is used
        // http://wpf.codeplex.com/releases/view/40535
        public void AddPieCharts(ShapeLayer layer)
        {
            // our demo data
            var stores = new List <Store> {
                new Store
                {
                    Name      = "KA-Center",
                    Latitude  = 48.96,
                    Longitude = 8.39,
                    Sales     = new List <Sale> {
                        new Sale {
                            Type = "Food", Amount = 30
                        },
                        new Sale {
                            Type = "Non Food", Amount = 70
                        }
                    }
                },
                new Store
                {
                    Name      = "KA-North",
                    Latitude  = 49.04,
                    Longitude = 8.41,
                    Sales     = new List <Sale> {
                        new Sale {
                            Type = "Food", Amount = 40
                        },
                        new Sale {
                            Type = "Non Food", Amount = 50
                        },
                        new Sale {
                            Type = "Pet Food", Amount = 10
                        }
                    }
                }
            };

            foreach (var store in stores)
            {
                // initialize a pie chart for each element
                var chart = new Chart();
                chart.BeginInit();

                chart.Width      = 300;
                chart.Height     = 250;
                chart.Background = new SolidColorBrush(Color.FromArgb(192, 255, 255, 255));
                var pieSeries = new PieSeries();
                chart.Title = store.Name;
                pieSeries.IndependentValuePath = "Type";
                pieSeries.DependentValuePath   = "Amount";
                pieSeries.ItemsSource          = store.Sales;
                pieSeries.IsSelectionEnabled   = true;
                chart.Series.Add(pieSeries);

                chart.EndInit();

                // Add to map
                ShapeCanvas.SetLocation(chart, new Point(store.Longitude, store.Latitude));
                ShapeCanvas.SetAnchor(chart, LocationAnchor.Center);
                ShapeCanvas.SetScale(chart, 2);
                ShapeCanvas.SetScaleFactor(chart, .25); // adopt the element to the scale factor
                layer.Shapes.Add(chart);
            }
        }
예제 #10
0
        /// <summary> Adds a pin to the map for each way point. </summary>
        #region doc:update the way point pins
        private void UpdateWayPointPins()
        {
            // already disposed
            if (disposed)
            {
                return;
            }

            (wayPointLayer as ShapeLayer)?.Shapes.Clear();

            foreach (var wayPoint in wayPoints)
            {
                var pin = new Pin();

                if (wayPoints.IndexOf(wayPoint) == 0)
                {
                    pin.Color = Colors.Green;
                }
                else if (wayPoints.IndexOf(wayPoint) == wayPoints.Count - 1)
                {
                    pin.Color = Colors.Red;
                }
                else
                {
                    pin.Color = Colors.Blue;
                }

                #region doc:waypoint context menu
                var cmWayPoints = new ContextMenu();
                var item        = new MenuItem {
                    Header = "Remove", CommandParameter = wayPoint
                };
                item.Click += RemoveItemClick;
                cmWayPoints.Items.Add(item);
                item = new MenuItem {
                    Header = "Move up", CommandParameter = wayPoint
                };
                item.Click += MoveUpItemClick;
                cmWayPoints.Items.Add(item);
                item = new MenuItem {
                    Header = "Move down", CommandParameter = wayPoint
                };
                item.Click += MoveDownItemClick;
                cmWayPoints.Items.Add(item);
                ContextMenuService.SetContextMenu(pin, cmWayPoints);
                #endregion

                pin.Width  = 40;
                pin.Height = 40;

                // set tool tip information
                ToolTipService.SetToolTip(pin, wayPoints.IndexOf(wayPoint) == 0 ? "Start" : wayPoints.IndexOf(wayPoint) == 0 ? "End" : "Waypoint " + (wayPoints.IndexOf(wayPoint) + 1));

                pin.Name = "Waypoint" + (wayPoints.IndexOf(wayPoint) + 1);

                Panel.SetZIndex(pin, -1);

                ShapeCanvas.SetAnchor(pin, LocationAnchor.RightBottom);
                ShapeCanvas.SetLocation(pin, new System.Windows.Point(wayPoint.x, wayPoint.y));

                (wayPointLayer as ShapeLayer)?.Shapes.Add(pin);
            }

            wayPointLayer.Refresh();
        }
예제 #11
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // go to Karlsruhe castle
            var myLocation = new Point(8.4044, 49.01405);

            Map.SetMapLocation(myLocation, 14);

            // add OSM tiles
            Map.Layers.Add(new TiledLayer("OSM_DE")
            {
                Caption        = "OpenStreetMap.DE",
                IsBaseMapLayer = true,
                TiledProvider  = new RemoteTiledProvider
                {
                    MinZoom = 0,
                    MaxZoom = 18,
                    RequestBuilderDelegate = (x, y, level) =>
                                             $"https://{"abc"[(x ^ y) % 3]}.tile.openstreetmap.de/tiles/osmde/{level}/{x}/{y}.png",
                },
                Copyright = $"Map © OpenStreetMap contributors",
                Icon      = ResourceHelper.LoadBitmapFromResource("Ptv.XServer.Controls.Map;component/Resources/Background.png")
            });

            // add basic xServer tiles
            // Map.Layers.Add(new TiledLayer("xserver")
            // {
            //     Caption = "PTV xServer",
            //     IsBaseMapLayer = true,
            //     TiledProvider = new RemoteTiledProvider
            //     {
            //         MinZoom = 0,
            //         MaxZoom = 22,
            //         RequestBuilderDelegate = (x, y, level) =>

            //         $"https://s0{"1234"[(x ^ y) % 4]}-xserver2-test.cloud.ptvgroup.com/services/rest/XMap/tile/" +
            //         $"{level}/{x}/{y}?storedProfile=silkysand&xtok=<your-xserver-internet-token>"
            //     },
            //     Copyright = $"© PTV, HERE",
            //     Icon = ResourceHelper.LoadBitmapFromResource("Ptv.XServer.Controls.Map;component/Resources/Background.png")
            // });

            // add stuff
            var myLayer = new ShapeLayer("MyLayer")
            {
                LocalOffset = myLocation // this new property eliminates jitter at deep zoom levels
            };

            Map.Layers.Add(myLayer);

            // add push-pin
            Control pin = new Pin
            {
                Width   = 50, // regarding scale fatoring
                Height  = 50,
                ToolTip = "I am a pin!",
                Color   = Colors.Red
            };

            ShapeCanvas.SetLocation(pin, myLocation);
            ShapeCanvas.SetAnchor(pin, LocationAnchor.RightBottom);
            ShapeCanvas.SetScaleFactor(pin, 0.1);
            Panel.SetZIndex(pin, 100);
            myLayer.Shapes.Add(pin);

            // add geographic circle
            double radius      = 435;                                            // radius in meters
            double cosB        = Math.Cos(myLocation.Y / 360.0 * (2 * Math.PI)); // factor depends on latitude
            double ellipseSize = Math.Abs(1.0 / cosB * radius) * 2;              // size mercator units

            var ellipse = new Ellipse
            {
                Width           = ellipseSize,
                Height          = ellipseSize,
                Fill            = new SolidColorBrush(Color.FromArgb(128, 0, 0, 255)),
                Stroke          = new SolidColorBrush(Colors.Black),
                StrokeThickness = radius / 20,
                ToolTip         = "I am a circle!"
            };

            ShapeCanvas.SetScaleFactor(ellipse, 1); // scale linear
            ShapeCanvas.SetLocation(ellipse, myLocation);
            myLayer.Shapes.Add(ellipse);
        }