设置BingMap缩放更大的LocationRect

时间:2014-03-14 10:45:47

标签: c# bing-maps windows-8.1

我试图将Bing Map的缩放级别设置为比LocationRect略微更靠后。我环顾四周,无法找到任何相关信息。这是设置地图视图的代码

myMap.SetView(new LocationRect(locationCollection));

用于 Windows 8 App XAML/C#: Set multiple pushpins to Bing map in one method

2 个答案:

答案 0 :(得分:6)

我偶然发现过这种情况。通常人们从图钉使用的位置集合创建LocationRect,然后设置视图以发现某些图钉不在视图范围内。这是因为LocationRect没有考虑图钉的像素大小,只关注坐标。在V7中,我们可以选择添加填充,但同样的选项不在Windows Store SDK中。我写了一篇博客文章回顾了如何根据缓冲区()的位置集合计算最佳地图视图。使用这个我把这个可重用的方法放在一起,用于计算带缓冲区的边界框的缩放级别。然后,您可以使用此缩放级别和LocationRect的center属性来设置地图视图。

public double CalculateZoomLevel(LocationRect boundingBox, double buffer, Map map)
{
    double zoom1=0, zoom2=0; 

    //best zoom level based on map width
    zoom1 = Math.Log(360.0 / 256.0 * (map.ActualWidth - 2*buffer) / boundingBox.Width) / Math.Log(2);

    //best zoom level based on map height
    zoom2 = Math.Log(180.0 / 256.0 * (map.ActualHeight - 2*buffer) / boundingBox.Height) / Math.Log(2);

    //use the most zoomed out of the two zoom levels
    var zoomLevel = (zoom1 < zoom2) ? zoom1 : zoom2;

    return zoomLevel;
}

答案 1 :(得分:0)

不幸的是,据我所知,没有像我们在AJAX v7中那样的“填充”选项。

您可能要做的就是添加假位置LocationCollection,这样您就可以手动扩展区域(您可以使用缩放级别和位置来计算地图分辨率,以便更好地定位那些虚假的位置)