mapbox-gl-geocoder icon indicating copy to clipboard operation
mapbox-gl-geocoder copied to clipboard

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

Open keithdoggett opened this issue 1 year ago • 2 comments

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 avatar Feb 28 '23 23:02 keithdoggett

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

keithdoggett avatar Mar 01 '23 00:03 keithdoggett

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

fo-rk avatar Jul 20 '23 14:07 fo-rk