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 diff --git a/searx/static/oscar/css/leaflet.min.css b/searx/static/oscar/css/leaflet.min.css new file mode 100644 index 000000000..417e0e8e7 Binary files /dev/null and b/searx/static/oscar/css/leaflet.min.css 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..37285c9c9 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,56 @@ $(document).ready(function(){ source: searx.searchResults.ttAdapter() }); } + + $(".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 osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; + var osmAttrib='Map data © OpenStreetMap contributors'; + var osm = new L.TileLayer(osmUrl, {minZoom: 1, maxZoom: 19, attribution: osmAttrib}); + + // init map view + if(map_bounds) { + // TODO hack: https://github.com/Leaflet/Leaflet/issues/2021 + setTimeout(function () { + map.fitBounds(map_bounds); + }, 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(osm); + + if(map_geojson) + L.geoJson(map_geojson).addTo(map); + //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/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 @@ +
{{ 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 %}