From 740594a4b73952ad3f5fa52dd1bb939c73dcc7c2 Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Sun, 2 Nov 2014 13:00:28 +0100 Subject: [enh] oscar_template: initial osm-map support for map results * TODO: remove leaflet.min.css if not required --- searx/engines/openstreetmap.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'searx/engines') diff --git a/searx/engines/openstreetmap.py b/searx/engines/openstreetmap.py index ea7251486..d73a116ba 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' result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}' @@ -38,9 +38,23 @@ 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']) + + 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']]} + # 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, 'url': url}) # return results -- cgit v1.2.3 From c38917bb2a472429f78cd00fffb5e7057ceecc02 Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Mon, 3 Nov 2014 18:46:58 +0100 Subject: [enh] template_oscar: show addressdata if possible --- searx/engines/openstreetmap.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'searx/engines') diff --git a/searx/engines/openstreetmap.py b/searx/engines/openstreetmap.py index d73a116ba..e5deba1e5 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&polygon_geojson=1' +url = 'https://nominatim.openstreetmap.org/search/{query}?format=json&polygon_geojson=1&addressdetails=1' result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}' @@ -47,6 +47,30 @@ def response(resp): 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('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({'template': 'map.html', 'title': title, @@ -55,6 +79,7 @@ def response(resp): 'latitude': r['lat'], 'boundingbox': r['boundingbox'], 'geojson': geojson, + 'address': address, 'url': url}) # return results -- cgit v1.2.3 From bc12a76fbbfdb4769a254cda5e3cfdf262765107 Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Mon, 3 Nov 2014 18:53:04 +0100 Subject: [fix] use address.city if possible --- searx/engines/openstreetmap.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'searx/engines') diff --git a/searx/engines/openstreetmap.py b/searx/engines/openstreetmap.py index e5deba1e5..db0fbfe75 100644 --- a/searx/engines/openstreetmap.py +++ b/searx/engines/openstreetmap.py @@ -64,7 +64,9 @@ def response(resp): if address.get('name'): address.update({'house_number':address_raw.get('house_number'), 'road':address_raw.get('road'), - 'locality':address_raw.get('town', address_raw.get('village')), + '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')}) -- cgit v1.2.3 From 4b75d41f864b9d127aa88c962b7ce849ee3b0b51 Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Wed, 19 Nov 2014 14:59:30 +0100 Subject: [enh][oscar_template] loading map informations from overpass-api --- searx/engines/openstreetmap.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'searx/engines') diff --git a/searx/engines/openstreetmap.py b/searx/engines/openstreetmap.py index db0fbfe75..f727ca8ea 100644 --- a/searx/engines/openstreetmap.py +++ b/searx/engines/openstreetmap.py @@ -39,6 +39,9 @@ def response(resp): 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 @@ -82,6 +85,7 @@ def response(resp): 'boundingbox': r['boundingbox'], 'geojson': geojson, 'address': address, + 'osm': osm, 'url': url}) # return results -- cgit v1.2.3