Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

c# - MapPolyline not being drawn

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
}

EDIT: 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:

Emulator error on top, XAML on the right

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...