Skip to content

Commit

Permalink
Merge pull request #9 from openlayers/renderer-switch
Browse files Browse the repository at this point in the history
Avoid switching renderers when updating the count
  • Loading branch information
tschaub authored Sep 12, 2023
2 parents 8fc5e5e + 2a99bc4 commit 488b588
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cases/vector-rendering/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -157,16 +157,24 @@ 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 {
useCanvas();
}
}

main(initialCount ? parseInt(initialCount) : parseInt(countSelect.value));
main();

0 comments on commit 488b588

Please sign in to comment.