Merge pull request #7700 from pedros007/fix-scaleline-projection-in-degrees

Fix ScaleLine control for Projections in degrees
This commit is contained in:
Andreas Hocevar
2018-01-15 13:14:45 +01:00
committed by GitHub
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() {
const 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() {