You can get an IEnumerable<Location>
from LocationCollection
of your polyline and then use an overload of SetView
to zoom to the locations. This overload allows you to set a margin as well.
myMap.SetView(polyline.Locations.Cast<Location>(),
new System.Windows.Thickness(0), 0);
Or you can create a LocationRect
from LocationCollection
of your polyline and then use another overload of SetView
to zoom to the rectangle.
myMap.SetView(new LocationRect(polyline.Locations));
Exampel 1 - IEnumerable<Location>
MapPolyline polyline = new MapPolyline();
polyline.Stroke = new SolidColorBrush(Colors.Blue);
polyline.Locations = new LocationCollection() {
new Location(47.6424, -122.3219),
new Location(47.8424,-122.1747),
new Location(47.67856,-122.130994)};
myMap.Children.Add(polyline);
myMap.SetView(polyline.Locations.Cast<Location>(),
new System.Windows.Thickness(0), 0);
Example 2 - LocationRect
MapPolyline polyline = new MapPolyline();
polyline.Stroke = new SolidColorBrush(Colors.Blue);
polyline.Locations = new LocationCollection() {
new Location(47.6424, -122.3219),
new Location(47.8424,-122.1747),
new Location(47.67856,-122.130994)};
myMap.Children.Add(polyline);
myMap.SetView(new LocationRect(polyline.Locations));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…