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 += "" + row + ""; + switch(row) { + case "phone": + case "fax": + newHtml += "" + element.tags[row] + ""; + break; + case "email": + newHtml += "" + element.tags[row] + ""; + break; + case "website": + case "url": + newHtml += "" + element.tags[row] + ""; + break; + case "wikidata": + newHtml += "" + element.tags[row] + ""; + break; + case "wikipedia": + if(element.tags[row].indexOf(":") != -1) { + newHtml += "" + element.tags[row] + ""; + break; + } + default: + newHtml += element.tags[row]; + break; + } + newHtml += ""; + } + } + $(result_table).html(newHtml); + $(result_table).removeClass('hidden'); + $(result_table_loadicon).addClass('hidden'); + } + }) + .fail(function() { + alert( "could not load " ); + }) + } + } + + // this event occour only once per element + $( this ).off( event ); + }); $(".searx_init_map").on( "click", function( event ) { var leaflet_target = $(this).data('leaflet-target'); @@ -119,7 +201,7 @@ $(document).ready(function(){ map.setView(new L.LatLng(map_lat, map_lon),8); } - map.addLayer(osmMapnik); + map.addLayer(osmMapquest); var baseLayers = { "OSM Mapnik": osmMapnik, diff --git a/searx/templates/oscar/result_templates/map.html b/searx/templates/oscar/result_templates/map.html index a7c37dd5..531146dc 100644 --- a/searx/templates/oscar/result_templates/map.html +++ b/searx/templates/oscar/result_templates/map.html @@ -3,13 +3,25 @@

{% if result['favicon'] %} {% endif %}{{ result.title|safe }}

{% if result.publishedDate %}{% endif %} + {{ icon('link') }} {{ _('cached') }} + {% if (result.latitude and result.longitude) or result.boundingbox %} {% endif %} +{% if result.osm and (result.osm.type and result.osm.id) %} + +{% endif %} + +{# {% if (result.latitude and result.longitude) %} + +{% endif %} #} + +
+ {% if result.address %} -

+

{% if result.address.name %} {{ result.address.name }}
{% endif %} @@ -27,11 +39,29 @@ {% if result.address.country %} {{ result.address.country }} {% endif %} -

+

{% endif %} -{% if result.content %}

{{ result.content|safe }}

{% endif %} +{% if result.osm and (result.osm.type and result.osm.id) %} +
+
Loading ...
+ + + +
+{% endif %} +{# {% if (result.latitude and result.longitude) %} +
+ Longitude: {{ result.longitude }}
+ Latitude: {{ result.latitude }} +
+{% endif %} #} + +{% if result.content %}

{{ result.content|safe }}

{% endif %} + +
+ {% if (result.latitude and result.longitude) or result.boundingbox %}