问题
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.
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.
回答1:
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");
}
});
来源:https://stackoverflow.com/questions/20978752/is-there-a-way-to-know-that-an-imgtileprovider-has-finished-loading-all-tiles