Compare commits

..

No commits in common. 'fbad4dba03ccde60f2093e7a670dc3da1b0b2f35' and 'e50790c3e9efff5064ca8d288e18113632aa7ea6' have entirely different histories.

@ -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-16 19:06:50 * @LastEditTime: 2024-04-15 16:00:27
* @Description: * @Description:
--> -->
<template> <template>
@ -22,7 +22,7 @@ import {
import { initViewer, perfViewer, showNavigator } from '@/utils/map/sceneViewer' 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 { inputGeoJson } from '@/utils/DataIO.ts' import {inputGeoJson} from "@/utils/DataIO.ts";
// import DrawPoint from '@/utils/map/draw/drawPoint' // import DrawPoint from '@/utils/map/draw/drawPoint'
import { DrawPolygon } from '@/utils/map/draw/drawPolygon' import { DrawPolygon } from '@/utils/map/draw/drawPolygon'
const viewerDivRef = ref<HTMLDivElement>() const viewerDivRef = ref<HTMLDivElement>()
@ -67,12 +67,12 @@ onMounted(() => {
// window // window
window.viewer = viewer window.viewer = viewer
// inputGeoJson(viewer) inputGeoJson(viewer)
// //
const drawPolyline = new CreatePolyline(viewer) // const drawPolyline = new CreatePolyline(viewer,true,{})
drawPolyline.start() // drawPolyline.start()
// const drawPolygon = new DrawPolygon(viewer) const drawPolygon = new DrawPolygon(viewer,true)
// drawPolygon.start() drawPolygon.start()
}) })
</script> </script>

@ -2,10 +2,10 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com * @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-04-13 10:36:06 * @Date: 2024-04-13 10:36:06
* @LastEditors: cbwu * @LastEditors: cbwu
* @LastEditTime: 2024-04-16 13:47:55 * @LastEditTime: 2024-04-13 11:14:53
* @Description: * @Description:
*/ */
import { Color, Cartesian2, HeightReference } from 'cesium' import { Color, Cartesian2 } from 'cesium'
export interface EntityOptions { export interface EntityOptions {
id?: string id?: string
name?: string name?: string
@ -23,5 +23,4 @@ export interface EntityOptions {
image?: string //图片url image?: string //图片url
imageWidth?: number //图片宽 imageWidth?: number //图片宽
imageHeight?: number //图片高 imageHeight?: number //图片高
heightReference?: HeightReference
} }

@ -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-22 16:19:27 * @LastEditTime: 2024-04-13 10:46:58
* @Description: Polyline * @Description: Polyline
*/ */
import { import {
@ -14,22 +14,26 @@ import {
Entity, Entity,
CallbackProperty, CallbackProperty,
PolylineDashMaterialProperty, PolylineDashMaterialProperty,
Cartesian2,
HeightReference,
} from 'cesium' } from 'cesium'
import { import { cartesian2ToCartesian3 } from '@/utils/map/coordinate'
cartesian2ToCartesian3,
cartesian3ToWGS84,
} from '@/utils/map/coordinate'
// import { PointEntity, PolylineEntity } from '@/utils/map/geometry' // import { PointEntity, PolylineEntity } from '@/utils/map/geometry'
import { PolylineEntity } from '../geometry/polylineEntity' import { PolylineEntity } from '../geometry/polylineEntity'
import { PointEntity } from '@/utils/map/geometry/pointEntity' import { PointEntity } from '@/utils/map/geometry/pointEntity'
import EditGeometry from '@/utils/map/draw/editGeometry' import EditGeometry from '@/utils/map/draw/editGeometry'
import { getDistance } from '@/utils/map/geocomputation.ts' import {getDistance} from "@/utils/map/geocomputation.ts";
import { Angle } from '@/utils/map/angle.ts' import {Angle} from "@/utils/map/angle.ts";
import { TextLabel } from '@/utils/map/geometry/textLabel.ts' import {TextLabel} from "@/utils/map/geometry/textLabel.ts";
import { EntityOptions } from '@/types/entityoptions.ts' type EntityOptions = {
id?: string
name?: string
show?: boolean
pixelSize?: number
color?: Color
fillColor?: Color
fill?: boolean
width?: number
outlineWidth?: number
}
export default class CreatePolyline { export default class CreatePolyline {
viewer: Viewer viewer: Viewer
handler: ScreenSpaceEventHandler handler: ScreenSpaceEventHandler
@ -43,15 +47,10 @@ export default class CreatePolyline {
moveSelectedPoint: PointEntity | null = null moveSelectedPoint: PointEntity | null = null
positions: Cartesian3[] = [] positions: Cartesian3[] = []
bMove: boolean = false bMove: boolean = false
bMeasure: boolean | undefined = false //是否处于测距模式 bMeasure: boolean | undefined = false //是否处于测距模式
totalDistance: number = 0 totalDistance: number = 0
bLongClick: boolean = false bLongClick: boolean = false
clickTimeout: any clickTimeout: any
altitudeOffset: number = 20 //相对高度
vDashLinePosition: Cartesian3[][] = [] //垂直辅助线坐标数组
// 存储第一次点击的信息
firstClickPosition: Cartesian2 | null = null
firstClickTime: number | null = null
// layer: CustomDataSource // layer: CustomDataSource
defaultStyle: EntityOptions = { defaultStyle: EntityOptions = {
// id: 'Polyline' + String(PolylineEntity.id), // id: 'Polyline' + String(PolylineEntity.id),
@ -60,13 +59,9 @@ export default class CreatePolyline {
width: 2, width: 2,
color: Color.GREEN, color: Color.GREEN,
} }
constructor( constructor(viewer: Viewer, bMeasure: boolean=false,options?: EntityOptions) {
viewer: Viewer,
bMeasure: boolean = false,
options?: EntityOptions,
) {
this.viewer = viewer this.viewer = viewer
this.bMeasure = bMeasure this.bMeasure = bMeasure;
this.handler = new ScreenSpaceEventHandler(this.viewer.scene.canvas) this.handler = new ScreenSpaceEventHandler(this.viewer.scene.canvas)
this.polyline = null this.polyline = null
this.trackingLine = null this.trackingLine = null
@ -103,13 +98,14 @@ export default class CreatePolyline {
} }
//左单击回调事件 //左单击回调事件
private leftClickCallBack = ( private leftClickCallBack = (event: ScreenSpaceEventHandler.PositionedEvent) => {
event: ScreenSpaceEventHandler.PositionedEvent, const pickedObject = this.viewer.scene.pick(event.position)
) => { if (pickedObject) {
//根据屏幕坐标判断是否为同一点 //点击同一位置,返回
if (this.isSamplePosition(event.position.clone())) return if (pickedObject.id.id === this.polyline?.controlPointsID[this.positions.length - 1])
return
let cartesian3 = cartesian2ToCartesian3(this.viewer, event.position) }
const cartesian3 = cartesian2ToCartesian3(this.viewer, event.position)
if (cartesian3 != undefined) { if (cartesian3 != undefined) {
if (!this.polyline) { if (!this.polyline) {
this.polyline = new PolylineEntity(this.positions) this.polyline = new PolylineEntity(this.positions)
@ -117,60 +113,29 @@ export default class CreatePolyline {
this.viewer.entities.add(this.dashLine) this.viewer.entities.add(this.dashLine)
this.viewer.dataSources.add(this.polyline) this.viewer.dataSources.add(this.polyline)
} }
const oldPosition = cartesian3
//计算高度偏移后的新坐标
cartesian3 = this.calculateAltitudeOffsetPosition(
cartesian3,
this.altitudeOffset,
)
this.polyline.addPoint(cartesian3) this.polyline.addPoint(cartesian3)
this.trackingLinePositions[0] = cartesian3 this.trackingLinePositions[0] = cartesian3
//垂直辅助线
const n = this.positions.length - 1
const ptArr = [oldPosition, cartesian3]
this.vDashLinePosition[n] = ptArr
this.viewer.entities.add(
this.createTrackingLine(this.vDashLinePosition[n], Color.WHITE),
)
//添加地表控制点
const groundControlPoint = new PointEntity(this.vDashLinePosition[n][0])
this.viewer.entities.add(groundControlPoint)
this.bMove = true this.bMove = true
this.viewer.scene.requestRender() //刷新 this.viewer.scene.requestRender() //刷新
// 计算2点距离 // 计算2点距离
if (this.positions.length >= 2 && this.bMeasure) { if(this.positions.length>=2 && this.bMeasure){
const distance = getDistance( let distance = getDistance(this.positions[this.positions.length-1],this.positions[this.positions.length-2])
this.positions[this.positions.length - 1],
this.positions[this.positions.length - 2],
)
this.totalDistance += distance this.totalDistance += distance
// 计算2点方位角 // 计算2点方位角
const azimuth = Angle.getAzimuth( let azimuth = Angle.getAzimuth(this.positions[this.positions.length-2],this.positions[this.positions.length-1])
this.positions[this.positions.length - 2],
this.positions[this.positions.length - 1],
)
// 计算2点的中间点 // 计算2点的中间点
const midPoint = Cartesian3.midpoint( let midPoint = Cartesian3.midpoint(this.positions[this.positions.length-1],this.positions[this.positions.length-2],new Cartesian3())
this.positions[this.positions.length - 1],
this.positions[this.positions.length - 2],
new Cartesian3(),
)
// 添加label // 添加label
const labelText = `距离: ${distance.toFixed(2)}km, 方位角: ${azimuth}°` let labelText = `距离: ${distance.toFixed(2)}km, 方位角: ${azimuth}°`
new TextLabel(this.viewer, midPoint, labelText) new TextLabel(this.viewer, midPoint,labelText)
} }
} }
} }
// 移动回调事件 // 移动回调事件
private moveCallBack = (event: ScreenSpaceEventHandler.MotionEvent) => { private moveCallBack = (event: ScreenSpaceEventHandler.MotionEvent) => {
if (this.bMove) { if (this.bMove) {
let cartesian3 = cartesian2ToCartesian3(this.viewer, event.endPosition) const cartesian3 = cartesian2ToCartesian3(this.viewer, event.endPosition)
if (cartesian3 != undefined) { if (cartesian3 != undefined) {
//计算高度偏移后的新坐标
cartesian3 = this.calculateAltitudeOffsetPosition(
cartesian3,
this.altitudeOffset,
)
//更新追踪线坐标 //更新追踪线坐标
this.trackingLinePositions[1] = cartesian3 this.trackingLinePositions[1] = cartesian3
if (!this.trackingLine) { if (!this.trackingLine) {
@ -185,9 +150,7 @@ export default class CreatePolyline {
} }
} }
// 左双击回调事件 // 左双击回调事件
private leftDoubleClickCallBack = ( private leftDoubleClickCallBack = (event: ScreenSpaceEventHandler.PositionedEvent,) => {
event: ScreenSpaceEventHandler.PositionedEvent,
) => {
if (!this.polyline) return if (!this.polyline) return
this.bMove = false this.bMove = false
const cartesian3 = cartesian2ToCartesian3(this.viewer, event.position) const cartesian3 = cartesian2ToCartesian3(this.viewer, event.position)
@ -198,18 +161,12 @@ export default class CreatePolyline {
} }
} }
if (this.bMeasure) { if(this.bMeasure){
// 添加总距离label // 添加总距离label
new TextLabel( new TextLabel(this.viewer,this.positions[this.positions.length-1],
this.viewer, `总距离: ${this.totalDistance.toFixed(2)}km`)
this.positions[this.positions.length - 1],
`总距离: ${this.totalDistance.toFixed(2)}km`,
)
} }
this.clearEvent() this.clearEvent()
console.log('end:' + this.positions.length.toString())
console.log(this.positions)
console.log(this.polyline.controlPointsID.length)
//结束绘制进入编辑模式 //结束绘制进入编辑模式
this.polyline.removeControlPoints() this.polyline.removeControlPoints()
const editTool = new EditGeometry(this.viewer, this.polyline.geometry!) const editTool = new EditGeometry(this.viewer, this.polyline.geometry!)
@ -230,21 +187,8 @@ 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)
} }
//计算高度偏移后的坐标
calculateAltitudeOffsetPosition(
oldPosition: Cartesian3,
altitudeOffset: number,
): Cartesian3 {
const newGeoPosition = cartesian3ToWGS84(oldPosition)
newGeoPosition[2] = newGeoPosition[2] + altitudeOffset
return Cartesian3.fromDegrees(
newGeoPosition[0],
newGeoPosition[1],
newGeoPosition[2],
)
}
//创建追踪线 //创建追踪线
createTrackingLine(positions: Cartesian3[], color: Color = Color.GREEN) { createTrackingLine(positions: Cartesian3[]) {
return new Entity({ return new Entity({
polyline: { polyline: {
positions: new CallbackProperty(() => { positions: new CallbackProperty(() => {
@ -252,35 +196,11 @@ export default class CreatePolyline {
}, false), }, false),
width: 2, width: 2,
material: new PolylineDashMaterialProperty({ material: new PolylineDashMaterialProperty({
color: color, color: Color.GREEN,
dashLength: 12, //短划线长度 dashLength: 15, //短划线长度
}), }),
// clampToGround: true, clampToGround: true,
}, },
}) })
} }
//判断点击是否同一位置
isSamplePosition(clickPosition: Cartesian2) {
if (this.firstClickPosition) {
const dist = Cartesian2.distance(this.firstClickPosition, clickPosition)
if (dist <= 3) {
console.log('********click the same point0')
return true
}
}
this.firstClickPosition = clickPosition
// const pickedObject = this.viewer.scene.pick(clickPosition)
// if (pickedObject) {
// //点击同一位置,返回
// if (
// pickedObject.id.id ===
// this.polyline?.controlPointsID[this.positions.length - 1]
// ) {
// console.log('********click the same point')
// return
// }
// }
return false
}
} }

@ -2,7 +2,7 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com * @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-27 11:06:45 * @Date: 2024-03-27 11:06:45
* @LastEditors: cbwu * @LastEditors: cbwu
* @LastEditTime: 2024-04-22 16:49:15 * @LastEditTime: 2024-04-13 10:47:09
* @Description: * @Description:
*/ */
import { import {
@ -16,10 +16,6 @@ import {
Entity, Entity,
ConstantPositionProperty, ConstantPositionProperty,
defined, defined,
CallbackProperty,
PolylineDashMaterialProperty,
Color,
Cartographic,
} from 'cesium' } from 'cesium'
import { cartesian2ToCartesian3 } from '@/utils/map/coordinate' import { cartesian2ToCartesian3 } from '@/utils/map/coordinate'
import { getClosestPoint, isOnLineSegment } from '@/utils/map/geocomputation' import { getClosestPoint, isOnLineSegment } from '@/utils/map/geocomputation'
@ -30,12 +26,8 @@ export default class EditGeometry {
geometry: Entity //要编辑的几何对象 geometry: Entity //要编辑的几何对象
oldPositions: Cartesian3[] = [] //存储未修改前的坐标 oldPositions: Cartesian3[] = [] //存储未修改前的坐标
positions: Cartesian3[] = [] //要编辑的几个对象坐标 positions: Cartesian3[] = [] //要编辑的几个对象坐标
controlPointsID: string[] = [] //节点控制点ID数组 controlPointsID: string[] = []
groundPointsID: string[] = [] //地表控制点ID数组 controlPoint: PointEntity | null = null
groundDashLineID: string[] = [] //垂直辅助线ID数组
groundDashLinesPosition: Cartesian3[][] = [] //垂直辅助线坐标数组
heightPoint: PointEntity | null = null //高度控制点
groundPoint: PointEntity | null = null //地表控制点
clickedGeometry: Entity | null = null clickedGeometry: Entity | null = null
clickDownPosition: Cartesian3 | null = null clickDownPosition: Cartesian3 | null = null
moveSelectedPoint: PointEntity | null = null moveSelectedPoint: PointEntity | null = null
@ -54,13 +46,6 @@ export default class EditGeometry {
// 创建控制点 // 创建控制点
this.positions.forEach((value, index) => { this.positions.forEach((value, index) => {
this.createPoint(value, index) this.createPoint(value, index)
//地表点
const groundPosition = this.calculateGroundPosition(value)
this.createGroundPoint(value, index)
//垂直辅助线
const ptArr = [value, groundPosition]
this.groundDashLinesPosition[index] = ptArr
this.createGroundDashLine(this.groundDashLinesPosition[index], index)
}) })
} }
public start() { public start() {
@ -101,7 +86,7 @@ export default class EditGeometry {
) => { ) => {
// 清除可能已经设置的单击定时器 // 清除可能已经设置的单击定时器
clearTimeout(this.clickTimeout) clearTimeout(this.clickTimeout)
// 判断是不是长按(100ms) // 判断是不是长按
this.clickTimeout = setTimeout(() => { this.clickTimeout = setTimeout(() => {
this.bLongClick = true this.bLongClick = true
}, 100) }, 100)
@ -126,14 +111,8 @@ export default class EditGeometry {
// 点中控制点 // 点中控制点
if (pickedObject.id.point instanceof PointGraphics) { if (pickedObject.id.point instanceof PointGraphics) {
console.log('You clicked a point entity.') console.log('You clicked a point entity.')
if (pickedObject.id.point.type === 0) { this.controlPoint = pickedObject.id
console.log('You clicked a HeightPoint entity.') console.log(this.controlPoint?.subId)
this.heightPoint = pickedObject.id
} else if (pickedObject.id.point.type === 1) {
console.log('You clicked a GroundPoint entity.')
this.groundPoint = pickedObject.id
}
// console.log(this.heightPoint?.subId)
this.bDrag = true this.bDrag = true
this.forbidDrawWorld(true) this.forbidDrawWorld(true)
} }
@ -155,7 +134,7 @@ export default class EditGeometry {
) { ) {
this.moveSelectedPoint = pickedObject.id this.moveSelectedPoint = pickedObject.id
this.moveSelectedPoint!.point!.pixelSize = new ConstantProperty( this.moveSelectedPoint!.point!.pixelSize = new ConstantProperty(
this.moveSelectedPoint!.options.pixelSize! + 1, this.moveSelectedPoint!.options.pixelSize! + 2,
) )
// console.log(this.moveSelectedPoint) // console.log(this.moveSelectedPoint)
} }
@ -165,19 +144,19 @@ export default class EditGeometry {
// 离开控制点恢复原始大小 // 离开控制点恢复原始大小
if (this.moveSelectedPoint) { if (this.moveSelectedPoint) {
this.moveSelectedPoint!.point!.pixelSize = new ConstantProperty( this.moveSelectedPoint!.point!.pixelSize = new ConstantProperty(
this.moveSelectedPoint!.options.pixelSize! - 1, this.moveSelectedPoint!.options.pixelSize! - 2,
) )
this.moveSelectedPoint = null this.moveSelectedPoint = null
this.viewer.scene.requestRender() //刷新 this.viewer.scene.requestRender() //刷新
} }
} }
if (!this.heightPoint || !this.bDrag) return if (!this.controlPoint || !this.bDrag) return
console.log('************************left down') console.log('************************left down')
const cartesian3 = cartesian2ToCartesian3(this.viewer, event.endPosition) const cartesian3 = cartesian2ToCartesian3(this.viewer, event.endPosition)
if (cartesian3) { if (cartesian3) {
// 修改节点坐标 // 修改节点坐标
this.modifyPoint(cartesian3, this.heightPoint.subId) this.modifyPoint(cartesian3, this.controlPoint.subId)
// this.geometry?.modifyPoint(cartesian3, this.controlPoint.subId) // this.geometry?.modifyPoint(cartesian3, this.controlPoint.subId)
this.viewer.scene.requestRender() //刷新 this.viewer.scene.requestRender() //刷新
} }
@ -251,10 +230,10 @@ export default class EditGeometry {
// 修改线坐标 // 修改线坐标
this.positions.splice(index, 1, pos) this.positions.splice(index, 1, pos)
// 修改控制点坐标 // 修改控制点坐标
this.heightPoint!.position = new ConstantPositionProperty(pos) this.controlPoint!.position = new ConstantPositionProperty(pos)
} }
/** /**
* *
* @param pos * @param pos
* @param index ,0 * @param index ,0
*/ */
@ -267,48 +246,4 @@ export default class EditGeometry {
this.controlPointsID.splice(index, 0, point.id) this.controlPointsID.splice(index, 0, point.id)
// } // }
} }
/**
*
* @param pos
* @param index ,0
*/
createGroundPoint(pos: Cartesian3, index: number) {
const point = new PointEntity(pos)
point.parent = this.geometry
point.subId = index
point.type = 1
this.geometry.entityCollection.add(point)
this.groundPointsID.splice(index, 0, point.id)
}
/**
* 线
* @param pos 线
* @param index ,0
*/
createGroundDashLine(positions: Cartesian3[], index: number) {
const vDashLine = new Entity({
polyline: {
positions: new CallbackProperty(() => {
return positions
}, false),
width: 2,
material: new PolylineDashMaterialProperty({
color: Color.WHITE,
dashLength: 12, //短划线长度
}),
},
})
this.groundDashLineID.splice(index, 0, vDashLine.id)
this.geometry.entityCollection.add(vDashLine)
}
//获取地表坐标
calculateGroundPosition(pos: Cartesian3) {
// 输入的当前点的笛卡尔坐标
const cartographic = Cartographic.fromCartesian(pos)
// 经度、纬度不变,将地面高度加上需要上升的距离, 假设垂直升高1000米
cartographic.height -= cartographic.height
// 最后使用Cesium.Cartographic.toCartesian将刚才得到的Cartographic对象转换为笛卡尔坐标
return Cartographic.toCartesian(cartographic)
}
} }

@ -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-22 11:32:00 * @LastEditTime: 2024-04-13 10:45:37
* @Description: * @Description:
*/ */
import { import {
@ -41,11 +41,7 @@ export abstract class BaseGeometry extends CustomDataSource {
* @param bAddControlPoint * @param bAddControlPoint
* @bAddControlPoint * @bAddControlPoint
*/ */
public addPoint( public addPoint(pos: Cartesian3, index: number = -1, bAddControlPoint: boolean = true,) {
pos: Cartesian3,
index: number = -1,
bAddControlPoint: boolean = true,
) {
if (index === -1) { if (index === -1) {
//插入尾部 //插入尾部
this.positions.push(pos) this.positions.push(pos)

@ -2,23 +2,15 @@
* @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-04-16 13:57:15 * @LastEditTime: 2024-04-13 11:15:48
* @Description: * @Description:
*/ */
import { import { Entity, Cartesian3, Color, PointGraphics, LabelGraphics } from 'cesium'
Entity,
Cartesian3,
Color,
PointGraphics,
LabelGraphics,
HeightReference,
} from 'cesium'
import { EntityOptions } from '@/types/entityoptions' import { EntityOptions } from '@/types/entityoptions'
// 点 // 点
class PointEntity extends Entity { class PointEntity extends Entity {
static ID: number = 0 static ID: number = 0
public subId: number = 0 //用于作为其他几何体的控制点时标记节点号 public subId: number = 0 //用于作为其他几何体的控制点时标记节点号
public type: number = 0 //用于判断是线上节点(0)还是地表控制点(1)
options: EntityOptions = { options: EntityOptions = {
id: 'Point' + String(PointEntity.ID), id: 'Point' + String(PointEntity.ID),
name: 'Point' + String(PointEntity.ID + 1), name: 'Point' + String(PointEntity.ID + 1),
@ -27,7 +19,6 @@ class PointEntity extends Entity {
color: Color.WHITE, color: Color.WHITE,
outlineColor: Color.GREEN, outlineColor: Color.GREEN,
outlineWidth: 0, outlineWidth: 0,
// heightReference: HeightReference.NONE,
} }
constructor(position: Cartesian3, options?: EntityOptions) { constructor(position: Cartesian3, options?: EntityOptions) {
super({ super({
@ -40,8 +31,6 @@ class PointEntity extends Entity {
color: this.options.color, color: this.options.color,
outlineColor: this.options.outlineColor, outlineColor: this.options.outlineColor,
outlineWidth: this.options.outlineWidth, outlineWidth: this.options.outlineWidth,
disableDepthTestDistance: 50000,
// heightReference: this.options.heightReference,
}) })
// 标注对象 // 标注对象
this.label = new LabelGraphics({ this.label = new LabelGraphics({

@ -2,16 +2,10 @@
* @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-16 11:12:08 * @LastEditTime: 2024-04-13 10:45:17
* @Description: Polyline * @Description: Polyline
*/ */
import { import { Entity, Cartesian3, Color, CallbackProperty } from 'cesium'
Entity,
Cartesian3,
Color,
CallbackProperty,
PolylineDashMaterialProperty,
} from 'cesium'
import { BaseGeometry } from './baseGeometry' import { BaseGeometry } from './baseGeometry'
import { EntityOptions } from '@/types/entityoptions' import { EntityOptions } from '@/types/entityoptions'
export class PolylineEntity extends BaseGeometry { export class PolylineEntity extends BaseGeometry {
@ -41,10 +35,6 @@ export class PolylineEntity extends BaseGeometry {
show: this.options.show, show: this.options.show,
width: this.options.width, width: this.options.width,
material: this.options.color, material: this.options.color,
// depthFailMaterial: new PolylineDashMaterialProperty({
// color: Color.GREEN,
// dashLength: 15, //短划线长度
// }),
}, },
}) })
this.entities.add(this.geometry) this.entities.add(this.geometry)

@ -1,20 +1,4 @@
/* import {Cartesian3, Entity, Color, Viewer, Cartesian2, HorizontalOrigin, VerticalOrigin, HeightReference} from "cesium";
* @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-04-16 18:59:56
* @LastEditors: cbwu
* @LastEditTime: 2024-04-22 09:11:33
* @Description:
*/
import {
Cartesian3,
Entity,
Color,
Viewer,
Cartesian2,
HorizontalOrigin,
VerticalOrigin,
HeightReference,
} from 'cesium'
/** /**
@ -22,64 +6,59 @@ import {
Zhaipeixiu Zhaipeixiu
*/ */
export type textLabelOptions = { export type textLabelOptions = {
showBackground?: boolean //显示背景 showBackground?: boolean, //显示背景
backgroundColor?: Color //背景色 backgroundColor?: Color, //背景色
backgroundPadding?: any //padding值 backgroundPadding?: any, //padding值
fillColor: Color fillColor: Color,
horizontalOrigin?: any //水平对齐方式 horizontalOrigin?: any, //水平对齐方式
verticalOrigin?: any //竖直对齐方式 verticalOrigin?: any, //竖直对齐方式
outlineColor?: any outlineColor?: any,
outlineWidth?: any outlineWidth?: any
} }
export class TextLabel { export class TextLabel{
_viewer: Viewer | undefined = undefined _viewer: Viewer|undefined = undefined
_defaultStyle: textLabelOptions = { _defaultStyle: textLabelOptions = {
showBackground: true, //显示背景 showBackground: true, //显示背景
backgroundColor: Color.BLACK, //背景色 backgroundColor: Color.BLACK, //背景色
backgroundPadding: new Cartesian2(10, 10), //padding值 backgroundPadding: new Cartesian2(10, 10), //padding值
fillColor: Color.WHITE, fillColor: Color.WHITE,
outlineColor: Color.WHITESMOKE, outlineColor: Color.WHITESMOKE,
outlineWidth: 1.0, outlineWidth: 1.0,
horizontalOrigin: HorizontalOrigin.CENTER, //对齐方式 horizontalOrigin: HorizontalOrigin.CENTER,//对齐方式
verticalOrigin: VerticalOrigin.CENTER, verticalOrigin: VerticalOrigin.CENTER,
} }
_cesiumLabel: Entity | undefined = undefined _cesiumLabel: Entity|undefined = undefined
// 构造函数新建label并显示 // 构造函数新建label并显示
constructor( constructor(viewer: Viewer, position: Cartesian3, text: string, options?: textLabelOptions) {
viewer: Viewer, this._viewer = viewer
position: Cartesian3, this._defaultStyle = {...this._defaultStyle, ...options}
text: string,
options?: textLabelOptions,
) {
this._viewer = viewer
this._defaultStyle = { ...this._defaultStyle, ...options }
this._cesiumLabel = new Entity({ this._cesiumLabel = new Entity({
position: position, position: position,
name: 'default', name: 'default',
label: { label: {
text: text, text: text,
scale: 0.6, scale: .6,
pixelOffset: new Cartesian2(20, -20), pixelOffset: new Cartesian2(20, -20),
showBackground: this._defaultStyle.showBackground, //显示背景 showBackground: this._defaultStyle.showBackground, //显示背景
backgroundColor: this._defaultStyle.backgroundColor, //背景色 backgroundColor: this._defaultStyle.backgroundColor, //背景色
backgroundPadding: this._defaultStyle.backgroundPadding, //padding值 backgroundPadding: this._defaultStyle.backgroundPadding, //padding值
fillColor: this._defaultStyle.fillColor, fillColor: this._defaultStyle.fillColor,
outlineColor: this._defaultStyle.outlineColor, outlineColor: this._defaultStyle.outlineColor,
outlineWidth: this._defaultStyle.outlineWidth, outlineWidth: this._defaultStyle.outlineWidth,
horizontalOrigin: this._defaultStyle.horizontalOrigin, //对齐方式 horizontalOrigin: this._defaultStyle.horizontalOrigin, //对齐方式
verticalOrigin: this._defaultStyle.verticalOrigin, verticalOrigin: this._defaultStyle.verticalOrigin,
heightReference: HeightReference.CLAMP_TO_GROUND, heightReference: HeightReference.CLAMP_TO_GROUND
}, }
}) })
this._viewer.entities.add(this._cesiumLabel) this._viewer.entities.add(this._cesiumLabel)
} }
//移除label //移除label
public remove() { public remove(){
if (this._cesiumLabel !== undefined && this._viewer !== null) if(this._cesiumLabel !== undefined && this._viewer!==null)
this._viewer.entities.remove(this._cesiumLabel) this._viewer.entities.remove(this._cesiumLabel)
} }
} }

@ -2,7 +2,7 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com * @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-13 09:32:21 * @Date: 2024-03-13 09:32:21
* @LastEditors: cbwu * @LastEditors: cbwu
* @LastEditTime: 2024-04-16 10:58:25 * @LastEditTime: 2024-04-13 10:49:06
* @Description: * @Description:
*/ */
// Viewer初始化 // Viewer初始化
@ -53,7 +53,7 @@ function initViewer(container: string | Element): Viewer {
const creditContainer = viewer.cesiumWidget.creditContainer as HTMLDivElement const creditContainer = viewer.cesiumWidget.creditContainer as HTMLDivElement
creditContainer.style.display = 'none' creditContainer.style.display = 'none'
// 开启深度检测 // 开启深度检测
viewer.scene.globe.depthTestAgainstTerrain = true viewer.scene.globe.depthTestAgainstTerrain = false
// 水雾特效 // 水雾特效
viewer.scene.globe.showGroundAtmosphere = true viewer.scene.globe.showGroundAtmosphere = true
// 设置更高的缩放惯性以使缩放操作更平滑 // 设置更高的缩放惯性以使缩放操作更平滑

Loading…
Cancel
Save