cesium 图层构建的那些事 (二十二)

我们来构建等高线图层


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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值