use precise international inchesPerMeter
test scalebar text
This commit is contained in:
@@ -468,7 +468,7 @@ class ScaleLine extends Control {
|
|||||||
);
|
);
|
||||||
const dpi = this.dpi_ || DEFAULT_DPI;
|
const dpi = this.dpi_ || DEFAULT_DPI;
|
||||||
const mpu = this.viewState_.projection.getMetersPerUnit();
|
const mpu = this.viewState_.projection.getMetersPerUnit();
|
||||||
const inchesPerMeter = 39.37;
|
const inchesPerMeter = 1000 / 25.4;
|
||||||
return parseFloat(resolution.toString()) * mpu * inchesPerMeter * dpi;
|
return parseFloat(resolution.toString()) * mpu * inchesPerMeter * dpi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -596,4 +596,53 @@ 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(
|
||||||
|
Math.round(map.getView().getResolution() / 0.00028)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
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(
|
||||||
|
Math.round((map.getView().getResolution() * 0.5) / 0.00028)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user