perf: Update option for addAnnotation.
Add an option to skip updating the layer when adding an annotation.
MODIFY
src/annotationLayer.js
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()));
}
+ if (update !== false) {
m_this.modified();
m_this.draw();
+ }
m_this.geoTrigger(geo_event.annotation.add, {
annotation: annotation
});

MODIFY
tests/cases/annotationLayer.js
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);

perf: Update option for addAnnotation.

Add an option to skip updating the layer when adding an annotation.