Merge pull request #11649 from ahocevar/units-proj4-longlat
Deal with undefined units from proj4 longlat projections
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
* @module ol/proj/proj4
|
||||
*/
|
||||
import Projection from './Projection.js';
|
||||
import Units from './Units.js';
|
||||
import {
|
||||
addCoordinateTransforms,
|
||||
addEquivalentProjections,
|
||||
@@ -31,12 +32,16 @@ export function register(proj4) {
|
||||
const code = projCodes[i];
|
||||
if (!get(code)) {
|
||||
const def = proj4.defs(code);
|
||||
let units = def.units;
|
||||
if (!units && def.projName === 'longlat') {
|
||||
units = Units.DEGREES;
|
||||
}
|
||||
addProjection(
|
||||
new Projection({
|
||||
code: code,
|
||||
axisOrientation: def.axis,
|
||||
metersPerUnit: def.to_meter,
|
||||
units: def.units,
|
||||
units,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Projection from '../../../src/ol/proj/Projection.js';
|
||||
import Units from '../../../src/ol/proj/Units.js';
|
||||
import {HALF_SIZE} from '../../../src/ol/proj/epsg3857.js';
|
||||
import {
|
||||
METERS_PER_UNIT,
|
||||
@@ -448,6 +449,20 @@ describe('ol.proj', function () {
|
||||
delete proj4.defs['EPSG:3739'];
|
||||
});
|
||||
|
||||
it('creates ol.proj.Projection instance from EPSG:4258', function () {
|
||||
proj4.defs(
|
||||
'EPSG:4258',
|
||||
'+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs'
|
||||
);
|
||||
register(proj4);
|
||||
const proj = getProjection('EPSG:4258');
|
||||
expect(proj.getCode()).to.eql('EPSG:4258');
|
||||
expect(proj.getUnits()).to.eql('degrees');
|
||||
expect(proj.getMetersPerUnit()).to.eql(METERS_PER_UNIT[Units.DEGREES]);
|
||||
|
||||
delete proj4.defs['EPSG:4258'];
|
||||
});
|
||||
|
||||
it('allows Proj4js projections to be used transparently', function () {
|
||||
register(proj4);
|
||||
const point = transform(
|
||||
|
||||
Reference in New Issue
Block a user