/// <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
        }
示例#2
0
        public void AddSymbols()
        {
            var layer = Map.Layers["Symbols"];

            if (layer != null)
            {
                Map.Layers.Remove(layer);
            }

            var symbolLayer = new ShapeLayer("Symbols")
            {
                LazyUpdate = useSymLazyUpdate
            };

            Map.Layers.Add(symbolLayer);

            for (int i = 0; i < coordinates.Count; i++)
            {
                const int symbolSize = 25;
                var       color      = i % 3 == 0 ? Colors.Blue : i % 3 == 1 ? Colors.Green : Colors.Red;

                FrameworkElement symbol;
                if (useSymBitmapCaching)
                {
                    var bitmap = GetCachedBitmap(color, symbolSize);
                    symbol = new Image {
                        Source = bitmap
                    };
                }
                else
                {
                    symbol = new Pyramid {
                        Color = color
                    };
                    symbol.Width = symbol.Height = symbolSize;
                }

                // log-scaling parameters
                ShapeCanvas.SetScale(symbol, 10);
                ShapeCanvas.SetScaleFactor(symbol, 0.4);

                ShapeCanvas.SetLocation(symbol, coordinates[i]);
                symbol.ToolTip = "Hello";
                symbolLayer.Shapes.Add(symbol);
            }
        }
        public void AddBalloon(MultiCanvasShapeLayer layer, double lat, double lon, Color color, string text,
                               string tooltip)
        {
            // create and initialize balloon
            var balloon = new Balloon
            {
                Color   = color,
                Text    = text,
                ToolTip = tooltip
            };

            // set geo location
            ShapeCanvas.SetLocation(balloon, new System.Windows.Point(lon, lat));

            // optional use adaptive (zoom-dependent scaling)
            ShapeCanvas.SetScale(balloon, 2.5);
            ShapeCanvas.SetScaleFactor(balloon, 0.1);

            // don't need a z_index, use TopShapes instead.
            // Canvas.SetZIndex(balloon, 1);

            // add to map
            layer.TopShapes.Add(balloon);
        }
示例#4
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);
            }
        }