Skip to content

Commit

Permalink
Merge pull request #12229 from brendandahl/ann-event
Browse files Browse the repository at this point in the history
Dispatch event when annotations have finished rendering.
  • Loading branch information
timvandermeij authored Aug 17, 2020
2 parents ebb903e + 7bba493 commit 37e9c97
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 3 additions & 1 deletion web/annotation_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ class AnnotationLayerBuilder {
/**
* @param {PageViewport} viewport
* @param {string} intent (default value is 'display')
* @returns {Promise<void>} A promise that is resolved when rendering of the
* annotations is complete.
*/
render(viewport, intent = "display") {
this.pdfPage.getAnnotations({ intent }).then(annotations => {
return this.pdfPage.getAnnotations({ intent }).then(annotations => {
if (this._cancelled) {
return;
}
Expand Down
22 changes: 20 additions & 2 deletions web/pdf_page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ class PDFPageView {
}
}

/**
* @private
*/
async _renderAnnotationLayer() {
let error = null;
try {
await this.annotationLayer.render(this.viewport, "display");
} catch (ex) {
error = ex;
} finally {
this.eventBus.dispatch("annotationlayerrendered", {
source: this,
pageNumber: this.id,
error,
});
}
}

/**
* @private
*/
Expand Down Expand Up @@ -384,7 +402,7 @@ class PDFPageView {
}

if (redrawAnnotations && this.annotationLayer) {
this.annotationLayer.render(this.viewport, "display");
this._renderAnnotationLayer();
}
}

Expand Down Expand Up @@ -542,7 +560,7 @@ class PDFPageView {
this.l10n
);
}
this.annotationLayer.render(this.viewport, "display");
this._renderAnnotationLayer();
}
div.setAttribute("data-loaded", true);

Expand Down

0 comments on commit 37e9c97

Please sign in to comment.