Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

feat: snap annotations to 3D surfaces (#3719)

Igor Dykhta5d71d1c1faa2
diff --git a/src/components/src/annotations/annotation-overlay.tsx b/src/components/src/annotations/annotation-overlay.tsx
index 99704f456..fb3d798e7 100644
--- a/src/components/src/annotations/annotation-overlay.tsx
+++ b/src/components/src/annotations/annotation-overlay.tsx
@@ -18,6 +18,7 @@ import AnnotationNode from './annotation-node';
import AnnotationText from './annotation-text';
import {
MapViewport,
+ PickWorldPosition,
isPointVisibleOnGlobe,
movePoint,
moveText,
@@ -57,6 +58,7 @@ export type AnnotationOverlayProps = {
mapIndex: number;
viewport: MapViewport;
isGlobeEnabled?: boolean;
+ pickWorldPosition?: PickWorldPosition;
updateAnnotation: ActionHandler<typeof updateAnnotation>;
setSelectedAnnotation: ActionHandler<typeof setSelectedAnnotation>;
};
@@ -69,6 +71,7 @@ const AnnotationOverlay: FC<AnnotationOverlayProps> = ({
mapIndex,
viewport,
isGlobeEnabled,
+ pickWorldPosition,
updateAnnotation: onUpdateAnnotation,
setSelectedAnnotation: onSetSelectedAnnotation
}) => {
@@ -137,10 +140,10 @@ const AnnotationOverlay: FC<AnnotationOverlayProps> = ({
let changes: Partial<Annotation> = {};
switch (handleKind) {
case 'MOVE_POINT':
- changes = movePoint(draggedAnn, ev.delta, viewport);
+ changes = movePoint(draggedAnn, ev.delta, viewport, pickWorldPosition);
break;
case 'MOVE_TEXT':
- changes = moveText(draggedAnn, ev.delta, viewport);
+ changes = moveText(draggedAnn, ev.delta, viewport, pickWorldPosition);
break;
case 'RESIZE':
changes = resizeCircle(draggedAnn, ev.delta, viewport);
@@ -150,7 +153,7 @@ const AnnotationOverlay: FC<AnnotationOverlayProps> = ({
onUpdateAnnotation(annId, changes);
}
},
- [viewport, onUpdateAnnotation]
+ [viewport, onUpdateAnnotation, pickWorldPosition]
);
const handleDragEnd = useCallback((_ev: DragEndEvent) => {
diff --git a/src/components/src/annotations/annotation-utils.ts b/src/components/src/annotations/annotation-utils.ts
index 72f09c3fd..bd7326d69 100644
--- a/src/components/src/annotations/annotation-utils.ts
+++ b/src/components/src/annotations/annotation-utils.ts
@@ -14,9 +14,11 @@ import {
textPlacementFromAngle
} from '@kepler.gl/constants';
+export type LngLatAltitude = [number, number] | [number, number, number];
+
export type MapViewport = {
- project: (lngLat: [number, number]) => [number, number];
- unproject: (xy: [number, number]) => [number, number];
+ project: (lngLat: ReadonlyArray<number>) => number[];
+ unproject: (xy: ReadonlyArray<number>) => number[];
longitude: number;
latitude: number;
width: number;
@@ -24,6 +26,11 @@ export type MapViewport = {
zoom: number;
};
+/** Screen-space pick that returns a world position, optionally with altitude. */
+export type PickWorldPosition = (
+ screen: [number, number]
+) => ReadonlyArray<number> | null | undefined;
+
export type BaseAnnotationMarker = {
kind: AnnotationKind;
x: number;
@@ -45,14 +52,20 @@ function degreesToRadians(degree: number): number {
return degree * (Math.PI / 180);
}
-function calcRadius(
- viewport: MapViewport,
- point: [number, number],
- radiusInMeters: number
-): number {
+function offsetLngLatByMeters(point: LngLatAltitude, eastMeters: number): LngLatAltitude {
+ const shifted = addMetersToLngLat(point, [eastMeters, 0, 0]);
+ // addMetersToLngLat returns [lng, lat]; keep altitude so rim and center
+ // project from the same height.
+ const altitude = point[2];
+ if (altitude !== undefined && Number.isFinite(altitude)) {
+ return [shifted[0], shifted[1], altitude];
+ }
+ return [shifted[0], shifted[1]];
+}
+
+function calcRadius(viewport: MapViewport, point: LngLatAltitude, radiusInMeters: number): number {
const [x, y] = viewport.project(point);
- const shifted = addMetersToLngLat(point, [radiusInMeters, 0, 0]) as [number, number];
- const [x1, y1] = viewport.project(shifted);
+ const [x1, y1] = viewport.project(offsetLngLatByMeters(point, radiusInMeters));
const dx = x1 - x;
const dy = y1 - y;
return Math.sqrt(dx * dx + dy * dy);
@@ -154,8 +167,20 @@ export function getAnnotationTextBoxStyle(
return style;
}
+export function normalizeAnchorPoint(
+ coord: ReadonlyArray<number> | null | undefined
+): LngLatAltitude | null {
+ if (!coord || coord.length < 2 || !Number.isFinite(coord[0]) || !Number.isFinite(coord[1])) {
+ return null;
+ }
+ if (coord.length >= 3 && Number.isFinite(coord[2])) {
+ return [coord[0], coord[1], coord[2]];
+ }
+ return [coord[0], coord[1]];
+}
+
/** Great-circle angular distance between two lng/lat points, in degrees. */
-function angularDistanceDeg(a: [number, number], b: [number, number]): number {
+function angularDistanceDeg(a: ReadonlyArray<number>, b: ReadonlyArray<number>): number {
const toRad = Math.PI / 180;
const phi1 = a[1] * toRad;
const phi2 = b[1] * toRad;
@@ -183,7 +208,10 @@ const GLOBE_VISIBILITY_TOLERANCE_DEG = 0.5;
* first and the point is occluded. This uses the real projection math, so it
* follows the true horizon and adapts to zoom/altitude automatically.
*/
-export function isPointVisibleOnGlobe(point: [number, number], viewport: MapViewport): boolean {
+export function isPointVisibleOnGlobe(
+ point: ReadonlyArray<number>,
+ viewport: MapViewport
+): boolean {
const projected = viewport.project(point);
if (!projected || !Number.isFinite(projected[0]) || !Number.isFinite(projected[1])) {
return false;
@@ -198,24 +226,31 @@ export function isPointVisibleOnGlobe(point: [number, number], viewport: MapView
export function movePoint(
annotation: Annotation,
delta: {x: number; y: number},
- viewport: MapViewport
+ viewport: MapViewport,
+ pickWorldPosition?: PickWorldPosition
): Partial<Annotation> {
const {anchorPoint} = annotation;
const [px, py] = viewport.project(anchorPoint);
- const [lon, lat] = viewport.unproject([px + delta.x, py + delta.y]);
- return {anchorPoint: [lon, lat]};
+ const screen: [number, number] = [px + delta.x, py + delta.y];
+ const picked = normalizeAnchorPoint(pickWorldPosition?.(screen));
+ if (picked) {
+ return {anchorPoint: picked};
+ }
+ const [lon, lat] = viewport.unproject(screen);
+ return {anchorPoint: Number.isFinite(lon) && Number.isFinite(lat) ? [lon, lat] : anchorPoint};
}
export function moveText(
annotation: Annotation,
delta: {x: number; y: number},
- viewport: MapViewport
+ viewport: MapViewport,
+ pickWorldPosition?: PickWorldPosition
): Partial<Annotation> {
const marker = makeMarker(annotation, viewport);
const {kind, tx, ty} = marker;
if (kind === AnnotationKind.TEXT) {
- return movePoint(annotation, delta, viewport);
+ return movePoint(annotation, delta, viewport, pickWorldPosition);
}
if (!isAnnotationWithArm(annotation)) {
return {};
@@ -252,12 +287,13 @@ export function resizeCircle(
): Partial<Annotation> {
if (annotation.kind !== AnnotationKind.CIRCLE) return {};
const {anchorPoint, radiusInMeters} = annotation;
- const shifted = addMetersToLngLat(anchorPoint, [radiusInMeters, 0, 0]) as [number, number];
- const [x] = viewport.project(shifted);
- const newPoint = viewport.unproject([x + delta.x, viewport.project(anchorPoint)[1]]);
- const dx = newPoint[0] - anchorPoint[0];
- const currentRadius = shifted[0] - anchorPoint[0];
- const ratio = currentRadius !== 0 ? (currentRadius + dx) / currentRadius : 1;
+ // Scale by the on-screen radius at the anchor's altitude. Unprojecting onto
+ // the ground plane would change radius with pitch even when delta.x is 0.
+ const currentScreenRadius = calcRadius(viewport, anchorPoint, radiusInMeters);
+ if (!(currentScreenRadius > 0)) {
+ return {radiusInMeters: Math.max(0, radiusInMeters)};
+ }
+ const ratio = (currentScreenRadius + delta.x) / currentScreenRadius;
return {radiusInMeters: Math.max(0, radiusInMeters * ratio)};
}
diff --git a/src/components/src/index.ts b/src/components/src/index.ts
index 360c82958..bc8fe7dd7 100644
--- a/src/components/src/index.ts
+++ b/src/components/src/index.ts
@@ -388,9 +388,10 @@ export {
angleForTextPlacement,
textPlacementFromAngle,
getAnnotationTextBoxStyle,
- isPointVisibleOnGlobe
+ isPointVisibleOnGlobe,
+ normalizeAnchorPoint
} from './annotations';
-export type {MapViewport, AnnotationMarker} from './annotations';
+export type {MapViewport, AnnotationMarker, PickWorldPosition, LngLatAltitude} from './annotations';
export {default as AnnotationControlFactory} from './map/annotations/annotation-control';
export {default as ColorBreaksPanelFactory} from './side-panel/layer-panel/color-breaks-panel';
diff --git a/src/components/src/map-container.tsx b/src/components/src/map-container.tsx
index 73a3c8a2f..876aacf2c 100644
--- a/src/components/src/map-container.tsx
+++ b/src/components/src/map-container.tsx
@@ -734,8 +734,8 @@ export default function MapContainerFactory(
const mergedState = {...mapState, ...internalViewState, width, height};
const vp = getViewportFromMapState(mergedState) as any;
const viewport = {
- project: (lngLat: [number, number]) => vp.project(lngLat) as [number, number],
- unproject: (xy: [number, number]) => vp.unproject(xy) as [number, number],
+ project: (lngLat: ReadonlyArray<number>) => vp.project(lngLat),
+ unproject: (xy: ReadonlyArray<number>) => vp.unproject(xy),
longitude,
latitude,
width,
@@ -746,6 +746,34 @@ export default function MapContainerFactory(
return viewport;
}
+ _pickAnnotationWorldPosition = (xy: [number, number]): number[] | null => {
+ const deck = this._deck;
+ if (!deck || typeof deck.pickObject !== 'function') {
+ return null;
+ }
+ try {
+ const info = deck.pickObject({
+ x: xy[0],
+ y: xy[1],
+ radius: 0,
+ unproject3D: true
+ });
+ const coordinate = info?.coordinate;
+ // Only accept a reconstructed 3D hit. A 2D unproject (no depth) is the
+ // same as the ground-plane fallback in movePoint.
+ if (
+ !Array.isArray(coordinate) ||
+ coordinate.length < 3 ||
+ !Number.isFinite(coordinate[2])
+ ) {
+ return null;
+ }
+ return coordinate;
+ } catch {
+ return null;
+ }
+ };
+
_onDeckError = (error, layer) => {
const errorMessage = error?.message || 'unknown-error';
const layerMessage = layer?.id ? ` in ${layer.id} layer` : '';
@@ -1001,6 +1029,7 @@ export default function MapContainerFactory(
mapboxApiAccessToken,
mapboxApiUrl,
layersForDeck,
+ isAnnotationMode: Boolean(mapControls?.annotation?.active),
editorInfo: primaryMap
? {
editor,
@@ -1500,6 +1529,7 @@ export default function MapContainerFactory(
mapIndex={index || 0}
viewport={this._getAnnotationViewport(mapState, internalViewState)}
isGlobeEnabled={Boolean(mapState.globe?.enabled)}
+ pickWorldPosition={this._pickAnnotationWorldPosition}
updateAnnotation={visStateActions.updateAnnotation}
setSelectedAnnotation={visStateActions.setSelectedAnnotation}
/>
diff --git a/src/deckgl-layers/src/3d-building-layer/3d-building-layer.ts b/src/deckgl-layers/src/3d-building-layer/3d-building-layer.ts
index cba5fcb37..ec8e0704b 100644
--- a/src/deckgl-layers/src/3d-building-layer/3d-building-layer.ts
+++ b/src/deckgl-layers/src/3d-building-layer/3d-building-layer.ts
@@ -29,6 +29,7 @@ export default class ThreeDBuildingLayer extends CompositeLayer<ThreeDBuildingLa
return [
new DeckGLTileLayer({
id: `${this.id}-deck-3d-building` as string,
+ pickable: this.props.pickable,
getTileData: (tile: TileLoadProps) =>
getTileData(this.props.mapboxApiUrl, this.props.mapboxApiAccessToken, tile),
minZoom: 13,
diff --git a/src/deckgl-layers/src/3d-building-layer/types.ts b/src/deckgl-layers/src/3d-building-layer/types.ts
index 76524f9e2..860041cdd 100644
--- a/src/deckgl-layers/src/3d-building-layer/types.ts
+++ b/src/deckgl-layers/src/3d-building-layer/types.ts
@@ -20,6 +20,7 @@ export type ThreeDBuildingLayerProps = {
mapboxApiAccessToken: string;
mapboxApiUrl: string;
threeDBuildingColor: RGBColor;
+ pickable?: boolean;
updateTriggers: {
getFillColor: RGBColor;
};
diff --git a/src/layers/src/geojson-layer/geojson-layer.ts b/src/layers/src/geojson-layer/geojson-layer.ts
index dd7f31c00..a1cb8d5ea 100644
--- a/src/layers/src/geojson-layer/geojson-layer.ts
+++ b/src/layers/src/geojson-layer/geojson-layer.ts
@@ -108,7 +108,8 @@ export const geojsonVisConfigs: {
elevationScale: {
...LAYER_VIS_CONFIGS.elevationScale,
focusRange: [0, 1],
- focusWeight: 0.3
+ focusWeight: 0.3,
+ step: 0.01
},
stroked: 'stroked',
filled: 'filled',
@@ -807,7 +808,9 @@ export default class GeoJsonLayer extends Layer {
opacity: visConfig.strokeOpacity
};
- const pickable = interactionConfig.tooltip.enabled && visConfig.allowHover;
+ const pickable =
+ (interactionConfig.tooltip.enabled && visConfig.allowHover) ||
+ Boolean(opts.experimentalContext?.isAnnotationMode && visConfig.enable3d);
const hoverOverlayData = visConfig.enable3d ? null : this._getHoverOverlayData(objectHovered);
const {data, ...props} = dataProps;
diff --git a/src/layers/src/tile3d-layer/tile3d-layer.ts b/src/layers/src/tile3d-layer/tile3d-layer.ts
index 5232de896..344771c13 100644
--- a/src/layers/src/tile3d-layer/tile3d-layer.ts
+++ b/src/layers/src/tile3d-layer/tile3d-layer.ts
@@ -667,7 +667,9 @@ export default class Tile3DLayer extends Layer {
onTileUnload: this._onTileUnload,
getPointColor: pointColor,
pointSize: visConfig.pointSize ?? 2,
- pickable: false,
+ // Picking is off by default (no tooltip fields). Enable it while
+ // placing annotations so snap can reconstruct XYZ from mesh depth.
+ pickable: Boolean(opts.experimentalContext?.isAnnotationMode),
opacity: visConfig.opacity ?? 1,
extensions: EMPTY_EXTENSIONS,
parameters: DEPTH_TEST_PARAMS
diff --git a/src/reducers/src/layer-utils.ts b/src/reducers/src/layer-utils.ts
index 6cdd9ccc4..98e99522f 100644
--- a/src/reducers/src/layer-utils.ts
+++ b/src/reducers/src/layer-utils.ts
@@ -384,6 +384,7 @@ export type ComputeDeckLayersProps = {
mapboxApiAccessToken?: string;
mapboxApiUrl?: string;
primaryMap?: boolean;
+ isAnnotationMode?: boolean;
layersForDeck?: {[key: string]: boolean};
editorInfo?: {
editor: Editor;
@@ -430,6 +431,7 @@ function computeDeckLayersFromLayerOrder(
animationConfig: any;
mapLayers: any;
hasShadowEffect: boolean;
+ isAnnotationMode?: boolean;
},
layerCallbacks?: any
): any[] {
@@ -441,7 +443,8 @@ function computeDeckLayersFromLayerOrder(
interactionConfig,
animationConfig,
mapLayers,
- hasShadowEffect
+ hasShadowEffect,
+ isAnnotationMode
} = renderProps;
return layerOrder
.slice()
@@ -489,7 +492,8 @@ function computeDeckLayersFromLayerOrder(
animationConfig,
mapLayers,
experimentalContext: {
- hasShadowEffect
+ hasShadowEffect,
+ isAnnotationMode
}
},
bindedLayerCallbacks
@@ -518,8 +522,15 @@ export function computeDeckLayers(
splitMaps
} = visState;
- const {mapIndex, mapboxApiAccessToken, mapboxApiUrl, primaryMap, layersForDeck, editorInfo} =
- options || {};
+ const {
+ mapIndex,
+ mapboxApiAccessToken,
+ mapboxApiUrl,
+ primaryMap,
+ layersForDeck,
+ editorInfo,
+ isAnnotationMode
+ } = options || {};
let dataLayers: any[] = [];
@@ -555,7 +566,8 @@ export function computeDeckLayers(
interactionConfig,
animationConfig,
mapLayers,
- hasShadowEffect
+ hasShadowEffect,
+ isAnnotationMode
},
layerCallbacks
)
@@ -587,7 +599,8 @@ export function computeDeckLayers(
animationConfig,
mapLayers,
experimentalContext: {
- hasShadowEffect
+ hasShadowEffect,
+ isAnnotationMode
}
},
bindedLayerCallbacks
@@ -612,6 +625,7 @@ export function computeDeckLayers(
mapboxApiAccessToken,
mapboxApiUrl,
threeDBuildingColor: mapStyle.threeDBuildingColor,
+ pickable: Boolean(isAnnotationMode),
updateTriggers: {
getFillColor: mapStyle.threeDBuildingColor
}
diff --git a/src/reducers/src/vis-state-merger.ts b/src/reducers/src/vis-state-merger.ts
index e420ed690..e2befaddd 100644
--- a/src/reducers/src/vis-state-merger.ts
+++ b/src/reducers/src/vis-state-merger.ts
@@ -733,7 +733,8 @@ export function mergeAnnotations<S extends VisState>(state: S, annotations: any[
!existingIds.has(a.id) &&
isAnnotationKind(a.kind) &&
Array.isArray(a.anchorPoint) &&
- a.anchorPoint.length === 2
+ (a.anchorPoint.length === 2 || a.anchorPoint.length === 3) &&
+ a.anchorPoint.every(value => Number.isFinite(value))
)
.map(a => ({
isVisible: true,
diff --git a/src/types/annotations.d.ts b/src/types/annotations.d.ts
index 2056eb60d..d539ed638 100644
--- a/src/types/annotations.d.ts
+++ b/src/types/annotations.d.ts
@@ -16,7 +16,8 @@ export type BaseAnnotation = {
isVisible: boolean;
autoSize: boolean;
autoSizeY: boolean;
- anchorPoint: [number, number];
+ /** [lng, lat] or [lng, lat, altitudeMeters]. Missing altitude is treated as 0. */
+ anchorPoint: [number, number] | [number, number, number];
label: string;
editorState?: Record<string, any>;
mapIndex?: number;
diff --git a/test/node/reducers/annotation-merger-test.js b/test/node/reducers/annotation-merger-test.js
index a5b981188..f130afdbf 100644
--- a/test/node/reducers/annotation-merger-test.js
+++ b/test/node/reducers/annotation-merger-test.js
@@ -144,3 +144,20 @@ test('#mergeAnnotations -> should return same state when all annotations are inv
t.end();
});
+
+test('#mergeAnnotations -> should accept 3D anchorPoint', t => {
+ const state = makeState();
+ const annotations = [
+ makeAnnotation({id: 'xyz', anchorPoint: [-122.4, 37.8, 45]}),
+ makeAnnotation({id: 'too-long', anchorPoint: [1, 2, 3, 4]}),
+ makeAnnotation({id: 'nan-z', anchorPoint: [1, 2, Number.NaN]})
+ ];
+
+ const result = mergeAnnotations(state, annotations);
+
+ t.equal(result.annotations.length, 1, 'should only accept [lng, lat] or [lng, lat, alt]');
+ t.equal(result.annotations[0].id, 'xyz', 'should keep the 3D annotation');
+ t.deepEqual(result.annotations[0].anchorPoint, [-122.4, 37.8, 45], 'should keep altitude');
+
+ t.end();
+});
diff --git a/test/node/schemas/annotation-schema-test.js b/test/node/schemas/annotation-schema-test.js
index fe0ccad92..9e8ca9da4 100644
--- a/test/node/schemas/annotation-schema-test.js
+++ b/test/node/schemas/annotation-schema-test.js
@@ -233,3 +233,22 @@ test('#AnnotationsSchema -> saves only known properties', t => {
t.end();
});
+
+test('#AnnotationsSchema -> 3D anchorPoint round-trips', t => {
+ const original = [makePointAnnotation({anchorPoint: [-122.4, 37.8, 120]})];
+ const saved = schema.save(original);
+ const loaded = schema.load(saved.annotations);
+
+ t.deepEqual(
+ saved.annotations[0].anchorPoint,
+ [-122.4, 37.8, 120],
+ 'should save [lng, lat, altitude]'
+ );
+ t.deepEqual(
+ loaded.annotations[0].anchorPoint,
+ [-122.4, 37.8, 120],
+ 'should load [lng, lat, altitude]'
+ );
+
+ t.end();
+});
diff --git a/test/node/utils/annotation-utils-test.js b/test/node/utils/annotation-utils-test.js
index 2acffaf92..2dbd43b9f 100644
--- a/test/node/utils/annotation-utils-test.js
+++ b/test/node/utils/annotation-utils-test.js
@@ -12,11 +12,12 @@ import {
isBelowOriented,
getTextPlacement,
getAnnotationTextBoxStyle,
- isPointVisibleOnGlobe
+ isPointVisibleOnGlobe,
+ normalizeAnchorPoint
} from '@kepler.gl/components';
const mockViewport = {
- project: ([lng, lat]) => [lng * 10 + 500, lat * -10 + 300],
+ project: ([lng, lat, alt = 0]) => [lng * 10 + 500, lat * -10 + 300 - alt],
unproject: ([x, y]) => [(x - 500) / 10, (y - 300) / -10],
longitude: 0,
latitude: 0,
@@ -266,6 +267,54 @@ test('#movePoint -> zero delta returns same position', t => {
t.end();
});
+test('#movePoint -> uses pickWorldPosition xyz when provided', t => {
+ const annotation = makePointAnnotation({anchorPoint: [0, 0]});
+ const pickWorldPosition = () => [12.3, 45.6, 80];
+
+ const changes = movePoint(annotation, {x: 10, y: -5}, mockViewport, pickWorldPosition);
+
+ t.deepEqual(
+ changes.anchorPoint,
+ [12.3, 45.6, 80],
+ 'should persist reconstructed [lng, lat, altitude]'
+ );
+
+ t.end();
+});
+
+test('#movePoint -> falls back to ground plane when pick returns no altitude', t => {
+ const annotation = makePointAnnotation({anchorPoint: [0, 0]});
+ const pickWorldPosition = () => null;
+
+ const changes = movePoint(annotation, {x: 10, y: -5}, mockViewport, pickWorldPosition);
+
+ t.equal(changes.anchorPoint.length, 2, 'fallback should be [lon, lat]');
+ t.equal(changes.anchorPoint[0], 1, 'longitude should use viewport unproject');
+ t.equal(changes.anchorPoint[1], 0.5, 'latitude should use viewport unproject');
+
+ t.end();
+});
+
+test('#normalizeAnchorPoint', t => {
+ t.deepEqual(normalizeAnchorPoint([1, 2]), [1, 2], 'keeps 2D anchors');
+ t.deepEqual(normalizeAnchorPoint([1, 2, 3]), [1, 2, 3], 'keeps 3D anchors');
+ t.deepEqual(normalizeAnchorPoint([1, 2, 0]), [1, 2, 0], 'keeps zero altitude');
+ t.equal(normalizeAnchorPoint([1]), null, 'rejects incomplete coords');
+ t.equal(normalizeAnchorPoint(null), null, 'rejects null');
+
+ t.end();
+});
+
+test('#makeMarker -> projects altitude into screen y', t => {
+ const ground = makeMarker(makePointAnnotation({anchorPoint: [10, 20]}), mockViewport);
+ const raised = makeMarker(makePointAnnotation({anchorPoint: [10, 20, 15]}), mockViewport);
+
+ t.equal(raised.x, ground.x, 'longitude projection is unchanged by altitude');
+ t.equal(raised.y, ground.y - 15, 'altitude should shift screen y');
+
+ t.end();
+});
+
test('#moveText -> TEXT annotation delegates to movePoint', t => {
const annotation = makeTextAnnotation({anchorPoint: [0, 0]});
const delta = {x: 20, y: 10};
@@ -328,6 +377,57 @@ test('#resizeCircle -> radius cannot go below 0', t => {
t.end();
});
+test('#resizeCircle -> zero delta keeps radius for a 3D anchor', t => {
+ const annotation = makeCircleAnnotation({
+ anchorPoint: [10, 20, 80],
+ radiusInMeters: 1000
+ });
+ const pitchedViewport = {
+ ...mockViewport,
+ // Mimic pitch: altitude shifts y, so ground-plane unproject would drift.
+ project: ([lng, lat, alt = 0]) => [lng * 10 + 500 + alt * 0.2, lat * -10 + 300 - alt]
+ };
+
+ const changes = resizeCircle(annotation, {x: 0, y: 0}, pitchedViewport);
+
+ t.equal(changes.radiusInMeters, 1000, 'zero handle movement should not change radius');
+
+ t.end();
+});
+
+test('#resizeCircle -> scales radius by screen-space handle delta', t => {
+ const annotation = makeCircleAnnotation({
+ anchorPoint: [0, 0, 50],
+ radiusInMeters: 1000
+ });
+ const marker = makeMarker(annotation, mockViewport);
+ t.ok(marker.r > 0, 'circle should have a screen radius');
+
+ const doubled = resizeCircle(annotation, {x: marker.r, y: 0}, mockViewport);
+ t.equal(doubled.radiusInMeters, 2000, 'dragging the handle by one radius should double meters');
+
+ t.end();
+});
+
+test('#makeMarker -> CIRCLE screen radius is independent of altitude', t => {
+ const ground = makeMarker(
+ makeCircleAnnotation({anchorPoint: [10, 20], radiusInMeters: 1000}),
+ mockViewport
+ );
+ const raised = makeMarker(
+ makeCircleAnnotation({anchorPoint: [10, 20, 40], radiusInMeters: 1000}),
+ mockViewport
+ );
+
+ t.equal(
+ Math.round(raised.r * 1000) / 1000,
+ Math.round(ground.r * 1000) / 1000,
+ 'raised and ground circles should have the same screen radius in this projection'
+ );
+
+ t.end();
+});
+
test('#isPointVisibleOnGlobe -> front-facing point round-trips to itself', t => {
// A GlobeViewport-like mock where project/unproject are inverses: any point
// resolves back to itself, i.e. it is on the near (visible) hemisphere.