Is there a way to know that an ImgTileProvider has finished loading all tiles?

StackOverflow https://stackoverflow.com/questions/20978752

  •  25-09-2022
  •  | 
  •  

Domanda

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.

È stato utile?

Soluzione

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");
    }
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top