Merge pull request #13834 from jipexu/scalebarcolors
ability to change the color of the scalebar
This commit is contained in:
+10
-12
@@ -379,7 +379,7 @@ class ScaleLine extends Control {
|
|||||||
'1 : ' + Math.round(this.getScaleForResolution()).toLocaleString();
|
'1 : ' + Math.round(this.getScaleForResolution()).toLocaleString();
|
||||||
const scaleSteps = [];
|
const scaleSteps = [];
|
||||||
const stepWidth = width / this.scaleBarSteps_;
|
const stepWidth = width / this.scaleBarSteps_;
|
||||||
let backgroundColor = '#ffffff';
|
let backgroundColor = 'ol-scale-singlebar-odd';
|
||||||
for (let i = 0; i < this.scaleBarSteps_; i++) {
|
for (let i = 0; i < this.scaleBarSteps_; i++) {
|
||||||
if (i === 0) {
|
if (i === 0) {
|
||||||
// create the first marker at position 0
|
// create the first marker at position 0
|
||||||
@@ -388,14 +388,13 @@ class ScaleLine extends Control {
|
|||||||
scaleSteps.push(
|
scaleSteps.push(
|
||||||
'<div>' +
|
'<div>' +
|
||||||
'<div ' +
|
'<div ' +
|
||||||
'class="ol-scale-singlebar" ' +
|
'class="ol-scale-singlebar ' +
|
||||||
|
backgroundColor +
|
||||||
|
'" ' +
|
||||||
'style=' +
|
'style=' +
|
||||||
'"width: ' +
|
'"width: ' +
|
||||||
stepWidth +
|
stepWidth +
|
||||||
'px;' +
|
'px;"' +
|
||||||
'background-color: ' +
|
|
||||||
backgroundColor +
|
|
||||||
';"' +
|
|
||||||
'>' +
|
'>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
this.createMarker('relative', i) +
|
this.createMarker('relative', i) +
|
||||||
@@ -411,12 +410,11 @@ class ScaleLine extends Control {
|
|||||||
}
|
}
|
||||||
scaleSteps.push(this.createStepText(i + 1, width, true, scale, suffix));
|
scaleSteps.push(this.createStepText(i + 1, width, true, scale, suffix));
|
||||||
}
|
}
|
||||||
// switch colors of steps between black and white
|
// switch style of steps
|
||||||
if (backgroundColor === '#ffffff') {
|
backgroundColor =
|
||||||
backgroundColor = '#000000';
|
backgroundColor === 'ol-scale-singlebar-odd'
|
||||||
} else {
|
? 'ol-scale-singlebar-even'
|
||||||
backgroundColor = '#ffffff';
|
: 'ol-scale-singlebar-odd';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let scaleBarText;
|
let scaleBarText;
|
||||||
|
|||||||
@@ -29,6 +29,12 @@
|
|||||||
will-change: contents, width;
|
will-change: contents, width;
|
||||||
transition: all 0.25s;
|
transition: all 0.25s;
|
||||||
}
|
}
|
||||||
|
.ol-scale-singlebar-even{
|
||||||
|
background-color: #000000;
|
||||||
|
}
|
||||||
|
.ol-scale-singlebar-odd{
|
||||||
|
background-color: #ffffff;
|
||||||
|
}
|
||||||
.ol-scale-bar {
|
.ol-scale-bar {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 8px;
|
bottom: 8px;
|
||||||
|
|||||||
Reference in New Issue
Block a user