Skip to content

Fix the situation sometimes coordinate.z is lost #2474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/geo/projection/Projection.Baidu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ const ProjectionMethods = {
cD[8] * cB * cB * cB * cB * cB * cB;
T *= (cC.x < 0 ? -1 : 1);
cE *= (cC.y < 0 ? -1 : 1);
const z = cC.z;
if (out) {
out.x = T;
out.y = cE;
out.z = z;
return out;
}
return new Coordinate(T, cE);
return new Coordinate(T, cE, z);
},
toRadians: function (T: number): number {
return Math.PI * T / 180;
Expand Down
8 changes: 6 additions & 2 deletions src/geo/projection/Projection.EPSG3857.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ const EPSG3857Projection = {
}
const x = lng * metersPerDegree;
const y = c * metersPerDegree;
const z = lnglat.z;
if (out) {
out.x = x;
out.y = y;
out.z = z;
return out;
}
return new Coordinate(x, y);
return new Coordinate(x, y, z);
},

unproject: function (pLnglat: Coordinate, out?: Coordinate) {
Expand All @@ -60,12 +62,14 @@ const EPSG3857Projection = {
// const ry = wrap(c, -this.maxLatitude, this.maxLatitude);
const rx = x;
const ry = c;
const rz = pLnglat.z;
if (out) {
out.x = rx;
out.y = ry;
out.z = rz;
return out;
}
return new Coordinate(rx, ry);
return new Coordinate(rx, ry, rz);
}
};

Expand Down
2 changes: 2 additions & 0 deletions src/geo/projection/Projection.EPSG4326.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const EPSG4326Projection = {
if (out) {
out.x = p.x;
out.y = p.y;
out.z = p.z;
return out;
}
return new Coordinate(p);
Expand All @@ -22,6 +23,7 @@ const EPSG4326Projection = {
if (out) {
out.x = p.x;
out.y = p.y;
out.z = p.z;
return out;
}
return new Coordinate(p);
Expand Down
8 changes: 6 additions & 2 deletions src/geo/projection/Projection.EPSG9807.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,29 @@ const EPSG9807Projection = {
P.fwd(lp, xy);
const x = P.a * xy.x + P.x0 - originX;
const y = P.a * xy.y + P.y0 - originY;
const z = p.z;
if (out) {
out.x = x;
out.y = y;
out.z = z;
return out;
}
return new Coordinate(x, y);
return new Coordinate(x, y, z);
},
unproject: function (p: Coordinate, out?: Coordinate): Coordinate {
xy.x = (p.x - P.x0 + originX) / P.a;
xy.y = (p.y - P.y0 + originY) / P.a;
P.inv(xy, lp);
const x = (lp.lam + P.lam0) * RAD_TO_DEG;
const y = lp.phi * RAD_TO_DEG;
const z = p.z;
if (out) {
out.x = x;
out.y = y;
out.z = z;
return out;
}
return new Coordinate(x, y);
return new Coordinate(x, y, z);
}
};

Expand Down
2 changes: 2 additions & 0 deletions src/geo/projection/Projection.IDENTITY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const IdentityProjection = {
if (out) {
out.x = p.x;
out.y = p.y;
out.z = p.z;
return out;
}
return p.copy();
Expand All @@ -21,6 +22,7 @@ const IdentityProjection = {
if (out) {
out.x = p.x;
out.y = p.y;
out.z = p.z;
return out;
}
return p.copy();
Expand Down
3 changes: 2 additions & 1 deletion src/map/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@ export class Map extends Handlerable(Eventable(Renderable(Class))) {
this._center = center;
return this;
}
this._centerZ = center.z;
this.onMoveStart();
this._setPrjCenter(pcenter);
this.onMoveEnd(this._parseEventFromCoord(this.getCenter()));
Expand Down Expand Up @@ -2234,6 +2233,7 @@ export class Map extends Handlerable(Eventable(Renderable(Class))) {
//@internal
_setPrjCenter(pcenter: Coordinate) {
this._prjCenter = pcenter;
this._centerZ = pcenter.z;
if (this.isInteracting() && !this.isMoving()) {
// when map is not moving, map's center is updated but map platform won't
// mapViewCoord needs to be synced
Expand All @@ -2257,6 +2257,7 @@ export class Map extends Handlerable(Eventable(Renderable(Class))) {
//@internal
_setPrjCoordAtOffsetToCenter(prjCoord: Coordinate, offset: Point) {
const pcenter = this._pointToPrj(this._prjToPoint(prjCoord)._sub(offset));
pcenter.z = this.getCenter().z + (prjCoord.z || 0);
this._setPrjCenter(pcenter);
return this;
}
Expand Down