You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
GCSGUI/src/utils/map/geometry/baseGeometry.ts

145 lines
3.8 KiB
TypeScript

/*
* @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-28 16:22:58
* @LastEditors: cbwu
* @LastEditTime: 2024-04-22 11:32:00
* @Description:
*/
import {
// EntityCollection,
Entity,
Cartesian3,
Color,
ConstantPositionProperty,
CustomDataSource,
} from 'cesium'
import { PointEntity } from './pointEntity'
import { EntityOptions } from '@/types/entityoptions'
export abstract class BaseGeometry extends CustomDataSource {
static ID: number
// abstract subId: number
geometry: Entity | null = null
positions: Cartesian3[] = []
controlPointsID: string[] = [] //存储
options: EntityOptions = {
// id: 'Point' + String(PointEntity.ID),
// name: 'Point' + String(PointEntity.ID + 1),
show: true,
// pixelSize: 10,
width: 2,
color: Color.GREEN,
outlineWidth: 0,
}
constructor() {
super()
}
/**
* ,
* @param pos
* @param index 0
* @param bAddControlPoint
* @bAddControlPoint
*/
public addPoint(
pos: Cartesian3,
index: number = -1,
bAddControlPoint: boolean = true,
) {
if (index === -1) {
//插入尾部
this.positions.push(pos)
if (bAddControlPoint)
this.createControlPoint(pos, this.positions.length - 1)
} else if (index >= 0 && index < this.positions.length) {
this.positions.splice(index, 0, pos)
if (bAddControlPoint) this.createControlPoint(pos, index)
} else {
return
}
}
/**
*
* @param index
* @returns
*/
public removePoint(index: number = -1) {
if (index === -1 || index === this.positions.length - 1) {
//移除尾部元素
this.positions.pop()
} else if (index >= 0 && index < this.positions.length) {
this.positions.splice(index, 1)
} else {
return
}
//移除控制点
this.removeControlPoint(index)
}
/**
*
* @param pos
* @param index
*/
public modifyPoint(pos: Cartesian3, index: number) {
if (index === -1) {
index = this.positions.length - 1
}
if (index >= 0 && index < this.positions.length) {
this.positions.splice(index, 1, pos)
if (this.controlPointsID[index]) {
//修改控制点坐标
const point = this.entities.getById(this.controlPointsID[index])
if (point) {
point.position = new ConstantPositionProperty(pos)
}
}
}
}
/**
*
* @param pos
* @param index ,0
*/
public createControlPoint(pos: Cartesian3, index: number) {
// if (this.geometry) {
const point = new PointEntity(pos)
point.parent = this.geometry!
point.subId = index
this.entities.add(point)
this.controlPointsID.splice(index, 0, point.id)
// }
}
/**
*
* @param index
*/
public removeControlPoint(index: number) {
if (index === -1) index = this.controlPointsID.length - 1
if (this.controlPointsID[index]) {
this.entities.removeById(this.controlPointsID[index])
this.controlPointsID.splice(index, 1)
}
}
/**
*
*/
removeControlPoints() {
this.controlPointsID.forEach((value) => {
this.entities.removeById(value)
})
this.controlPointsID = []
}
/**
*
* @param index
* @param bShow
*/
showControlPoint(index: number, bShow: boolean) {
if (index === -1) index = this.controlPointsID.length - 1
if (this.controlPointsID[index]) {
const point = this.entities.getById(this.controlPointsID[index])
if (point) point.show = bShow
}
}
}