From b3d8d8337a4e6b695149e7cff6da90b598508446 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Thu, 7 Nov 2024 09:18:13 -0500 Subject: [PATCH] perf: Speed up adding annotations Track annotation ids on the annotation layer to speed up adding large numbers of annotations. --- src/annotationLayer.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/annotationLayer.js b/src/annotationLayer.js index 89ef6b5bd0..6b6def83da 100644 --- a/src/annotationLayer.js +++ b/src/annotationLayer.js @@ -96,6 +96,7 @@ var annotationLayer = function (arg) { m_options, m_mode = null, m_annotations = [], + m_annotationIds = {}, m_features = [], m_labelFeature, m_labelLayer, @@ -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() : ( @@ -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) { @@ -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 */ @@ -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; };