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

perf: defer rendering loading spinner on image viewer #2529

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions packages/portal/src/components/media/MediaImageViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<LoadingSpinner
class="text-white"
size="lg"
:delay="0"
/>
</b-container>
<slot />
Expand Down Expand Up @@ -132,6 +133,7 @@
data() {
return {
imageLoading: null,
imageLoadingTimeout: null,
info: null,
olExtent: null,
olMap: null,
Expand All @@ -143,7 +145,11 @@
},

async fetch() {
this.imageLoading = true;
// TODO: this should be part of the delay handling in LoadingSpinner.vue,
// but that entails moving the b-container into there too, and
// updating all dependent components
this.imageLoadingTimeout = setTimeout(() => this.imageLoading = true, 1000);

try {
// clear any old OL layers e.g. from previous page, so tiles and anno
// highlight vectors don't hang around while the new one loads
Expand Down Expand Up @@ -267,6 +273,11 @@
}
},

handleImageLoaded() {
clearTimeout(this.imageLoadingTimeout);
this.imageLoading = false;
},

handleOlError(olError, message) {
const error = new MediaImageViewerError(message);
error.type = olError.type;
Expand Down Expand Up @@ -388,9 +399,9 @@
const source = new IIIFSource(sourceOptions);
source.on('error', (olError) => this.handleOlError(olError, 'OpenLayers IIIF Source error'));
source.on('imageloaderror', (olError) => this.handleOlError(olError, 'OpenLayers IIIF Source imageloaderror'));
source.on('imageloadend', () => this.imageLoading = false);
source.on('imageloadend', this.handleImageLoaded);
source.on('tileloaderror', (olError) => this.handleOlError(olError, 'OpenLayers IIIF Source tileloaderror'));
source.on('tileloadend', () => this.imageLoading = false);
source.on('tileloadend', this.handleImageLoaded);
const layer = new TileLayer({ properties: { id: 'image' }, source });
layer.on('error', (olError) => this.handleOlError(olError, 'OpenLayers Tile Layer error'));

Expand All @@ -411,20 +422,19 @@
});
source.on('error', (olError) => this.handleOlError(olError, 'OpenLayers Static Source error'));
source.on('imageloaderror', (olError) => this.handleOlError(olError, 'OpenLayers Static Source imageloaderror'));
source.on('imageloadend', () => this.imageLoading = false);
source.on('imageloadend', this.handleImageLoaded);
const layer = new ImageLayer({ properties: { id: 'image' }, source });
layer.on('error', (olError) => this.handleOlError(olError, 'OpenLayers Image Layer error'));

return { extent, layer, source };
},

async renderImage() {
await (this.$nextTick()); // without this static images won't render, some race condition

if (this.source === 'IIIF') {
const mapOptions = this.initOlImageLayerIIIF();
this.initOl(mapOptions);
} else {
await (this.$nextTick()); // without this static images won't render, some race condition
// TODO: should we always be using the media proxy for static images?
const url = this.$apis.record.mediaProxyUrl(this.url, this.itemId, { disposition: 'inline' });
const mapOptions = this.initOlImageLayerStatic(url, this.width, this.height);
Expand Down
Loading