Deal with undefined units from proj4 longlat projections
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
* @module ol/proj/proj4
|
* @module ol/proj/proj4
|
||||||
*/
|
*/
|
||||||
import Projection from './Projection.js';
|
import Projection from './Projection.js';
|
||||||
|
import Units from './Units.js';
|
||||||
import {
|
import {
|
||||||
addCoordinateTransforms,
|
addCoordinateTransforms,
|
||||||
addEquivalentProjections,
|
addEquivalentProjections,
|
||||||
@@ -31,12 +32,16 @@ export function register(proj4) {
|
|||||||
const code = projCodes[i];
|
const code = projCodes[i];
|
||||||
if (!get(code)) {
|
if (!get(code)) {
|
||||||
const def = proj4.defs(code);
|
const def = proj4.defs(code);
|
||||||
|
let units = def.units;
|
||||||
|
if (!units && def.projName === 'longlat') {
|
||||||
|
units = Units.DEGREES;
|
||||||
|
}
|
||||||
addProjection(
|
addProjection(
|
||||||
new Projection({
|
new Projection({
|
||||||
code: code,
|
code: code,
|
||||||
axisOrientation: def.axis,
|
axisOrientation: def.axis,
|
||||||
metersPerUnit: def.to_meter,
|
metersPerUnit: def.to_meter,
|
||||||
units: def.units,
|
units,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import Projection from '../../../src/ol/proj/Projection.js';
|
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 {HALF_SIZE} from '../../../src/ol/proj/epsg3857.js';
|
||||||
import {
|
import {
|
||||||
METERS_PER_UNIT,
|
METERS_PER_UNIT,
|
||||||
@@ -448,6 +449,20 @@ describe('ol.proj', function () {
|
|||||||
delete proj4.defs['EPSG:3739'];
|
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 () {
|
it('allows Proj4js projections to be used transparently', function () {
|
||||||
register(proj4);
|
register(proj4);
|
||||||
const point = transform(
|
const point = transform(
|
||||||
|
|||||||
Reference in New Issue
Block a user