mapbox-gl-geocoder
mapbox-gl-geocoder copied to clipboard
Geocoder flies to wrong location when using the `naturalEarth` projection
When selecting a location with the naturalEarth
projection, places selected from the geocoder will fly to the wrong location (but the pin is placed in the correct location).
This does not happen for poi
types from the dropdown so I think it has something to do with the bbox
property of the geocoder API response not being projected since POIs that worked don't have a bbox
property in the response.
Here's a fiddle I was able to reproduce it on.
https://jsfiddle.net/qL7064jz/
And a video demonstrating the bug
https://user-images.githubusercontent.com/12189611/222004827-fd7d5e34-4ad5-43c9-b745-98eeb002afde.mov
If you need any more details let me know.
Likely related to this https://github.com/mapbox/mapbox-gl-js/issues/12565
This is what helped for us. We disabled built-in flyTo
and handled ourselves using the center of the result from geocoder. Works with naturalEarth
.
var geocoder = new MapboxGeocoder({
accessToken: mapboxgl.accessToken,
mapboxgl: mapboxgl,
flyTo: false,
})
map.addControl(
geocoder,
'top-right'
)
geocoder.on('result', ({result}) => {
map.flyTo({
center: result.center,
zoom: 12
})
})