剖面分析
DMap3D.analysis.profile 用于分析地形沿路径的高程剖面,并以图表形式展示。
引入
import DMap3D from 'dmap3d'
import * as Cesium from 'cesium'
基本用法
const viewer = new Cesium.Viewer('cesiumContainer')
// 创建剖面分析工具
const profile = new DMap3D.analysis.profile(viewer)
// 监听分析完成事件
profile.onAnalysisEnd((result) => {
result.forEach((point) => {
console.log(`距离: ${point.distance}m, 坐标: ${point.lnglat}`)
})
})
// 激活绘制(用户在场景中绘制路径)
profile.activate()
构造函数
new DMap3D.analysis.profile(viewer, options?)
参数:
viewer- Cesium.Viewer 实例options?- 可选配置项
Options:
interface ProfileOptions {
perStep?: number // 采样点个数,10-500,默认 50
perExpansion?: number // 扩充点个数,0-100,默认 20
showChart?: boolean // 是否显示图表,默认 true
chartPosition?: { // 图表位置
bottom?: string
left?: string
width?: string
height?: string
}
}
方法
activate()
激活路径绘制功能。
profile.activate()
deactivate()
停用绘制功能。
profile.deactivate()
startAnalysis(coords, distances)
通过坐标数组直接执行剖面分析。
const coords = [
[116.4074, 39.9042, 100],
[116.4174, 39.9142, 200],
[116.4274, 39.9042, 150]
]
const distances = [0, 1500, 3000]
const result = await profile.startAnalysis(coords, distances)
clear()
清除绘制内容。
profile.clear()
setPerStep(value)
设置采样点个数(10-500)。
profile.setPerStep(100)
setPerExpansion(value)
设置扩充点个数(0-100)。
profile.setPerExpansion(30)
showChart() / hideChart()
显示或隐藏剖面图表。
profile.showChart()
profile.hideChart()
getAnalysisResult()
获取分析结果数据。
const result = profile.getAnalysisResult()
destroy()
销毁工具并释放资源。
profile.destroy()
分析结果
interface ProfileResultPoint {
distance: number // 距起点的距离(米)
lnglat: [number, number, number] // [经度, 纬度, 高度]
}
完整示例
const viewer = new Cesium.Viewer('cesiumContainer')
// 创建剖面分析工具
const profile = new DMap3D.analysis.profile(viewer, {
perStep: 100,
perExpansion: 30,
showChart: true,
chartPosition: {
bottom: '20px',
left: '20px',
width: '600px',
height: '300px'
}
})
// 监听分析完成
profile.onAnalysisEnd((result) => {
console.log('剖面点数:', result.length)
const maxHeight = Math.max(...result.map(p => p.lnglat[2]))
console.log('最高点:', maxHeight, '米')
})
// 激活绘制
profile.activate()
// 销毁
profile.destroy()