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

Multiple osm_tag to filter Photon result #196

Closed
marcus-at-localhost opened this issue Mar 4, 2018 · 4 comments
Closed

Multiple osm_tag to filter Photon result #196

marcus-at-localhost opened this issue Mar 4, 2018 · 4 comments

Comments

@marcus-at-localhost
Copy link

Hi,
it's possible to add multiple osm_tag parameter to filter photon results for osm_key and osm_value fields. https://github.com/komoot/photon/blob/master/README.md#user-content-filter-results-by-tags-and-values

To filter all shops from the result set I would do this.

M.geocoder = L.Control.geocoder({
	geocoder: L.Control.Geocoder.photon({
		geocodingQueryParams: {
			limit: 8,
			osm_tag: '!shop'
		}
	})
})

Which translate to: https://photon.komoot.de/api/?q=kaufland&limit=8&osm_tag=!shop

But of course it is not possible to have multiple osm_tag params
https://photon.komoot.de/api/?q=kaufland&limit=8&osm_tag=!shop&osm_tag=!landuse
since same keys are getting merged:

geocodingQueryParams: {
	osm_tag: '!shop',
	osm_tag: '!landuse',
}

And when I look at the utils/getJSON function I don't see how to make this work with only changing the Photon provider plugin.

Any idea?

@simon04
Copy link
Collaborator

simon04 commented Mar 5, 2018

Specifying two identical keys for the JavaScript object cannot work, since the second one overrides the first one. An option would be to specify an array of osm_tag, but this function https://github.com/Leaflet/Leaflet/blob/6708981c7474109211162103037b28c26724ed51/src/core/Util.js#L145-L156 does not handle arrays.

geocodingQueryParams: {
	osm_tag: ['!shop', '!landuse']
}

We could either file a PR for Leaflet, or copy & modify this function in leaflet-control-geocoder.

@marcus-at-localhost
Copy link
Author

marcus-at-localhost commented Mar 5, 2018

I think photon is not really standard conform here. The right way to do it is osm_tag[]=x&osm_tag[]=y so in this case this hack should be made in the leaflet-control-geocoder lib. I'm not really familiar with the build process of this lib, else I would give it a shot. Maybe I'll try it.
Edit: I forked it, and I have no clue how to test changes. :/

@marcus-at-localhost
Copy link
Author

marcus-at-localhost commented Mar 5, 2018

What if params can be also a string and the query gets build in the provider plugin for this special case?

export function getJSON(url, params, callback) {
 //...
   if (typeof params === 'object') {
        url += L.Util.getParamString(params);
    }else{
       url += params;
    }
  xmlHttp.open('GET', url, true);
 // ...
}

@simon04
Copy link
Collaborator

simon04 commented Sep 3, 2018

Since 2d06ebf, the following should work and yield the URL ...&osm_tag=!shop&osm_tag=!landuse:

geocodingQueryParams: {
	osm_tag: ['!shop', '!landuse']
}

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

No branches or pull requests

2 participants