Skip to content

Commit dca2a20

Browse files
committed
perf: Allow skipping event triggers on removeAnnotation
Also on removeAllAnnotations
1 parent 540466b commit dca2a20

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# GeoJS Change Log
22

3+
## Version 1.12.10
4+
5+
### Performance Improvements
6+
7+
- Allow skipping event triggers on removeAnnotation and removeAllAnnotations ([#13521](../../pull/13521))
8+
39
## Version 1.12.9
410

511
### Performance Improvements

src/annotationLayer.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ 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
494+
* @param {boolean} [trigger] If `false`, do not trigger add_before and add
495495
* events.
496496
* @returns {this} The current layer.
497497
* @fires geo.event.annotation.add_before
@@ -570,10 +570,11 @@ var annotationLayer = function (arg) {
570570
* the annotation.
571571
* @param {int} [pos] The posiiton of the annotation in the annotation list,
572572
* if known. This speeds up the process.
573+
* @param {boolean} [trigger] If `false`, do not trigger remove event.
573574
* @returns {boolean} `true` if an annotation was removed.
574575
* @fires geo.event.annotation.remove
575576
*/
576-
this.removeAnnotation = function (annotation, update, pos) {
577+
this.removeAnnotation = function (annotation, update, pos, trigger) {
577578
if (annotation.id && m_annotationIds[annotation.id()] !== undefined) {
578579
pos = m_annotations.indexOf(annotation);
579580
if (annotation === m_this.currentAnnotation) {
@@ -588,9 +589,11 @@ var annotationLayer = function (arg) {
588589
m_this.modified();
589590
m_this.draw();
590591
}
591-
m_this.geoTrigger(geo_event.annotation.remove, {
592-
annotation: annotation
593-
});
592+
if (trigger !== false) {
593+
m_this.geoTrigger(geo_event.annotation.remove, {
594+
annotation: annotation
595+
});
596+
}
594597
return true;
595598
}
596599
return false;
@@ -603,16 +606,17 @@ var annotationLayer = function (arg) {
603606
* are in the create state.
604607
* @param {boolean} [update] If `false`, don't update the layer after
605608
* removing the annotation.
609+
* @param {boolean} [trigger] If `false`, do not trigger remove events.
606610
* @returns {number} The number of annotations that were removed.
607611
*/
608-
this.removeAllAnnotations = function (skipCreating, update) {
612+
this.removeAllAnnotations = function (skipCreating, update, trigger) {
609613
var removed = 0, annotation;
610614
for (let pos = m_annotations.length - 1; pos >= 0; pos -= 1) {
611615
annotation = m_annotations[pos];
612616
if (skipCreating && annotation.state() === geo_annotation.state.create) {
613617
continue;
614618
}
615-
m_this.removeAnnotation(annotation, false, pos);
619+
m_this.removeAnnotation(annotation, false, pos, trigger);
616620
removed += 1;
617621
}
618622
if (removed && update !== false) {

tests/cases/annotationLayer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('geo.annotationLayer', function () {
8989
expect(layer.mode()).toBe(layer.modes.edit);
9090
expect(layer.mode(null)).toBe(layer);
9191
expect(layer.mode()).toBe(null);
92-
layer.removeAllAnnotations();
92+
layer.removeAllAnnotations(undefined, undefined, false);
9393
});
9494
it('annotations', function () {
9595
var poly = geo.annotation.polygonAnnotation({

0 commit comments

Comments
 (0)