diff --git a/searx/engines/openstreetmap.py b/searx/engines/openstreetmap.py index db0fbfe7..f727ca8e 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 diff --git a/searx/static/oscar/img/loader.gif b/searx/static/oscar/img/loader.gif new file mode 100644 index 00000000..3980ff00 Binary files /dev/null and b/searx/static/oscar/img/loader.gif differ diff --git a/searx/static/oscar/js/scripts.js b/searx/static/oscar/js/scripts.js index b37c7285..92847de9 100644 --- a/searx/static/oscar/js/scripts.js +++ b/searx/static/oscar/js/scripts.js @@ -68,6 +68,88 @@ $(document).ready(function(){ source: searx.searchResults.ttAdapter() }); } + + $(".searx_overpass_request").on( "click", function( event ) { + var overpass_url = "http://overpass-api.de/api/interpreter?data="; + var query_start = overpass_url + "[out:json][timeout:25];("; + var query_end = ");out meta;"; + + var osm_id = $(this).data('osm-id'); + var osm_type = $(this).data('osm-type'); + var result_table = $(this).data('result-table'); + var result_table_loadicon = "#" + $(this).data('result-table-loadicon'); + + // tags which can be ignored + var osm_ignore_tags = [ "addr:city", "addr:country", "addr:housenumber", "addr:postcode", "addr:street" ] + + if(osm_id && osm_type && result_table) { + result_table = "#" + result_table; + var query = null; + switch(osm_type) { + case 'node': + query = query_start + "node(" + osm_id + ");" + query_end; + break; + case 'way': + query = query_start + "way(" + osm_id + ");" + query_end; + break; + case 'relation': + query = query_start + "relation(" + osm_id + ");" + query_end; + break; + default: + break; + } + if(query) { + //alert(query); + var ajaxRequest = $.ajax( query ) + .done(function( html) { + if(html && html['elements'] && html['elements'][0]) { + var element = html['elements'][0]; + var newHtml = $(result_table).html(); + for (var row in element.tags) { + if(element.tags["name"] == null || osm_ignore_tags.indexOf(row) == -1) { + newHtml += "
+
{% if result.address.name %}
{{ result.address.name }}
{% endif %}
@@ -27,11 +39,29 @@
{% if result.address.country %}
{{ result.address.country }}
{% endif %}
-
{{ result.content|safe }}
{% endif %} +{% if result.osm and (result.osm.type and result.osm.id) %} +{{ result.content|safe }}
{% endif %} + +