From 8e404c4f3cf7880681b6f4cdf3c378e084ad54d2 Mon Sep 17 00:00:00 2001 From: hellekin Date: Tue, 2 Feb 2021 18:39:14 +0100 Subject: Add leaflet-geosearch This Leaflet plugin adds a live address search on the map. We anticipate the possibility to find POIs from their address, or to check whether an address is already in the database. For now it enables looking up an address. https://smeijer.github.io/leaflet-geosearch/leaflet-control/ --- app/javascript/controllers/map_controller.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'app/javascript/controllers') diff --git a/app/javascript/controllers/map_controller.js b/app/javascript/controllers/map_controller.js index 57bafa5..0a64f98 100644 --- a/app/javascript/controllers/map_controller.js +++ b/app/javascript/controllers/map_controller.js @@ -19,6 +19,7 @@ import "leaflet.markercluster/dist/leaflet.markercluster.js" import 'leaflet-extra-markers' import 'leaflet-easyprint' +import { GeoSearchControl, OpenStreetMapProvider } from 'leaflet-geosearch'; export default class extends Controller { static targets = [ "container" ] @@ -75,6 +76,15 @@ export default class extends Controller { sizeModes: ['A4Portrait', 'A4Landscape'] }).addTo(this.map); + /* Add search */ + const provider = new OpenStreetMapProvider(); + const searchControl = new GeoSearchControl({ + provider: provider, + style: 'button', + position: 'bottomright' + }); + this.map.addControl(searchControl); + // Allow calling the mapController from elsewhere. this.element[this.identifier] = this } -- cgit v1.2.3