Add color invert option to scale-line example

This commit is contained in:
Maximilian Krög
2022-07-16 14:56:40 +02:00
parent e10432260f
commit 436a4ca597
3 changed files with 19 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ const unitsSelect = document.getElementById('units');
const typeSelect = document.getElementById('type');
const stepsSelect = document.getElementById('steps');
const scaleTextCheckbox = document.getElementById('showScaleText');
const invertColorsCheckbox = document.getElementById('invertColors');
let control;
@@ -26,6 +27,7 @@ function scaleControl() {
text: scaleTextCheckbox.checked,
minWidth: 140,
});
onInvertColorsChange();
scaleBarOptionsContainer.style.display = 'block';
}
return control;
@@ -51,7 +53,14 @@ function reconfigureScaleLine() {
function onChangeUnit() {
control.setUnits(unitsSelect.value);
}
function onInvertColorsChange() {
control.element.classList.toggle(
'ol-scale-bar-inverted',
invertColorsCheckbox.checked
);
}
unitsSelect.addEventListener('change', onChangeUnit);
typeSelect.addEventListener('change', reconfigureScaleLine);
stepsSelect.addEventListener('change', reconfigureScaleLine);
scaleTextCheckbox.addEventListener('change', reconfigureScaleLine);
invertColorsCheckbox.addEventListener('change', onInvertColorsChange);