Merge pull request #7462 from ahocevar/scaleline-meters-per-unit
Respect metersPerUnit in ScaleLine control
This commit is contained in:
+1
-1
@@ -275,7 +275,7 @@ olx.interaction.InteractionOptions;
|
|||||||
* Method called by the map to notify the interaction that a browser event was
|
* 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,
|
* dispatched to the map. If the function returns a falsy value,
|
||||||
* propagation of the event to other interactions in the map's interactions
|
* 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}
|
* {@link https://developer.mozilla.org/en-US/docs/Glossary/Falsy}
|
||||||
* @type {function(ol.MapBrowserEvent):boolean}
|
* @type {function(ol.MapBrowserEvent):boolean}
|
||||||
* @api
|
* @api
|
||||||
|
|||||||
@@ -174,6 +174,9 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
|
|||||||
ol.proj.Units.METERS;
|
ol.proj.Units.METERS;
|
||||||
var pointResolution =
|
var pointResolution =
|
||||||
ol.proj.getPointResolution(projection, viewState.resolution, center, pointResolutionUnits);
|
ol.proj.getPointResolution(projection, viewState.resolution, center, pointResolutionUnits);
|
||||||
|
if (units != ol.control.ScaleLineUnits.DEGREES) {
|
||||||
|
pointResolution *= projection.getMetersPerUnit();
|
||||||
|
}
|
||||||
|
|
||||||
var nominalCount = this.minWidth_ * pointResolution;
|
var nominalCount = this.minWidth_ * pointResolution;
|
||||||
var suffix = '';
|
var suffix = '';
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
goog.require('ol');
|
||||||
|
|
||||||
goog.require('ol.Map');
|
goog.require('ol.Map');
|
||||||
goog.require('ol.View');
|
goog.require('ol.View');
|
||||||
goog.require('ol.control.ScaleLine');
|
goog.require('ol.control.ScaleLine');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
|
goog.require('ol.proj.Projection');
|
||||||
|
|
||||||
describe('ol.control.ScaleLine', function() {
|
describe('ol.control.ScaleLine', function() {
|
||||||
var map;
|
var map;
|
||||||
@@ -265,6 +265,40 @@ describe('ol.control.ScaleLine', function() {
|
|||||||
var innerHtml4326 = ctrl.element_.innerHTML;
|
var innerHtml4326 = ctrl.element_.innerHTML;
|
||||||
expect(innerHtml4326).to.not.be(innerHtml3857);
|
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() {
|
describe('latitude may affect scale line in EPSG:4326', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user