未绘制MapPolyline [英] MapPolyline not being drawn
问题描述
我正在尝试在地图中使用MapPolyLine来显示实时路线,希望它会移动/缩放.问题是该线未显示在地图上,而且我找不到任何编程错误:
I am trying to use a MapPolyLine in my Map to show a real-time route, hopefully it will move/scale this time. The thing is the line is not being shown on the map, and I cannot find any programming mistake:
C#
MapLayer pathLayer;
//Constructor
pathLayer = new MapLayer();
MapPolyline line = new MapPolyline();
line.StrokeColor = Colors.Red;
line.StrokeThickness = 10;
//line.Path.Add(several points); Tested, no effect
MapOverlay overlay = new MapOverlay();
overlay.Content = line;
//overlay.GeoCoordinate = new GeoCoordinate(0,0); Tested, no effect
//overlay.PositionOrigin = new Point(0.0, 1.0); Tested, no effect
pathLayer.Add(overlay);
MyMap.Layers.Add(pathLayer);
void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
MapPolyline line = pathLayer.First(TrackPath).Content as MapPolyline;
line.Path.Add(args.Position.Coordinate); // Checked values, line.Path adds them correctly
}
新信息.尝试使用XAML进行添加时,模拟器显示错误,并且模拟器在地图顶部以图形故障的形式显示类的名称:
New info. The emulator shows an error when trying to add it using XAML, and the emulator shows the name of the class on the top of the map as a graphic glitch:
推荐答案
MapPolylines
和MapPolygons
应该添加到MapElements
集合中,而不是MapLayer
或MapOverlay
.
MapPolylines
and MapPolygons
should be added to the MapElements
collection... not a MapLayer
or a MapOverlay
.
您应该能够使此示例为您工作.
You should be able to make this example work for you.
MapPolyline line = new MapPolyline();
line.StrokeColor = Colors.Red;
line.StrokeThickness = 10;
line.Path.Add(new GeoCoordinate(47.6602, -122.098358));
line.Path.Add(new GeoCoordinate(47.561482, -122.071544));
MyMap.MapElements.Add(line);
在GeoCoord观察器中,您必须从地图的MapElements
集合中获取线,并将新位置添加到线的路径中,而不是像我一样预先定义.这应该可行.
In your GeoCoord watcher you'll have to get the line from the map's MapElements
collection, and add the new position to the line's path instead of predefining like I did. This should be doable.
这篇关于未绘制MapPolyline的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!