Skip to content

Commit 10ebfc9

Browse files
committed
fix map.pointAtResToAltitude when point < 0 which caused jumping when moving map with terrain below sea level
1 parent 4e86957 commit 10ebfc9

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

packages/maptalks/src/map/Map.Camera.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ Map.include(/** @lends Map.prototype */{
914914
// remains previous center altitude if queried altitude is null
915915
queriedAltitude = this.centerAltitude;
916916
}
917-
const centerAltitude = queriedAltitude || 0;
917+
const centerAltitude = queriedAltitude > 0 && queriedAltitude || 0;
918918
const pitch = this.getPitch() * RADIAN;
919919
const bearing = this.getBearing() * RADIAN;
920920
const altDist = (centerAltitude - this.centerAltitude) * this._meterToGLPoint;

packages/maptalks/src/map/Map.CoordTransform.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,23 +372,20 @@ Map.include(/** @lends Map.prototype */{
372372
this._altitudeOriginDirty = false;
373373
}
374374
const p = this.distanceToPointAtRes(altitude, altitude, res, originCenter || DEFAULT_CENTER, POINT);
375-
if (altitude < 0 && p.x > 0) {
376-
p.x = -p.x;
377-
}
378375
const heightFactor = this.options['heightFactor'];
379376
if (heightFactor && heightFactor !== 1) {
380377
p.x *= heightFactor;
381378
p.y *= heightFactor;
382379
}
383-
return p.x;
380+
return p.x * Math.sign(altitude);
384381
};
385382
}(),
386383

387384
pointAtResToAltitude: function () {
388385
const DEFAULT_CENTER = new Coordinate(0, 40);
389386
return function (point = 0, res, originCenter) {
390387
const altitude = this.pointAtResToDistance(point, 0, res, originCenter || DEFAULT_CENTER);
391-
return altitude;
388+
return altitude * Math.sign(point);
392389
};
393390
}(),
394391

0 commit comments

Comments
 (0)