|
|
@ -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-24 16:52:23
|
|
|
|
* @Description: 编辑几何体类。操作逻辑
|
|
|
|
* @Description: 编辑几何体类。操作逻辑
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
import {
|
|
|
@ -20,10 +20,17 @@ import {
|
|
|
|
PolylineDashMaterialProperty,
|
|
|
|
PolylineDashMaterialProperty,
|
|
|
|
Color,
|
|
|
|
Color,
|
|
|
|
Cartographic,
|
|
|
|
Cartographic,
|
|
|
|
|
|
|
|
Cartesian2,
|
|
|
|
|
|
|
|
Ellipsoid,
|
|
|
|
} 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,
|
|
|
|
|
|
|
|
getElevation,
|
|
|
|
|
|
|
|
} from '@/utils/map/geocomputation'
|
|
|
|
import { PointEntity } from '@/utils/map/geometry/pointEntity'
|
|
|
|
import { PointEntity } from '@/utils/map/geometry/pointEntity'
|
|
|
|
|
|
|
|
import { setMouseStyle, MouseType } from '@/utils/map/mouseStyle'
|
|
|
|
export default class EditGeometry {
|
|
|
|
export default class EditGeometry {
|
|
|
|
viewer: Viewer
|
|
|
|
viewer: Viewer
|
|
|
|
editHandler: ScreenSpaceEventHandler
|
|
|
|
editHandler: ScreenSpaceEventHandler
|
|
|
@ -34,14 +41,21 @@ export default class EditGeometry {
|
|
|
|
groundPointsID: string[] = [] //地表控制点ID数组
|
|
|
|
groundPointsID: string[] = [] //地表控制点ID数组
|
|
|
|
groundDashLineID: string[] = [] //垂直辅助线ID数组
|
|
|
|
groundDashLineID: string[] = [] //垂直辅助线ID数组
|
|
|
|
groundDashLinesPosition: Cartesian3[][] = [] //垂直辅助线坐标数组
|
|
|
|
groundDashLinesPosition: Cartesian3[][] = [] //垂直辅助线坐标数组
|
|
|
|
heightPoint: PointEntity | null = null //高度控制点
|
|
|
|
controlPoint: PointEntity | null = null //控制点
|
|
|
|
groundPoint: PointEntity | null = null //地表控制点
|
|
|
|
// groundPoint: PointEntity | null = null //地表控制点
|
|
|
|
clickedGeometry: Entity | null = null
|
|
|
|
clickedGeometry: Entity | null = null
|
|
|
|
clickDownPosition: Cartesian3 | null = null
|
|
|
|
clickDownPosition: Cartesian3 | null = null
|
|
|
|
|
|
|
|
clickScreenPosition: Cartesian2 | null = null
|
|
|
|
|
|
|
|
startHeightPointPosition: Cartesian3 | null = null //记录高度时的初始坐标值
|
|
|
|
|
|
|
|
firstClickScreenPosition: Cartesian2 | null = null //记录第一次单击的位置
|
|
|
|
|
|
|
|
heightScale: number = 1 //高度调节比例
|
|
|
|
moveSelectedPoint: PointEntity | null = null
|
|
|
|
moveSelectedPoint: PointEntity | null = null
|
|
|
|
bDrag: boolean = false //拖动标识
|
|
|
|
bDrag: boolean = false //拖动标识
|
|
|
|
bLongClick: boolean = false //长按标识
|
|
|
|
bLongClick: boolean = false //长按标识
|
|
|
|
|
|
|
|
bDoubleClick: boolean = false //双击标识
|
|
|
|
|
|
|
|
nClick: number = 0 //单击次数
|
|
|
|
clickTimeout: any
|
|
|
|
clickTimeout: any
|
|
|
|
|
|
|
|
doubleClickTimeout: any
|
|
|
|
|
|
|
|
|
|
|
|
constructor(viewer: Viewer, editGeometry: Entity) {
|
|
|
|
constructor(viewer: Viewer, editGeometry: Entity) {
|
|
|
|
this.viewer = viewer
|
|
|
|
this.viewer = viewer
|
|
|
@ -55,8 +69,8 @@ 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)
|
|
|
|
const groundPosition = this.modifyPositionZ(value)
|
|
|
|
this.createGroundPoint(value, index)
|
|
|
|
this.createGroundPoint(groundPosition, index)
|
|
|
|
//垂直辅助线
|
|
|
|
//垂直辅助线
|
|
|
|
const ptArr = [value, groundPosition]
|
|
|
|
const ptArr = [value, groundPosition]
|
|
|
|
this.groundDashLinesPosition[index] = ptArr
|
|
|
|
this.groundDashLinesPosition[index] = ptArr
|
|
|
@ -76,25 +90,12 @@ export default class EditGeometry {
|
|
|
|
this.leftUpClickCallBack,
|
|
|
|
this.leftUpClickCallBack,
|
|
|
|
ScreenSpaceEventType.LEFT_UP,
|
|
|
|
ScreenSpaceEventType.LEFT_UP,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
this.editHandler.setInputAction(
|
|
|
|
|
|
|
|
this.leftDoubleClickCallBack,
|
|
|
|
|
|
|
|
ScreenSpaceEventType.LEFT_DOUBLE_CLICK,
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//左键点击回调
|
|
|
|
|
|
|
|
private leftClickCallBack = (
|
|
|
|
|
|
|
|
event: ScreenSpaceEventHandler.PositionedEvent,
|
|
|
|
|
|
|
|
) => {
|
|
|
|
|
|
|
|
const pickedObject = this.viewer.scene.pick(event.position)
|
|
|
|
|
|
|
|
// 点中控制点
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
defined(pickedObject) &&
|
|
|
|
|
|
|
|
defined(pickedObject.id) &&
|
|
|
|
|
|
|
|
pickedObject.id.point instanceof PointGraphics
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
console.log('You clicked a point entity.')
|
|
|
|
|
|
|
|
this.controlPoint = pickedObject.id
|
|
|
|
|
|
|
|
console.log(this.controlPoint?.subId)
|
|
|
|
|
|
|
|
this.bDrag = true
|
|
|
|
|
|
|
|
this.forbidDrawWorld(true)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//左键按下回调
|
|
|
|
//左键按下回调
|
|
|
|
private leftDownClickCallBack = (
|
|
|
|
private leftDownClickCallBack = (
|
|
|
|
event: ScreenSpaceEventHandler.PositionedEvent,
|
|
|
|
event: ScreenSpaceEventHandler.PositionedEvent,
|
|
|
@ -111,29 +112,25 @@ export default class EditGeometry {
|
|
|
|
// 记录点击的几何对象及位置
|
|
|
|
// 记录点击的几何对象及位置
|
|
|
|
this.clickedGeometry = pickedObject.id
|
|
|
|
this.clickedGeometry = pickedObject.id
|
|
|
|
this.clickDownPosition = this.viewer.scene.pickPosition(event.position)
|
|
|
|
this.clickDownPosition = this.viewer.scene.pickPosition(event.position)
|
|
|
|
// // 判断是否同一实体
|
|
|
|
this.clickScreenPosition = event.position
|
|
|
|
// if (this.geometry != pickedObject.id) {
|
|
|
|
|
|
|
|
// this.geometry = pickedObject.id
|
|
|
|
|
|
|
|
// if (
|
|
|
|
|
|
|
|
// pickedObject instanceof PolylineGraphics &&
|
|
|
|
|
|
|
|
// pickedObject.positions
|
|
|
|
|
|
|
|
// ) {
|
|
|
|
|
|
|
|
// this.oldPositions = this.geometry!.polyline!.positions?.getValue(
|
|
|
|
|
|
|
|
// this.viewer.clock.currentTime,
|
|
|
|
|
|
|
|
// )
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// 点中控制点
|
|
|
|
// 点中控制点
|
|
|
|
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.')
|
|
|
|
//记录初始坐标,用于高度调节
|
|
|
|
this.heightPoint = pickedObject.id
|
|
|
|
this.startHeightPointPosition =
|
|
|
|
} else if (pickedObject.id.point.type === 1) {
|
|
|
|
this.positions[pickedObject.id.subId].clone()
|
|
|
|
console.log('You clicked a GroundPoint entity.')
|
|
|
|
//计算高度缩放比例
|
|
|
|
this.groundPoint = pickedObject.id
|
|
|
|
this.heightScale = this.getHeightPerPixel(this.startHeightPointPosition)
|
|
|
|
}
|
|
|
|
// console.log(this.controlPoint)
|
|
|
|
// console.log(this.heightPoint?.subId)
|
|
|
|
// if (pickedObject.id.type === 0) {
|
|
|
|
|
|
|
|
// console.log('You clicked a HeightPoint entity.')
|
|
|
|
|
|
|
|
// // this.controlPoint = pickedObject.id
|
|
|
|
|
|
|
|
// } else if (pickedObject.id.type === 1) {
|
|
|
|
|
|
|
|
// console.log('You clicked a GroundPoint entity.')
|
|
|
|
|
|
|
|
// // this.groundPoint = pickedObject.id
|
|
|
|
|
|
|
|
// }
|
|
|
|
this.bDrag = true
|
|
|
|
this.bDrag = true
|
|
|
|
this.forbidDrawWorld(true)
|
|
|
|
this.forbidDrawWorld(true)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -142,43 +139,29 @@ export default class EditGeometry {
|
|
|
|
//移动回调
|
|
|
|
//移动回调
|
|
|
|
private moveCallBack = (event: ScreenSpaceEventHandler.MotionEvent) => {
|
|
|
|
private moveCallBack = (event: ScreenSpaceEventHandler.MotionEvent) => {
|
|
|
|
const pickedObject = this.viewer.scene.pick(event.endPosition)
|
|
|
|
const pickedObject = this.viewer.scene.pick(event.endPosition)
|
|
|
|
// 悬停控制点放大
|
|
|
|
// 出发不同编辑内容修改鼠标形状
|
|
|
|
if (
|
|
|
|
this.changeSelectedStyle(pickedObject)
|
|
|
|
pickedObject &&
|
|
|
|
|
|
|
|
pickedObject.id &&
|
|
|
|
|
|
|
|
pickedObject.id.point instanceof PointGraphics
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
if (pickedObject.id.point instanceof PointGraphics) {
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
this.moveSelectedPoint == null ||
|
|
|
|
|
|
|
|
this.moveSelectedPoint.id !== pickedObject.id.id
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
this.moveSelectedPoint = pickedObject.id
|
|
|
|
|
|
|
|
this.moveSelectedPoint!.point!.pixelSize = new ConstantProperty(
|
|
|
|
|
|
|
|
this.moveSelectedPoint!.options.pixelSize! + 1,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
// console.log(this.moveSelectedPoint)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.viewer.scene.requestRender() //刷新
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 离开控制点恢复原始大小
|
|
|
|
|
|
|
|
if (this.moveSelectedPoint) {
|
|
|
|
|
|
|
|
this.moveSelectedPoint!.point!.pixelSize = new ConstantProperty(
|
|
|
|
|
|
|
|
this.moveSelectedPoint!.options.pixelSize! - 1,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
this.moveSelectedPoint = null
|
|
|
|
|
|
|
|
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)
|
|
|
|
if (this.controlPoint.type === 1) {
|
|
|
|
// this.geometry?.modifyPoint(cartesian3, this.controlPoint.subId)
|
|
|
|
// 修改节点xy坐标
|
|
|
|
|
|
|
|
this.modifyPoint(cartesian3, this.controlPoint.subId)
|
|
|
|
|
|
|
|
} else if (this.controlPoint.type === 0) {
|
|
|
|
|
|
|
|
//计算屏幕y坐标偏移量
|
|
|
|
|
|
|
|
const altValue = this.clickScreenPosition!.y - event.endPosition.y
|
|
|
|
|
|
|
|
// console.log('************moveYValue:' + altValue.toString())
|
|
|
|
|
|
|
|
//调节高度
|
|
|
|
|
|
|
|
this.modifyAltitude(
|
|
|
|
|
|
|
|
this.startHeightPointPosition!,
|
|
|
|
|
|
|
|
altValue * this.heightScale,
|
|
|
|
|
|
|
|
this.controlPoint.subId,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.viewer.scene.requestRender() //刷新
|
|
|
|
this.viewer.scene.requestRender() //刷新
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -187,12 +170,26 @@ export default class EditGeometry {
|
|
|
|
event: ScreenSpaceEventHandler.PositionedEvent,
|
|
|
|
event: ScreenSpaceEventHandler.PositionedEvent,
|
|
|
|
) => {
|
|
|
|
) => {
|
|
|
|
clearTimeout(this.clickTimeout)
|
|
|
|
clearTimeout(this.clickTimeout)
|
|
|
|
|
|
|
|
// 单击控制点结束
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
!this.bLongClick &&
|
|
|
|
|
|
|
|
this.clickedGeometry?.point instanceof PointGraphics
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
if (this.nClick === 0) this.firstClickScreenPosition = event.position
|
|
|
|
|
|
|
|
//记录单击次数
|
|
|
|
|
|
|
|
this.nClick++
|
|
|
|
|
|
|
|
//200ms内没有再次单击,次数清0
|
|
|
|
|
|
|
|
this.doubleClickTimeout = setTimeout(() => {
|
|
|
|
|
|
|
|
this.nClick = 0
|
|
|
|
|
|
|
|
}, 200)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 单击添加点
|
|
|
|
// 单击添加点
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
!this.bLongClick &&
|
|
|
|
!this.bLongClick &&
|
|
|
|
this.clickedGeometry?.polyline instanceof PolylineGraphics
|
|
|
|
this.clickedGeometry?.polyline instanceof PolylineGraphics
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
console.log('点中线,加点')
|
|
|
|
// console.log('点中线,加点')
|
|
|
|
this.addPoint()
|
|
|
|
this.addPoint()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.bLongClick = false
|
|
|
|
this.bLongClick = false
|
|
|
@ -203,7 +200,17 @@ export default class EditGeometry {
|
|
|
|
private leftDoubleClickCallBack = (
|
|
|
|
private leftDoubleClickCallBack = (
|
|
|
|
event: ScreenSpaceEventHandler.PositionedEvent,
|
|
|
|
event: ScreenSpaceEventHandler.PositionedEvent,
|
|
|
|
) => {
|
|
|
|
) => {
|
|
|
|
// this.geometry.
|
|
|
|
// console.log('***********Double Clicked!')
|
|
|
|
|
|
|
|
//双击移除点
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
this.nClick === 2 &&
|
|
|
|
|
|
|
|
Cartesian2.distance(this.firstClickScreenPosition!, event.position) <= 3
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
// console.log('***********双击移除点!')
|
|
|
|
|
|
|
|
//移除点
|
|
|
|
|
|
|
|
this.removePoint(this.controlPoint!.subId)
|
|
|
|
|
|
|
|
this.viewer.scene.requestRender() //刷新
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Viewer操作控制
|
|
|
|
// Viewer操作控制
|
|
|
|
forbidDrawWorld(isForbid: boolean) {
|
|
|
|
forbidDrawWorld(isForbid: boolean) {
|
|
|
@ -229,37 +236,120 @@ export default class EditGeometry {
|
|
|
|
this.clickDownPosition!,
|
|
|
|
this.clickDownPosition!,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
this.positions.splice(i + 1, 0, pt)
|
|
|
|
this.positions.splice(i + 1, 0, pt)
|
|
|
|
// 新建控制点
|
|
|
|
// 新建节点控制点
|
|
|
|
this.createPoint(pt, i + 1)
|
|
|
|
this.createPoint(pt, i + 1)
|
|
|
|
// 修改控制点的subid
|
|
|
|
// 新建地表控制点
|
|
|
|
|
|
|
|
const groundPos = this.modifyPositionZ(pt) //计算地表点坐标
|
|
|
|
|
|
|
|
this.createGroundPoint(groundPos, i + 1)
|
|
|
|
|
|
|
|
// 修改控制点的subid(往后移)
|
|
|
|
for (let index = i + 2; index < this.controlPointsID.length; ++index) {
|
|
|
|
for (let index = i + 2; index < this.controlPointsID.length; ++index) {
|
|
|
|
|
|
|
|
//节点控制点
|
|
|
|
const point = this.geometry.entityCollection.getById(
|
|
|
|
const point = this.geometry.entityCollection.getById(
|
|
|
|
this.controlPointsID[index],
|
|
|
|
this.controlPointsID[index],
|
|
|
|
) as PointEntity
|
|
|
|
) as PointEntity
|
|
|
|
point!.subId = point!.subId + 1
|
|
|
|
point!.subId = point!.subId + 1
|
|
|
|
|
|
|
|
//地表控制点
|
|
|
|
|
|
|
|
const groundPoint = this.geometry.entityCollection.getById(
|
|
|
|
|
|
|
|
this.groundPointsID[index],
|
|
|
|
|
|
|
|
) as PointEntity
|
|
|
|
|
|
|
|
groundPoint!.subId = groundPoint!.subId + 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 新建垂直辅助线
|
|
|
|
|
|
|
|
const ptArr = [pt, groundPos]
|
|
|
|
|
|
|
|
this.groundDashLinesPosition.splice(i + 1, 0, ptArr)
|
|
|
|
|
|
|
|
this.createGroundDashLine(this.groundDashLinesPosition[i + 1], i + 1)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 删除一个节点
|
|
|
|
|
|
|
|
* @param index 移除点号
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
removePoint(index: number) {
|
|
|
|
|
|
|
|
this.positions.splice(index, 1)
|
|
|
|
|
|
|
|
//移除辅助实体
|
|
|
|
|
|
|
|
this.geometry.entityCollection.removeById(this.controlPointsID[index])
|
|
|
|
|
|
|
|
this.geometry.entityCollection.removeById(this.groundPointsID[index])
|
|
|
|
|
|
|
|
this.geometry.entityCollection.removeById(this.groundDashLineID[index])
|
|
|
|
|
|
|
|
//删除实体ID记录
|
|
|
|
|
|
|
|
this.controlPointsID.splice(index, 1)
|
|
|
|
|
|
|
|
this.groundPointsID.splice(index, 1)
|
|
|
|
|
|
|
|
this.groundDashLineID.splice(index, 1)
|
|
|
|
|
|
|
|
this.groundDashLinesPosition.splice(index, 1)
|
|
|
|
|
|
|
|
//修改控制点号
|
|
|
|
|
|
|
|
for (let i = index; i < this.controlPointsID.length; ++i) {
|
|
|
|
|
|
|
|
//节点控制点
|
|
|
|
|
|
|
|
const point = this.geometry.entityCollection.getById(
|
|
|
|
|
|
|
|
this.controlPointsID[i],
|
|
|
|
|
|
|
|
) as PointEntity
|
|
|
|
|
|
|
|
point!.subId = point!.subId - 1
|
|
|
|
|
|
|
|
//地表控制点
|
|
|
|
|
|
|
|
const groundPoint = this.geometry.entityCollection.getById(
|
|
|
|
|
|
|
|
this.groundPointsID[i],
|
|
|
|
|
|
|
|
) as PointEntity
|
|
|
|
|
|
|
|
groundPoint!.subId = groundPoint!.subId - 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 修改某点的坐标
|
|
|
|
* 修改某点的坐标
|
|
|
|
* @param pos 修改点的坐标
|
|
|
|
* @param pos 修改点的坐标
|
|
|
|
* @param index 修改点的位置
|
|
|
|
* @param index 修改点的位置
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
modifyPoint(pos: Cartesian3, index: number) {
|
|
|
|
modifyPoint(pos: Cartesian3, index: number) {
|
|
|
|
|
|
|
|
//计算新坐标
|
|
|
|
|
|
|
|
const newHeightPos = this.calculateHeightPosition(
|
|
|
|
|
|
|
|
this.positions[index],
|
|
|
|
|
|
|
|
pos,
|
|
|
|
|
|
|
|
)
|
|
|
|
// 修改线坐标
|
|
|
|
// 修改线坐标
|
|
|
|
this.positions.splice(index, 1, pos)
|
|
|
|
this.positions.splice(index, 1, newHeightPos)
|
|
|
|
// 修改控制点坐标
|
|
|
|
// 修改高度控制点坐标
|
|
|
|
this.heightPoint!.position = new ConstantPositionProperty(pos)
|
|
|
|
const heightPt = this.geometry.entityCollection.getById(
|
|
|
|
|
|
|
|
this.controlPointsID[index],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
heightPt!.position = new ConstantPositionProperty(newHeightPos)
|
|
|
|
|
|
|
|
// 修改地表控制点坐标
|
|
|
|
|
|
|
|
const groundPt = this.geometry.entityCollection.getById(
|
|
|
|
|
|
|
|
this.groundPointsID[index],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
groundPt!.position = new ConstantPositionProperty(pos)
|
|
|
|
|
|
|
|
//修改垂直辅助线坐标
|
|
|
|
|
|
|
|
this.groundDashLinesPosition[index][0] = newHeightPos
|
|
|
|
|
|
|
|
this.groundDashLinesPosition[index][1] = pos
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 新加一个节点
|
|
|
|
* 调节航点高度
|
|
|
|
|
|
|
|
* @param oldPosition 修改前的笛卡尔坐标
|
|
|
|
|
|
|
|
* @param increaseAltitude 高度增量
|
|
|
|
|
|
|
|
* @param index 要修改的点号
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
modifyAltitude(
|
|
|
|
|
|
|
|
oldPosition: Cartesian3,
|
|
|
|
|
|
|
|
increaseAltitude: number,
|
|
|
|
|
|
|
|
index: number,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
const heightPos = this.modifyPositionZ(oldPosition, increaseAltitude)
|
|
|
|
|
|
|
|
this.positions.splice(index, 1, heightPos)
|
|
|
|
|
|
|
|
this.groundDashLinesPosition[index][0] = heightPos
|
|
|
|
|
|
|
|
const heightPt = this.geometry.entityCollection.getById(
|
|
|
|
|
|
|
|
this.controlPointsID[index],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
heightPt!.position = new ConstantPositionProperty(heightPos)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 创建一个节点
|
|
|
|
* @param pos 点的坐标
|
|
|
|
* @param pos 点的坐标
|
|
|
|
* @param index 插入的位置,0起步
|
|
|
|
* @param index 插入的位置,0起步
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
createPoint(pos: Cartesian3, index: number) {
|
|
|
|
createPoint(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
|
|
|
|
point.subId = index
|
|
|
|
point.subId = index
|
|
|
@ -267,8 +357,9 @@ export default class EditGeometry {
|
|
|
|
this.controlPointsID.splice(index, 0, point.id)
|
|
|
|
this.controlPointsID.splice(index, 0, point.id)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 新加一个地表控制点
|
|
|
|
* 创建一个地表控制点
|
|
|
|
* @param pos 点的坐标
|
|
|
|
* @param pos 点的坐标
|
|
|
|
* @param index 插入的位置,0起步
|
|
|
|
* @param index 插入的位置,0起步
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -301,14 +392,99 @@ export default class EditGeometry {
|
|
|
|
this.groundDashLineID.splice(index, 0, vDashLine.id)
|
|
|
|
this.groundDashLineID.splice(index, 0, vDashLine.id)
|
|
|
|
this.geometry.entityCollection.add(vDashLine)
|
|
|
|
this.geometry.entityCollection.add(vDashLine)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//获取地表坐标
|
|
|
|
/**
|
|
|
|
calculateGroundPosition(pos: Cartesian3) {
|
|
|
|
* 获取更改高度值的坐标
|
|
|
|
|
|
|
|
* @param pos 要修改高度的笛卡尔坐标
|
|
|
|
|
|
|
|
* @param increaseAltitude 可选高度增量值,未选择则默认地表
|
|
|
|
|
|
|
|
* @returns 修改后的坐标
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
modifyPositionZ(pos: Cartesian3, increaseAltitude?: number) {
|
|
|
|
// 输入的当前点的笛卡尔坐标
|
|
|
|
// 输入的当前点的笛卡尔坐标
|
|
|
|
const cartographic = Cartographic.fromCartesian(pos)
|
|
|
|
const cartographic = Cartographic.fromCartesian(pos)
|
|
|
|
// 经度、纬度不变,将地面高度加上需要上升的距离, 假设垂直升高1000米
|
|
|
|
// 经度、纬度不变,将地面高度加上需要上升的距离
|
|
|
|
cartographic.height -= cartographic.height
|
|
|
|
if (increaseAltitude != undefined) {
|
|
|
|
|
|
|
|
cartographic.height += increaseAltitude
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const height = getElevation(this.viewer, pos)
|
|
|
|
|
|
|
|
cartographic.height = height
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 最后使用Cesium.Cartographic.toCartesian将刚才得到的Cartographic对象转换为笛卡尔坐标
|
|
|
|
// 最后使用Cesium.Cartographic.toCartesian将刚才得到的Cartographic对象转换为笛卡尔坐标
|
|
|
|
return Cartographic.toCartesian(cartographic)
|
|
|
|
return Cartographic.toCartesian(cartographic)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取移动后的高度坐标
|
|
|
|
|
|
|
|
* @param heightPos 要修改xy的笛卡尔坐标
|
|
|
|
|
|
|
|
* @param groundPos 目标位置的笛卡尔坐标
|
|
|
|
|
|
|
|
* @returns 修改xy位置的新坐标
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
calculateHeightPosition(heightPos: Cartesian3, groundPos: Cartesian3) {
|
|
|
|
|
|
|
|
const groundCartographic = Cartographic.fromCartesian(groundPos)
|
|
|
|
|
|
|
|
const heightCartographic = Cartographic.fromCartesian(heightPos)
|
|
|
|
|
|
|
|
return Cartesian3.fromRadians(
|
|
|
|
|
|
|
|
groundCartographic.longitude,
|
|
|
|
|
|
|
|
groundCartographic.latitude,
|
|
|
|
|
|
|
|
heightCartographic.height,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 修改高度
|
|
|
|
|
|
|
|
* @param heightPos 要修改高度的坐标
|
|
|
|
|
|
|
|
* @param addAltValue 高度增量值
|
|
|
|
|
|
|
|
* @returns 返回修改高度后的坐标
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
calculateHeightPositionZ(heightPos: Cartesian3, addAltValue: number) {
|
|
|
|
|
|
|
|
const heightCartographic = Cartographic.fromCartesian(heightPos)
|
|
|
|
|
|
|
|
heightCartographic.height += addAltValue
|
|
|
|
|
|
|
|
return Cartographic.toCartesian(heightCartographic)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 计算一像素对应的高度(有待优化)
|
|
|
|
|
|
|
|
getHeightPerPixel(pos: Cartesian3) {
|
|
|
|
|
|
|
|
const screenPos0 = this.viewer.scene.cartesianToCanvasCoordinates(pos)
|
|
|
|
|
|
|
|
const screenPos1 = this.viewer.scene.cartesianToCanvasCoordinates(
|
|
|
|
|
|
|
|
this.modifyPositionZ(pos, 1),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
const heightDifference = 1 / Math.abs(screenPos0.y - screenPos1.y)
|
|
|
|
|
|
|
|
// console.log('*****像素高度:' + heightDifference.toString())
|
|
|
|
|
|
|
|
return heightDifference
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置移动靠近编辑实体对象的样式变化
|
|
|
|
|
|
|
|
changeSelectedStyle(pickedObject: any) {
|
|
|
|
|
|
|
|
// console.log(pickedObject)
|
|
|
|
|
|
|
|
if (pickedObject && pickedObject.id) {
|
|
|
|
|
|
|
|
if (pickedObject.id.point instanceof PointGraphics) {
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
this.moveSelectedPoint == null ||
|
|
|
|
|
|
|
|
this.moveSelectedPoint.id !== pickedObject.id.id
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
this.moveSelectedPoint = pickedObject.id as PointEntity
|
|
|
|
|
|
|
|
this.moveSelectedPoint!.point!.pixelSize = new ConstantProperty(
|
|
|
|
|
|
|
|
this.moveSelectedPoint!.options.pixelSize! + 1,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
// console.log('**************Selected Point')
|
|
|
|
|
|
|
|
//设置鼠标形状
|
|
|
|
|
|
|
|
if (this.moveSelectedPoint.type === 0) {
|
|
|
|
|
|
|
|
setMouseStyle(this.viewer, MouseType.NSMove)
|
|
|
|
|
|
|
|
} else if (this.moveSelectedPoint.type === 1) {
|
|
|
|
|
|
|
|
setMouseStyle(this.viewer, MouseType.Move)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (pickedObject.id.polyline instanceof PolylineGraphics) {
|
|
|
|
|
|
|
|
setMouseStyle(this.viewer, MouseType.AddPoint)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.viewer.scene.requestRender() //刷新
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 离开控制点恢复原始大小
|
|
|
|
|
|
|
|
if (this.moveSelectedPoint) {
|
|
|
|
|
|
|
|
this.moveSelectedPoint.point!.pixelSize = new ConstantProperty(
|
|
|
|
|
|
|
|
this.moveSelectedPoint!.options.pixelSize! - 1,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
//设置鼠标形状
|
|
|
|
|
|
|
|
setMouseStyle(this.viewer, MouseType.Default)
|
|
|
|
|
|
|
|
this.moveSelectedPoint = null
|
|
|
|
|
|
|
|
this.viewer.scene.requestRender() //刷新
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|