cesium 图层构建的那些事 (二十二)
我们来构建等高线图层
```javascript
import {Layer} from "./Layer";
import { GraphicLayer } from "./GraphicLayer";
export class IsoLineLayer extends Layer {
private option: any;
protected isAdd2LoadCesium = true;
constructor(option: any) {
super(option.name);
this.option = option;
}
public flyTo(duration?: number, pitch?: number, heading?: number, range?: number, maximumHeight?: number): this {
if (this.map) {
this.cesiumObj.flyTo(duration,pitch,heading,range,maximumHeight);
}
return this;
}
protected _addToMap(map: any): void {
this.cesiumObj = this.createIsoLine();
map.dataSources.add(this.cesiumObj);
}
-
protected _removeByMap(destroy?: boolean): void {
-
this.map.dataSources.remove(this.cesiumObj);
-
}
-
private createIsoLine(){
-
var lines:any = this.getIsoLine();
-
const levels = this.option.levels;
-
const gl = new GraphicLayer();
-
for(let index=0;index<lines.features.length;index++){
-
const feature = lines.features[index];
-
const coordinates = feature.geometry.coordinates
-
let level:any = levels[feature.properties.value];
-
const style = level ? level.style : {
-
width: 5,
-
material: Cesium.Color.RED
-
};
-
for(let i = 0;i < coordinates.length;i++){
-
const positions = coordinates[i];
-
gl.addByOption({
-
id: index+"线"+ i,
-
polyline: {
-
positions: positions,
-
...style
-
}
-
});
-
}
-
}
-
return gl;
-
}
-
//采用网格特征和点特征的z值和值断点数组并生成等值线。
-
private getIsoLine() {
-
const {points, levels} = this.option;
-
const breaks = levels.map((level:any)=>{
-
return level.value;
-
})
-
const features = points.map((item:any)=>{
-
const p = turf.point(item.coordinates);
-
p.properties!.value = item.value;
-
return p;
-
});
-
var collection:any = turf.featureCollection(features);
-
var lines = turf.isolines(collection, breaks, {zProperty: 'value'});
-
return lines;
-
}
更多参考 https://xiaozhuanlan.com/topic/0792451836
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律