bergmania / Bergmania.OpenStreetMap

MIT License
4 stars 7 forks source link

Add basic search functionality #6

Closed bjarnef closed 3 years ago

bjarnef commented 3 years ago

Currently there is no easy way to find a specific address except zooming, panning and dragging the marker to a location.

It would be great to add a basic search feature to search a city or address.

There are different ways to solve this.

Esri Leaflet http://esri.github.io/esri-leaflet/

Leaflet.Control.Search https://opengeo.tech/maps/leaflet-search/

Alternatively it can also be a separate search input using the API from https://nominatim.openstreetmap.org https://nominatim.org/release-docs/latest/api/Search/

bjarnef commented 3 years ago

I had a look at different approaches. The Esri plugin seems to be great but rely on the ArcGIS Online World Geocoding Service https://github.com/Esri/esri-leaflet-geocoder#terms-and-conditions and seems to require a subscription to use in production.

Leaflet.Control.Search seems to be offer many features as well, but doesn't look great out-of-the-box when using search outside the map.

I found examples using OpenLayers instead of Leaflet - both have pros and cons. For example something like this extension for Joomla seems to use OpenLayers: https://www.tassos.gr/joomla-extensions/advanced-custom-fields/docs/the-openstreetmap-field

Some examples I found requires an API Key although free to signup - some of these seems to have been a paid product or paid by number of request (similar to Google Maps).

However I found this example instead, which may work well using Leaflet: https://github.com/tomik23/Leaflet.Autocomplete There's a demo available here: https://tomik23.github.io/Leaflet.Autocomplete/

We could add a configuration property to hide/show search (but by default it think it make sense to show search by default).