Leaflet mapquest路由何时完成渲染?

Leaflet mapquest路由何时完成渲染?,leaflet,mapquest,Leaflet,Mapquest,我正在使用带有传单的MapQuest地图。正在动态注入路由。将管线添加到地图时,完成渲染需要时间。 我想在渲染贴图时阻止屏幕。 是否有任何方法(mapquest API或传单事件)可以知道地图已准备好或已完成渲染,以便我可以停止屏幕阻塞 我用传单来增加路线。大概是这样的: function (locations) { const dir = MQ.routing.directions(); dir.route({ locations: locations }); comp.mqrou

我正在使用带有传单的MapQuest地图。正在动态注入路由。将管线添加到地图时,完成渲染需要时间。 我想在渲染贴图时阻止屏幕。 是否有任何方法(mapquest API或传单事件)可以知道地图已准备好或已完成渲染,以便我可以停止屏幕阻塞

我用传单来增加路线。大概是这样的:

function (locations) {
  const dir = MQ.routing.directions();
  dir.route({ locations: locations });
  comp.mqroute = MQ.routing.routeLayer({
    directions: dir,
    fitBounds: true,
    draggable: false,
  });
  comp.map.addLayer(comp.mqroute);
}

这是RTFM的一个例子

您在代码中使用
MQ.routing.directions
这一事实告诉我,您正在使用的是

通过阅读API文档,可以注意到一个
success
事件,我引用:

成功

从服务器检索路由数据并解压缩形状点时激发。[……]

我非常怀疑,您不需要知道何时呈现路由(意思是:当线路显示在屏幕上时),而需要知道何时完成路由的网络请求(这是花费最多时间的)。在屏幕上实际渲染线条的时间通常可以忽略不计,除非使用数千个线段(在douglas peucker自动简化之后)

我还非常怀疑这是一个问题,您试图解决的根本问题是当用户(重新)请求路由太快时的竞争条件,解决方案只是限制请求,而不是阻塞UI

如何使用此
success
事件,请参见MapQuest的:


这闻起来像是一种味道。首先,你为什么要屏蔽屏幕?另外,知道你是如何请求路由的也很好。有图书馆吗?传单插件?手动
fetch
requests?1。正如我前面提到的,地图绘制路线需要时间,我想防止用户单击屏幕上的任何其他按钮。2.我用传单来增加路线。类似这样的内容:函数(位置){const dir=MQ.routing.directions();dir.route({locations:locations});comp.mqroute=MQ.routing.routeLayer({directions:dir,fitBounds:true,draggable:false,});comp.map.addLayer(comp.mqroute);}
dir = MQ.routing.directions();

dir.on('success', function(data) {
     // ...
     // the code here will run once the route is ready
     // ...
  }