放大位置数组

时间:2015-03-16 16:46:23

标签: javascript view bing-maps

我正面临一些关于在bing地图上设置最佳视图的小问题。

我已经在互联网上找到了一些解决方案但很遗憾没有一个能为我工作。 我的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)});
     }

2 个答案:

答案 0 :(得分:0)

当您从您的位置计算LocationRect时,它将紧靠坐标并且不会考虑图钉图标的大小。您可以将视图集设置为填充值以解决此问题。试试这个:

 map.setView({bounds: Microsoft.Maps.LocationRect.fromLocations(locs), padding: 100});

答案 1 :(得分:0)

由于map.setview是异步的,因此有时无法正确加载视图。为它添加延迟解决了我的问题。

setTimeout((function () {
                map.setView({bounds: Microsoft.Maps.LocationRect.fromLocations(locs)});
            }).bind(this), 1500);