Appearance
@bendyline/molen-terrain/kernel
Molen terrain capability: heightfield sampling (kernel) and chunked LOD meshing (client).
ts
import { /* … */ } from '@bendyline/molen-terrain/kernel';Classes
Heightfield
Constructors
Constructor
ts
new Heightfield(
grid,
cols,
rows,
opts
): Heightfield;grid holds normalized [0,1] heights, row-major, length = cols*rows.
Parameters
grid
Float32Array
cols
number
rows
number
opts
Returns
Properties
cellSize
ts
readonly cellSize: [number, number];Grid cell size in meters [x, z]; satisfies the kernel's GroundField contract.
cols
ts
readonly cols: number;heightRange
ts
readonly heightRange: object;The height range the normalized grid maps onto.
max
ts
max: number;min
ts
min: number;origin
ts
readonly origin: [number, number];World XZ of the field's (0,0) corner.
rows
ts
readonly rows: number;worldSize
ts
readonly worldSize: [number, number];World size in meters [width(x), depth(z)].
Methods
copySamples()
ts
copySamples(): Float32Array;Independent normalized samples for transfer to a worker; the resident field stays intact.
Returns
Float32Array
normalAt()
ts
normalAt(x, z): [number, number, number];Approximate surface normal at world (x, z) from the height gradient.
Parameters
x
number
z
number
Returns
[number, number, number]
raycastDown()
ts
raycastDown(x, z): number;The terrain surface height directly below/above (x, z) — same as sampleHeight for a heightmap.
Parameters
x
number
z
number
Returns
number
sampleHeight()
ts
sampleHeight(x, z): number;Bilinear-sampled terrain height (world Y in meters) at world (x, z).
Parameters
x
number
z
number
Returns
number
slopeAt()
ts
slopeAt(x, z): number;Slope at (x,z): 0 = flat, 1 = vertical.
Parameters
x
number
z
number
Returns
number
toRapierHeightfield()
ts
toRapierHeightfield(): HeightfieldCollider;The field as a physics heightfield collider: denormalized meters, transposed to the column-major layout rigid-body engines (Rapier/parry) expect, with the world center so the collider can be placed without an authored offset.
Returns
Interfaces
BridgeDeckOptions
Properties
approachLift
ts
approachLift: number;Lift above terrain at an end that meets a grade road (the road's surface lift).
clearance
ts
clearance: number;Clearance above terrain at an unconnected (clipped or free) end, in metres (6 roads, 3 paths).
connections?
ts
optional connections?: readonly object[];Authored deck endpoints in the path's frame, blended in over radius.
connects
ts
connects: readonly [boolean, boolean];Whether each end meets a grade road: [start, end].
deckElevation?
ts
optional deckElevation?: number;Surveyed absolute deck height; when present the deck is flat at this Y.
groundApproach?
ts
optional groundApproach?: boolean;A connected ground approach follows terrain, with only a local endpoint correction.
Gray16
Properties
data
ts
data: Float32Array;Normalized [0,1] values, row-major, length = width*height.
height
ts
height: number;width
ts
width: number;HeightfieldCollider
What a physics engine needs to build a heightfield collider from this field.
Properties
center
ts
center: [number, number, number];World position of the field's center (the collider is centered on its local origin).
heights
ts
heights: Float32Array;Denormalized heights (meters), column-major: heights[col * nrows + row].
ncols
ts
ncols: number;nrows
ts
nrows: number;scale
ts
scale: [number, number, number];Local x/y/z scale: [worldWidth, 1, worldDepth] (heights already carry meters).
HeightfieldOptions
Properties
height
ts
height: object;Height value range the normalized grid maps onto.
max
ts
max: number;min
ts
min: number;origin
ts
origin: [number, number];World XZ of the field's (0,0) corner.
worldSize
ts
worldSize: [number, number];World size in meters [width(x), depth(z)].
HeightmapGenOptions
Properties
frequency?
ts
optional frequency?: number;Base noise frequency across the map.
island?
ts
optional island?: boolean;Radial island falloff: heights taper to 0 at the edges.
octaves?
ts
optional octaves?: number;seed
ts
seed: number;size
ts
size: number;PmtilesArchiveOptions
Extended by
Properties
bounds
ts
bounds: readonly [number, number, number, number];[west, south, east, north] in degrees.
center?
ts
optional center?: readonly [number, number, number];[longitude, latitude, zoom]; defaults to the bounds center at minZoom.
metadata?
ts
optional metadata?: Record<string, unknown>;JSON metadata (TileJSON-like). Stored gzip-compressed, like every directory.
tileCompression?
ts
optional tileCompression?: PmtilesTileCompression;Compression of the tile payloads themselves (default 'none').
tileType
ts
tileType: PmtilesTileType;PmtilesDirectories
Properties
leafDirectoryCount
ts
leafDirectoryCount: number;leaves
ts
leaves: Uint8Array;Concatenated gzip-compressed leaf directories (empty when the root holds every entry).
root
ts
root: Uint8Array;gzip-compressed root directory, sized to fit the reader's initial fetch.
PmtilesDirectoryEntry
A directory entry: one tile run, or (with runLength 0) a pointer to a leaf directory.
Properties
length
ts
length: number;offset
ts
offset: number;runLength
ts
runLength: number;tileId
ts
tileId: number;PmtilesPrefixOptions
Extends
Properties
bounds
ts
bounds: readonly [number, number, number, number];[west, south, east, north] in degrees.
Inherited from
center?
ts
optional center?: readonly [number, number, number];[longitude, latitude, zoom]; defaults to the bounds center at minZoom.
Inherited from
maxZoom
ts
maxZoom: number;metadata?
ts
optional metadata?: Record<string, unknown>;JSON metadata (TileJSON-like). Stored gzip-compressed, like every directory.
Inherited from
PmtilesArchiveOptions.metadata
minZoom
ts
minZoom: number;tileCompression?
ts
optional tileCompression?: PmtilesTileCompression;Compression of the tile payloads themselves (default 'none').
Inherited from
PmtilesArchiveOptions.tileCompression
tileType
ts
tileType: PmtilesTileType;Inherited from
PmtilesArchiveOptions.tileType
PmtilesTileRecord
One tile's position in a caller-streamed tile-data block, sorted by tileId.
Properties
byteLength
ts
byteLength: number;tileId
ts
tileId: number;PmtilesWriterTile
One tile to archive. data is stored verbatim (already compressed if tileCompression says so).
Properties
data
ts
data: Uint8Array;x
ts
x: number;y
ts
y: number;z
ts
z: number;RenderedGroundSource
The part of a heightfield the sampler reads.
Properties
cols
ts
readonly cols: number;Methods
sampleHeight()
ts
sampleHeight(x, z): number;Parameters
x
number
z
number
Returns
number
TerrainArchiveHeader
Properties
maxZoom
ts
maxZoom: number;minZoom
ts
minZoom: number;tileType?
ts
optional tileType?: number;TerrainArchiveSetBase
The coarse archive serving every level from minLevel through maxLevel.
Properties
bytes?
ts
optional bytes?: number;maxLevel
ts
maxLevel: number;minLevel
ts
minLevel: number;sha256?
ts
optional sha256?: string;url
ts
url: string;Archive URL, relative to the archive-set document or absolute.
TerrainArchiveSetDescriptor
Properties
archives
ts
archives: TerrainArchiveSetEntry[];base?
ts
optional base?: TerrainArchiveSetBase;format
ts
format: "molen/archive-set@1";geohash?
ts
optional geohash?: TerrainArchiveSetGeohashTier[];Geohash-partitioned tiers, each over its own band of levels.
name
ts
name: string;partitionLevel?
ts
optional partitionLevel?: number;Level whose tiles partition the archives (at most 10: a 1M-cell lookup). Required when archives is not empty.
tileType
ts
tileType: TerrainArchiveSetTileType;Payload type shared by every archive in the set.
TerrainArchiveSetEntry
One detail archive and the partition cells it owns.
Properties
bounds?
ts
optional bounds?: [number, number, number, number];Informational [west, south, east, north] in degrees.
bytes?
ts
optional bytes?: number;id
ts
id: string;maxLevel
ts
maxLevel: number;minLevel
ts
minLevel: number;partitions
ts
partitions: string;Run-length list of partition indices (y * 2^partitionLevel + x), e.g. "40-44,60".
sha256?
ts
optional sha256?: string;url
ts
url: string;Archive URL, relative to the archive-set document or absolute.
TerrainArchiveSetGeohashTier
One archive per geohash cell for a band of levels.
Properties
cells
ts
cells: string;Run-length list of the cells that have an archive, as geohash indices (geohashIndex).
maxLevel
ts
maxLevel: number;minLevel
ts
minLevel: number;precision
ts
precision: number;Geohash length of a cell, 1-6 (3 is 1.40625° square, about 156 km at the equator).
url
ts
url: string;Archive URL template, relative to the document or absolute; {cell} becomes the geohash.
TerrainArchiveSetRouter
Properties
descriptor
ts
readonly descriptor: TerrainArchiveSetDescriptor;maxLevel
ts
readonly maxLevel: number;minLevel
ts
readonly minLevel: number;Coarsest and finest levels any archive in the set serves.
Methods
resolve()
ts
resolve(
level,
x,
y
): TerrainArchiveSetRoute | undefined;The archive holding XYZ tile level/x/y, or undefined when no archive covers it.
Parameters
level
number
x
number
y
number
Returns
TerrainArchiveSetRoute | undefined
TerrainArchiveTile
Properties
data
ts
data: ArrayBuffer;TerrainBuildingDetailChild
One descendant at the detail level and its tile, or undefined where the sidecar has none.
Properties
tile
ts
tile: TerrainSemanticTile | undefined;x
ts
x: number;z
ts
z: number;TerrainBuildingDetailOptions
Properties
cacheSize?
ts
optional cacheSize?: number;Recently loaded detail tiles kept for overlapping requests (default 48).
level
ts
level: number;The level the detail sidecar serves (e.g. 15 for Protomaps).
maxDepth?
ts
optional maxDepth?: number;How many levels coarser than level a tile may be and still be composed from it (default 2: a tile two levels up reads 16 detail tiles). Coarser tiles keep their own buildings.
TerrainBuildingFeature
Source identity and a bounded set of public map classification tags.
Extends
Properties
brand?
ts
optional brand?: string;brandId?
ts
optional brandId?: string;class?
ts
optional class?: string;heading?
ts
optional heading?: number;Rotation about +Y in radians; authored model front is +Z.
Inherited from
TerrainStructureIdentity.heading
height?
ts
optional height?: number;World-space height above the building base.
id?
ts
optional id?: string | number;layer?
ts
optional layer?: number;Source stacking layer (negative = underground); informational.
levels?
ts
optional levels?: number;minHeight?
ts
optional minHeight?: number;World-space offset of the building base above terrain.
name?
ts
optional name?: string;polygons
ts
polygons: TerrainSemanticPolygon[];subclass?
ts
optional subclass?: string;Finer source category when the schema carries one (e.g. Protomaps kind_detail).
tags?
ts
optional tags?: Record<string, string>;Inherited from
wikidata?
ts
optional wikidata?: string;Inherited from
TerrainStructureIdentity.wikidata
TerrainDescriptor
Properties
chunkSize
ts
chunkSize: number;Meters per chunk edge.
collision
ts
collision: object;When enabled, the tooling registers the heightfield as the scene's ground/collision.
enabled
ts
enabled: boolean;format
ts
format: "molen/terrain@2";gridSize
ts
gridSize: [number, number];Chunks in X,Z.
height
ts
height: object;max
ts
max: number;min
ts
min: number;layers
ts
layers: TerrainLayer[];lod
ts
lod: object;distanceBands
ts
distanceBands: number[];levels
ts
levels: number;skirts
ts
skirts: boolean;metersPerUnit?
ts
optional metersPerUnit?: number;World meters per unit of the source's projected space. Projected-Earth packages set this to cos(center latitude) and pre-multiply origin/chunkSize by it, so world XZ is metric; absent = 1 (local/invented worlds).
name
ts
name: string;origin
ts
origin: [number, number];World XZ of tile (0,0) corner.
streaming
ts
streaming: TerrainStreamingOptions;tileResolution
ts
tileResolution: number;Height samples per chunk edge (shared borders).
tiles
ts
tiles: object;heightUrl
ts
heightUrl: string;splatUrl?
ts
optional splatUrl?: string;TerrainLandcoverFeature
Properties
class
ts
class: string;density?
ts
optional density?: number;Optional normalized vegetation/decorator density multiplier.
id?
ts
optional id?: string | number;polygons
ts
polygons: TerrainSemanticPolygon[];subclass?
ts
optional subclass?: string;Finer source category when the schema carries one (e.g. Protomaps kind_detail).
TerrainLayer
Properties
auto?
ts
optional auto?: object;Optional height/slope auto-banding (terrain-owned, not matgraph nodes).
heightMax?
ts
optional heightMax?: number;heightMin?
ts
optional heightMin?: number;slopeMax?
ts
optional slopeMax?: number;slopeMin?
ts
optional slopeMin?: number;color?
ts
optional color?: string;Flat color for vertex-color splat banding (v1 shading).
materialRef?
ts
optional materialRef?: string;name
ts
name: string;tiling
ts
tiling: number;TerrainLinePath
Properties
distances
ts
distances: number[];length
ts
length: number;points
ts
points: TerrainSemanticPoint[];TerrainLineSample
Properties
dx
ts
dx: number;dz
ts
dz: number;x
ts
x: number;z
ts
z: number;TerrainMvtSemanticDecoderLimits
Properties
maxFeaturesPerTile?
ts
optional maxFeaturesPerTile?: number;maxGeometryPointsPerTile?
ts
optional maxGeometryPointsPerTile?: number;TerrainMvtSemanticDecoderOptions
Properties
layers?
ts
optional layers?: Partial<TerrainMvtSemanticLayerNames>;limits?
ts
optional limits?: TerrainMvtSemanticDecoderLimits;linearUnitScale?
ts
optional linearUnitScale?: number;Convert source height/width properties into terrain world units.
properties?
ts
optional properties?: Partial<TerrainMvtSemanticPropertyNames>;TerrainMvtSemanticLayerNames
Properties
building
ts
building: readonly string[];landcover
ts
landcover: readonly string[];poi
ts
poi: readonly string[];transportation
ts
transportation: readonly string[];water
ts
water: readonly string[];TerrainMvtSemanticPropertyNames
Properties
bridge
ts
bridge: readonly string[];buildingClass
ts
buildingClass: readonly string[];buildingHeight
ts
buildingHeight: readonly string[];buildingLayer
ts
buildingLayer: readonly string[];buildingLevels
ts
buildingLevels: readonly string[];buildingMinHeight
ts
buildingMinHeight: readonly string[];buildingName
ts
buildingName: readonly string[];buildingSubclass
ts
buildingSubclass: readonly string[];landcoverClass
ts
landcoverClass: readonly string[];landcoverDensity
ts
landcoverDensity: readonly string[];landcoverSubclass
ts
landcoverSubclass: readonly string[];transportationClass
ts
transportationClass: readonly string[];transportationLanes
ts
transportationLanes: readonly string[];transportationLayer
ts
transportationLayer: readonly string[];transportationLink
ts
transportationLink: readonly string[];transportationOneway
ts
transportationOneway: readonly string[];transportationService
ts
transportationService: readonly string[];transportationSubclass
ts
transportationSubclass: readonly string[];transportationSurface
ts
transportationSurface: readonly string[];transportationWidth
ts
transportationWidth: readonly string[];tunnel
ts
tunnel: readonly string[];waterClass
ts
waterClass: readonly string[];waterWidth
ts
waterWidth: readonly string[];TerrainPackageAttribution
Properties
license
ts
license: string;licenseUrl?
ts
optional licenseUrl?: string;sourceUrl?
ts
optional sourceUrl?: string;text
ts
text: string;TerrainPackageDescriptor
Properties
attribution
ts
attribution: TerrainPackageAttribution[];coordinateSpace
ts
coordinateSpace: TerrainPackageCoordinateSpace;elevation
ts
elevation: object;encoding
ts
encoding: "png16";height
ts
height: object;height.max
ts
max: number;height.min
ts
min: number;source
ts
source: TerrainPackageArchiveSource;features?
ts
optional features?: object;buildingDetail?
ts
optional buildingDetail?: object;Finer tiles for building footprints and places, same encoding and profile. Basemaps merge and drop buildings below their last zoom (Protomaps keeps almost none below 15), so a package may carry that zoom separately, often only where people look. Feature tiles a level or two coarser take their buildings from it; tiles it does not cover keep their own.
buildingDetail.level
ts
level: number;buildingDetail.source
ts
source: TerrainPackageArchiveSource;encoding
ts
encoding: "mvt";layers
ts
layers: ("water" | "transportation" | "building" | "poi")[];profile?
ts
optional profile?: "protomaps-basemap@1";source
ts
source: TerrainPackageArchiveSource;files
ts
files: TerrainPackageFileRecord[];format
ts
format: "molen/terrain-package@1";landcover?
ts
optional landcover?: object;encoding
ts
encoding: "mvt" | "png8";layer
ts
layer: "landcover";profile?
ts
optional profile?: "protomaps-basemap@1";source
ts
source: TerrainPackageArchiveSource;models?
ts
optional models?: object;index
ts
index: string;name
ts
name: string;preset?
ts
optional preset?: "1gb" | "5gb" | "20gb";provenance
ts
provenance: object;compiler
ts
compiler: string;compilerVersion
ts
compilerVersion: string;sources
ts
sources: TerrainPackageSourceRecord[];surface?
ts
optional surface?: object;layers?
ts
optional layers?: TerrainLayer[];seaLevel?
ts
optional seaLevel?: number;tileMatrix
ts
tileMatrix: object;maxLevel
ts
maxLevel: number;minLevel
ts
minLevel: number;rootTiles
ts
rootTiles: [number, number];scheme
ts
scheme: "xyz" | "tms";tileResolution
ts
tileResolution: number;version
ts
version: string;TerrainPackageFileRecord
Properties
bytes
ts
bytes: number;path
ts
path: string;sha256
ts
sha256: string;TerrainPackageFrame
The local metric frame a host renders a projected-Earth package in. World X/Z are Web Mercator meters multiplied by cos(latitude), which is exact at latitude and drifts by about 1.75% × tan(latitude) per degree of latitude away from it (1% at 30°, 2% at 48°, 3% at 60°). Omitted, the frame sits at the center latitude of the package bounds: right for a regional package, but a worldwide package centers on the equator, so a host viewing a place should pass that place's latitude and re-anchor (rebuild its streams on a new frame) after moving more than about a degree north or south.
Properties
latitude
ts
latitude: number;TerrainPackageSourceRecord
Properties
id
ts
id: string;release
ts
release: string;sha256?
ts
optional sha256?: string;TerrainPoiFeature
A mapped business, amenity, or individual outdoor object.
Extends
Properties
brand?
ts
optional brand?: string;brandId?
ts
optional brandId?: string;Stable source brand identifier, when supplied by an enriched source.
capacity?
ts
optional capacity?: number;class
ts
class: string;crownDiameter?
ts
optional crownDiameter?: number;heading?
ts
optional heading?: number;Rotation about +Y in radians; local model front is +Z.
Overrides
TerrainStructureIdentity.heading
height?
ts
optional height?: number;Measurements in world units; absence means unknown.
id?
ts
optional id?: string | number;leafType?
ts
optional leafType?: string;name?
ts
optional name?: string;point
ts
point: TerrainSemanticPoint;subclass?
ts
optional subclass?: string;tags?
ts
optional tags?: Record<string, string>;Inherited from
wikidata?
ts
optional wikidata?: string;Inherited from
TerrainStructureIdentity.wikidata
TerrainPyramidDescriptor
Coordinate-independent contract for a square planar terrain pyramid.
Earth packages, invented worlds, and generated game maps all adapt to this shape. Geographic projection and archive addressing deliberately stay outside this type.
Properties
coverage?
ts
optional coverage?: [number, number, number, number];Optional data coverage inside the root square: [minX,minZ,maxX,maxZ].
height
ts
height: object;max
ts
max: number;min
ts
min: number;layers
ts
layers: TerrainLayer[];maxLevel
ts
maxLevel: number;metersPerUnit?
ts
optional metersPerUnit?: number;World meters per unit of the source's projected space (see TerrainDescriptor). Origin, rootSize, and coverage are already multiplied by it; absent = 1.
minLevel
ts
minLevel: number;name
ts
name: string;origin
ts
origin: [number, number];World X/Z of the north-west/root minimum corner.
rootSize
ts
rootSize: number;Width and depth of the level-zero square, in world units.
skirts
ts
skirts: boolean;tileResolution
ts
tileResolution: number;TerrainPyramidTileAddress
Address of one square tile in a root-quad terrain pyramid.
Properties
level
ts
level: number;x
ts
x: number;z
ts
z: number;TerrainSemanticOverzoomOptions
Properties
buffer?
ts
optional buffer?: number;Clip margin around the descendant in tile units (default 1/64, about one road width).
TerrainSemanticPolygon
Properties
holes?
ts
optional holes?: TerrainSemanticRing[];outer
ts
outer: TerrainSemanticRing;Closed or open outer ring. The renderer closes it implicitly.
TerrainSemanticTile
Properties
buildings
ts
buildings: TerrainBuildingFeature[];buildingsGeneralized?
ts
optional buildingsGeneralized?: boolean;Source merged/generalized footprints cannot reliably identify individual premises.
buildingSourceLevel?
ts
optional buildingSourceLevel?: number;Level the building footprints were read at, when finer than the tile (composed from a building-detail sidecar). Their clip buffer is the source's buffer divided by 2^(buildingSourceLevel - tile level); tile-edge ownership rules should narrow theirs to match.
format
ts
format: "molen/terrain-semantics@1";landcover
ts
landcover: TerrainLandcoverFeature[];pois?
ts
optional pois?: TerrainPoiFeature[];transportation
ts
transportation: TerrainTransportationFeature[];water
ts
water: TerrainWaterFeature[];TerrainSemanticTileDecodeContext
Properties
address
ts
address: TerrainPyramidTileAddress;Logical XYZ-style address used by the terrain renderer (+Z south).
content
ts
content:
| TerrainPackageSemanticContent
| "all";encoding
ts
encoding: "mvt" | "png8";layers
ts
layers: readonly string[];Source layer names declared by terrain-package.json.
TerrainSemanticTileDecoder
Source-format adapter implemented by a pipeline/app-specific MVT or PNG8 decoder.
Extended by
Methods
decode()
ts
decode(data, context):
| TerrainSemanticTile
| Promise<TerrainSemanticTile>;Parameters
data
Uint8Array
context
TerrainSemanticTileDecodeContext
Returns
| TerrainSemanticTile | Promise<TerrainSemanticTile>
TerrainSemanticTileLoader
Anything that loads semantic tiles by pyramid address.
Methods
load()
ts
load(address, signal): Promise<TerrainSemanticTile | undefined>;Parameters
address
signal
AbortSignal
Returns
Promise<TerrainSemanticTile | undefined>
TerrainStreamingOptions
Properties
loadRadius
ts
loadRadius: number;Radius around the camera, measured in chunks, that should be resident.
maxConcurrentLoads
ts
maxConcurrentLoads: number;Maximum number of height-tile requests in flight at once.
maxResidentTiles
ts
maxResidentTiles: number;Hard ceiling for decoded resident height tiles and their meshes.
unloadRadius
ts
unloadRadius: number;Larger hysteresis radius; resident tiles outside it may be evicted.
TerrainStructureIdentity
Source identity and a bounded set of public map classification tags.
Extended by
Properties
heading?
ts
optional heading?: number;Rotation about +Y in radians; authored model front is +Z.
tags?
ts
optional tags?: Record<string, string>;wikidata?
ts
optional wikidata?: string;TerrainTileAddress
Address of one fixed-grid terrain chunk.
Properties
x
ts
x: number;z
ts
z: number;TerrainTileArchive
Extended by
Methods
getHeader()?
ts
optional getHeader(): Promise<TerrainArchiveHeader>;Returns
Promise<TerrainArchiveHeader>
getZxy()
ts
getZxy(
level,
x,
y,
signal?
): Promise<TerrainArchiveTile | undefined>;Parameters
level
number
x
number
y
number
signal?
AbortSignal
Returns
Promise<TerrainArchiveTile | undefined>
TerrainTransportationFeature
Source identity and a bounded set of public map classification tags.
Extends
Properties
bridge?
ts
optional bridge?: boolean;bridgeConnections?
ts
optional bridgeConnections?: object[];Join an inferred bridge or connected ground approach to an authored deck. Ground approaches blend back to terrain without generating bridge slabs. Points use normalized tile coordinates.
elevation
ts
elevation: number;point
ts
point: TerrainSemanticPoint;radius
ts
radius: number;class
ts
class: string;deckElevation?
ts
optional deckElevation?: number;Optional surveyed bridge deck elevation in absolute world Y units.
heading?
ts
optional heading?: number;Rotation about +Y in radians; authored model front is +Z.
Inherited from
TerrainStructureIdentity.heading
id?
ts
optional id?: string | number;lanes?
ts
optional lanes?: number;layer?
ts
optional layer?: number;Grade separation; different layers do not form junctions.
lines
ts
lines: TerrainSemanticLine[];link?
ts
optional link?: boolean;Turning connector or ramp, rather than an independent junction approach.
name?
ts
optional name?: string;oneway?
ts
optional oneway?: boolean;service?
ts
optional service?: string;Source service subtype, for example parking_aisle or driveway.
subclass?
ts
optional subclass?: string;Finer category, e.g. residential, parking_aisle or footway.
surface?
ts
optional surface?: string;tags?
ts
optional tags?: Record<string, string>;Inherited from
tunnel?
ts
optional tunnel?: boolean;width?
ts
optional width?: number;Suggested rendered width in world units (meters for Earth packages).
wikidata?
ts
optional wikidata?: string;Inherited from
TerrainStructureIdentity.wikidata
TerrainWaterFeature
Properties
class?
ts
optional class?: string;id?
ts
optional id?: string | number;lines?
ts
optional lines?: TerrainSemanticLine[];polygons?
ts
optional polygons?: TerrainSemanticPolygon[];width?
ts
optional width?: number;Suggested rendered width for linear waterways, in world units.
WebMercatorTileAddress
Properties
level
ts
level: number;x
ts
x: number;y
ts
y: number;Type Aliases
PmtilesTileCompression
ts
type PmtilesTileCompression = "none" | "gzip" | "brotli" | "zstd";Compression already applied to every tile payload.
PmtilesTileType
ts
type PmtilesTileType = "mvt" | "png" | "jpeg" | "webp" | "avif" | "unknown";Tile payload types, with their PMTiles header codes.
TerrainArchiveSetRoute
ts
type TerrainArchiveSetRoute =
| {
base: TerrainArchiveSetBase;
kind: "base";
}
| {
entry: TerrainArchiveSetEntry;
kind: "archive";
}
| {
cell: string;
id: string;
kind: "cell";
tier: TerrainArchiveSetGeohashTier;
url: string;
};Which archive serves a tile: the base, one detail entry, or one geohash cell's archive.
TerrainArchiveSetTileType
ts
type TerrainArchiveSetTileType = "png" | "mvt";Payload type shared by every archive in a set.
TerrainPackageArchiveSource
ts
type TerrainPackageArchiveSource =
| {
kind: "pmtiles";
path: string;
}
| {
kind: "pmtiles";
url: string;
}
| {
kind: "pmtiles-set";
path: string;
}
| {
kind: "pmtiles-set";
url: string;
};TerrainPackageCoordinateSpace
ts
type TerrainPackageCoordinateSpace =
| {
bounds: [number, number, number, number];
kind: "local";
units: "meters";
}
| {
bounds: [number, number, number, number];
crs: "EPSG:3857" | "EPSG:4326";
ellipsoid: "WGS84";
kind: "geospatial";
};TerrainPackageSemanticContent
ts
type TerrainPackageSemanticContent = "landcover" | "features";TerrainPackageSemanticProfile
ts
type TerrainPackageSemanticProfile = "protomaps-basemap@1";TerrainSemanticBounds
ts
type TerrainSemanticBounds = [number, number, number, number];TerrainSemanticLine
ts
type TerrainSemanticLine = TerrainSemanticPoint[];TerrainSemanticPoint
ts
type TerrainSemanticPoint = [number, number];TerrainSemanticRing
ts
type TerrainSemanticRing = TerrainSemanticPoint[];TransportKind
ts
type TransportKind = "street" | "service" | "path" | "rail" | "motorway";Painter/simulation class of a transportation feature.
Variables
BRIDGE_SURFACE_LIFT
ts
const BRIDGE_SURFACE_LIFT: 4 = 4;Extra height the painter adds to a bridge road's nominal elevation, in metres.
DEGENERATE_RING_AREA
ts
const DEGENERATE_RING_AREA: number;Normalized-area floor below which a ring encloses nothing a triangulator can use. Tile-local [u, v] units, so this is ~1e-6 of a tile edge squared — far below any mapped real feature at any zoom, and above the float noise of a collinear ring.
GEOHASH_MAX_PRECISION
ts
const GEOHASH_MAX_PRECISION: 6 = 6;Longest geohash these helpers accept (32^6 cells, about 1.2 × 0.6 km).
PATH_SURFACE_LIFT
ts
const PATH_SURFACE_LIFT: 0.43 = .43;Height of a painted path surface above the rendered terrain, in metres.
PMTILES_HEADER_BYTES
ts
const PMTILES_HEADER_BYTES: 127 = 127;PMTiles v3 header size in bytes.
ROAD_SURFACE_LIFT
ts
const ROAD_SURFACE_LIFT: 0.32 = .32;Height of a painted street surface above the rendered terrain, in metres.
WEB_MERCATOR_EARTH_RADIUS_METERS
ts
const WEB_MERCATOR_EARTH_RADIUS_METERS: number;Navigation/data-projection helpers for the projected-Earth terrain adapter.
These functions map WGS84 longitude/latitude to the engine's planar convention: +X east, +Z south, meters. They are intended for package compilation, navigation, and rendering—not as deterministic simulation math. The renderer rebases this large projected frame near the camera.
WEB_MERCATOR_HALF_WORLD_METERS
ts
const WEB_MERCATOR_HALF_WORLD_METERS: number;WEB_MERCATOR_MAX_LATITUDE
ts
const WEB_MERCATOR_MAX_LATITUDE: number;Functions
assertTerrainPyramidAddress()
ts
function assertTerrainPyramidAddress(descriptor, address): void;Parameters
descriptor
address
Returns
void
assertTerrainSemanticTile()
ts
function assertTerrainSemanticTile(tile): void;Fail early when a source decoder violates the renderer's normalized semantic contract.
Parameters
tile
Returns
void
bridgeDeckHeightFn()
ts
function bridgeDeckHeightFn(
path,
groundAt,
options
): (x, z) => number;A tile fragment cannot establish the elevation of an entire bridge. Use a bank-to-bank profile for complete spans and deterministic terrain clearance at clipped ends. groundAt samples terrain in the same frame as path.
Parameters
path
groundAt
(x, z) => number
options
Returns
(x, z) => number
buildPmtilesDirectories()
ts
function buildPmtilesDirectories(entries, rootBudget?): PmtilesDirectories;Split directory entries (sorted by tile id) into a root that fits the reader's initial fetch plus leaf directories. rootBudget is the compressed-root byte budget.
Parameters
entries
readonly PmtilesDirectoryEntry[]
rootBudget?
number
Returns
clampBounds()
ts
function clampBounds(
bounds,
lo?,
hi?
): TerrainSemanticBounds;Clamp bounds into [lo, hi] on both axes.
Parameters
bounds
lo?
number
hi?
number
Returns
composeTerrainBuildingDetail()
ts
function composeTerrainBuildingDetail(
base,
address,
detailLevel,
children
): TerrainSemanticTile | undefined;Compose base's buildings and places from its descendants at detailLevel. children lists every descendant of address at that level (missing tiles as tile: undefined). With no descendant present, base is returned unchanged.
Parameters
base
TerrainSemanticTile | undefined
address
detailLevel
number
children
readonly TerrainBuildingDetailChild[]
Returns
TerrainSemanticTile | undefined
createBuildingDetailTerrainSemanticSource()
ts
function createBuildingDetailTerrainSemanticSource(
base,
detail,
options
): TerrainSemanticTileLoader;Wrap a feature source so tiles within maxDepth levels of the detail level take their buildings and places from detail (see the module comment). Tiles at or finer than the detail level take them from the covering detail tile; coarser tiles, and tiles the sidecar does not cover, are served by base unchanged.
Parameters
base
detail
options
Returns
createEmptyTerrainSemanticTile()
ts
function createEmptyTerrainSemanticTile(): TerrainSemanticTile;Allocate a normalized empty tile without sharing mutable collection instances.
Returns
createOverzoomTerrainSemanticSource()
ts
function createOverzoomTerrainSemanticSource(
source,
maxLevel,
options?
): TerrainSemanticTileLoader;Wrap a semantic source so levels above maxLevel load their maxLevel ancestor and overzoom it. Recently decoded ancestors are kept (cacheSize, default 32), since a camera refining one ancestor asks for its descendants within moments of each other.
Parameters
source
maxLevel
number
options?
TerrainSemanticOverzoomOptions & object
Returns
createPmtilesPrefix()
ts
function createPmtilesPrefix(
tiles,
tileDataLength,
options
): Uint8Array;Everything that precedes the tile data of a clustered archive: header, root directory, metadata and leaf directories. Write the returned bytes, then the tile payloads in tiles order — the streaming path for archives too large to hold in memory.
Parameters
tiles
readonly PmtilesTileRecord[]
tileDataLength
number
options
Returns
Uint8Array
createProtomapsTerrainMvtDecoder()
ts
function createProtomapsTerrainMvtDecoder(options?): TerrainMvtSemanticDecoder;Preset matching the world.pmtiles Protomaps basemap this repo's sample package ships.
Parameters
options?
Omit<TerrainMvtSemanticDecoderOptions, "layers"> & object
Returns
createTerrainArchiveSetRouter()
ts
function createTerrainArchiveSetRouter(descriptor): TerrainArchiveSetRouter;Build the tile → archive router. Throws when two archives claim one partition cell, when a quadtree-partitioned set has no partitionLevel, or when geohash tiers overlap.
Parameters
descriptor
Returns
createTerrainMvtSemanticDecoder()
ts
function createTerrainMvtSemanticDecoder(options?): TerrainMvtSemanticDecoder;Decode configured MVT source layers into renderer-neutral tile-local semantic geometry.
Parameters
options?
TerrainMvtSemanticDecoderOptions
Returns
decodePng16()
ts
function decodePng16(png): Gray16;Decode a 16-bit grayscale PNG to a normalized [0,1] grid.
Parameters
png
Uint8Array
Returns
encodeGeohash()
ts
function encodeGeohash(
longitude,
latitude,
precision
): string;The geohash of precision characters holding a point (west and south edges are inside).
Parameters
longitude
number
latitude
number
precision
number
Returns
string
encodePng16()
ts
function encodePng16(img): Uint8Array;Encode a normalized grayscale grid as a 16-bit grayscale PNG.
Parameters
img
Returns
Uint8Array
encodeTerrainArchiveSetCells()
ts
function encodeTerrainArchiveSetCells(cells): string;Encode geohash cells (all of one precision) as a tier's run-length cells list.
Parameters
cells
Iterable<string>
Returns
string
encodeTerrainArchiveSetPartitions()
ts
function encodeTerrainArchiveSetPartitions(indices): string;Encode partition indices as a sorted run-length list ([9, 3, 4, 5] → "3-5,9").
Parameters
indices
Iterable<number>
Returns
string
generateHeightmap()
ts
function generateHeightmap(opts): Gray16;Generate a normalized heightmap grid.
Parameters
opts
Returns
generateHeightmapPng()
ts
function generateHeightmapPng(opts): Uint8Array;Generate a heightmap and encode it as a 16-bit grayscale PNG.
Parameters
opts
Returns
Uint8Array
geohashBounds()
ts
function geohashBounds(hash): [number, number, number, number];A geohash's [west, south, east, north] in degrees.
Parameters
hash
string
Returns
[number, number, number, number]
geohashFromIndex()
ts
function geohashFromIndex(index, precision): string;The geohash of precision characters with this index.
Parameters
index
number
precision
number
Returns
string
geohashIndex()
ts
function geohashIndex(hash): number;A geohash's characters read as one base-32 number.
Parameters
hash
string
Returns
number
groupTransportationFeatures()
ts
function groupTransportationFeatures(features): TerrainTransportationFeature[];Merge features whose properties are identical (ignoring id), concatenating their lines. Protomaps splits one road into many features; grouping lets fragments join end to end.
Parameters
features
readonly TerrainTransportationFeature[]
Returns
TerrainTransportationFeature[]
heightfieldFromPng()
ts
function heightfieldFromPng(descriptor, png): Heightfield;Build a Heightfield covering the whole terrain from a single decoded heightmap PNG.
Parameters
descriptor
png
Uint8Array
Returns
heightfieldSubtileFromPng()
ts
function heightfieldSubtileFromPng(
descriptor,
address,
png,
subdivision,
offset
): Heightfield;Decode one ancestor PNG16 tile and crop/resample the requested descendant into a tile-scoped heightfield. Adjacent descendants share the same ancestor samples at their common border.
Parameters
descriptor
address
png
Uint8Array
subdivision
number
offset
Returns
heightfieldTileFromPng()
ts
function heightfieldTileFromPng(
descriptor,
address,
png
): Heightfield;Build one tile-scoped Heightfield from a streamed height tile.
Parameters
descriptor
address
png
Uint8Array
Returns
inferLaneCount()
ts
function inferLaneCount(feature, width): number;Total lane count across both directions, matching the painted lane lines.
Parameters
feature
width
number
Returns
number
isDegenerateRing()
ts
function isDegenerateRing(ring): boolean;A ring that cannot bound a face: fewer than three distinct vertices, or an enclosed area below DEGENERATE_RING_AREA (collinear or repeated points). Triangulators — three.js earcut among them — fault or emit nothing for these, so contract validation and mesh adapters share this one definition.
Parameters
ring
readonly TerrainSemanticPoint[]
Returns
boolean
isPaintedTransport()
ts
function isPaintedTransport(feature, options): boolean;Whether the painter draws this feature at all (tunnels, crossings and unstyled sidewalks are skipped).
Parameters
feature
options
sidewalks
boolean
Returns
boolean
isTransportLink()
ts
function isTransportLink(feature): boolean;True for slip roads and ramps.
Parameters
feature
Returns
boolean
joinTerrainLines()
ts
function joinTerrainLines(lines): TerrainSemanticLine[];Join degree-two source fragments so profiles and dash phases continue through tile features.
Parameters
lines
readonly TerrainSemanticLine[]
Returns
lineSegmentIndex()
ts
function lineSegmentIndex(path, distance): number;Index of the segment [i, i + 1] containing distance (clamped to the path).
Parameters
path
distance
number
Returns
number
normalizeRing()
ts
function normalizeRing(ring): TerrainSemanticRing;Drop a repeated closing vertex and consecutive duplicates.
Parameters
ring
Returns
overzoomTerrainSemanticTile()
ts
function overzoomTerrainSemanticTile(
tile,
from,
to,
options?
): TerrainSemanticTile;Re-express an ancestor's semantic tile for one of its descendants. from must be an ancestor of (or equal to) to.
Parameters
tile
from
to
options?
TerrainSemanticOverzoomOptions
Returns
parseTerrainArchiveSetPartitions()
ts
function parseTerrainArchiveSetPartitions(ranges): number[];Parse a run-length partition list ("3-5,9" → [3, 4, 5, 9]).
Parameters
ranges
string
Returns
number[]
pathBounds()
ts
function pathBounds(path): [number, number, number, number];Axis-aligned bounds [minX, minZ, maxX, maxZ] of a path's vertices.
Parameters
path
Returns
[number, number, number, number]
pmtilesTileId()
ts
function pmtilesTileId(
z,
x,
y
): number;The PMTiles v3 tile id (Hilbert order across zoom levels) of an XYZ tile.
Parameters
z
number
x
number
y
number
Returns
number
pointInPolygon()
ts
function pointInPolygon(point, polygon): boolean;Inside the outer ring and outside every hole.
Parameters
point
polygon
Returns
boolean
pointInRing()
ts
function pointInRing(point, ring): boolean;Even-odd containment test against one ring.
Parameters
point
ring
readonly TerrainSemanticPoint[]
Returns
boolean
polygonArea()
ts
function polygonArea(polygon): number;Outer area minus hole areas, never negative.
Parameters
polygon
Returns
number
polygonBounds()
ts
function polygonBounds(polygon): TerrainSemanticBounds;Unclamped bounds of the outer ring (buffered geometry may exceed [0, 1]).
Parameters
polygon
Returns
projectedToWorld()
ts
function projectedToWorld(
metersPerUnit,
x,
z
): [number, number];Projected (Mercator) X/Z → world meters, given the package's metersPerUnit.
Parameters
metersPerUnit
number
x
number
z
number
Returns
[number, number]
registerTerrainSchemas()
ts
function registerTerrainSchemas(): void;Register the terrain descriptor schema into the shared registry (idempotent).
Returns
void
renderedGroundSampler()
ts
function renderedGroundSampler(
heightfield,
origin,
tileSize,
surfaceResolution?
): (x, z) => number;Build a world-space sampler for one tile's rendered ground. Points outside the tile clamp to its edge cells. Vertex heights are cached, so the sampler is cheap after the first queries.
Parameters
heightfield
origin
readonly [number, number]
tileSize
number
surfaceResolution?
number
Returns
(x, z) => number
ringArea()
ts
function ringArea(ring): number;Parameters
ring
readonly TerrainSemanticPoint[]
Returns
number
ringSignedArea()
ts
function ringSignedArea(ring): number;Twice-signed shoelace area halved; positive when the ring winds +u then +v.
Parameters
ring
readonly TerrainSemanticPoint[]
Returns
number
roadWidth()
ts
function roadWidth(className, explicit?): number;Road ribbon width in world units for a transportation class.
Parameters
className
string
explicit?
number
Returns
number
sampleTerrainLine()
ts
function sampleTerrainLine(
path,
distance,
offset?
): TerrainLineSample;Sample a path by arc length; offset edges interpolate shared, bounded miter joins. Closed paths use the same join at both ends, avoiding a wedge at the closure.
Parameters
path
distance
number
offset?
number
Returns
serializePmtilesDirectory()
ts
function serializePmtilesDirectory(entries): Uint8Array;Encode a directory in the uncompressed PMTiles v3 column layout.
Parameters
entries
readonly PmtilesDirectoryEntry[]
Returns
Uint8Array
terrainArchiveSetTierCells()
ts
function terrainArchiveSetTierCells(tier): string[];The cells of a geohash tier, as geohashes (expands the run-length list).
Parameters
tier
Returns
string[]
terrainLinePath()
ts
function terrainLinePath(line, tileSize): TerrainLinePath;Convert normalized tile geometry once; collapse duplicate vertices.
Parameters
line
tileSize
number
Returns
terrainPackageFrameLatitude()
ts
function terrainPackageFrameLatitude(pkg, frame?): number | undefined;Latitude the package's metric frame is exact at: frame.latitude when given, else the center of the package bounds. Undefined for a local (already metric) package.
Parameters
pkg
frame?
Returns
number | undefined
terrainPackageMetersPerUnit()
ts
function terrainPackageMetersPerUnit(pkg, frame?): number;Ground meters per projected unit for a package in a frame: cos(frame latitude) for a projected-Earth package, 1 for a local package.
Parameters
pkg
frame?
Returns
number
terrainPyramidAddressAt()
ts
function terrainPyramidAddressAt(
descriptor,
level,
x,
z
): TerrainPyramidTileAddress | undefined;Parameters
descriptor
level
number
x
number
z
number
Returns
TerrainPyramidTileAddress | undefined
terrainPyramidAncestor()
ts
function terrainPyramidAncestor(address, level): TerrainPyramidTileAddress;Parameters
address
level
number
Returns
terrainPyramidParent()
ts
function terrainPyramidParent(address): TerrainPyramidTileAddress | undefined;Parameters
address
Returns
TerrainPyramidTileAddress | undefined
terrainPyramidTileCount()
ts
function terrainPyramidTileCount(level): number;Parameters
level
number
Returns
number
terrainPyramidTileKey()
ts
function terrainPyramidTileKey(address): string;Parameters
address
Returns
string
terrainPyramidTileOrigin()
ts
function terrainPyramidTileOrigin(descriptor, address): [number, number];Parameters
descriptor
address
Returns
[number, number]
terrainPyramidTileSize()
ts
function terrainPyramidTileSize(descriptor, level): number;Parameters
descriptor
level
number
Returns
number
terrainTileGeohash()
ts
function terrainTileGeohash(
level,
x,
y,
precision
): string;The geohash cell a Web Mercator XYZ tile (+y south) belongs to in a geohash-partitioned archive set: the cell holding the tile's center.
Parameters
level
number
x
number
y
number
precision
number
Returns
string
terrainTileKey()
ts
function terrainTileKey(address): string;Parameters
address
Returns
string
terrainTileOrigin()
ts
function terrainTileOrigin(descriptor, address): [number, number];Parameters
descriptor
address
Returns
[number, number]
transportKind()
ts
function transportKind(feature): TransportKind;Classify a feature from its class, subclass and service tags.
Parameters
feature
Returns
transportSurfaceLift()
ts
function transportSurfaceLift(kind, bridge?): number;Nominal painted surface elevation above terrain (bridges add BRIDGE_SURFACE_LIFT).
Parameters
kind
bridge?
boolean
Returns
number
transportWidth()
ts
function transportWidth(
feature,
kind?,
scale?
): number;Carriageway width in metres, matching the painter (capped at 80 m).
Parameters
feature
kind?
scale?
number
Returns
number
waterwayWidth()
ts
function waterwayWidth(className, explicit?): number;Waterway ribbon width in world units for a water class.
Parameters
className
string | undefined
explicit?
number
Returns
number
webMercatorScaleAtLatitude()
ts
function webMercatorScaleAtLatitude(latitudeDegrees): number;Ground meters per projected Web Mercator meter at a latitude: cos(lat). Mercator inflates horizontal distances by 1/cos(lat) (≈1.48× at 47.6°N), while heights stay in true meters; multiplying projected X/Z by this factor makes a scene metrically consistent. Latitude is clamped to the Mercator limit.
Parameters
latitudeDegrees
number
Returns
number
webMercatorTileBounds()
ts
function webMercatorTileBounds(address): [number, number, number, number];Projected X/Z bounds for one XYZ Web Mercator tile.
Parameters
address
Returns
[number, number, number, number]
webMercatorToWgs84()
ts
function webMercatorToWgs84(x, z): [number, number];Convert Web Mercator X/Z meters (+Z south) to WGS84 longitude/latitude degrees.
Parameters
x
number
z
number
Returns
[number, number]
wgs84ToWebMercator()
ts
function wgs84ToWebMercator(longitude, latitude): [number, number];Convert WGS84 longitude/latitude degrees to Web Mercator X/Z meters (+Z south).
Parameters
longitude
number
latitude
number
Returns
[number, number]
wgs84ToWebMercatorTile()
ts
function wgs84ToWebMercatorTile(
longitude,
latitude,
level
): WebMercatorTileAddress;XYZ address containing a WGS84 point at a Web Mercator level.
Parameters
longitude
number
latitude
number
level
number
Returns
wgs84ToWorld()
ts
function wgs84ToWorld(
metersPerUnit,
longitude,
latitude
): [number, number];WGS84 longitude/latitude → metric world X/Z in a frame whose scale is metersPerUnit (see terrainPackageMetersPerUnit). This is where a host places a camera, marker or entity.
Parameters
metersPerUnit
number
longitude
number
latitude
number
Returns
[number, number]
worldToProjected()
ts
function worldToProjected(
metersPerUnit,
x,
z
): [number, number];World meters → projected (Mercator) X/Z, given the package's metersPerUnit.
Parameters
metersPerUnit
number
x
number
z
number
Returns
[number, number]
worldToWgs84()
ts
function worldToWgs84(
metersPerUnit,
x,
z
): [number, number];Metric world X/Z in a frame of scale metersPerUnit → WGS84 longitude/latitude.
Parameters
metersPerUnit
number
x
number
z
number
Returns
[number, number]
writePmtilesArchive()
ts
function writePmtilesArchive(tiles, options): Uint8Array;Build a complete clustered PMTiles v3 archive in memory. Tiles may arrive in any order; zooms are derived from them. Use createPmtilesPrefix to stream larger archives to disk.
Parameters
tiles
readonly PmtilesWriterTile[]
options
Returns
Uint8Array