ViewshedAnalysis
A spatial analysis object for viewshed analysis, used to perform viewshed analysis on a 3D scene.
Constructor
import { ViewshedAnalysis } from '@maptalks/gl-layers';
const viewshedAnalysis = new ViewshedAnalysis({
eyePos: [121, 39, 100],
lookPoint: [121, 39, 0],
verticalAngle: 90,
horizontalAngle: 90,
visibleColor: [0.0, 1.0, 0.0, 1.0],
invisibleColor: [1.0, 0.0, 0.0, 1.0]
});
viewshedAnalysis.addTo(groupGLLayer);Details
- options* Object configuration options, the available options are as follows:
| Option | Type | Description | Default |
|---|---|---|---|
| eyePos* | Number[] | Observer position, [x, y, h]; x and y are longitude and latitude, h is altitude | null |
| lookPoint* | Number[] | Look-at target position, [x, y, h]; x and y are longitude and latitude, h is altitude | null |
| verticalAngle | Number | Vertical angle of view, in degrees | 90 |
| horizontalAngle | Number | Horizontal angle of view, in degrees | 90 |
| visibleColor | Number[] | A 4-component normalized array; the color of the visible area | [0, 1, 0, 0.3] |
| invisibleColor | Number[] | A 4-component normalized array; the color of the invisible area | [1, 0, 0, 0.3] |
Note: The default opacity of visibleColor / invisibleColor has been adjusted to 0.3 in the new version (default values [0.0, 1.0, 0.0, 0.3] / [1.0, 0.0, 0.0, 0.3] in the 2026 source's renderAnalysis, verified 2026).
Methods
getVertexCoordinates()
Gets the coordinates of the 4 vertices of the viewshed pyramid (added after cross-checking the 2026 source code).
Returns:
- Array
Methods Inherited from Analysis
addTo(groupGLLayer)
Adds the analysis object to a GroupGLLayer.
Spatial analysis objects can only be added to a GroupGLLayer; they cannot be added to other WebGL layers.
Parameters:
- groupGLLayer GroupGLLayer the GroupGLLayer
Returns:
- this
remove()
Removes the spatial analysis object from the layer.
Returns:
- void
update(name, value)
Updates options data.
Parameters:
- name String the setting name
- value any the setting value
Returns:
- void
getAnalysisType()
Gets the type of the Analysis.
Returns:
- String
getDefines()
Internal method.
Returns the defines added to the shader when the Analysis is rendered.
Returns:
- Object
renderAnalysis(meshes)
Internal method.
Renders the spatial analysis scene (implemented by each analysis subclass) and returns the uniform variables required for rendering.
Parameters:
- meshes Mesh[] the scene meshes
Returns:
- Object
enable()
Enables the analysis.
Returns:
- void
disable()
Disables the analysis.
Returns:
- void
isEnable()
Whether the analysis is enabled.
Returns:
- Boolean
getExcludeLayers()
Gets the list of layer ids excluded from the analysis (these layers are ignored during the analysis).
Returns:
- String[]
setExcludeLayers(layerIds)
Sets the list of layer ids excluded from the analysis.
Parameters:
- layerIds String[] list of layer ids
Returns:
- void
exportAnalysisMap(meshes)
Exports the analysis result image (RGBA pixel data); returns null when the analysis is not enabled.
Parameters:
- meshes Mesh[] the scene meshes
Returns:
- Uint8Array
This document has been cross-checked against the @maptalks/gl-layers 2026 source (api-notes-others.md / api-notes-vt-gl.md)