ipyleaflet icon indicating copy to clipboard operation
ipyleaflet copied to clipboard

Add photon support for SearchControl

Open giswqs opened this issue 3 years ago • 1 comments

Due to the Nominatim Usage Policy, leafmap can't have the nominatim URL hard coded in the SearchControl. As suggested by @martinfleis, photon seems a good alternative. However, the two APIs return different formats of results, i.e., nominatim returns a list while photon returns a dictionary. The keys of the dictionary are also different. I looked into leaflet-search, it seems to have functionality for reformatting the query result (e.g., the formatData option). However, I am not quite sure how to make it work with ipyleaflet.

And advice? @stefanocudini @martinRenou @davidbrochart @sackh

from ipyleaflet import Map, SearchControl, Marker, AwesomeIcon

m = Map(zoom=3, center=[19.1646, 72.8493])

marker = Marker(icon=AwesomeIcon(name="check", marker_color='green', icon_color='darkgreen'))

m.add_control(SearchControl(
  position="topleft",
  url='https://photon.komoot.io/api/?q={s}',
  #   url='https://nominatim.openstreetmap.org/search?format=json&q={s}',
  zoom=5,
  marker=marker
))

m

https://nominatim.openstreetmap.org/search?format=json&q=berlin image

https://photon.komoot.io/api/?q=berlin image

giswqs avatar Jan 22 '22 18:01 giswqs

Unfortunately, it's unlikely that we can make formatData work with the ipyleaflet SearchControl.

If that makes sense, you can probably make your own PhotonSearchControl widget, where you use formatData JavaScript side to get the proper result.

martinRenou avatar Jan 24 '22 08:01 martinRenou

I was looking for similar functionality in leafmap (which uses ipyleaflet as a default backend). formatData might be workable if the user can pass a Javascript function to the SearchControl.

prusswan avatar Dec 24 '23 21:12 prusswan