开发者

Bing Maps route poly line can not be removed from map

开发者 https://www.devze.com 2023-03-06 03:00 出处:网络
I have the following xaml to bind an instance of the class LocationCollection to an instance of the class MapPolyline.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号