Fix ScaleLine control for Projections in degrees

This commit is contained in:
Pete Schmitt
2018-01-12 14:00:45 -07:00
parent 5cb983c760
commit acacad0515
2 changed files with 16 additions and 1 deletions

View File

@@ -176,7 +176,7 @@ ScaleLine.prototype.updateElement_ = function() {
Units.METERS;
let pointResolution =
getPointResolution(projection, viewState.resolution, center, pointResolutionUnits);
if (units != ScaleLineUnits.DEGREES) {
if (projection.getUnits() != Units.DEGREES && units == ScaleLineUnits.METRIC) {
pointResolution *= projection.getMetersPerUnit();
}

View File

@@ -298,6 +298,21 @@ describe('ol.control.ScaleLine', function() {
map.renderSync();
expect(ctrl.element_.innerText).to.be('100 mm');
});
it('Metric display works with Geographic (EPSG:4326) projection', function() {
var ctrl = new ScaleLine();
ctrl.setMap(map);
map.setView(new View({
center: [0, 0],
zoom: 0, /* min zoom */
projection: 'EPSG:4326'
}));
map.renderSync();
expect(ctrl.element_.innerText).to.be('10000 km');
map.getView().setZoom(28); /* max zoom */
map.renderSync();
expect(ctrl.element_.innerText).to.be('50 mm');
});
});
describe('latitude may affect scale line in EPSG:4326', function() {