geojs 1.12.8 → 1.12.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geojs",
3
- "version": "1.12.8",
3
+ "version": "1.12.9",
4
4
  "description": "JavaScript Geo Visualization and Analysis Library",
5
5
  "homepage": "https://github.com/OpenGeoscience/geojs",
6
6
  "license": "Apache-2.0",
@@ -42,8 +42,7 @@ var lineAnnotation = function (args) {
42
42
  line: function (d) {
43
43
  /* Return an array that has the same number of items as we have
44
44
  * vertices. */
45
- return Array.apply(null, Array(m_this.options('vertices').length)).map(
46
- function () { return d; });
45
+ return Array(m_this.options('vertices').length).fill(d);
47
46
  },
48
47
  position: function (d, i) {
49
48
  return m_this.options('vertices')[i];
@@ -53,8 +52,7 @@ var lineAnnotation = function (args) {
53
52
  line: function (d) {
54
53
  /* Return an array that has the same number of items as we have
55
54
  * vertices. */
56
- return Array.apply(null, Array(m_this.options('vertices').length)).map(
57
- function () { return d; });
55
+ return Array(m_this.options('vertices').length).fill(d);
58
56
  },
59
57
  position: function (d, i) {
60
58
  return m_this.options('vertices')[i];
@@ -43,7 +43,9 @@ var polygonAnnotation = function (args) {
43
43
  return new polygonAnnotation(args);
44
44
  }
45
45
 
46
- args = util.deepMerge({}, this.constructor.defaults, {
46
+ var m_this = this;
47
+
48
+ args = util.deepMerge({
47
49
  style: {
48
50
  polygon: function (d) { return d.polygon; }
49
51
  },
@@ -52,12 +54,11 @@ var polygonAnnotation = function (args) {
52
54
  const coord = m_this._coordinates();
53
55
  /* Return an array that has the same number of items as we have
54
56
  * vertices. */
55
- return Array.apply(null, Array((coord.outer || coord).length)).map(
56
- function () { return d; });
57
+ return Array((coord.outer || coord).length).fill(d);
57
58
  },
58
59
  position: function (d, i) {
59
60
  if (d.x !== undefined) {
60
- return d.x;
61
+ return d;
61
62
  }
62
63
  return m_this.options('vertices')[i];
63
64
  }
@@ -65,13 +66,12 @@ var polygonAnnotation = function (args) {
65
66
  cursorStyle: {
66
67
  position: util.identityFunction
67
68
  }
68
- }, args);
69
+ }, this.constructor.defaults, args);
69
70
  args.vertices = args.vertices || args.coordinates || [];
70
71
  delete args.coordinates;
71
72
  annotation.call(this, 'polygon', args);
72
73
 
73
- var m_this = this,
74
- s_actions = this.actions,
74
+ var s_actions = this.actions,
75
75
  s_state = this.state;
76
76
 
77
77
  /**
@@ -491,18 +491,22 @@ var annotationLayer = function (arg) {
491
491
  * gcs, `null` to use the map gcs, or any other transform.
492
492
  * @param {boolean} [update] If `false`, don't update the layer after adding
493
493
  * the annotation.
494
+ * @param {boolean} [trigger] If `false`, do trigger add_before and add
495
+ * events.
494
496
  * @returns {this} The current layer.
495
497
  * @fires geo.event.annotation.add_before
496
498
  * @fires geo.event.annotation.add
497
499
  */
498
- this.addAnnotation = function (annotation, gcs, update) {
500
+ this.addAnnotation = function (annotation, gcs, update, trigger) {
499
501
  if (m_annotationIds[annotation.id()] === undefined) {
500
502
  while (m_this.annotationById(annotation.id())) {
501
503
  annotation.newId();
502
504
  }
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
+ }
506
510
  m_annotations.push(annotation);
507
511
  m_annotationIds[annotation.id()] = annotation;
508
512
  annotation.layer(m_this);
@@ -516,8 +520,43 @@ var annotationLayer = function (arg) {
516
520
  m_this.modified();
517
521
  m_this.draw();
518
522
  }
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) {
519
558
  m_this.geoTrigger(geo_event.annotation.add, {
520
- annotation: annotation
559
+ annotations: added
521
560
  });
522
561
  }
523
562
  return m_this;
package/src/event.js CHANGED
@@ -656,20 +656,23 @@ geo_event.camera.viewport = 'geo_camera_viewport';
656
656
  geo_event.annotation = {};
657
657
 
658
658
  /**
659
- * Triggered when an annotation has been added.
659
+ * Triggered when or more multiple annotations have been added.
660
660
  *
661
661
  * @event geo.event.annotation.add
662
662
  * @type {geo.event.base}
663
- * @property {geo.annotation} annotation The annotation that was added.
663
+ * @property {geo.annotation} [annotation] The annotation that was added.
664
+ * @property {geo.annotation} [annotations] The annotations that were added.
664
665
  */
665
666
  geo_event.annotation.add = 'geo_annotation_add';
666
667
 
667
668
  /**
668
- * Triggered when an annotation is about to be added.
669
+ * Triggered when one or multiple annotations are about to be added.
669
670
  *
670
671
  * @event geo.event.annotation.add_before
671
672
  * @type {geo.event.base}
672
- * @property {geo.annotation} annotation The annotation that will be added.
673
+ * @property {geo.annotation} [annotation] The annotation that will be added.
674
+ * @property {geo.annotation[]} [annotations] The annotations that will be
675
+ * added.
673
676
  */
674
677
  geo_event.annotation.add_before = 'geo_annotation_add_before';
675
678
 
@@ -1011,15 +1011,15 @@ var util = {
1011
1011
  }
1012
1012
  const copy = source[key];
1013
1013
  if (copy && typeof copy === 'object' && (copy.constructor === Object || Array.isArray(copy))) {
1014
- let src = target[key];
1014
+ let value = target[key];
1015
1015
  if (!Array.isArray(copy)) {
1016
- if (typeof src !== 'object' || Array.isArray(src)) {
1017
- src = {};
1016
+ if (typeof value !== 'object' || Array.isArray(value)) {
1017
+ value = {};
1018
1018
  }
1019
- } else if (!Array.isArray(src)) {
1020
- src = [];
1019
+ } else if (!Array.isArray(value)) {
1020
+ value = [];
1021
1021
  }
1022
- target[key] = util.deepMerge(src, copy);
1022
+ target[key] = util.deepMerge(value, copy);
1023
1023
  } else if (copy !== undefined) {
1024
1024
  target[key] = copy;
1025
1025
  }