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 ++++++++++ app/javascript/packs/application.js | 1 + app/javascript/scss/application.scss | 1 + 3 files changed, 12 insertions(+) (limited to 'app') 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 } diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 0ddfdb5..ea65dca 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -18,6 +18,7 @@ import "../scss/application" //= require leaflet //= require leaflet-defaulticon-compatibility +//= require leaflet-geosearch //= require leaflet.markercluster import "controllers" diff --git a/app/javascript/scss/application.scss b/app/javascript/scss/application.scss index 3bf6259..2775c69 100644 --- a/app/javascript/scss/application.scss +++ b/app/javascript/scss/application.scss @@ -28,6 +28,7 @@ /* Vendors */ @import "leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.webpack.css"; +@import "leaflet-geosearch/dist/geosearch.css"; @import "leaflet.markercluster/dist/MarkerCluster.css"; @import "leaflet.markercluster/dist/MarkerCluster.Default.css"; -- cgit v1.2.3