Skip to content

Commit cf4c1c0

Browse files
committed
fix: Clamps tilt value to prevent error.
1 parent b9ce0ca commit cf4c1c0

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

samples/3d-camera-position/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ async function initMap(): Promise<void> {
3636
// Update values on UI when the map changes.
3737
const updateUI = () => {
3838
const heading = map3DElement.heading?.toFixed(0) ?? '0';
39-
const tilt = map3DElement.tilt?.toFixed(0) ?? '0';
39+
const rawTilt = map3DElement.tilt ?? 0;
40+
const tilt = Math.max(0, rawTilt).toFixed(0);
4041
const range = map3DElement.range?.toFixed(0) ?? '0';
4142
const rawFov = parseFloat(map3DElement.fov?.toFixed(0) ?? '45');
4243
const fovClamped = Math.min(80, Math.max(5, rawFov));
@@ -121,8 +122,9 @@ async function initMap(): Promise<void> {
121122
};
122123
}
123124
} else {
125+
const finalVal = prop === 'tilt' ? Math.max(0, val) : val;
124126
// eslint-disable-next-line @typescript-eslint/no-explicit-any
125-
(map3DElement as any)[prop] = val;
127+
(map3DElement as any)[prop] = finalVal;
126128
}
127129
updateUI();
128130
});
@@ -136,7 +138,12 @@ async function initMap(): Promise<void> {
136138

137139
// Update UI on camera change events.
138140
map3DElement.addEventListener('gmp-headingchange', updateUI);
139-
map3DElement.addEventListener('gmp-tiltchange', updateUI);
141+
map3DElement.addEventListener('gmp-tiltchange', () => {
142+
if ((map3DElement.tilt ?? 0) < 0) {
143+
map3DElement.tilt = 0;
144+
}
145+
updateUI();
146+
});
140147
map3DElement.addEventListener('gmp-rangechange', updateUI);
141148
map3DElement.addEventListener('gmp-fovchange', updateUI);
142149

0 commit comments

Comments
 (0)