From 8b3fddaf3ba64cb26ed280389c682f9489f585ba Mon Sep 17 00:00:00 2001 From: David Manthey Date: Thu, 27 Jan 2022 09:10:14 -0500 Subject: [PATCH] perf: Update option for addAnnotation. Add an option to skip updating the layer when adding an annotation. --- src/annotationLayer.js | 10 +++++++--- tests/cases/annotationLayer.js | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/annotationLayer.js b/src/annotationLayer.js index ad48fb2b34..1ea3e175dd 100644 --- a/src/annotationLayer.js +++ b/src/annotationLayer.js @@ -399,11 +399,13 @@ var annotationLayer = function (arg) { * @param {geo.annotation} annotation The annotation to add. * @param {string|geo.transform|null} [gcs] `undefined` to use the interface * gcs, `null` to use the map gcs, or any other transform. + * @param {boolean} update If `false`, don't update the layer after adding + * the annotation. * @returns {this} The current layer. * @fires geo.event.annotation.add_before * @fires geo.event.annotation.add */ - this.addAnnotation = function (annotation, gcs) { + this.addAnnotation = function (annotation, gcs, update) { var pos = $.inArray(annotation, m_annotations); if (pos < 0) { m_this.geoTrigger(geo_event.annotation.add_before, { @@ -418,8 +420,10 @@ var annotationLayer = function (arg) { annotation._coordinates(transform.transformCoordinates( gcs, map.gcs(), annotation._coordinates())); } - m_this.modified(); - m_this.draw(); + if (update !== false) { + m_this.modified(); + m_this.draw(); + } m_this.geoTrigger(geo_event.annotation.add, { annotation: annotation }); diff --git a/tests/cases/annotationLayer.js b/tests/cases/annotationLayer.js index 6c611b436f..2ebcea52ad 100644 --- a/tests/cases/annotationLayer.js +++ b/tests/cases/annotationLayer.js @@ -201,6 +201,16 @@ describe('geo.annotationLayer', function () { expect(removeAnnotationEvent).toBe(3); expect(layer.annotations().length).toBe(1); }); + it('addAnnotation update flag', function () { + layer.removeAllAnnotations(); + let mod = layer.timestamp(); + layer.addAnnotation(poly); + expect(layer.timestamp()).not.toEqual(mod); + layer.removeAllAnnotations(); + mod = layer.timestamp(); + layer.addAnnotation(poly, undefined, false); + expect(layer.timestamp()).toEqual(mod); + }); it('geojson', function () { layer.removeAllAnnotations(); layer.addAnnotation(poly);