Skip to content

Commit

Permalink
Merge pull request #1340 from OpenGeoscience/annotation-id
Browse files Browse the repository at this point in the history
perf: Speed up adding annotations
  • Loading branch information
manthey authored Nov 7, 2024
2 parents 0bf0f62 + b3d8d83 commit 5ad0374
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/annotationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ var annotationLayer = function (arg) {
m_options,
m_mode = null,
m_annotations = [],
m_annotationIds = {},
m_features = [],
m_labelFeature,
m_labelLayer,
Expand Down Expand Up @@ -504,6 +505,7 @@ var annotationLayer = function (arg) {
annotation: annotation
});
m_annotations.push(annotation);
m_annotationIds[annotation.id()] = annotation;
annotation.layer(m_this);
var map = m_this.map();
gcs = (gcs === null ? map.gcs() : (
Expand Down Expand Up @@ -537,6 +539,9 @@ var annotationLayer = function (arg) {
if (annotation === m_this.currentAnnotation) {
m_this.currentAnnotation = null;
}
if (m_annotationIds[annotation.id()] !== undefined) {
delete m_annotationIds[annotation.id()];
}
annotation._exit();
m_annotations.splice(pos, 1);
if (update !== false) {
Expand Down Expand Up @@ -597,12 +602,7 @@ var annotationLayer = function (arg) {
if (id !== undefined && id !== null) {
id = +id; /* Cast to int */
}
var annotations = m_annotations.filter(function (annotation) {
return annotation.id() === id;
});
if (annotations.length) {
return annotations[0];
}
return m_annotationIds[id];
};

/* A list of special modes */
Expand Down Expand Up @@ -1434,6 +1434,7 @@ var annotationLayer = function (arg) {
// Call super class exit
s_exit.call(m_this);
m_annotations = [];
m_annotationIds = {};
m_features = [];
return m_this;
};
Expand Down

0 comments on commit 5ad0374

Please sign in to comment.