question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to replace the tile URL in a custom TileSource without disrupting the viewer?

See original GitHub issue

I’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:

  1. 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).
  2. 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:closed
  • Created 2 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
iangilmancommented, Apr 22, 2021

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’s exists… 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):

viewer.addHandler('tile-load-failed', function(event) {
  // We need a brief timeout here because the exists flag is set after the event is fired 
  setTimeout(function() {
    event.tile.exists = true;
    
    // Update the URLs used by getTileUrl
  }, 1);
});
0reactions
iangilmancommented, Dec 2, 2022

FIxed by #2247.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Question: Implementing Custom Tile Source #690 - GitHub
I discovered that if I set the tileSources to the json request url then the getImageInfo method is called. But I am getting...
Read more >
openseadragon/openseadragon - Gitter
You can change that to 100% by using visibilityRatio: 1 in your viewer options ... tileSources: [{ type: 'image', url: "/static/images/vestiaire-hd.jpg", }] ...
Read more >
Change tile URL in OpenLayers-3 - GIS Stack Exchange
Solved the problem, I had tu use ol.source.XYZ instead of ol.source.OSM(). And later you can change map url by: source.setUrl(); ol.source.
Read more >
https://www.domenicoperrone.net/openseadragon/chan...
addTiledImage with replace:true when viewer has navigator (#948) 2.1.0: * BREAKING CHANGE: the tile does not hold a reference to its image anymore....
Read more >
Inline Configuration for Custom Tile Sources - OpenSeadragon
Functionally, this allows you to define a new TileSource implementation inline. Alternatively, you can create a new tile source which implements the required ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found