簡體   English   中英

如何縮放bing貼圖以顯示一組緯度/經度?

[英]How to zoom a bing map to display a set of lat/long points?

我正在使用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 Map的縮放級別,以便顯示整個矩形?

見這里: http//jsfiddle.net/MQ76x/

忘記傳遞center / zoom ,並將矩形作為bounds傳遞

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

對於任何以我身份登陸並根據位置中心(緯度,經度)和以千米為單位的位置半徑搜索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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM