Skip to content

Commit

Permalink
Fix thumbnail ordering in Chrome #370
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Oct 2, 2023
1 parent aa24c1d commit b23fb2e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/models/stac.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,6 @@ class STAC {
*/
getThumbnails(browserOnly = false, prefer = null) { // prefer can be either
let thumbnails = this.getAssetsWithRoles(['thumbnail', 'overview']);
if (prefer && thumbnails.length > 1) {
thumbnails.sort(a => a.roles.includes(prefer) ? -1 : 1);
}
// Get from links only if no assets are available as they should usually be the same as in assets
if (thumbnails.length === 0) {
thumbnails = this.getLinksWithRels(['preview']);
Expand All @@ -313,6 +310,15 @@ class STAC {
// Remove all images that can't be displayed in a browser
thumbnails = thumbnails.filter(img => Utils.canBrowserDisplayImage(img));
}
if (prefer && thumbnails.length > 1) {
// Prefer one role over the other.
// The two step approach with two filters ensures the same sort bevahiour across all browsers:
// see https://github.com/radiantearth/stac-browser/issues/370
let filter = img => img.roles.includes(prefer);
thumbnails = thumbnails
.filter(filter)
.concat(thumbnails.filter(img => !filter(img)));
}
return thumbnails.map(img => this._linkToAbsolute(img));
}

Expand Down

0 comments on commit b23fb2e

Please # to comment.