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

Add a mapboxgl.EventData option, pass to 'map.fitBounds' and 'map.flyTo' #478

Open Marvosg opened 1 year ago

Marvosg commented 1 year ago

Camera move functions can have additional eventData passed to them, which is passed to event listeners of camera events ('move', 'zoom', etc)

https://docs.mapbox.com/mapbox-gl-js/api/map/#map#flyto https://docs.mapbox.com/mapbox-gl-js/api/map/#map#fitbounds

This is useful for behaviour customization, but very useful for detecting whether a camera event was triggered by the user or programatically, as discussed here mapbox-gl-js/issues/9700

This library already has a single function that initializes all camera moves, _fly, with two usages of fitBounds and one usage of flyTo.

Adding an eventData argument (which is just a user defined object) to these invocations (as the 2nd/3rd parameter respectively) works as expected. Passing undefined as eventData works as expected, too, there is no change compared to the current behaviour and events are not modified.

The eventData could be supplied by the user through the geocoder initialization options, as well as through a function that could update it after instance creation.