diff --git a/js/plugin/Search.js b/js/plugin/Search.js index c56e6df..2f3064a 100644 --- a/js/plugin/Search.js +++ b/js/plugin/Search.js @@ -1,29 +1,28 @@ -BR.Search = L.Control.Geocoder.extend({ - options: { - geocoder: new L.Control.Geocoder.LatLng({ - next: new L.Control.Geocoder.Nominatim({ - serviceUrl: 'https://nominatim.openstreetmap.org/', - }), - sizeInMeters: 800, - }), - position: 'topleft', - 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'), - }); +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/', + }), + sizeInMeters: 800, + }), + position: 'topleft', + shortcut: { + search: 70, // char code for 'f' + }, + 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(); } - }, -}); + } +}; diff --git a/package.json b/package.json index f1f273e..1f18958 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/yarn.lock b/yarn.lock index faaecb1..94d9675 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"