zooming/switching to show unnamed roads will not rebuild the complete
driving directions, pending JSONP calls can be cleared
This commit is contained in:
parent
eb3c2f560e
commit
f3290ab64b
@ -52,7 +52,7 @@ init: function() {
|
|||||||
document.getElementById("gui-options-toggle").onclick = OSRM.GUI.toggleOptions;
|
document.getElementById("gui-options-toggle").onclick = OSRM.GUI.toggleOptions;
|
||||||
document.getElementById("open-josm").onclick = OSRM.RoutingGUI.openJOSM;
|
document.getElementById("open-josm").onclick = OSRM.RoutingGUI.openJOSM;
|
||||||
document.getElementById("open-osmbugs").onclick = OSRM.RoutingGUI.openOSMBugs;
|
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
|
// gui after transition events
|
||||||
if( OSRM.Browser.FF3==-1 && OSRM.Browser.IE6_9==-1 ) {
|
if( OSRM.Browser.FF3==-1 && OSRM.Browser.IE6_9==-1 ) {
|
||||||
|
@ -18,7 +18,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
// OSRM JSONP call wrapper
|
// OSRM JSONP call wrapper
|
||||||
// [wrapper for JSONP calls with DOM cleaning, fencing, timout handling]
|
// [wrapper for JSONP calls with DOM cleaning, fencing, timout handling]
|
||||||
|
|
||||||
|
xxx="test";
|
||||||
OSRM.JSONP = {
|
OSRM.JSONP = {
|
||||||
|
|
||||||
// storage to keep track of unfinished JSONP calls
|
// storage to keep track of unfinished JSONP calls
|
||||||
@ -29,8 +29,8 @@ OSRM.JSONP = {
|
|||||||
|
|
||||||
|
|
||||||
// default callback routines
|
// default callback routines
|
||||||
late: function() { /*OSRM.debug.log("[jsonp] reply too late");*/ },
|
late: function() {},
|
||||||
empty: function() { /*OSRM.debug.log("[jsonp] empty callback");*/ },
|
empty: function() {},
|
||||||
|
|
||||||
|
|
||||||
// init JSONP call
|
// init JSONP call
|
||||||
@ -42,6 +42,7 @@ OSRM.JSONP = {
|
|||||||
|
|
||||||
// wrap timeout function
|
// wrap timeout function
|
||||||
OSRM.JSONP.timeouts[id] = function(response) {
|
OSRM.JSONP.timeouts[id] = function(response) {
|
||||||
|
console.log("timeout",id);
|
||||||
try {
|
try {
|
||||||
timeout_function(response, parameters);
|
timeout_function(response, parameters);
|
||||||
} finally {
|
} finally {
|
||||||
@ -49,8 +50,6 @@ OSRM.JSONP = {
|
|||||||
OSRM.JSONP.timeouts[id] = OSRM.JSONP.empty;
|
OSRM.JSONP.timeouts[id] = OSRM.JSONP.empty;
|
||||||
OSRM.JSONP.fences[id] = undefined; // clean fence
|
OSRM.JSONP.fences[id] = undefined; // clean fence
|
||||||
}
|
}
|
||||||
|
|
||||||
// OSRM.debug.log("[jsonp] timout handling: "+id);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// wrap callback function
|
// wrap callback function
|
||||||
@ -65,34 +64,37 @@ OSRM.JSONP = {
|
|||||||
OSRM.JSONP.timeouts[id] = OSRM.JSONP.late;
|
OSRM.JSONP.timeouts[id] = OSRM.JSONP.late;
|
||||||
OSRM.JSONP.fences[id] = undefined; // clean fence
|
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)
|
// clean DOM
|
||||||
var jsonp = document.getElementById('jsonp_'+id);
|
//var jsonp = document.getElementById('jsonp_'+id);
|
||||||
if(jsonp)
|
//if(jsonp)
|
||||||
jsonp.parentNode.removeChild(jsonp);
|
// jsonp.parentNode.removeChild(jsonp);
|
||||||
|
|
||||||
// add script to DOM
|
// add script to DOM
|
||||||
var script = document.createElement('script');
|
var script = document.createElement('script');
|
||||||
script.type = 'text/javascript';
|
script.type = 'text/javascript';
|
||||||
script.id = 'jsonp_'+id;
|
//script.id = 'jsonp_'+id;
|
||||||
script.src = source + "&json_callback=OSRM.JSONP.callbacks."+id + "&jsonp=OSRM.JSONP.callbacks."+id;
|
script.src = source + "&json_callback=OSRM.JSONP.callbacks."+id + "&jsonp=console.log(xxx);OSRM.JSONP.callbacks."+id;
|
||||||
document.head.appendChild(script);
|
document.head.appendChild(script);
|
||||||
|
|
||||||
// start timeout timer
|
// start timeout timer
|
||||||
OSRM.JSONP.timers[id] = setTimeout(OSRM.JSONP.timeouts[id], timeout);
|
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;
|
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 all data
|
||||||
reset: function() {
|
reset: function() {
|
||||||
OSRM.JSONP.fences = {};
|
OSRM.JSONP.fences = {};
|
||||||
|
@ -112,7 +112,12 @@ initPosition: function() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// map event handlers
|
// 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) {;},
|
contextmenu: function(e) {;},
|
||||||
mousemove: function(e) { OSRM.Via.drawDragMarker(e); },
|
mousemove: function(e) { OSRM.Via.drawDragMarker(e); },
|
||||||
click: function(e) {
|
click: function(e) {
|
||||||
|
@ -25,7 +25,6 @@ OSRM.GLOBALS.markers = null;
|
|||||||
OSRM.GLOBALS.dragging = null;
|
OSRM.GLOBALS.dragging = null;
|
||||||
OSRM.GLOBALS.dragid = null;
|
OSRM.GLOBALS.dragid = null;
|
||||||
OSRM.GLOBALS.pending = false;
|
OSRM.GLOBALS.pending = false;
|
||||||
OSRM.GLOBALS.pendingTimer = null;
|
|
||||||
|
|
||||||
|
|
||||||
OSRM.Routing = {
|
OSRM.Routing = {
|
||||||
@ -53,7 +52,7 @@ timeoutRoute: function() {
|
|||||||
showRouteSimple: function(response) {
|
showRouteSimple: function(response) {
|
||||||
if(!response)
|
if(!response)
|
||||||
return;
|
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;
|
return;
|
||||||
|
|
||||||
if( response.status == 207) {
|
if( response.status == 207) {
|
||||||
@ -66,7 +65,7 @@ showRouteSimple: function(response) {
|
|||||||
OSRM.Routing._updateHints(response);
|
OSRM.Routing._updateHints(response);
|
||||||
|
|
||||||
if(OSRM.G.pending)
|
if(OSRM.G.pending)
|
||||||
OSRM.G.pendingTimer = setTimeout(OSRM.Routing.draggingTimeout,1);
|
setTimeout(OSRM.Routing.draggingTimeout,1);
|
||||||
},
|
},
|
||||||
showRoute: function(response) {
|
showRoute: function(response) {
|
||||||
if(!response)
|
if(!response)
|
||||||
@ -87,6 +86,16 @@ showRoute: function(response) {
|
|||||||
}
|
}
|
||||||
OSRM.Routing._updateHints(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();
|
OSRM.G.route.hideRoute();
|
||||||
return;
|
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');
|
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() {
|
getDragRoute: function() {
|
||||||
OSRM.G.pending = !OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=false', OSRM.Routing.showRouteSimple, OSRM.Routing.timeoutRouteSimple, OSRM.DEFAULTS.JSONP_TIMEOUT, 'dragging');;
|
OSRM.G.pending = !OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=false', OSRM.Routing.showRouteSimple, OSRM.Routing.timeoutRouteSimple, OSRM.DEFAULTS.JSONP_TIMEOUT, 'dragging');;
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user