leaflet-control-geocoder
leaflet-control-geocoder copied to clipboard
Latest version breaks integration with leaflet-routing-machine
The latest version of leaflet-geocoder seems to break its integration with leaflet-routing-machine.
The "start" and "end" address textboxes on the main demo are non-functional. Other geocoder demos are also affected. I reproduced the issue locally and confirmed that downgrading leaflet-geocoder to version 2.4.0 resolves the problem. This suggests a regression in recent updates.
If you need to use 3.* version with leaflet-routing-machine, you can make geocoder compatible with this simple hack
function RoutingMachineGeocoder(geocoder) {
const geocode = geocoder.geocode;
if ('AsyncFunction' === geocode[Symbol.toStringTag]) {
geocoder.geocode = function (query, callback, context) {
geocode.apply(this, [query]).then(callback.bind(context));
};
}
const reverse = geocoder.reverse;
if ('AsyncFunction' === reverse[Symbol.toStringTag]) {
geocoder.reverse = function (location, scale, callback, context) {
reverse.apply(this, [location, scale]).then(callback.bind(context));
};
}
return geocoder;
}
const Geocoder = RoutingMachineGeocoder(L.Control.Geocoder.nominatim());
But this should be handled by leaflet-routing-machine