feat: 新增Polygon绘制类。

pull/6/head
cbwu 1 year ago
parent 1f5c7a3244
commit 4f2823f073

@ -6,8 +6,8 @@
<script setup lang="ts"> <script setup lang="ts">
import { Angle } from '@/utils/map/angle.ts' import { Angle } from '@/utils/map/angle.ts'
import { ScreenSpaceEventHandler, Math, ScreenSpaceEventType } from 'cesium' import { ScreenSpaceEventHandler, Math, ScreenSpaceEventType } from 'cesium'
import {onMounted, ref} from "vue"; import { onMounted, ref } from 'vue'
import {cartesian2ToCartesian3} from "@/utils/map/coordinate.ts"; import { cartesian2ToCartesian3 } from '@/utils/map/coordinate.ts'
let nowLatStr: string, nowLonStr: string let nowLatStr: string, nowLonStr: string
let lonlatStr = ref('') let lonlatStr = ref('')
let isDecimal = ref(true) let isDecimal = ref(true)
@ -21,20 +21,24 @@ onMounted(()=>{
let position = cartesian2ToCartesian3(_viewer, e.endPosition) let position = cartesian2ToCartesian3(_viewer, e.endPosition)
if (position) { if (position) {
// //
let cartographic = _viewer.scene.globe.ellipsoid.cartesianToCartographic(position); let cartographic =
_viewer.scene.globe.ellipsoid.cartesianToCartographic(position)
try { try {
// //
nowLatStr = Math.toDegrees(cartographic.latitude).toFixed(7) // nowLatStr = Math.toDegrees(cartographic.latitude).toFixed(7) //
nowLonStr = Math.toDegrees(cartographic.longitude).toFixed(7) // nowLonStr = Math.toDegrees(cartographic.longitude).toFixed(7) //
let camera_alt = (_viewer.camera.positionCartographic.height / 1000) // let camera_alt = _viewer.camera.positionCartographic.height / 1000 //
// 250-80 // 250-80
let needElevation: boolean = camera_alt < 250 && (_viewer.camera.pitch < -(Math.PI/180)*80) let needElevation: boolean =
let elevStr = needElevation? _viewer.scene.globe.getHeight(cartographic)?.toFixed(2)+'m'?? '' : '高度过高' camera_alt < 250 && _viewer.camera.pitch < -(Math.PI / 180) * 80
let elevStr = needElevation
? _viewer.scene.globe.getHeight(cartographic)?.toFixed(2) + 'm' ?? ''
: '高度过高'
if(isDecimal.value) { // if (isDecimal.value) {
//
lonlatStr.value = `经度: ${nowLonStr}°, 纬度: ${nowLatStr}°, 高度: ${elevStr}` lonlatStr.value = `经度: ${nowLonStr}°, 纬度: ${nowLatStr}°, 高度: ${elevStr}`
} } else {
else {
lonlatStr.value = `经度: ${Angle.DecimalDegree2DMS(nowLonStr)}, 纬度: ${Angle.DecimalDegree2DMS(nowLatStr)}, lonlatStr.value = `经度: ${Angle.DecimalDegree2DMS(nowLonStr)}, 纬度: ${Angle.DecimalDegree2DMS(nowLatStr)},
高度: ${elevStr}` 高度: ${elevStr}`
} }
@ -47,9 +51,10 @@ function lonlatClick() {
let elevStr = lonlatStr.value.split('高度')[1] let elevStr = lonlatStr.value.split('高度')[1]
console.log(elevStr) console.log(elevStr)
if (isDecimal.value) { if (isDecimal.value) {
lonlatStr.value = `经度: ${Angle.DecimalDegree2DMS(nowLonStr)}, 纬度: ${Angle.DecimalDegree2DMS(nowLatStr)}, 高度` + elevStr lonlatStr.value =
} `经度: ${Angle.DecimalDegree2DMS(nowLonStr)}, 纬度: ${Angle.DecimalDegree2DMS(nowLatStr)}, 高度` +
else { elevStr
} else {
lonlatStr.value = `经度: ${nowLonStr}°, 纬度: ${nowLatStr}°, 高度` + elevStr lonlatStr.value = `经度: ${nowLonStr}°, 纬度: ${nowLatStr}°, 高度` + elevStr
} }
isDecimal.value = !isDecimal.value isDecimal.value = !isDecimal.value

@ -2,7 +2,7 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com * @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-07 14:15:35 * @Date: 2024-03-07 14:15:35
* @LastEditors: cbwu * @LastEditors: cbwu
* @LastEditTime: 2024-04-11 09:11:25 * @LastEditTime: 2024-04-12 09:22:20
* @Description: * @Description:
--> -->
<template> <template>
@ -23,6 +23,7 @@ import { initViewer, perfViewer, showNavigator } from '@/utils/map/sceneViewer'
import { flyToChina } from '@/utils/map/camera' import { flyToChina } from '@/utils/map/camera'
import CreatePolyline from '@/utils/map/draw/drawPolyline' import CreatePolyline from '@/utils/map/draw/drawPolyline'
// import DrawPoint from '@/utils/map/draw/drawPoint' // import DrawPoint from '@/utils/map/draw/drawPoint'
import { DrawPolygon } from '@/utils/map/draw/drawPolygon'
const viewerDivRef = ref<HTMLDivElement>() const viewerDivRef = ref<HTMLDivElement>()
let viewer: Viewer let viewer: Viewer
window.CESIUM_BASE_URL = 'node_modules/cesium/Build/Cesium/' window.CESIUM_BASE_URL = 'node_modules/cesium/Build/Cesium/'
@ -69,6 +70,8 @@ onMounted( () => {
// //
// const drawPolyline = new CreatePolyline(viewer) // const drawPolyline = new CreatePolyline(viewer)
// drawPolyline.start() // drawPolyline.start()
const drawPolygon = new DrawPolygon(viewer)
drawPolygon.start()
}) })
</script> </script>

@ -1,5 +1,5 @@
import {getAzimuth} from "@/utils/map/geocomputation.ts"; import { getAzimuth } from '@/utils/map/geocomputation.ts'
import {Cartesian3} from "cesium"; import { Cartesian3 } from 'cesium'
class Angle { class Angle {
constructor() {} constructor() {}
@ -11,17 +11,28 @@ class Angle {
*/ */
static DecimalDegree2DMS(decimal_var: number | string) { static DecimalDegree2DMS(decimal_var: number | string) {
if (!decimal_var.toString().includes('.')) if (!decimal_var.toString().includes('.'))
return decimal_var.toString() + '°0\'0\'\'' return decimal_var.toString() + "°0'0''"
let decimalStr = decimal_var.toString().split('.') let decimalStr = decimal_var.toString().split('.')
let degreeStr = decimalStr[0] let degreeStr = decimalStr[0]
if (decimalStr[1]) { if (decimalStr[1]) {
let minutes = Number(decimalStr[1]) / Math.pow(10,decimalStr[1].length) * 60 let minutes =
(Number(decimalStr[1]) / Math.pow(10, decimalStr[1].length)) * 60
if (!minutes.toString().includes('.')) if (!minutes.toString().includes('.'))
return degreeStr + '°'+ minutes.toString() +'\'0\'\'' return degreeStr + '°' + minutes.toString() + "'0''"
let minuteSecondsStr = minutes.toString().split('.') let minuteSecondsStr = minutes.toString().split('.')
if (minuteSecondsStr[1]) { if (minuteSecondsStr[1]) {
let secondStr = Number(minuteSecondsStr[1]) / Math.pow(10,minuteSecondsStr[1].length) * 60 let secondStr =
return degreeStr + '°'+ minuteSecondsStr[0] +'\'' + secondStr.toFixed(3) + '\'\'' (Number(minuteSecondsStr[1]) /
Math.pow(10, minuteSecondsStr[1].length)) *
60
return (
degreeStr +
'°' +
minuteSecondsStr[0] +
"'" +
secondStr.toFixed(3) +
"''"
)
} }
} }
return '' return ''
@ -42,16 +53,15 @@ class Angle {
* @param degree * @param degree
*/ */
static degree2rad(degree: number): number { static degree2rad(degree: number): number {
return Math.PI/180 * degree return (Math.PI / 180) * degree
} }
/** /**
* *
* @param rad * @param rad
*/ */
static rad2degree(rad: number): number { static rad2degree(rad: number): number {
return 180/Math.PI * rad return (180 / Math.PI) * rad
} }
} }
export { Angle } export { Angle }

@ -0,0 +1,160 @@
/*
* @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-04-11 13:53:40
* @LastEditors: cbwu
* @LastEditTime: 2024-04-12 15:18:40
* @Description:
*/
import {
Viewer,
ScreenSpaceEventHandler,
Cartesian3,
Color,
ScreenSpaceEventType,
Entity,
CallbackProperty,
PolylineDashMaterialProperty,
} from 'cesium'
import { cartesian2ToCartesian3 } from '@/utils/map/coordinate'
import { PolygonEntity } from '../geometry/polygonEntity'
import { PointEntity } from '@/utils/map/geometry/pointEntity'
import EditGeometry from '@/utils/map/draw/editGeometry'
export class DrawPolygon {
viewer: Viewer
handler: ScreenSpaceEventHandler
polygon: PolygonEntity | null
positions: Cartesian3[] = []
trackingLine: Entity | null
trackingLinePositions: Cartesian3[] = []
bMove: boolean = false
bLongClick: boolean = false
constructor(viewer: Viewer) {
this.viewer = viewer
this.handler = new ScreenSpaceEventHandler(viewer.scene.canvas)
this.polygon = null
this.trackingLine = null
}
public start() {
// 左单击加点
this.handler.setInputAction(
this.leftClickCallBack,
ScreenSpaceEventType.LEFT_CLICK,
)
// 移动动态绘制
this.handler.setInputAction(
this.moveCallBack,
ScreenSpaceEventType.MOUSE_MOVE,
)
// 左双击结束
this.handler.setInputAction(
this.leftDoubleClickCallBack,
ScreenSpaceEventType.LEFT_DOUBLE_CLICK,
)
}
//左单击回调事件
private leftClickCallBack = (
event: ScreenSpaceEventHandler.PositionedEvent,
) => {
const pickedObject = this.viewer.scene.pick(event.position)
// console.log(pickedObject)
if (pickedObject) {
//点击同一位置,返回
if (
pickedObject.id.id ===
this.polygon?.controlPointsID[this.positions.length - 1]
) {
console.log('********click the same point')
return
}
}
console.log('****************leftClick!')
const cartesian3 = cartesian2ToCartesian3(this.viewer, event.position)
if (cartesian3 != undefined) {
if (this.positions.length <= 2) {
this.positions.push(cartesian3)
this.trackingLinePositions.push(cartesian3)
} else {
this.polygon!.modifyPoint(cartesian3, -1)
this.polygon!.showControlPoint(-1, true)
//多创建一个点,用于鼠标移动实时变化
this.polygon!.addPoint(cartesian3, -1)
this.polygon!.showControlPoint(-1, false)
this.trackingLinePositions[2] = cartesian3
}
this.bMove = true
this.viewer.scene.requestRender() //刷新
}
}
//移动回调事件
private moveCallBack = (event: ScreenSpaceEventHandler.MotionEvent) => {
if (this.bMove) {
const cartesian3 = cartesian2ToCartesian3(this.viewer, event.endPosition)
if (cartesian3 != undefined) {
if (this.positions.length === 1) {
//更新追踪线坐标
this.trackingLinePositions[1] = cartesian3
// this.positions[1] = cartesian3
if (!this.trackingLine) {
//创建追踪线对象
this.trackingLine = this.createTrackingLine(
this.trackingLinePositions,
)
this.viewer.entities.add(this.trackingLine)
}
}
if (this.positions.length === 2) {
//移除追踪直线
if (this.trackingLine) {
this.viewer.entities.remove(this.trackingLine)
}
this.positions.push(cartesian3)
console.log(
'*********PositionsLength:' + this.positions.length.toString(),
)
//创建多边形
if (!this.polygon) {
this.polygon = new PolygonEntity(this.positions)
this.viewer.dataSources.add(this.polygon)
// 实时移动不显示控制点
this.polygon.showControlPoint(-1, false)
}
}
//实时改变多边形
if (this.positions.length >= 3) {
this.polygon!.modifyPoint(cartesian3, -1)
}
this.viewer.scene.requestRender() //刷新
}
}
}
//左双击回调事件
private leftDoubleClickCallBack = (
event: ScreenSpaceEventHandler.PositionedEvent,
) => {
if (!this.polygon) return
console.log('**************************** double click')
this.bMove = false
//移除多余的点
this.polygon.removePoint(-1)
this.polygon.removePoint(-1)
}
//创建追踪线
createTrackingLine(positions: Cartesian3[]) {
return new Entity({
polyline: {
positions: new CallbackProperty(() => {
return positions
}, false),
width: 2,
material: new PolylineDashMaterialProperty({
color: Color.GREEN,
dashLength: 15, //短划线长度
}),
clampToGround: true,
},
})
}
}

@ -2,7 +2,7 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com * @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-27 08:43:44 * @Date: 2024-03-27 08:43:44
* @LastEditors: cbwu * @LastEditors: cbwu
* @LastEditTime: 2024-04-02 13:33:25 * @LastEditTime: 2024-04-12 09:06:27
* @Description: Polyline * @Description: Polyline
*/ */
import { import {
@ -178,7 +178,7 @@ export default class CreatePolyline {
this.handler.removeInputAction(ScreenSpaceEventType.MOUSE_MOVE) this.handler.removeInputAction(ScreenSpaceEventType.MOUSE_MOVE)
this.handler.removeInputAction(ScreenSpaceEventType.LEFT_DOUBLE_CLICK) this.handler.removeInputAction(ScreenSpaceEventType.LEFT_DOUBLE_CLICK)
} }
//创建追踪线
createTrackingLine(positions: Cartesian3[]) { createTrackingLine(positions: Cartesian3[]) {
return new Entity({ return new Entity({
polyline: { polyline: {

@ -2,7 +2,7 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com * @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-15 08:43:26 * @Date: 2024-03-15 08:43:26
* @LastEditors: cbwu * @LastEditors: cbwu
* @LastEditTime: 2024-03-26 14:20:32 * @LastEditTime: 2024-04-12 10:30:36
* @FilePath: \GCSMap\src\utils\drawer.ts * @FilePath: \GCSMap\src\utils\drawer.ts
* @Description: * @Description:
*/ */

@ -5,7 +5,14 @@
* @LastEditTime: 2024-04-01 14:05:43 * @LastEditTime: 2024-04-01 14:05:43
* @Description: * @Description:
*/ */
import {Cartesian3, Cartographic, EllipsoidGeodesic, Math as Cesium_Math, Matrix4, Transforms} from 'cesium' import {
Cartesian3,
Cartographic,
EllipsoidGeodesic,
Math as Cesium_Math,
Matrix4,
Transforms,
} from 'cesium'
/** /**
* 线 * 线
* @param lineStart 线[longitude1, latitude1, height1] * @param lineStart 线[longitude1, latitude1, height1]
@ -84,16 +91,14 @@ function isOnLineSegment(
*/ */
} }
/** /**
* *
* @param p1 * @param p1
* @param p2 * @param p2
*/ */
function getDistance(p1:Cartesian3, p2: Cartesian3): number function getDistance(p1: Cartesian3, p2: Cartesian3): number {
{ let point1cartographic = Cartographic.fromCartesian(p1)
let point1cartographic = Cartographic.fromCartesian(p1); let point2cartographic = Cartographic.fromCartesian(p2)
let point2cartographic = Cartographic.fromCartesian(p2);
/**根据经纬度计算出距离**/ /**根据经纬度计算出距离**/
let geodesic = new EllipsoidGeodesic() let geodesic = new EllipsoidGeodesic()
geodesic.setEndPoints(point1cartographic, point2cartographic) geodesic.setEndPoints(point1cartographic, point2cartographic)
@ -106,20 +111,30 @@ function getDistance(p1:Cartesian3, p2: Cartesian3): number
* @param p2 * @param p2
* @param digits 1 * @param digits 1
*/ */
function getAzimuth(p1:Cartesian3, p2: Cartesian3, digits=1): string function getAzimuth(p1: Cartesian3, p2: Cartesian3, digits = 1): string {
{
// 建立局部坐标系北为y东为xp1为原点 // 建立局部坐标系北为y东为xp1为原点
const localMatrix = Transforms.eastNorthUpToFixedFrame(p1) const localMatrix = Transforms.eastNorthUpToFixedFrame(p1)
//求世界坐标到局部坐标的变换矩阵 //求世界坐标到局部坐标的变换矩阵
const worldToLocalMatrix = Matrix4.inverse(localMatrix, new Matrix4()) const worldToLocalMatrix = Matrix4.inverse(localMatrix, new Matrix4())
//p1在局部坐标系的位置即局部坐标原点 //p1在局部坐标系的位置即局部坐标原点
const localPosition1 = Matrix4.multiplyByPoint(worldToLocalMatrix, p1, new Cartesian3()) const localPosition1 = Matrix4.multiplyByPoint(
worldToLocalMatrix,
p1,
new Cartesian3(),
)
//p2在局部坐标系的位置 //p2在局部坐标系的位置
const localPosition2 = Matrix4.multiplyByPoint(worldToLocalMatrix, p2, new Cartesian3()) const localPosition2 = Matrix4.multiplyByPoint(
worldToLocalMatrix,
p2,
new Cartesian3(),
)
//弧度 //弧度
const angle = Math.atan2(localPosition2.x - localPosition1.x, localPosition2.y - localPosition1.y) const angle = Math.atan2(
localPosition2.x - localPosition1.x,
localPosition2.y - localPosition1.y,
)
//转为角度 //转为角度
let theta = angle * (180 / Math.PI); let theta = angle * (180 / Math.PI)
theta = theta < 0 ? theta + 360 : theta theta = theta < 0 ? theta + 360 : theta
return theta.toFixed(digits) return theta.toFixed(digits)
} }
@ -139,4 +154,10 @@ function getPolygonArea(vertexs: Cartesian3[]) {
return Math.abs(area) return Math.abs(area)
} }
export { getClosestPoint, isOnLineSegment, getDistance, getAzimuth, getPolygonArea } export {
getClosestPoint,
isOnLineSegment,
getDistance,
getAzimuth,
getPolygonArea,
}

@ -2,7 +2,7 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com * @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-28 16:22:58 * @Date: 2024-03-28 16:22:58
* @LastEditors: cbwu * @LastEditors: cbwu
* @LastEditTime: 2024-04-02 14:09:15 * @LastEditTime: 2024-04-12 14:57:49
* @Description: * @Description:
*/ */
import { import {
@ -37,16 +37,21 @@ export abstract class BaseGeometry extends CustomDataSource {
* , * ,
* @param pos * @param pos
* @param index 0 * @param index 0
* @bAddControlPoint
*/ */
public addPoint(pos: Cartesian3, index: number = -1) { public addPoint(
pos: Cartesian3,
index: number = -1,
bAddControlPoint: boolean = true,
) {
if (index === -1) { if (index === -1) {
//插入尾部 //插入尾部
this.positions.push(pos) this.positions.push(pos)
// console.log(this.positions.length) if (bAddControlPoint)
this.createPoint(pos, this.positions.length - 1) this.createControlPoint(pos, this.positions.length - 1)
} else if (index >= 0 && index < this.positions.length) { } else if (index >= 0 && index < this.positions.length) {
this.positions.splice(index, 0, pos) this.positions.splice(index, 0, pos)
this.createPoint(pos, index) if (bAddControlPoint) this.createControlPoint(pos, index)
} else { } else {
return return
} }
@ -62,11 +67,11 @@ export abstract class BaseGeometry extends CustomDataSource {
this.positions.pop() this.positions.pop()
} else if (index >= 0 && index < this.positions.length) { } else if (index >= 0 && index < this.positions.length) {
this.positions.splice(index, 1) this.positions.splice(index, 1)
this.entities.removeById(this.controlPointsID[index])
this.controlPointsID.splice(index, 1)
} else { } else {
return return
} }
//移除控制点
this.removeControlPoint(index)
} }
/** /**
* *
@ -74,8 +79,12 @@ export abstract class BaseGeometry extends CustomDataSource {
* @param index * @param index
*/ */
public modifyPoint(pos: Cartesian3, index: number) { public modifyPoint(pos: Cartesian3, index: number) {
if (index === -1) {
index = this.positions.length - 1
}
if (index >= 0 && index < this.positions.length) { if (index >= 0 && index < this.positions.length) {
this.positions.splice(index, 1, pos) this.positions.splice(index, 1, pos)
if (this.controlPointsID[index]) {
//修改控制点坐标 //修改控制点坐标
const point = this.entities.getById(this.controlPointsID[index]) const point = this.entities.getById(this.controlPointsID[index])
if (point) { if (point) {
@ -83,12 +92,13 @@ export abstract class BaseGeometry extends CustomDataSource {
} }
} }
} }
}
/** /**
* *
* @param pos * @param pos
* @param index ,0 * @param index ,0
*/ */
createPoint(pos: Cartesian3, index: number) { public createControlPoint(pos: Cartesian3, index: number) {
// if (this.geometry) { // if (this.geometry) {
const point = new PointEntity(pos) const point = new PointEntity(pos)
point.parent = this.geometry! point.parent = this.geometry!
@ -97,6 +107,17 @@ export abstract class BaseGeometry extends CustomDataSource {
this.controlPointsID.splice(index, 0, point.id) 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)
}
}
/** /**
* *
*/ */
@ -106,4 +127,16 @@ export abstract class BaseGeometry extends CustomDataSource {
}) })
this.controlPointsID = [] 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
}
}
} }

@ -2,7 +2,7 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com * @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-28 16:35:33 * @Date: 2024-03-28 16:35:33
* @LastEditors: cbwu * @LastEditors: cbwu
* @LastEditTime: 2024-03-30 22:06:23 * @LastEditTime: 2024-04-12 15:43:49
* @Description: * @Description:
*/ */
import { import {
@ -39,8 +39,9 @@ class PointEntity extends Entity {
id: 'Point' + String(PointEntity.ID), id: 'Point' + String(PointEntity.ID),
name: 'Point' + String(PointEntity.ID + 1), name: 'Point' + String(PointEntity.ID + 1),
show: true, show: true,
pixelSize: 10, pixelSize: 8,
color: Color.GREEN, color: Color.WHITE,
outlineColor: Color.GREEN,
outlineWidth: 0, outlineWidth: 0,
} }
constructor(position: Cartesian3, options?: EntityOptions) { constructor(position: Cartesian3, options?: EntityOptions) {

@ -2,7 +2,7 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com * @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-04-11 09:26:56 * @Date: 2024-04-11 09:26:56
* @LastEditors: cbwu * @LastEditors: cbwu
* @LastEditTime: 2024-04-11 13:26:25 * @LastEditTime: 2024-04-12 15:34:45
* @Description: Polygon * @Description: Polygon
*/ */
import { import {
@ -10,8 +10,7 @@ import {
Cartesian3, Cartesian3,
Color, Color,
CallbackProperty, CallbackProperty,
Property, PolygonHierarchy,
PolygonGraphics,
} from 'cesium' } from 'cesium'
import { BaseGeometry } from './baseGeometry' import { BaseGeometry } from './baseGeometry'
import { type EntityOptions } from './pointEntity' import { type EntityOptions } from './pointEntity'
@ -28,20 +27,30 @@ export class PolygonEntity extends BaseGeometry {
fillColor: Color.RED.withAlpha(0.5), fillColor: Color.RED.withAlpha(0.5),
fill: true, fill: true,
} }
constructor(ptArr: Cartesian3[] | Property, options?: EntityOptions) { constructor(ptArr: Cartesian3[], options?: EntityOptions) {
super() super()
this.positions = ptArr
this.options = { ...this.options, ...options } this.options = { ...this.options, ...options }
this.geometry = new Entity({ this.geometry = new Entity({
show: this.options.show, show: this.options.show,
name: this.options.name, name: this.options.name,
polygon: { polygon: {
hierarchy: ptArr, hierarchy: new CallbackProperty(() => {
return new PolygonHierarchy(this.positions)
}, false),
material: this.options.fillColor, //填充颜色 material: this.options.fillColor, //填充颜色
fill: this.options.fill, //是否填充 fill: this.options.fill, //是否填充
outlineWidth: this.options.width, //线宽 outline: true,
// outlineWidth: this.options.width, //线宽
outlineColor: this.options.color, //线颜色 outlineColor: this.options.color, //线颜色
}, },
}) })
this.entities.add(this.geometry)
// 添加控制点
ptArr.forEach((pt, index) => {
this.createControlPoint(pt, index)
})
PolygonEntity.ID++ PolygonEntity.ID++
} }
} }

@ -2,7 +2,7 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com * @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-28 16:49:02 * @Date: 2024-03-28 16:49:02
* @LastEditors: cbwu * @LastEditors: cbwu
* @LastEditTime: 2024-04-01 17:04:55 * @LastEditTime: 2024-04-12 14:27:12
* @Description: Polyline * @Description: Polyline
*/ */
import { Entity, Cartesian3, Color, CallbackProperty } from 'cesium' import { Entity, Cartesian3, Color, CallbackProperty } from 'cesium'
@ -40,7 +40,7 @@ export class PolylineEntity extends BaseGeometry {
this.entities.add(this.geometry) this.entities.add(this.geometry)
// 添加控制点 // 添加控制点
ptArr.forEach((pt, index) => { ptArr.forEach((pt, index) => {
this.createPoint(pt, index) this.createControlPoint(pt, index)
}) })
PolylineEntity.ID++ PolylineEntity.ID++

Loading…
Cancel
Save