Lighting Methods
setSunlight
Updates the sun light position based on a given datetime and coordinates.Parameters
Date and time for calculating sun position
Coordinates for sun calculation. Can be
{lng, lat} object or [lng, lat] array. If omitted, uses map.getCenter()Example
defaultLights
Creates the default illumination for the Threebox scene.THREE.AmbientLight(assigned totb.lights.ambientLight)- Two
THREE.DirectionalLightinstances (assigned totb.lights.dirLightandtb.lights.dirLightBack)
Example
realSunlight
Creates illumination that simulates real sun light.Parameters
Whether to show a visual helper for the directional light
THREE.DirectionalLightwith shadow mappingTHREE.HemisphereLightfor ambient sky/ground lighting- Automatically positions light based on sun position using SunCalc
Example
Sun Position Methods
getSunPosition
Gets the sun position (azimuth, altitude) for a given date and coordinates.Parameters
Date and time for sun position calculation
Coordinates as
[lng, lat]Returns
Object with
azimuth and altitude properties in radiansExample
getSunSky
Gets the sun sky layer position for atmospheric rendering.Parameters
Date for calculation. If omitted, uses
new Date()Pre-calculated sun position. If omitted, calculates based on
map.getCenter()Returns
Array with
[azimuth, altitude] in degreesExample
getSunTimes
Gets sun times for different light phases (sunrise, sunset, etc.).Parameters
Date for sun times calculation
Coordinates as
[lng, lat, altitude] (altitude is optional)Returns
Object with Date properties for:
sunrise- Sunrise (top edge of sun appears)sunriseEnd- Sunrise ends (bottom edge touches horizon)goldenHourEnd- Morning golden hour endssolarNoon- Solar noon (sun at highest position)goldenHour- Evening golden hour startssunsetStart- Sunset startssunset- Sunset (sun disappears)dusk- Evening nautical twilight startsnauticalDusk- Evening astronomical twilight startsnight- Night startsnadir- Darkest momentnightEnd- Night endsnauticalDawn- Morning nautical twilight startsdawn- Morning civil twilight starts
Example
Coordinate Conversion
projectToWorld
Converts geographic coordinates to Three.js world coordinates.Parameters
Geographic coordinates as
[lng, lat]Returns
Three.js Vector3 in world space
Example
unprojectFromWorld
Converts Three.js world coordinates to geographic coordinates.Parameters
Three.js Vector3 in world space
Returns
Geographic coordinates with
lng and lat propertiesExample
projectedUnitsPerMeter
Gets the projected units per meter at a given latitude.Parameters
Latitude in degrees
Returns
Number of projected units per meter at the given latitude
Example
Query Methods
queryRenderedFeatures
Finds objects intersecting a screen point using raycasting.Parameters
Screen coordinates as
{x: number, y: number} (as returned by Mapbox mouse events as e.point)Returns
Array of intersected objects ordered by distance (closest first)
Example
findParent3DObject
Finds the parent Object3D from a mesh.Parameters
Mesh object (typically from raycaster intersection)
Returns
The parent Object3D in the Threebox scene
Example
Feature Utilities
getFeatureCenter
Calculates the center of a GeoJSON feature geometry.Parameters
GeoJSON feature
3D model (optional)
Level/floor number (optional)
Returns
Center coordinates as
[lng, lat, altitude]getObjectHeightOnFloor
Calculates the altitude for a GeoJSON feature at a given level.Parameters
GeoJSON feature
3D object (optional)
Level/floor number
Returns
Altitude in meters
Info Methods
memory
Returns memory information from the WebGL renderer.Returns
Memory info from
THREE.WebGLRenderer.info.memoryprograms
Returns the number of WebGL programs.Returns
Number of active WebGL programs
findParent3DObject
Finds the parent Object3D from a raycast intersection mesh.Parameters
Raycast intersection result containing an
object propertyReturns
The parent Object3D, or undefined if not found
Layer Management
setLayerZoomRange
Sets the zoom range for a layer and enables zoom-based visibility toggling.Parameters
Layer ID
Minimum zoom level
Maximum zoom level
setLayoutProperty
Sets a layout property on a Mapbox layer.Parameters
Layer ID
Property name (e.g., ‘visibility’)
Property value
toggleLayer
Toggles layer visibility based on zoom range.Parameters
Layer ID
Force visibility state (default: true)
toggle
Sets layer and label visibility.Parameters
Layer ID
Visibility state
Sky and Terrain Updates
updateSunGround
Updates terrain layer opacity based on sun position (for day/night effect).Parameters
Sun position object with
altitude property from getSunPosition()Example
updateSunSky
Updates the sky layer with new sun position parameters.Parameters
Sky parameters object from
getSunSky()