Sort annotations
This commit is contained in:
parent
19a8ceca0f
commit
e9b5f0d10e
@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
18
apps/red-ui/src/app/utils/annotation-utils.ts
Normal file
18
apps/red-ui/src/app/utils/annotation-utils.ts
Normal 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;
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user