Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e2e95cc27 | |||
| f4c6ec90ce | |||
| eed22b343a | |||
| 08ce748a37 | |||
| 69790eb8c7 | |||
| 97b9c65c97 | |||
| 92dbadebae | |||
| fe6d854e11 | |||
| 4615b01fdf | |||
| 276b023b05 | |||
| 350cacb2f3 | |||
| 25ec6105c5 | |||
| 3e4249ad41 | |||
| 13126ac0c1 | |||
| d51aee4fbe | |||
| f9877fd8ba | |||
| a39a35df73 | |||
| 2670dd68f3 | |||
| 9adb590ce7 | |||
| 9567a7e38c |
@@ -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
@@ -34,7 +34,7 @@ OSRM.JSONP = {
|
||||
|
||||
|
||||
// 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
|
||||
if (OSRM.JSONP.fences[id] == true)
|
||||
return false;
|
||||
@@ -42,25 +42,29 @@ OSRM.JSONP = {
|
||||
|
||||
// wrap timeout function
|
||||
OSRM.JSONP.timeouts[id] = function(response) {
|
||||
timeout_function(response);
|
||||
|
||||
OSRM.JSONP.callbacks[id] = OSRM.JSONP.late; // clean functions
|
||||
OSRM.JSONP.timeouts[id] = OSRM.JSONP.late;
|
||||
OSRM.JSONP.fences[id] = undefined; // clean fence
|
||||
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
|
||||
}
|
||||
|
||||
// OSRM.debug.log("[jsonp] timout handling: "+id);
|
||||
};
|
||||
|
||||
// wrap callback function
|
||||
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;
|
||||
|
||||
callback_function(response); // actual wrapped callback
|
||||
|
||||
OSRM.JSONP.callbacks[id] = OSRM.JSONP.late; // clean functions
|
||||
OSRM.JSONP.timeouts[id] = OSRM.JSONP.late;
|
||||
OSRM.JSONP.fences[id] = undefined; // clean fence
|
||||
try {
|
||||
callback_function(response, parameters); // actual wrapped callback
|
||||
} finally {
|
||||
OSRM.JSONP.callbacks[id] = OSRM.JSONP.empty; // clean functions
|
||||
OSRM.JSONP.timeouts[id] = OSRM.JSONP.late;
|
||||
OSRM.JSONP.fences[id] = undefined; // clean fence
|
||||
}
|
||||
|
||||
// OSRM.debug.log("[jsonp] response handling: "+id);
|
||||
};
|
||||
|
||||
@@ -48,7 +48,7 @@ OSRM.Localization["de"] = {
|
||||
"GUI_HIGHLIGHT_UNNAMED_ROADS": "Unbenannte Straßen hervorheben",
|
||||
"GUI_START_TOOLTIP": "Startposition 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
|
||||
"SEARCH_RESULTS": "Suchergebnisse",
|
||||
"TIMED_OUT": "Zeitüberschreitung",
|
||||
@@ -57,7 +57,8 @@ OSRM.Localization["de"] = {
|
||||
"NO_RESULTS_FOUND_TARGET": "Keine Ergebnisse gefunden für Ziel",
|
||||
// routing
|
||||
"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",
|
||||
"GPX_FILE": "GPX Datei",
|
||||
"DISTANCE": "Distanz",
|
||||
@@ -88,7 +89,7 @@ OSRM.Localization["en"] = {
|
||||
"GUI_HIGHLIGHT_UNNAMED_ROADS": "Highlight unnamed streets",
|
||||
"GUI_START_TOOLTIP": "Enter start",
|
||||
"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
|
||||
"SEARCH_RESULTS": "Search Results",
|
||||
"TIMED_OUT": "Timed Out",
|
||||
@@ -97,7 +98,8 @@ OSRM.Localization["en"] = {
|
||||
"NO_RESULTS_FOUND_TARGET": "No results found for end",
|
||||
//routing
|
||||
"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",
|
||||
"GPX_FILE": "GPX File",
|
||||
"DISTANCE": "Distance",
|
||||
|
||||
+42
-56
@@ -26,25 +26,23 @@ OSRM.Marker = function( label, style, position ) {
|
||||
|
||||
this.marker = new L.MouseMarker( this.position, style );
|
||||
this.marker.parent = this;
|
||||
this.dirty_move = true;
|
||||
this.dirty_type = true;
|
||||
|
||||
this.shown = false;
|
||||
this.hint = undefined;
|
||||
this.hint = null;
|
||||
};
|
||||
OSRM.extend( OSRM.Marker,{
|
||||
show: function() {
|
||||
map.addLayer(this.marker);
|
||||
OSRM.G.map.addLayer(this.marker);
|
||||
this.shown = true;
|
||||
},
|
||||
hide: function() {
|
||||
map.removeLayer(this.marker);
|
||||
OSRM.G.map.removeLayer(this.marker);
|
||||
this.shown = false;
|
||||
},
|
||||
setPosition: function( position ) {
|
||||
this.position = position;
|
||||
this.marker.setLatLng( position );
|
||||
this.hint = undefined;
|
||||
this.hint = null;
|
||||
},
|
||||
getPosition: function() {
|
||||
return this.position;
|
||||
@@ -58,12 +56,10 @@ getLng: function() {
|
||||
isShown: function() {
|
||||
return this.shown;
|
||||
},
|
||||
centerView: function(zooming) {
|
||||
var zoom = OSRM.DEFAULTS.ZOOM_LEVEL;
|
||||
if( zooming == false )
|
||||
zoom = map.getZoom();
|
||||
//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);
|
||||
centerView: function(zoom) {
|
||||
if( zoom == undefined )
|
||||
zoom = OSRM.DEFAULTS.ZOOM_LEVEL;
|
||||
OSRM.G.map.setView( new L.LatLng( this.position.lat, this.position.lng), zoom);
|
||||
},
|
||||
toString: function() {
|
||||
return "OSRM.Marker: \""+this.label+"\", "+this.position+")";
|
||||
@@ -102,58 +98,46 @@ OSRM.RouteMarker = function ( label, style, position ) {
|
||||
OSRM.inheritFrom( OSRM.RouteMarker, OSRM.Marker );
|
||||
OSRM.extend( OSRM.RouteMarker, {
|
||||
onClick: function(e) {
|
||||
for( var i=0; i<my_markers.route.length; i++) {
|
||||
if( my_markers.route[i].marker === this ) {
|
||||
my_markers.removeMarker( i );
|
||||
for( var i=0; i<OSRM.G.markers.route.length; i++) {
|
||||
if( OSRM.G.markers.route[i].marker === this ) {
|
||||
OSRM.G.markers.removeMarker( i );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
getRoute(OSRM.FULL_DESCRIPTION);
|
||||
my_markers.highlight.hide();
|
||||
getRoute(OSRM.C.FULL_DESCRIPTION);
|
||||
OSRM.G.markers.highlight.hide();
|
||||
},
|
||||
onDrag: function(e) {
|
||||
this.parent.dirty_move = true;
|
||||
this.parent.setPosition( e.target.getLatLng() );
|
||||
if(OSRM.dragging == true) // TODO: hack that deals with drag events after dragend event
|
||||
getRoute(OSRM.NO_DESCRIPTION);
|
||||
else
|
||||
getRoute(OSRM.FULL_DESCRIPTION);
|
||||
|
||||
getRoute(OSRM.C.NO_DESCRIPTION);
|
||||
updateLocation( this.parent.label );
|
||||
},
|
||||
onDragStart: function(e) {
|
||||
OSRM.dragging = true;
|
||||
OSRM.G.dragging = true;
|
||||
|
||||
// hack to store id of dragged marker
|
||||
for( var i=0; i<my_markers.route.length; i++)
|
||||
if( my_markers.route[i].marker === this ) {
|
||||
OSRM.dragid = i;
|
||||
// store id of dragged marker
|
||||
for( var i=0; i<OSRM.G.markers.route.length; i++)
|
||||
if( OSRM.G.markers.route[i].marker === this ) {
|
||||
OSRM.G.dragid = i;
|
||||
break;
|
||||
}
|
||||
|
||||
my_markers.highlight.hide();
|
||||
if (my_route.isShown()) {
|
||||
my_route.showOldRoute();
|
||||
}
|
||||
|
||||
updateLocation( this.parent.label );
|
||||
OSRM.G.markers.highlight.hide();
|
||||
if (OSRM.G.route.isShown())
|
||||
OSRM.G.route.showOldRoute();
|
||||
},
|
||||
onDragEnd: function(e) {
|
||||
getRoute(OSRM.FULL_DESCRIPTION);
|
||||
if (my_route.isShown()) {
|
||||
my_route.hideOldRoute();
|
||||
my_route.hideUnnamedRoute();
|
||||
OSRM.G.dragging = false;
|
||||
this.parent.setPosition( e.target.getLatLng() );
|
||||
getRoute(OSRM.C.FULL_DESCRIPTION);
|
||||
if (OSRM.G.route.isShown()) {
|
||||
OSRM.G.route.hideOldRoute();
|
||||
OSRM.G.route.hideUnnamedRoute();
|
||||
}
|
||||
OSRM.dragging = false;
|
||||
|
||||
updateLocation( this.parent.label );
|
||||
if(my_route.isShown()==false) {
|
||||
if(this.parent.label == "source")
|
||||
updateReverseGeocoder("source");
|
||||
else if(this.parent.label == "target")
|
||||
updateReverseGeocoder("target");
|
||||
}
|
||||
if(OSRM.G.route.isShown()==false)
|
||||
updateAddress(this.parent.label);
|
||||
},
|
||||
toString: function() {
|
||||
return "OSRM.RouteMarker: \""+this.label+"\", "+this.position+")";
|
||||
@@ -181,18 +165,18 @@ removeVias: function() {
|
||||
},
|
||||
setSource: function(position) {
|
||||
// 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);
|
||||
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;
|
||||
},
|
||||
setTarget: function(position) {
|
||||
// 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);
|
||||
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;
|
||||
},
|
||||
setVia: function(id, position) {
|
||||
@@ -200,7 +184,7 @@ setVia: function(id, position) {
|
||||
if( this.route.length<2 || id > this.route.length-2 )
|
||||
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;
|
||||
},
|
||||
removeMarker: function(id) {
|
||||
@@ -208,24 +192,26 @@ removeMarker: function(id) {
|
||||
return;
|
||||
|
||||
// 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();
|
||||
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();
|
||||
id = this.route.length-1;
|
||||
document.getElementById('input-target-name').value = "";
|
||||
}
|
||||
|
||||
this.route[id].hide();
|
||||
this.route.splice(id, 1);
|
||||
},
|
||||
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 false;
|
||||
},
|
||||
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 false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,11 +32,11 @@ OSRM.SimpleRoute = function (label, style) {
|
||||
};
|
||||
OSRM.extend( OSRM.SimpleRoute,{
|
||||
show: function() {
|
||||
map.addLayer(this.route);
|
||||
OSRM.G.map.addLayer(this.route);
|
||||
this.shown = true;
|
||||
},
|
||||
hide: function() {
|
||||
map.removeLayer(this.route);
|
||||
OSRM.G.map.removeLayer(this.route);
|
||||
this.shown = false;
|
||||
},
|
||||
isShown: function() {
|
||||
@@ -53,10 +53,10 @@ setStyle: function(style) {
|
||||
},
|
||||
centerView: function() {
|
||||
var bounds = new L.LatLngBounds( this.getPositions() );
|
||||
map.fitBounds( bounds );
|
||||
OSRM.G.map.fitBounds( bounds );
|
||||
},
|
||||
onClick: function(e) {
|
||||
if(my_route.isRoute())
|
||||
if(OSRM.G.route.isRoute())
|
||||
findViaPosition( e.latlng );
|
||||
},
|
||||
toString: function() {
|
||||
@@ -74,11 +74,11 @@ OSRM.MultiRoute = function (label) {
|
||||
};
|
||||
OSRM.extend( OSRM.MultiRoute,{
|
||||
show: function() {
|
||||
map.addLayer(this.route);
|
||||
OSRM.G.map.addLayer(this.route);
|
||||
this.shown = true;
|
||||
},
|
||||
hide: function() {
|
||||
map.removeLayer(this.route);
|
||||
OSRM.G.map.removeLayer(this.route);
|
||||
this.shown = false;
|
||||
},
|
||||
isShown: function() {
|
||||
@@ -86,7 +86,7 @@ isShown: function() {
|
||||
},
|
||||
addRoute: function(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 );
|
||||
},
|
||||
clearRoutes: function() {
|
||||
|
||||
+12
-6
@@ -16,13 +16,19 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM base class
|
||||
// [has to loaded before all other OSRM classes]
|
||||
// [has to be loaded before all other OSRM classes]
|
||||
|
||||
OSRM = {};
|
||||
OSRM.VERSION = '0.1.1';
|
||||
var OSRM = {};
|
||||
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.inheritFrom = function( sub_class, base_class ) {
|
||||
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 ) {
|
||||
for( property in properties ) {
|
||||
target_class.prototype[property] = properties[property];
|
||||
@@ -40,7 +46,7 @@ OSRM.extend = function( target_class, properties ) {
|
||||
};
|
||||
|
||||
|
||||
// usage:
|
||||
// [usage of convenience functions]
|
||||
// SubClass = function() {
|
||||
// SubClass.prototype.base.constructor.apply(this, arguments);
|
||||
// }
|
||||
|
||||
@@ -21,12 +21,16 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
OSRM.DEFAULTS = {
|
||||
HOST_ROUTING_URL: 'http://router.project-osrm.org/viaroute',
|
||||
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,
|
||||
ZOOM_LEVEL: 14,
|
||||
ONLOAD_LATITUDE: 48.84,
|
||||
ONLOAD_LONGITUDE: 10.10,
|
||||
ONLOAD_SOURCE: "",
|
||||
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
@@ -20,114 +20,92 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
// [TODO: better separation of GUI and geocoding routines, reverse geocoding]
|
||||
|
||||
// some constants
|
||||
OSRM.GEOCODE_POST = 'http://nominatim.openstreetmap.org/search?format=json&bounded=1&viewbox=-27.0,72.0,46.0,36.0';
|
||||
OSRM.SOURCE_MARKER_LABEL = "source";
|
||||
OSRM.TARGET_MARKER_LABEL = "target";
|
||||
OSRM.CONSTANTS.SOURCE_LABEL = "source";
|
||||
OSRM.CONSTANTS.TARGET_LABEL = "target";
|
||||
OSRM.CONSTANTS.VIA_LABEL = "via";
|
||||
OSRM.C.DO_FALLBACK_TO_LAT_LNG = true;
|
||||
|
||||
|
||||
// update geo coordinates in input boxes
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
//[normal geocoding]
|
||||
|
||||
// process input request and call geocoder if needed
|
||||
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=="")
|
||||
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*$/)){
|
||||
var coord = query.split(/[,;]/);
|
||||
onclickGeocoderResult(marker_id, coord[0], coord[1], true);
|
||||
onclickGeocoderResult(marker_id, coord[0], coord[1]);
|
||||
updateAddress( marker_id );
|
||||
return;
|
||||
}
|
||||
|
||||
//build request
|
||||
if (marker_id == OSRM.SOURCE_MARKER_LABEL) {
|
||||
var src= OSRM.GEOCODE_POST + "&q=" + query;
|
||||
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" );
|
||||
}
|
||||
//build request for geocoder
|
||||
var call = OSRM.DEFAULTS.HOST_GEOCODER_URL + "?format=json" + OSRM.DEFAULTS.GEOCODER_BOUNDS + "&q=" + query;
|
||||
OSRM.JSONP.call( call, showGeocoderResults, showGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "geocoder_"+marker_id, marker_id );
|
||||
}
|
||||
|
||||
|
||||
// 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;
|
||||
if( marker_id == OSRM.SOURCE_MARKER_LABEL )
|
||||
index = my_markers.setSource( new L.LatLng(lat, lon) );
|
||||
else if( marker_id == OSRM.TARGET_MARKER_LABEL )
|
||||
index = my_markers.setTarget( new L.LatLng(lat, lon) );
|
||||
if( marker_id == OSRM.C.SOURCE_LABEL )
|
||||
index = OSRM.G.markers.setSource( new L.LatLng(lat, lon) );
|
||||
else if( marker_id == OSRM.C.TARGET_LABEL )
|
||||
index = OSRM.G.markers.setTarget( new L.LatLng(lat, lon) );
|
||||
else
|
||||
index = -1; // via nodes not yet implemented
|
||||
return;
|
||||
|
||||
if( do_reverse_geocode == true )
|
||||
updateReverseGeocoder(marker_id);
|
||||
if( zoom == undefined )
|
||||
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;
|
||||
OSRM.G.markers.route[index].show();
|
||||
OSRM.G.markers.route[index].centerView();
|
||||
getRoute(OSRM.C.FULL_DESCRIPTION);
|
||||
}
|
||||
|
||||
// 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 ?
|
||||
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);
|
||||
// process geocoder response
|
||||
function showGeocoderResults(response, marker_id) {
|
||||
if(!response){
|
||||
showGeocoderResults_Empty(marker_id);
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
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>";
|
||||
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>";
|
||||
else
|
||||
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) ] -
|
||||
OSRM.REVERSE_GEOCODE_POST = 'http://nominatim.openstreetmap.org/reverse?format=json&bounded=1&viewbox=-27.0,72.0,46.0,36.0';
|
||||
// [reverse geocoding]
|
||||
|
||||
//update reverse geocoder informatiopn in input boxes
|
||||
function updateReverseGeocoder(marker_id) {
|
||||
if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.hasSource()==true) { //&& my_markers.route[0].dirty == true ) {
|
||||
//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 && my_markers.hasTarget()==true) { //&& my_markers.route[my_markers.route.length-1].dirty == 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);
|
||||
callReverseGeocoder("target", my_markers.route[my_markers.route.length-1].getPosition().lat, my_markers.route[my_markers.route.length-1].getPosition().lng);
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
//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 = "";
|
||||
if( response.address.road)
|
||||
address += response.address.road;
|
||||
if( response.address.city ) {
|
||||
if( address != "" )
|
||||
address += ", ";
|
||||
address += response.address.city;
|
||||
} else if( response.address.village ) {
|
||||
if( address != "" )
|
||||
address += ", ";
|
||||
address += response.address.village;
|
||||
}
|
||||
if( address == "" && response.address.country )
|
||||
address += response.address.country;
|
||||
if( address == "" )
|
||||
return;
|
||||
// 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;
|
||||
}
|
||||
|
||||
if(marker_id == OSRM.SOURCE_MARKER_LABEL) {
|
||||
document.getElementById("input-source-name").value = address;
|
||||
my_markers.route[0].dirty_move = false;
|
||||
my_markers.route[0].dirty_type = false;
|
||||
} else if(marker_id == OSRM.TARGET_MARKER_LABEL) {
|
||||
document.getElementById("input-target-name").value = address;
|
||||
my_markers.route[my_markers.route.length-1].dirty_move = false;
|
||||
my_markers.route[my_markers.route.length-1].dirty_type = false;
|
||||
}
|
||||
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -34,11 +34,11 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
|
||||
<!-- stylesheets -->
|
||||
<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"/>
|
||||
|
||||
<!-- scripts -->
|
||||
<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.MouseMarker.js" type="text/javascript"></script>
|
||||
|
||||
@@ -88,14 +88,14 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
<table class="full">
|
||||
<tr>
|
||||
<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 class="right"><a class="button not-selectable" id="gui-search-source" onclick="centerMarker('source')">Zeigen</a></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="showMarker('source')">Zeigen</a></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<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 class="right"><a class="button not-selectable" id="gui-search-target" onclick="centerMarker('target');">Zeigen</a></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="showMarker('target');">Zeigen</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -112,7 +112,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
<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-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>
|
||||
|
||||
|
||||
+57
-28
@@ -18,7 +18,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
// OSRM initialization
|
||||
// [initialization of maps, local strings, image prefetching]
|
||||
|
||||
var map;
|
||||
// will hold the Leaflet map object
|
||||
OSRM.GLOBALS.map = null;
|
||||
|
||||
|
||||
// onload initialization routine
|
||||
@@ -92,7 +93,7 @@ function initLocale() {
|
||||
|
||||
// centering on geolocation
|
||||
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() {
|
||||
if (navigator.geolocation)
|
||||
@@ -125,7 +126,7 @@ function initMap() {
|
||||
cloudmade = new L.TileLayer(cloudmadeURL, cloudmadeOptions);
|
||||
|
||||
// setup map
|
||||
map = new L.Map('map', {
|
||||
OSRM.G.map = new L.Map('map', {
|
||||
center: new L.LatLng(51.505, -0.09),
|
||||
zoom: 13,
|
||||
zoomAnimation: false, // false: removes animations and hiding of routes during zoom
|
||||
@@ -143,25 +144,32 @@ function initMap() {
|
||||
|
||||
var 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.top="5px";
|
||||
|
||||
// initial map position and zoom
|
||||
map.setView( new L.LatLng( OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE), OSRM.DEFAULTS.ZOOM_LEVEL);
|
||||
map.on('zoomend', function(e) { getRoute(OSRM.FULL_DESCRIPTION); });
|
||||
map.on('contextmenu', function(e) {});
|
||||
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) {});
|
||||
|
||||
// click on map to set source and target nodes
|
||||
map.on('click', function(e) {
|
||||
if( !my_markers.route[0] || my_markers.route[0].label != OSRM.SOURCE_MARKER_LABEL) {
|
||||
onclickGeocoderResult("source", e.latlng.lat, e.latlng.lng, true, false );
|
||||
OSRM.G.map.on('click', function(e) {
|
||||
if( !OSRM.G.markers.hasSource() ) {
|
||||
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
|
||||
var positions = [];
|
||||
var destination = undefined;
|
||||
var destination_name = undefined;
|
||||
var zoom = null;
|
||||
var center = null;
|
||||
var destination = null;
|
||||
var destination_name = null;
|
||||
|
||||
// parse input
|
||||
var splitted_url = called_url.split('&');
|
||||
@@ -201,13 +211,28 @@ function checkURL(){
|
||||
else if(name_val[0] == 'destname') {
|
||||
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
|
||||
if( destination != undefined ) {
|
||||
onclickGeocoderResult("target", destination.lat, destination.lng, (destination_name == undefined) );
|
||||
if( destination_name != 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;
|
||||
}
|
||||
|
||||
@@ -215,23 +240,27 @@ function checkURL(){
|
||||
if( positions != []) {
|
||||
// draw via points
|
||||
if( positions.length > 0) {
|
||||
onclickGeocoderResult("source", positions[0].lat, positions[0].lng, true, false );
|
||||
//my_markers.setSource( positions[0] );
|
||||
OSRM.G.markers.setSource( positions[0] );
|
||||
updateAddress( OSRM.C.SOURCE_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
|
||||
}
|
||||
if(positions.length > 1) {
|
||||
onclickGeocoderResult("target", positions[positions.length-1].lat, positions[positions.length-1].lng, true, false );
|
||||
//my_markers.setTarget( positions[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++)
|
||||
my_markers.setVia( i-1, positions[i] );
|
||||
for(var i=0; i<my_markers.route.length;i++)
|
||||
my_markers.route[i].show();
|
||||
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
|
||||
var bounds = new L.LatLngBounds( positions );
|
||||
map.fitBounds( bounds );
|
||||
// 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.FULL_DESCRIPTION);
|
||||
getRoute(OSRM.C.FULL_DESCRIPTION);
|
||||
}
|
||||
}
|
||||
|
||||
+103
-93
@@ -20,20 +20,22 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
// [TODO: major refactoring scheduled]
|
||||
|
||||
// some variables
|
||||
var my_route = undefined;
|
||||
var my_markers = undefined;
|
||||
OSRM.GLOBALS.route = null;
|
||||
OSRM.GLOBALS.markers = null;
|
||||
|
||||
OSRM.NO_DESCRIPTION = 0;
|
||||
OSRM.FULL_DESCRIPTION = 1;
|
||||
OSRM.dragging = false;
|
||||
OSRM.pending = false;
|
||||
OSRM.pendingTimer = undefined;
|
||||
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() {
|
||||
my_route = new OSRM.Route();
|
||||
my_markers = new OSRM.Markers();
|
||||
OSRM.G.route = new OSRM.Route();
|
||||
OSRM.G.markers = new OSRM.Markers();
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +49,7 @@ function timeoutRouteSimple() {
|
||||
}
|
||||
function timeoutRoute() {
|
||||
showNoRouteGeometry();
|
||||
my_route.hideUnnamedRoute();
|
||||
OSRM.G.route.hideUnnamedRoute();
|
||||
showNoRouteDescription();
|
||||
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)
|
||||
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;
|
||||
|
||||
if( response.status == 207) {
|
||||
@@ -69,9 +71,9 @@ function showRouteSimple(response) {
|
||||
updateHints(response);
|
||||
|
||||
// // TODO: hack to process final drag event, if it was fenced, but we are still dragging (alternative approach)
|
||||
// if(OSRM.pending) {
|
||||
// clearTimeout(OSRM.pendingTimer);
|
||||
// OSRM.pendingTimer = setTimeout(timeoutDrag,100);
|
||||
// if(OSRM.G.pending) {
|
||||
// clearTimeout(OSRM.G.pendingTimer);
|
||||
// OSRM.G.pendingTimer = setTimeout(timeoutDrag,100);
|
||||
// }
|
||||
}
|
||||
function showRoute(response) {
|
||||
@@ -80,7 +82,7 @@ function showRoute(response) {
|
||||
|
||||
if(response.status == 207) {
|
||||
showNoRouteGeometry();
|
||||
my_route.hideUnnamedRoute();
|
||||
OSRM.G.route.hideUnnamedRoute();
|
||||
showNoRouteDescription();
|
||||
document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("NO_ROUTE_FOUND")+".<p>";
|
||||
} else {
|
||||
@@ -96,13 +98,13 @@ function showRoute(response) {
|
||||
// show route geometry
|
||||
function showNoRouteGeometry() {
|
||||
var positions = [];
|
||||
for(var i=0; i<my_markers.route.length;i++)
|
||||
positions.push( my_markers.route[i].getPosition() );
|
||||
for(var i=0; i<OSRM.G.markers.route.length;i++)
|
||||
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) {
|
||||
via_points = response.via_points.slice(0);
|
||||
OSRM.G.via_points = response.via_points.slice(0);
|
||||
|
||||
var geometry = decodeRouteGeometry(response.route_geometry, 5);
|
||||
|
||||
@@ -110,20 +112,22 @@ function showRouteGeometry(response) {
|
||||
for( var i=0; i < geometry.length; i++) {
|
||||
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)
|
||||
function onClickRouteDescription(geometry_index) {
|
||||
var positions = my_route.getPositions();
|
||||
var positions = OSRM.G.route.getPositions();
|
||||
|
||||
my_markers.highlight.setPosition( positions[geometry_index] );
|
||||
my_markers.highlight.show();
|
||||
my_markers.highlight.centerView();
|
||||
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){
|
||||
OSRM.JSONP.call(OSRM.DEFAULTS.HOST_SHORTENER_URL+src+'&jsonp=showRouteLink', showRouteLink, showRouteLink_TimeOut, 2000, 'shortener');
|
||||
src += '&z='+ OSRM.G.map.getZoom() + '¢er=' + 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){
|
||||
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) {
|
||||
// compute query string
|
||||
var query_string = '?z='+ map.getZoom();
|
||||
for(var i=0; i<my_markers.route.length; i++)
|
||||
query_string += '&loc=' + my_markers.route[i].getLat() + ',' + my_markers.route[i].getLng();
|
||||
var query_string = '?rebuild=1';
|
||||
for(var i=0; i<OSRM.G.markers.route.length; i++)
|
||||
query_string += '&loc=' + OSRM.G.markers.route[i].getLat() + ',' + OSRM.G.markers.route[i].getLng();
|
||||
|
||||
// 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
|
||||
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
|
||||
var route_desc = "";
|
||||
@@ -227,7 +231,7 @@ function showNoRouteDescription() {
|
||||
function showRouteNonames(response) {
|
||||
// do not display unnamed streets?
|
||||
if( document.getElementById('option-highlight-nonames').checked == false) {
|
||||
my_route.hideUnnamedRoute();
|
||||
OSRM.G.route.hideUnnamedRoute();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -261,7 +265,7 @@ function showRouteNonames(response) {
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
||||
// if source or target are not set -> hide route
|
||||
if( my_markers.route.length < 2 ) {
|
||||
my_route.hideRoute();
|
||||
if( OSRM.G.markers.route.length < 2 ) {
|
||||
OSRM.G.route.hideRoute();
|
||||
return;
|
||||
}
|
||||
|
||||
// prepare JSONP call
|
||||
var type = undefined;
|
||||
var callback = undefined;
|
||||
var timeout = undefined;
|
||||
var type = null;
|
||||
var callback = null;
|
||||
var timeout = null;
|
||||
|
||||
var source = OSRM.DEFAULTS.HOST_ROUTING_URL;
|
||||
source += '?z=' + map.getZoom() + '&output=json' + '&geomformat=cmp';
|
||||
if(my_markers.checksum)
|
||||
source += '&checksum=' + my_markers.checksum;
|
||||
for(var i=0; i<my_markers.route.length; i++) {
|
||||
source += '&loc=' + my_markers.route[i].getLat() + ',' + my_markers.route[i].getLng();
|
||||
if( my_markers.route[i].hint)
|
||||
source += '&hint=' + my_markers.route[i].hint;
|
||||
source += '?z=' + OSRM.G.map.getZoom() + '&output=json' + '&geomformat=cmp';
|
||||
if(OSRM.G.markers.checksum)
|
||||
source += '&checksum=' + OSRM.G.markers.checksum;
|
||||
for(var i=0; i<OSRM.G.markers.route.length; i++) {
|
||||
source += '&loc=' + OSRM.G.markers.route[i].getLat() + ',' + OSRM.G.markers.route[i].getLng();
|
||||
if( OSRM.G.markers.route[i].hint)
|
||||
source += '&hint=' + OSRM.G.markers.route[i].hint;
|
||||
}
|
||||
|
||||
// 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
|
||||
if(called == false && !do_description) {
|
||||
clearTimeout(OSRM.pendingTimer);
|
||||
OSRM.pendingTimer = setTimeout(timeoutDrag,OSRM.DEFAULTS.JSONP_TIMEOUT);
|
||||
clearTimeout(OSRM.G.pendingTimer);
|
||||
OSRM.G.pendingTimer = setTimeout(timeoutDrag,OSRM.DEFAULTS.JSONP_TIMEOUT);
|
||||
}
|
||||
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) {
|
||||
// OSRM.pending = true;
|
||||
// OSRM.G.pending = true;
|
||||
// } else {
|
||||
// clearTimeout(OSRM.pendingTimer);
|
||||
// OSRM.pending = false;
|
||||
// clearTimeout(OSRM.G.pendingTimer);
|
||||
// OSRM.G.pending = false;
|
||||
// }
|
||||
}
|
||||
function timeoutDrag() {
|
||||
my_markers.route[OSRM.dragid].hint = undefined;
|
||||
getRoute(OSRM.NO_DESCRIPTION);
|
||||
OSRM.G.markers.route[OSRM.G.dragid].hint = null;
|
||||
getRoute(OSRM.C.NO_DESCRIPTION);
|
||||
}
|
||||
|
||||
|
||||
@@ -361,27 +365,22 @@ function decodeRouteGeometry(encoded, precision) {
|
||||
// update hints of all markers
|
||||
function updateHints(response) {
|
||||
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++)
|
||||
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() {
|
||||
var positions = my_route.getPositions();
|
||||
var positions = OSRM.G.route.getPositions();
|
||||
|
||||
my_markers.route[0].setPosition( positions[0] );
|
||||
my_markers.route[my_markers.route.length-1].setPosition( positions[positions.length-1] );
|
||||
for(var i=0; i<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[0].setPosition( positions[0] );
|
||||
OSRM.G.markers.route[OSRM.G.markers.route.length-1].setPosition( positions[positions.length-1] );
|
||||
for(var i=0; i<OSRM.G.via_points.length; i++)
|
||||
OSRM.G.markers.route[i+1].setPosition( new L.LatLng(OSRM.G.via_points[i][0], OSRM.G.via_points[i][1]) );
|
||||
|
||||
// updateLocation( "source" );
|
||||
// updateLocation( "target" );
|
||||
|
||||
//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");
|
||||
updateAddress(OSRM.C.SOURCE_LABEL);
|
||||
updateAddress(OSRM.C.TARGET_LABEL);
|
||||
}
|
||||
|
||||
// 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 second 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 sixth 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-target-name').value = "";
|
||||
|
||||
my_route.hideAll();
|
||||
my_markers.removeAll();
|
||||
my_markers.highlight.hide();
|
||||
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();
|
||||
OSRM.JSONP.reset();
|
||||
}
|
||||
|
||||
// click: button "reverse"
|
||||
@@ -443,27 +442,27 @@ function reverseRouting() {
|
||||
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') );
|
||||
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(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') );
|
||||
} 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') );
|
||||
|
||||
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') );
|
||||
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( my_route.isShown() ) {
|
||||
getRoute(OSRM.FULL_DESCRIPTION);
|
||||
my_markers.highlight.hide();
|
||||
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 = "";
|
||||
@@ -471,10 +470,21 @@ function reverseRouting() {
|
||||
}
|
||||
|
||||
// click: button "show"
|
||||
function centerMarker(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 ) {
|
||||
my_markers.route[0].centerView();
|
||||
} 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();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
+8
-8
@@ -16,7 +16,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// 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)
|
||||
@@ -24,7 +24,7 @@ function findNearestRouteSegment( new_via ) {
|
||||
var min_dist = Number.MAX_VALUE;
|
||||
var min_index = undefined;
|
||||
|
||||
var positions = my_route.getPositions();
|
||||
var positions = OSRM.G.route.getPositions();
|
||||
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);
|
||||
if( dist < min_dist) {
|
||||
@@ -43,10 +43,10 @@ function findViaPosition( new_via_position ) {
|
||||
var nearest_index = findNearestRouteSegment( new_via_position );
|
||||
|
||||
// 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();
|
||||
for(var i=0; i<via_points.length; i++) {
|
||||
via_index[i] = findNearestRouteSegment( new L.LatLng(via_points[i][0], via_points[i][1]) );
|
||||
for(var i=0; i<OSRM.G.via_points.length; i++) {
|
||||
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) {
|
||||
new_via_index = i;
|
||||
break;
|
||||
@@ -54,10 +54,10 @@ function findViaPosition( new_via_position ) {
|
||||
}
|
||||
|
||||
// add via node
|
||||
var index = my_markers.setVia(new_via_index, new_via_position);
|
||||
my_markers.route[index].show();
|
||||
var index = OSRM.G.markers.setVia(new_via_index, new_via_position);
|
||||
OSRM.G.markers.route[index].show();
|
||||
|
||||
getRoute(OSRM.FULL_DESCRIPTION);
|
||||
getRoute(OSRM.C.FULL_DESCRIPTION);
|
||||
|
||||
return new_via_index;
|
||||
}
|
||||
Reference in New Issue
Block a user