/// <summary> /// Converts a MapShape into a Geometry object. /// </summary> /// <param name="shape">A Bing Maps MapShape object</param> /// <returns>A Geometry representation of the MapMultiPoint object</returns> public static Geometry ToGeometry(this MapShapeBase shape) { if (shape is MapPolyline) { return((shape as MapPolyline).ToGeometry()); } else if (shape is MapPolygon) { return((shape as MapPolygon).ToGeometry()); } return(null); }
public void PrepareItem(MapItem item) { item.Attributes.Add(new MapItemAttribute() { Name = "name", Value = GenerateName(item) }); MapShapeBase shape = item as MapShapeBase; if (shape != null) { shape.Fill = new SolidColorBrush(fillColorEdit.Color); shape.Stroke = new SolidColorBrush(strokeColorEdit.Color); } }
/// <summary> /// Apply a style to a MapShapeBase (MapPolygon, MapPolyline). /// </summary> /// <param name="element">MapShapeBase to apply style to.</param> /// <param name="style">Style to apply to MapShape.</param> public static void ApplyStyle(MapShapeBase polyShape, ShapeStyle style) { if (polyShape != null && style != null) { polyShape.StrokeLineJoin = PenLineJoin.Round; polyShape.StrokeStartLineCap = PenLineCap.Round; polyShape.StrokeEndLineCap = PenLineCap.Round; if (polyShape is MapPolyline) { var polyline = polyShape as MapPolyline; if (style.StrokeColor.HasValue) { polyline.Stroke = new SolidColorBrush(style.StrokeColor.Value.ToColor()); } else { polyline.Stroke = new SolidColorBrush(DefaultPolylineColor); } if (!double.IsNaN(style.StrokeThickness) && style.StrokeThickness > 0) { polyline.StrokeThickness = style.StrokeThickness; } else { polyline.StrokeThickness = DefaultPolylineThickness; } } else if (polyShape is MapPolygon) { var polygon = polyShape as MapPolygon; if (style.FillColor.HasValue) { polygon.Fill = new SolidColorBrush(style.FillColor.Value.ToColor()); } else { polygon.Fill = new SolidColorBrush(DefaultPolygonFillColor); } if (style.StrokeColor.HasValue) { polygon.Stroke = new SolidColorBrush(style.StrokeColor.Value.ToColor()); } else { polygon.Stroke = new SolidColorBrush(DefaultPolylineColor); } if (!double.IsNaN(style.StrokeThickness) && style.StrokeThickness > 0) { polygon.StrokeThickness = style.StrokeThickness; } else { polygon.StrokeThickness = DefaultPolylineThickness; } } } }
private void Boutton_valider_Click(object sender, RoutedEventArgs e) { if (listBox.SelectedIndex != -1) { if (!(userData.Liste[listBox.SelectedIndex] is POI)) { MapShapeBase obj = myMap.Children[listBox.SelectedIndex] as MapShapeBase; obj.Stroke = superCombo.SelectedColor; if (userData.Liste[listBox.SelectedIndex] is Polyline) { Polyline line = userData.Liste[listBox.SelectedIndex] as Polyline; line.Color = ((SolidColorBrush)superCombo.SelectedColor).Color; userData.Liste[listBox.SelectedIndex] = line; } if (userData.Liste[listBox.SelectedIndex] is Polygon) { Polygon polygon = userData.Liste[listBox.SelectedIndex] as Polygon; polygon.Linecolor = ((SolidColorBrush)superCombo.SelectedColor).Color; polygon.Bgcolor = Color.FromArgb(150, polygon.Linecolor.R, polygon.Linecolor.G, polygon.Linecolor.B); obj.Fill = new SolidColorBrush(polygon.Bgcolor) { Opacity = 0.3 }; userData.Liste[listBox.SelectedIndex] = polygon; } if (!Desc_Box.Text.Equals(listBox.SelectedItem.ToString())) { int index = listBox.SelectedIndex; listBox.Items.RemoveAt(listBox.SelectedIndex); listBox.Items.Insert(index, Desc_Box.Text); } } else if (userData.Liste[listBox.SelectedIndex] is POI) { POI poi = userData.Liste[listBox.SelectedIndex] as POI; poi.X = Double.Parse(X_box.Text); poi.Y = Double.Parse(Y_box.Text); Location loc = new Location(Double.Parse(Y_box.Text), Double.Parse(X_box.Text)); Pushpin pin = myMap.Children[listBox.SelectedIndex] as Pushpin; pin.Location = loc; } listBox.UnselectAll(); Boutton_valider.Visibility = Visibility.Hidden; superCombo.Visibility = Visibility.Visible; Desc_Box.Text = ""; StatusText.Text = "Objet modifié"; } else { if (!String.IsNullOrEmpty(X_box.Text) && !String.IsNullOrEmpty(Y_box.Text)) { Pushpin pin = new Pushpin(); POI poi = new POI(Desc_Box.Text, Double.Parse(X_box.Text), Double.Parse(Y_box.Text)); pin.Location = new Location(Double.Parse(Y_box.Text), Double.Parse(X_box.Text)); userData.Add(poi); myMap.Children.Add(pin); listBox.Items.Add(poi.Description); Desc_Box.Text = ""; nbPoi++; StatusText.Text = "POI ajouté"; } } }