---
title: "Terrain | JavaScript maps SDK"
description: "Documentation for MapTiler SDK"
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# Class Terrain

##### Index

### Constructors[](#constructors)

[constructor](#constructor)

### Properties[](#properties)

[coordsIndex](#coordsindex) [exaggeration](#exaggeration) [meshSize](#meshsize) [options](#options) [painter](#painter) [qualityFactor](#qualityfactor) [tileManager](#tilemanager)

### Methods[](#methods)

[depthAtPoint](#depthatpoint) [destroy](#destroy) [getCoordsTexture](#getcoordstexture) [getDEMElevation](#getdemelevation) [getElevation](#getelevation) [getElevationForLngLat](#getelevationforlnglat) [getElevationForLngLatZoom](#getelevationforlnglatzoom) [getFramebuffer](#getframebuffer) [getMeshFrameDelta](#getmeshframedelta) [getMinMaxElevation](#getminmaxelevation) [getMinTileElevationForLngLatZoom](#getmintileelevationforlnglatzoom) [getTerrainData](#getterraindata) [getTerrainMesh](#getterrainmesh) [pointCoordinate](#pointcoordinate)

## Constructors[](#constructors-1)

### constructor[](#constructor)

-   new Terrain(  
        painter: [Painter](https://docs.maptiler.com/sdk-js/api-reference/classes/Painter/),  
        tileManager: [TileManager](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.TileManager/),  
        options: [TerrainSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/TerrainSpecification/),  
    ): Terrain[](#constructorterrain)
    
    #### Parameters
    
    -   painter: [Painter](https://docs.maptiler.com/sdk-js/api-reference/classes/Painter/)
    -   tileManager: [TileManager](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.TileManager/)
    -   options: [TerrainSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/TerrainSpecification/)
    
    #### Returns Terrain
    

## Properties[](#properties-1)

### coordsIndex[](#coordsindex)

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[](#exaggeration)

exaggeration: number

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

### meshSize[](#meshsize)

meshSize: number

define the meshSize per tile.

### options[](#options)

options: [TerrainSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/TerrainSpecification/)

the TerrainSpecification object passed to this instance

### painter[](#painter)

painter: [Painter](https://docs.maptiler.com/sdk-js/api-reference/classes/Painter/)

The style this terrain corresponds to

### qualityFactor[](#qualityfactor)

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[](#tilemanager)

tileManager: [TerrainTileManager](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.TerrainTileManager/)

the tilemanager this terrain is based on

## Methods[](#methods-1)

### depthAtPoint[](#depthatpoint)

-   depthAtPoint(p: [Point](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Point/)): number[](#depthatpoint-1)
    
    Reads the depth value from the depth-framebuffer at a given screen pixel
    
    #### Parameters
    
    -   p: [Point](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Point/)
        
        Screen coordinate
        
    
    #### Returns number
    
    depth value in clip space (between 0 and 1)
    

### destroy[](#destroy)

-   destroy(): void[](#destroy-1)
    
    #### Returns void
    

### getCoordsTexture[](#getcoordstexture)

-   getCoordsTexture(): [Texture](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Texture/)[](#getcoordstexture-1)
    
    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](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Texture/)
    
    the texture
    

### getDEMElevation[](#getdemelevation)

-   getDEMElevation(  
        tileID: [OverscaledTileID](https://docs.maptiler.com/sdk-js/api-reference/classes/OverscaledTileID/),  
        x: number,  
        y: number,  
        extent?: number,  
    ): number[](#getdemelevation-1)
    
    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](https://docs.maptiler.com/sdk-js/api-reference/classes/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)`
        
    -   `Optional`extent: number
        
        optional, default 8192
        
    
    #### Returns number
    
    the elevation
    

### getElevation[](#getelevation)

-   getElevation(  
        tileID: [OverscaledTileID](https://docs.maptiler.com/sdk-js/api-reference/classes/OverscaledTileID/),  
        x: number,  
        y: number,  
        extent?: number,  
    ): number[](#getelevation-1)
    
    Get the elevation for given coordinate in respect of exaggeration.
    
    #### Parameters
    
    -   tileID: [OverscaledTileID](https://docs.maptiler.com/sdk-js/api-reference/classes/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)`
        
    -   `Optional`extent: number
        
        optional, default 8192
        
    
    #### Returns number
    
    the elevation
    

### getElevationForLngLat[](#getelevationforlnglat)

-   getElevationForLngLat(lnglat: [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/), transform: [IReadonlyTransform](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.IReadonlyTransform/)): number[](#getelevationforlnglat-1)
    
    Get the elevation for given [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/) in respect of exaggeration. This will traverse up the zoom levels to find the first tile with data to return.
    
    #### Parameters
    
    -   lnglat: [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/)
        
        the location
        
    -   transform: [IReadonlyTransform](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.IReadonlyTransform/)
    
    #### Returns number
    
    the elevation
    

### getElevationForLngLatZoom[](#getelevationforlnglatzoom)

-   getElevationForLngLatZoom(lnglat: [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/), zoom: number): number[](#getelevationforlnglatzoom-1)
    
    Get the elevation for given [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/) in respect of exaggeration.
    
    #### Parameters
    
    -   lnglat: [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/)
        
        the location
        
    -   zoom: number
        
        the zoom, use [getElevationForLngLat](#getelevationforlnglat) if you don't want a specific zoom level, but more accurate results.
        
    
    #### Returns number
    
    the elevation
    

### getFramebuffer[](#getframebuffer)

-   getFramebuffer(texture: string): [Framebuffer](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Framebuffer/)[](#getframebuffer-1)
    
    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](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Framebuffer/)
    
    the frame buffer
    

### getMeshFrameDelta[](#getmeshframedelta)

-   getMeshFrameDelta(zoom: number): number[](#getmeshframedelta-1)
    
    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
    

### getMinMaxElevation[](#getminmaxelevation)

-   getMinMaxElevation(  
        tileID: [OverscaledTileID](https://docs.maptiler.com/sdk-js/api-reference/classes/OverscaledTileID/),  
    ): { maxElevation: number | null; minElevation: number | null }[](#getminmaxelevation-1)
    
    Get the minimum and maximum elevation contained in a tile. This includes any exaggeration included in the terrain.
    
    #### Parameters
    
    -   tileID: [OverscaledTileID](https://docs.maptiler.com/sdk-js/api-reference/classes/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
    

### getMinTileElevationForLngLatZoom[](#getmintileelevationforlnglatzoom)

-   getMinTileElevationForLngLatZoom(lnglat: [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/), zoom: number): number[](#getmintileelevationforlnglatzoom-1)
    
    #### Parameters
    
    -   lnglat: [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/)
    -   zoom: number
    
    #### Returns number
    

### getTerrainData[](#getterraindata)

-   getTerrainData(tileID: [OverscaledTileID](https://docs.maptiler.com/sdk-js/api-reference/classes/OverscaledTileID/)): [TerrainData](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.TerrainData/)[](#getterraindata-1)
    
    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](https://docs.maptiler.com/sdk-js/api-reference/classes/OverscaledTileID/)
        
        the tile to get the terrain for
        
    
    #### Returns [TerrainData](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.TerrainData/)
    
    the terrain data to use in the program
    

### getTerrainMesh[](#getterrainmesh)

-   getTerrainMesh(tileId: [OverscaledTileID](https://docs.maptiler.com/sdk-js/api-reference/classes/OverscaledTileID/)): [Mesh](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Mesh/)[](#getterrainmesh-1)
    
    create a regular mesh which will be used by all terrain-tiles
    
    #### Parameters
    
    -   tileId: [OverscaledTileID](https://docs.maptiler.com/sdk-js/api-reference/classes/OverscaledTileID/)
    
    #### Returns [Mesh](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Mesh/)
    
    the created regular mesh
    

### pointCoordinate[](#pointcoordinate)

-   pointCoordinate(p: [Point](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Point/)): [MercatorCoordinate](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.MercatorCoordinate/)[](#pointcoordinate-1)
    
    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](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Point/)
        
        Screen-Coordinate
        
    
    #### Returns [MercatorCoordinate](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.MercatorCoordinate/)
    
    Mercator coordinate for a screen pixel, or null, if the pixel is not covered by terrain (is in the sky).
