示例#1
0
        public static MapShape CreateUserShape(ShapeData data)
        {
            var shape = new MapRectangle()
            {
                Width    = data.Width,
                Height   = data.Height,
                Location = new Location(data.Latitude, data.Longitude)
            };

            var user = data.Tag as entities.User;

            if (user != null)
            {
                var propertySet = new ExtendedPropertySet();
                propertySet.RegisterProperty("Placemark.Name", "Name", typeof(string), string.Empty); // KML file defines Placemark.Name, we create a same property too.
                var extendedData = new ExtendedData(propertySet);
                extendedData.SetValue("Placemark.Name", user.UserName);

                shape.ExtendedData = extendedData;
                shape.Tag          = user;
            }

            //set CaptionTemplate
            shape.CaptionTemplate = Application.Current.FindResource("ShapeCaptionTemplate") as DataTemplate; //In the template, we use ExtendedData["Placemark.Name"] as caption

            return(shape);
        }
        private void FillInformationLayer()
        {
            // Create extended property set.
            // It can be shared between the number
            // of the map shapes.
            ExtendedPropertySet propertySet = new ExtendedPropertySet();

            propertySet.RegisterProperty("Name", "City Name", typeof(string), String.Empty);
            propertySet.RegisterProperty("Population", "Population", typeof(int), 0);

            MapEllipse sofiaEllipse = new MapEllipse()
            {
                ShapeFill = new MapShapeFill()
                {
                    Stroke          = new SolidColorBrush(Colors.Red),
                    StrokeThickness = 2,
                    Fill            = new SolidColorBrush(Colors.Transparent)
                },
                Width    = 20,
                Height   = 20,
                Location = new Location(42.6957539183824, 23.3327663758679),
            };

            // Create extended data for the ellipse
            // using existing property set.
            ExtendedData sofiaData = new ExtendedData(propertySet);

            // Set the extended properties.
            sofiaData.SetValue("Name", "Sofia");
            sofiaData.SetValue("Population", 1300000);

            // Assign extended data to the map shape.
            sofiaEllipse.ExtendedData = sofiaData;

            // Assign tooltip which uses the extended properties.
            ToolTip tooltip        = new ToolTip();
            Binding tooltipBinding = new Binding()
            {
                Converter          = new ExtendedDataConverter(),
                ConverterParameter = "{Name}: {Population} people",
                Source             = sofiaEllipse.ExtendedData
            };

            tooltip.SetBinding(System.Windows.Controls.ToolTip.ContentProperty, tooltipBinding);
            ToolTipService.SetToolTip(sofiaEllipse, tooltip);

            this.informationLayer.Items.Add(sofiaEllipse);
        }
示例#3
0
        private void FillInformationLayer()
        {
            // Create extended property set.
            // It can be shared between the number
            // of the map shapes.
            ExtendedPropertySet propertySet = new ExtendedPropertySet();
            propertySet.RegisterProperty("Name", "City Name", typeof(string), String.Empty);
            propertySet.RegisterProperty("Population", "Population", typeof(int), 0);

            MapEllipse sofiaEllipse = new MapEllipse()
            {
                ShapeFill = new MapShapeFill()
                {
                    Stroke = new SolidColorBrush(Colors.Red),
                    StrokeThickness = 2,
                    Fill = new SolidColorBrush(Colors.Transparent)
                },
                Width = 20,
                Height = 20,
                Location = new Location(42.6957539183824, 23.3327663758679),
            };

            // Create extended data for the ellipse
            // using existing property set.
            ExtendedData sofiaData = new ExtendedData(propertySet);

            // Set the extended properties.
            sofiaData.SetValue("Name", "Sofia");
            sofiaData.SetValue("Population", 1300000);

            // Assign extended data to the map shape.
            sofiaEllipse.ExtendedData = sofiaData;

            // Assign tooltip which uses the extended properties.
            ToolTip tooltip = new ToolTip();
            Binding tooltipBinding = new Binding()
            {
                Converter = new ExtendedDataConverter(),
                ConverterParameter = "{Name}: {Population} people",
                Source = sofiaEllipse.ExtendedData
            };
            tooltip.SetBinding(System.Windows.Controls.ToolTip.ContentProperty, tooltipBinding);
            ToolTipService.SetToolTip(sofiaEllipse, tooltip);

            this.informationLayer.Items.Add(sofiaEllipse);
        }