Skip to content

Commit 0e9285b

Browse files
refactor(core): tidy GlobeViewport anchor helpers
- Consolidate stray imports at the top of the file. - Document the two GLOBE_ZOOM_ANCHOR_* constants so the empirical damping behavior (start damping at 0.75 of the limb, never below 35% strength) is self-explanatory. - Add a JSDoc to _getRayToGlobe explaining it as the shared ray/sphere math helper for unproject + isPointOnGlobe + panByGlobeAnchor.
1 parent e60090a commit 0e9285b

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

modules/core/src/viewports/globe-viewport.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
// SPDX-License-Identifier: MIT
33
// Copyright (c) vis.gl contributors
44

5-
import {Matrix4} from '@math.gl/core';
5+
import {Matrix4, vec3, vec4} from '@math.gl/core';
6+
import {altitudeToFovy, fovyToAltitude, MAX_LATITUDE} from '@math.gl/web-mercator';
67
import Viewport from './viewport';
78
import {PROJECTION_MODE} from '../lib/constants';
8-
import {altitudeToFovy, fovyToAltitude} from '@math.gl/web-mercator';
9-
10-
import {vec3, vec4} from '@math.gl/core';
119

1210
const DEGREES_TO_RADIANS = Math.PI / 180;
1311
const RADIANS_TO_DEGREES = 180 / Math.PI;
1412
const EARTH_RADIUS = 6370972;
1513
export const GLOBE_RADIUS = 256;
14+
// Where along the screen-pixel-to-globe-center distance ratio the anchored
15+
// zoom starts losing strength. Below this ratio the anchor pins exactly; from
16+
// here to the limb (ratio = 1) the anchor blends toward MIN_STRENGTH so a
17+
// near-edge pixel doesn't snap the camera across the globe.
1618
const GLOBE_ZOOM_ANCHOR_DAMPING_START_RATIO = 0.75;
1719
const GLOBE_ZOOM_ANCHOR_MIN_STRENGTH = 0.35;
18-
import {MAX_LATITUDE} from '@math.gl/web-mercator';
1920

2021
function getDistanceScales() {
2122
const unitsPerMeter = GLOBE_RADIUS / EARTH_RADIUS;
@@ -193,6 +194,12 @@ export default class GlobeViewport extends Viewport {
193194
];
194195
}
195196

197+
/**
198+
* Builds the screen-pixel → globe-center ray and the intermediate ray/sphere
199+
* math reused by `unproject` (intersection point) and the public hit-test
200+
* helpers (`isPointOnGlobe`, `panByGlobeAnchor`). One function so the same
201+
* pixelUnprojectionMatrix work isn't duplicated.
202+
*/
196203
private _getRayToGlobe(
197204
xy: number[],
198205
{topLeft = true, targetZ}: {topLeft?: boolean; targetZ?: number} = {}

0 commit comments

Comments
 (0)