mapbox / mapbox-gl-geocoder

Geocoder control for mapbox-gl-js using Mapbox Geocoding API
https://mapbox.com/mapbox-gl-js/example/mapbox-gl-geocoder/
ISC License
362 stars 181 forks source link

Geocoder flies to wrong location when using the `naturalEarth` projection #489

Open keithdoggett opened 1 year ago

keithdoggett commented 1 year ago

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.

keithdoggett commented 1 year ago

Likely related to this https://github.com/mapbox/mapbox-gl-js/issues/12565

fo-rk commented 1 year ago

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
  })
})