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.
tileset
Section titled “tileset”Type: Tiles3dTileset | undefined
Description: The root tileset JSON of a 3d-tiles layer, once it has loaded (see tilesetLoaded). undefined until then, while a source update reloads it, and for other layer types. See 3D Tiles metadata.
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: featureUpdated fires for every feature set of the layer, and their evaluate callbacks run again.
Syntax:
forceUpdate(options?: { batchIds?: readonly (number | undefined)[] }): voidParameters:
options.batchIds: Re-evaluates only these features, identified by thebatchIdthat evaluate callbacks and picked features carry.featureUpdatedthen fires only for the feature sets holding them, andevaluate()calls back only for them. Entries that areundefinedor no longer loaded are skipped. A highlight that follows the pointer costs two features this way, however many features the layer holds. An evaluate callback returns every value on every evaluation: a value a feature already has costs no upload. A listener that keeps state between evaluations keeps it per feature, since an evaluation withbatchIdscovers only some features of a set.
Example:
// Trigger re-evaluation after style changeslayer.forceUpdate();
// Re-evaluate only the feature the pointer left and the one it enteredlet hovered: number | undefined;view.on("featureHover", (info) => { if (info?.batchId === hovered) return; layer.forceUpdate({ batchIds: [hovered, info?.batchId] }); hovered = info?.batchId;});getFeatureSetContent()
Section titled “getFeatureSetContent()”Returns the source content a feature set was loaded from: the same value as content in its featureCreated event. Returns undefined for a feature set without source content information, and once the feature set is removed.
Syntax:
getFeatureSetContent(featureSetId: FeatureSetId): FeatureSetContent | undefinedExample:
view.on("featureClick", (info) => { if (info?.featureSetId === undefined) return; const content = layer.getFeatureSetContent(info.featureSetId); if (content?.type === "3d-tiles") { console.log(content.credit, content.metadata?.tile); }});Events
Section titled “Events”featureCreated
Section titled “featureCreated”Description: Fires when a new feature set 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 |
content | FeatureSetContent | undefined | The source content the feature set was loaded from, discriminated by type. For 3D Tiles, { type: "3d-tiles", credit?, metadata? }: credit is the glTF asset.copyright, and metadata is the 3D Tiles metadata of the tile, content and group (see 3D Tiles metadata). undefined for other layers |
Example:
layer.on("featureCreated", ({ evaluator }) => { console.log("Feature set created:", evaluator.featureSetId);});featureUpdated
Section titled “featureUpdated”Description: Fires when a feature set 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 |
batchIds | ReadonlySet<number> | undefined | The batch ids given to forceUpdate({ batchIds }) when only those features are re-evaluated. undefined when every feature of the set is |
Example:
layer.on("featureUpdated", ({ evaluator }) => { evaluator.evaluate(({ properties }) => { const height = properties?.["height"] as number; return { color: new Color().setStyle(height > 50 ? "#ff0000" : "#00ff00"), }; });});featureVisibilityChanged
Section titled “featureVisibilityChanged”Description: Fires when the visibility of a feature set 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 set is removed from the layer.
Handler Type:
(params: FeatureRemovedParams) => voidFeatureRemovedParams:
| Property | Type | Description |
|---|---|---|
featureSetId | FeatureSetId | Identifier of the removed feature set |
tilesetLoaded
Section titled “tilesetLoaded”Description: Fires when a 3d-tiles layer loads its root tileset JSON, and again when a source update reloads it. The value is also available as tileset.
Handler Type:
(tileset: Tiles3dTileset) => voidTiles3dTileset:
| Property | Type | Description |
|---|---|---|
metadata | Tiles3dMetadataEntity | undefined | The tileset’s own metadata entity |
schema | Record<string, unknown> | undefined | The schema object of the tileset JSON |
updated
Section titled “updated”Description: Fires after update() (or view.updateLayerById()) applies a new configuration. The handler receives the configuration as it was passed in.
Handler Type:
(l: LayerDescription) => voidExample:
layer.on("updated", (description) => { console.log("Layer updated", description);});deleted
Section titled “deleted”Description: Fires when the layer is deleted.
Handler Type:
() => voidExample:
layer.on("deleted", () => { console.log("Layer has been deleted");});transitionStart
Section titled “transitionStart”Description: Fires on the first frame a transition of the layer’s features blends in, after its delay, when none of them was blending before.
Handler Type:
() => voidExample:
layer.on("transitionStart", () => { console.log("Features started moving");});transitionEnd
Section titled “transitionEnd”Description: Fires after the frame the last running transition of the layer’s features ends in. A feature set removed while it moves, such as a tile that unloads, counts as ended, and so do the transitions running when the view is disposed: it fires during view.dispose(), after the meshes are removed.
Handler Type:
() => voidExample:
// Delete the layer once its features have faded outlayer.once("transitionEnd", () => layer.delete());layer.forceUpdate(); // Its evaluate callback now returns show: false and opacity: 0 with a transitionBaseHandle
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 |