在 Mapbox 中定义地图中心

Define center of map in Mapbox

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

目前,当我缩放到某个要素时,它看起来像这样,被 UI 组件覆盖:

我希望它自动以观众的一半为中心,像这样:

fitBounds method allows you to pass an option for 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
});