如何将字符串放在多边形内?它将显示在MapOverlay。
中private void DrawMapMarker(GeoCoordinate coordinate, Color color, MapLayer mapLayer)
{
Polygon polygon = new Polygon();
polygon.Points.Add(new Point(0, 0));
polygon.Points.Add(new Point(0, 75));
polygon.Points.Add(new Point(25, 0));
polygon.Fill = new SolidColorBrush(color);
polygon.DataContext = "HIIIIIII";
// Enable marker to be tapped for location information
polygon.Tag = new GeoCoordinate(coordinate.Latitude, coordinate.Longitude);
polygon.MouseLeftButtonUp += polygon_MouseLeftButtonUp;
// Create a MapOverlay and add marker.
MapOverlay overlay = new MapOverlay();
overlay.Content = polygon;
overlay.GeoCoordinate = new GeoCoordinate(coordinate.Latitude, coordinate.Longitude);
overlay.PositionOrigin = new Point(0.0, 1.0);
mapLayer.Add(overlay);
}
答案 0 :(得分:3)
只需使用某种面板(例如,StackPanel),并将多边形和TextBlock放入其中:
private void DrawMapMarker(GeoCoordinate coordinate, Color color, MapLayer mapLayer)
{
var content = new Grid { Width = 25, Height = 75 };
Polygon polygon = new Polygon();
polygon.Points.Add(new Point(0, 0));
polygon.Points.Add(new Point(0, 75));
polygon.Points.Add(new Point(25, 0));
polygon.Fill = new SolidColorBrush(color);
var text = new TextBlock
{
Text = "HIIIIIII",
Foreground = new SolidColorBrush(Colors.Orange),
};
var viewbox = new Viewbox { Child = text };
content.Children.Add(polygon);
content.Children.Add(viewbox);
// Enable marker to be tapped for location information
polygon.Tag = new GeoCoordinate(coordinate.Latitude, coordinate.Longitude);
polygon.MouseLeftButtonUp += polygon_MouseLeftButtonUp;
// Create a MapOverlay and add marker.
MapOverlay overlay = new MapOverlay();
overlay.Content = content;
overlay.GeoCoordinate = new GeoCoordinate(coordinate.Latitude, coordinate.Longitude);
overlay.PositionOrigin = new Point(0.0, 1.0);
mapLayer.Add(overlay);
}