Descriptor Types
In navara_three, Descriptors are classified into the following 4 types:
- Resource Layers - Layers that load and display geographic data from external data sources (raster tiles, terrain, GeoJSON, 3D Tiles, etc.)
- Mesh Descs - Descriptors that add 3D mesh objects to the scene
- Effect Descs - Descriptors that apply post-processing effects
- Light Descs - Descriptors that manage scene lighting
Resource layers and other Descriptors (mesh, effect, light) return different handle classes.
A handle class for controlling resource layers (imagery, terrain, GeoJSON, 3D Tiles, etc.). Returned when adding a resource layer with ThreeView.addLayer().
Properties
Section titled “Properties”Type: string
Description: The unique identifier of the layer.
Methods
Section titled “Methods”update()
Section titled “update()”Updates the layer settings.
Syntax:
update(l: LayerDescription): voidParameters:
l: New layer settings
Example:
const geoJsonSource = view.addSource({ type: "geojson", url: "https://example.com/data.geojson",});
const geoJsonHandle = view.addLayer({ type: "vector", source: geoJsonSource, point: { color: 0xff0000 },});
// Update layer settingsgeoJsonHandle.update({ type: "vector", source: geoJsonSource, point: { color: 0x00ff00 },});delete()
Section titled “delete()”Removes the layer from the scene and releases resources. Do not use the layer after deletion.
Syntax:
delete(): voidExample:
geoJsonHandle.delete();forceUpdate()
Section titled “forceUpdate()”Marks the layer for update on the next frame. Call this when you need to trigger featureUpdated events.
Syntax:
forceUpdate(): voidExample:
// Trigger re-evaluation after style changeslayer.forceUpdate();Events
Section titled “Events”featureCreated
Section titled “featureCreated”Description: Fires when a new feature is created within the layer.
Handler Type:
(params: FeatureCreatedParams) => voidFeatureCreatedParams:
| Property | Type | Description |
|---|---|---|
featureSetId | FeatureSetId | Unique identifier of the created feature set |
evaluator | FeatureEvaluator | Evaluator class used for feature styling |
credit | string | undefined | Data source credit information (optional) |
Example:
layer.on("featureCreated", ({ evaluator }) => { console.log("Feature created:", evaluator.id);});featureUpdated
Section titled “featureUpdated”Description: Fires when a feature within the layer is updated.
Handler Type:
(params: FeatureUpdatedParams) => voidFeatureUpdatedParams:
| Property | Type | Description |
|---|---|---|
featureSetId | FeatureSetId | Unique identifier of the updated feature set |
evaluator | FeatureEvaluator | Evaluator class used for feature styling |
updatedAt | number | Update timestamp |
Example:
layer.on("featureUpdated", ({ evaluator }) => { evaluator.evaluate((_batchId, property) => { const height = property?.["height"] as number; return { color: new Color().setStyle(height > 50 ? "#ff0000" : "#00ff00"), }; });});featureVisibilityChanged
Section titled “featureVisibilityChanged”Description: Fires when the visibility of a feature changes.
Handler Type:
(params: FeatureVisibilityChangedParams) => voidFeatureVisibilityChangedParams:
| Property | Type | Description |
|---|---|---|
featureSetId | FeatureSetId | Identifier of the feature set whose visibility changed |
visible | boolean | Whether the feature set is now visible |
featureRemoved
Section titled “featureRemoved”Description: Fires when a feature is removed from the layer.
Handler Type:
(params: FeatureRemovedParams) => voidFeatureRemovedParams:
| Property | Type | Description |
|---|---|---|
featureSetId | FeatureSetId | Identifier of the removed feature set |
deleted
Section titled “deleted”Description: Fires when the layer is deleted.
Handler Type:
() => voidExample:
layer.on("deleted", () => { console.log("Layer has been deleted");});BaseHandle
Section titled “BaseHandle”A handle class for controlling mesh descriptors, light descriptors, and effect descriptors. Returned when adding a Descriptor with ThreeView.addMesh(), ThreeView.addLight(), or ThreeView.addEffect().
Properties
Section titled “Properties”Type: string
Description: The unique identifier of the object.
Example:
// SkyMeshDesc must be registeredconst skyHandle = view.addMesh<SkyMeshDesc>({ sky: {} });console.log("Object ID:", skyHandle.id);visible
Section titled “visible”Type: boolean
Description: Whether the object is visible in the scene.
Example:
// Check visibilityconsole.log("Visible:", skyHandle.visible);
// Toggle visibilityskyHandle.visible = false;Type: T (subclass of BaseDesc)
Description: Provides direct access to the underlying Descriptor instance. Use this to access Descriptor-specific methods and properties not exposed through the handle.
Example:
// SkyMeshDesc must be registeredconst skyHandle = view.addMesh<SkyMeshDesc>({ sky: {} });
// Access the underlying Descriptor instanceconst skyDesc = skyHandle.ref;Methods
Section titled “Methods”update()
Section titled “update()”Updates Descriptor settings with a partial update. Only the specified properties are changed; others remain unchanged.
Syntax:
update(updates: UpdateConfig): voidParameters:
updates: A partial configuration object containing the properties to update
Example:
// SkyMeshDesc must be registeredconst skyHandle = view.addMesh<SkyMeshDesc>({ sky: {} });
// Update settingsskyHandle.update({ sky: { sunAngularRadius: 0.05 } });delete()
Section titled “delete()”Removes the object from the scene and releases resources. Do not use the handle after deletion.
Syntax:
delete(): voidExample:
skyHandle.delete();Events
Section titled “Events”deleted
Section titled “deleted”Description: Fires when the object is deleted.
Handler Type:
() => voidExample:
skyHandle.on("deleted", () => { console.log("Sky object has been deleted");});BaseDesc
Section titled “BaseDesc”An abstract base class for mesh descriptors, light descriptors, and effect descriptors. Extend this class to create custom descriptor types.
These descriptors differ from resource layers in that they are purely client-side and do not load data from external sources. They directly create Three.js objects.
Type Parameters
Section titled “Type Parameters”Config- The Descriptor configuration type (extends BaseDescConfig)UpdateConfig- Updatable configuration properties (extends BaseDescConfigUpdate)Instance- The underlying Three.js object type that the Descriptor createsCustomEvent- Additional custom events that the Descriptor can fire
Properties
Section titled “Properties”Type: string
Description: The unique identifier of the object. Specified via config.id or auto-generated.
visible
Section titled “visible”Type: boolean
Description: Gets or sets whether the object is currently visible.
Methods
Section titled “Methods”onCreate() (abstract)
Section titled “onCreate() (abstract)”Called when the Descriptor is added to the scene. Override to create Three.js objects. You must initialize this._instance and add it to the appropriate scene here.
Syntax:
abstract onCreate(): voidonUpdateConfig()
Section titled “onUpdateConfig()”Called when the Descriptor configuration is updated via BaseHandle.update(). Override to handle custom configuration updates.
Syntax:
onUpdateConfig(updates: UpdateConfig): voidParameters:
updates: The configuration properties being updated
onDestroy()
Section titled “onDestroy()”Called when the object is removed via BaseHandle.delete(). Override to clean up resources. Remember to call super.onDestroy().
Syntax:
onDestroy(): voidExample
Section titled “Example”import { BaseDesc, type BaseDescConfig } from "@navaramap/three";import { BoxGeometry, Mesh, MeshBasicMaterial } from "three";
// Define custom configuration typetype MyBoxConfig = BaseDescConfig & { size?: number; color?: number;};
// Create custom Descriptorclass MyBoxDesc extends BaseDesc<MyBoxConfig, MyBoxConfig, Mesh> { private size: number; private color: number;
constructor(view: ThreeView, ctx: ViewContext, config: MyBoxConfig) { super(view, ctx, config); this.size = config.size ?? 1; this.color = config.color ?? 0xff0000; }
onCreate() { const geometry = new BoxGeometry(this.size, this.size, this.size); const material = new MeshBasicMaterial({ color: this.color }); this._instance = new Mesh(geometry, material); this.ctx.scenes.opaque.add(this._instance); }
onUpdateConfig(updates: MyBoxConfig) { super.onUpdateConfig(updates);
if (updates.color !== undefined && this._instance) { (this._instance.material as MeshBasicMaterial).color.set(updates.color); } }
onDestroy() { if (this._instance) { this.ctx.scenes.opaque.remove(this._instance); this._instance.geometry.dispose(); (this._instance.material as MeshBasicMaterial).dispose(); } super.onDestroy(); }}BaseDescConfig
Section titled “BaseDescConfig”Base configuration options common to all mesh, effect, and light descriptors.
| Property | Type | Default | Description |
|---|---|---|---|
id | string | undefined | Auto-generated | Custom ID for the object |
visible | boolean | undefined | true | Whether to display the object |