improved handling of dragging,

link to route gui improved,
JSONP can now take parameters
This commit is contained in:
DennisSchiefer 2012-03-18 17:42:05 +01:00
parent 4615b01fdf
commit fe6d854e11
5 changed files with 32 additions and 45 deletions

View File

@ -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;
@ -43,7 +43,7 @@ OSRM.JSONP = {
// wrap timeout function
OSRM.JSONP.timeouts[id] = function(response) {
try {
timeout_function(response);
timeout_function(response, parameters);
} finally {
OSRM.JSONP.callbacks[id] = OSRM.JSONP.late; // clean functions
OSRM.JSONP.timeouts[id] = OSRM.JSONP.empty;
@ -59,7 +59,7 @@ OSRM.JSONP = {
OSRM.JSONP.timers[id] = undefined;
try {
callback_function(response); // actual wrapped callback
callback_function(response, parameters); // actual wrapped callback
} finally {
OSRM.JSONP.callbacks[id] = OSRM.JSONP.empty; // clean functions
OSRM.JSONP.timeouts[id] = OSRM.JSONP.late;

View File

@ -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",
@ -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",

View File

@ -30,7 +30,7 @@ OSRM.Marker = function( label, style, position ) {
this.dirty_type = true;
this.shown = false;
this.hint = undefined;
this.hint = null;
};
OSRM.extend( OSRM.Marker,{
show: function() {
@ -44,7 +44,7 @@ hide: function() {
setPosition: function( position ) {
this.position = position;
this.marker.setLatLng( position );
this.hint = undefined;
this.hint = null;
},
getPosition: function() {
return this.position;
@ -113,19 +113,15 @@ onClick: function(e) {
OSRM.G.markers.highlight.hide();
},
onDrag: function(e) {
this.parent.dirty_move = true;
this.parent.setPosition( e.target.getLatLng() );
if(OSRM.G.dragging == true) // TODO: hack that deals with drag events after dragend event
getRoute(OSRM.C.NO_DESCRIPTION);
else
getRoute(OSRM.C.FULL_DESCRIPTION);
getRoute(OSRM.C.NO_DESCRIPTION);
updateLocation( this.parent.label );
},
onDragStart: function(e) {
OSRM.G.dragging = true;
this.parent.dirty_move = true;
// hack to store id of dragged marker
// 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;
@ -133,27 +129,20 @@ onDragStart: function(e) {
}
OSRM.G.markers.highlight.hide();
if (OSRM.G.route.isShown()) {
if (OSRM.G.route.isShown())
OSRM.G.route.showOldRoute();
}
updateLocation( this.parent.label );
},
onDragEnd: function(e) {
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.G.dragging = false;
updateLocation( this.parent.label );
if(OSRM.G.route.isShown()==false) {
if(this.parent.label == OSRM.C.SOURCE_LABEL)
updateReverseGeocoder(OSRM.C.SOURCE_LABEL);
else if(this.parent.label == OSRM.C.TARGET_LABEL)
updateReverseGeocoder(OSRM.C.TARGET_LABEL);
}
if(OSRM.G.route.isShown()==false)
updateReverseGeocoder(this.parent.label);
},
toString: function() {
return "OSRM.RouteMarker: \""+this.label+"\", "+this.position+")";

View File

@ -27,9 +27,9 @@ OSRM.CONSTANTS.VIA_LABEL = "via";
// update geo coordinates in input boxes
function updateLocation(marker_id) {
if (marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.route[0].dirty_move == true ) {
if (marker_id == OSRM.C.SOURCE_LABEL) {
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.route[OSRM.G.markers.route.length-1].dirty_move == true) {
} else if (marker_id == OSRM.C.TARGET_LABEL) {
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);
}
}

View File

@ -26,10 +26,10 @@ OSRM.GLOBALS.markers = null;
OSRM.CONSTANTS.NO_DESCRIPTION = 0;
OSRM.CONSTANTS.FULL_DESCRIPTION = 1;
OSRM.G.dragging = null;
OSRM.GLOBALS.dragid = null;
OSRM.GLOBALS.dragging = false;
OSRM.GLOBALS.pending = false;
OSRM.GLOBALS.pendingTimer = undefined;
OSRM.GLOBALS.pendingTimer = null;
// init routing data structures
@ -57,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) {
@ -126,6 +126,7 @@ function onClickRouteDescription(geometry_index) {
}
function onClickCreateShortcut(src){
OSRM.JSONP.call(OSRM.DEFAULTS.HOST_SHORTENER_URL+src+'&jsonp=showRouteLink', 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>]';
@ -141,10 +142,10 @@ function showRouteDescription(response) {
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 = "";
@ -280,9 +281,9 @@ function getRoute(do_description) {
}
// 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=' + OSRM.G.map.getZoom() + '&output=json' + '&geomformat=cmp';
@ -327,7 +328,7 @@ function getRoute(do_description) {
// }
}
function timeoutDrag() {
OSRM.G.markers.route[OSRM.G.dragid].hint = undefined;
OSRM.G.markers.route[OSRM.G.dragid].hint = null;
getRoute(OSRM.C.NO_DESCRIPTION);
}
@ -378,13 +379,8 @@ function snapRoute() {
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( OSRM.C.SOURCE_LABEL );
// updateLocation( OSRM.C.TARGET_LABEL );
//if(OSRM.G.dragid == 0 && OSRM.G.markers.hasSource())
updateReverseGeocoder(OSRM.C.SOURCE_LABEL);
//else if(OSRM.G.dragid == OSRM.G.markers.route.length-1 && OSRM.G.markers.hasTarget())
updateReverseGeocoder(OSRM.C.TARGET_LABEL);
updateReverseGeocoder(OSRM.C.SOURCE_LABEL);
updateReverseGeocoder(OSRM.C.TARGET_LABEL);
}
// map driving instructions to icons
@ -435,7 +431,7 @@ function resetRouting() {
document.getElementById('information-box').innerHTML = "";
document.getElementById('information-box-headline').innerHTML = "";
OSRM.JSONP.reset();
OSRM.JSONP.reset();
}
// click: button "reverse"