Esri / esri-leaflet-geocoder

helpers for using the ArcGIS World Geocoding Service in Leaflet
http://esri.github.io/esri-leaflet/examples/geocoding-control.html
Apache License 2.0
242 stars 97 forks source link

How are you cancelling pending requests during typing? #205

Closed slead closed 6 years ago

slead commented 6 years ago

Looking at the sample at https://esri.github.io/esri-leaflet/examples/geocoding-control.html with the debugger open, I can see that as the user keeps typing in the search box, the pending requests are cancelled and only the final request (once they stop typing) actually executes.

How is this handled? I'm executing the geocoding request outside of the map frame (rather than using your tool), hence I'm calling the requests manually using the L.esri.Geocoding.geocode() function and I'd like to emulate the "cancel pending requests" functionality.

Thanks

jgravois commented 6 years ago

we create an array of pendingSuggestions and loop through them and call abort() each time another key is pressed.

relevant logic: https://github.com/Esri/esri-leaflet-geocoder/blob/master/src/Controls/Geosearch.js#L314-L319

https://github.com/Esri/esri-leaflet-geocoder/blob/master/src/Classes/GeosearchCore.js#L116-L117

slead commented 6 years ago

many thanks