在Mapbox

时间:2017-11-10 14:00:56

标签: mapbox-gl-js

我使用Mapbox创建查看器,查看器将全屏显示。但是,屏幕的一半将覆盖浮动UI组件。因此,如果地图缩放到某个要素,则应将该要素定位在屏幕另一半的中心。什么是接近这个的好方法?

目前,当我缩放到某个功能时,它将如下所示,由UI组件覆盖:

Currently when I zoom to a feature it will look like this, covered by the UI component:

我希望它能自动集中在观众的一半上,如下所示:

I want it to automatically center on one half of the viewer, like this:

1 个答案:

答案 0 :(得分:1)

fitBounds method允许您传递padding的选项,例如:

map.fitBounds([[min_lon, min_lat], [max_lon, max_lat]], {
    padding: {
        top: 5,
        bottom: 5,
        left: 5,
        right: document.getElementById('your_div').offsetWidth + 5
    },
    linear: true,
    duration: 0
});
相关问题