From 2a99bc45472a7c8b75035d565b01f751a0677002 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Tue, 12 Sep 2023 18:18:38 +0200 Subject: [PATCH] Avoid switching renderers when updating the count --- cases/vector-rendering/main.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cases/vector-rendering/main.js b/cases/vector-rendering/main.js index 28ce10c..7dc38b0 100644 --- a/cases/vector-rendering/main.js +++ b/cases/vector-rendering/main.js @@ -82,11 +82,11 @@ const countSelect = /** @type {HTMLSelectElement} */ ( ); countSelect.addEventListener('change', function () { link.update('count', countSelect.value); - main(parseInt(countSelect.value)); + resetData(parseInt(countSelect.value)); }); const initialCount = link.track('count', (newCount) => { - main(parseInt(newCount)); + resetData(parseInt(newCount)); }); if (initialCount) { countSelect.value = initialCount; @@ -157,11 +157,19 @@ async function addFeatures(features) { /** * @param {number} count The number of features to create. */ -function main(count) { +function resetData(count) { source.clear(); const data = makeData(count); const features = parseFeatures(data); addFeatures(features); +} + +function main() { + const count = initialCount + ? parseInt(initialCount) + : parseInt(countSelect.value); + resetData(count); + if (initialRenderer === 'webgl') { useWebGL(); } else { @@ -169,4 +177,4 @@ function main(count) { } } -main(initialCount ? parseInt(initialCount) : parseInt(countSelect.value)); +main();