【问题标题】:How to zoom a bing map to display a set of lat/long points?如何缩放 bing 地图以显示一组纬度/经度点?
【发布时间】:2011-12-09 12:38:50
【问题描述】:

我正在使用 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);

这行得通,并且创建的地图以这些点为中心。如何设置 Bing 地图的缩放级别以显示整个矩形?

请看这里:http://jsfiddle.net/MQ76x/

【问题讨论】:

    标签: javascript bing-maps


    【解决方案1】:

    忘记传递center/zoompass the rectangle as bounds instead

    var mapOptions = {
      credentials : bingMapsKey,
      bounds      : r, // <-- HERE
      mapTypeId   : Microsoft.Maps.MapTypeId.road
    }
    

    【讨论】:

      【解决方案2】:

      对于像我一样登陆这里并根据位置中心(纬度、经度)和位置半径(以公里为单位)搜索 BingMaps V8 缩放计算的任何人:

      (也许你也在用Microsoft.Maps.SpatialMath在位置中心画一个圆圈)

      function getZoomLevel(radiusInKilometer: number, latitude: number, heightOfMapInPixels: number, widthOfMapInPixels: number): number {
          const rangeInMeters = radiusInKilometer * 1000;
          // we take the lower value of the bounding rect of the map, so the circle will be best seen
          const limitBoundPixels = Math.min(heightOfMapInPixels, widthOfMapInPixels);
          const zoom = Math.floor(Math.log(156543.03392 * Math.cos(latitude * Math.PI / 180) / (rangeInMeters / limitBoundPixels)) / Math.log(2));
      
          return zoom;
      }
      

      【讨论】:

        猜你喜欢
        • 2012-04-14
        • 2012-10-09
        • 2011-03-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-28
        • 2020-08-09
        • 2016-03-06
        相关资源
        最近更新 更多