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

@@ -1,3 +1,11 @@
#scaleBarOptions { #scaleBarOptions {
display: none; display: none;
} }
.ol-scale-bar-inverted .ol-scale-singlebar-even {
background-color: var(--ol-background-color);
}
.ol-scale-bar-inverted .ol-scale-singlebar-odd {
background-color: var(--ol-subtle-foreground-color);;
}

View File

@@ -31,4 +31,6 @@ tags: "scale-line, openstreetmap"
</select> </select>
<label><input type="checkbox" id="showScaleText" checked> Show scale text</label> <label><input type="checkbox" id="showScaleText" checked> Show scale text</label>
<label><input type="checkbox" id="invertColors"> Invert colors</label>
</div> </div>

View File

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