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 diff --git a/searx/static/oscar/css/leaflet.min.css b/searx/static/oscar/css/leaflet.min.css new file mode 100644 index 000000000..bca0c58b9 Binary files /dev/null and b/searx/static/oscar/css/leaflet.min.css differ diff --git a/searx/static/oscar/css/oscar.min.css b/searx/static/oscar/css/oscar.min.css index 5d2c24e63..b8d6fba15 100644 Binary files a/searx/static/oscar/css/oscar.min.css and b/searx/static/oscar/css/oscar.min.css differ diff --git a/searx/static/oscar/img/loader.gif b/searx/static/oscar/img/loader.gif new file mode 100644 index 000000000..3980ff00b Binary files /dev/null and b/searx/static/oscar/img/loader.gif differ diff --git a/searx/static/oscar/img/map/layers-2x.png b/searx/static/oscar/img/map/layers-2x.png new file mode 100644 index 000000000..a2cf7f9ef Binary files /dev/null and b/searx/static/oscar/img/map/layers-2x.png differ diff --git a/searx/static/oscar/img/map/layers.png b/searx/static/oscar/img/map/layers.png new file mode 100644 index 000000000..bca0a0e42 Binary files /dev/null and b/searx/static/oscar/img/map/layers.png differ diff --git a/searx/static/oscar/img/map/marker-icon-2x.png b/searx/static/oscar/img/map/marker-icon-2x.png new file mode 100644 index 000000000..0015b6495 Binary files /dev/null and b/searx/static/oscar/img/map/marker-icon-2x.png differ diff --git a/searx/static/oscar/img/map/marker-icon.png b/searx/static/oscar/img/map/marker-icon.png new file mode 100644 index 000000000..e2e9f757f Binary files /dev/null and b/searx/static/oscar/img/map/marker-icon.png differ diff --git a/searx/static/oscar/img/map/marker-shadow.png b/searx/static/oscar/img/map/marker-shadow.png new file mode 100644 index 000000000..d1e773c71 Binary files /dev/null and b/searx/static/oscar/img/map/marker-shadow.png differ diff --git a/searx/static/oscar/js/leaflet-0.7.3.min.js b/searx/static/oscar/js/leaflet-0.7.3.min.js new file mode 100644 index 000000000..03434b77d Binary files /dev/null and b/searx/static/oscar/js/leaflet-0.7.3.min.js differ diff --git a/searx/static/oscar/js/require-2.1.15.min.js b/searx/static/oscar/js/require-2.1.15.min.js new file mode 100644 index 000000000..be103a74e Binary files /dev/null and b/searx/static/oscar/js/require-2.1.15.min.js differ diff --git a/searx/static/oscar/js/scripts.js b/searx/static/oscar/js/scripts.js index 6c3a10a74..92847de96 100644 --- a/searx/static/oscar/js/scripts.js +++ b/searx/static/oscar/js/scripts.js @@ -7,6 +7,13 @@ */ +requirejs.config({ +baseUrl: '/static/oscar/js', +paths: { +app: '../app' +} +}); + if(searx.autocompleter) { searx.searchResults = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), @@ -61,4 +68,157 @@ $(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 += "
{{ result.publishedDate }}
{% endif %} +{% if result.content %}{{ result.content|safe }}
{% endif %}
{{ result.pretty_url }}
+{{ result.pretty_url }} cached
+ {% if result.publishedDate %}{{ result.publishedDate }}
{% endif %} +{% if result.img_src %}{% endif %}{% if result.content %}{{ result.content|safe }}
{% endif %}