Fix ScaleLine control now that getPointResolution works correctly
This commit is contained in:
@@ -201,20 +201,12 @@ class ScaleLine extends Control {
|
|||||||
ProjUnits.METERS;
|
ProjUnits.METERS;
|
||||||
let pointResolution =
|
let pointResolution =
|
||||||
getPointResolution(projection, viewState.resolution, center, pointResolutionUnits);
|
getPointResolution(projection, viewState.resolution, center, pointResolutionUnits);
|
||||||
if (projection.getUnits() != ProjUnits.DEGREES && projection.getMetersPerUnit()
|
|
||||||
&& pointResolutionUnits == ProjUnits.METERS) {
|
|
||||||
pointResolution *= projection.getMetersPerUnit();
|
|
||||||
}
|
|
||||||
|
|
||||||
let nominalCount = this.minWidth_ * pointResolution;
|
let nominalCount = this.minWidth_ * pointResolution;
|
||||||
let suffix = '';
|
let suffix = '';
|
||||||
if (units == Units.DEGREES) {
|
if (units == Units.DEGREES) {
|
||||||
const metersPerDegree = METERS_PER_UNIT[ProjUnits.DEGREES];
|
const metersPerDegree = METERS_PER_UNIT[ProjUnits.DEGREES];
|
||||||
if (projection.getUnits() == ProjUnits.DEGREES) {
|
nominalCount *= metersPerDegree;
|
||||||
nominalCount *= metersPerDegree;
|
|
||||||
} else {
|
|
||||||
pointResolution /= metersPerDegree;
|
|
||||||
}
|
|
||||||
if (nominalCount < metersPerDegree / 60) {
|
if (nominalCount < metersPerDegree / 60) {
|
||||||
suffix = '\u2033'; // seconds
|
suffix = '\u2033'; // seconds
|
||||||
pointResolution *= 3600;
|
pointResolution *= 3600;
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import Map from '../../../../src/ol/Map.js';
|
import Map from '../../../../src/ol/Map.js';
|
||||||
import View from '../../../../src/ol/View.js';
|
import View from '../../../../src/ol/View.js';
|
||||||
import ScaleLine, {render} from '../../../../src/ol/control/ScaleLine.js';
|
import ScaleLine, {render} from '../../../../src/ol/control/ScaleLine.js';
|
||||||
import {fromLonLat} from '../../../../src/ol/proj.js';
|
import {fromLonLat, clearAllProjections, addCommon} from '../../../../src/ol/proj.js';
|
||||||
import Projection from '../../../../src/ol/proj/Projection.js';
|
import Projection from '../../../../src/ol/proj/Projection.js';
|
||||||
|
import proj4 from 'proj4';
|
||||||
|
import {register} from '../../../../src/ol/proj/proj4.js';
|
||||||
|
|
||||||
describe('ol.control.ScaleLine', function() {
|
describe('ol.control.ScaleLine', function() {
|
||||||
let map;
|
let map;
|
||||||
@@ -244,6 +246,25 @@ describe('ol.control.ScaleLine', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('projections affect the scaleline', function() {
|
describe('projections affect the scaleline', function() {
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
proj4.defs('Indiana-East', 'PROJCS["IN83-EF",GEOGCS["LL83",DATUM["NAD83",' +
|
||||||
|
'SPHEROID["GRS1980",6378137.000,298.25722210]],PRIMEM["Greenwich",0],' +
|
||||||
|
'UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],' +
|
||||||
|
'PARAMETER["false_easting",328083.333],' +
|
||||||
|
'PARAMETER["false_northing",820208.333],' +
|
||||||
|
'PARAMETER["scale_factor",0.999966666667],' +
|
||||||
|
'PARAMETER["central_meridian",-85.66666666666670],' +
|
||||||
|
'PARAMETER["latitude_of_origin",37.50000000000000],' +
|
||||||
|
'UNIT["Foot_US",0.30480060960122]]');
|
||||||
|
register(proj4);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
clearAllProjections();
|
||||||
|
addCommon();
|
||||||
|
});
|
||||||
|
|
||||||
it('is rendered differently for different projections', function() {
|
it('is rendered differently for different projections', function() {
|
||||||
const ctrl = new ScaleLine();
|
const ctrl = new ScaleLine();
|
||||||
ctrl.setMap(map);
|
ctrl.setMap(map);
|
||||||
@@ -253,15 +274,47 @@ describe('ol.control.ScaleLine', function() {
|
|||||||
projection: 'EPSG:3857'
|
projection: 'EPSG:3857'
|
||||||
}));
|
}));
|
||||||
map.renderSync();
|
map.renderSync();
|
||||||
const innerHtml3857 = ctrl.element.innerHTML;
|
expect(ctrl.element.innerText).to.be('2000 km');
|
||||||
map.setView(new View({
|
map.setView(new View({
|
||||||
center: [7, 52],
|
center: [7, 52],
|
||||||
zoom: 2,
|
zoom: 2,
|
||||||
projection: 'EPSG:4326'
|
projection: 'EPSG:4326'
|
||||||
}));
|
}));
|
||||||
map.renderSync();
|
map.renderSync();
|
||||||
const innerHtml4326 = ctrl.element.innerHTML;
|
expect(ctrl.element.innerText).to.be('5000 km');
|
||||||
expect(innerHtml4326).to.not.be(innerHtml3857);
|
map.setView(new View({
|
||||||
|
center: fromLonLat([-85.685, 39.891], 'Indiana-East'),
|
||||||
|
zoom: 7,
|
||||||
|
projection: 'Indiana-East'
|
||||||
|
}));
|
||||||
|
map.renderSync();
|
||||||
|
expect(ctrl.element.innerText).to.be('100 km');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows the same scale for different projections at higher resolutions', function() {
|
||||||
|
const ctrl = new ScaleLine();
|
||||||
|
ctrl.setMap(map);
|
||||||
|
map.setView(new View({
|
||||||
|
center: fromLonLat([-85.685, 39.891]),
|
||||||
|
zoom: 7,
|
||||||
|
projection: 'EPSG:3857'
|
||||||
|
}));
|
||||||
|
map.renderSync();
|
||||||
|
expect(ctrl.element.innerText).to.be('100 km');
|
||||||
|
map.setView(new View({
|
||||||
|
center: [-85.685, 39.891],
|
||||||
|
zoom: 7,
|
||||||
|
projection: 'EPSG:4326'
|
||||||
|
}));
|
||||||
|
map.renderSync();
|
||||||
|
expect(ctrl.element.innerText).to.be('100 km');
|
||||||
|
map.setView(new View({
|
||||||
|
center: fromLonLat([-85.685, 39.891], 'Indiana-East'),
|
||||||
|
zoom: 7,
|
||||||
|
projection: 'Indiana-East'
|
||||||
|
}));
|
||||||
|
map.renderSync();
|
||||||
|
expect(ctrl.element.innerText).to.be('100 km');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Projection\'s metersPerUnit affect scale for non-degree units', function() {
|
it('Projection\'s metersPerUnit affect scale for non-degree units', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user