Compare commits

...

38 Commits

Author SHA1 Message Date
DennisSchiefer 4e2e95cc27 version and date is now taken from OSRM.base,
when source/target markers are deleted the inputbox is emptied
2012-03-19 17:09:03 +01:00
DennisSchiefer f4c6ec90ce fix to route link generator and parser 2012-03-19 10:28:32 +01:00
DennisSchiefer eed22b343a more geocoder refactoring 2012-03-18 22:17:59 +01:00
DennisSchiefer 08ce748a37 removed dirty flags 2012-03-18 22:00:29 +01:00
DennisSchiefer 69790eb8c7 refactored geocoder code (still need to check dirty flags) 2012-03-18 21:44:14 +01:00
DennisSchiefer 97b9c65c97 refactored reverse geocoder 2012-03-18 20:03:15 +01:00
DennisSchiefer 92dbadebae increased zoom level for route description (new config entry),
removed some deprecated comments
2012-03-18 18:17:04 +01:00
DennisSchiefer fe6d854e11 improved handling of dragging,
link to route gui improved,
JSONP can now take parameters
2012-03-18 17:42:05 +01:00
DennisSchiefer 4615b01fdf moved inputbox logic to javascript file,
corrected error with second ENTER not being registered
2012-03-18 15:04:17 +01:00
DennisSchiefer 276b023b05 changed checking if eventhandler storage exists 2012-03-18 12:29:02 +01:00
DennisSchiefer 350cacb2f3 added try-finally guards to JSONP calls 2012-03-18 11:38:21 +01:00
DennisSchiefer 25ec6105c5 reverse geocoding now always shows two information if possible 2012-03-17 22:26:57 +01:00
DennisSchiefer 3e4249ad41 used abbreviations for sub-namespaces GLOBALS, CONSTANTS 2012-03-17 20:49:19 +01:00
DennisSchiefer 13126ac0c1 moved all variables/objects to OSRM namespace 2012-03-17 20:43:52 +01:00
DennisSchiefer d51aee4fbe bugfix to route link storing map view location 2012-03-17 17:07:34 +01:00
DennisSchiefer f9877fd8ba refactoring: used hasSource, hasTarget routines throughout the code 2012-03-17 17:04:45 +01:00
DennisSchiefer a39a35df73 moved leaflet.ie.css to new position 2012-03-17 15:48:24 +01:00
DennisSchiefer 2670dd68f3 added event handler base class 2012-03-17 15:28:27 +01:00
DennisSchiefer 9adb590ce7 added OSRM.CONSTANTS, OSRM.GLOBALS for better structuring,
improved comments in OSRM.base.js and OSRM.config.js
2012-03-17 14:45:04 +01:00
DennisSchiefer 9567a7e38c added support for saving route zoom level and position in route links 2012-03-17 14:17:08 +01:00
DennisSchiefer d86eaa00a0 compressed target.png 2012-03-16 18:27:52 +01:00
DennisSchiefer 54c0d50b68 reseting now also resets OSRM.JSONP 2012-03-16 17:52:10 +01:00
DennisSchiefer 204189c326 - version bump to v0.1.1
- restructured buttons (route is gone, search is show)
- added prefetching gui hide/show buttons
- increased timeout to 5000ms
- click highlight marker to hide it
- boundary box on Europe when querying geocoder
- added "reached your destination" display in route instructions
- improved visual for route summary
- when loading a stored route, source and target are named and the route
is zoomed correctly
- improved display results of reverse geocoder (ues village/country
tags)
- more consistent behaviour when displaying reverse geocoder results
or geocoordinates
- reverse geocoder now works at dragend
- more consistent behaviour when leaving an input box
- reversing a route when only one marker is set empties the result box
2012-03-16 15:06:43 +01:00
DennisSchiefer acdfa546a8 added more precise distance values (at least three digits of precision) 2012-03-16 10:41:54 +01:00
DennisSchiefer 6a9216d6e4 added functions to check whether source or target exists,
readded routing button
2012-03-16 09:42:14 +01:00
DennisSchiefer 9c2a1dc37f implemented several security measures when parsing GET input to the site 2012-03-16 09:07:03 +01:00
DennisSchiefer 26c9d357f0 made reverse geocoding more intuitive,
changed search and route buttons to centering buttons
2012-03-16 07:22:47 +01:00
DennisSchiefer 879d73c629 testing to remove route button -> search will be automatical on lost
focus
2012-03-15 17:45:22 +01:00
DennisSchiefer 441146eeae changed look of route description header area 2012-03-15 17:42:17 +01:00
DennisSchiefer d453cadc8c added call option to set destination when calling the site 2012-03-15 14:22:00 +01:00
DennisSchiefer 74188206e8 website url is now retrieved directly from browser,
removed unneeded localization strings
2012-03-15 14:01:34 +01:00
DennisSchiefer 700206099b made route reset more robust by clearing *really* everything,
improved route description (added distances to the right, bold street
names, orientation in first instruction and non-breaking spaces for
units),
route link now displays the shortened link name,
content of input boxes is only overwritten if the respective node is
set or dragged,
experimental support for reverse geocoding (when setting a new node by
text box or clicking on map)
2012-03-15 13:29:28 +01:00
DennisSchiefer aa952df541 added favicon,
removed commata that IE was complaining about
2012-03-15 09:05:00 +01:00
DennisSchiefer b8944da9dc prevent browser context menu on map 2012-03-14 18:07:15 +01:00
DennisSchiefer 22dda2b285 added new gui buttons for opening/closing,
route button now works,
more precise error message when geocoder does not find a result,
added maximum input length for text boxes
2012-03-14 17:42:14 +01:00
DennisSchiefer 0ee469c4e0 Merge branch 'develop' of
https://DennisSchiefer@bitbucket.org/DennisSchiefer/project-osrm-web.git
into develop

Conflicts:
	WebContent/routing.js
2012-03-14 16:50:14 +01:00
DennisSchiefer a7eef27e99 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,
corrected spelling error for roundabout
2012-03-14 16:45:15 +01:00
DennisSchiefer 4b40f1253f 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
2012-03-14 16:30:11 +01:00
31 changed files with 1189 additions and 625 deletions
+25 -4
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);
@@ -6,7 +27,7 @@ L.DashedPolyline = L.Polyline.extend({
options: { options: {
dashed: true dashed: true
}, }
}); });
@@ -20,7 +41,7 @@ L.DashedPolyline = !L.Browser.svg ? L.DashedPolyline : L.DashedPolyline.extend({
else else
this._path.setAttribute('stroke-dasharray', ''); this._path.setAttribute('stroke-dasharray', '');
} }
}, }
}); });
@@ -34,6 +55,6 @@ L.DashedPolyline = L.Browser.svg || !L.Browser.vml ? L.DashedPolyline : L.Dashed
else else
this._stroke.dashstyle = "solid"; this._stroke.dashstyle = "solid";
} }
}, }
}); });
+24 -1
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);
@@ -26,5 +49,5 @@ L.MouseMarker = L.Marker.extend({
shiftKey: e.shiftKey, shiftKey: e.shiftKey,
button: e.button button: e.button
}); });
}, }
}); });
+19 -1
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() {
@@ -6,7 +24,7 @@
OSRM.Browser = { OSRM.Browser = {
FF3: useragent.search(/Firefox\/3/), FF3: useragent.search(/Firefox\/3/),
IE6_9: useragent.search(/MSIE (6|7|8|9)/), IE6_9: useragent.search(/MSIE (6|7|8|9)/)
}; };
}()); }());
+61
View File
@@ -0,0 +1,61 @@
/*
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 EventHandler
// [adds simple event handling: other classes can derive from this class to acquire custom event handling]
OSRM.EventHandler = function() {
this._listeners = {};
};
OSRM.extend( OSRM.EventHandler, {
// add listener
addListener: function(type, listener) {
if( this._listeners[type] == undefined)
this._listeners[type] = [];
this._listeners[type].push(listener);
},
//remove event listener
removeListener: function(type, listener) {
if( this._listeners[type] != undefined) {
for(var i=0; i<this._listeners[type].length; i++)
if( this._listeners[type][i] == listener) {
this._listeners[type].splice(i,1);
break;
}
}
},
// fire event
fire: function(event) {
if( typeof event == "string")
event = {type:event};
if( !event.target )
event.target = this;
if( !event.type )
throw new Error("event object missing type property!");
if( this._listeners[type] != undefined)
for(var listener in this._listeners[event.type])
listener.call(this, event);
}
});
+20 -2
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 = {
@@ -57,6 +75,6 @@ toggleOptions: function() {
} else { } else {
document.getElementById('options-box').style.visibility="visible"; document.getElementById('options-box').style.visibility="visible";
} }
}, }
}; };
+57 -36
View File
@@ -1,66 +1,78 @@
/*
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");*/ },
call: function(source, callback_function, timeout_function, timeout, id) {
// init JSONP call
call: function(source, callback_function, timeout_function, timeout, id, parameters) {
// 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); try {
timeout_function(response, parameters);
} finally {
OSRM.JSONP.callbacks[id] = OSRM.JSONP.late; // clean functions
OSRM.JSONP.timeouts[id] = OSRM.JSONP.empty;
OSRM.JSONP.fences[id] = undefined; // clean fence
}
// var jsonp = document.getElementById('jsonp_'+id); // clean DOM // OSRM.debug.log("[jsonp] timout handling: "+id);
// if(jsonp)
// jsonp.parentNode.removeChild(jsonp);
OSRM.JSONP.callbacks[id] = OSRM.JSONP.late; // clean functions
OSRM.JSONP.timeouts[id] = OSRM.JSONP.late;
OSRM.JSONP.fences[id] = undefined; // clean fence
// console.log("timeout: "+id); // at the end - otherwise racing conditions may happen
// document.getElementById('information-box').innerHTML += "timeout:" + id + "<br>";
}; };
// wrap callback function // wrap callback function
OSRM.JSONP.callbacks[id] = function(response) { OSRM.JSONP.callbacks[id] = function(response) {
clearTimeout(OSRM.JSONP.timers[id]); // clear timeout timer clearTimeout(OSRM.JSONP.timers[id]); // clear timeout timer
OSRM.JSONP.timers[id] = undefined; OSRM.JSONP.timers[id] = undefined;
if( OSRM.JSONP.fences[id] == undefined ) // fence to prevent execution after timeout function (when precompiled!) try {
return; callback_function(response, parameters); // actual wrapped callback
} finally {
callback_function(response); // actual wrapped callback OSRM.JSONP.callbacks[id] = OSRM.JSONP.empty; // clean functions
OSRM.JSONP.timeouts[id] = OSRM.JSONP.late;
OSRM.JSONP.fences[id] = undefined; // clean fence
}
// var jsonp = document.getElementById('jsonp_'+id); // clean DOM // OSRM.debug.log("[jsonp] response handling: "+id);
// if(jsonp)
// jsonp.parentNode.removeChild(jsonp);
OSRM.JSONP.callbacks[id] = OSRM.JSONP.late; // clean functions
OSRM.JSONP.timeouts[id] = OSRM.JSONP.late;
OSRM.JSONP.fences[id] = undefined; // clean fence
// console.log("[status] jsonp response for "+id); // at the end - otherwise racing conditions may happen
// 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);
// add script to DOM // add script to DOM
var script = document.createElement('script'); var script = document.createElement('script');
@@ -71,7 +83,16 @@ 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;
},
// reset all data
reset: function() {
OSRM.JSONP.fences = {};
OSRM.JSONP.callbacks = {};
OSRM.JSONP.timeouts = {};
OSRM.JSONP.timers = {};
} }
}; };
+68 -23
View File
@@ -1,73 +1,118 @@
// 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",
"GUI_END": "Ende", "GUI_END": "Ziel",
"GUI_RESET": "Reset", "GUI_RESET": "Reset",
"GUI_SEARCH": "Suchen", "GUI_SEARCH": "Zeigen",
"GUI_ROUTE": "Route",
"GUI_REVERSE": "Umdrehen", "GUI_REVERSE": "Umdrehen",
"GUI_OPTIONS": "Optionen", "GUI_OPTIONS": "Optionen",
"GUI_HIGHLIGHT_UNNAMED_ROADS": "Unbenannte Straen 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 v"+OSRM.VERSION+" "+OSRM.DATE+" - 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": "Zeitberschreitung", "TIMED_OUT": "Zeitüberschreitung",
"NO_RESULTS_FOUND": "Keine Ergebnisse gefunden", "NO_RESULTS_FOUND": "Keine Ergebnisse gefunden",
"NO_RESULTS_FOUND_SOURCE": "Keine Ergebnisse gefunden für Start",
"NO_RESULTS_FOUND_TARGET": "Keine Ergebnisse gefunden für Ziel",
// routing // routing
"ROUTE_DESCRIPTION": "Routenbeschreibung", "ROUTE_DESCRIPTION": "Routenbeschreibung",
"GET_LINK": "Generiere Link", "GET_LINK_TO_ROUTE": "Generiere Link",
"LINK_TO_ROUTE": "Link zur Route", "GENERATE_LINK_TO_ROUTE": "Warte auf Antwort",
"LINK_TO_ROUTE_TIMEOUT": "nicht möglich", "LINK_TO_ROUTE_TIMEOUT": "nicht möglich",
"GPX_FILE": "GPX Datei", "GPX_FILE": "GPX Datei",
"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 mglich", "NO_ROUTE_FOUND": "Keine Route hierher möglich",
// directions
"N": "Norden",
"O": "Ost",
"S": "Süden",
"W": "Westen",
"NO": "Nordost",
"SO": "Südost",
"SW": "Südwest",
"NW": "Nordwest"
}; };
// English language support
OSRM.Localization["en"] = { OSRM.Localization["en"] = {
//gui //gui
"GUI_START": "Start", "GUI_START": "Start",
"GUI_END": "End", "GUI_END": "End",
"GUI_RESET": "Reset", "GUI_RESET": "&nbsp;&nbsp;Reset&nbsp;&nbsp;",
"GUI_SEARCH": "Search", "GUI_SEARCH": "&nbsp;&nbsp;Show&nbsp;&nbsp;",
"GUI_ROUTE": "Route",
"GUI_REVERSE": "Reverse", "GUI_REVERSE": "Reverse",
"GUI_OPTIONS": "Options", "GUI_OPTIONS": "Options",
"GUI_HIGHLIGHT_UNNAMED_ROADS": "Highlight unnamed streets", "GUI_HIGHLIGHT_UNNAMED_ROADS": "Highlight unnamed streets",
"GUI_START_TOOLTIP": "Enter start", "GUI_START_TOOLTIP": "Enter start",
"GUI_END_TOOLTIP": "Enter destination", "GUI_END_TOOLTIP": "Enter destination",
"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 v"+OSRM.VERSION+" "+OSRM.DATE+" - 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": "Search Results", "SEARCH_RESULTS": "Search Results",
"TIMED_OUT": "Timed Out", "TIMED_OUT": "Timed Out",
"NO_RESULTS_FOUND": "No results found", "NO_RESULTS_FOUND": "No results found",
"NO_RESULTS_FOUND_SOURCE": "No results found for start",
"NO_RESULTS_FOUND_TARGET": "No results found for end",
//routing //routing
"ROUTE_DESCRIPTION": "Route Description", "ROUTE_DESCRIPTION": "Route Description",
"GET_LINK": "Generate Link", "GET_LINK_TO_ROUTE": "Generate Link",
"LINK_TO_ROUTE": "Route Link", "GENERATE_LINK_TO_ROUTE": "waiting for link",
"LINK_TO_ROUTE_TIMEOUT": "not available", "LINK_TO_ROUTE_TIMEOUT": "not available",
"GPX_FILE": "GPX File", "GPX_FILE": "GPX File",
"DISTANCE": "Distance", "DISTANCE": "Distance",
"DURATION": "Duration", "DURATION": "Duration",
"YOUR_ROUTE_IS_BEING_COMPUTED": "Your route is being computed", "YOUR_ROUTE_IS_BEING_COMPUTED": "Your route is being computed",
"NO_ROUTE_FOUND": "No route possible", "NO_ROUTE_FOUND": "No route possible",
// directions
"N": "north",
"E": "east",
"S": "south",
"W": "west",
"NE": "northeast",
"SE": "southeast",
"SW": "southwest",
"NW": "northwest"
}; };
+81 -58
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);
@@ -11,21 +28,21 @@ OSRM.Marker = function( label, style, position ) {
this.marker.parent = this; this.marker.parent = this;
this.shown = false; this.shown = false;
this.hint = undefined; this.hint = null;
}; };
OSRM.extend( OSRM.Marker,{ OSRM.extend( OSRM.Marker,{
show: function() { show: function() {
map.addLayer(this.marker); OSRM.G.map.addLayer(this.marker);
this.shown = true; this.shown = true;
}, },
hide: function() { hide: function() {
map.removeLayer(this.marker); OSRM.G.map.removeLayer(this.marker);
this.shown = false; this.shown = false;
}, },
setPosition: function( position ) { setPosition: function( position ) {
this.position = position; this.position = position;
this.marker.setLatLng( position ); this.marker.setLatLng( position );
this.hint = undefined; this.hint = null;
}, },
getPosition: function() { getPosition: function() {
return this.position; return this.position;
@@ -39,33 +56,36 @@ getLng: function() {
isShown: function() { isShown: function() {
return this.shown; return this.shown;
}, },
centerView: function(zooming) { centerView: function(zoom) {
var zoom = OSRM.DEFAULTS.ZOOM_LEVEL; if( zoom == undefined )
if( zooming == false ) zoom = OSRM.DEFAULTS.ZOOM_LEVEL;
zoom = map.getZoom(); OSRM.G.map.setView( new L.LatLng( this.position.lat, this.position.lng), zoom);
//map.setView( new L.LatLng( this.position.lat, this.position.lng-0.02), zoom); // dirty hack
map.setView( new L.LatLng( this.position.lat, this.position.lng), zoom);
}, },
toString: function() { toString: function() {
return "OSRM.Marker: \""+this.label+"\", "+this.position+")"; return "OSRM.Marker: \""+this.label+"\", "+this.position+")";
}, }
}); });
// 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";
this.marker.on( 'click', this.onClick );
}; };
OSRM.inheritFrom( OSRM.HighlightMarker, OSRM.Marker ); OSRM.inheritFrom( OSRM.HighlightMarker, OSRM.Marker );
OSRM.extend( OSRM.HighlightMarker, { OSRM.extend( OSRM.HighlightMarker, {
toString: function() { toString: function() {
return "OSRM.HighlightMarker: \""+this.label+"\", "+this.position+")"; return "OSRM.HighlightMarker: \""+this.label+"\", "+this.position+")";
}, },
onClick: function(e) {
this.parent.hide();
}
}); });
// 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,64 +98,55 @@ 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) for( var i=0; i<OSRM.G.markers.route.length; i++) {
// return; if( OSRM.G.markers.route[i].marker === this ) {
for( var i=0; i<my_markers.route.length; i++) { OSRM.G.markers.removeMarker( i );
if( my_markers.route[i].marker === this ) {
my_markers.removeMarker( i );
break; break;
} }
} }
getRoute(OSRM.FULL_DESCRIPTION); getRoute(OSRM.C.FULL_DESCRIPTION);
my_markers.highlight.hide(); OSRM.G.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 getRoute(OSRM.C.NO_DESCRIPTION);
getRoute(OSRM.NO_DESCRIPTION);
else
getRoute(OSRM.FULL_DESCRIPTION);
updateLocation( this.parent.label ); updateLocation( this.parent.label );
}, },
onDragStart: function(e) { onDragStart: function(e) {
// OSRM.debug.log("[event] dragstart event"); OSRM.G.dragging = true;
OSRM.dragging = true;
// hack to store id of dragged marker // store id of dragged marker
for( var i=0; i<my_markers.route.length; i++) for( var i=0; i<OSRM.G.markers.route.length; i++)
if( my_markers.route[i].marker === this ) { if( OSRM.G.markers.route[i].marker === this ) {
OSRM.dragid = i; OSRM.G.dragid = i;
break; break;
} }
my_markers.highlight.hide(); OSRM.G.markers.highlight.hide();
if (my_route.isShown()) { if (OSRM.G.route.isShown())
my_route.showOldRoute(); OSRM.G.route.showOldRoute();
}
updateLocation( this.parent.label );
}, },
onDragEnd: function(e) { onDragEnd: function(e) {
// OSRM.debug.log("[event] dragend event"); OSRM.G.dragging = false;
getRoute(OSRM.FULL_DESCRIPTION); this.parent.setPosition( e.target.getLatLng() );
if (my_route.isShown()) { getRoute(OSRM.C.FULL_DESCRIPTION);
my_route.hideOldRoute(); if (OSRM.G.route.isShown()) {
my_route.hideUnnamedRoute(); // provides better visuals OSRM.G.route.hideOldRoute();
OSRM.G.route.hideUnnamedRoute();
} }
OSRM.dragging = false;
updateLocation( this.parent.label ); if(OSRM.G.route.isShown()==false)
updateAddress(this.parent.label);
}, },
toString: function() { toString: function() {
return "OSRM.RouteMarker: \""+this.label+"\", "+this.position+")"; return "OSRM.RouteMarker: \""+this.label+"\", "+this.position+")";
}, }
}); });
//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']});;
@@ -154,18 +165,18 @@ removeVias: function() {
}, },
setSource: function(position) { setSource: function(position) {
// source node is always first node // source node is always first node
if( this.route[0] && this.route[0].label == OSRM.SOURCE_MARKER_LABEL ) if( this.route[0] && this.route[0].label == OSRM.C.SOURCE_LABEL )
this.route[0].setPosition(position); this.route[0].setPosition(position);
else else
this.route.splice(0,0, new OSRM.RouteMarker("source", {draggable:true,icon:OSRM.icons['marker-source']}, position)); this.route.splice(0,0, new OSRM.RouteMarker(OSRM.C.SOURCE_LABEL, {draggable:true,icon:OSRM.icons['marker-source']}, position));
return 0; return 0;
}, },
setTarget: function(position) { setTarget: function(position) {
// target node is always last node // target node is always last node
if( this.route[this.route.length-1] && this.route[ this.route.length-1 ].label == OSRM.TARGET_MARKER_LABEL ) if( this.route[this.route.length-1] && this.route[ this.route.length-1 ].label == OSRM.C.TARGET_LABEL )
this.route[this.route.length-1].setPosition(position); this.route[this.route.length-1].setPosition(position);
else else
this.route.splice( this.route.length,0, new OSRM.RouteMarker("target", {draggable:true,icon:OSRM.icons['marker-target']}, position)); this.route.splice( this.route.length,0, new OSRM.RouteMarker(OSRM.C.TARGET_LABEL, {draggable:true,icon:OSRM.icons['marker-target']}, position));
return this.route.length-1; return this.route.length-1;
}, },
setVia: function(id, position) { setVia: function(id, position) {
@@ -173,7 +184,7 @@ setVia: function(id, position) {
if( this.route.length<2 || id > this.route.length-2 ) if( this.route.length<2 || id > this.route.length-2 )
return -1; return -1;
this.route.splice(id+1,0, new OSRM.RouteMarker("via", {draggable:true,icon:OSRM.icons['marker-via']}, position)); this.route.splice(id+1,0, new OSRM.RouteMarker(OSRM.C.VIA_LABEL, {draggable:true,icon:OSRM.icons['marker-via']}, position));
return id+1; return id+1;
}, },
removeMarker: function(id) { removeMarker: function(id) {
@@ -181,14 +192,26 @@ removeMarker: function(id) {
return; return;
// also remove vias if source or target are removed // also remove vias if source or target are removed
if( id==0 && this.route[0].label == OSRM.SOURCE_MARKER_LABEL ) if( id==0 && this.route[0].label == OSRM.C.SOURCE_LABEL ) {
this.removeVias(); this.removeVias();
else if( id == this.route.length-1 && this.route[ this.route.length-1 ].label == OSRM.TARGET_MARKER_LABEL ) { document.getElementById('input-source-name').value = "";
} else if( id == this.route.length-1 && this.route[ this.route.length-1 ].label == OSRM.C.TARGET_LABEL ) {
this.removeVias(); this.removeVias();
id = this.route.length-1; id = this.route.length-1;
document.getElementById('input-target-name').value = "";
} }
this.route[id].hide(); this.route[id].hide();
this.route.splice(id, 1); this.route.splice(id, 1);
},
hasSource: function() {
if( OSRM.G.markers.route[0] && OSRM.G.markers.route[0].label == OSRM.C.SOURCE_LABEL )
return true;
return false;
},
hasTarget: function() {
if( OSRM.G.markers.route[OSRM.G.markers.route.length-1] && OSRM.G.markers.route[OSRM.G.markers.route.length-1].label == OSRM.C.TARGET_LABEL )
return true;
return false;
} }
}); });
+38 -14
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();
@@ -14,11 +32,11 @@ OSRM.SimpleRoute = function (label, style) {
}; };
OSRM.extend( OSRM.SimpleRoute,{ OSRM.extend( OSRM.SimpleRoute,{
show: function() { show: function() {
map.addLayer(this.route); OSRM.G.map.addLayer(this.route);
this.shown = true; this.shown = true;
}, },
hide: function() { hide: function() {
map.removeLayer(this.route); OSRM.G.map.removeLayer(this.route);
this.shown = false; this.shown = false;
}, },
isShown: function() { isShown: function() {
@@ -35,20 +53,19 @@ 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 OSRM.G.map.fitBounds( bounds );
map.fitBounds( bounds );
}, },
onClick: function(e) { onClick: function(e) {
if(my_route.isRoute()) if(OSRM.G.route.isRoute())
findViaPosition( e.latlng ); findViaPosition( e.latlng );
}, },
toString: function() { toString: function() {
return "OSRM.Route("+ this.label + ", " + this.route.getLatLngs().length + " points)"; return "OSRM.Route("+ this.label + ", " + this.route.getLatLngs().length + " points)";
}, }
}); });
// 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();
@@ -57,11 +74,11 @@ OSRM.MultiRoute = function (label) {
}; };
OSRM.extend( OSRM.MultiRoute,{ OSRM.extend( OSRM.MultiRoute,{
show: function() { show: function() {
map.addLayer(this.route); OSRM.G.map.addLayer(this.route);
this.shown = true; this.shown = true;
}, },
hide: function() { hide: function() {
map.removeLayer(this.route); OSRM.G.map.removeLayer(this.route);
this.shown = false; this.shown = false;
}, },
isShown: function() { isShown: function() {
@@ -69,7 +86,7 @@ isShown: function() {
}, },
addRoute: function(positions) { addRoute: function(positions) {
var line = new L.DashedPolyline( positions ); var line = new L.DashedPolyline( positions );
line.on('click', function(e) { my_route.fire('click',e); }); line.on('click', function(e) { OSRM.G.route.fire('click',e); });
this.route.addLayer( line ); this.route.addLayer( line );
}, },
clearRoutes: function() { clearRoutes: function() {
@@ -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"} );
@@ -117,6 +135,12 @@ OSRM.extend( OSRM.Route,{
this._current_route.hide(); this._current_route.hide();
this._unnamed_route.hide(); this._unnamed_route.hide();
}, },
hideAll: function() {
this._current_route.hide();
this._unnamed_route.hide();
this._old_route.hide();
this._noroute = OSRM.Route.ROUTE;
},
showUnnamedRoute: function(positions) { showUnnamedRoute: function(positions) {
this._unnamed_route.clearRoutes(); this._unnamed_route.clearRoutes();
@@ -129,7 +153,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();
-12
View File
@@ -1,12 +0,0 @@
// OSRM route class
OSRM.TheRoute = {
};
OSRM.extend( OSRM.TheRoute, {
show: function() {},
hide: function() {},
});
+32 -5
View File
@@ -1,9 +1,34 @@
/*
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 be loaded before all other OSRM classes]
OSRM = {}; var OSRM = {};
OSRM.VERSION = '0.1'; OSRM.VERSION = '0.1.2';
OSRM.DATE = '120319';
OSRM.CONSTANTS = {};
OSRM.DEFAULTS = {};
OSRM.GLOBALS = {};
OSRM.G = OSRM.GLOBALS; // abbreviations
OSRM.C = OSRM.CONSTANTS;
// inheritance helper function (convenience function)
// [convenience function] declare one class to be a subclass of another class
OSRM._inheritFromHelper = function() {}; OSRM._inheritFromHelper = function() {};
OSRM.inheritFrom = function( sub_class, base_class ) { OSRM.inheritFrom = function( sub_class, base_class ) {
OSRM._inheritFromHelper.prototype = base_class.prototype; OSRM._inheritFromHelper.prototype = base_class.prototype;
@@ -12,14 +37,16 @@ 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)
// [convenience function] extend prototypes of a class -> used to add member values and functions
OSRM.extend = function( target_class, properties ) { OSRM.extend = function( target_class, properties ) {
for( property in properties ) { for( property in properties ) {
target_class.prototype[property] = properties[property]; target_class.prototype[property] = properties[property];
} }
}; };
// usage:
// [usage of convenience functions]
// SubClass = function() { // SubClass = function() {
// SubClass.prototype.base.constructor.apply(this, arguments); // SubClass.prototype.base.constructor.apply(this, arguments);
// } // }
+26 -4
View File
@@ -1,14 +1,36 @@
/*
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',
HOST_SHORTENER_URL: 'http://map.project-osrm.org/shorten/', HOST_SHORTENER_URL: 'http://map.project-osrm.org/shorten/',
WEBSITE_URL: 'http://map.project-osrm.org/', HOST_GEOCODER_URL: 'http://nominatim.openstreetmap.org/search',
JSONP_TIMEOUT: 2000, HOST_REVERSE_GEOCODER_URL: 'http://nominatim.openstreetmap.org/reverse',
WEBSITE_URL: document.URL.replace(/#*(\?.*|$)/i,""), // truncates URL before first ?, and removes tailing #
JSONP_TIMEOUT: 5000,
ZOOM_LEVEL: 14, ZOOM_LEVEL: 14,
ONLOAD_LATITUDE: 48.84, ONLOAD_LATITUDE: 48.84,
ONLOAD_LONGITUDE: 10.10, ONLOAD_LONGITUDE: 10.10,
ONLOAD_SOURCE: "", ONLOAD_SOURCE: "",
ONLOAD_TARGET: "", ONLOAD_TARGET: "",
}; HIGHLIGHT_ZOOM_LEVEL: 16,
LANGUAGE: "en",
GEOCODER_BOUNDS: '&bounded=1&viewbox=-27.0,72.0,46.0,36.0'
};
+18 -1
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 = {};
+174 -135
View File
@@ -1,164 +1,203 @@
/*
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.CONSTANTS.SOURCE_LABEL = "source";
OSRM.REVERSE_GEOCODE_POST = 'http://nominatim.openstreetmap.org/reverse?format=json'; OSRM.CONSTANTS.TARGET_LABEL = "target";
OSRM.SOURCE_MARKER_LABEL = "source"; OSRM.CONSTANTS.VIA_LABEL = "via";
OSRM.TARGET_MARKER_LABEL = "target"; OSRM.C.DO_FALLBACK_TO_LAT_LNG = true;
// update locations in input boxes //[normal geocoding]
function updateLocation(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);
} 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);
}
}
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);
}
}
// process input request and call geocoder if needed
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.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? if(query=="")
return;
//geo coordinates given -> directly draw 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]);
// updateReverseGeocoder(marker_id); updateAddress( marker_id );
return; return;
} }
//build request //build request for geocoder
if (marker_id == OSRM.SOURCE_MARKER_LABEL) { var call = OSRM.DEFAULTS.HOST_GEOCODER_URL + "?format=json" + OSRM.DEFAULTS.GEOCODER_BOUNDS + "&q=" + query;
var src= OSRM.GEOCODE_POST + "&q=" + query; OSRM.JSONP.call( call, showGeocoderResults, showGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "geocoder_"+marker_id, marker_id );
OSRM.JSONP.call( src, showGeocoderResults_Source, showGeocoderResults_Timeout, OSRM.JSONP.TIMEOUT, "geocoder_source" );
} else if (marker_id == OSRM.TARGET_MARKER_LABEL) {
var src = OSRM.GEOCODE_POST + "&q=" + query;
OSRM.JSONP.call( src, showGeocoderResults_Target, showGeocoderResults_Timeout, OSRM.JSONP.TIMEOUT, "geocoder_target" );
}
} }
// helper function for clicks on geocoder search results // helper function for clicks on geocoder search results
function onclickGeocoderResult(marker_id, lat, lon) { function onclickGeocoderResult(marker_id, lat, lon) {
var index; var index;
if( marker_id == OSRM.SOURCE_MARKER_LABEL ) if( marker_id == OSRM.C.SOURCE_LABEL )
index = my_markers.setSource( new L.LatLng(lat, lon) ); index = OSRM.G.markers.setSource( new L.LatLng(lat, lon) );
else if( marker_id == OSRM.TARGET_MARKER_LABEL ) else if( marker_id == OSRM.C.TARGET_LABEL )
index = my_markers.setTarget( new L.LatLng(lat, lon) ); index = OSRM.G.markers.setTarget( new L.LatLng(lat, lon) );
else else
index = -1; // search via positions not yet implemented return;
my_markers.route[index].show(); OSRM.G.markers.route[index].show();
my_markers.route[index].centerView(); OSRM.G.markers.route[index].centerView();
getRoute(OSRM.FULL_DESCRIPTION); getRoute(OSRM.C.FULL_DESCRIPTION);
} }
// processing JSONP response of geocoder
// (with wrapper functions for source/target jsonp)
function showGeocoderResults_Source(response) { showGeocoderResults(OSRM.SOURCE_MARKER_LABEL, response); }
function showGeocoderResults_Target(response) { showGeocoderResults(OSRM.TARGET_MARKER_LABEL, response); }
function showGeocoderResults(marker_id, response) {
if(response){
if(response.length == 0) {
showGeocoderResults_Empty();
return;
}
var html = "";
html += '<table class="results-table">';
for(var i=0; i < response.length; i++){
var result = response[i];
//odd or even ? // process geocoder response
var rowstyle='results-odd'; function showGeocoderResults(response, marker_id) {
if(i%2==0) { rowstyle='results-even'; } if(!response){
showGeocoderResults_Empty(marker_id);
html += '<tr class="'+rowstyle+'">'; return;
html += '<td class="result-counter"><span">'+(i+1)+'.</span></td>';
html += '<td class="result-items">';
if(result.display_name){
html += '<div class="result-item" onclick="onclickGeocoderResult(\''+marker_id+'\', '+result.lat+', '+result.lon+');">'+result.display_name+'</div>';
}
html += "</td></tr>";
}
html += '</table>';
document.getElementById('information-box-headline').innerHTML = OSRM.loc("SEARCH_RESULTS")+":";
document.getElementById('information-box').innerHTML = html;
onclickGeocoderResult(marker_id, response[0].lat, response[0].lon);
} }
}
function showGeocoderResults_Empty() { if(response.length == 0) {
showGeocoderResults_Empty(marker_id);
return;
}
// show possible results for input
var html = "";
html += '<table class="results-table">';
for(var i=0; i < response.length; i++){
var result = response[i];
//odd or even ?
var rowstyle='results-odd';
if(i%2==0) { rowstyle='results-even'; }
html += '<tr class="'+rowstyle+'">';
html += '<td class="result-counter"><span">'+(i+1)+'.</span></td>';
html += '<td class="result-items">';
if(result.display_name){
html += '<div class="result-item" onclick="onclickGeocoderResult(\''+marker_id+'\', '+result.lat+', '+result.lon+');">'+result.display_name+'</div>';
}
html += "</td></tr>";
}
html += '</table>';
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("NO_RESULTS_FOUND")+".<p>"; document.getElementById('information-box').innerHTML = html;
onclickGeocoderResult(marker_id, response[0].lat, response[0].lon);
}
function showGeocoderResults_Empty(marker_id) {
document.getElementById('information-box-headline').innerHTML = OSRM.loc("SEARCH_RESULTS")+":";
if(marker_id == OSRM.C.SOURCE_LABEL)
document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("NO_RESULTS_FOUND_SOURCE")+".<p>";
else if(marker_id == OSRM.C.TARGET_LABEL)
document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("NO_RESULTS_FOUND_TARGET")+".<p>";
else
document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("NO_RESULTS_FOUND")+".<p>";
} }
function showGeocoderResults_Timeout() { 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>";
} }
// [reverse geocoding]
//update geo coordinates in input boxes
function updateLocation(marker_id) {
if (marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource()) {
document.getElementById("input-source-name").value = OSRM.G.markers.route[0].getPosition().lat.toFixed(6) + ", " + OSRM.G.markers.route[0].getPosition().lng.toFixed(6);
} else if (marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget()) {
document.getElementById("input-target-name").value = OSRM.G.markers.route[OSRM.G.markers.route.length-1].getPosition().lat.toFixed(6) + ", " + OSRM.G.markers.route[OSRM.G.markers.route.length-1].getPosition().lng.toFixed(6);
}
}
// update address in input boxes
function updateAddress(marker_id, do_fallback_to_lat_lng) {
// build request for reverse geocoder
var lat = null;
var lng = null;
if(marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource()) {
lat = OSRM.G.markers.route[0].getPosition().lat;
lng = OSRM.G.markers.route[0].getPosition().lng;
} else if(marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget() ) {
lat = OSRM.G.markers.route[OSRM.G.markers.route.length-1].getPosition().lat;
lng = OSRM.G.markers.route[OSRM.G.markers.route.length-1].getPosition().lng;
} else
return;
var call = OSRM.DEFAULTS.HOST_REVERSE_GEOCODER_URL + "?format=json" + "&lat=" + lat + "&lon=" + lng;
OSRM.JSONP.call( call, showReverseGeocoderResults, showReverseGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "reverse_geocoder_"+marker_id, {marker_id:marker_id, do_fallback: do_fallback_to_lat_lng} );
}
// processing JSONP response of reverse geocoder
function showReverseGeocoderResults(response, parameters) {
if(!response) {
showReverseGeocoderResults_Timeout(response, parameters);
return;
}
if(response.address == undefined) {
showReverseGeocoderResults_Timeout(response, parameters);
return;
}
// build reverse geocoding address
var used_address_data = 0;
var address = "";
if( response.address.road) {
address += response.address.road;
used_address_data++;
}
if( response.address.city ) {
if( used_address_data > 0 )
address += ", ";
address += response.address.city;
used_address_data++;
} else if( response.address.village ) {
if( used_address_data > 0 )
address += ", ";
address += response.address.village;
used_address_data++;
}
if( used_address_data < 2 && response.address.country ) {
if( used_address_data > 0 )
address += ", ";
address += response.address.country;
used_address_data++;
}
if( used_address_data == 0 ) {
showReverseGeocoderResults_Timeout(response, parameters);
return;
}
// add result to DOM
if(parameters.marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource() )
document.getElementById("input-source-name").value = address;
else if(parameters.marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget() )
document.getElementById("input-target-name").value = address;
}
function showReverseGeocoderResults_Timeout(response, parameters) {
if(!parameters.do_fallback)
return;
updateLocation(parameters.marker_id);
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 429 B

After

Width:  |  Height:  |  Size: 402 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 447 B

After

Width:  |  Height:  |  Size: 484 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 440 B

After

Width:  |  Height:  |  Size: 483 B

Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 488 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 489 B

+55 -5
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;
@@ -89,7 +109,7 @@ html, body, #map {
padding:0px; padding:0px;
} }
.main-toggle .main-toggle-out
{ {
cursor:pointer; cursor:pointer;
position:absolute; position:absolute;
@@ -99,14 +119,32 @@ html, body, #map {
height:16px; height:16px;
background-image:url("images/cancel.png"); background-image:url("images/cancel.png");
} }
.main-toggle:hover .main-toggle-out:hover
{ {
background-image:url("images/cancel_hover.png"); background-image:url("images/cancel_hover.png");
} }
.main-toggle:active .main-toggle-out:active
{ {
background-image:url("images/cancel_active.png"); background-image:url("images/cancel_active.png");
} }
.main-toggle-in
{
cursor:pointer;
position:absolute;
right:5px;
top:5px;
width:16px;
height:16px;
background-image:url("images/restore.png");
}
.main-toggle-in:hover
{
background-image:url("images/restore_hover.png");
}
.main-toggle-in:active
{
background-image:url("images/restore_active.png");
}
.main-options .main-options
{ {
@@ -222,6 +260,16 @@ html, body, #map {
padding-top:1px; padding-top:1px;
padding-bottom: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 .result-item
{ {
cursor:pointer; cursor:pointer;
@@ -241,7 +289,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 +309,7 @@ html, body, #map {
user-select: text; user-select: text;
} }
/* buttons */ /* buttons */
.button .button
{ {
+31 -13
View File
@@ -1,4 +1,22 @@
<!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">
<!--
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.
-->
<html> <html>
@@ -11,13 +29,16 @@
<meta name="description" content="OSRM Website"/> <meta name="description" content="OSRM Website"/>
<meta name="author" content="Dennis Schieferdecker" /> <meta name="author" content="Dennis Schieferdecker" />
<!-- favicon -->
<link rel="shortcut icon" href="images/osrm-favicon.ico" type="image/x-icon" />
<!-- stylesheets --> <!-- stylesheets -->
<link rel="stylesheet" href="leaflet/leaflet.css" type="text/css"/> <link rel="stylesheet" href="leaflet/leaflet.css" type="text/css"/>
<!--[if lte IE 8]><link rel="stylesheet" href="leaflet/leaflet.ie.css" type="text/css"/><![endif]-->
<link rel="stylesheet" href="main.css" type="text/css"/> <link rel="stylesheet" href="main.css" type="text/css"/>
<!-- scripts --> <!-- scripts -->
<script src="leaflet/leaflet-src.js" type="text/javascript"></script> <script src="leaflet/leaflet-src.js" type="text/javascript"></script>
<!--[if lte IE 8]><link rel="stylesheet" href="leaflet/leaflet.ie.css" type="text/css"/><![endif]-->
<script src="L.DashedPolyline.js" type="text/javascript"></script> <script src="L.DashedPolyline.js" type="text/javascript"></script>
<script src="L.MouseMarker.js" type="text/javascript"></script> <script src="L.MouseMarker.js" type="text/javascript"></script>
@@ -51,7 +72,7 @@
<!-- show ui blob --> <!-- show ui blob -->
<div id="blob-wrapper" class="gui-wrapper"> <div id="blob-wrapper" class="gui-wrapper">
<div id="blob-input" class="gui-box"> <div id="blob-input" class="gui-box">
<div class="main-toggle" onclick="OSRM.GUI.toggleMain()"></div> <div class="main-toggle-in" onclick="OSRM.GUI.toggleMain()"></div>
</div> </div>
</div> </div>
@@ -60,23 +81,21 @@
<!-- input box --> <!-- input box -->
<div class="gui-box not-selectable" id="main-input"> <div class="gui-box not-selectable" id="main-input">
<div class="main-toggle" onclick="OSRM.GUI.toggleMain()"></div> <div class="main-toggle-out" onclick="OSRM.GUI.toggleMain()"></div>
<img id="osrm-logo" alt="OSRM Logo" src="images/osrm-logo.png" /> <img id="osrm-logo" alt="OSRM Logo" src="images/osrm-logo.png" />
<!-- source/target input --> <!-- source/target input -->
<table class="full"> <table class="full">
<tr> <tr>
<td id="gui-search-source-label">Start:</td> <td id="gui-search-source-label">Start:</td>
<td><input id="input-source-name" class="input-box" type="text" value="" title="Startposition eingeben" onkeypress="if(event.keyCode==13) {callGeocoder(OSRM.SOURCE_MARKER_LABEL, document.getElementById('input-source-name').value);}" /></td> <td><input id="input-source-name" class="input-box" type="text" maxlength="200" value="" title="Startposition eingeben" onchange="inputChanged(OSRM.C.SOURCE_LABEL);" /></td>
<!-- <td class="right"><a class="button not-selectable" id="gui-here-target" onclick="">i</a></td> --> <td class="right"><a class="button not-selectable" id="gui-search-source" onclick="showMarker('source')">Zeigen</a></td>
<td class="right"><a class="button not-selectable" id="gui-search-source" onclick="callGeocoder(OSRM.SOURCE_MARKER_LABEL, document.getElementById('input-source-name').value);">Suchen</a></td>
</tr> </tr>
<tr> <tr>
<td id="gui-search-target-label">Ende:</td> <td id="gui-search-target-label">Ende:</td>
<td><input id="input-target-name" class="input-box" type="text" value="" title="Zielposition eingeben" onkeypress="if(event.keyCode==13) {callGeocoder(OSRM.TARGET_MARKER_LABEL, document.getElementById('input-target-name').value);}" /></td> <td><input id="input-target-name" class="input-box" type="text" maxlength="200" value="" title="Zielposition eingeben" onchange="inputChanged(OSRM.C.TARGET_LABEL);" /></td>
<!-- <td class="right"><a class="button not-selectable" id="gui-here-target" onclick="">i</a></td> --> <td class="right"><a class="button not-selectable" id="gui-search-target" onclick="showMarker('target');">Zeigen</a></td>
<td class="right"><a class="button not-selectable" id="gui-search-target" onclick="callGeocoder(OSRM.TARGET_MARKER_LABEL, document.getElementById('input-target-name').value);">Suchen</a></td>
</tr> </tr>
</table> </table>
@@ -85,8 +104,7 @@
<table style="width:100%"> <table style="width:100%">
<tr> <tr>
<td> <a class="button not-selectable" id="gui-reset" onclick="resetRouting();">Reset</a></td> <td> <a class="button not-selectable" id="gui-reset" onclick="resetRouting();">Reset</a></td>
<td class="center"> <a class="button not-selectable" id="gui-reverse" onclick="reverseRouting();">Reverse</a></td> <td class="right"> <a class="button not-selectable" id="gui-reverse" onclick="reverseRouting();">Umdrehen</a></td>
<td class="right"> <a class="button not-selectable" id="gui-route" onclick="startRouting();">Route</a></td>
</tr> </tr>
</table> </table>
@@ -94,7 +112,7 @@
<div class="vquad"></div> <div class="vquad"></div>
<div class="main-options not-selectable" id="options-toggle" onclick="OSRM.GUI.toggleOptions()">Options</div> <div class="main-options not-selectable" id="options-toggle" onclick="OSRM.GUI.toggleOptions()">Options</div>
<div class="main-options not-selectable" id="options-box"> <div class="main-options not-selectable" id="options-box">
<input type="checkbox" id="option-highlight-nonames" name="main-options" value="highlight-nonames" onclick="getRoute(OSRM.FULL_DESCRIPTION)" /><span id="gui-option-highlight-nonames-label">Unbenannte Straßen hervorheben</span> <input type="checkbox" id="option-highlight-nonames" name="main-options" value="highlight-nonames" onclick="getRoute(OSRM.C.FULL_DESCRIPTION)" /><span id="gui-option-highlight-nonames-label">Unbenannte Straßen hervorheben</span>
</div> </div>
</div> </div>
@@ -102,7 +120,7 @@
<div class="gui-box not-selectable" id="main-output"> <div class="gui-box not-selectable" id="main-output">
<div id="information-box-headline"></div> <div id="information-box-headline"></div>
<div id="information-box"></div> <div id="information-box"></div>
<div id="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></div> <div id="legal-notice">GUI2 v0.1.1 120316 - OSRM hosting by <a href='http://algo2.iti.kit.edu/'>KIT</a> - Geocoder by <a href='http://www.osm.org/'>OSM</a></div>
</div> </div>
</div> </div>
+141 -89
View File
@@ -1,6 +1,28 @@
var 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 initialization
// [initialization of maps, local strings, image prefetching]
// will hold the Leaflet map object
OSRM.GLOBALS.map = null;
// onload initialization routine
function init() { function init() {
prefetchImages(); prefetchImages();
prefetchIcons(); prefetchIcons();
@@ -20,9 +42,15 @@ function prefetchImages() {
var images = [ 'images/marker-source.png', var images = [ 'images/marker-source.png',
'images/marker-target.png', 'images/marker-target.png',
'images/marker-via.png', 'images/marker-via.png',
'images/marker-highlight.png' 'images/marker-highlight.png',
'images/cancel.png',
'images/cancel_active.png',
'images/cancel_hover.png',
'images/restore.png',
'images/restore_active.png',
'images/restore_hover.png'
]; ];
for(var i=0; i<images.length; i++) { for(var i=0; i<images.length; i++) {
OSRM.images[i] = new Image(); OSRM.images[i] = new Image();
OSRM.images[i].src = images[i]; OSRM.images[i].src = images[i];
@@ -46,7 +74,6 @@ function prefetchIcons() {
// init localization // init localization
function initLocale() { function initLocale() {
document.getElementById("gui-route").innerHTML = OSRM.loc("GUI_ROUTE");
document.getElementById("gui-reset").innerHTML = OSRM.loc("GUI_RESET"); document.getElementById("gui-reset").innerHTML = OSRM.loc("GUI_RESET");
document.getElementById("gui-reverse").innerHTML = OSRM.loc("GUI_REVERSE"); document.getElementById("gui-reverse").innerHTML = OSRM.loc("GUI_REVERSE");
document.getElementById("gui-option-highlight-nonames-label").innerHTML = OSRM.loc("GUI_HIGHLIGHT_UNNAMED_ROADS"); document.getElementById("gui-option-highlight-nonames-label").innerHTML = OSRM.loc("GUI_HIGHLIGHT_UNNAMED_ROADS");
@@ -66,7 +93,7 @@ function initLocale() {
// centering on geolocation // centering on geolocation
function callbak_centerOnGeolocation( position ) { function callbak_centerOnGeolocation( position ) {
map.setView( new L.LatLng( position.coords.latitude, position.coords.longitude-0.02), OSRM.DEFAULTS.ZOOM_LEVEL); OSRM.G.map.setView( new L.LatLng( position.coords.latitude, position.coords.longitude), OSRM.DEFAULTS.ZOOM_LEVEL);
} }
function centerOnGeolocation() { function centerOnGeolocation() {
if (navigator.geolocation) if (navigator.geolocation)
@@ -76,6 +103,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 +125,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);
map = new L.Map('map', { // setup map
OSRM.G.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,
@@ -114,101 +144,123 @@ function initMap() {
var overlayMaps = {}; var overlayMaps = {};
var layersControl = new L.Control.Layers(baseMaps, overlayMaps); var layersControl = new L.Control.Layers(baseMaps, overlayMaps);
map.addControl(layersControl); OSRM.G.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.on('zoomend', function(e) { getRoute(OSRM.FULL_DESCRIPTION); }); OSRM.G.map.setView( new L.LatLng( OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE), OSRM.DEFAULTS.ZOOM_LEVEL);
OSRM.G.map.on('zoomend', function(e) { getRoute(OSRM.C.FULL_DESCRIPTION); });
OSRM.G.map.on('contextmenu', function(e) {});
map.on('click', function(e) { // click on map to set source and target nodes
if( !my_markers.route[0] || my_markers.route[0].label != OSRM.SOURCE_MARKER_LABEL) { OSRM.G.map.on('click', function(e) {
index = my_markers.setSource( e.latlng ); if( !OSRM.G.markers.hasSource() ) {
my_markers.route[index].show(); var index = OSRM.G.markers.setSource( e.latlng );
my_markers.route[index].centerView(false); updateAddress( OSRM.C.SOURCE_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
getRoute(OSRM.FULL_DESCRIPTION); OSRM.G.markers.route[index].show();
updateLocation("source"); OSRM.G.markers.route[index].centerView( OSRM.G.map.getZoom() );
// updateReverseGeocoder("source"); getRoute( OSRM.C.FULL_DESCRIPTION );
} else if( !OSRM.G.markers.hasTarget() ) {
var index = OSRM.G.markers.setTarget( e.latlng );
updateAddress( OSRM.C.TARGET_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
OSRM.G.markers.route[index].show();
OSRM.G.markers.route[index].centerView( OSRM.G.map.getZoom() );
getRoute( OSRM.C.FULL_DESCRIPTION );
} }
else if( !my_markers.route[my_markers.route.length-1] || my_markers.route[ my_markers.route.length-1 ].label != OSRM.TARGET_MARKER_LABEL) {
index = my_markers.setTarget( e.latlng );
my_markers.route[index].show();
my_markers.route[index].centerView(false);
getRoute(OSRM.FULL_DESCRIPTION);
updateLocation("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 != '') {
var positions = []; // reject messages that are clearly too long or too small
if( called_url.length > 1000 || called_url.length == 0)
return;
// storage for parameter values
var positions = [];
var zoom = null;
var center = null;
var destination = null;
var destination_name = null;
// parse input (currently only parses start, dest, via) // parse input
var splitted_url = called_url.split('&'); var splitted_url = called_url.split('&');
for(var i=0; i<splitted_url.length; i++) { for(var i=0; i<splitted_url.length; i++) {
var name_val = splitted_url[i].split('='); var name_val = splitted_url[i].split('=');
if(name_val.length!=2) if(name_val.length!=2)
continue; continue;
if(name_val[0] == 'loc') {
var coordinates = unescape(name_val[1]).split(','); var coordinates = unescape(name_val[1]).split(',');
if(coordinates.length!=2) if(coordinates.length!=2 || !isLatitude(coordinates[0]) || !isLongitude(coordinates[1]) )
continue; return;
positions.push ( new L.LatLng( coordinates[0], coordinates[1]) );
if(name_val[0] == 'loc')
positions.push ( new L.LatLng( coordinates[0], coordinates[1]) );
} }
else if(name_val[0] == 'dest') {
// draw via points var coordinates = unescape(name_val[1]).split(',');
if( positions.length > 0) if(coordinates.length!=2 || !isLatitude(coordinates[0]) || !isLongitude(coordinates[1]) )
my_markers.setSource( positions[0] ); return;
for(var i=1; i<positions.length-1;i++) destination = new L.LatLng( coordinates[0], coordinates[1]);
my_markers.setVia( i-1, positions[i] ); }
if(positions.length > 1) else if(name_val[0] == 'destname') {
my_markers.setTarget( positions[positions.length-1] ); destination_name = decodeURI(name_val[1]).replace(/<\/?[^>]+(>|$)/g ,""); // discard tags
for(var i=0; i<my_markers.route.length;i++) }
my_markers.route[i].show(); else if(name_val[0] == 'z') {
zoom = name_val[1];
// compute route if( zoom<0 || zoom > 18)
getRoute(OSRM.FULL_DESCRIPTION); return;
}
var bounds = new L.LatLngBounds( positions ); else if(name_val[0] == 'center') {
//bounds._southWest.lng-=1.02; // dirty hacks var coordinates = unescape(name_val[1]).split(',');
map.fitBounds( bounds ); if(coordinates.length!=2 || !isLatitude(coordinates[0]) || !isLongitude(coordinates[1]) )
//my_route.centerView(); return;
center = new L.LatLng( coordinates[0], coordinates[1]);
}
} }
}
// case 1: destination given
if( destination != undefined ) {
var index = OSRM.G.markers.setTarget( e.latlng );
if( destination_name == null )
updateAddress( OSRM.C.TARGET_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
else
document.getElementById("input-target-name").value = destination_name;
OSRM.G.markers.route[index].show();
OSRM.G.markers.route[index].centerView();
return;
}
// case 2: locations given
if( positions != []) {
// draw via points
if( positions.length > 0) {
OSRM.G.markers.setSource( positions[0] );
updateAddress( OSRM.C.SOURCE_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
}
if(positions.length > 1) {
OSRM.G.markers.setTarget( positions[positions.length-1] );
updateAddress( OSRM.C.TARGET_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
}
for(var i=1; i<positions.length-1;i++)
OSRM.G.markers.setVia( i-1, positions[i] );
for(var i=0; i<OSRM.G.markers.route.length;i++)
OSRM.G.markers.route[i].show();
// center on route (support for old links) / move to given view (new behaviour)
if(zoom == null || center == null) {
var bounds = new L.LatLngBounds( positions );
OSRM.G.map.fitBounds( bounds );
} else {
OSRM.G.map.setView(center, zoom);
}
// compute route
getRoute(OSRM.C.FULL_DESCRIPTION);
}
}
+249 -182
View File
@@ -1,46 +1,47 @@
var my_route = undefined; /*
var my_markers = undefined; 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.
OSRM.NO_DESCRIPTION = 0; This program is distributed in the hope that it will be useful,
OSRM.FULL_DESCRIPTION = 1; but WITHOUT ANY WARRANTY; without even the implied warranty of
OSRM.dragging = false; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
OSRM.pending = false; GNU General Public License for more details.
OSRM.pendingTimer = undefined;
// init data 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
OSRM.GLOBALS.route = null;
OSRM.GLOBALS.markers = null;
OSRM.CONSTANTS.NO_DESCRIPTION = 0;
OSRM.CONSTANTS.FULL_DESCRIPTION = 1;
OSRM.G.dragging = null;
OSRM.GLOBALS.dragid = null;
OSRM.GLOBALS.pending = false;
OSRM.GLOBALS.pendingTimer = null;
// init routing data structures
function initRouting() { function initRouting() {
my_route = new OSRM.Route(); OSRM.G.route = new OSRM.Route();
my_markers = new OSRM.Markers(); OSRM.G.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();
@@ -48,7 +49,7 @@ function timeoutRouteSimple() {
} }
function timeoutRoute() { function timeoutRoute() {
showNoRouteGeometry(); showNoRouteGeometry();
my_route.hideUnnamedRoute(); OSRM.G.route.hideUnnamedRoute();
showNoRouteDescription(); showNoRouteDescription();
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>";
} }
@@ -56,7 +57,7 @@ function showRouteSimple(response) {
if(!response) if(!response)
return; return;
if (OSRM.JSONP.fences.route) // prevent simple routing when real routing is done! if( !OSRM.G.dragging ) // prevent simple routing when no longer dragging
return; return;
if( response.status == 207) { if( response.status == 207) {
@@ -68,10 +69,11 @@ function showRouteSimple(response) {
showRouteDescriptionSimple(response); showRouteDescriptionSimple(response);
} }
updateHints(response); updateHints(response);
// if(OSRM.pending) { // // TODO: hack to process final drag event, if it was fenced, but we are still dragging (alternative approach)
// clearTimeout(OSRM.pendingTimer); // if(OSRM.G.pending) {
// OSRM.pendingTimer = setTimeout(timeoutDrag,100); // dirty dirty! // clearTimeout(OSRM.G.pendingTimer);
// OSRM.G.pendingTimer = setTimeout(timeoutDrag,100);
// } // }
} }
function showRoute(response) { function showRoute(response) {
@@ -80,7 +82,7 @@ function showRoute(response) {
if(response.status == 207) { if(response.status == 207) {
showNoRouteGeometry(); showNoRouteGeometry();
my_route.hideUnnamedRoute(); OSRM.G.route.hideUnnamedRoute();
showNoRouteDescription(); showNoRouteDescription();
document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("NO_ROUTE_FOUND")+".<p>"; document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("NO_ROUTE_FOUND")+".<p>";
} else { } else {
@@ -92,15 +94,17 @@ 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<OSRM.G.markers.route.length;i++)
positions.push( my_markers.route[i].getPosition() ); positions.push( OSRM.G.markers.route[i].getPosition() );
my_route.showRoute(positions, OSRM.Route.NOROUTE); OSRM.G.route.showRoute(positions, OSRM.Route.NOROUTE);
} }
function showRouteGeometry(response) { function showRouteGeometry(response) {
via_points = response.via_points.slice(0); OSRM.G.via_points = response.via_points.slice(0);
var geometry = decodeRouteGeometry(response.route_geometry, 5); var geometry = decodeRouteGeometry(response.route_geometry, 5);
@@ -108,37 +112,40 @@ function showRouteGeometry(response) {
for( var i=0; i < geometry.length; i++) { for( var i=0; i < geometry.length; i++) {
points.push( new L.LatLng(geometry[i][0], geometry[i][1]) ); points.push( new L.LatLng(geometry[i][0], geometry[i][1]) );
} }
my_route.showRoute(points, OSRM.Route.ROUTE); OSRM.G.route.showRoute(points, OSRM.Route.ROUTE);
} }
function onClickRouteDescription(geometry_index) {
var positions = my_route.getPositions();
my_markers.highlight.setPosition( positions[geometry_index] ); // route description display (and helper functions)
my_markers.highlight.show(); function onClickRouteDescription(geometry_index) {
my_markers.highlight.centerView(); var positions = OSRM.G.route.getPositions();
OSRM.G.markers.highlight.setPosition( positions[geometry_index] );
OSRM.G.markers.highlight.show();
OSRM.G.markers.highlight.centerView(OSRM.DEFAULTS.HIGHLIGHT_ZOOM_LEVEL);
} }
function onClickCreateShortcut(src){ function onClickCreateShortcut(src){
OSRM.JSONP.call(OSRM.DEFAULTS.HOST_SHORTENER_URL+src+'&jsonp=showRouteLink', showRouteLink, showRouteLink_TimeOut, 2000, 'shortener'); src += '&z='+ OSRM.G.map.getZoom() + '&center=' + OSRM.G.map.getCenter().lat + ',' + OSRM.G.map.getCenter().lng;
OSRM.JSONP.call(OSRM.DEFAULTS.HOST_SHORTENER_URL+src, showRouteLink, showRouteLink_TimeOut, 2000, 'shortener');
document.getElementById('route-prelink').innerHTML = '['+OSRM.loc("GENERATE_LINK_TO_ROUTE")+']';
} }
function showRouteLink(response){ function showRouteLink(response){
document.getElementById('route-link').innerHTML = '[<a id="gpx-link" href="' +response.ShortURL+ '">'+OSRM.loc("LINK_TO_ROUTE")+'</a>]'; document.getElementById('route-prelink').innerHTML = '[<a id="gpx-link" class = "text-selectable" href="' +response.ShortURL+ '">'+response.ShortURL+'</a>]';
} }
function showRouteLink_TimeOut(){ function showRouteLink_TimeOut(){
document.getElementById('route-link').innerHTML = '['+OSRM.loc("LINK_TO_ROUTE_TIMEOUT")+']'; document.getElementById('route-prelink').innerHTML = '['+OSRM.loc("LINK_TO_ROUTE_TIMEOUT")+']';
} }
function showRouteDescription(response) { function showRouteDescription(response) {
// compute query string // compute query string
var query_string = '?z='+ map.getZoom(); var query_string = '?rebuild=1';
for(var i=0; i<my_markers.route.length; i++) for(var i=0; i<OSRM.G.markers.route.length; i++)
query_string += '&loc=' + my_markers.route[i].getLat() + ',' + my_markers.route[i].getLng(); query_string += '&loc=' + OSRM.G.markers.route[i].getLat() + ',' + OSRM.G.markers.route[i].getLng();
// create link to the route // create link to the route
var route_link ='<span class="route-summary" id="route-link">[<a id="gpx-link" onclick="onClickCreateShortcut(\'' + OSRM.DEFAULTS.WEBSITE_URL + query_string + '\')">'+OSRM.loc("GET_LINK")+'</a>]</span>'; var route_link ='<span class="route-summary" id="route-prelink">[<a id="gpx-link" onclick="onClickCreateShortcut(\'' + OSRM.DEFAULTS.WEBSITE_URL + query_string + '\')">'+OSRM.loc("GET_LINK_TO_ROUTE")+'</a>]</span>';
//var route_link ='<span class="route-summary" id="route-link">[<a id="gpx-link" href="#" onclick="onClickCreateShortcut(\'' + document.URL + query_string + '\')">'+OSRM.loc("GET_LINK")+'</a>]</span>';
// create GPX link // create GPX link
var gpx_link = '<span class="route-summary">[<a id="gpx-link" onClick="javascript: document.location.href=\'' + OSRM.DEFAULTS.HOST_ROUTING_URL + query_string + '&output=gpx\';">'+OSRM.loc("GPX_FILE")+'</a>]</span>'; var gpx_link = '<span class="route-summary">[<a id="gpx-link" onClick="document.location.href=\'' + OSRM.DEFAULTS.HOST_ROUTING_URL + query_string + '&output=gpx\';">'+OSRM.loc("GPX_FILE")+'</a>]</span>';
// create route description // create route description
var route_desc = ""; var route_desc = "";
@@ -155,31 +162,38 @@ 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 '; route_desc += response.route_instructions[i][0];
if( response.route_instructions[i][2] > 0 ) if( i == 0 )
route_desc += response.route_instructions[i][1] + ' for ' route_desc += ' ' + OSRM.loc( response.route_instructions[i][6] );
+ getDistanceWithUnit(response.route_instructions[i][2]) if( response.route_instructions[i][1] != "" ) {
+ '</span>'; route_desc += ' on ';
route_desc += '<b>' + response.route_instructions[i][1] + '</b>';
}
//route_desc += ' for ';
route_desc += '</span>';
route_desc += "</td>";
route_desc += '<td class="result-distance">';
if( i != response.route_instructions.length-1 )
route_desc += '<b>'+getDistanceWithUnit(response.route_instructions[i][2])+'</b>';
route_desc += "</td>"; route_desc += "</td>";
route_desc += "</tr>"; route_desc += "</tr>";
} }
route_desc += '</table>'; route_desc += '</table>';
headline = ""; headline = "";
headline += OSRM.loc("ROUTE_DESCRIPTION")+":<br>"; headline += OSRM.loc("ROUTE_DESCRIPTION")+":<br>";
headline += '<div style="float:left;width:70%">'; headline += '<div style="float:left;width:40%">';
headline += "<span class='route-summary'>" headline += "<span class='route-summary'>"
+ OSRM.loc("DISTANCE")+": " + getDistanceWithUnit(response.route_summary.total_distance) + OSRM.loc("DISTANCE")+": " + getDistanceWithUnit(response.route_summary.total_distance)
+ " - " + "<br>"
+ OSRM.loc("DURATION")+": " + secondsToTime(response.route_summary.total_time) + OSRM.loc("DURATION")+": " + secondsToTime(response.route_summary.total_time)
+ "</span>"; + "</span>";
headline += '</div>'; headline += '</div>';
headline += '<div style="float:left;text-align:right;width:30%;">'+route_link+'<br>'+gpx_link+'</div>'; headline += '<div style="float:left;text-align:right;width:60%;">'+route_link+'<br>'+gpx_link+'</div>';
var output = ""; var output = "";
output += route_desc; output += route_desc;
@@ -191,7 +205,7 @@ function showRouteDescriptionSimple(response) {
headline = OSRM.loc("ROUTE_DESCRIPTION")+":<br>"; headline = OSRM.loc("ROUTE_DESCRIPTION")+":<br>";
headline += "<span class='route-summary'>" headline += "<span class='route-summary'>"
+ OSRM.loc("DISTANCE")+": " + getDistanceWithUnit(response.route_summary.total_distance) + OSRM.loc("DISTANCE")+": " + getDistanceWithUnit(response.route_summary.total_distance)
+ " - " + "<br>"
+ OSRM.loc("DURATION")+": " + secondsToTime(response.route_summary.total_time) + OSRM.loc("DURATION")+": " + secondsToTime(response.route_summary.total_time)
+ "</span>"; + "</span>";
headline += '<br><br>'; headline += '<br><br>';
@@ -203,7 +217,7 @@ function showNoRouteDescription() {
headline = OSRM.loc("ROUTE_DESCRIPTION")+":<br>"; headline = OSRM.loc("ROUTE_DESCRIPTION")+":<br>";
headline += "<span class='route-summary'>" headline += "<span class='route-summary'>"
+ OSRM.loc("DISTANCE")+": N/A" + OSRM.loc("DISTANCE")+": N/A"
+ " - " + "<br>"
+ OSRM.loc("DURATION")+": N/A" + OSRM.loc("DURATION")+": N/A"
+ "</span>"; + "</span>";
headline += '<br><br>'; headline += '<br><br>';
@@ -212,10 +226,12 @@ 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) {
my_route.hideUnnamedRoute(); OSRM.G.route.hideUnnamedRoute();
return; return;
} }
@@ -249,33 +265,34 @@ function showRouteNonames(response) {
} }
// display unnamed streets // display unnamed streets
my_route.showUnnamedRoute(all_positions); OSRM.G.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( OSRM.G.markers.route.length < 2 ) {
my_route.hideRoute(); OSRM.G.route.hideRoute();
//my_markers.removeVias(); // TODO: do I need this?
//my_markers.highlight.hide();
return; return;
} }
// prepare JSONP call // prepare JSONP call
var type = undefined; var type = null;
var callback = undefined; var callback = null;
var timeout = undefined; var timeout = null;
var source = OSRM.DEFAULTS.HOST_ROUTING_URL; var source = OSRM.DEFAULTS.HOST_ROUTING_URL;
source += '?z=' + map.getZoom() + '&output=json' + '&geomformat=cmp'; source += '?z=' + OSRM.G.map.getZoom() + '&output=json' + '&geomformat=cmp';
if(my_markers.checksum) if(OSRM.G.markers.checksum)
source += '&checksum=' + my_markers.checksum; source += '&checksum=' + OSRM.G.markers.checksum;
for(var i=0; i<my_markers.route.length; i++) { for(var i=0; i<OSRM.G.markers.route.length; i++) {
source += '&loc=' + my_markers.route[i].getLat() + ',' + my_markers.route[i].getLng(); source += '&loc=' + OSRM.G.markers.route[i].getLat() + ',' + OSRM.G.markers.route[i].getLng();
if( my_markers.route[i].hint) if( OSRM.G.markers.route[i].hint)
source += '&hint=' + my_markers.route[i].hint; source += '&hint=' + OSRM.G.markers.route[i].hint;
} }
// decide whether it is a dragging call or a normal one // decide whether it is a dragging call or a normal one
@@ -292,106 +309,82 @@ 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.G.pendingTimer);
OSRM.pendingTimer = setTimeout(timeoutDrag,OSRM.JSONP.TIMEOUT); OSRM.G.pendingTimer = setTimeout(timeoutDrag,OSRM.DEFAULTS.JSONP_TIMEOUT);
} }
else { else {
clearTimeout(OSRM.pendingTimer); clearTimeout(OSRM.G.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.G.pending = true;
// } else { // } else {
// clearTimeout(OSRM.pendingTimer); // clearTimeout(OSRM.G.pendingTimer);
// OSRM.pending = false; // OSRM.G.pending = false;
// } // }
} }
function timeoutDrag() { function timeoutDrag() {
my_markers.route[OSRM.dragid].hint = undefined; OSRM.G.markers.route[OSRM.G.dragid].hint = null;
getRoute(OSRM.NO_DESCRIPTION); getRoute(OSRM.C.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; OSRM.G.markers.checksum = response.hint_data.checksum;
for(var i=0; i<hint_locations.length; i++) for(var i=0; i<hint_locations.length; i++)
my_markers.route[i].hint = hint_locations[i]; OSRM.G.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 = OSRM.G.route.getPositions();
my_markers.route[0].setPosition( positions[0] ); OSRM.G.markers.route[0].setPosition( positions[0] );
my_markers.route[my_markers.route.length-1].setPosition( positions[positions.length-1] ); OSRM.G.markers.route[OSRM.G.markers.route.length-1].setPosition( positions[positions.length-1] );
for(var i=0; i<via_points.length; i++) for(var i=0; i<OSRM.G.via_points.length; i++)
my_markers.route[i+1].setPosition( new L.LatLng(via_points[i][0], via_points[i][1]) ); OSRM.G.markers.route[i+1].setPosition( new L.LatLng(OSRM.G.via_points[i][0], OSRM.G.via_points[i][1]) );
updateLocation( "source" ); updateAddress(OSRM.C.SOURCE_LABEL);
updateLocation( "target" ); updateAddress(OSRM.C.TARGET_LABEL);
} }
function positionsToInput() { // map driving instructions to icons
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",
@@ -403,21 +396,95 @@ function getDirectionIcon(name) {
"Turn slight right":"slight-right.png", "Turn slight right":"slight-right.png",
"Turn sharp left":"sharp-left.png", "Turn sharp left":"sharp-left.png",
"Turn sharp right":"sharp-right.png", "Turn sharp right":"sharp-right.png",
"Enter round-about and leave at first exit":"round-about.png", "Enter roundabout and leave at first exit":"round-about.png",
"Enter round-about and leave at second exit":"round-about.png", "Enter roundabout and leave at second exit":"round-about.png",
"Enter round-about and leave at third exit":"round-about.png", "Enter roundabout and leave at third exit":"round-about.png",
"Enter round-about and leave at forth exit":"round-about.png", "Enter roundabout and leave at fourth exit":"round-about.png",
"Enter round-about and leave at fifth exit":"round-about.png", "Enter roundabout and leave at fifth exit":"round-about.png",
"Enter round-about and leave at sixth exit":"round-about.png", "Enter roundabout and leave at sixth exit":"round-about.png",
"Enter round-about and leave at seventh exit":"round-about.png", "Enter roundabout and leave at seventh exit":"round-about.png",
"Enter round-about and leave at eighth exit":"round-about.png", "Enter roundabout and leave at eighth exit":"round-about.png",
"Enter round-about and leave at nineth exit":"round-about.png", "Enter roundabout and leave at nineth exit":"round-about.png",
"Enter round-about and leave at tenth exit":"round-about.png", "Enter roundabout and leave at tenth exit":"round-about.png",
"Enter round-about and leave at one of the too many exit":"round-about.png", "Enter roundabout and leave at one of the too many exit":"round-about.png",
"You have reached your destination":"target.png"
}; };
if( directions[name] ) if( directions[name] )
return directions[name]; return directions[name];
else else
return "default.png"; return "default.png";
} }
// -- gui functions --
// click: button "reset"
function resetRouting() {
document.getElementById('input-source-name').value = "";
document.getElementById('input-target-name').value = "";
OSRM.G.route.hideAll();
OSRM.G.markers.removeAll();
OSRM.G.markers.highlight.hide();
document.getElementById('information-box').innerHTML = "";
document.getElementById('information-box-headline').innerHTML = "";
OSRM.JSONP.reset();
}
// 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
OSRM.G.markers.route.reverse();
if(OSRM.G.markers.route.length == 1) {
if(OSRM.G.markers.route[0].label == OSRM.C.TARGET_LABEL) {
OSRM.G.markers.route[0].label = OSRM.C.SOURCE_LABEL;
OSRM.G.markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') );
} else if(OSRM.G.markers.route[0].label == OSRM.C.SOURCE_LABEL) {
OSRM.G.markers.route[0].label = OSRM.C.TARGET_LABEL;
OSRM.G.markers.route[0].marker.setIcon( new L.Icon('images/marker-target.png') );
}
} else if(OSRM.G.markers.route.length > 1){
OSRM.G.markers.route[0].label = OSRM.C.SOURCE_LABEL;
OSRM.G.markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') );
OSRM.G.markers.route[OSRM.G.markers.route.length-1].label = OSRM.C.TARGET_LABEL;
OSRM.G.markers.route[OSRM.G.markers.route.length-1].marker.setIcon( new L.Icon('images/marker-target.png') );
}
// recompute route
if( OSRM.G.route.isShown() ) {
getRoute(OSRM.C.FULL_DESCRIPTION);
OSRM.G.markers.highlight.hide();
} else {
document.getElementById('information-box').innerHTML = "";
document.getElementById('information-box-headline').innerHTML = "";
}
}
// click: button "show"
function showMarker(marker_id) {
if( OSRM.JSONP.fences["geocoder_source"] || OSRM.JSONP.fences["geocoder_target"] )
return;
if( marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource() )
OSRM.G.markers.route[0].centerView();
else if( marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget() )
OSRM.G.markers.route[OSRM.G.markers.route.length-1].centerView();
}
// changed: any inputbox (is called when return is pressed [after] or focus is lost [before])
function inputChanged(marker_id) {
if( marker_id == OSRM.C.SOURCE_LABEL)
callGeocoder(OSRM.C.SOURCE_LABEL, document.getElementById('input-source-name').value);
else if( marker_id == OSRM.C.TARGET_LABEL)
callGeocoder(OSRM.C.TARGET_LABEL, document.getElementById('input-target-name').value);
}
-27
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>
+41 -5
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+'( |$)');
@@ -19,18 +36,37 @@ function secondsToTime(seconds){
hours = parseInt(minutes/60); hours = parseInt(minutes/60);
minutes = minutes%60; minutes = minutes%60;
if(hours==0){ if(hours==0){
return minutes+' min'; return minutes + '&nbsp;' + 'min';
} }
else{ else{
return hours+' h '+minutes+' min'; return hours + '&nbsp;' + 'h' + '&nbsp;' + minutes + '&nbsp;' + 'min';
} }
} }
// human readable distance // human readable distance
function getDistanceWithUnit(distance){ function getDistanceWithUnit(distance){
distance = parseInt(distance); distance = parseInt(distance);
if(distance >= 1000){ return (parseInt(distance/1000))+' km'; }
else{ return distance+' m'; } if(distance >= 100000){ return (parseInt(distance/1000))+'&nbsp;' + 'km'; }
else if(distance >= 10000){ return (parseInt(distance/1000).toFixed(1))+'&nbsp;' + 'km'; }
else if(distance >= 1000){ return (parseFloat(distance/1000).toFixed(2))+'&nbsp;' + 'km'; }
else{ return distance+'&nbsp;' + 'm'; }
}
//------------------------------------------------------
// verify angles
function isLatitude(value) {
if( value >=-90 && value <=90)
return true;
else
return false;
}
function isLongitude(value) {
if( value >=-180 && value <=180)
return true;
else
return false;
} }
// ------------------------------------------------------ // ------------------------------------------------------
+29 -8
View File
@@ -1,10 +1,30 @@
var via_points; /*
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
OSRM.GLOBALS.via_points = null;
// 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;
var positions = my_route.getPositions(); var positions = OSRM.G.route.getPositions();
for(var i=0; i<positions.length-1; i++) { for(var i=0; i<positions.length-1; i++) {
var dist = dotLineLength( new_via.lng, new_via.lat, positions[i].lng, positions[i].lat, positions[i+1].lng, positions[i+1].lat, true); var dist = dotLineLength( new_via.lng, new_via.lat, positions[i].lng, positions[i].lat, positions[i+1].lng, positions[i+1].lat, true);
if( dist < min_dist) { if( dist < min_dist) {
@@ -17,15 +37,16 @@ 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 );
// find correct index to insert new via node // find correct index to insert new via node
var new_via_index = via_points.length; var new_via_index = OSRM.G.via_points.length;
var via_index = Array(); var via_index = Array();
for(var i=0; i<via_points.length; i++) { for(var i=0; i<OSRM.G.via_points.length; i++) {
via_index[i] = findNearestRouteSegment( new L.LatLng(via_points[i][0], via_points[i][1]) ); via_index[i] = findNearestRouteSegment( new L.LatLng(OSRM.G.via_points[i][0], OSRM.G.via_points[i][1]) );
if(via_index[i] > nearest_index) { if(via_index[i] > nearest_index) {
new_via_index = i; new_via_index = i;
break; break;
@@ -33,10 +54,10 @@ function findViaPosition( new_via_position ) {
} }
// add via node // add via node
var index = my_markers.setVia(new_via_index, new_via_position); var index = OSRM.G.markers.setVia(new_via_index, new_via_position);
my_markers.route[index].show(); OSRM.G.markers.route[index].show();
getRoute(OSRM.FULL_DESCRIPTION); getRoute(OSRM.C.FULL_DESCRIPTION);
return new_via_index; return new_via_index;
} }