Skip to content

ThreeViewCamera Class

The ThreeViewCamera class manages the camera’s position, orientation, projection, and interactive control behavior. It is accessed via the camera property of a ThreeView instance.

import ThreeView from "@navaramap/three";
const view = new ThreeView({ container: element });
await view.init();
const camera = view.camera;

Type: PerspectiveCamera

Read-only

The underlying Three.js PerspectiveCamera. Use this for read-only integration with Three.js APIs, such as reading the camera matrix or world position.

Do not write to raw.fov (or other frustum fields) directly — the engine synchronizes raw.fov from its internal frustum state, so direct writes will be overwritten and can leave the Rust-side culling state out of sync. Use the fov setter instead.

Example:

// Read the camera's world position
const position = view.camera.raw.position;
// Set FOV through the ThreeViewCamera setter (keeps engine frustum in sync)
view.camera.fov = 60;

Type: { x: number; y: number; z: number }

Read-only

The camera’s current position in Earth-Centered, Earth-Fixed (ECEF) coordinates (meters).

Example:

const pos = view.camera.positionECEF;
console.log(`ECEF: ${pos.x}, ${pos.y}, ${pos.z}`);

Type: { lng: number; lat: number; height: number }

Read-only

The camera’s current position in geographic coordinates.

  • lng: Longitude (degrees)
  • lat: Latitude (degrees)
  • height: Height above the ellipsoid (meters)

Example:

const pos = view.camera.positionGeographic;
console.log(`Lng: ${pos.lng}, Lat: ${pos.lat}, Height: ${pos.height}m`);

Type: { heading: number; pitch: number; roll: number }

Read-only

The camera’s current orientation.

  • heading: Azimuth angle (degrees, 0 = North, clockwise)
  • pitch: Elevation angle (degrees, negative = looking down)
  • roll: Roll angle (degrees)

Example:

const { heading, pitch, roll } = view.camera.orientation;
console.log(`Heading: ${heading}°, Pitch: ${pitch}°, Roll: ${roll}°`);

Type: number | undefined

Read-only

The current vertical field of view in degrees. Returns undefined if the engine is not yet initialized.

Example:

const fov = view.camera.fovy;
if (fov !== undefined) {
console.log(`Vertical FOV: ${fov}°`);
}

Type: number (setter)

Sets the vertical field of view in degrees. Valid range: 1180. Values outside this range are ignored.

Example:

// Narrow FOV for a telephoto effect
view.camera.fov = 30;
// Wide FOV for a panoramic effect
view.camera.fov = 90;

Type: number (getter / setter)

The near clipping plane distance (meters). Must be greater than 0.

Example:

// Read the current near plane
console.log(view.camera.near);
// Set the near plane
view.camera.near = 0.5;

Type: number (getter / setter)

The far clipping plane distance (meters). Must be greater than near.

Example:

// Read the current far plane
console.log(view.camera.far);
// Set the far plane
view.camera.far = 1e9;

Type: CameraOptions (setter)

Configures the camera’s interactive control behavior. All fields are optional; only the specified fields are updated.

type CameraOptions = {
autoAdjustNearFar?: boolean;
minimumZoomDistance?: number;
maximumZoomDistance?: number;
spinSpeed?: number;
zoomSpeed?: number;
spinDuration?: number;
zoomDuration?: number;
translateDuration?: number;
enableSpin?: boolean;
enableZoom?: boolean;
enableTilt?: boolean;
};
OptionTypeDefaultDescription
autoAdjustNearFarbooleantrueAutomatically adjust near/far clipping planes based on camera altitude
minimumZoomDistancenumber~6,356,752Minimum zoom distance from the Earth’s surface (meters)
maximumZoomDistancenumber~63,567,523Maximum zoom distance from the Earth’s surface (meters)
spinSpeednumber2.0Multiplier for mouse drag rotation speed
zoomSpeednumber0.6Multiplier for scroll wheel zoom speed
spinDurationnumber500Spin inertia duration after releasing mouse drag (ms)
zoomDurationnumber100Zoom inertia duration after scroll wheel input (ms)
translateDurationnumber500Translation inertia duration (ms)
enableSpinbooleantrueWhether drag/swipe rotation is enabled
enableZoombooleantrueWhether scroll wheel and pinch/spread zoom are enabled
enableTiltbooleantrueWhether tilt interactions (Ctrl+left drag, right-click drag, double-swipe, or rotate gestures) are enabled

Example:

// Disable all interactive controls (e.g. for programmatic camera only)
view.camera.options = {
enableSpin: false,
enableZoom: false,
enableTilt: false,
};
// Tune inertia feel
view.camera.options = {
spinDuration: 1000,
zoomDuration: 50,
translateDuration: 800,
};
// Restrict zoom range for a fixed-altitude application
view.camera.options = {
minimumZoomDistance: 500,
maximumZoomDistance: 5_000_000,
};

ThreeViewCamera inherits from EventHandler and emits the following events. Subscribe with on() and unsubscribe with off().

Fired once when the camera begins moving (user interaction or programmatic animation).

Handler type: () => void

Example:

view.camera.on("movestart", () => {
console.log("Camera started moving");
});

Fired every frame while the camera is in motion.

Handler type: () => void

Example:

view.camera.on("move", () => {
const pos = view.camera.positionGeographic;
console.log(`Moving — height: ${pos.height.toFixed(0)}m`);
});

Fired once when the camera stops moving.

Handler type: () => void

Example:

view.camera.on("moveend", () => {
const pos = view.camera.positionGeographic;
console.log(`Stopped at lng=${pos.lng.toFixed(4)}, lat=${pos.lat.toFixed(4)}`);
});

Fired when the camera’s frustum parameters change (FOV, near, or far plane).

Handler type: () => void

Example:

view.camera.on("frustumChanged", () => {
console.log(`FOV: ${view.camera.fovy}°`);
});

Subscribes to a camera event.

Syntax:

on(event: CameraEventName, handler: () => void): void

Example:

const handler = () => console.log("Camera moved");
view.camera.on("move", handler);

Unsubscribes a previously registered handler.

Syntax:

off(event: CameraEventName, handler: () => void): void

Example:

view.camera.off("move", handler);

Subscribes to a camera event for a single execution, then automatically unsubscribes.

Syntax:

once(event: CameraEventName, handler: () => void): void

Example:

view.camera.once("moveend", () => {
console.log("First move complete");
});