Compare commits

..

20 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
12 changed files with 460 additions and 360 deletions
+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);
}
});
+16 -12
View File
@@ -34,7 +34,7 @@ OSRM.JSONP = {
// init JSONP call // init JSONP call
call: function(source, callback_function, timeout_function, timeout, id) { 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;
@@ -42,25 +42,29 @@ OSRM.JSONP = {
// 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);
OSRM.JSONP.callbacks[id] = OSRM.JSONP.late; // clean functions } finally {
OSRM.JSONP.timeouts[id] = OSRM.JSONP.late; OSRM.JSONP.callbacks[id] = OSRM.JSONP.late; // clean functions
OSRM.JSONP.fences[id] = undefined; // clean fence OSRM.JSONP.timeouts[id] = OSRM.JSONP.empty;
OSRM.JSONP.fences[id] = undefined; // clean fence
}
// OSRM.debug.log("[jsonp] timout handling: "+id); // OSRM.debug.log("[jsonp] timout handling: "+id);
}; };
// 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;
callback_function(response); // actual wrapped callback try {
callback_function(response, parameters); // actual wrapped callback
OSRM.JSONP.callbacks[id] = OSRM.JSONP.late; // clean functions } finally {
OSRM.JSONP.timeouts[id] = OSRM.JSONP.late; OSRM.JSONP.callbacks[id] = OSRM.JSONP.empty; // clean functions
OSRM.JSONP.fences[id] = undefined; // clean fence OSRM.JSONP.timeouts[id] = OSRM.JSONP.late;
OSRM.JSONP.fences[id] = undefined; // clean fence
}
// OSRM.debug.log("[jsonp] response handling: "+id); // OSRM.debug.log("[jsonp] response handling: "+id);
}; };
+6 -4
View File
@@ -48,7 +48,7 @@ OSRM.Localization["de"] = {
"GUI_HIGHLIGHT_UNNAMED_ROADS": "Unbenannte Straßen hervorheben", "GUI_HIGHLIGHT_UNNAMED_ROADS": "Unbenannte Straßen hervorheben",
"GUI_START_TOOLTIP": "Startposition eingeben", "GUI_START_TOOLTIP": "Startposition eingeben",
"GUI_END_TOOLTIP": "Zielposition eingeben", "GUI_END_TOOLTIP": "Zielposition eingeben",
"GUI_LEGAL_NOTICE": "GUI2 v0.1.1 120316 - 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": "Zeitüberschreitung", "TIMED_OUT": "Zeitüberschreitung",
@@ -57,7 +57,8 @@ OSRM.Localization["de"] = {
"NO_RESULTS_FOUND_TARGET": "Keine Ergebnisse gefunden für Ziel", "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",
"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",
@@ -88,7 +89,7 @@ OSRM.Localization["en"] = {
"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.1 120316 - 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",
@@ -97,7 +98,8 @@ OSRM.Localization["en"] = {
"NO_RESULTS_FOUND_TARGET": "No results found for end", "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",
"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",
+42 -56
View File
@@ -26,25 +26,23 @@ OSRM.Marker = function( label, style, position ) {
this.marker = new L.MouseMarker( this.position, style ); this.marker = new L.MouseMarker( this.position, style );
this.marker.parent = this; this.marker.parent = this;
this.dirty_move = true;
this.dirty_type = true;
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;
@@ -58,12 +56,10 @@ 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+")";
@@ -102,58 +98,46 @@ 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) {
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 ) {
my_markers.removeMarker( i ); OSRM.G.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) {
this.parent.dirty_move = true;
this.parent.setPosition( e.target.getLatLng() ); this.parent.setPosition( e.target.getLatLng() );
if(OSRM.dragging == true) // TODO: hack that deals 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.dragging = true; OSRM.G.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) {
getRoute(OSRM.FULL_DESCRIPTION); OSRM.G.dragging = false;
if (my_route.isShown()) { this.parent.setPosition( e.target.getLatLng() );
my_route.hideOldRoute(); getRoute(OSRM.C.FULL_DESCRIPTION);
my_route.hideUnnamedRoute(); if (OSRM.G.route.isShown()) {
OSRM.G.route.hideOldRoute();
OSRM.G.route.hideUnnamedRoute();
} }
OSRM.dragging = false;
updateLocation( this.parent.label ); if(OSRM.G.route.isShown()==false)
if(my_route.isShown()==false) { updateAddress(this.parent.label);
if(this.parent.label == "source")
updateReverseGeocoder("source");
else if(this.parent.label == "target")
updateReverseGeocoder("target");
}
}, },
toString: function() { toString: function() {
return "OSRM.RouteMarker: \""+this.label+"\", "+this.position+")"; return "OSRM.RouteMarker: \""+this.label+"\", "+this.position+")";
@@ -181,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) {
@@ -200,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) {
@@ -208,24 +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() { hasSource: function() {
if( my_markers.route[0] && my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL ) if( OSRM.G.markers.route[0] && OSRM.G.markers.route[0].label == OSRM.C.SOURCE_LABEL )
return true; return true;
return false; return false;
}, },
hasTarget: function() { hasTarget: function() {
if( my_markers.route[my_markers.route.length-1] && my_markers.route[my_markers.route.length-1].label == OSRM.TARGET_MARKER_LABEL ) 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 true;
return false; return false;
} }
}); });
+7 -7
View File
@@ -32,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() {
@@ -53,10 +53,10 @@ setStyle: function(style) {
}, },
centerView: function() { centerView: function() {
var bounds = new L.LatLngBounds( this.getPositions() ); var bounds = new L.LatLngBounds( this.getPositions() );
map.fitBounds( bounds ); OSRM.G.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() {
@@ -74,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() {
@@ -86,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() {
+12 -6
View File
@@ -16,13 +16,19 @@ or see http://www.gnu.org/licenses/agpl.txt.
*/ */
// OSRM base class // OSRM base class
// [has to loaded before all other OSRM classes] // [has to be loaded before all other OSRM classes]
OSRM = {}; var OSRM = {};
OSRM.VERSION = '0.1.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;
@@ -32,7 +38,7 @@ OSRM.inheritFrom = function( sub_class, base_class ) {
}; };
// 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];
@@ -40,7 +46,7 @@ OSRM.extend = function( target_class, properties ) {
}; };
// usage: // [usage of convenience functions]
// SubClass = function() { // SubClass = function() {
// SubClass.prototype.base.constructor.apply(this, arguments); // SubClass.prototype.base.constructor.apply(this, arguments);
// } // }
+6 -2
View File
@@ -21,12 +21,16 @@ or see http://www.gnu.org/licenses/agpl.txt.
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: document.URL.replace(/#*\?.*/i,""), HOST_GEOCODER_URL: 'http://nominatim.openstreetmap.org/search',
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, 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: "",
LANGUAGE: "en" HIGHLIGHT_ZOOM_LEVEL: 16,
LANGUAGE: "en",
GEOCODER_BOUNDS: '&bounded=1&viewbox=-27.0,72.0,46.0,36.0'
}; };
+136 -138
View File
@@ -20,114 +20,92 @@ or see http://www.gnu.org/licenses/agpl.txt.
// [TODO: better separation of GUI and geocoding routines, reverse geocoding] // [TODO: better separation of GUI and geocoding routines, reverse geocoding]
// some constants // some constants
OSRM.GEOCODE_POST = 'http://nominatim.openstreetmap.org/search?format=json&bounded=1&viewbox=-27.0,72.0,46.0,36.0'; OSRM.CONSTANTS.SOURCE_LABEL = "source";
OSRM.SOURCE_MARKER_LABEL = "source"; OSRM.CONSTANTS.TARGET_LABEL = "target";
OSRM.TARGET_MARKER_LABEL = "target"; OSRM.CONSTANTS.VIA_LABEL = "via";
OSRM.C.DO_FALLBACK_TO_LAT_LNG = true;
// update geo coordinates in input boxes //[normal geocoding]
function updateLocation(marker_id) {
if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.route[0].dirty_move == true ) {
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 && my_markers.route[my_markers.route.length-1].dirty_move == true) {
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);
}
}
// process input request and call geocoder if needed // process input request and call geocoder if needed
function callGeocoder(marker_id, query) { function callGeocoder(marker_id, query) {
if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.route[0] && my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL && my_markers.route[0].dirty_move == false && my_markers.route[0].dirty_type == false)
return;
if (marker_id == OSRM.TARGET_MARKER_LABEL && my_markers.route[my_markers.route.length-1] && my_markers.route[my_markers.route.length-1].label == OSRM.TARGET_MARKER_LABEL && my_markers.route[my_markers.route.length-1].dirty_move == false && my_markers.route[my_markers.route.length-1].dirty_type == false)
return;
if(query=="") if(query=="")
return; return;
//geo coordinates given -> go directly to drawing results //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], true); onclickGeocoderResult(marker_id, coord[0], coord[1]);
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.DEFAULTS.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.DEFAULTS.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, do_reverse_geocode, zoom ) { 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; // via nodes not yet implemented return;
if( do_reverse_geocode == true ) OSRM.G.markers.route[index].show();
updateReverseGeocoder(marker_id); OSRM.G.markers.route[index].centerView();
if( zoom == undefined ) getRoute(OSRM.C.FULL_DESCRIPTION);
zoom = true;
my_markers.route[index].show();
if( !my_markers.route[index].dirty_move || my_markers.route[index].dirty_type )
my_markers.route[index].centerView(zoom);
getRoute(OSRM.FULL_DESCRIPTION);
my_markers.route[index].dirty_move = false;
my_markers.route[index].dirty_type = false;
} }
// process 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(marker_id);
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);
} }
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').innerHTML = html;
onclickGeocoderResult(marker_id, response[0].lat, response[0].lon);
} }
function showGeocoderResults_Empty(marker_id) { function showGeocoderResults_Empty(marker_id) {
document.getElementById('information-box-headline').innerHTML = OSRM.loc("SEARCH_RESULTS")+":"; document.getElementById('information-box-headline').innerHTML = OSRM.loc("SEARCH_RESULTS")+":";
if(marker_id == OSRM.SOURCE_MARKER_LABEL) 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>"; 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.TARGET_MARKER_LABEL) 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>"; 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 else
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 = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("NO_RESULTS_FOUND")+".<p>";
@@ -138,68 +116,88 @@ function showGeocoderResults_Timeout() {
} }
// - [upcoming feature: reverse geocoding (untested) ] - // [reverse geocoding]
OSRM.REVERSE_GEOCODE_POST = 'http://nominatim.openstreetmap.org/reverse?format=json&bounded=1&viewbox=-27.0,72.0,46.0,36.0';
//update reverse geocoder informatiopn in input boxes //update geo coordinates in input boxes
function updateReverseGeocoder(marker_id) { function updateLocation(marker_id) {
if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.hasSource()==true) { //&& my_markers.route[0].dirty == true ) { if (marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource()) {
//document.getElementById("input-source-name").value = my_markers.route[0].getPosition().lat.toFixed(6) + ", " + my_markers.route[0].getPosition().lng.toFixed(6); document.getElementById("input-source-name").value = OSRM.G.markers.route[0].getPosition().lat.toFixed(6) + ", " + OSRM.G.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.C.TARGET_LABEL && OSRM.G.markers.hasTarget()) {
} else if (marker_id == OSRM.TARGET_MARKER_LABEL && my_markers.hasTarget()==true) { //&& my_markers.route[my_markers.route.length-1].dirty == true) { 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);
//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);
} }
} }
//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, showReverseGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "reverse_geocoder_source" );
} else if (marker_id == OSRM.TARGET_MARKER_LABEL) {
var src = OSRM.REVERSE_GEOCODE_POST + "&lat=" + lat + "&lon=" + lon;
OSRM.JSONP.call( src, showReverseGeocoderResults_Target, showReverseGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "reverse_geocoder_target" );
}
}
//processing JSONP response of reverse geocoder
//(with wrapper functions for source/target jsonp)
function showReverseGeocoderResults_Timeout() {}
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 = ""; // update address in input boxes
if( response.address.road) function updateAddress(marker_id, do_fallback_to_lat_lng) {
address += response.address.road; // build request for reverse geocoder
if( response.address.city ) { var lat = null;
if( address != "" ) var lng = null;
address += ", ";
address += response.address.city; if(marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource()) {
} else if( response.address.village ) { lat = OSRM.G.markers.route[0].getPosition().lat;
if( address != "" ) lng = OSRM.G.markers.route[0].getPosition().lng;
address += ", "; } else if(marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget() ) {
address += response.address.village; 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;
if( address == "" && response.address.country ) } else
address += response.address.country; return;
if( address == "" )
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;
}
if(marker_id == OSRM.SOURCE_MARKER_LABEL) { // add result to DOM
document.getElementById("input-source-name").value = address; if(parameters.marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource() )
my_markers.route[0].dirty_move = false; document.getElementById("input-source-name").value = address;
my_markers.route[0].dirty_type = false; else if(parameters.marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget() )
} else if(marker_id == OSRM.TARGET_MARKER_LABEL) { document.getElementById("input-target-name").value = address;
document.getElementById("input-target-name").value = address; }
my_markers.route[my_markers.route.length-1].dirty_move = false; function showReverseGeocoderResults_Timeout(response, parameters) {
my_markers.route[my_markers.route.length-1].dirty_type = false; if(!parameters.do_fallback)
} return;
} updateLocation(parameters.marker_id);
} }
+6 -6
View File
@@ -34,11 +34,11 @@ or see http://www.gnu.org/licenses/agpl.txt.
<!-- 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>
@@ -88,14 +88,14 @@ or see http://www.gnu.org/licenses/agpl.txt.
<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" maxlength="200" value="" title="Startposition eingeben" onchange="if( my_markers.route[0] && my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL) my_markers.route[0].dirty_type = true;" onblur="callGeocoder(OSRM.SOURCE_MARKER_LABEL, document.getElementById('input-source-name').value);" 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-search-source" onclick="centerMarker('source')">Zeigen</a></td> <td class="right"><a class="button not-selectable" id="gui-search-source" onclick="showMarker('source')">Zeigen</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" maxlength="200" value="" title="Zielposition eingeben" onchange="if( my_markers.route[my_markers.route.length-1] && my_markers.route[my_markers.route.length-1].label == OSRM.TARGET_MARKER_LABEL) my_markers.route[my_markers.route.length-1].dirty_type = true;" onblur="callGeocoder(OSRM.TARGET_MARKER_LABEL, document.getElementById('input-target-name').value);" 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-search-target" onclick="centerMarker('target');">Zeigen</a></td> <td class="right"><a class="button not-selectable" id="gui-search-target" onclick="showMarker('target');">Zeigen</a></td>
</tr> </tr>
</table> </table>
@@ -112,7 +112,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
<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>
+57 -28
View File
@@ -18,7 +18,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
// OSRM initialization // OSRM initialization
// [initialization of maps, local strings, image prefetching] // [initialization of maps, local strings, image prefetching]
var map; // will hold the Leaflet map object
OSRM.GLOBALS.map = null;
// onload initialization routine // onload initialization routine
@@ -92,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)
@@ -125,7 +126,7 @@ function initMap() {
cloudmade = new L.TileLayer(cloudmadeURL, cloudmadeOptions); cloudmade = new L.TileLayer(cloudmadeURL, cloudmadeOptions);
// setup map // setup map
map = new L.Map('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, // false: removes animations and hiding of routes during zoom zoomAnimation: false, // false: removes animations and hiding of routes during zoom
@@ -143,25 +144,32 @@ 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 // 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";
// initial map position and zoom // initial map position and zoom
map.setView( new L.LatLng( OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE), OSRM.DEFAULTS.ZOOM_LEVEL); OSRM.G.map.setView( new L.LatLng( OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE), OSRM.DEFAULTS.ZOOM_LEVEL);
map.on('zoomend', function(e) { getRoute(OSRM.FULL_DESCRIPTION); }); OSRM.G.map.on('zoomend', function(e) { getRoute(OSRM.C.FULL_DESCRIPTION); });
map.on('contextmenu', function(e) {}); OSRM.G.map.on('contextmenu', function(e) {});
// click on map to set source and target nodes // click on map to set source and target nodes
map.on('click', function(e) { OSRM.G.map.on('click', function(e) {
if( !my_markers.route[0] || my_markers.route[0].label != OSRM.SOURCE_MARKER_LABEL) { if( !OSRM.G.markers.hasSource() ) {
onclickGeocoderResult("source", e.latlng.lat, e.latlng.lng, true, false ); var index = OSRM.G.markers.setSource( e.latlng );
updateAddress( OSRM.C.SOURCE_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( !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) {
onclickGeocoderResult("target", e.latlng.lat, e.latlng.lng, true, false );
}
} ); } );
} }
@@ -176,8 +184,10 @@ function checkURL(){
// storage for parameter values // storage for parameter values
var positions = []; var positions = [];
var destination = undefined; var zoom = null;
var destination_name = undefined; var center = null;
var destination = null;
var destination_name = null;
// parse input // parse input
var splitted_url = called_url.split('&'); var splitted_url = called_url.split('&');
@@ -201,13 +211,28 @@ function checkURL(){
else if(name_val[0] == 'destname') { else if(name_val[0] == 'destname') {
destination_name = decodeURI(name_val[1]).replace(/<\/?[^>]+(>|$)/g ,""); // discard tags destination_name = decodeURI(name_val[1]).replace(/<\/?[^>]+(>|$)/g ,""); // discard tags
} }
else if(name_val[0] == 'z') {
zoom = name_val[1];
if( zoom<0 || zoom > 18)
return;
}
else if(name_val[0] == 'center') {
var coordinates = unescape(name_val[1]).split(',');
if(coordinates.length!=2 || !isLatitude(coordinates[0]) || !isLongitude(coordinates[1]) )
return;
center = new L.LatLng( coordinates[0], coordinates[1]);
}
} }
// case 1: destination given // case 1: destination given
if( destination != undefined ) { if( destination != undefined ) {
onclickGeocoderResult("target", destination.lat, destination.lng, (destination_name == undefined) ); var index = OSRM.G.markers.setTarget( e.latlng );
if( destination_name != undefined ) 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; document.getElementById("input-target-name").value = destination_name;
OSRM.G.markers.route[index].show();
OSRM.G.markers.route[index].centerView();
return; return;
} }
@@ -215,23 +240,27 @@ function checkURL(){
if( positions != []) { if( positions != []) {
// draw via points // draw via points
if( positions.length > 0) { if( positions.length > 0) {
onclickGeocoderResult("source", positions[0].lat, positions[0].lng, true, false ); OSRM.G.markers.setSource( positions[0] );
//my_markers.setSource( positions[0] ); updateAddress( OSRM.C.SOURCE_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
} }
if(positions.length > 1) { if(positions.length > 1) {
onclickGeocoderResult("target", positions[positions.length-1].lat, positions[positions.length-1].lng, true, false ); OSRM.G.markers.setTarget( positions[positions.length-1] );
//my_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++) for(var i=1; i<positions.length-1;i++)
my_markers.setVia( i-1, positions[i] ); OSRM.G.markers.setVia( i-1, positions[i] );
for(var i=0; i<my_markers.route.length;i++) for(var i=0; i<OSRM.G.markers.route.length;i++)
my_markers.route[i].show(); OSRM.G.markers.route[i].show();
// center on route // center on route (support for old links) / move to given view (new behaviour)
var bounds = new L.LatLngBounds( positions ); if(zoom == null || center == null) {
map.fitBounds( bounds ); var bounds = new L.LatLngBounds( positions );
OSRM.G.map.fitBounds( bounds );
} else {
OSRM.G.map.setView(center, zoom);
}
// compute route // compute route
getRoute(OSRM.FULL_DESCRIPTION); getRoute(OSRM.C.FULL_DESCRIPTION);
} }
} }
+103 -93
View File
@@ -20,20 +20,22 @@ or see http://www.gnu.org/licenses/agpl.txt.
// [TODO: major refactoring scheduled] // [TODO: major refactoring scheduled]
// some variables // some variables
var my_route = undefined; OSRM.GLOBALS.route = null;
var my_markers = undefined; OSRM.GLOBALS.markers = null;
OSRM.NO_DESCRIPTION = 0; OSRM.CONSTANTS.NO_DESCRIPTION = 0;
OSRM.FULL_DESCRIPTION = 1; OSRM.CONSTANTS.FULL_DESCRIPTION = 1;
OSRM.dragging = false;
OSRM.pending = false; OSRM.G.dragging = null;
OSRM.pendingTimer = undefined; OSRM.GLOBALS.dragid = null;
OSRM.GLOBALS.pending = false;
OSRM.GLOBALS.pendingTimer = null;
// init routing data structures // 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();
} }
@@ -47,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>";
} }
@@ -55,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) {
@@ -69,9 +71,9 @@ function showRouteSimple(response) {
updateHints(response); updateHints(response);
// // TODO: hack to process final drag event, if it was fenced, but we are still dragging (alternative approach) // // TODO: hack to process final drag event, if it was fenced, but we are still dragging (alternative approach)
// if(OSRM.pending) { // if(OSRM.G.pending) {
// clearTimeout(OSRM.pendingTimer); // clearTimeout(OSRM.G.pendingTimer);
// OSRM.pendingTimer = setTimeout(timeoutDrag,100); // 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 {
@@ -96,13 +98,13 @@ function showRoute(response) {
// show route geometry // 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);
@@ -110,20 +112,22 @@ 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);
} }
// route description display (and helper functions) // route description display (and helper functions)
function onClickRouteDescription(geometry_index) { function onClickRouteDescription(geometry_index) {
var positions = my_route.getPositions(); var positions = OSRM.G.route.getPositions();
my_markers.highlight.setPosition( positions[geometry_index] ); OSRM.G.markers.highlight.setPosition( positions[geometry_index] );
my_markers.highlight.show(); OSRM.G.markers.highlight.show();
my_markers.highlight.centerView(); 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-prelink').innerHTML = '[<a id="gpx-link" class = "text-selectable" href="' +response.ShortURL+ '">'+response.ShortURL+'</a>]'; document.getElementById('route-prelink').innerHTML = '[<a id="gpx-link" class = "text-selectable" href="' +response.ShortURL+ '">'+response.ShortURL+'</a>]';
@@ -133,15 +137,15 @@ function showRouteLink_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-prelink">[<a id="gpx-link" href="#" 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>';
// 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 = "";
@@ -227,7 +231,7 @@ function showNoRouteDescription() {
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;
} }
@@ -261,7 +265,7 @@ function showRouteNonames(response) {
} }
// display unnamed streets // display unnamed streets
my_route.showUnnamedRoute(all_positions); OSRM.G.route.showUnnamedRoute(all_positions);
} }
@@ -271,24 +275,24 @@ function showRouteNonames(response) {
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();
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
@@ -309,23 +313,23 @@ function getRoute(do_description) {
// TODO: hack to process final drag event, if it was fenced, but we are still dragging // 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.DEFAULTS.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) // // 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);
} }
@@ -361,27 +365,22 @@ function decodeRouteGeometry(encoded, precision) {
// update hints of all markers // 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 // 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);
//if(OSRM.dragid == 0 && my_markers.hasSource()==true)
updateReverseGeocoder("source");
//else if(OSRM.dragid == my_markers.route.length-1 && my_markers.hasTarget()==true)
updateReverseGeocoder("target");
} }
// map driving instructions to icons // map driving instructions to icons
@@ -400,7 +399,7 @@ function getDirectionIcon(name) {
"Enter roundabout and leave at first exit":"round-about.png", "Enter roundabout and leave at first exit":"round-about.png",
"Enter roundabout and leave at second exit":"round-about.png", "Enter roundabout and leave at second exit":"round-about.png",
"Enter roundabout and leave at third exit":"round-about.png", "Enter roundabout and leave at third exit":"round-about.png",
"Enter roundabout and leave at forth exit":"round-about.png", "Enter roundabout and leave at fourth exit":"round-about.png",
"Enter roundabout and leave at fifth exit":"round-about.png", "Enter roundabout and leave at fifth exit":"round-about.png",
"Enter roundabout and leave at sixth exit":"round-about.png", "Enter roundabout and leave at sixth exit":"round-about.png",
"Enter roundabout and leave at seventh exit":"round-about.png", "Enter roundabout and leave at seventh exit":"round-about.png",
@@ -425,14 +424,14 @@ function resetRouting() {
document.getElementById('input-source-name').value = ""; document.getElementById('input-source-name').value = "";
document.getElementById('input-target-name').value = ""; document.getElementById('input-target-name').value = "";
my_route.hideAll(); OSRM.G.route.hideAll();
my_markers.removeAll(); OSRM.G.markers.removeAll();
my_markers.highlight.hide(); OSRM.G.markers.highlight.hide();
document.getElementById('information-box').innerHTML = ""; document.getElementById('information-box').innerHTML = "";
document.getElementById('information-box-headline').innerHTML = ""; document.getElementById('information-box-headline').innerHTML = "";
OSRM.JSONP.reset(); OSRM.JSONP.reset();
} }
// click: button "reverse" // click: button "reverse"
@@ -443,27 +442,27 @@ function reverseRouting() {
document.getElementById("input-target-name").value = tmp; document.getElementById("input-target-name").value = tmp;
// invert route // invert route
my_markers.route.reverse(); OSRM.G.markers.route.reverse();
if(my_markers.route.length == 1) { if(OSRM.G.markers.route.length == 1) {
if(my_markers.route[0].label == OSRM.TARGET_MARKER_LABEL) { if(OSRM.G.markers.route[0].label == OSRM.C.TARGET_LABEL) {
my_markers.route[0].label = OSRM.SOURCE_MARKER_LABEL; OSRM.G.markers.route[0].label = OSRM.C.SOURCE_LABEL;
my_markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') ); OSRM.G.markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') );
} else if(my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL) { } else if(OSRM.G.markers.route[0].label == OSRM.C.SOURCE_LABEL) {
my_markers.route[0].label = OSRM.TARGET_MARKER_LABEL; OSRM.G.markers.route[0].label = OSRM.C.TARGET_LABEL;
my_markers.route[0].marker.setIcon( new L.Icon('images/marker-target.png') ); OSRM.G.markers.route[0].marker.setIcon( new L.Icon('images/marker-target.png') );
} }
} else if(my_markers.route.length > 1){ } else if(OSRM.G.markers.route.length > 1){
my_markers.route[0].label = OSRM.SOURCE_MARKER_LABEL; OSRM.G.markers.route[0].label = OSRM.C.SOURCE_LABEL;
my_markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') ); OSRM.G.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; OSRM.G.markers.route[OSRM.G.markers.route.length-1].label = OSRM.C.TARGET_LABEL;
my_markers.route[my_markers.route.length-1].marker.setIcon( new L.Icon('images/marker-target.png') ); OSRM.G.markers.route[OSRM.G.markers.route.length-1].marker.setIcon( new L.Icon('images/marker-target.png') );
} }
// recompute route // recompute route
if( my_route.isShown() ) { if( OSRM.G.route.isShown() ) {
getRoute(OSRM.FULL_DESCRIPTION); getRoute(OSRM.C.FULL_DESCRIPTION);
my_markers.highlight.hide(); OSRM.G.markers.highlight.hide();
} else { } else {
document.getElementById('information-box').innerHTML = ""; document.getElementById('information-box').innerHTML = "";
document.getElementById('information-box-headline').innerHTML = ""; document.getElementById('information-box-headline').innerHTML = "";
@@ -471,10 +470,21 @@ function reverseRouting() {
} }
// click: button "show" // click: button "show"
function centerMarker(marker_id) { function showMarker(marker_id) {
if( marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.route[0] && my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL && !my_markers.route[0].dirty_type ) { if( OSRM.JSONP.fences["geocoder_source"] || OSRM.JSONP.fences["geocoder_target"] )
my_markers.route[0].centerView(); return;
} else if( marker_id == OSRM.TARGET_MARKER_LABEL && my_markers.route[my_markers.route.length-1] && my_markers.route[my_markers.route.length-1].label == OSRM.TARGET_MARKER_LABEL && !my_markers.route[my_markers.route.length-1].dirty_type) {
my_markers.route[my_markers.route.length-1].centerView(); 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);
} }
+8 -8
View File
@@ -16,7 +16,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
*/ */
// store location of via points returned by server // store location of via points returned by server
var via_points; 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) // find route segment of current route geometry that is closest to the new via node (marked by index of its endpoint)
@@ -24,7 +24,7 @@ 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) {
@@ -43,10 +43,10 @@ function findViaPosition( new_via_position ) {
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;
@@ -54,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;
} }