必应地图JS API设置地图中心比例尺边界

时间:2018-12-05 14:29:33

标签: javascript bing-api

我有一个根函数可以按如下方式绘制地图图块,有没有一种方法可以根据窗口大小,特定位置的中心地图和极限地图范围设置初始缩放?

const renderMap = () => {
    window.map = new Microsoft.Maps.Map('#map', {
            showDashboard: false,
            enableClickableLogo: false,
            showScalebar: false,
            showTermsLink: false,
            mapTypeId: Microsoft.Maps.MapTypeId.grayscale
    });
}

1 个答案:

答案 0 :(得分:0)

const renderMap = () => {
    let windowHeight = window.innerHeight;
    let meterToPixRatio = 850000 / windowHeight;
    let scale = Math.floor(-1.4430 * Math.log(meterToPixRatio / 156434));
    let x = 
    let y = 
    let xextent = 
    let yextent = 
    window.map = new Microsoft.Maps.Map('#map', {
            ...
            zoom: scale,
            center: centerLocation = new Microsoft.Maps.Location(x, y),
            maxBounds: new Microsoft.Maps.LocationRect(centerLocation, xextent, yextent),
    });
}