我在 bing 地图上设置最佳视图时遇到了一些小问题。
我已经在互联网上找到了一些解决方案,但不幸的是,它们都不适合我。我的必应地图显示多个地址,工作正常,现在我想调整视图,以便我的地图放大我的图钉。
以下是我的源代码:
function addData(locationInput){
counter = 0;
var locationSet = locationInput.split("#");
//Array from Locations
var locs = new Array();
for(var i = 0; i < locationInput.length; i++){
if(i == 0){
locationSet[0] = locationSet[0].substr(1);
}
var locSet = locationSet[i].split(";");
var location = new Microsoft.Maps.Location(locSet[0], locSet[1]);
locs.push(location);
var pushpin=new Microsoft.Maps.Pushpin(location,{text:counter.toString()});
map.entities.push(pushpin);
counter++;
console.log(this);
}
//Set view boundaries
map.setView({bounds: Microsoft.Maps.LocationRect.fromLocations(locs)});
}
当您从您的位置计算 LocationRect 时,它将紧贴坐标,并且不考虑图钉图标的大小。您可以设置视图设置填充值以说明这一点。试试这个:
map.setView({bounds: Microsoft.Maps.LocationRect.fromLocations(locs), padding: 100});
由于map.setview是异步的,因此视图有时无法正确加载。添加延迟可以为我解决问题。
setTimeout((function () {
map.setView({bounds: Microsoft.Maps.LocationRect.fromLocations(locs)});
}).bind(this), 1500);