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

This is the main class which handles most of the 3D Terrain logic. It has the following topics:

  1. loads raster-dem tiles via the internal tileManager this.tileManager
  2. creates a depth-framebuffer, which is used to calculate the visibility of coordinates
  3. stores all render-to-texture tiles in the this.tileManager._tiles
  4. calculates the elevation for a specific tile-coordinate
  5. creates a terrain-mesh

A note about the GPU resource-usage:

Framebuffers:

  • one for the depth framebuffer with the size of the map-div.
  • one for rendering a tile to texture with the size of tileSize (= 512x512).

Textures:

  • one texture for an empty raster-dem tile with size 1x1
  • one texture for an empty depth-buffer, when terrain is disabled with size 1x1
  • one texture for an each loaded raster-dem with size of the source.tileSize
  • one texture for the depth-framebuffer with the size of the map-div.
  • finally for each render-to-texture tile (= this._tiles) a set of textures for each render stack (The stack-concept is documented in painter.ts).

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.

Index

Constructors

Properties

exaggeration: number

multiplicator for the elevation. Used to make terrain more "extreme".

meshSize: number

define the meshSize per tile.

the TerrainSpecification object passed to this instance

painter: Painter

The style this terrain corresponds to

qualityFactor: number

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: TerrainTileManager

the tilemanager this terrain is based on

Methods

  • Returns void

  • 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: number

      optional, default 8192

    Returns number

    the elevation

  • 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: number

      optional, default 8192

    Returns number

    the elevation

  • 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

    Returns number

    the elevation

  • 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

  • get a framebuffer as big as the map-div, which will be used to render depth into a texture

    Returns Framebuffer

    the frame buffer

  • 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

  • Parameters

    Returns number

  • Calculates the height of the tile skirts for the "auto" strategy.

    Parameters

    • zoom: number

      current zoomlevel

    Returns number

    the elevation delta in meters

  • returns a Terrain Object for a tile. Unless the tile corresponds to data (e.g. tile is loading), return a flat dem object

    Parameters

    Returns TerrainData

    the terrain data to use in the program

  • Clear CPU elevation samplers that may retain a previously selected DEM tile.

    Returns void

Was this helpful?