For AI agents: a documentation index is available at /llms.txt. Markdown versions of all pages are available by appending .md to any URL.
Class Terrain
Index
Constructors
Properties
Methods
Constructors
constructor
- new Terrain(
painter: Painter,
tileManager: TileManager,
options: TerrainSpecification,
terrainSkirtLength?: "none" | "auto",
): TerrainParameters
- painter: Painter
- tileManager: TileManager
- options: TerrainSpecification
OptionalterrainSkirtLength: "none" | "auto"
Returns Terrain
Properties
exaggeration
multiplicator for the elevation. Used to make terrain more "extreme".
meshSize
define the meshSize per tile.
options
the TerrainSpecification object passed to this instance
painter
The style this terrain corresponds to
qualityFactor
to not see pixels in the render-to-texture tiles it is good to render them bigger this number is the multiplicator (must be a power of 2) for the current tileSize. So to get good results with not too much memory footprint a value of 2 should be fine.
tileManager
the tilemanager this terrain is based on
Methods
destroy
Returns void
getCoverageIndex
Index of the tiles the terrain currently renders, for sampling the terrain surface on the CPU. Built on first use and kept until resetElevationCache.
Returns TerrainCoverageIndex | null
the index, or null when no terrain tile is renderable
getDEMElevation
Get the elevation-value from original dem-data for a given tile-coordinate. Coordinates that fall outside
[0, extent)are normalized to the appropriate neighbor tile before lookup.Parameters
- tileID: OverscaledTileID
the tile to get the elevation for
- x: number
x coordinate relative to the tile, may be outside
[0, extent) - y: number
y coordinate relative to the tile, may be outside
[0, extent) Optionalextent: numberoptional, default 8192
Returns number
the elevation
- tileID: OverscaledTileID
getElevation
Get the elevation for given coordinate in respect of exaggeration.
Parameters
- tileID: OverscaledTileID
the tile id
- x: number
x coordinate relative to the tile, may be outside
[0, extent) - y: number
y coordinate relative to the tile, may be outside
[0, extent) Optionalextent: numberoptional, default 8192
Returns number
the elevation
- tileID: OverscaledTileID
getElevationForLngLat
Get the elevation for given LngLat in respect of exaggeration. Where the location is covered by a rendered tile with loaded DEM data this samples the rendered surface, so the result agrees with what is drawn; elsewhere it traverses up the zoom levels to find the first tile with data to return.
Parameters
- lnglat: LngLat
the location
- transform: IReadonlyTransform
Returns number
the elevation
- lnglat: LngLat
getElevationForLngLatZoom
Get the elevation for given LngLat in respect of exaggeration.
Parameters
- lnglat: LngLat
the location
- zoom: number
the zoom, use getElevationForLngLat if you don't want a specific zoom level, but more accurate results.
Returns number
the elevation
- lnglat: LngLat
getFramebuffer
get a framebuffer as big as the map-div, which will be used to render depth into a texture
Returns Framebuffer
the frame buffer
getMinMaxElevation
- getMinMaxElevation(
tileID: OverscaledTileID,
): { maxElevation: number | null; minElevation: number | null }Get the minimum and maximum elevation contained in a tile. This includes any exaggeration included in the terrain.
Parameters
- tileID: OverscaledTileID
ID of the tile to be used as a source for the min/max elevation
Returns { maxElevation: number | null; minElevation: number | null }
the minimum and maximum elevation found in the tile, including the terrain's exaggeration
- tileID: OverscaledTileID
getMinTileElevationForLngLatZoom
Parameters
- lnglat: LngLat
- zoom: number
Returns number
getSkirtLength
Calculates the height of the tile skirts for the "auto" strategy.
Parameters
- zoom: number
current zoomlevel
Returns number
the elevation delta in meters
- zoom: number
getTerrainData
returns a Terrain Object for a tile. Unless the tile corresponds to data (e.g. tile is loading), return a flat dem object
Parameters
- tileID: OverscaledTileID
the tile to get the terrain for
Returns TerrainData
the terrain data to use in the program
- tileID: OverscaledTileID
getTerrainMesh
create a regular mesh which will be used by all terrain-tiles
Parameters
- tileId: OverscaledTileID
Returns Mesh
the created regular mesh
Internal
This is the main class which handles most of the 3D Terrain logic. It has the following topics:
A note about the GPU resource-usage:
Framebuffers:
Textures:
Normally there exists 1-3 Textures per tile, depending on the stylesheet. Each Textures has the size 2*tileSize (= 1024x1024). Also there exists a cache of the last 150 newest rendered tiles.