summaryrefslogtreecommitdiff
path: root/searx/static/oscar/js/scripts.js
diff options
context:
space:
mode:
authorThomas Pointhuber <thomas.pointhuber@gmx.at>2014-11-02 13:00:28 +0100
committerThomas Pointhuber <thomas.pointhuber@gmx.at>2014-11-02 13:00:28 +0100
commit740594a4b73952ad3f5fa52dd1bb939c73dcc7c2 (patch)
tree07966947a2c61b7de99b9c52cd1bd4eebcc85759 /searx/static/oscar/js/scripts.js
parentb4829891f93515c7d19af2472a855eccd7807c4a (diff)
[enh] oscar_template: initial osm-map support for map results
* TODO: remove leaflet.min.css if not required
Diffstat (limited to 'searx/static/oscar/js/scripts.js')
-rw-r--r--searx/static/oscar/js/scripts.js59
1 files changed, 59 insertions, 0 deletions
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 © <a href="https://openstreetmap.org">OpenStreetMap</a> 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 );
+ });
});