Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Update option for addAnnotation. #1161

Merged
merged 1 commit into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/annotationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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
});
Expand Down
10 changes: 10 additions & 0 deletions tests/cases/annotationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down