有没有办法禁用Mapbox-gl在触发GeolocateControl时缩放?

问题描述 投票:0回答:2

我试图在触发 GeolocateControl 时禁用用户位置缩放。 基本上我不想在定位用户时运行

map.flyTo()
函数。

const geolocate = useRef( new mapboxgl.GeolocateControl({
    positionOptions: {
        enableHighAccuracy: true
    },
    trackUserLocation: true,
    showAccuracyCircle: false
}))
javascript maps mapbox
2个回答
0
投票
map.current.addControl(geolocate.current);
geolocate.current.on('geolocate', function(e) {
    map.current.flyTo({
        zoom: map.current.getZoom()
    });
});

好吧,我找到了实现这一目标的方法。


0
投票

以下涉及重写

_updateCamera
GeolocateControl
函数来自定义其行为,有效防止默认缩放到用户位置。

geolocate.current._updateCamera = () => {};
© www.soinside.com 2019 - 2024. All rights reserved.