"+OSRM.loc("TIMED_OUT")+".
";
}
+
+
+// - [upcoming feature: reverse geocoding] -
+//OSRM.REVERSE_GEOCODE_POST = 'http://nominatim.openstreetmap.org/reverse?format=json';
+//
+//function updateReverseGeocoder(marker_id) {
+// if (marker_id == OSRM.SOURCE_MARKER_LABEL) {
+// document.getElementById("input-source-name").value = my_markers.route[0].getPosition().lat.toFixed(6) + ", " + my_markers.route[0].getPosition().lng.toFixed(6);
+// callReverseGeocoder("source", my_markers.route[0].getPosition().lat, my_markers.route[0].getPosition().lng);
+// } else if (marker_id == OSRM.TARGET_MARKER_LABEL) {
+// document.getElementById("input-target-name").value = my_markers.route[my_markers.route.length-1].getPosition().lat.toFixed(6) + ", " + my_markers.route[my_markers.route.length-1].getPosition().lng.toFixed(6);
+// callReverseGeocoder("target", my_markers.route[my_markers.route.length-1].getPosition().lat, my_markers.route[my_markers.route.length-1].getPosition().lng);
+// }
+//}
+//function updateLocations() {
+// if( my_markers.route[0] && my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL) {
+// document.getElementById("input-source-name").value = my_markers.route[0].getPosition().lat.toFixed(6) + ", " + my_markers.route[0].getPosition().lng.toFixed(6);
+// callReverseGeocoder("source", my_markers.route[0].getPosition().lat, my_markers.route[0].getPosition().lng);
+// //OSRM.debug.log("[call1] reverse geocoder");
+// }
+//
+// if( my_markers.route[my_markers.route.length-1] && my_markers.route[ my_markers.route.length-1 ].label == OSRM.TARGET_MARKER_LABEL) {
+// document.getElementById("input-target-name").value = my_markers.route[my_markers.route.length-1].getPosition().lat.toFixed(6) + ", " + my_markers.route[my_markers.route.length-1].getPosition().lng.toFixed(6);
+// callReverseGeocoder("target", my_markers.route[my_markers.route.length-1].getPosition().lat, my_markers.route[my_markers.route.length-1].getPosition().lng);
+// }
+//}
+//
+//
+//function timeout_ReverseGeocoder() {
+// //OSRM.debug.log("[timeout] reverse geocoder");
+//}
+//
+////prepare request and call reverse geocoder
+//function callReverseGeocoder(marker_id, lat, lon) {
+// //build request
+// if (marker_id == OSRM.SOURCE_MARKER_LABEL) {
+// var src= OSRM.REVERSE_GEOCODE_POST + "&lat=" + lat + "&lon=" + lon;
+// OSRM.JSONP.call( src, showReverseGeocoderResults_Source, timeout_ReverseGeocoder, OSRM.DEFAULTS.JSONP_TIMEOUT, "reverse_geocoder_source" );
+// //OSRM.debug.log("[call2] reverse geocoder");
+// } else if (marker_id == OSRM.TARGET_MARKER_LABEL) {
+// var src = OSRM.REVERSE_GEOCODE_POST + "&lat=" + lat + "&lon=" + lon;
+// OSRM.JSONP.call( src, showReverseGeocoderResults_Target, timeout_ReverseGeocoder, OSRM.DEFAULTS.JSONP_TIMEOUT, "reverse_geocoder_target" );
+// }
+//}
+////processing JSONP response of reverse geocoder
+////(with wrapper functions for source/target jsonp)
+//function showReverseGeocoderResults_Source(response) { showReverseGeocoderResults(OSRM.SOURCE_MARKER_LABEL, response); }
+//function showReverseGeocoderResults_Target(response) { showReverseGeocoderResults(OSRM.TARGET_MARKER_LABEL, response); }
+//function showReverseGeocoderResults(marker_id, response) {
+// //OSRM.debug.log("[inner] reverse geocoder");
+// if(response){
+// if(response.address == undefined)
+// return;
+//
+// var address = "";
+// if( response.address.road)
+// address += response.address.road;
+// if( response.address.city) {
+// if( response.address.road)
+// address += ", ";
+// address += response.address.city;
+// }
+// if( address == "" )
+// return;
+//
+// if(marker_id == OSRM.SOURCE_MARKER_LABEL)
+// document.getElementById("input-source-name").value = address;
+// else if(marker_id == OSRM.TARGET_MARKER_LABEL)
+// document.getElementById("input-target-name").value = address;
+// }
+//}
diff --git a/WebContent/main.css b/WebContent/main.css
index e05f8bed3..e2ae5ad18 100644
--- a/WebContent/main.css
+++ b/WebContent/main.css
@@ -1,4 +1,24 @@
-/* styles for map */
+/*
+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 */
+
+
+/* map -> fullscreen */
body {
padding: 0;
margin: 0;
@@ -241,7 +261,8 @@ html, body, #map {
font-size:10px;
}
-/* generally useful styles (above buttons, so that they get their special cursor!)*/
+
+/* utility styles (defined above buttons, so that buttons retain cursor:pointer)*/
.not-selectable
{
cursor:default;
@@ -260,6 +281,7 @@ html, body, #map {
user-select: text;
}
+
/* buttons */
.button
{
diff --git a/WebContent/main.html b/WebContent/main.html
index 8c14d1c58..6f476f6cf 100644
--- a/WebContent/main.html
+++ b/WebContent/main.html
@@ -1,3 +1,20 @@
+
+
diff --git a/WebContent/main.js b/WebContent/main.js
index 7bee258b8..174b9a059 100644
--- a/WebContent/main.js
+++ b/WebContent/main.js
@@ -1,6 +1,27 @@
+/*
+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 initialization
+// [initialization of maps, local strings, image prefetching]
+
var map;
+// onload initialization routine
function init() {
prefetchImages();
prefetchIcons();
@@ -76,6 +97,7 @@ function centerOnGeolocation() {
// init map
function initMap() {
+ // setup tile servers
var osmorgURL = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
osmorgAttribution = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 Mapnik',
osmorgOptions = {maxZoom: 18, attribution: osmorgAttribution};
@@ -97,14 +119,16 @@ function initMap() {
mapquest = new L.TileLayer(mapquestURL, mapquestOptions),
cloudmade = new L.TileLayer(cloudmadeURL, cloudmadeOptions);
+ // setup map
map = new L.Map('map', {
center: new L.LatLng(51.505, -0.09),
zoom: 13,
- zoomAnimation: false, // uncomment to remove animations and hiding of routes during zoom
+ zoomAnimation: false, // false: removes animations and hiding of routes during zoom
fadeAnimation: false,
layers: [osmorg]
});
+ // add tileservers
var baseMaps = {
"osm.org": osmorg,
"osm.de": osmde,
@@ -116,12 +140,15 @@ function initMap() {
var layersControl = new L.Control.Layers(baseMaps, overlayMaps);
map.addControl(layersControl);
+ // move zoom markers
getElementsByClassName(document,'leaflet-control-zoom')[0].style.left="420px";
getElementsByClassName(document,'leaflet-control-zoom')[0].style.top="5px";
- map.setView( new L.LatLng( OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE-0.02), OSRM.DEFAULTS.ZOOM_LEVEL);
+ // initial map position and zoom
+ map.setView( new L.LatLng( OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE), OSRM.DEFAULTS.ZOOM_LEVEL);
map.on('zoomend', function(e) { getRoute(OSRM.FULL_DESCRIPTION); });
+ // click on map to set source and target nodes
map.on('click', function(e) {
if( !my_markers.route[0] || my_markers.route[0].label != OSRM.SOURCE_MARKER_LABEL) {
index = my_markers.setSource( e.latlng );
@@ -140,39 +167,10 @@ function initMap() {
// updateReverseGeocoder("target");
}
} );
- // onmousemove test
-// map.on('mousemove', function(e) { console.log("pos: " + e.latlng); });
-// map.on('mousemove', function(e) {
-// var objs = new Array;
-// var obj = null;
-// do {
-// obj = document.elementFromPoint(e.layerPoint.x, e.layerPoint.y);
-//
-// if (obj == null)
-// break;
-// if (obj == document.body)
-// break;
-// if (obj instanceof SVGPathElement)
-// break;
-//
-// objs.push(obj);
-// obj.style.display = 'none';
-// } while(true);
-// for(var i=0; i "+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+". ";
}
+
+// unnamed streets display
function showRouteNonames(response) {
// do not display unnamed streets?
if( document.getElementById('option-highlight-nonames').checked == false) {
@@ -252,14 +256,15 @@ function showRouteNonames(response) {
my_route.showUnnamedRoute(all_positions);
}
-// function for dragging and drawing routes
+
+//-- main function --
+
+// generate server calls to query routes
function getRoute(do_description) {
// if source or target are not set -> hide route
if( my_markers.route.length < 2 ) {
my_route.hideRoute();
- //my_markers.removeVias(); // TODO: do I need this?
- //my_markers.highlight.hide();
return;
}
@@ -292,16 +297,17 @@ function getRoute(do_description) {
}
// do call
- var called = OSRM.JSONP.call(source, callback, timeout, OSRM.JSONP.TIMEOUT, type);
+ var called = OSRM.JSONP.call(source, callback, timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, type);
- // TODO: guarantee to do last drag
+ // TODO: hack to process final drag event, if it was fenced, but we are still dragging
if(called == false && !do_description) {
clearTimeout(OSRM.pendingTimer);
- OSRM.pendingTimer = setTimeout(timeoutDrag,OSRM.JSONP.TIMEOUT);
+ OSRM.pendingTimer = setTimeout(timeoutDrag,OSRM.DEFAULTS.JSONP_TIMEOUT);
}
else {
clearTimeout(OSRM.pendingTimer);
}
+// // TODO: hack to process final drag event, if it was fenced, but we are still dragging (alternative approach)
// if(called == false && !do_description) {
// OSRM.pending = true;
// } else {
@@ -309,28 +315,42 @@ function getRoute(do_description) {
// OSRM.pending = false;
// }
}
-
function timeoutDrag() {
my_markers.route[OSRM.dragid].hint = undefined;
getRoute(OSRM.NO_DESCRIPTION);
}
-function startRouting() {
- getRoute(OSRM.FULL_DESCRIPTION);
-}
-
-function resetRouting() {
- document.getElementById('input-source-name').value = "";
- document.getElementById('input-target-name').value = "";
-
- my_route.hideRoute();
- my_markers.removeAll();
- my_markers.highlight.hide();
-
- document.getElementById('information-box').innerHTML = "";
- document.getElementById('information-box-headline').innerHTML = "";
+
+//-- helper functions --
+
+//decode compressed route geometry
+function decodeRouteGeometry(encoded, precision) {
+ precision = Math.pow(10, -precision);
+ var len = encoded.length, index=0, lat=0, lng = 0, array = [];
+ while (index < len) {
+ var b, shift = 0, result = 0;
+ do {
+ b = encoded.charCodeAt(index++) - 63;
+ result |= (b & 0x1f) << shift;
+ shift += 5;
+ } while (b >= 0x20);
+ var dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
+ lat += dlat;
+ shift = 0;
+ result = 0;
+ do {
+ b = encoded.charCodeAt(index++) - 63;
+ result |= (b & 0x1f) << shift;
+ shift += 5;
+ } while (b >= 0x20);
+ var dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
+ lng += dlng;
+ array.push([lat * precision, lng * precision]);
+ }
+ return array;
}
+// update hints of all markers
function updateHints(response) {
var hint_locations = response.hint_data.locations;
my_markers.checksum = response.hint_data.checksum;
@@ -338,6 +358,7 @@ function updateHints(response) {
my_markers.route[i].hint = hint_locations[i];
}
+// snap all markers to the received route
function snapRoute() {
var positions = my_route.getPositions();
@@ -350,48 +371,8 @@ function snapRoute() {
updateLocation( "target" );
}
-function positionsToInput() {
- if(my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL) {
- document.getElementById('input-source-name').value = my_markers.route[0].getPosition().lat.toFixed(6)+","+my_markers.route[0].getPosition().lng.toFixed(6);
- }
- if(my_markers.route[my_markers.route.length-1].label == OSRM.TARGET_MARKER_LABEL) {
- document.getElementById('input-target-name').value = my_markers.route[my_markers.route.length-1].getPosition().lat.toFixed(6)+","+my_markers.route[my_markers.route.length-1].getPosition().lng.toFixed(6);
- }
-}
-
-function reverseRouting() {
- // invert input boxes
- var tmp = document.getElementById("input-source-name").value;
- document.getElementById("input-source-name").value = document.getElementById("input-target-name").value;
- document.getElementById("input-target-name").value = tmp;
-
- // invert route
- my_markers.route.reverse();
- if(my_markers.route.length == 1) {
- if(my_markers.route[0].label == OSRM.TARGET_MARKER_LABEL) {
- my_markers.route[0].label = OSRM.SOURCE_MARKER_LABEL;
- my_markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') );
- } else if(my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL) {
- my_markers.route[0].label = OSRM.TARGET_MARKER_LABEL;
- my_markers.route[0].marker.setIcon( new L.Icon('images/marker-target.png') );
- }
- } else if(my_markers.route.length > 1){
- my_markers.route[0].label = OSRM.SOURCE_MARKER_LABEL;
- my_markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') );
-
- my_markers.route[my_markers.route.length-1].label = OSRM.TARGET_MARKER_LABEL;
- my_markers.route[my_markers.route.length-1].marker.setIcon( new L.Icon('images/marker-target.png') );
- }
-
- // recompute route
- getRoute(OSRM.FULL_DESCRIPTION);
- my_markers.highlight.hide();
-}
-
-
-
-
-//--------------------
+// map driving instructions to images
+// [TODO: better implementation, language-safe]
function getDirectionIcon(name) {
var directions = {
"Turn left":"turn-left.png",
@@ -420,4 +401,55 @@ function getDirectionIcon(name) {
return directions[name];
else
return "default.png";
-}
\ No newline at end of file
+}
+
+
+// -- gui functions --
+
+// click: button "route"
+function startRouting() {
+ getRoute(OSRM.FULL_DESCRIPTION);
+}
+
+// click: button "reset"
+function resetRouting() {
+ document.getElementById('input-source-name').value = "";
+ document.getElementById('input-target-name').value = "";
+
+ my_route.hideRoute();
+ my_markers.removeAll();
+ my_markers.highlight.hide();
+
+ document.getElementById('information-box').innerHTML = "";
+ document.getElementById('information-box-headline').innerHTML = "";
+}
+
+// click: button "reverse"
+function reverseRouting() {
+ // invert input boxes
+ var tmp = document.getElementById("input-source-name").value;
+ document.getElementById("input-source-name").value = document.getElementById("input-target-name").value;
+ document.getElementById("input-target-name").value = tmp;
+
+ // invert route
+ my_markers.route.reverse();
+ if(my_markers.route.length == 1) {
+ if(my_markers.route[0].label == OSRM.TARGET_MARKER_LABEL) {
+ my_markers.route[0].label = OSRM.SOURCE_MARKER_LABEL;
+ my_markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') );
+ } else if(my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL) {
+ my_markers.route[0].label = OSRM.TARGET_MARKER_LABEL;
+ my_markers.route[0].marker.setIcon( new L.Icon('images/marker-target.png') );
+ }
+ } else if(my_markers.route.length > 1){
+ my_markers.route[0].label = OSRM.SOURCE_MARKER_LABEL;
+ my_markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') );
+
+ my_markers.route[my_markers.route.length-1].label = OSRM.TARGET_MARKER_LABEL;
+ my_markers.route[my_markers.route.length-1].marker.setIcon( new L.Icon('images/marker-target.png') );
+ }
+
+ // recompute route
+ getRoute(OSRM.FULL_DESCRIPTION);
+ my_markers.highlight.hide();
+}
diff --git a/WebContent/test.html b/WebContent/test.html
deleted file mode 100644
index 782af23ad..000000000
--- a/WebContent/test.html
+++ /dev/null
@@ -1,27 +0,0 @@
-
- This could be your output.'+(i+1)+'. ';
-
route_desc += '';
route_desc += ''
+ response.route_instructions[i][0] + ' on ';
@@ -212,6 +214,8 @@ function showNoRouteDescription() {
document.getElementById('information-box').innerHTML = " Test Javascript Snippets
-