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: Speed up adding annotations #1340

Merged
merged 1 commit into from
Nov 7, 2024
Merged
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
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