diff --git a/api/latlng.php b/api/latlng.php new file mode 100755 index 0000000..6fc8e7b --- /dev/null +++ b/api/latlng.php @@ -0,0 +1,35 @@ +prezzi = $db->getResults( sprintf( + "SELECT DISTINCT price.prezzo, price.isSelf, descCarburante " . + "FROM price, station " . + "WHERE price.idImpianto = %d AND price.idImpianto = station.idImpianto " . + "ORDER BY price.prezzo" + , + $result[$i]->idImpianto + ) ); + } +} + +http_json_header(); + +echo json_encode( + $result + , JSON_PRETTY_PRINT +); diff --git a/facile.css b/facile.css new file mode 100755 index 0000000..959a020 --- /dev/null +++ b/facile.css @@ -0,0 +1,20 @@ +html, body { + height:100%; +} +#map { + position:absolute; + top:0; + left:0; + width:100%; + height:100%; +} +#overworld { + position:absolute; + top:0; + left:0; + z-index:1000; +} +.prices td { + padding:4px !important; + +} diff --git a/facile.js b/facile.js new file mode 100755 index 0000000..9e036e1 --- /dev/null +++ b/facile.js @@ -0,0 +1,156 @@ +var map; +var clickMarker = L.marker(); +var roundMarkers = L.layerGroup(); +var radius = 1000; +var radiusExtra = 400; + + + +$(document).ready(function() { + +map = L.map('map'); + +var w = $("body").width(); +var h = $("body").height(); +$("#map").width( w ).height( h ); + +// create the tile layer with correct attribution +var osmUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; +var osmAttrib='Map data Facile.it © OpenStreetMap contributors'; +var osm = new L.TileLayer(osmUrl, {minZoom: 8, maxZoom: 17, attribution: osmAttrib}); +map.addLayer(osm); +map.addLayer(roundMarkers); + +// start the map in South-East England +map.setView([42.5, 12.9], 7); + +map.on("click", function(e) { + var popLocation= e.latlng; + + map.hasLayer(clickMarker) && map.removeLayer(clickMarker); + + /* + clickMarker = L.marker( + popLocation, + { + bounceOnAdd: true, + bounceOnAddOptions: {duration: 500, height: 100}, + bounceOnAddCallback: function() { + console.log("done"); + } + } + ).addTo(map); + */ + + $.getJSON( + "/api/latlng.php", { + lat: popLocation.lat, + lng: popLocation.lng, + radius: radius + radiusExtra + }, + function(json) { + console.log(json); + + map.setView(popLocation, 15); + + roundMarkers.clearLayers(); + + for(var i=0; iPrezzi: "; + for(var j=0; j"; + txt += "" + json[i].prezzi[j].prezzo + ""; + txt += "per il " + json[i].prezzi[j].descCarburante + ""; + txt += ""; + } + txt += ""; + + L.marker( + [json[i].latitudine, json[i].longitudine], + { + bounceOnAdd: true, + bounceOnAddOptions: {duration: 500, height: 100}, + bounceOnAddCallback: function() {} + } + ) + .bindPopup(txt) + .addTo(roundMarkers); + + } + + if(json.length > 0) { + L.circle(popLocation, radius).addTo(roundMarkers); + } + } + ); +}); + +// On ready +}); + + + + + +function suggest_nominatim_addresses(query) { + showProgressBar(); + + $.ajax({ + url: "https://nominatim.openstreetmap.org/search", + jsonp: "nominatimJsonp", + dataType: "jsonp", + data: { + q: query, + format: "json", + json_callback: "nominatimJsonp" + } + }) + .always(hideProgressBar) + .fail(toastForNetworkFail); +} + +function nominatimJsonp(json) { + if(! json) { + toastForJSONFail(); + return false; + } + + var $searchResults = $("#modal-search-addr-results"); + var $list = $searchResults.find("ol").empty(); + + if(json.length > 0) { + var h = get_hashtag_params(); + for(i=0; i") + .append( + $('') + .data("hashtag", { + setView: { + latLng: {lat: json[i].lat, lng: json[i].lon}, + zoom: ZOOM_OPENING_SEARCH_RESULT, + enfatize: true + } + } ) + .text(json[i].display_name) + ) + .append( + $("") + ) + .append( + $("") + .text(json[i].licence) + ) + ); + } + // Result links + $searchResults.find("a").click(function() { + $searchResults.closeModal(); + }); + } else { + $list.append( $("").text( L10n.noAddressFound ) ); + } + $searchResults.openModal(); +} + diff --git a/import.php b/import.php deleted file mode 100755 index a64c566..0000000 --- a/import.php +++ /dev/null @@ -1,81 +0,0 @@ -CIAO"); -// Ogni volta che lancio svuota il DB e lo riempe di merda - -$db->query("TRUNCATE station"); -$db->query("TRUNCATE price"); - -echo("STAR Tabella price"); -try - { - $fileName = 'import/prezzo_alle_8.csv'; - if ( !file_exists($fileName) ) { - throw new Exception('File not found.'); - } - $handle = fopen($fileName, "r"); - if ( !$handle ) { - throw new Exception('File open failed.'); - } - fgetcsv($handle); // get line 0 and move pointer to line 1 - fgetcsv($handle); // get line 1 and move pointer to line 2 - while(($data = fgetcsv($handle, 255, ";")) !== FALSE) { - $db->insertRow( - 'price', - [ - new DBCol('idImpianto', intval($data[0]), 'd'), - new DBCol('descCarburante', $data[1], 's'), - new DBCol('prezzo', floatval($data[2]), 'f'), - new DBCol('isSelf', intval($data[3]), 'd'), - new DBCol('dtComu', $data[4], 's') - ] - ); - } - fclose($handle); - // send success JSON - - } catch ( Exception $e ) { - // send error message if you can - echo($e->getMessage()); - } -echo("END Tabella price"); -echo("STAR Tabella station"); -try - { - $fileName = 'import/prezzo_alle_8.csv'; - if ( !file_exists($fileName) ) { - throw new Exception('File not found.'); - } - $handle = fopen($fileName, "r"); - if ( !$handle ) { - throw new Exception('File open failed.'); - } - fgetcsv($handle); // get line 0 and move pointer to line 1 - fgetcsv($handle); // get line 1 and move pointer to line 2 - while(($data = fgetcsv($handle, 255, ";")) !== FALSE) { - $db->insertRow( - 'station', - [ - new DBCol('idImpianto', intval($data[0]), 'd'), - new DBCol('gestore', $data[1], 's'), - new DBCol('bandiera', $data[2], 's'), - new DBCol('tipoImpianto', $data[3], 's'), - new DBCol('nomeImpianto', $data[4], 's'), - new DBCol('indirizzo', $data[5], 's'), - new DBCol('comune', $data[6], 's'), - new DBCol('provincia', $data[7], 's'), - new DBCol('latitudine', floatval($data[8]), 'f'), - new DBCol('longitudine', intval($data[9]), 'f') - ] - ); - } - fclose($handle); - // send success JSON - - } catch ( Exception $e ) { - // send error message if you can - echo($e->getMessage()); - } -echo("END Tabella station"); -echo("FINE"); diff --git a/includes/footer.php b/includes/footer.php index 35513db..cb223c9 100755 --- a/includes/footer.php +++ b/includes/footer.php @@ -1,25 +1,24 @@ . */ function get_footer($page = null, $args = null) { ?> -