Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
HARP-11261: Fix zoomOnTargetPosition
Browse files Browse the repository at this point in the history
Camera target must be computed, since mapView.targetWorld might be
outdated, .e.g., during a zoom animation.

Signed-off-by: Andres Mandado <andres.mandado-almajano@here.com>
  • Loading branch information
atomicsulfate committed Jul 29, 2020
1 parent 4172c48 commit bbdecbd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
25 changes: 25 additions & 0 deletions @here/harp-map-controls/test/MapControlsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,31 @@ describe("MapControls", function() {
expect(initWorldDir.dot(endWorldDir)).closeTo(1, 1e-5);
});

it(`camera target is recomputed (pitch ${pitch})`, function() {
resetCamera(pitch, 5);
mapControls.maxTiltAngle = 90;

mapControls.zoomOnTargetPosition(0, 0.1, 6);
// tslint:disable-next-line: deprecation
const oldTarget = MapViewUtils.getTargetAndDistance(projection, camera)
.target;
const expAzimuth = MapViewUtils.extractSphericalCoordinatesFromLocation(
mapView,
camera,
projection.unprojectPoint(oldTarget)
).azimuth;
mapControls.zoomOnTargetPosition(0, 0.2, 7);
// tslint:disable-next-line: deprecation
const newTarget = MapViewUtils.getTargetAndDistance(projection, camera)
.target;
const actualAzimuth = MapViewUtils.extractSphericalCoordinatesFromLocation(
mapView,
camera,
projection.unprojectPoint(newTarget)
).azimuth;
expect(actualAzimuth).to.be.closeTo(expAzimuth, 1e-5);
});

it(`zoom target stays at the same screen coords (pitch ${pitch})`, function() {
resetCamera(pitch);

Expand Down
10 changes: 9 additions & 1 deletion @here/harp-mapview/lib/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,15 @@ export namespace MapViewUtils {

// Get current target position in world space before we zoom.
const zoomTarget = rayCastWorldCoordinates(mapView, targetNDCx, targetNDCy, elevation);
const cameraTarget = mapView.worldTarget;

// Compute current camera target, it may not be the one set in MapView, e.g. when this
// function is called multiple times between frames.
// tslint:disable-next-line: deprecation
const cameraTarget = MapViewUtils.getTargetAndDistance(
projection,
camera,
elevationProvider
).target;
const newCameraDistance = calculateDistanceFromZoomLevel(mapView, zoomLevel);

if (mapView.geoMaxBounds) {
Expand Down

0 comments on commit bbdecbd

Please sign in to comment.