有没有办法知道ImgTileProvider已完成加载所有图块? [英] Is there a way to know that an ImgTileProvider has finished loading all tiles?

查看:63
本文介绍了有没有办法知道ImgTileProvider已完成加载所有图块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个地图应用程序,该应用程序通过

I'm building out a map app that pulls in tiles via an ImgTileProvider. I would like to know when the tiles have been correctly loaded, but the only method exposed by the ImgTileProvider.Options is the getUrl function, which helps me know where to get an image tile, not when it returns.

在每个图块/所有图块已经创建/渲染到页面之后,是否会触发事件?我注意到,有一个addListener函数可用于ImgTileProvider实例,如果我知道在映像创建过程中触发了哪个事件,我将订阅该函数.

Is there an event that is fired after each tile/all tiles has/have been created/rendered to the page? I noticed that there was an addListener function available for ImgTileProvider instances, which I would subscribe to if I knew which event was being fired on image create.

推荐答案

因此,在我撰写此问题时,出现了一个想法:为什么不检查源代码?我使用Chrome浏览器对map-render-display.js文件进行了美化,并查找了通过addListener函数添加的事件.我没有看到ImgTileProvider的任何内容,但是我发现其他一些提供程序正在订阅response事件的提供程序.因此,我在ImgTileProvider实例上添加了一个事件侦听器,它起作用了!以下是工作代码示例.

So, as I was writing this question, a thought occurred: why not check the source? Using Chrome, I prettified the map-render-display.js file and looked for events added via the addListener function. I didn't see anything for ImgTileProvider, but I found several other providers subscribing to a response event. So I added an event listener on my ImgTileProvider instance and it worked! Below is a sample of working code.

// A magic number representing the total number of tiles in the map.
var magicNumber = 22;
// Returns a new ImgTileProvider.
tileProvider = self.imgTileProvider();
tileProvider.addListener("response", function () {
    magicNumber--;
    if (magicNumber === 0) {
        console.log("All tiles loaded");
    }
});

这篇关于有没有办法知道ImgTileProvider已完成加载所有图块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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