Transform without axis order in proj4

This commit is contained in:
Andreas Hocevar
2020-05-23 20:59:08 +02:00
parent 6802fb7e34
commit 49658709c7
2 changed files with 23 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ import {
addProjection,
get,
} from '../proj.js';
import {assign} from '../obj.js';
import {get as getTransform} from './transforms.js';
/**
@@ -46,10 +47,16 @@ export function register(proj4) {
const code2 = projCodes[j];
const proj2 = get(code2);
if (!getTransform(code1, code2)) {
if (proj4.defs[code1] === proj4.defs[code2]) {
const def1 = proj4.defs(code1);
const def2 = proj4.defs(code2);
if (def1 === def2) {
addEquivalentProjections([proj1, proj2]);
} else {
const transform = proj4(code1, code2);
// Reset axis because OpenLayers always uses x, y axis order
const transform = proj4(
assign({}, def1, {axis: undefined}),
assign({}, def2, {axis: undefined})
);
addCoordinateTransforms(
proj1,
proj2,

View File

@@ -728,6 +728,20 @@ describe('ol.proj', function () {
clearAllProjections();
addCommon();
});
it('does not flip axis order', function () {
proj4.defs('enu', '+proj=longlat');
proj4.defs('neu', '+proj=longlat +axis=neu');
register(proj4);
const got = transform([1, 2], 'neu', 'enu');
expect(got).to.eql([1, 2]);
delete proj4.defs.enu;
delete proj4.defs.neu;
clearAllProjections();
addCommon();
});
});
describe('ol.proj.Projection.prototype.getMetersPerUnit()', function () {