Layers & Descriptors
What is a Layer?
Section titled “What is a Layer?”In navara_three, elements displayed in the 3D scene are managed as “layers” and “Descriptors.” Map data rendering uses layers: a layer references a Source that says where the data comes from, and describes how that data is rendered. 3D object placement, post-processing effects, and lighting are added and controlled as Descriptors.
Descriptor Types
Section titled “Descriptor Types”navara_three has 4 types of Descriptors:
| Descriptor Type | Description | Method |
|---|---|---|
| Layer | Renders geographic data from a Source | addLayer() with a layer type ("vector", "raster", "terrain", "3d-tiles") + a source |
| Mesh Desc | Adds 3D mesh objects to the scene | addMesh() |
| Effect Desc | Applies post-processing effects | addEffect() |
| Light Desc | Manages scene lighting | addLight() |
Layer Data Structure
Section titled “Layer Data Structure”Layers organize geographic data in a hierarchical structure:
- Layer: The top-level container added via
addLayer(). Each layer has a uniqueLayerId. - FeatureSet: A rendering unit within a layer. Feature events (
featureCreated,featureUpdated, etc.) are emitted per feature set, and each carries aFeatureSetId. A single feature set may span multiple LOD levels. - Feature: One entity of the source data, such as a building or a road segment. It has properties, and a
featureIdwhen the source data gives it a top-level id. - Batch: A feature as rendered in one feature set. Each batch has a
batchId, which picking reports.
Features of vector tile sources, and GeoJSON polygons and polylines whose material sets clampToGround or tiled, are split across the tiles they cross. Each piece is a separate batch in its own feature set, with its own batchId, and all pieces share the feature’s featureId and properties.
Identifiers
Section titled “Identifiers”| Identifier | Identifies | Read from | Lifetime |
|---|---|---|---|
layerId | A layer | layer.id, FeatureInfo, picks | Until the layer is removed |
featureSetId | A feature set | evaluator.featureSetId, feature events, picks | Until the feature set is removed. A tile loaded again gets a new one |
featureId | A source feature | FeatureInfo, picks | Comes from the source data, so it does not change when tiles are reloaded |
batchId | A batch | FeatureInfo, picks | Until the feature set is removed. The number is then given to other batches |
batchId and featureId serve different purposes:
batchId: Every batch has one, whatever the source data, and it is unique among the batches currently rendered. Use it for a highlight that lasts only while the feature is on screen, such as on hover. For a feature split across tiles, it covers only the piece in one tile, and it changes when that tile is loaded again. The old number is then given to another batch, so a selection kept bybatchIdcan move to a different feature.featureId: It comes from the source data, so it does not change when tiles are reloaded, and matching by it styles every piece of the feature across tiles. Use it to keep a selection. It isundefinedwhen the source data has no top-level id: 3D Tiles never have one, and many GeoJSON and vector tile datasets omit it. Navara does not check thatfeatureIdvalues are unique.
To keep a selection in data without featureId, match by a stable property instead, such as gml_id in PLATEAU data.
For details on feature events (featureCreated, featureUpdated, etc.), see Layer Types.
Sources and Layers
Section titled “Sources and Layers”A layer does not fetch data itself. It references a Source. The source describes where the data is and how it is fetched/decoded (URL, zoom range, tiling scheme, elevation decoder). The layer describes how it renders (materials). One source can be shared by several layers.
// 1. Register a source (the data)const imagery = view.addSource({ type: "raster-tile", url: "https://example.com/{z}/{x}/{y}.png", maxZoom: 19,});
// 2. Add a layer that renders it (the styling)view.addLayer({ type: "raster", source: imagery, raster: { opacity: 0.8 } });See About Source for source types and Layer Types for the layer types and their render options.
Differences Between Layers and Other Descriptors
Section titled “Differences Between Layers and Other Descriptors”Layers render external geographic data, so they differ from mesh, effect, and light descriptors in how they are used.
Layers render a source such as GeoJSON, vector tiles, raster imagery, terrain, or 3D Tiles.
Characteristics:
- Specify the layer type for
type("vector","raster","terrain","3d-tiles") - Reference the data with the
sourceproperty (aSourcehandle or itsid) - Multiple Materials can be specified depending on the layer type
- Available Materials vary by layer type
// Vector layer example (a geojson / vector-tile source)const features = view.addSource({ type: "geojson", data: { type: "FeatureCollection", features: [] },});const vectorHandle = view.addLayer({ type: "vector", source: features, // A vector layer can take several materials at once point: { color: 0xff0000, size: 10 }, polyline: { color: 0x00ff00, width: 2 }, polygon: { color: 0x0000ff, opacity: 0.5 },});
// Terrain layer example (a raster-dem / quantized-mesh source)const dem = view.addSource({ type: "raster-dem", url: "https://example.com/dem/{z}/{x}/{y}.png", maxZoom: 15,});const terrainHandle = view.addLayer({ type: "terrain", source: dem, terrain: { castShadow: true, receiveShadow: true },});Mesh, Effect, and Light Descs
Section titled “Mesh, Effect, and Light Descs”Mesh descriptors, effect descriptors, and light descriptors create Three.js objects directly on the client side.
Characteristics:
- Use the dedicated method for each type:
addMesh(),addEffect(), oraddLight() - Each descriptor has a single Material (configuration object)
- The Material key name determines the descriptor type
- Descriptor class registration is required before use (
registerMesh,registerEffect,registerLight)
import { BoxMeshDesc, FXAAEffectDesc, SunLightDesc } from "@navaramap/three-default-descs";
// Register descriptor classes (required before addMesh/addEffect/addLight)view.registerMesh("box", BoxMeshDesc);view.registerEffect("fxaa", FXAAEffectDesc);view.registerLight("sun", SunLightDesc);
// Mesh descriptor example (BoxMeshDesc)const boxHandle = view.addMesh<BoxMeshDesc>({ box: { // Recognized as BoxMeshDesc by the box key width: 100, height: 100, },});
// Effect descriptor example (FXAAEffectDesc)const fxaaHandle = view.addEffect<FXAAEffectDesc>({ fxaa: { // Recognized as FXAAEffectDesc by the fxaa key },});
// Light descriptor example (SunLightDesc)const sunHandle = view.addLight<SunLightDesc>({ sun: { // Recognized as SunLightDesc by the sun key intensity: 1.0, castShadow: true, },});Differences in Returned Handle Classes
Section titled “Differences in Returned Handle Classes”The handle class returned from view.addLayer() / view.addMesh() / view.addEffect() / view.addLight() differs depending on the descriptor type:
| Descriptor Type | Returned Class | Main Features |
|---|---|---|
| Layer | Layer | update(), delete(), forceUpdate(), feature events |
| Mesh / Effect / Light Desc | BaseHandle<T> | update(), delete(), visible, ref (access to the base instance) |
const source = view.addSource({ type: "geojson", url: "https://example.com/data.geojson",});const layerHandle = view.addLayer({ type: "vector", source });
// Update by fully overwriting the configurationlayerHandle.update({ type: "vector", source, point: { color: 0x00ff00 } });
// Subscribe to feature eventslayerHandle.on("featureCreated", ({ featureSetId }) => { console.log("A feature set was created:", featureSetId);});
// Delete the layerlayerHandle.delete();BaseHandle (for Mesh / Effect / Light Descs)
Section titled “BaseHandle (for Mesh / Effect / Light Descs)”// BoxMeshDesc must be registeredconst boxHandle = view.addMesh<BoxMeshDesc>({ box: { width: 100, height: 100, depth: 100 },});
// Partial update (only the specified properties are changed)boxHandle.update({ box: { width: 200 } });
// Toggle visibilityboxHandle.visible = false;
// Access the underlying Three.js objectconst boxMesh = boxHandle.ref;
// Delete the objectboxHandle.delete();For detailed API reference, see Descriptor Types.
Summary
Section titled “Summary”| Aspect | Layer | Mesh / Effect / Light Desc |
|---|---|---|
| Purpose | Rendering data from a source | 3D objects, effects, lighting |
| Method | addLayer() with a layer type + source | addMesh(), addEffect(), addLight() |
| Pre-registration | Not required | Required (registerMesh / registerEffect / registerLight) |
| Number of Materials | Multiple depending on the layer type | 1 Material per Descriptor |
| Handle Class | Layer | BaseHandle<T> |
| Update Method | Overwrite with a complete configuration object | Partial updates are possible |
Related Resources
Section titled “Related Resources”- About Source - where layer data comes from
- Layer Types - layer types and render options
- Materials - styling (materials) reference
- three_default_descs - Default Descriptor details