Merge pull request #11395 from mike-000/patch-9

Correct inchesPerMeter and add tests for ScaleBar text
This commit is contained in:
Andreas Hocevar
2020-08-08 14:10:40 +02:00
committed by GitHub
2 changed files with 46 additions and 1 deletions

View File

@@ -468,7 +468,7 @@ class ScaleLine extends Control {
);
const dpi = this.dpi_ || DEFAULT_DPI;
const mpu = this.viewState_.projection.getMetersPerUnit();
const inchesPerMeter = 39.37;
const inchesPerMeter = 1000 / 25.4;
return parseFloat(resolution.toString()) * mpu * inchesPerMeter * dpi;
}

View File

@@ -596,4 +596,49 @@ describe('ol.control.ScaleLine', function () {
}
});
});
describe('scalebar text', function () {
it('it corresponds to the resolution', function () {
const ctrl = new ScaleLine({
bar: true,
text: true,
});
ctrl.setMap(map);
map.setView(
new View({
center: [0, 0],
zoom: 2,
multiWorld: true,
})
);
map.renderSync();
const element = document.querySelector('.ol-scale-text', map.getTarget());
expect(element).to.not.be(null);
expect(element).to.be.a(HTMLDivElement);
const text = element.innerText;
expect(text.slice(0, 4)).to.be('1 : ');
expect(text.replace(/^1|\D/g, '')).to.eql(139770566);
});
it('it changes with latitude', function () {
const ctrl = new ScaleLine({
bar: true,
text: true,
});
ctrl.setMap(map);
map.setView(
new View({
center: fromLonLat([0, 60]),
zoom: 2,
multiWorld: true,
})
);
map.renderSync();
const element = document.querySelector('.ol-scale-text', map.getTarget());
expect(element).to.not.be(null);
expect(element).to.be.a(HTMLDivElement);
const text = element.innerText;
expect(text.slice(0, 4)).to.be('1 : ');
expect(text.replace(/^1|\D/g, '')).to.eql(69885283);
});
});
});