Class Terrain
Index
Constructors
Properties
Methods
Constructors
constructor
Parameters
- painter: Painter
- tileManager: TileManager
- options: TerrainSpecification
Returns Terrain
Properties
coordsIndex
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
depthAtPoint
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)
- p: Point
destroy
Returns void
getCoordsTexture
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
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. This will traverse 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 & coords into a texture
Parameters
- texture: string
the texture
Returns Framebuffer
the frame buffer
- texture: string
getMeshFrameDelta
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
- zoom: number
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
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
pointCoordinate
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).
- p: Point
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.