Sort annotations

This commit is contained in:
Adina Țeudan 2020-10-10 01:53:40 +03:00
parent 19a8ceca0f
commit e9b5f0d10e
2 changed files with 22 additions and 3 deletions

View File

@ -16,6 +16,7 @@ import {tap} from "rxjs/operators";
import WebViewer, {Annotations, WebViewerInstance} from "@pdftron/webviewer";
import {TranslateService} from "@ngx-translate/core";
import {ViewerSyncService} from "../service/viwer-sync.service";
import { AnnotationUtils } from '../../../utils/annotation-utils';
@ -82,9 +83,9 @@ export class PdfViewerComponent implements OnInit, AfterViewInit, OnDestroy {
this._viewerSyncService.registerViewer(this.fileType, this.wvInstance);
this._configureTextPopup();
this._configureHeader();
instance.annotManager.on('annotationChanged', (annotations,b,c) => {
if(b === 'add'){
this.annotationsAdded.emit(annotations);
instance.annotManager.on('annotationChanged', (annotations, action) => {
if(action === 'add'){
this.annotationsAdded.emit(AnnotationUtils.sortAnnotations(annotations));
}
});

View File

@ -0,0 +1,18 @@
import { Annotations } from '@pdftron/webviewer';
export class AnnotationUtils {
public static sortAnnotations(annotations: Annotations.Annotation[]): Annotations.Annotation[] {
return annotations.sort((ann1, ann2) => {
if (ann1.getPageNumber() === ann2.getPageNumber()) {
if (ann1.getY() === ann2.getY()) {
if (ann1.getX() === ann2.getY()) {
return 0;
}
return ann1.getX() < ann2.getX() ? -1 : 1;
}
return ann1.getY() < ann2.getY() ? -1 : 1;
}
return ann1.getPageNumber() < ann2.getPageNumber() ? -1 : 1;
})
}
}