Skip to content

Commit

Permalink
bring over all properties (fixes #230)
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmetcalf committed Apr 25, 2017
1 parent 692e6e8 commit 92f412f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import transform from './transform';
var wgs84 = proj('WGS84');

function transformer(from, to, coords) {
var transformedArray;
var transformedArray, out, keys;
if (Array.isArray(coords)) {
transformedArray = transform(from, to, coords);
if (coords.length === 3) {
Expand All @@ -14,7 +14,18 @@ function transformer(from, to, coords) {
}
}
else {
return transform(from, to, coords);
out = transform(from, to, coords);
keys = Object.keys(coords);
if (keys.length === 2) {
return out;
}
keys.forEach(function (key) {

This comment has been minimized.

Copy link
@gpcboekema

gpcboekema Mar 26, 2019

Contributor

shouldn't this also apply for using an array as input? (line 10? coords.length === 3 return transformed x/y and original z?)
now it only works if you use an object: proj4(from, to,{x:1000,y:43700,z:10})or proj4(from, to).forward({x:1000,y:43700,z:10});
NOT if you use an array: proj4(from, to, [1000,43700,10]) or proj4().forward([1000,43700,10])

This comment has been minimized.

Copy link
@calvinmetcalf

calvinmetcalf Mar 26, 2019

Author Member

good catch

if (key === 'x' || key === 'y') {
return;
}
out[key] = coords[key];
});
return out;
}
}

Expand Down Expand Up @@ -61,4 +72,4 @@ function proj4(fromProj, toProj, coord) {
return obj;
}
}
export default proj4;
export default proj4;
22 changes: 22 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,27 @@ function startTests(chai, proj4, testPoints) {
});
});
});
describe('points', function () {
it('should ignore stuff it does not know', function (){

var sweref99tm = '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs';
var rt90 = '+lon_0=15.808277777799999 +lat_0=0.0 +k=1.0 +x_0=1500000.0 +y_0=0.0 +proj=tmerc +ellps=bessel +units=m +towgs84=414.1,41.3,603.1,-0.855,2.141,-7.023,0 +no_defs';
var rslt = proj4(sweref99tm, rt90).forward({
x: 319180,
y: 6399862,
z: 0,
m: 1000,
method: function () {
return 'correct answer';
}
});
assert.closeTo(rslt.x, 1271137.9275601401, 0.000001);
assert.closeTo(rslt.y, 6404230.291459564, 0.000001);
assert.equal(rslt.z, 0);
assert.equal(rslt.m, 1000);
assert.equal(rslt.method(), 'correct answer');
});
});
describe('defs', function() {
assert.equal(proj4.defs('testmerc'), proj4.defs['testmerc']);
proj4.defs('foo', '+proj=merc +lon_0=5.937 +lat_ts=45.027 +ellps=sphere');
Expand Down Expand Up @@ -265,6 +286,7 @@ function startTests(chai, proj4, testPoints) {
});
});
});

});
}
if(typeof process !== 'undefined'&&process.toString() === '[object process]'){
Expand Down

0 comments on commit 92f412f

Please sign in to comment.