我试图在触发 GeolocateControl 时禁用用户位置缩放。 基本上我不想在定位用户时运行
map.flyTo()
函数。
const geolocate = useRef( new mapboxgl.GeolocateControl({
positionOptions: {
enableHighAccuracy: true
},
trackUserLocation: true,
showAccuracyCircle: false
}))
map.current.addControl(geolocate.current);
geolocate.current.on('geolocate', function(e) {
map.current.flyTo({
zoom: map.current.getZoom()
});
});
好吧,我找到了实现这一目标的方法。
以下涉及重写
_updateCamera
的 GeolocateControl
函数来自定义其行为,有效防止默认缩放到用户位置。
geolocate.current._updateCamera = () => {};