Skip to content

Commit e0a9a46

Browse files
authored
add altitude in projections (#2475)
1 parent b7f8627 commit e0a9a46

5 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/geo/projection/Projection.Baidu.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ const ProjectionMethods = {
6969
cD[8] * cB * cB * cB * cB * cB * cB;
7070
T *= (cC.x < 0 ? -1 : 1);
7171
cE *= (cC.y < 0 ? -1 : 1);
72+
const z = cC.z;
7273
if (out) {
7374
out.x = T;
7475
out.y = cE;
76+
out.z = z;
7577
return out;
7678
}
77-
return new Coordinate(T, cE);
79+
return new Coordinate(T, cE, z);
7880
},
7981
toRadians: function (T: number): number {
8082
return Math.PI * T / 180;

src/geo/projection/Projection.EPSG3857.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ const EPSG3857Projection = {
3030
}
3131
const x = lng * metersPerDegree;
3232
const y = c * metersPerDegree;
33+
const z = lnglat.z;
3334
if (out) {
3435
out.x = x;
3536
out.y = y;
37+
out.z = z;
3638
return out;
3739
}
38-
return new Coordinate(x, y);
40+
return new Coordinate(x, y, z);
3941
},
4042

4143
unproject: function (pLnglat: Coordinate, out?: Coordinate) {
@@ -60,12 +62,14 @@ const EPSG3857Projection = {
6062
// const ry = wrap(c, -this.maxLatitude, this.maxLatitude);
6163
const rx = x;
6264
const ry = c;
65+
const rz = pLnglat.z;
6366
if (out) {
6467
out.x = rx;
6568
out.y = ry;
69+
out.z = rz;
6670
return out;
6771
}
68-
return new Coordinate(rx, ry);
72+
return new Coordinate(rx, ry, rz);
6973
}
7074
};
7175

src/geo/projection/Projection.EPSG4326.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const EPSG4326Projection = {
1414
if (out) {
1515
out.x = p.x;
1616
out.y = p.y;
17+
out.z = p.z;
1718
return out;
1819
}
1920
return new Coordinate(p);
@@ -22,6 +23,7 @@ const EPSG4326Projection = {
2223
if (out) {
2324
out.x = p.x;
2425
out.y = p.y;
26+
out.z = p.z;
2527
return out;
2628
}
2729
return new Coordinate(p);

src/geo/projection/Projection.EPSG9807.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,29 @@ const EPSG9807Projection = {
7171
P.fwd(lp, xy);
7272
const x = P.a * xy.x + P.x0 - originX;
7373
const y = P.a * xy.y + P.y0 - originY;
74+
const z = p.z;
7475
if (out) {
7576
out.x = x;
7677
out.y = y;
78+
out.z = z;
7779
return out;
7880
}
79-
return new Coordinate(x, y);
81+
return new Coordinate(x, y, z);
8082
},
8183
unproject: function (p: Coordinate, out?: Coordinate): Coordinate {
8284
xy.x = (p.x - P.x0 + originX) / P.a;
8385
xy.y = (p.y - P.y0 + originY) / P.a;
8486
P.inv(xy, lp);
8587
const x = (lp.lam + P.lam0) * RAD_TO_DEG;
8688
const y = lp.phi * RAD_TO_DEG;
89+
const z = p.z;
8790
if (out) {
8891
out.x = x;
8992
out.y = y;
93+
out.z = z;
9094
return out;
9195
}
92-
return new Coordinate(x, y);
96+
return new Coordinate(x, y, z);
9397
}
9498
};
9599

src/geo/projection/Projection.IDENTITY.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const IdentityProjection = {
1313
if (out) {
1414
out.x = p.x;
1515
out.y = p.y;
16+
out.z = p.z;
1617
return out;
1718
}
1819
return p.copy();
@@ -21,6 +22,7 @@ const IdentityProjection = {
2122
if (out) {
2223
out.x = p.x;
2324
out.y = p.y;
25+
out.z = p.z;
2426
return out;
2527
}
2628
return p.copy();

0 commit comments

Comments
 (0)