如何缩放bing贴图以显示一组纬度/经度?

Che*_*eso 5 javascript bing-maps

我正在使用Bing Maps v7控件.

我有一系列纬度/经度点.(类型Microsoft.Map.Location)

从该数组中,我可以使用生成矩形和矩形的中心 LocationRect.fromLocations()

使用Map构造函数创建地图时,我可以使用该矩形的中心来居中地图.它看起来像这样:

    var LLA = [
       new Microsoft.Maps.Location(43.386,-111.6123),
       new Microsoft.Maps.Location(43.4929, -112.0349),
       new Microsoft.Maps.Location(43.2609,-115.7811),
       ...
    ];
    var r = Microsoft.Maps.LocationRect.fromLocations(LLA);
    var mapOptions = {
        credentials : bingMapsKey,
        center      : r.center,
        mapTypeId   : Microsoft.Maps.MapTypeId.road,
        zoom        : 7
    },
    elt = document.getElementById('out2');
    var map = new Microsoft.Maps.Map(elt, mapOptions);
Run Code Online (Sandbox Code Playgroud)

这是有效的,创建的地图以这些点为中心.如何设置Bing Map的缩放级别,以便显示整个矩形?

见这里:http://jsfiddle.net/MQ76x/

Roa*_*rth 8

忘记传递center/ zoom通过矩形作为bounds代替:

var mapOptions = {
  credentials : bingMapsKey,
  bounds      : r, // <-- HERE
  mapTypeId   : Microsoft.Maps.MapTypeId.road
}
Run Code Online (Sandbox Code Playgroud)