UWP C#:将MapPolygon添加到MapControl

时间:2018-06-25 11:43:21

标签: c# google-maps uwp

我正在尝试通过使用以下代码示例(从https://docs.microsoft.com/en-us/windows/uwp/maps-and-location/display-poi#add-a-shape中检索)向地图添加多边形:

public void HighlightArea() {

double centerLatitude = myMap.Center.Position.Latitude;
double centerLongitude = myMap.Center.Position.Longitude;

var mapPolygon = new MapPolygon
{
    Path = new Geopath(new List<BasicGeoposition> {
                new BasicGeoposition() {Latitude=centerLatitude+0.0005, Longitude=centerLongitude-0.001 },
                new BasicGeoposition() {Latitude=centerLatitude-0.0005, Longitude=centerLongitude-0.001 },
                new BasicGeoposition() {Latitude=centerLatitude-0.0005, Longitude=centerLongitude+0.001 },
                new BasicGeoposition() {Latitude=centerLatitude+0.0005, Longitude=centerLongitude+0.001 },
            }),
    ZIndex = 1,
    FillColor = Colors.Red,
    StrokeColor = Colors.Blue,
    StrokeThickness = 3,
    StrokeDashed = false,
};

// Add MapPolygon to a layer on the map control.
var MyHighlights = new List<MapElement>();

MyHighlights.Add(mapPolygon);

var HighlightsLayer = new MapElementsLayer
{
    ZIndex = 1,
    MapElements = MyHighlights
};

myMap.Layers.Add(HighlightsLayer);

}

该多边形最初显示在地图上,但从其出现后的2秒钟内消失(消失)。我已经使用从同一链接中检索到的示例成功添加了粘贴到地图的MapPolyline,这就是为什么我不明白为什么MapPolygon不会粘贴的原因。

什么会导致多边形消失?

0 个答案:

没有答案