您可能只需要将每个阶段强制到不同的事件线程中,这可以通过几种方式实现。
window.setTimeout()
$("input#drawAllRoutes").click(function (e) {
console.log("drawAllRoutes: Start Drawing");
showWaitPanel(); // assumed to be synchronous.
window.setTimeout(function() {
...
//foreach routeElement add vector layer on map
...
hideWaitPanel(); // ok in same event thread unless vector rendering is itself asynchronous.
console.log("drawAllRoutes: Ok");
}, 0); // even with a timeout of zero seconds, the passed function will execute in a later event thread.
});
这里的净效应应该与使用
setTimeout()
showWaitPanel()
返回一个承诺,否则
showWaitPanel().then()
将抛出错误。所以你需要修改你的
显示等待面板()
作用
$("input#drawAllRoutes").click(function (e) {
console.log("drawAllRoutes: Start Drawing");
showWaitPanel().then(function() {
...
//foreach routeElement add vector layer on map
...
hideWaitPanel(); // ok in same event thread unless vector rendering is itself asynchronous.
console.log("drawAllRoutes: Ok");
});
});
TBH,在这里使用承诺是过分的。如果有效,我会使用
设置超时()
尽管它很丑陋。