如何缩放地图以一次显示地图中的所有图钉? 我使用“Bing Maps AJAX Control,7.0版”。 谢谢!
答案 0 :(得分:2)
有一种名为LocationRect
的方法可用于此目的。以下是MSDN的示例:
function init(){
// Load the map
var map = new Microsoft.Maps.Map(
document.getElementById("myMap"),
{
credentials: "YOUR-BING-KEY",
mapTypeId: Microsoft.Maps.MapTypeId.road
}
);
// Some sample pins
var locs = [];
var loc1 = new Microsoft.Maps.Location(-10, 0);
var pin1 = new Microsoft.Maps.Pushpin(loc1 , {text: '1'});
var loc2 = new Microsoft.Maps.Location(0, 10);
var pin2 = new Microsoft.Maps.Pushpin(loc2, {text: '2'});
var loc3 = new Microsoft.Maps.Location(10, 0);
var pin3 = new Microsoft.Maps.Pushpin(loc3, {text: '3'});
var loc4 = new Microsoft.Maps.Location(20, -20);
var pin4 = new Microsoft.Maps.Pushpin(loc4, {text: '4'});
locs.push(loc1);
locs.push(loc2);
locs.push(loc3);
locs.push(loc4);
map.entities.push(pin1);
map.entities.push(pin2);
map.entities.push(pin3);
map.entities.push(pin4);
var bestview = Microsoft.Maps.LocationRect.fromLocations(locs);
map.setView({bounds:bestview });
}