From 8bb9b1228b90ec3e834e4825c22cf8460f35b7b8 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Thu, 10 Sep 2020 18:02:41 +0200 Subject: [PATCH] Optimazation: the popup content is only initialized when the popup marker is clicked --- Logic/FilteredLayer.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Logic/FilteredLayer.ts b/Logic/FilteredLayer.ts index 8ce39f9..7e09e25 100644 --- a/Logic/FilteredLayer.ts +++ b/Logic/FilteredLayer.ts @@ -186,13 +186,11 @@ export class FilteredLayer { } this._dataFromOverpass = fusedFeatures; - console.log("New elements are ", this._newElements) for (const feature of this._newElements) { if (!idsFromOverpass.has(feature.properties.id)) { // This element is not yet uploaded or not yet visible in overpass // We include it in the layer fusedFeatures.push(feature); - console.log("Adding ", feature," to fusedFeatures") } } @@ -237,11 +235,19 @@ export class FilteredLayer { }); } let eventSource = State.state.allElements.addOrGetElement(feature); - const uiElement = self._showOnPopup(eventSource, feature); - const popup = L.popup({}, marker).setContent(uiElement.Render()); + const popup = L.popup({}, marker); + let uiElement: UIElement; + let content = undefined; marker.bindPopup(popup) .on("popupopen", () => { - uiElement.Activate(); + + if (content === undefined) { + uiElement = self._showOnPopup(eventSource, feature); + // Lazily create the content + content = uiElement.Render(); + } + popup.setContent(content); + uiElement.Activate(); uiElement.Update(); }); return marker;