diff --git a/WebContent/OSRM.JSONP.js b/WebContent/OSRM.JSONP.js index c29e634e6..f62ed470d 100644 --- a/WebContent/OSRM.JSONP.js +++ b/WebContent/OSRM.JSONP.js @@ -66,8 +66,8 @@ OSRM.JSONP = { OSRM.JSONP.fences[id] = undefined; // clean fence } -// OSRM.JSONP.sum[id] += new Number( new Date() - OSRM.JSONP.durations[id] ); -// OSRM.debug.log("[jsonp] response handling: "+id+" "+ (OSRM.JSONP.sum[id]/OSRM.JSONP.counter[id]).toFixed(2) ); + OSRM.JSONP.sum[id] += new Number( new Date() - OSRM.JSONP.durations[id] ); + OSRM.debug.log("[jsonp] response handling: "+id+" "+ (OSRM.JSONP.sum[id]/OSRM.JSONP.counter[id]).toFixed(2) ); }; // clean DOM (unfortunately, script elements cannot be reused by all browsers) @@ -85,9 +85,9 @@ OSRM.JSONP = { // start timeout timer OSRM.JSONP.timers[id] = setTimeout(OSRM.JSONP.timeouts[id], timeout); -// if(!OSRM.JSONP.durations) { OSRM.JSONP.durations = {}; OSRM.JSONP.counter = {}; OSRM.JSONP.sum = {}; } -// if(OSRM.JSONP.counter[id]) OSRM.JSONP.counter[id]++; else {OSRM.JSONP.counter[id] = 1;OSRM.JSONP.sum[id] = 0;} -// OSRM.JSONP.durations[id] = new Date(); + if(!OSRM.JSONP.durations) { OSRM.JSONP.durations = {}; OSRM.JSONP.counter = {}; OSRM.JSONP.sum = {}; } + if(OSRM.JSONP.counter[id]) OSRM.JSONP.counter[id]++; else {OSRM.JSONP.counter[id] = 1;OSRM.JSONP.sum[id] = 0;} + OSRM.JSONP.durations[id] = new Date(); // OSRM.debug.log("[jsonp] init: "+id); return true; diff --git a/WebContent/OSRM.Map.js b/WebContent/OSRM.Map.js index 1031f3f0a..f53874d59 100644 --- a/WebContent/OSRM.Map.js +++ b/WebContent/OSRM.Map.js @@ -121,6 +121,8 @@ init: function() { // initial map position and zoom var position = new L.LatLng( OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE); OSRM.G.map.setViewUI( position, OSRM.DEFAULTS.ZOOM_LEVEL); + if (navigator.geolocation && document.URL.indexOf("file://") == -1) + navigator.geolocation.getCurrentPosition(OSRM.Map.geolocationResponse); // map events OSRM.G.map.on('zoomend', OSRM.Map.zoomed ); @@ -146,6 +148,10 @@ click: function(e) { OSRM.G.markers.route[index].show(); OSRM.G.markers.route[index].centerView( OSRM.G.map.getZoom() ); OSRM.Routing.getRoute(); - } + } +}, +geolocationResponse: function(response) { + var latlng = new L.LatLng(response.coords.latitude, response.coords.longitude); + OSRM.G.map.setViewUI(latlng, OSRM.DEFAULTS.ZOOM_LEVEL ); } }; \ No newline at end of file diff --git a/WebContent/main.html b/WebContent/main.html index 939df3ea5..a561bd4e0 100644 --- a/WebContent/main.html +++ b/WebContent/main.html @@ -46,7 +46,7 @@ or see http://www.gnu.org/licenses/agpl.txt. - + diff --git a/WebContent/printing/OSRM.Printing.js b/WebContent/printing/OSRM.Printing.js index 03df8d4ca..e1f19a8e9 100644 --- a/WebContent/printing/OSRM.Printing.js +++ b/WebContent/printing/OSRM.Printing.js @@ -18,43 +18,73 @@ or see http://www.gnu.org/licenses/agpl.txt. // OSRM printer // [printing support] - OSRM.Printing = { -x: function(){ - OSRM.printwindow.test(); -// var pos1 = OSRM.printwindow.document.getElementById('map1'); -// var pos2 = OSRM.printwindow.document.getElementById('map2'); -// // setup map -// var osmorgURL = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', -// osmorgOptions = {maxZoom: 18}; -// var osmorg = new L.TileLayer(osmorgURL, osmorgOptions); -// var temp1 = new OSRM.MapView(pos1, { -// center: new L.LatLng(51.505, -0.09), -// zoom: 13, -// zoomAnimation: false, // false: removes animations and hiding of routes during zoom -// fadeAnimation: false, -// layers: [osmorg] -// }); -// var osmorgURL = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', -// osmorgOptions = {maxZoom: 18}; -// var osmorg = new L.TileLayer(osmorgURL, osmorgOptions); -// var temp2 = new OSRM.MapView(pos2, { -// center: new L.LatLng(51.505, -0.09), -// zoom: 13, -// zoomAnimation: false, // false: removes animations and hiding of routes during zoom -// fadeAnimation: false, -// layers: [osmorg] -// }); +windowLoaded: function(){ + OSRM.printwindow.initialize(); + OSRM.Printing.show( OSRM.G.response ); + OSRM.printwindow.focus(); +}, + +show: function(response) { + // create route description + var route_desc = ""; + route_desc += ''; + + for(var i=0; i < response.route_instructions.length; i++){ + //odd or even ? + var rowstyle='results-odd'; + if(i%2==0) { rowstyle='results-even'; } + + route_desc += ''; + + route_desc += '"; + + route_desc += '"; + + route_desc += '"; + + route_desc += ""; + } + + route_desc += '
'; + route_desc += ''; + route_desc += "'; + route_desc += ''; + route_desc += response.route_instructions[i][0]; + if( i == 0 ) + route_desc += ' ' + OSRM.loc( response.route_instructions[i][6] ); + if( response.route_instructions[i][1] != "" ) { + route_desc += ' on '; + route_desc += '' + response.route_instructions[i][1] + ''; + } + //route_desc += ' for '; + route_desc += ''; + route_desc += "'; + if( i != response.route_instructions.length-1 ) + route_desc += ''+OSRM.Utils.metersToDistance(response.route_instructions[i][2])+''; + route_desc += "
'; + headline = ""; + headline += OSRM.loc("ROUTE_DESCRIPTION")+":
"; + headline += '
'; + headline += "" + + OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance) + + "
" + + OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time) + + "
"; + headline += '
'; + + var output = ""; + output += route_desc; + + OSRM.printwindow.document.getElementById('description-headline').innerHTML = headline; + OSRM.printwindow.document.getElementById('description').innerHTML = output; }, // react to click print: function() { - OSRM.printwindow = window.open("printing.html", "Popupfenster", "width=400,height=300,resizable=yes"); -// fenster.document.write("
a
b
"); - OSRM.printwindow.focus(); - - OSRM.printwindow.addEventListener("DOMContentLoaded", OSRM.Printing.x, false); + OSRM.printwindow = window.open("printing/printing.html","","width=400,height=300,left=100,top=100,dependent=yes,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes"); + OSRM.printwindow.addEventListener("DOMContentLoaded", OSRM.Printing.windowLoaded, false); } }; \ No newline at end of file diff --git a/WebContent/printing/printing.css b/WebContent/printing/printing.css new file mode 100644 index 000000000..a1ae513f0 --- /dev/null +++ b/WebContent/printing/printing.css @@ -0,0 +1,105 @@ +/* +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. +*/ + +/* OSRM CSS styles for printing*/ + + +/* printer button */ +.printer-inactive +{ + cursor:pointer; + width:16px; + height:16px; + background-image:url("../images/printer_inactive.png"); +} +.printer +{ + cursor:pointer; + width:16px; + height:16px; + background-image:url("../images/printer.png"); +} +.printer:hover +{ + background-image:url("../images/printer_hover.png"); +} +.printer:active +{ + background-image:url("../images/printer_active.png"); +} + +/* route summary */ +.route-summary +{ + font-size: 12px; +} + +/* route description box */ +#description +{ + position:absolute; + bottom:15px; + top:60px; + width:380px; + font-size:12px; + margin:5px; +} +.results-table +{ + border-spacing:0px; +} +.results-odd +{ + background-color: #FAF3E9; //#ffffff; +} +.results-even +{ + background-color: #F2DE9C; //#ffffe0; +} +.result-items +{ + text-align:left; + vertical-align: middle; + width:100%; + padding-left:1px; + padding-right:1px; + padding-top:1px; + padding-bottom:1px; +} +.result-direction +{ + width:30px; + padding-left:1px; + padding-right:1px; + padding-top:1px; + padding-bottom:1px; +} +.result-distance +{ + text-align:right; + vertical-align: middle; + width:30px; + padding-left:1px; + padding-right:1px; + padding-top:1px; + padding-bottom:1px; +} +.result-item +{ + cursor:pointer; + color:#000000 +} diff --git a/WebContent/printing/printing.html b/WebContent/printing/printing.html index 01382ab0b..5580e15da 100644 --- a/WebContent/printing/printing.html +++ b/WebContent/printing/printing.html @@ -30,17 +30,18 @@ or see http://www.gnu.org/licenses/agpl.txt. - + - - + + + - + @@ -74,10 +79,13 @@ function test() { - +
-
-
+ + +
+
diff --git a/WebContent/routing/OSRM.Routing.js b/WebContent/routing/OSRM.Routing.js index 2796d187d..b05704acd 100644 --- a/WebContent/routing/OSRM.Routing.js +++ b/WebContent/routing/OSRM.Routing.js @@ -71,6 +71,7 @@ showRoute: function(response) { if(!response) return; + OSRM.G.response = response; OSRM.G.via_points = response.via_points.slice(0); if(response.status == 207) { OSRM.RoutingGeometry.showNA();