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 += "" + 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'); + var map_lon = $(this).data('map-lon'); + var map_lat = $(this).data('map-lat'); + var map_zoom = $(this).data('map-zoom'); + var map_boundingbox = $(this).data('map-boundingbox'); + var map_geojson = $(this).data('map-geojson'); + + require(['leaflet-0.7.3.min'], function(leaflet) { + if(map_boundingbox) { + var southWest = L.latLng(map_boundingbox[0], map_boundingbox[2]), + northEast = L.latLng(map_boundingbox[1], map_boundingbox[3]), + map_bounds = L.latLngBounds(southWest, northEast); + } + + // TODO hack + // change default imagePath + L.Icon.Default.imagePath = "/static/oscar/img/map"; + + // init map + var map = L.map(leaflet_target); + + // create the tile layer with correct attribution + var osmMapnikUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; + var osmMapnikAttrib='Map data © OpenStreetMap contributors'; + var osmMapnik = new L.TileLayer(osmMapnikUrl, {minZoom: 1, maxZoom: 19, attribution: osmMapnikAttrib}); + + var osmMapquestUrl='http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg'; + var osmMapquestAttrib='Map data © OpenStreetMap contributors | Tiles Courtesy of MapQuest '; + var osmMapquest = new L.TileLayer(osmMapquestUrl, {minZoom: 1, maxZoom: 18, subdomains: '1234', attribution: osmMapquestAttrib}); + + var osmMapquestOpenAerialUrl='http://otile{s}.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg'; + var osmMapquestOpenAerialAttrib='Map data © OpenStreetMap contributors | Tiles Courtesy of MapQuest | Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency'; + var osmMapquestOpenAerial = new L.TileLayer(osmMapquestOpenAerialUrl, {minZoom: 1, maxZoom: 11, subdomains: '1234', attribution: osmMapquestOpenAerialAttrib}); + + // init map view + if(map_bounds) { + // TODO hack: https://github.com/Leaflet/Leaflet/issues/2021 + setTimeout(function () { + map.fitBounds(map_bounds, { + maxZoom:17 + }); + }, 0); + } else if (map_lon && map_lat) { + if(map_zoom) + map.setView(new L.LatLng(map_lat, map_lon),map_zoom); + else + map.setView(new L.LatLng(map_lat, map_lon),8); + } + + map.addLayer(osmMapquest); + + var baseLayers = { + "OSM Mapnik": osmMapnik, + "MapQuest": osmMapquest/*, + "MapQuest Open Aerial": osmMapquestOpenAerial*/ + }; + + L.control.layers(baseLayers).addTo(map); + + + if(map_geojson) + L.geoJson(map_geojson).addTo(map); + /*else if(map_bounds) + L.rectangle(map_bounds, {color: "#ff7800", weight: 3, fill:false}).addTo(map);*/ + }); + + // this event occour only once per element + $( this ).off( event ); + }); }); diff --git a/searx/static/oscar/less/oscar/cursor.less b/searx/static/oscar/less/oscar/cursor.less index c7e3191d8..cbc1ea6fc 100644 --- a/searx/static/oscar/less/oscar/cursor.less +++ b/searx/static/oscar/less/oscar/cursor.less @@ -2,3 +2,7 @@ .cursor-text { cursor: text !important; } + +.cursor-pointer { + cursor: pointer !important; +} diff --git a/searx/static/oscar/less/oscar/results.less b/searx/static/oscar/less/oscar/results.less index 06c8a1740..08500b3ff 100644 --- a/searx/static/oscar/less/oscar/results.less +++ b/searx/static/oscar/less/oscar/results.less @@ -1,3 +1,29 @@ + +.result_header { + margin-bottom:5px; + margin-top:20px; + + .favicon { + margin-bottom:-3px; + } + + a { + vertical-align: bottom; + + .highlight { + font-weight:bold; + } + } +} + +.result-content { + margin-top: 5px; + + .highlight { + font-weight:bold; + } +} + // default formating of results .result-default { clear: both; @@ -24,6 +50,11 @@ clear: both; } +// map formating of results +.result-map { + clear: both; +} + // suggestion .suggestion_item { margin: 2px 5px; diff --git a/searx/templates/courgette/result_templates/map.html b/searx/templates/courgette/result_templates/map.html new file mode 100644 index 000000000..734f9066c --- /dev/null +++ b/searx/templates/courgette/result_templates/map.html @@ -0,0 +1,13 @@ +
+ + {% if result['favicon'] %} + + {% endif %} + +
+

{{ result.title|safe }}

+ {% if result.publishedDate %}

{{ result.publishedDate }}

{% endif %} +

{% if result.content %}{{ result.content|safe }}
{% endif %}

+

{{ result.pretty_url }}

+
+
diff --git a/searx/templates/default/result_templates/map.html b/searx/templates/default/result_templates/map.html new file mode 100644 index 000000000..78221aa01 --- /dev/null +++ b/searx/templates/default/result_templates/map.html @@ -0,0 +1,13 @@ +
+ + {% if result['favicon'] %} + + {% endif %} + +
+

{{ result.title|safe }}

+

{{ result.pretty_url }} cached

+ {% if result.publishedDate %}

{{ result.publishedDate }}

{% endif %} +

{% if result.img_src %}{% endif %}{% if result.content %}{{ result.content|safe }}
{% endif %}

+
+
diff --git a/searx/templates/oscar/base.html b/searx/templates/oscar/base.html index 807da84e7..6fde942ac 100644 --- a/searx/templates/oscar/base.html +++ b/searx/templates/oscar/base.html @@ -11,7 +11,8 @@ - + +