On this page

Class Terrain

Index

Constructors

Properties

coordsIndex: string[]

coords index contains a list of tileID.keys. This index is used to identify the tile via the alpha-cannel in the coords-texture. As the alpha-channel has 1 Byte a max of 255 tiles can rendered without an error.

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

  • Reads the depth value from the depth-framebuffer at a given screen pixel

    Parameters

    • p: Point

      Screen coordinate

    Returns number

    depth value in clip space (between 0 and 1)

  • Returns void

  • create coords texture, needed to grab coordinates from canvas encode coords coordinate into 4 bytes:

    • 8 lower bits for x
    • 8 lower bits for y
    • 4 higher bits for x
    • 4 higher bits for y
    • 8 bits for coordsIndex (1 .. 255) (= number of terraintile), is later set in draw_terrain uniform value

    Returns Texture

    the texture

  • 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. This will traverse 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 & coords into a texture

    Parameters

    • texture: string

      the texture

    Returns Framebuffer

    the frame buffer

  • Calculates a height of the frame around the terrain-mesh to avoid stitching between tile boundaries in different zoomlevels.

    Parameters

    • zoom: number

      current zoomlevel

    Returns number

    the elevation delta in meters

  • 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

  • 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

  • Reads a pixel from the coords-framebuffer and translate this to mercator, or null, if the pixel doesn't lie on the terrain's surface (but the sky instead).

    Parameters

    • p: Point

      Screen-Coordinate

    Returns MercatorCoordinate

    Mercator coordinate for a screen pixel, or null, if the pixel is not covered by terrain (is in the sky).

Was this helpful?
SDK JS
Reference
Terrain