Bing Maps route poly line can not be removed from map
I have the following xaml to bind an instance of the class LocationCollection
to an instance of the class MapPolyline
.
<Microsoft_Phone_Controls_Maps:MapPolyline Stroke="Green"
Locations="{Binding Points}"
StrokeThickness="6"
Opacity="0.7" />
The Points
property is defined in the ViewModel as:
public LocationCollection Po开发者_如何学Goints
{
get
{
return this.points;
}
set
{
this.SetPropertyAndNotify(ref this.points, value, "Points");
}
}
Now when I set the Points
property the route line is displayed as expected but when I want to remove the line with the following code the line is still displayed - even though I've created a new empty LocationCollection
class and notify the property has changed.
Anyone got any idea why the route line is not removed?
this.Points = new LocationCollection();
The answer is setting the collection to a new instance or clearing the current collection completely is wrong, what I had to do was remove all but the first item from the collection.
e.g.
private void ResetPoints()
{
if (this.Points.Count() > 0)
{
var firstPoint = this.Points.First();
this.Points.Clear();
this.Points.Add(firstPoint);
}
}
create route layer with this
MapLayer route_layer = new MapLayer();
create line with MapPolyline such as
MapPolyline routeLine = new MapPolyline()
{
Locations = locs,
Stroke = new SolidColorBrush(c),
StrokeThickness = 5
};
add to your route layer and then map with this
route_layer.Children.Add(routeLine);
MyMap.Children.Add(route_layer);
remove from your map with this.
MyMap.Children.Remove(route_layer);
精彩评论