How to replace the tile URL in a custom TileSource without disrupting the viewer?
See original GitHub issueI’ve been really enjoying working with OpenSeadragon!
I’m trying to figure out the best approach for a somewhat complicated feature. I’m using a custom TileSource that uses getTileUrl
to fetch tiles from an S3 bucket. (I don’t think it’s relevant, but I’m also using range requests to get the tiles from a single image, so the tile URL is the same for every tile.) I’m trying to make it more secure by having the S3 signed URL expire after a fairly short time, which means I then need to update the TileSource to use this new URL. Somehow I need to seamlessly replace the URL without triggering a redraw in the viewer - it just needs to use the new URL whenever new tiles are fetched.
There are 2 approaches I’m considering:
- Use
addTiledImage
to replace the TileSource, and somehow prevent the viewer from flickering/stuttering/freezing while the swap takes place. This seems a bit heavy handed, but probably fairly straightforward (although I haven’t gotten it working yet). - Create a custom version of OSD that will retry a failed tile fetch (I’ve seen the retry logic in #1627, and would probably start there). I think I would also need to add some kind of
preRetry
function that gets called to replace the tile URL for the viewer. This seems more complicated, but possibly more robust.
In both cases, the problem boils down to finding a way to replace the URL for the TileSource without otherwise disrupting the viewer. Do you have any thoughts on the cleanest approach to accomplishing this?
Thank you for your work on this library!
Issue Analytics
- State:
- Created 2 years ago
- Comments:15 (9 by maintainers)
Top GitHub Comments
Glad you’re enjoying OSD!
Do you know when you need to switch URLs, or do you only know after you receive a fail?
If you know when you need to switch URLs, it seems you could just change the logic in your custom
getTileUrl
, unless I’m missing something.Otherwise, yes, being able to retry the failed tile would be important. Unlike in #1627 you would want to explicitly trigger the retry (once you had changed the URLs). You can watch for
tile-load-failed
errors and then reset the tile’sexists
… I’m not sure if that would be enough to make it try that tile again, but it’s a start. See here for reference:https://github.com/openseadragon/openseadragon/blob/dba9bcd76c2407ad7b856aba065389503c2db506/src/tiledimage.js#L1615
Here’s an idea of something to try (I haven’t tested this code):
FIxed by #2247.