未绘制 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屋!