我正在我的Mapbox地图中添加GeolocateControl。它工作正常并显示我当前的位置。但是,它缩放得太多了。默认情况下,我的地图缩放为10。但是,当我单击GeolocateControl时,它会移动到新目的地并缩小。我尝试添加缩放:10,但是没有运气...
map.addControl(
new mapboxgl.GeolocateControl({
zoom: 10,
positionOptions: {
enableHighAccuracy: true
},
trackUserLocation: true,
})
);
遵循文档有些费时,但是基本上不是直接在您提供的对象上使用zoom
,而是需要在名为fitBoundsOptions
的对象上使用:
map.addControl(
new mapboxgl.GeolocateControl({
fitBoundsOptions: {
zoom: 10,
},
positionOptions: {
enableHighAccuracy: true
},
trackUserLocation: true,
})
);