@@ -491,18 +491,22 @@ var annotationLayer = function (arg) {
491491 * gcs, `null` to use the map gcs, or any other transform.
492492 * @param {boolean } [update] If `false`, don't update the layer after adding
493493 * the annotation.
494+ * @param {boolean } [trigger] If `false`, do trigger add_before and add
495+ * events.
494496 * @returns {this } The current layer.
495497 * @fires geo.event.annotation.add_before
496498 * @fires geo.event.annotation.add
497499 */
498- this . addAnnotation = function ( annotation , gcs , update ) {
500+ this . addAnnotation = function ( annotation , gcs , update , trigger ) {
499501 if ( m_annotationIds [ annotation . id ( ) ] === undefined ) {
500502 while ( m_this . annotationById ( annotation . id ( ) ) ) {
501503 annotation . newId ( ) ;
502504 }
503- m_this . geoTrigger ( geo_event . annotation . add_before , {
504- annotation : annotation
505- } ) ;
505+ if ( trigger !== false ) {
506+ m_this . geoTrigger ( geo_event . annotation . add_before , {
507+ annotation : annotation
508+ } ) ;
509+ }
506510 m_annotations . push ( annotation ) ;
507511 m_annotationIds [ annotation . id ( ) ] = annotation ;
508512 annotation . layer ( m_this ) ;
@@ -516,8 +520,43 @@ var annotationLayer = function (arg) {
516520 m_this . modified ( ) ;
517521 m_this . draw ( ) ;
518522 }
523+ if ( trigger !== false ) {
524+ m_this . geoTrigger ( geo_event . annotation . add , {
525+ annotation : annotation
526+ } ) ;
527+ }
528+ }
529+ return m_this ;
530+ } ;
531+
532+ /**
533+ * Add multiple annotations to the layer. The annotations could be in any
534+ * state.
535+ *
536+ * @param {geo.annotation[] } annotations The annotations to add.
537+ * @param {string|geo.transform|null } [gcs] `undefined` to use the interface
538+ * gcs, `null` to use the map gcs, or any other transform.
539+ * @param {boolean } [update] If `false`, don't update the layer after adding
540+ * the annotation.
541+ * @returns {this } The current layer.
542+ * @fires geo.event.annotation.add_before
543+ * @fires geo.event.annotation.add
544+ */
545+ this . addMultipleAnnotations = function ( annotations , gcs , update ) {
546+ const added = [ ] ;
547+ m_this . geoTrigger ( geo_event . annotation . add_before , {
548+ annotations : annotations
549+ } ) ;
550+ for ( let i = 0 ; i < annotations . length ; i += 1 ) {
551+ const annotation = annotations [ i ] ;
552+ if ( m_annotationIds [ annotation . id ( ) ] === undefined ) {
553+ this . addAnnotation ( annotation , gcs , update , false ) ;
554+ added . push ( annotation ) ;
555+ }
556+ }
557+ if ( added . length ) {
519558 m_this . geoTrigger ( geo_event . annotation . add , {
520- annotation : annotation
559+ annotations : added
521560 } ) ;
522561 }
523562 return m_this ;
0 commit comments