Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved best first level calculation #1198

Merged
merged 2 commits into from May 22, 2017
Merged

Improved best first level calculation #1198

merged 2 commits into from May 22, 2017

Conversation

iangilman
Copy link
Member

Fixes #1197

The issue hinges around the levelVisibility calculation that's based in part on TileSource.getClosestLevel. With 254px tiles, the response from getClosestLevel is reasonable, but with 500px tiles it just returns 0.

I'm not actually sure why getClosestLevel compares against the container size. It seems to me the best thing to do is just find the highest level where the entire image can fit on a single tile, so I changed it to do that, and in my testing the results are good: regardless of the tile size or the viewer size, the first tile that's loaded is the largest single-tile level, and then higher level tiles are loaded to fill in the remainder.

If you force the defaultZoomLevel to be something small, it will start with a lower level, since it doesn't need a tile as large as the largest single-tile level. If you force defaultZoomLevel to something big, it still starts with the largest single-tile level (unless you have immediateRender on), since we don't want to risk having holes. All seems good to me.

Even though getClosestLevel is technically a documented function, I'm not terribly concerned about changing it like this; it's not really a function people would use, and it still produces the same kind of value (even if the logic is different now), and ignoring the old argument isn't really a breaking change. Also note that this function is currently called in only one place. I suppose I could at least improve its documentation.

That said, I'd love a second opinion... @avandecreme, what do you think?

@rmcloughlin, can you verify that this fixes the issue you found?

@rmcloughlin
Copy link

When I apply this change to the test page I made in https://github.com/rmcloughlin/osd-tile-loading, this PR fixes the problem perfectly; no low layer images are fetched at all.

However in my actual application things still act a bit strange. My image is about 60,000 (w) by 40,000 (h) with tile size 1024 and overlap 1. Before the fix is applied (using OSD 2.2.1). The tiles are loaded in this order:

0/0_0.jpeg
1/0_0.jpeg
8/0_0.jpeg
2/0_0.jpeg
7/0_0.jpeg
3/0_0.jpeg
6/0_0.jpeg
4/0_0.jpeg
5/0_0.jpeg
9/0_0.jpeg
10/0_0.jpeg
11/0_0.jpeg
11/1_0.jpeg
11/0_1.jpeg
11/1_1.jpeg

When I use OSD that was built from this PR, the tiles are loaded in the following order:

10/0_0.jpeg
11/0_0.jpeg
8/0_0.jpeg
11/1_0.jpeg
7/0_0.jpeg
11/0_1.jpeg
6/0_0.jpeg
11/1_1.jpeg
5/0_0.jpeg
9/0_0.jpeg
4/0_0.jpeg
3/0_0.jpeg
2/0_0.jpeg
1/0_0.jpeg
0/0_0.jpeg

So in this case it's still loading the low-layer tiles but it's getting them after loading the more appropriate tiles.

@iangilman
Copy link
Member Author

@rmcloughlin That second issue you're seeing is the one fixed by #1193. To see both this patch and the other patch together you can use this combined branch:

https://github.com/openseadragon/openseadragon/tree/ig-both

Could you try that one and verify that it does the right thing?

@rmcloughlin
Copy link

Yes that one (ig-both) works better. It makes fewer requests and doesn't request all the low layer images (like 0/0_0.jpeg, 1/0_0.jpeg).

@iangilman
Copy link
Member Author

@rmcloughlin Awesome, thank you for testing it!

I'll leave this open for a few more days to see if @avandecreme (or anyone else) has anything to add.

);

if( tiles.x + 1 >= tilesPerSide.x && tiles.y + 1 >= tilesPerSide.y ){
if (tiles.x > 1 || tiles.y > 1) {
break;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the line below, shouldn't we return Math.max(this.minLevel, i - 1)?
Also, we could start the loop at i = this.minLevel + 1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Fixed :)

@iangilman iangilman merged commit e477123 into master May 22, 2017
@iangilman iangilman deleted the ig-closest branch May 22, 2017 17:17
iangilman added a commit that referenced this pull request May 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loading too many tiles for large tile sizes
3 participants