Update leaflet-control-geocoder (#296)

Switch BR.Search to ES6 class because L.Control.Geocoder is now an ES6 class and Leaflet L.Class.extend doesn't work anymore (undefined).
This commit is contained in:
Norbert Renner 2021-03-26 21:13:38 +01:00
parent cd8ac29aab
commit fbcfd8cf8e
3 changed files with 33 additions and 34 deletions

View file

@ -1,5 +1,8 @@
BR.Search = L.Control.Geocoder.extend({
options: {
BR.Search = class extends L.Control.Geocoder {
constructor(options) {
super(
Object.assign(
{
geocoder: new L.Control.Geocoder.LatLng({
next: new L.Control.Geocoder.Nominatim({
serviceUrl: 'https://nominatim.openstreetmap.org/',
@ -10,20 +13,16 @@ BR.Search = L.Control.Geocoder.extend({
shortcut: {
search: 70, // char code for 'f'
},
},
initialize: function (options) {
L.Control.Geocoder.prototype.initialize.call(this, options);
L.setOptions(this, {
// i18next.t will only return 'undefined' if it is called in a static context
// (e.g. when added directly to "options:" above), so we have to call it here
placeholder: i18next.t('map.geocoder-placeholder'),
});
},
options
)
);
L.DomEvent.addListener(document, 'keydown', this._keydownListener, this);
},
}
markGeocode: function (result) {
markGeocode(result) {
this._map.fitBounds(result.geocode.bbox, {
maxZoom: 17,
});
@ -37,18 +36,18 @@ BR.Search = L.Control.Geocoder.extend({
}).addTo(this._map);
return this;
},
}
clear: function () {
clear() {
if (this._geocodeMarker) {
this._map.removeLayer(this._geocodeMarker);
}
},
}
_keydownListener: function (e) {
_keydownListener(e) {
if (BR.Util.keyboardShortcutsAllowed(e) && e.keyCode === this.options.shortcut.search) {
$('#map .leaflet-control-geocoder')[0].dispatchEvent(new MouseEvent('mousedown'));
e.preventDefault();
}
},
});
}
};

View file

@ -57,7 +57,7 @@
"jquery-i18next": "^1.2.1",
"jstree": "^3.3.8",
"leaflet": "~1.6.0",
"leaflet-control-geocoder": "^1.13.0",
"leaflet-control-geocoder": "^2.2.0",
"leaflet-easybutton": "*",
"leaflet-editable": "^1.1.0",
"leaflet-filelayer": "^1.2.0",

View file

@ -6554,10 +6554,10 @@ lead@^1.0.0:
dependencies:
flush-write-stream "^1.0.2"
leaflet-control-geocoder@^1.13.0:
version "1.13.0"
resolved "https://registry.yarnpkg.com/leaflet-control-geocoder/-/leaflet-control-geocoder-1.13.0.tgz#c84cffd8f64a8f0b1091a59c3b59c03d5dcc583e"
integrity sha512-mgYGx/2WA5CcvhP+IJtw7VvJwSGAe5zxX+TKe6ruYkLj2W5I5V/K/nQiLvsUtqifBojBGoKIPNZ8m0mXJNIudg==
leaflet-control-geocoder@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/leaflet-control-geocoder/-/leaflet-control-geocoder-2.2.0.tgz#c2ebf1913acae683d995769f8652f61b0508122f"
integrity sha512-OSnKVIeSZQUXGsErunUBhLbXf2YPRBADaStKipkD3/yrtsZAhLiyFoNHmhjP1nAqD6KO63A98xGfVs4EroFvFA==
optionalDependencies:
open-location-code "^1.0.0"