@@ -306,8 +306,7 @@ export default class Guest extends Delegator {
306
306
} ) ;
307
307
308
308
this . subscribe ( 'annotationsLoaded' , annotations => {
309
- this . loadDoodles ( annotations . filter ( this . isDoodleAnnotation ) ) ;
310
- annotations . map ( annotation => this . anchor ( annotation ) ) ;
309
+ annotations . forEach ( annotation => this . anchor ( annotation ) ) ;
311
310
} ) ;
312
311
}
313
312
@@ -499,6 +498,17 @@ export default class Guest extends Delegator {
499
498
}
500
499
}
501
500
annotation . $orphan = hasAnchorableTargets && ! hasAnchoredTargets ;
501
+ // An annotation is a doodle if any of its selectors have the type 'DoodleSelector'
502
+ annotation . $doodle = anchors . some ( a => {
503
+ return (
504
+ a . target && a . target . selector ?. some ( s => s . type === 'DoodleSelector' )
505
+ ) ;
506
+ } ) ;
507
+
508
+ // Display the doodle on the canvas
509
+ if ( annotation . $doodle ) {
510
+ this . loadDoodle ( annotation ) ;
511
+ }
502
512
503
513
// Add the anchors for this annotation to instance storage.
504
514
this . anchors = this . anchors . concat ( anchors ) ;
@@ -796,43 +806,17 @@ export default class Guest extends Delegator {
796
806
}
797
807
}
798
808
799
- /**
800
- *
801
- * @param {* } annotation
802
- * @returns true if the annotation is a doodleAnnotation
803
- */
804
-
805
- isDoodleAnnotation ( annotation ) {
806
- // If any of the targets have a DoodleSelector, this is a doodle annotation. Otherwise, it is not.
807
- if ( annotation . target ) {
808
- for ( let targ of annotation . target ) {
809
- // not all targets have selectors at this point
810
- if ( targ . selector ) {
811
- for ( let selector of targ . selector ) {
812
- if ( selector . type === 'DoodleSelector' ) {
813
- return true ;
814
- }
815
- }
816
- }
817
- }
818
- }
819
- return false ;
820
- }
821
-
822
- loadDoodles ( doodleAnnotations ) {
823
- // First, make sure there are doodleAnnotations and a Controller
824
- if ( ! doodleAnnotations . length || ! this . doodleCanvasController ) {
809
+ loadDoodle ( doodleAnnotation ) {
810
+ if ( ! this . doodleCanvasController ) {
825
811
return ;
826
812
}
827
813
828
- // Then, load the lines into our doodleCanvasController.
814
+ //load the lines into our doodleCanvasController.
829
815
let newLines = [ ] ;
830
- for ( let doodle of doodleAnnotations ) {
831
- for ( let targ of doodle . target ) {
832
- for ( let sel of targ . selector ) {
833
- if ( sel . type === 'DoodleSelector' ) {
834
- newLines = [ ...newLines , sel . line ] ;
835
- }
816
+ for ( let targ of doodleAnnotation . target ) {
817
+ for ( let sel of targ . selector ) {
818
+ if ( sel . type === 'DoodleSelector' ) {
819
+ newLines = [ ...newLines , sel . line ] ;
836
820
}
837
821
}
838
822
}
0 commit comments