Skip to content

Layers & Descriptors

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.

navara_three has 4 types of Descriptors:

Descriptor TypeDescriptionMethod
LayerRenders geographic data from a SourceaddLayer() with a layer type ("vector", "raster", "terrain", "3d-tiles") + a source
Mesh DescAdds 3D mesh objects to the sceneaddMesh()
Effect DescApplies post-processing effectsaddEffect()
Light DescManages scene lightingaddLight()

Layers organize geographic data in a hierarchical structure:

Layer

FeatureSet

Feature

Batch

  • Layer: The top-level container added via addLayer(). Each layer has a unique LayerId.
  • FeatureSet: A rendering unit within a layer. Feature events (featureCreated, featureUpdated, etc.) are emitted per feature set, and each carries a FeatureSetId. 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 featureId when 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.

IdentifierIdentifiesRead fromLifetime
layerIdA layerlayer.id, FeatureInfo, picksUntil the layer is removed
featureSetIdA feature setevaluator.featureSetId, feature events, picksUntil the feature set is removed. A tile loaded again gets a new one
featureIdA source featureFeatureInfo, picksComes from the source data, so it does not change when tiles are reloaded
batchIdA batchFeatureInfo, picksUntil 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 by batchId can 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 is undefined when 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 that featureId values 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.

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 source property (a Source handle or its id)
  • 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 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(), or addLight()
  • 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,
},
});

The handle class returned from view.addLayer() / view.addMesh() / view.addEffect() / view.addLight() differs depending on the descriptor type:

Descriptor TypeReturned ClassMain Features
LayerLayerupdate(), delete(), forceUpdate(), feature events
Mesh / Effect / Light DescBaseHandle<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 configuration
layerHandle.update({ type: "vector", source, point: { color: 0x00ff00 } });
// Subscribe to feature events
layerHandle.on("featureCreated", ({ featureSetId }) => {
console.log("A feature set was created:", featureSetId);
});
// Delete the layer
layerHandle.delete();

BaseHandle (for Mesh / Effect / Light Descs)

Section titled “BaseHandle (for Mesh / Effect / Light Descs)”
// BoxMeshDesc must be registered
const 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 visibility
boxHandle.visible = false;
// Access the underlying Three.js object
const boxMesh = boxHandle.ref;
// Delete the object
boxHandle.delete();

For detailed API reference, see Descriptor Types.

AspectLayerMesh / Effect / Light Desc
PurposeRendering data from a source3D objects, effects, lighting
MethodaddLayer() with a layer type + sourceaddMesh(), addEffect(), addLight()
Pre-registrationNot requiredRequired (registerMesh / registerEffect / registerLight)
Number of MaterialsMultiple depending on the layer type1 Material per Descriptor
Handle ClassLayerBaseHandle<T>
Update MethodOverwrite with a complete configuration objectPartial updates are possible