Respect metersPerUnit in ScaleLine control

This commit is contained in:
Andreas Hocevar
2017-11-10 12:47:21 +01:00
parent dbfca19e09
commit 9c45f9a8d6
3 changed files with 40 additions and 3 deletions

View File

@@ -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

View File

@@ -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 = '';

View File

@@ -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() {