diff --git a/externs/olx.js b/externs/olx.js index cf29fa0d01..990f4b3241 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -275,7 +275,7 @@ olx.interaction.InteractionOptions; * Method called by the map to notify the interaction that a browser event was * dispatched to the map. If the function returns a falsy value, * propagation of the event to other interactions in the map's interactions - * chain will be prevented (this includes functions with no explicit return). See + * chain will be prevented (this includes functions with no explicit return). See * {@link https://developer.mozilla.org/en-US/docs/Glossary/Falsy} * @type {function(ol.MapBrowserEvent):boolean} * @api diff --git a/src/ol/control/scaleline.js b/src/ol/control/scaleline.js index 19bcbe2b99..6009641225 100644 --- a/src/ol/control/scaleline.js +++ b/src/ol/control/scaleline.js @@ -174,6 +174,9 @@ ol.control.ScaleLine.prototype.updateElement_ = function() { ol.proj.Units.METERS; var pointResolution = ol.proj.getPointResolution(projection, viewState.resolution, center, pointResolutionUnits); + if (units != ol.control.ScaleLineUnits.DEGREES) { + pointResolution *= projection.getMetersPerUnit(); + } var nominalCount = this.minWidth_ * pointResolution; var suffix = ''; diff --git a/test/spec/ol/control/scaleline.test.js b/test/spec/ol/control/scaleline.test.js index 135355acf4..20c4b0300e 100644 --- a/test/spec/ol/control/scaleline.test.js +++ b/test/spec/ol/control/scaleline.test.js @@ -1,9 +1,9 @@ - - +goog.require('ol'); goog.require('ol.Map'); goog.require('ol.View'); goog.require('ol.control.ScaleLine'); goog.require('ol.proj'); +goog.require('ol.proj.Projection'); describe('ol.control.ScaleLine', function() { var map; @@ -265,6 +265,40 @@ describe('ol.control.ScaleLine', function() { var innerHtml4326 = ctrl.element_.innerHTML; expect(innerHtml4326).to.not.be(innerHtml3857); }); + + it('Projection\'s metersPerUnit affect scale for non-degree units', function() { + var ctrl = new ol.control.ScaleLine(); + ctrl.setMap(map); + map.setView(new ol.View({ + center: [0, 0], + zoom: 0, + resolutions: [1], + projection: new ol.proj.Projection({ + code: 'METERS', + units: 'm', + getPointResolution: function(r) { + return r; + } + }) + })); + map.renderSync(); + expect(ctrl.element_.innerText).to.be('100 m'); + map.setView(new ol.View({ + center: [0, 0], + zoom: 0, + resolutions: [1], + projection: new ol.proj.Projection({ + code: 'PIXELS', + units: 'pixels', + metersPerUnit: 1 / 1000, + getPointResolution: function(r) { + return r; + } + }) + })); + map.renderSync(); + expect(ctrl.element_.innerText).to.be('100 mm'); + }); }); describe('latitude may affect scale line in EPSG:4326', function() {