OpenLayers:如何检测地图视图是否已完全加载? [英] OpenLayers: How to detect the map view is completely loaded?

查看:1024
本文介绍了OpenLayers:如何检测地图视图是否已完全加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OpenLayers 3实现地图导出功能.

I'm implementing map exporting functionality using OpenLayers 3.

但是有一个问题:无法确定地图视图是否已完全加载或缺少一些图块.

But there is one problem: one cannot determine whether the map view is completely loaded or a few tiles is missing yet.

似乎没有这样的API或事件.最接近的是tileloadstart-tileloadend对.但是OpenLayers会异步加载磁贴,并且在磁贴实际加载之前不会触发tileloadstart-也就是说,在磁贴队列中排队的磁贴在实际加载之前不会触发事件.

It seems there is no such API or event. The close one is tileloadstart - tileloadend pair. But OpenLayers loads tiles asynchronously, and before the tile is actually loading the tileloadstart is not fired - that is, a tile that is queued in the tile queue does not fire the event before actually loading.

我能检测到地图视图已完全加载吗?

Hot can I detect the map view is completely loaded?

推荐答案

我最终成功实现了导出功能.下面是粗略的解释.

I eventually implemented the export function successfully. Below is the rough explanation.

  1. 使用ol.source.on()ol.source上注册tileloadstarttileloadendtileloaderror事件处理程序,并开始管理切片负载计数.
  2. 使用ol.Map.once()ol.Map上注册postcompose事件处理程序.
  3. 致电ol.Map.renderSync().这会触发图块加载,因此从现在开始如果没有图块加载,则意味着所有图块均已加载.
  4. postcompose事件处理程序上,使用event.context.canvas.toDataURL()event.context捕获地图内容,并使用event.frameState.postRenderFunctions.push()注册后期渲染功能(有点hacky).
  5. 在已注册的后期渲染功能上,检查切片负载计数(可由tileload*事件处理程序管理).如果计数不为零,则放弃捕获的内容.否则,捕获就完成了.
  6. tileloadendtileloaderror上,如果瓦片负载计数变为零,请从上面的步骤3重试.
  1. Register tileloadstart, tileloadend, tileloaderror event handlers on the ol.sources using ol.source.on(), and start managing the tile load count.
  2. Register postcompose event handlers on the ol.Map using ol.Map.once().
  3. call ol.Map.renderSync(). This triggers the tile loading, so from now if there is no tile loading, it will mean that all tile have been loaded.
  4. On postcompose event handler, capture the map content from event.context using event.context.canvas.toDataURL(), and register postrender function using event.frameState.postRenderFunctions.push() (a bit hacky).
  5. On the registered postrender function, check the tile load count (which can be managed by the tileload* event handlers). If the count is not zero, abandon the captured content. Else, the capture is done.
  6. On tileloadend and tileloaderror, if the tile load count becomes zero, retry from the step 3 above.

这篇关于OpenLayers:如何检测地图视图是否已完全加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆