gpt4 book ai didi

c# - WPF Bing map - 缩放至折线

转载 作者:行者123 更新时间:2023-12-04 08:18:13 25 4
gpt4 key购买 nike

我创建了一个 WPF Bing map 并添加了折线,我想设置适合折线的中心和缩放级别。像 map.fitBounds(bounds)。

MapPolyline polyline = new MapPolyline();
polyline.Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.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);

最佳答案

您可以获得 IEnumerable<Location>来自 LocationCollection 的多段线,然后使用重载 SetView 缩放到位置。此重载还允许您设置边距。

myMap.SetView(polyline.Locations.Cast<Location>(), 
new System.Windows.Thickness(0), 0);
或者您可以创建一个 LocationRect 来自 LocationCollection 然后使用另一个重载 SetView 缩放到矩形。
myMap.SetView(new LocationRect(polyline.Locations));
示例 1 - IEnumerable<位置>
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);
示例 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));
enter image description here

关于c# - WPF Bing map - 缩放至折线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65615406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com