zooming/switching to show unnamed roads will not rebuild the complete

driving directions,
pending JSONP calls can be cleared
This commit is contained in:
DennisSchiefer 2012-04-20 07:37:26 +02:00
parent eb3c2f560e
commit f3290ab64b
4 changed files with 52 additions and 26 deletions

View File

@ -52,7 +52,7 @@ init: function() {
document.getElementById("gui-options-toggle").onclick = OSRM.GUI.toggleOptions;
document.getElementById("open-josm").onclick = OSRM.RoutingGUI.openJOSM;
document.getElementById("open-osmbugs").onclick = OSRM.RoutingGUI.openOSMBugs;
document.getElementById("option-highlight-nonames").onclick = OSRM.Routing.getRoute;
document.getElementById("option-highlight-nonames").onclick = OSRM.Routing.getZoomRoute;
// gui after transition events
if( OSRM.Browser.FF3==-1 && OSRM.Browser.IE6_9==-1 ) {

View File

@ -18,7 +18,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
// OSRM JSONP call wrapper
// [wrapper for JSONP calls with DOM cleaning, fencing, timout handling]
xxx="test";
OSRM.JSONP = {
// storage to keep track of unfinished JSONP calls
@ -29,8 +29,8 @@ OSRM.JSONP = {
// default callback routines
late: function() { /*OSRM.debug.log("[jsonp] reply too late");*/ },
empty: function() { /*OSRM.debug.log("[jsonp] empty callback");*/ },
late: function() {},
empty: function() {},
// init JSONP call
@ -42,6 +42,7 @@ OSRM.JSONP = {
// wrap timeout function
OSRM.JSONP.timeouts[id] = function(response) {
console.log("timeout",id);
try {
timeout_function(response, parameters);
} finally {
@ -49,8 +50,6 @@ OSRM.JSONP = {
OSRM.JSONP.timeouts[id] = OSRM.JSONP.empty;
OSRM.JSONP.fences[id] = undefined; // clean fence
}
// OSRM.debug.log("[jsonp] timout handling: "+id);
};
// wrap callback function
@ -65,34 +64,37 @@ OSRM.JSONP = {
OSRM.JSONP.timeouts[id] = OSRM.JSONP.late;
OSRM.JSONP.fences[id] = undefined; // clean fence
}
// OSRM.JSONP.sum[id] += new Number( new Date() - OSRM.JSONP.durations[id] );
// OSRM.debug.log("[jsonp] response handling: "+id+" "+ (OSRM.JSONP.sum[id]/OSRM.JSONP.counter[id]).toFixed(2) );
};
// clean DOM (unfortunately, script elements cannot be reused by all browsers)
var jsonp = document.getElementById('jsonp_'+id);
if(jsonp)
jsonp.parentNode.removeChild(jsonp);
// clean DOM
//var jsonp = document.getElementById('jsonp_'+id);
//if(jsonp)
// jsonp.parentNode.removeChild(jsonp);
// add script to DOM
var script = document.createElement('script');
script.type = 'text/javascript';
script.id = 'jsonp_'+id;
script.src = source + "&json_callback=OSRM.JSONP.callbacks."+id + "&jsonp=OSRM.JSONP.callbacks."+id;
//script.id = 'jsonp_'+id;
script.src = source + "&json_callback=OSRM.JSONP.callbacks."+id + "&jsonp=console.log(xxx);OSRM.JSONP.callbacks."+id;
document.head.appendChild(script);
// start timeout timer
OSRM.JSONP.timers[id] = setTimeout(OSRM.JSONP.timeouts[id], timeout);
// if(!OSRM.JSONP.durations) { OSRM.JSONP.durations = {}; OSRM.JSONP.counter = {}; OSRM.JSONP.sum = {}; }
// if(OSRM.JSONP.counter[id]) OSRM.JSONP.counter[id]++; else {OSRM.JSONP.counter[id] = 1;OSRM.JSONP.sum[id] = 0;}
// OSRM.JSONP.durations[id] = new Date();
// OSRM.debug.log("[jsonp] init: "+id);
return true;
},
clear: function(id) {
clearTimeout(OSRM.JSONP.timers[id]); // clear timeout timer
OSRM.JSONP.callbacks[id] = OSRM.JSONP.empty; // clean functions
OSRM.JSONP.timeouts[id] = OSRM.JSONP.empty;
OSRM.JSONP.fences[id] = undefined; // clean fence
// clean DOM
var jsonp = document.getElementById('jsonp_'+id);
if(jsonp)
jsonp.parentNode.removeChild(jsonp);
},
// reset all data
reset: function() {
OSRM.JSONP.fences = {};

View File

@ -112,7 +112,12 @@ initPosition: function() {
},
// map event handlers
zoomed: function(e) { OSRM.Routing.getRoute(); },
zoomed: function(e) {
if(OSRM.G.dragging)
OSRM.Routing.getDragRoute();
else
OSRM.Routing.getZoomRoute();
},
contextmenu: function(e) {;},
mousemove: function(e) { OSRM.Via.drawDragMarker(e); },
click: function(e) {

View File

@ -25,7 +25,6 @@ OSRM.GLOBALS.markers = null;
OSRM.GLOBALS.dragging = null;
OSRM.GLOBALS.dragid = null;
OSRM.GLOBALS.pending = false;
OSRM.GLOBALS.pendingTimer = null;
OSRM.Routing = {
@ -53,7 +52,7 @@ timeoutRoute: function() {
showRouteSimple: function(response) {
if(!response)
return;
if( !OSRM.G.dragging ) // prevent simple routing when no longer dragging
if( !OSRM.G.dragging ) // prevent simple routing when not dragging (required as there can be drag events after a dragstop event!)
return;
if( response.status == 207) {
@ -66,7 +65,7 @@ showRouteSimple: function(response) {
OSRM.Routing._updateHints(response);
if(OSRM.G.pending)
OSRM.G.pendingTimer = setTimeout(OSRM.Routing.draggingTimeout,1);
setTimeout(OSRM.Routing.draggingTimeout,1);
},
showRoute: function(response) {
if(!response)
@ -87,6 +86,16 @@ showRoute: function(response) {
}
OSRM.Routing._updateHints(response);
},
showRouteZooming: function(response) {
if(!response)
return;
if(response.status != 207) {
OSRM.RoutingGeometry.show(response);
OSRM.RoutingNoNames.show(response);
}
OSRM.Routing._updateHints(response);
},
@ -100,9 +109,19 @@ getRoute: function() {
OSRM.G.route.hideRoute();
return;
}
OSRM.JSONP.clear('dragging');
OSRM.JSONP.clear('zooming');
OSRM.JSONP.clear('route');
OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=true', OSRM.Routing.showRoute, OSRM.Routing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'route');
},
getZoomRoute: function() {
if( OSRM.G.markers.route.length < 2 )
return;
OSRM.JSONP.clear('dragging');
OSRM.JSONP.clear('zooming');
OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=true', OSRM.Routing.showRouteZooming, OSRM.Routing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'zooming');
},
getDragRoute: function() {
OSRM.G.pending = !OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=false', OSRM.Routing.showRouteSimple, OSRM.Routing.timeoutRouteSimple, OSRM.DEFAULTS.JSONP_TIMEOUT, 'dragging');;
},