moved all variables/objects to OSRM namespace
This commit is contained in:
parent
d51aee4fbe
commit
13126ac0c1
@ -34,11 +34,11 @@ OSRM.Marker = function( label, style, position ) {
|
||||
};
|
||||
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 ) {
|
||||
@ -61,9 +61,9 @@ isShown: function() {
|
||||
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);
|
||||
zoom = OSRM.G.map.getZoom();
|
||||
//OSRM.G.map.setView( new L.LatLng( this.position.lat, this.position.lng-0.02), zoom); // dirty hack
|
||||
OSRM.G.map.setView( new L.LatLng( this.position.lat, this.position.lng), zoom);
|
||||
},
|
||||
toString: function() {
|
||||
return "OSRM.Marker: \""+this.label+"\", "+this.position+")";
|
||||
@ -102,57 +102,57 @@ 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.CONSTANTS.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);
|
||||
if(OSRM.GLOBALS.dragging == true) // TODO: hack that deals with drag events after dragend event
|
||||
getRoute(OSRM.CONSTANTS.NO_DESCRIPTION);
|
||||
else
|
||||
getRoute(OSRM.FULL_DESCRIPTION);
|
||||
getRoute(OSRM.CONSTANTS.FULL_DESCRIPTION);
|
||||
|
||||
updateLocation( this.parent.label );
|
||||
},
|
||||
onDragStart: function(e) {
|
||||
OSRM.dragging = true;
|
||||
OSRM.GLOBALS.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;
|
||||
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();
|
||||
OSRM.G.markers.highlight.hide();
|
||||
if (OSRM.G.route.isShown()) {
|
||||
OSRM.G.route.showOldRoute();
|
||||
}
|
||||
|
||||
updateLocation( this.parent.label );
|
||||
},
|
||||
onDragEnd: function(e) {
|
||||
getRoute(OSRM.FULL_DESCRIPTION);
|
||||
if (my_route.isShown()) {
|
||||
my_route.hideOldRoute();
|
||||
my_route.hideUnnamedRoute();
|
||||
getRoute(OSRM.CONSTANTS.FULL_DESCRIPTION);
|
||||
if (OSRM.G.route.isShown()) {
|
||||
OSRM.G.route.hideOldRoute();
|
||||
OSRM.G.route.hideUnnamedRoute();
|
||||
}
|
||||
OSRM.dragging = false;
|
||||
OSRM.GLOBALS.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) {
|
||||
if(this.parent.label == OSRM.CONSTANTS.SOURCE_LABEL)
|
||||
updateReverseGeocoder(OSRM.CONSTANTS.SOURCE_LABEL);
|
||||
else if(this.parent.label == OSRM.CONSTANTS.TARGET_LABEL)
|
||||
updateReverseGeocoder(OSRM.CONSTANTS.TARGET_LABEL);
|
||||
}
|
||||
},
|
||||
toString: function() {
|
||||
@ -181,18 +181,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.CONSTANTS.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.CONSTANTS.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.CONSTANTS.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.CONSTANTS.TARGET_LABEL, {draggable:true,icon:OSRM.icons['marker-target']}, position));
|
||||
return this.route.length-1;
|
||||
},
|
||||
setVia: function(id, position) {
|
||||
@ -200,7 +200,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.CONSTANTS.VIA_LABEL, {draggable:true,icon:OSRM.icons['marker-via']}, position));
|
||||
return id+1;
|
||||
},
|
||||
removeMarker: function(id) {
|
||||
@ -208,9 +208,9 @@ 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.CONSTANTS.SOURCE_LABEL )
|
||||
this.removeVias();
|
||||
else if( id == this.route.length-1 && this.route[ this.route.length-1 ].label == OSRM.TARGET_MARKER_LABEL ) {
|
||||
else if( id == this.route.length-1 && this.route[ this.route.length-1 ].label == OSRM.CONSTANTS.TARGET_LABEL ) {
|
||||
this.removeVias();
|
||||
id = this.route.length-1;
|
||||
}
|
||||
@ -219,12 +219,12 @@ removeMarker: function(id) {
|
||||
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.CONSTANTS.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.CONSTANTS.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() {
|
||||
|
@ -23,6 +23,8 @@ OSRM.VERSION = '0.1.1';
|
||||
OSRM.CONSTANTS = {};
|
||||
OSRM.DEFAULTS = {};
|
||||
OSRM.GLOBALS = {};
|
||||
OSRM.G = OSRM.GLOBALS; // abbreviations
|
||||
OSRM.C = OSRM.CONSTANTS;
|
||||
|
||||
|
||||
// [convenience function] declare one class to be a subclass of another class
|
||||
|
@ -21,6 +21,8 @@ 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/',
|
||||
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,
|
||||
@ -28,5 +30,6 @@ OSRM.DEFAULTS = {
|
||||
ONLOAD_LONGITUDE: 10.10,
|
||||
ONLOAD_SOURCE: "",
|
||||
ONLOAD_TARGET: "",
|
||||
LANGUAGE: "en"
|
||||
LANGUAGE: "en",
|
||||
GEOCODER_BOUNDS: '&bounded=1&viewbox=-27.0,72.0,46.0,36.0'
|
||||
};
|
||||
|
@ -20,26 +20,26 @@ 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";
|
||||
|
||||
|
||||
// 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);
|
||||
if (marker_id == OSRM.CONSTANTS.SOURCE_LABEL && OSRM.G.markers.route[0].dirty_move == true ) {
|
||||
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.CONSTANTS.TARGET_LABEL && OSRM.G.markers.route[OSRM.G.markers.route.length-1].dirty_move == 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// process input request and call geocoder if needed
|
||||
function callGeocoder(marker_id, query) {
|
||||
if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.hasSource() && my_markers.route[0].dirty_move == false && my_markers.route[0].dirty_type == false)
|
||||
if (marker_id == OSRM.CONSTANTS.SOURCE_LABEL && OSRM.G.markers.hasSource() && OSRM.G.markers.route[0].dirty_move == false && OSRM.G.markers.route[0].dirty_type == false)
|
||||
return;
|
||||
if (marker_id == OSRM.TARGET_MARKER_LABEL && my_markers.hasTarget() && my_markers.route[my_markers.route.length-1].dirty_move == false && my_markers.route[my_markers.route.length-1].dirty_type == false)
|
||||
if (marker_id == OSRM.CONSTANTS.TARGET_LABEL && OSRM.G.markers.hasTarget() && OSRM.G.markers.route[OSRM.G.markers.route.length-1].dirty_move == false && OSRM.G.markers.route[OSRM.G.markers.route.length-1].dirty_type == false)
|
||||
return;
|
||||
if(query=="")
|
||||
return;
|
||||
@ -52,12 +52,12 @@ function callGeocoder(marker_id, query) {
|
||||
}
|
||||
|
||||
//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" );
|
||||
if (marker_id == OSRM.CONSTANTS.SOURCE_LABEL) {
|
||||
var call = OSRM.DEFAULTS.HOST_GEOCODER_URL + "?format=json" + OSRM.DEFAULTS.GEOCODER_BOUNDS + "&q=" + query;
|
||||
OSRM.JSONP.call( call, showGeocoderResults_Source, showGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "geocoder_source" );
|
||||
} else if (marker_id == OSRM.CONSTANTS.TARGET_LABEL) {
|
||||
var call = OSRM.DEFAULTS.HOST_GEOCODER_URL + "?format=json" + OSRM.DEFAULTS.GEOCODER_BOUNDS + "&q=" + query;
|
||||
OSRM.JSONP.call( call, showGeocoderResults_Target, showGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "geocoder_target" );
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,10 +65,10 @@ function callGeocoder(marker_id, query) {
|
||||
// helper function for clicks on geocoder search results
|
||||
function onclickGeocoderResult(marker_id, lat, lon, do_reverse_geocode, zoom ) {
|
||||
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.CONSTANTS.SOURCE_LABEL )
|
||||
index = OSRM.G.markers.setSource( new L.LatLng(lat, lon) );
|
||||
else if( marker_id == OSRM.CONSTANTS.TARGET_LABEL )
|
||||
index = OSRM.G.markers.setTarget( new L.LatLng(lat, lon) );
|
||||
else
|
||||
index = -1; // via nodes not yet implemented
|
||||
|
||||
@ -77,19 +77,19 @@ function onclickGeocoderResult(marker_id, lat, lon, do_reverse_geocode, zoom ) {
|
||||
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);
|
||||
OSRM.G.markers.route[index].show();
|
||||
if( !OSRM.G.markers.route[index].dirty_move || OSRM.G.markers.route[index].dirty_type )
|
||||
OSRM.G.markers.route[index].centerView(zoom);
|
||||
getRoute(OSRM.CONSTANTS.FULL_DESCRIPTION);
|
||||
|
||||
my_markers.route[index].dirty_move = false;
|
||||
my_markers.route[index].dirty_type = false;
|
||||
OSRM.G.markers.route[index].dirty_move = false;
|
||||
OSRM.G.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_Source(response) { showGeocoderResults(OSRM.CONSTANTS.SOURCE_LABEL, response); }
|
||||
function showGeocoderResults_Target(response) { showGeocoderResults(OSRM.CONSTANTS.TARGET_LABEL, response); }
|
||||
function showGeocoderResults(marker_id, response) {
|
||||
if(response){
|
||||
if(response.length == 0) {
|
||||
@ -125,9 +125,9 @@ function showGeocoderResults(marker_id, response) {
|
||||
}
|
||||
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.CONSTANTS.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.CONSTANTS.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>";
|
||||
@ -139,35 +139,34 @@ 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';
|
||||
|
||||
//update reverse geocoder informatiopn in input boxes
|
||||
function updateReverseGeocoder(marker_id) {
|
||||
if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.hasSource()) { //&& 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()) { //&& 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);
|
||||
if (marker_id == OSRM.CONSTANTS.SOURCE_LABEL && OSRM.G.markers.hasSource()) { //&& OSRM.G.markers.route[0].dirty == true ) {
|
||||
//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(OSRM.CONSTANTS.SOURCE_LABEL, OSRM.G.markers.route[0].getPosition().lat, OSRM.G.markers.route[0].getPosition().lng);
|
||||
} else if (marker_id == OSRM.CONSTANTS.TARGET_LABEL && OSRM.G.markers.hasTarget()) { //&& OSRM.G.markers.route[OSRM.G.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);
|
||||
callReverseGeocoder(OSRM.CONSTANTS.TARGET_LABEL, OSRM.G.markers.route[OSRM.G.markers.route.length-1].getPosition().lat, OSRM.G.markers.route[OSRM.G.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" );
|
||||
if (marker_id == OSRM.CONSTANTS.SOURCE_LABEL) {
|
||||
var call = OSRM.DEFAULTS.HOST_REVERSE_GEOCODER_URL + "?format=json" + "&lat=" + lat + "&lon=" + lon;
|
||||
OSRM.JSONP.call( call, showReverseGeocoderResults_Source, showReverseGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "reverse_geocoder_source" );
|
||||
} else if (marker_id == OSRM.CONSTANTS.TARGET_LABEL) {
|
||||
var call = OSRM.DEFAULTS.HOST_REVERSE_GEOCODER_URL + "?format=json" + "&lat=" + lat + "&lon=" + lon;
|
||||
OSRM.JSONP.call( call, 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_Source(response) { showReverseGeocoderResults(OSRM.CONSTANTS.SOURCE_LABEL, response); }
|
||||
function showReverseGeocoderResults_Target(response) { showReverseGeocoderResults(OSRM.CONSTANTS.TARGET_LABEL, response); }
|
||||
function showReverseGeocoderResults(marker_id, response) {
|
||||
//OSRM.debug.log("[inner] reverse geocoder");
|
||||
if(response){
|
||||
@ -191,14 +190,14 @@ function showReverseGeocoderResults(marker_id, response) {
|
||||
if( address == "" )
|
||||
return;
|
||||
|
||||
if(marker_id == OSRM.SOURCE_MARKER_LABEL) {
|
||||
if(marker_id == OSRM.CONSTANTS.SOURCE_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) {
|
||||
OSRM.G.markers.route[0].dirty_move = false;
|
||||
OSRM.G.markers.route[0].dirty_type = false;
|
||||
} else if(marker_id == OSRM.CONSTANTS.TARGET_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;
|
||||
OSRM.G.markers.route[OSRM.G.markers.route.length-1].dirty_move = false;
|
||||
OSRM.G.markers.route[OSRM.G.markers.route.length-1].dirty_type = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -88,13 +88,13 @@ 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.hasSource() ) 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="if( OSRM.G.markers.hasSource() ) OSRM.G.markers.route[0].dirty_type = true;" onblur="callGeocoder(OSRM.CONSTANTS.SOURCE_LABEL, document.getElementById('input-source-name').value);" onkeypress="if(event.keyCode==13) {callGeocoder(OSRM.CONSTANTS.SOURCE_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>
|
||||
</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.hasTarget() ) 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="if( OSRM.G.markers.route.hasTarget() ) OSRM.G.markers.route[OSRM.G.markers.route.length-1].dirty_type = true;" onblur="callGeocoder(OSRM.CONSTANTS.TARGET_LABEL, document.getElementById('input-target-name').value);" onkeypress="if(event.keyCode==13) {callGeocoder(OSRM.CONSTANTS.TARGET_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>
|
||||
</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.CONSTANTS.FULL_DESCRIPTION)" /><span id="gui-option-highlight-nonames-label">Unbenannte Straßen hervorheben</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -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-0.02), 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,23 +144,23 @@ 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.CONSTANTS.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.hasSource() )
|
||||
onclickGeocoderResult("source", e.latlng.lat, e.latlng.lng, true, false );
|
||||
else if( !my_markers.hasTarget() )
|
||||
onclickGeocoderResult("target", e.latlng.lat, e.latlng.lng, true, false );
|
||||
OSRM.G.map.on('click', function(e) {
|
||||
if( !OSRM.G.markers.hasSource() )
|
||||
onclickGeocoderResult(OSRM.CONSTANTS.SOURCE_LABEL, e.latlng.lat, e.latlng.lng, true, false );
|
||||
else if( !OSRM.G.markers.hasTarget() )
|
||||
onclickGeocoderResult(OSRM.CONSTANTS.TARGET_LABEL, e.latlng.lat, e.latlng.lng, true, false );
|
||||
} );
|
||||
}
|
||||
|
||||
@ -216,7 +217,7 @@ function checkURL(){
|
||||
|
||||
// case 1: destination given
|
||||
if( destination != undefined ) {
|
||||
onclickGeocoderResult("target", destination.lat, destination.lng, (destination_name == undefined) );
|
||||
onclickGeocoderResult(OSRM.CONSTANTS.TARGET_LABEL, destination.lat, destination.lng, (destination_name == undefined) );
|
||||
if( destination_name != undefined )
|
||||
document.getElementById("input-target-name").value = destination_name;
|
||||
return;
|
||||
@ -226,27 +227,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] );
|
||||
onclickGeocoderResult(OSRM.CONSTANTS.SOURCE_LABEL, positions[0].lat, positions[0].lng, true, false );
|
||||
//OSRM.G.markers.setSource( positions[0] );
|
||||
}
|
||||
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] );
|
||||
onclickGeocoderResult(OSRM.CONSTANTS.TARGET_LABEL, positions[positions.length-1].lat, positions[positions.length-1].lng, true, false );
|
||||
//OSRM.G.markers.setTarget( positions[positions.length-1] );
|
||||
}
|
||||
for(var i=1; i<positions.length-1;i++)
|
||||
my_markers.setVia( i-1, positions[i] );
|
||||
for(var i=0; i<my_markers.route.length;i++)
|
||||
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 (support for old links) / move to given view (new behaviour)
|
||||
if(zoom == null || center == null) {
|
||||
var bounds = new L.LatLngBounds( positions );
|
||||
map.fitBounds( bounds );
|
||||
OSRM.G.map.fitBounds( bounds );
|
||||
} else {
|
||||
map.setView(center, zoom);
|
||||
OSRM.G.map.setView(center, zoom);
|
||||
}
|
||||
|
||||
// compute route
|
||||
getRoute(OSRM.FULL_DESCRIPTION);
|
||||
getRoute(OSRM.CONSTANTS.FULL_DESCRIPTION);
|
||||
}
|
||||
}
|
||||
|
@ -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.GLOBALS.dragid = null;
|
||||
OSRM.GLOBALS.dragging = false;
|
||||
OSRM.GLOBALS.pending = false;
|
||||
OSRM.GLOBALS.pendingTimer = undefined;
|
||||
|
||||
|
||||
// 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>";
|
||||
}
|
||||
@ -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.GLOBALS.pending) {
|
||||
// clearTimeout(OSRM.GLOBALS.pendingTimer);
|
||||
// OSRM.GLOBALS.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,17 +112,17 @@ 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();
|
||||
}
|
||||
function onClickCreateShortcut(src){
|
||||
OSRM.JSONP.call(OSRM.DEFAULTS.HOST_SHORTENER_URL+src+'&jsonp=showRouteLink', showRouteLink, showRouteLink_TimeOut, 2000, 'shortener');
|
||||
@ -133,10 +135,10 @@ function showRouteLink_TimeOut(){
|
||||
}
|
||||
function showRouteDescription(response) {
|
||||
// compute query string
|
||||
var query_string = '?z='+ map.getZoom();
|
||||
query_string += '¢er=' + map.getCenter().lat + ',' + map.getCenter().lng;
|
||||
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 = '?z='+ OSRM.G.map.getZoom();
|
||||
query_string += '¢er=' + OSRM.G.map.getCenter().lat + ',' + OSRM.G.map.getCenter().lng;
|
||||
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>';
|
||||
@ -228,7 +230,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;
|
||||
}
|
||||
|
||||
@ -262,7 +264,7 @@ function showRouteNonames(response) {
|
||||
}
|
||||
|
||||
// display unnamed streets
|
||||
my_route.showUnnamedRoute(all_positions);
|
||||
OSRM.G.route.showUnnamedRoute(all_positions);
|
||||
}
|
||||
|
||||
|
||||
@ -272,8 +274,8 @@ 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;
|
||||
}
|
||||
|
||||
@ -283,13 +285,13 @@ function getRoute(do_description) {
|
||||
var timeout = undefined;
|
||||
|
||||
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
|
||||
@ -310,23 +312,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.GLOBALS.pendingTimer);
|
||||
OSRM.GLOBALS.pendingTimer = setTimeout(timeoutDrag,OSRM.DEFAULTS.JSONP_TIMEOUT);
|
||||
}
|
||||
else {
|
||||
clearTimeout(OSRM.pendingTimer);
|
||||
clearTimeout(OSRM.GLOBALS.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.GLOBALS.pending = true;
|
||||
// } else {
|
||||
// clearTimeout(OSRM.pendingTimer);
|
||||
// OSRM.pending = false;
|
||||
// clearTimeout(OSRM.GLOBALS.pendingTimer);
|
||||
// OSRM.GLOBALS.pending = false;
|
||||
// }
|
||||
}
|
||||
function timeoutDrag() {
|
||||
my_markers.route[OSRM.dragid].hint = undefined;
|
||||
getRoute(OSRM.NO_DESCRIPTION);
|
||||
OSRM.G.markers.route[OSRM.G.dragid].hint = undefined;
|
||||
getRoute(OSRM.CONSTANTS.NO_DESCRIPTION);
|
||||
}
|
||||
|
||||
|
||||
@ -362,27 +364,27 @@ 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" );
|
||||
// updateLocation( OSRM.CONSTANTS.SOURCE_LABEL );
|
||||
// updateLocation( OSRM.CONSTANTS.TARGET_LABEL );
|
||||
|
||||
//if(OSRM.dragid == 0 && my_markers.hasSource())
|
||||
updateReverseGeocoder("source");
|
||||
//else if(OSRM.dragid == my_markers.route.length-1 && my_markers.hasTarget())
|
||||
updateReverseGeocoder("target");
|
||||
//if(OSRM.G.dragid == 0 && OSRM.G.markers.hasSource())
|
||||
updateReverseGeocoder(OSRM.CONSTANTS.SOURCE_LABEL);
|
||||
//else if(OSRM.G.dragid == OSRM.G.markers.route.length-1 && OSRM.G.markers.hasTarget())
|
||||
updateReverseGeocoder(OSRM.CONSTANTS.TARGET_LABEL);
|
||||
}
|
||||
|
||||
// map driving instructions to icons
|
||||
@ -426,9 +428,9 @@ 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 = "";
|
||||
@ -444,27 +446,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.CONSTANTS.TARGET_LABEL) {
|
||||
OSRM.G.markers.route[0].label = OSRM.CONSTANTS.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.CONSTANTS.SOURCE_LABEL) {
|
||||
OSRM.G.markers.route[0].label = OSRM.CONSTANTS.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.CONSTANTS.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.CONSTANTS.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.CONSTANTS.FULL_DESCRIPTION);
|
||||
OSRM.G.markers.highlight.hide();
|
||||
} else {
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-headline').innerHTML = "";
|
||||
@ -473,9 +475,9 @@ function reverseRouting() {
|
||||
|
||||
// click: button "show"
|
||||
function centerMarker(marker_id) {
|
||||
if( marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.hasSource() && !my_markers.route[0].dirty_type ) {
|
||||
my_markers.route[0].centerView();
|
||||
} else if( marker_id == OSRM.TARGET_MARKER_LABEL && my_markers.hasTarget() && !my_markers.route[my_markers.route.length-1].dirty_type) {
|
||||
my_markers.route[my_markers.route.length-1].centerView();
|
||||
if( marker_id == OSRM.CONSTANTS.SOURCE_LABEL && OSRM.G.markers.hasSource() && !OSRM.G.markers.route[0].dirty_type ) {
|
||||
OSRM.G.markers.route[0].centerView();
|
||||
} else if( marker_id == OSRM.CONSTANTS.TARGET_LABEL && OSRM.G.markers.hasTarget() && !OSRM.G.markers.route[OSRM.G.markers.route.length-1].dirty_type) {
|
||||
OSRM.G.markers.route[OSRM.G.markers.route.length-1].centerView();
|
||||
}
|
||||
}
|
||||
|
@ -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.CONSTANTS.FULL_DESCRIPTION);
|
||||
|
||||
return new_via_index;
|
||||
}
|
Loading…
Reference in New Issue
Block a user