Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaflet search: limit search area? #168

Open
jzadra opened this issue Jul 8, 2019 · 3 comments
Open

Leaflet search: limit search area? #168

jzadra opened this issue Jul 8, 2019 · 3 comments

Comments

@jzadra
Copy link

jzadra commented Jul 8, 2019

Is there any way to limit the search results either to the area being viewed on the map, or by hardcoding it (for instance just for North Carolina, or a certain county)?

I'm not clear on whether the filterData would allow this, as the documentation doesn't explain the arguments/parameters.

@alenastern
Copy link

Hello! @trafficonese - has this question been answered anywhere? I would like to do something similar in an RShiny app that I am working on. Thank you!!

@trafficonese
Copy link
Owner

I dont think it's possible currently. When you search in OSM you will always query the whole world.
The filterData argument is only relevant for the addSearchFeatures function.

Here is an example in the JS-library:
https://github.com/stefanocudini/leaflet-search/blob/d29c5392b33cc31b338c3d17b5f8532fef5eae48/examples/fuzzy.html#L71
https://opengeo.tech/maps/leaflet-search/examples/fuzzy.html

This has to be tackled in the upstream JS repo:
stefanocudini/leaflet-search#231

@trafficonese
Copy link
Owner

Would it be enough to just add a country or state as filter?
The search plugin uses the free-form-query from Nominatim

Free-form queries are processed first left-to-right and then right-to-left if that fails. So you may search for pilkington avenue, birmingham as well as for birmingham, pilkington avenue. Commas are optional, but improve performance by reducing the complexity of the search.

So the idea would be to have a restrictTo argument that is always at the start of a query. So for example I want to restrict my queries to Austria & find all objects named Vienna, it would look like this:

https://nominatim.openstreetmap.org/search?format=json&q=Austria,Vienna
instead of just
https://nominatim.openstreetmap.org/search?format=json&q=Vienna

This should result in shorter search results and improve the search speed.

and ideally I could make the filter as long as possible..
so for example if I want to find all objects named Cannstätter in Germany and the region Neckarvorstadt:
https://nominatim.openstreetmap.org/search?format=json&q=Germany,Neckarvorstadt,Cannstätter

Unfortunately the plugin doesn't offer this option currently, but it would be a small addition and quick PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants