Event for when a tile has loaded
- Dominant language
- JavaScript
- Stars
- 15.7k
- Forks
- 3.9k
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 34
Description
Would like an event listener for when a slippy tile has loaded. I'm trying to keep track of our calls to a map tile server, since that API doesn't provide a counter for how many requests we've done. I've almost gotten something hacked together using the `_requestImagery` function of `ImageryLayer`, but it is hard to do without modifying the source code, especially since `_requestImagery` doesn't return a promise or take a callback. If it did, I could at least check for `ImageryState.Received`.
The way I'm having to currently do it, I don't think is totally foolproof.
let layer = layers.addImageryProvider(new Cesium.createOpenStreetMapImageryProvider({
url: url,
}));
layer._requestImagery = function(imagery) {
Cesium.ImageryLayer.prototype._requestImagery.call(this, imagery);
if(imagery.state === Cesium.ImageryState.TRANSITIONING) {
num_api_calls++;
}
};
Since the images are being requested asynchronously, it isn't possible to just check for `ImageryState.RECEIVED` right after the call. The best I can do is check for `TRANSITIONING` instead of `UNLOADED`, but there is still the chance it could go back to `UNLOADED` if too many images are being requested concurrently. Surprisingly, my `num_api_calls` is actually decently accurate, reporting 1779 requests when actual was 1766.
I think this could be solved by having a public event that fires when the `imagePromise` in ImageryState.js has been resolved.
Contributor guide
Research direction
Start with ImageryLayer._requestImagery and ImageryState.js, focusing on how imagePromise resolution changes imagery state. Define the public event behavior around a successfully loaded tile and verify that it supports reliable request counting without modifying private methods.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100