added legal headers,

beautified comments,
moved language settings to config,
moved timeout settings to config,
corrected bug with route link and via nodes
removed old files
This commit is contained in:
DennisSchiefer 2012-03-14 16:30:11 +01:00
parent 5ebe8080f9
commit 4b40f1253f
20 changed files with 598 additions and 302 deletions

View File

@ -1,4 +1,25 @@
// dashed polyline /*
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.
*/
// Leaflet extension: Dashed Polyline
// [adds dashed optionally dashed lines when using SVG or VML rendering]
// dashed polyline class
L.DashedPolyline = L.Polyline.extend({ L.DashedPolyline = L.Polyline.extend({
initialize: function(latlngs, options) { initialize: function(latlngs, options) {
L.Polyline.prototype.initialize.call(this, latlngs, options); L.Polyline.prototype.initialize.call(this, latlngs, options);

View File

@ -1,3 +1,26 @@
/*
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.
*/
// Leaflet extension: MouseMarker
// [marker class that propagates modifier and button presses]
// [currently deactivated: propagation mousemove events]
// extended marker class
L.MouseMarker = L.Marker.extend({ L.MouseMarker = L.Marker.extend({
initialize: function (latlng, options) { initialize: function (latlng, options) {
L.Marker.prototype.initialize.apply(this, arguments); L.Marker.prototype.initialize.apply(this, arguments);

View File

@ -1,4 +1,22 @@
/*
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 browser detection // OSRM browser detection
// [simple detection routines to respect some browser peculiarities]
(function() { (function() {

View File

@ -1,4 +1,22 @@
// GUI functionality /*
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 GUI functionality
// [responsible for all non-routing related GUI behaviour]
OSRM.GUI = { OSRM.GUI = {

View File

@ -1,39 +1,54 @@
/*
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 JSONP call wrapper // OSRM JSONP call wrapper
// w/ DOM cleaning, fencing, timout handling // [wrapper for JSONP calls with DOM cleaning, fencing, timout handling]
OSRM.JSONP = { OSRM.JSONP = {
// storage to keep track of unfinished JSONP calls
fences: {}, fences: {},
callbacks: {}, callbacks: {},
timeouts: {}, timeouts: {},
timers: {}, timers: {},
TIMEOUT: OSRM.DEFAULTS.JSONP_TIMEOUT,
late: function() { },//console.log("reply too late");}, // default callback routines
empty: function() { },//console.log("empty callback");}, late: function() { /*OSRM.debug.log("[jsonp] reply too late");*/ },
empty: function() { /*OSRM.debug.log("[jsonp] empty callback");*/ },
// init JSONP call
call: function(source, callback_function, timeout_function, timeout, id) { call: function(source, callback_function, timeout_function, timeout, id) {
// only one active JSONP call per id // only one active JSONP call per id
if (OSRM.JSONP.fences[id] == true) if (OSRM.JSONP.fences[id] == true)
return false; return false;
OSRM.JSONP.fences[id] = true; OSRM.JSONP.fences[id] = true;
// console.log("[status] jsonp init for "+id);
// console.log("[status] jsonp request ",source);
// wrap timeout function // wrap timeout function
OSRM.JSONP.timeouts[id] = function(response) { OSRM.JSONP.timeouts[id] = function(response) {
timeout_function(response); timeout_function(response);
// var jsonp = document.getElementById('jsonp_'+id); // clean DOM
// if(jsonp)
// jsonp.parentNode.removeChild(jsonp);
OSRM.JSONP.callbacks[id] = OSRM.JSONP.late; // clean functions OSRM.JSONP.callbacks[id] = OSRM.JSONP.late; // clean functions
OSRM.JSONP.timeouts[id] = OSRM.JSONP.late; OSRM.JSONP.timeouts[id] = OSRM.JSONP.late;
OSRM.JSONP.fences[id] = undefined; // clean fence OSRM.JSONP.fences[id] = undefined; // clean fence
// console.log("timeout: "+id); // at the end - otherwise racing conditions may happen // OSRM.debug.log("[jsonp] timout handling: "+id);
// document.getElementById('information-box').innerHTML += "timeout:" + id + "<br>";
}; };
// wrap callback function // wrap callback function
@ -46,18 +61,14 @@ OSRM.JSONP = {
callback_function(response); // actual wrapped callback callback_function(response); // actual wrapped callback
// var jsonp = document.getElementById('jsonp_'+id); // clean DOM
// if(jsonp)
// jsonp.parentNode.removeChild(jsonp);
OSRM.JSONP.callbacks[id] = OSRM.JSONP.late; // clean functions OSRM.JSONP.callbacks[id] = OSRM.JSONP.late; // clean functions
OSRM.JSONP.timeouts[id] = OSRM.JSONP.late; OSRM.JSONP.timeouts[id] = OSRM.JSONP.late;
OSRM.JSONP.fences[id] = undefined; // clean fence OSRM.JSONP.fences[id] = undefined; // clean fence
// console.log("[status] jsonp response for "+id); // at the end - otherwise racing conditions may happen // OSRM.debug.log("[jsonp] response handling: "+id);
// document.getElementById('information-box').innerHTML += "callback:" + id + "<br>";
}; };
// clean DOM (cannot reuse script element with all browsers, unfortunately) // clean DOM (unfortunately, script elements cannot be reused by all browsers)
var jsonp = document.getElementById('jsonp_'+id); var jsonp = document.getElementById('jsonp_'+id);
if(jsonp) if(jsonp)
jsonp.parentNode.removeChild(jsonp); jsonp.parentNode.removeChild(jsonp);
@ -72,6 +83,7 @@ OSRM.JSONP = {
// start timeout timer // start timeout timer
OSRM.JSONP.timers[id] = setTimeout(OSRM.JSONP.timeouts[id], timeout); OSRM.JSONP.timers[id] = setTimeout(OSRM.JSONP.timeouts[id], timeout);
// OSRM.debug.log("[jsonp] init: "+id);
return true; return true;
} }
}; };

View File

@ -1,19 +1,42 @@
// localization /*
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 localization
// [basic localization options]
OSRM.Localization = { OSRM.Localization = {
language: "en",
// if existing, return localized string -> English string -> input string
translate: function(text) { translate: function(text) {
if( OSRM.Localization[OSRM.Localization.language][text] ) if( OSRM.Localization[OSRM.DEFAULTS.LANGUAGE][text] )
return OSRM.Localization[OSRM.Localization.language][text]; return OSRM.Localization[OSRM.DEFAULTS.LANGUAGE][text];
else if( OSRM.Localization[OSRM.Localization.language][text] ) else if( OSRM.Localization["en"][text] )
return OSRM.Localization[OSRM.Localization.language][text]; return OSRM.Localization["en"][text];
else else
return text; return text;
}, },
}; };
// shorter call to translate function
OSRM.loc = OSRM.Localization.translate; OSRM.loc = OSRM.Localization.translate;
// German language support
OSRM.Localization["de"] = { OSRM.Localization["de"] = {
//gui //gui
"GUI_START": "Start", "GUI_START": "Start",
@ -23,13 +46,13 @@ OSRM.Localization["de"] = {
"GUI_ROUTE": "Route", "GUI_ROUTE": "Route",
"GUI_REVERSE": "Umdrehen", "GUI_REVERSE": "Umdrehen",
"GUI_OPTIONS": "Optionen", "GUI_OPTIONS": "Optionen",
"GUI_HIGHLIGHT_UNNAMED_ROADS": "Unbenannte Stra<EFBFBD>en hervorheben", "GUI_HIGHLIGHT_UNNAMED_ROADS": "Unbenannte Straßen hervorheben",
"GUI_START_TOOLTIP": "Startposition eingeben", "GUI_START_TOOLTIP": "Startposition eingeben",
"GUI_END_TOOLTIP": "Zielposition eingeben", "GUI_END_TOOLTIP": "Zielposition eingeben",
"GUI_LEGAL_NOTICE": "GUI2 v0.1 120313 - OSRM hosting by <a href='http://algo2.iti.kit.edu/'>KIT</a> - Geocoder by <a href='http://www.osm.org/'>OSM</a>", "GUI_LEGAL_NOTICE": "GUI2 v0.1 120313 - OSRM hosting by <a href='http://algo2.iti.kit.edu/'>KIT</a> - Geocoder by <a href='http://www.osm.org/'>OSM</a>",
// geocoder // geocoder
"SEARCH_RESULTS": "Suchergebnisse", "SEARCH_RESULTS": "Suchergebnisse",
"TIMED_OUT": "Zeit<EFBFBD>berschreitung", "TIMED_OUT": "Zeitüberschreitung",
"NO_RESULTS_FOUND": "Keine Ergebnisse gefunden", "NO_RESULTS_FOUND": "Keine Ergebnisse gefunden",
// routing // routing
"ROUTE_DESCRIPTION": "Routenbeschreibung", "ROUTE_DESCRIPTION": "Routenbeschreibung",
@ -40,9 +63,11 @@ OSRM.Localization["de"] = {
"DISTANCE": "Distanz", "DISTANCE": "Distanz",
"DURATION": "Dauer", "DURATION": "Dauer",
"YOUR_ROUTE_IS_BEING_COMPUTED": "Ihre Route wird berechnet", "YOUR_ROUTE_IS_BEING_COMPUTED": "Ihre Route wird berechnet",
"NO_ROUTE_FOUND": "Keine Route hierher m<EFBFBD>glich", "NO_ROUTE_FOUND": "Keine Route hierher möglich",
}; };
// English language support
OSRM.Localization["en"] = { OSRM.Localization["en"] = {
//gui //gui
"GUI_START": "Start", "GUI_START": "Start",

View File

@ -1,8 +1,25 @@
// OSRM.Marker class /*
// + sub-classes 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 markers
// [base marker class, derived highlight marker and route marker classes, marker management]
// base class // base marker class (wraps Leaflet markers)
OSRM.Marker = function( label, style, position ) { OSRM.Marker = function( label, style, position ) {
this.label = label ? label : "marker"; this.label = label ? label : "marker";
this.position = position ? position : new L.LatLng(0,0); this.position = position ? position : new L.LatLng(0,0);
@ -52,7 +69,7 @@ toString: function() {
}); });
// highlight marker // highlight marker class (cannot be dragged)
OSRM.HighlightMarker = function( label, style, position) { OSRM.HighlightMarker = function( label, style, position) {
OSRM.HighlightMarker.prototype.base.constructor.apply( this, arguments ); OSRM.HighlightMarker.prototype.base.constructor.apply( this, arguments );
this.label = label ? label : "highlight_marker"; this.label = label ? label : "highlight_marker";
@ -65,7 +82,7 @@ toString: function() {
}); });
// route marker // route marker class (draggable, invokes route drawing routines)
OSRM.RouteMarker = function ( label, style, position ) { OSRM.RouteMarker = function ( label, style, position ) {
OSRM.RouteMarker.prototype.base.constructor.apply( this, arguments ); OSRM.RouteMarker.prototype.base.constructor.apply( this, arguments );
this.label = label ? label : "route_marker"; this.label = label ? label : "route_marker";
@ -78,8 +95,6 @@ OSRM.RouteMarker = function ( label, style, position ) {
OSRM.inheritFrom( OSRM.RouteMarker, OSRM.Marker ); OSRM.inheritFrom( OSRM.RouteMarker, OSRM.Marker );
OSRM.extend( OSRM.RouteMarker, { OSRM.extend( OSRM.RouteMarker, {
onClick: function(e) { onClick: function(e) {
// if(!e.ctrlKey)
// return;
for( var i=0; i<my_markers.route.length; i++) { for( var i=0; i<my_markers.route.length; i++) {
if( my_markers.route[i].marker === this ) { if( my_markers.route[i].marker === this ) {
my_markers.removeMarker( i ); my_markers.removeMarker( i );
@ -91,9 +106,8 @@ onClick: function(e) {
my_markers.highlight.hide(); my_markers.highlight.hide();
}, },
onDrag: function(e) { onDrag: function(e) {
// OSRM.debug.log("[event] drag event");
this.parent.setPosition( e.target.getLatLng() ); this.parent.setPosition( e.target.getLatLng() );
if(OSRM.dragging == true) // TODO: hack to deal with drag events after dragend event if(OSRM.dragging == true) // TODO: hack that deals with drag events after dragend event
getRoute(OSRM.NO_DESCRIPTION); getRoute(OSRM.NO_DESCRIPTION);
else else
getRoute(OSRM.FULL_DESCRIPTION); getRoute(OSRM.FULL_DESCRIPTION);
@ -101,7 +115,6 @@ onDrag: function(e) {
updateLocation( this.parent.label ); updateLocation( this.parent.label );
}, },
onDragStart: function(e) { onDragStart: function(e) {
// OSRM.debug.log("[event] dragstart event");
OSRM.dragging = true; OSRM.dragging = true;
// hack to store id of dragged marker // hack to store id of dragged marker
@ -119,11 +132,10 @@ onDragStart: function(e) {
updateLocation( this.parent.label ); updateLocation( this.parent.label );
}, },
onDragEnd: function(e) { onDragEnd: function(e) {
// OSRM.debug.log("[event] dragend event");
getRoute(OSRM.FULL_DESCRIPTION); getRoute(OSRM.FULL_DESCRIPTION);
if (my_route.isShown()) { if (my_route.isShown()) {
my_route.hideOldRoute(); my_route.hideOldRoute();
my_route.hideUnnamedRoute(); // provides better visuals my_route.hideUnnamedRoute();
} }
OSRM.dragging = false; OSRM.dragging = false;
@ -135,7 +147,8 @@ toString: function() {
}); });
//marker array class // marker management class (all route markers should only be set and deleted with these routines!)
// [this holds the vital information of the route]
OSRM.Markers = function() { OSRM.Markers = function() {
this.route = new Array(); this.route = new Array();
this.highlight = new OSRM.HighlightMarker("highlight", {draggable:false,icon:OSRM.icons['marker-highlight']});; this.highlight = new OSRM.HighlightMarker("highlight", {draggable:false,icon:OSRM.icons['marker-highlight']});;

View File

@ -1,7 +1,25 @@
// OSRM route classes /*
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 routes
// [drawing of all types of route geometry]
// base route class // simple route class (wraps Leaflet Polyline)
OSRM.SimpleRoute = function (label, style) { OSRM.SimpleRoute = function (label, style) {
this.label = (label ? label : "route"); this.label = (label ? label : "route");
this.route = new L.DashedPolyline(); this.route = new L.DashedPolyline();
@ -35,7 +53,6 @@ setStyle: function(style) {
}, },
centerView: function() { centerView: function() {
var bounds = new L.LatLngBounds( this.getPositions() ); var bounds = new L.LatLngBounds( this.getPositions() );
bounds._southWest.lng-=1.02; // dirty hack
map.fitBounds( bounds ); map.fitBounds( bounds );
}, },
onClick: function(e) { onClick: function(e) {
@ -48,7 +65,7 @@ toString: function() {
}); });
// multiroute class (several separate route parts) // multiroute class (wraps Leaflet LayerGroup to hold several disjoint routes)
OSRM.MultiRoute = function (label) { OSRM.MultiRoute = function (label) {
this.label = (label ? label : "multiroute"); this.label = (label ? label : "multiroute");
this.route = new L.LayerGroup(); this.route = new L.LayerGroup();
@ -84,7 +101,8 @@ toString: function() {
}); });
// main route class // route management (handles drawing of route geometry - current route, old route, unnamed route, highlight unnamed streets)
// [this holds the route geometry]
OSRM.Route = function() { OSRM.Route = function() {
this._current_route = new OSRM.SimpleRoute("current" , {dashed:false} ); this._current_route = new OSRM.SimpleRoute("current" , {dashed:false} );
this._old_route = new OSRM.SimpleRoute("old", {dashed:false,color:"#123"} ); this._old_route = new OSRM.SimpleRoute("old", {dashed:false,color:"#123"} );
@ -129,7 +147,7 @@ OSRM.extend( OSRM.Route,{
hideUnnamedRoute: function() { hideUnnamedRoute: function() {
this._unnamed_route.hide(); this._unnamed_route.hide();
}, },
// TODO: hack to put unnamed_route above old_route -> easier way in Leaglet 0.4+ // TODO: hack to put unnamed_route above old_route -> easier way in will be available Leaflet 0.4
_raiseUnnamedRoute: function() { _raiseUnnamedRoute: function() {
if(this._unnamed_route.isShown()) { if(this._unnamed_route.isShown()) {
this._unnamed_route.hide(); this._unnamed_route.hide();

View File

@ -1,12 +0,0 @@
// OSRM route class
OSRM.TheRoute = {
};
OSRM.extend( OSRM.TheRoute, {
show: function() {},
hide: function() {},
});

View File

@ -1,8 +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 base class // OSRM base class
// [has to loaded before all other OSRM classes]
OSRM = {}; OSRM = {};
OSRM.VERSION = '0.1'; OSRM.VERSION = '0.1';
// inheritance helper function (convenience function) // inheritance helper function (convenience function)
OSRM._inheritFromHelper = function() {}; OSRM._inheritFromHelper = function() {};
OSRM.inheritFrom = function( sub_class, base_class ) { OSRM.inheritFrom = function( sub_class, base_class ) {
@ -12,6 +31,7 @@ OSRM.inheritFrom = function( sub_class, base_class ) {
sub_class.prototype.base = base_class.prototype; sub_class.prototype.base = base_class.prototype;
}; };
// class prototype extending helper function (convenience function) // class prototype extending helper function (convenience function)
OSRM.extend = function( target_class, properties ) { OSRM.extend = function( target_class, properties ) {
for( property in properties ) { for( property in properties ) {
@ -19,6 +39,7 @@ OSRM.extend = function( target_class, properties ) {
} }
}; };
// usage: // usage:
// SubClass = function() { // SubClass = function() {
// SubClass.prototype.base.constructor.apply(this, arguments); // SubClass.prototype.base.constructor.apply(this, arguments);

View File

@ -1,5 +1,22 @@
/*
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 config file // OSRM config file
// (has to be loaded directly after OSRM.base!) // [has to be loaded directly after OSRM.base]
OSRM.DEFAULTS = { OSRM.DEFAULTS = {
HOST_ROUTING_URL: 'http://router.project-osrm.org/viaroute', HOST_ROUTING_URL: 'http://router.project-osrm.org/viaroute',
@ -11,4 +28,5 @@ OSRM.DEFAULTS = {
ONLOAD_LONGITUDE: 10.10, ONLOAD_LONGITUDE: 10.10,
ONLOAD_SOURCE: "", ONLOAD_SOURCE: "",
ONLOAD_TARGET: "", ONLOAD_TARGET: "",
LANGUAGE: "en",
}; };

View File

@ -1,5 +1,22 @@
/*
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.
*/
// debug code for OSRM // debug code for OSRM
// (works faster than console.log in time-critical events) // [works better than console.log in older browsers and for logging event handling]
OSRM.debug = {}; OSRM.debug = {};

View File

@ -1,11 +1,31 @@
/*
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 geocoding routines
// [geocoder query, management and display of geocoder results]
// [TODO: better separation of GUI and geocoding routines, reverse geocoding]
// some constants // some constants
OSRM.GEOCODE_POST = 'http://nominatim.openstreetmap.org/search?format=json'; OSRM.GEOCODE_POST = 'http://nominatim.openstreetmap.org/search?format=json';
OSRM.REVERSE_GEOCODE_POST = 'http://nominatim.openstreetmap.org/reverse?format=json';
OSRM.SOURCE_MARKER_LABEL = "source"; OSRM.SOURCE_MARKER_LABEL = "source";
OSRM.TARGET_MARKER_LABEL = "target"; OSRM.TARGET_MARKER_LABEL = "target";
// update locations in input boxes // update geo coordinates in input boxes
function updateLocation(marker_id) { function updateLocation(marker_id) {
if (marker_id == OSRM.SOURCE_MARKER_LABEL) { 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); document.getElementById("input-source-name").value = my_markers.route[0].getPosition().lat.toFixed(6) + ", " + my_markers.route[0].getPosition().lng.toFixed(6);
@ -13,77 +33,11 @@ function updateLocation(marker_id) {
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); 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 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() { // process input request and call geocoder if needed
//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.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.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;
}
}
// prepare request and call geocoder
function callGeocoder(marker_id, query) { function callGeocoder(marker_id, query) {
//geo coordinate given? //geo coordinates given -> go directly to drawing results
if(query.match(/^\s*[-+]?[0-9]*\.?[0-9]+\s*[,;]\s*[-+]?[0-9]*\.?[0-9]+\s*$/)){ if(query.match(/^\s*[-+]?[0-9]*\.?[0-9]+\s*[,;]\s*[-+]?[0-9]*\.?[0-9]+\s*$/)){
var coord = query.split(/[,;]/); var coord = query.split(/[,;]/);
onclickGeocoderResult(marker_id, coord[0], coord[1]); onclickGeocoderResult(marker_id, coord[0], coord[1]);
@ -94,10 +48,10 @@ function callGeocoder(marker_id, query) {
//build request //build request
if (marker_id == OSRM.SOURCE_MARKER_LABEL) { if (marker_id == OSRM.SOURCE_MARKER_LABEL) {
var src= OSRM.GEOCODE_POST + "&q=" + query; var src= OSRM.GEOCODE_POST + "&q=" + query;
OSRM.JSONP.call( src, showGeocoderResults_Source, showGeocoderResults_Timeout, OSRM.JSONP.TIMEOUT, "geocoder_source" ); OSRM.JSONP.call( src, showGeocoderResults_Source, showGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "geocoder_source" );
} else if (marker_id == OSRM.TARGET_MARKER_LABEL) { } else if (marker_id == OSRM.TARGET_MARKER_LABEL) {
var src = OSRM.GEOCODE_POST + "&q=" + query; var src = OSRM.GEOCODE_POST + "&q=" + query;
OSRM.JSONP.call( src, showGeocoderResults_Target, showGeocoderResults_Timeout, OSRM.JSONP.TIMEOUT, "geocoder_target" ); OSRM.JSONP.call( src, showGeocoderResults_Target, showGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "geocoder_target" );
} }
} }
@ -117,7 +71,7 @@ function onclickGeocoderResult(marker_id, lat, lon) {
getRoute(OSRM.FULL_DESCRIPTION); getRoute(OSRM.FULL_DESCRIPTION);
} }
// processing JSONP response of geocoder // process JSONP response of geocoder
// (with wrapper functions for source/target jsonp) // (with wrapper functions for source/target jsonp)
function showGeocoderResults_Source(response) { showGeocoderResults(OSRM.SOURCE_MARKER_LABEL, response); } function showGeocoderResults_Source(response) { showGeocoderResults(OSRM.SOURCE_MARKER_LABEL, response); }
function showGeocoderResults_Target(response) { showGeocoderResults(OSRM.TARGET_MARKER_LABEL, response); } function showGeocoderResults_Target(response) { showGeocoderResults(OSRM.TARGET_MARKER_LABEL, response); }
@ -162,3 +116,74 @@ function showGeocoderResults_Timeout() {
document.getElementById('information-box-headline').innerHTML = OSRM.loc("SEARCH_RESULTS")+":"; document.getElementById('information-box-headline').innerHTML = OSRM.loc("SEARCH_RESULTS")+":";
document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("TIMED_OUT")+".<p>"; document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("TIMED_OUT")+".<p>";
} }
// - [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;
// }
//}

View File

@ -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 { body {
padding: 0; padding: 0;
margin: 0; margin: 0;
@ -241,7 +261,8 @@ html, body, #map {
font-size:10px; 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 .not-selectable
{ {
cursor:default; cursor:default;
@ -260,6 +281,7 @@ html, body, #map {
user-select: text; user-select: text;
} }
/* buttons */ /* buttons */
.button .button
{ {

View File

@ -1,3 +1,20 @@
<!--
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.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html> <html>

View File

@ -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; var map;
// onload initialization routine
function init() { function init() {
prefetchImages(); prefetchImages();
prefetchIcons(); prefetchIcons();
@ -76,6 +97,7 @@ function centerOnGeolocation() {
// init map // init map
function initMap() { function initMap() {
// setup tile servers
var osmorgURL = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', var osmorgURL = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
osmorgAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 Mapnik', osmorgAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 Mapnik',
osmorgOptions = {maxZoom: 18, attribution: osmorgAttribution}; osmorgOptions = {maxZoom: 18, attribution: osmorgAttribution};
@ -97,14 +119,16 @@ function initMap() {
mapquest = new L.TileLayer(mapquestURL, mapquestOptions), mapquest = new L.TileLayer(mapquestURL, mapquestOptions),
cloudmade = new L.TileLayer(cloudmadeURL, cloudmadeOptions); cloudmade = new L.TileLayer(cloudmadeURL, cloudmadeOptions);
// setup map
map = new L.Map('map', { map = new L.Map('map', {
center: new L.LatLng(51.505, -0.09), center: new L.LatLng(51.505, -0.09),
zoom: 13, 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, fadeAnimation: false,
layers: [osmorg] layers: [osmorg]
}); });
// add tileservers
var baseMaps = { var baseMaps = {
"osm.org": osmorg, "osm.org": osmorg,
"osm.de": osmde, "osm.de": osmde,
@ -116,12 +140,15 @@ function initMap() {
var layersControl = new L.Control.Layers(baseMaps, overlayMaps); var layersControl = new L.Control.Layers(baseMaps, overlayMaps);
map.addControl(layersControl); map.addControl(layersControl);
// move zoom markers
getElementsByClassName(document,'leaflet-control-zoom')[0].style.left="420px"; getElementsByClassName(document,'leaflet-control-zoom')[0].style.left="420px";
getElementsByClassName(document,'leaflet-control-zoom')[0].style.top="5px"; 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); }); map.on('zoomend', function(e) { getRoute(OSRM.FULL_DESCRIPTION); });
// click on map to set source and target nodes
map.on('click', function(e) { map.on('click', function(e) {
if( !my_markers.route[0] || my_markers.route[0].label != OSRM.SOURCE_MARKER_LABEL) { if( !my_markers.route[0] || my_markers.route[0].label != OSRM.SOURCE_MARKER_LABEL) {
index = my_markers.setSource( e.latlng ); index = my_markers.setSource( e.latlng );
@ -140,39 +167,10 @@ function initMap() {
// updateReverseGeocoder("target"); // 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<objs.length; ++i)
// objs[i].style.display ='';
//
// if (obj == null)
// return;
//
// if (obj instanceof SVGPathElement)
// xroute.route.fire('mousemove',e);
// else
// xroute.route.fire('mouseout',e);
// });
} }
// parse URL GET parameters if existing // parse URL GET parameters if any exist
function checkURL(){ function checkURL(){
var called_url = document.location.search.substr(1,document.location.search.length); var called_url = document.location.search.substr(1,document.location.search.length);
if( called_url != '') { if( called_url != '') {
@ -196,19 +194,18 @@ function checkURL(){
// draw via points // draw via points
if( positions.length > 0) if( positions.length > 0)
my_markers.setSource( positions[0] ); my_markers.setSource( positions[0] );
for(var i=1; i<positions.length-1;i++)
my_markers.setVia( i-1, positions[i] );
if(positions.length > 1) if(positions.length > 1)
my_markers.setTarget( positions[positions.length-1] ); my_markers.setTarget( positions[positions.length-1] );
for(var i=1; i<positions.length-1;i++)
my_markers.setVia( i-1, positions[i] );
for(var i=0; i<my_markers.route.length;i++) for(var i=0; i<my_markers.route.length;i++)
my_markers.route[i].show(); my_markers.route[i].show();
// compute route // compute route
getRoute(OSRM.FULL_DESCRIPTION); getRoute(OSRM.FULL_DESCRIPTION);
// center on route
var bounds = new L.LatLngBounds( positions ); var bounds = new L.LatLngBounds( positions );
//bounds._southWest.lng-=1.02; // dirty hacks
map.fitBounds( bounds ); map.fitBounds( bounds );
//my_route.centerView();
} }
} }

View File

@ -1,3 +1,25 @@
/*
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 routing routines
// [management of routing/direction requests and processing of responses]
// [TODO: major refactoring scheduled]
// some variables
var my_route = undefined; var my_route = undefined;
var my_markers = undefined; var my_markers = undefined;
@ -7,40 +29,17 @@ OSRM.dragging = false;
OSRM.pending = false; OSRM.pending = false;
OSRM.pendingTimer = undefined; OSRM.pendingTimer = undefined;
// init data
// init routing data structures
function initRouting() { function initRouting() {
my_route = new OSRM.Route(); my_route = new OSRM.Route();
my_markers = new OSRM.Markers(); my_markers = new OSRM.Markers();
} }
// 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;
}
// display a transmitted route // -- JSONP processing --
// process JSONP response of routing server
function timeoutRouteSimple() { function timeoutRouteSimple() {
showNoRouteGeometry(); showNoRouteGeometry();
showNoRouteDescription(); showNoRouteDescription();
@ -69,9 +68,10 @@ function showRouteSimple(response) {
} }
updateHints(response); updateHints(response);
// // TODO: hack to process final drag event, if it was fenced, but we are still dragging (alternative approach)
// if(OSRM.pending) { // if(OSRM.pending) {
// clearTimeout(OSRM.pendingTimer); // clearTimeout(OSRM.pendingTimer);
// OSRM.pendingTimer = setTimeout(timeoutDrag,100); // dirty dirty! // OSRM.pendingTimer = setTimeout(timeoutDrag,100);
// } // }
} }
function showRoute(response) { function showRoute(response) {
@ -92,6 +92,8 @@ function showRoute(response) {
updateHints(response); updateHints(response);
} }
// show route geometry
function showNoRouteGeometry() { function showNoRouteGeometry() {
var positions = []; var positions = [];
for(var i=0; i<my_markers.route.length;i++) for(var i=0; i<my_markers.route.length;i++)
@ -111,6 +113,8 @@ function showRouteGeometry(response) {
my_route.showRoute(points, OSRM.Route.ROUTE); my_route.showRoute(points, OSRM.Route.ROUTE);
} }
// route description display (and helper functions)
function onClickRouteDescription(geometry_index) { function onClickRouteDescription(geometry_index) {
var positions = my_route.getPositions(); var positions = my_route.getPositions();
@ -155,8 +159,6 @@ function showRouteDescription(response) {
route_desc += '<img width="18px" src="images/'+getDirectionIcon(response.route_instructions[i][0])+'"/>'; route_desc += '<img width="18px" src="images/'+getDirectionIcon(response.route_instructions[i][0])+'"/>';
route_desc += "</td>"; route_desc += "</td>";
//route_desc += '<td class="result-counter"><span">'+(i+1)+'.</span></td>';
route_desc += '<td class="result-items">'; route_desc += '<td class="result-items">';
route_desc += '<span class="result-item" onclick="onClickRouteDescription('+response.route_instructions[i][3]+')">' route_desc += '<span class="result-item" onclick="onClickRouteDescription('+response.route_instructions[i][3]+')">'
+ response.route_instructions[i][0] + ' on '; + response.route_instructions[i][0] + ' on ';
@ -212,6 +214,8 @@ function showNoRouteDescription() {
document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+".<p>"; document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+".<p>";
} }
// unnamed streets display
function showRouteNonames(response) { function showRouteNonames(response) {
// do not display unnamed streets? // do not display unnamed streets?
if( document.getElementById('option-highlight-nonames').checked == false) { if( document.getElementById('option-highlight-nonames').checked == false) {
@ -252,14 +256,15 @@ function showRouteNonames(response) {
my_route.showUnnamedRoute(all_positions); my_route.showUnnamedRoute(all_positions);
} }
// function for dragging and drawing routes
//-- main function --
// generate server calls to query routes
function getRoute(do_description) { function getRoute(do_description) {
// if source or target are not set -> hide route // if source or target are not set -> hide route
if( my_markers.route.length < 2 ) { if( my_markers.route.length < 2 ) {
my_route.hideRoute(); my_route.hideRoute();
//my_markers.removeVias(); // TODO: do I need this?
//my_markers.highlight.hide();
return; return;
} }
@ -292,16 +297,17 @@ function getRoute(do_description) {
} }
// do call // 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) { if(called == false && !do_description) {
clearTimeout(OSRM.pendingTimer); clearTimeout(OSRM.pendingTimer);
OSRM.pendingTimer = setTimeout(timeoutDrag,OSRM.JSONP.TIMEOUT); OSRM.pendingTimer = setTimeout(timeoutDrag,OSRM.DEFAULTS.JSONP_TIMEOUT);
} }
else { else {
clearTimeout(OSRM.pendingTimer); 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) { // if(called == false && !do_description) {
// OSRM.pending = true; // OSRM.pending = true;
// } else { // } else {
@ -309,28 +315,42 @@ function getRoute(do_description) {
// OSRM.pending = false; // OSRM.pending = false;
// } // }
} }
function timeoutDrag() { function timeoutDrag() {
my_markers.route[OSRM.dragid].hint = undefined; my_markers.route[OSRM.dragid].hint = undefined;
getRoute(OSRM.NO_DESCRIPTION); getRoute(OSRM.NO_DESCRIPTION);
} }
function startRouting() {
getRoute(OSRM.FULL_DESCRIPTION); //-- helper functions --
}
//decode compressed route geometry
function resetRouting() { function decodeRouteGeometry(encoded, precision) {
document.getElementById('input-source-name').value = ""; precision = Math.pow(10, -precision);
document.getElementById('input-target-name').value = ""; var len = encoded.length, index=0, lat=0, lng = 0, array = [];
while (index < len) {
my_route.hideRoute(); var b, shift = 0, result = 0;
my_markers.removeAll(); do {
my_markers.highlight.hide(); b = encoded.charCodeAt(index++) - 63;
result |= (b & 0x1f) << shift;
document.getElementById('information-box').innerHTML = ""; shift += 5;
document.getElementById('information-box-headline').innerHTML = ""; } 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) { function updateHints(response) {
var hint_locations = response.hint_data.locations; var hint_locations = response.hint_data.locations;
my_markers.checksum = response.hint_data.checksum; my_markers.checksum = response.hint_data.checksum;
@ -338,6 +358,7 @@ function updateHints(response) {
my_markers.route[i].hint = hint_locations[i]; my_markers.route[i].hint = hint_locations[i];
} }
// snap all markers to the received route
function snapRoute() { function snapRoute() {
var positions = my_route.getPositions(); var positions = my_route.getPositions();
@ -350,48 +371,8 @@ function snapRoute() {
updateLocation( "target" ); updateLocation( "target" );
} }
function positionsToInput() { // map driving instructions to images
if(my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL) { // [TODO: better implementation, language-safe]
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();
}
//--------------------
function getDirectionIcon(name) { function getDirectionIcon(name) {
var directions = { var directions = {
"Turn left":"turn-left.png", "Turn left":"turn-left.png",
@ -421,3 +402,54 @@ function getDirectionIcon(name) {
else else
return "default.png"; return "default.png";
} }
// -- 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();
}

View File

@ -1,27 +0,0 @@
<html>
<head>
<script src="leaflet/leaflet-src.js"></script>
<script src="OSRM.js"></script>
<script src="OSRM.Markers.js"></script>
<script type="text/javascript">
function testSnippet()
{
var marker = new OSRM.RouteMarker("source",undefined,new L.Icon('images/marker-source.png'));
marker.yyy();
for(a in marker)
alert(a);
alert(marker);
}
</script>
</head>
<body>
<h1>Test Javascript Snippets</h1>
<p id="output">This could be your output.</p>
<button type="button" onclick="testSnippet()">Run Snippet</button>
</body>
</html>

View File

@ -1,4 +1,21 @@
// compatibility mode for old browser /*
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.
*/
// compatibility tools for old browsers
function getElementsByClassName(node, classname) { function getElementsByClassName(node, classname) {
var a = []; var a = [];
var re = new RegExp('(^| )'+classname+'( |$)'); var re = new RegExp('(^| )'+classname+'( |$)');

View File

@ -1,5 +1,25 @@
/*
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.
*/
// store location of via points returned by server
var via_points; var via_points;
// find route segment of current route geometry that is closest to the new via node (marked by index of its endpoint)
function findNearestRouteSegment( new_via ) { function findNearestRouteSegment( new_via ) {
var min_dist = Number.MAX_VALUE; var min_dist = Number.MAX_VALUE;
var min_index = undefined; var min_index = undefined;
@ -17,6 +37,7 @@ function findNearestRouteSegment( new_via ) {
} }
// find the correct index among all via nodes to insert the new via node, and insert it
function findViaPosition( new_via_position ) { function findViaPosition( new_via_position ) {
// find route segment that is closest to click position (marked by last index) // find route segment that is closest to click position (marked by last index)
var nearest_index = findNearestRouteSegment( new_via_position ); var nearest_index = findNearestRouteSegment( new_via_position );