Viewshed Area Analysis
DMap3D.analysis.viewshedArea performs regional visibility analysis based on frustum, displaying visible/invisible areas in the scene.
Import
import DMap3D from 'dmap3d'
import * as Cesium from 'cesium'
Basic Usage
const viewer = new Cesium.Viewer('cesiumContainer')
// Create viewshed area analysis tool
const viewshedArea = new DMap3D.analysis.viewshedArea(viewer)
// Interactive analysis (click two points: observer point and direction point)
viewshedArea.startAnalysis()
Constructor
new DMap3D.analysis.viewshedArea(viewer, options?)
Parameters:
viewer- Cesium.Viewer instanceoptions?- Optional configuration
Options:
interface ViewshedAreaOptions {
baseColor?: string // Wireframe color
visibleColor?: string // Visible area color
invisibleColor?: string // Invisible area color
visibleColorAlpha?: number // Visible area opacity (0-1)
invisibleColorAlpha?: number // Invisible area opacity (0-1)
fovx?: number // Horizontal field of view (1-130 degrees)
fovy?: number // Vertical field of view (1-179 degrees)
lineWidth?: number // Wireframe width
useLighting?: boolean // Whether to use lighting
heightOffset?: number // Observer height offset
showFrustumRefLines?: boolean // Whether to show reference lines
}
Methods
startAnalysis()
Start interactive analysis. The user clicks two points in the scene (observer point and direction point).
viewshedArea.startAnalysis()
setPositionAnalysis(params)
Set analysis area directly via coordinates, without interaction.
viewshedArea.setPositionAnalysis({
startPosition: [116.4074, 39.9042, 100], // [longitude, latitude, height]
endPosition: [116.4174, 39.9142, 50]
})
destroy()
Destroy the tool and release resources.
viewshedArea.destroy()
Dynamic Properties
The following properties can be dynamically adjusted after analysis:
// Field of view adjustment
viewshedArea.fovx = 90 // Horizontal field of view (1-130 degrees)
viewshedArea.fovy = 60 // Vertical field of view (1-179 degrees)
// Range and angle
viewshedArea.radiusScale = 1.5 // Analysis range scale
viewshedArea.offsetHeading = 30 // Horizontal rotation angle
viewshedArea.offsetPitch = -10 // Vertical rotation angle
// Color settings
viewshedArea.visibleColor = '#00FF00'
viewshedArea.invisibleColor = '#FF0000'
viewshedArea.visibleColorAlpha = 0.5
viewshedArea.invisibleColorAlpha = 0.5
// Other
viewshedArea.heightOffset = 1.8 // Observer height offset
viewshedArea.useLighting = true // Use lighting
viewshedArea.showFrustumRefLines = true // Show reference lines
Complete Example
const viewer = new Cesium.Viewer('cesiumContainer')
// Create viewshed area analysis tool
const viewshedArea = new DMap3D.analysis.viewshedArea(viewer, {
fovx: 90,
fovy: 60,
visibleColor: '#00FF00',
invisibleColor: '#FF0000',
visibleColorAlpha: 0.4,
invisibleColorAlpha: 0.4
})
// Analyze directly via coordinates
viewshedArea.setPositionAnalysis({
startPosition: [116.4074, 39.9042, 100],
endPosition: [116.4174, 39.9142, 50]
})
// Dynamically adjust parameters
viewshedArea.fovx = 120
viewshedArea.offsetHeading = 45
// Destroy
viewshedArea.destroy()