Skip to content

Commit

Permalink
Remove old transform, apply changes to mercator transform.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrneumann committed Sep 30, 2024
1 parent cd88615 commit 9940ea5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1,084 deletions.
20 changes: 20 additions & 0 deletions src/geo/projection/mercator_transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ export class MercatorTransform implements ITransform {
return mercatorCoveringTiles(this, options, this._invViewProjMatrix);
}

/**
* Recalculates the zoom.
*
* If any of the values would lead to an invalid zoom, the recalculation is
* skipped and an error logged to the console.
*
* @param terrain - the terrain
*/
recalculateZoom(terrain: Terrain): void {
const origElevation = this.elevation;
const origAltitude = Math.cos(this._helper._pitch) * this._cameraToCenterDistance / this._helper._pixelPerMeter;
Expand All @@ -281,6 +289,18 @@ export class MercatorTransform implements ITransform {
const requiredScale = requiredWorldSize / this.tileSize;
const zoom = scaleZoom(requiredScale);

// First try the recalculation on a clone. If setting the zoom throws,
// don't recalculate the zoom.
const clonedTransform = this.clone();
clonedTransform.setElevation(elevation);
clonedTransform.setCenter(center);
try {
clonedTransform.setZoom(zoom);
} catch (_e) {
console.error(`Could not recalculate zoom. requiredScale: ${requiredScale}`);
return;
}

// update matrices
this._helper._elevation = elevation;
this._helper._center = center;
Expand Down
Loading

0 comments on commit 9940ea5

Please sign in to comment.