diff options
| author | Adam Tauber <asciimoo@gmail.com> | 2014-11-19 16:19:03 +0100 |
|---|---|---|
| committer | Adam Tauber <asciimoo@gmail.com> | 2014-11-19 16:19:03 +0100 |
| commit | 075a5fe8985dcd3e675e7249755ab211da7a5ce4 (patch) | |
| tree | 3b343fae9708407151932ff17f4434e8372be1f2 /searx/engines | |
| parent | 1a81c20d738cdd760805ae597e611026ea007f3f (diff) | |
| parent | 807db97690e8421c0995860ec9644a8bbe084cba (diff) | |
Merge pull request #127 from pointhi/template_oscar_map
Template oscar, add map support
Diffstat (limited to 'searx/engines')
| -rw-r--r-- | searx/engines/openstreetmap.py | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/searx/engines/openstreetmap.py b/searx/engines/openstreetmap.py index ea7251486..f727ca8ea 100644 --- a/searx/engines/openstreetmap.py +++ b/searx/engines/openstreetmap.py @@ -15,7 +15,7 @@ categories = ['map'] paging = False # search-url -url = 'https://nominatim.openstreetmap.org/search/{query}?format=json' +url = 'https://nominatim.openstreetmap.org/search/{query}?format=json&polygon_geojson=1&addressdetails=1' result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}' @@ -38,9 +38,54 @@ def response(resp): osm_type = r.get('osm_type', r.get('type')) url = result_base_url.format(osm_type=osm_type, osm_id=r['osm_id']) + + osm = {'type':osm_type, + 'id':r['osm_id']} + + geojson = r.get('geojson') + + # if no geojson is found and osm_type is a node, add geojson Point + if not geojson and\ + osm_type == 'node': + geojson = {u'type':u'Point', + u'coordinates':[r['lon'],r['lat']]} + + address_raw = r.get('address') + address = {} + + # get name + if r['class'] == 'amenity' or\ + r['class'] == 'shop' or\ + r['class'] == 'tourism' or\ + r['class'] == 'leisure': + if address_raw.get('address29'): + address = {'name':address_raw.get('address29')} + else: + address = {'name':address_raw.get(r['type'])} + + # add rest of adressdata, if something is already found + if address.get('name'): + address.update({'house_number':address_raw.get('house_number'), + 'road':address_raw.get('road'), + 'locality':address_raw.get('city', + address_raw.get('town', + address_raw.get('village'))), + 'postcode':address_raw.get('postcode'), + 'country':address_raw.get('country'), + 'country_code':address_raw.get('country_code')}) + else: + address = None + # append result - results.append({'title': title, + results.append({'template': 'map.html', + 'title': title, 'content': '', + 'longitude': r['lon'], + 'latitude': r['lat'], + 'boundingbox': r['boundingbox'], + 'geojson': geojson, + 'address': address, + 'osm': osm, 'url': url}) # return results |