Skip to content

Descriptor Types

In navara_three, Descriptors are classified into the following 4 types:

  1. Resource Layers - Layers that load and display geographic data from external data sources (raster tiles, terrain, GeoJSON, 3D Tiles, etc.)
  2. Mesh Descs - Descriptors that add 3D mesh objects to the scene
  3. Effect Descs - Descriptors that apply post-processing effects
  4. 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().

Type: string

Description: The unique identifier of the layer.

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.

Updates the layer settings.

Syntax:

update(l: LayerDescription): void

Parameters:

  • 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 settings
geoJsonHandle.update({
type: "vector",
source: geoJsonSource,
point: { color: 0x00ff00 },
});

Removes the layer from the scene and releases resources. Do not use the layer after deletion.

Syntax:

delete(): void

Example:

geoJsonHandle.delete();

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)[] }): void

Parameters:

  • options.batchIds: Re-evaluates only these features, identified by the batchId that evaluate callbacks and picked features carry. featureUpdated then fires only for the feature sets holding them, and evaluate() calls back only for them. Entries that are undefined or 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 with batchIds covers only some features of a set.

Example:

// Trigger re-evaluation after style changes
layer.forceUpdate();
// Re-evaluate only the feature the pointer left and the one it entered
let hovered: number | undefined;
view.on("featureHover", (info) => {
if (info?.batchId === hovered) return;
layer.forceUpdate({ batchIds: [hovered, info?.batchId] });
hovered = info?.batchId;
});

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 | undefined

Example:

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);
}
});

Description: Fires when a new feature set is created within the layer.

Handler Type:

(params: FeatureCreatedParams) => void

FeatureCreatedParams:

PropertyTypeDescription
featureSetIdFeatureSetIdUnique identifier of the created feature set
evaluatorFeatureEvaluatorEvaluator class used for feature styling
contentFeatureSetContent | undefinedThe 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);
});

Description: Fires when a feature set within the layer is updated.

Handler Type:

(params: FeatureUpdatedParams) => void

FeatureUpdatedParams:

PropertyTypeDescription
featureSetIdFeatureSetIdUnique identifier of the updated feature set
evaluatorFeatureEvaluatorEvaluator class used for feature styling
updatedAtnumberUpdate timestamp
batchIdsReadonlySet<number> | undefinedThe 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"),
};
});
});

Description: Fires when the visibility of a feature set changes.

Handler Type:

(params: FeatureVisibilityChangedParams) => void

FeatureVisibilityChangedParams:

PropertyTypeDescription
featureSetIdFeatureSetIdIdentifier of the feature set whose visibility changed
visiblebooleanWhether the feature set is now visible

Description: Fires when a feature set is removed from the layer.

Handler Type:

(params: FeatureRemovedParams) => void

FeatureRemovedParams:

PropertyTypeDescription
featureSetIdFeatureSetIdIdentifier of the removed feature set

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) => void

Tiles3dTileset:

PropertyTypeDescription
metadataTiles3dMetadataEntity | undefinedThe tileset’s own metadata entity
schemaRecord<string, unknown> | undefinedThe schema object of the tileset JSON

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) => void

Example:

layer.on("updated", (description) => {
console.log("Layer updated", description);
});

Description: Fires when the layer is deleted.

Handler Type:

() => void

Example:

layer.on("deleted", () => {
console.log("Layer has been deleted");
});

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:

() => void

Example:

layer.on("transitionStart", () => {
console.log("Features started moving");
});

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:

() => void

Example:

// Delete the layer once its features have faded out
layer.once("transitionEnd", () => layer.delete());
layer.forceUpdate(); // Its evaluate callback now returns show: false and opacity: 0 with a transition

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().

Type: string

Description: The unique identifier of the object.

Example:

// SkyMeshDesc must be registered
const skyHandle = view.addMesh<SkyMeshDesc>({ sky: {} });
console.log("Object ID:", skyHandle.id);

Type: boolean

Description: Whether the object is visible in the scene.

Example:

// Check visibility
console.log("Visible:", skyHandle.visible);
// Toggle visibility
skyHandle.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 registered
const skyHandle = view.addMesh<SkyMeshDesc>({ sky: {} });
// Access the underlying Descriptor instance
const skyDesc = skyHandle.ref;

Updates Descriptor settings with a partial update. Only the specified properties are changed. Others remain unchanged.

Syntax:

update(updates: UpdateConfig): void

Parameters:

  • updates: A partial configuration object containing the properties to update

Example:

// SkyMeshDesc must be registered
const skyHandle = view.addMesh<SkyMeshDesc>({ sky: {} });
// Update settings
skyHandle.update({ sky: { sunAngularRadius: 0.05 } });

Removes the object from the scene and releases resources. Do not use the handle after deletion.

Syntax:

delete(): void

Example:

skyHandle.delete();

Description: Fires when the object is deleted.

Handler Type:

() => void

Example:

skyHandle.on("deleted", () => {
console.log("Sky object has been deleted");
});

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.

  • Config - The Descriptor configuration type (extends BaseDescConfig)
  • UpdateConfig - Updatable configuration properties (extends BaseDescConfigUpdate)
  • Instance - The underlying Three.js object type that the Descriptor creates
  • CustomEvent - Additional custom events that the Descriptor can fire

Type: string

Description: The unique identifier of the object. Specified via config.id or auto-generated.

Type: boolean

Description: Gets or sets whether the object is currently visible.

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(): void

Called when the Descriptor configuration is updated via BaseHandle.update(). Override to handle custom configuration updates.

Syntax:

onUpdateConfig(updates: UpdateConfig): void

Parameters:

  • updates: The configuration properties being updated

Called when the object is removed via BaseHandle.delete(). Override to clean up resources. Remember to call super.onDestroy().

Syntax:

onDestroy(): void
import { BaseDesc, type BaseDescConfig } from "@navaramap/three";
import { BoxGeometry, Mesh, MeshBasicMaterial } from "three";
// Define custom configuration type
type MyBoxConfig = BaseDescConfig & {
size?: number;
color?: number;
};
// Create custom Descriptor
class 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();
}
}

Base configuration options common to all mesh, effect, and light descriptors.

PropertyTypeDefaultDescription
idstring | undefinedAuto-generatedCustom ID for the object
visibleboolean | undefinedtrueWhether to display the object