From 740594a4b73952ad3f5fa52dd1bb939c73dcc7c2 Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Sun, 2 Nov 2014 13:00:28 +0100 Subject: [enh] oscar_template: initial osm-map support for map results * TODO: remove leaflet.min.css if not required --- searx/static/oscar/js/scripts.js | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'searx/static/oscar/js/scripts.js') 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 ); + }); }); -- cgit v1.2.3 From b2c976a5a33f234de1f5c67de0e04034c21c20d8 Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Sun, 2 Nov 2014 22:35:06 +0100 Subject: [enh] template_oscar: maxZoom if fitting bounds --- searx/static/oscar/js/scripts.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'searx/static/oscar/js/scripts.js') diff --git a/searx/static/oscar/js/scripts.js b/searx/static/oscar/js/scripts.js index 37285c9c9..4058fc039 100644 --- a/searx/static/oscar/js/scripts.js +++ b/searx/static/oscar/js/scripts.js @@ -100,7 +100,9 @@ $(document).ready(function(){ if(map_bounds) { // TODO hack: https://github.com/Leaflet/Leaflet/issues/2021 setTimeout(function () { - map.fitBounds(map_bounds); + map.fitBounds(map_bounds, { + maxZoom:17 + }); }, 0); } else if (map_lon && map_lat) { if(map_zoom) @@ -113,8 +115,8 @@ $(document).ready(function(){ if(map_geojson) L.geoJson(map_geojson).addTo(map); - //if(map_bounds) - // L.rectangle(map_bounds, {color: "#ff7800", weight: 3, fill:false}).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 -- cgit v1.2.3 From 3b7b106684a1dc899823bcef533e5892f7a813da Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Mon, 3 Nov 2014 18:47:18 +0100 Subject: [enh] template_oscar: add layer to leaflet map --- searx/static/oscar/js/scripts.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'searx/static/oscar/js/scripts.js') diff --git a/searx/static/oscar/js/scripts.js b/searx/static/oscar/js/scripts.js index 4058fc039..b37c72857 100644 --- a/searx/static/oscar/js/scripts.js +++ b/searx/static/oscar/js/scripts.js @@ -92,9 +92,17 @@ $(document).ready(function(){ 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}); + 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) { @@ -111,7 +119,16 @@ $(document).ready(function(){ map.setView(new L.LatLng(map_lat, map_lon),8); } - map.addLayer(osm); + map.addLayer(osmMapnik); + + 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); -- cgit v1.2.3 From 4b75d41f864b9d127aa88c962b7ce849ee3b0b51 Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Wed, 19 Nov 2014 14:59:30 +0100 Subject: [enh][oscar_template] loading map informations from overpass-api --- searx/static/oscar/js/scripts.js | 84 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) (limited to 'searx/static/oscar/js/scripts.js') diff --git a/searx/static/oscar/js/scripts.js b/searx/static/oscar/js/scripts.js index b37c72857..92847de96 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, -- cgit v1.2.3