简体   繁体   English

有没有办法在JavaScript中以编程方式放大或平移Bing地图?

[英]Is there a way to programmatically zoom in or pan a Bing map in javascript?

After an exhaustive search, I decided to ask here: I would like to initialize a Bing map from a distance and then zoom in to about level 8. I was thinking after a set time to then zoom out a ways and then pan to a new location and then zoom in again. 经过详尽的搜索后,我决定在这里问:我想从远处初始化一个Bing地图,然后放大到大约8级。我想在设定的时间后缩小范围,然后平移到一个新的位置。位置,然后再次放大。

Is this possible using the javascript API? 是否可以使用javascript API? I've only seen examples of doing this in WPF or Silverlight. 我只看到在WPF或Silverlight中执行此操作的示例。

If understand your question, you need to create map passing the container of the map. 如果了解您的问题,则需要创建一个通过地图容器的地图。 In that way the map is created with options set to null. 通过这种方式,可以将选项设置为null来创建地图。

var oMap = new Microsoft.Maps.Map(divMapContainer, null)

After the map is displayed you call setView method, and passing optional parameters as object. 显示地图后,您调用setView方法,并将可选参数作为对象传递。

The optional parameters are center and zoom. 可选参数是居中和缩放。

setTimeout(function () {
     oMap.setView({
          center: new Microsoft.Maps.Location(0, 0),
          zoom: 8
     });
}, 1000);

The function executed after one second in order to give a map some time to finish loading. 该功能在一秒钟后执行,以便给地图一些时间来完成加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM