Merge pull request 'dev-cbwu' (#6) from dev-cbwu into dev

Reviewed-on: #6
pull/8/head
WuChengbo 1 year ago
commit 6221bca0c0

@ -1,3 +1,10 @@
/*
* @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-04-13 10:03:23
* @LastEditors: cbwu
* @LastEditTime: 2024-04-13 11:07:45
* @Description:
*/
module.exports = {
env: {
browser: true,
@ -63,5 +70,6 @@ module.exports = {
semi: false,
},
],
'linebreak-style': [0, 'error', 'windows'], //取消对LF和CRLF的检查
},
}

@ -3,7 +3,7 @@
"semi": false,
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "ignore",
"endOfLine": "auto",
"endOfLine": "lf",
"trailingComma": "all",
"tabWidth": 2
}

@ -5,36 +5,40 @@
-->
<script setup lang="ts">
import { Angle } from '@/utils/map/angle.ts'
import {ScreenSpaceEventHandler, Math, ScreenSpaceEventType} from 'cesium'
import {onMounted, ref} from "vue";
import {cartesian2ToCartesian3} from "@/utils/map/coordinate.ts";
import { ScreenSpaceEventHandler, Math, ScreenSpaceEventType } from 'cesium'
import { onMounted, ref } from 'vue'
import { cartesian2ToCartesian3 } from '@/utils/map/coordinate.ts'
let nowLatStr: string, nowLonStr: string
let lonlatStr = ref('')
let isDecimal = ref(true)
onMounted(()=>{
onMounted(() => {
let _viewer = window.viewer
let canvas = _viewer.scene.canvas
let canvas = _viewer.scene.canvas
let handler = new ScreenSpaceEventHandler(canvas)
handler.setInputAction((e:any)=> {
handler.setInputAction((e: any) => {
//
let position = cartesian2ToCartesian3(_viewer, e.endPosition)
if (position) {
//
let cartographic = _viewer.scene.globe.ellipsoid.cartesianToCartographic(position);
try{
let cartographic =
_viewer.scene.globe.ellipsoid.cartesianToCartographic(position)
try {
//
nowLatStr = Math.toDegrees(cartographic.latitude).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
let needElevation: boolean = camera_alt < 250 && (_viewer.camera.pitch < -(Math.PI/180)*80)
let elevStr = needElevation? _viewer.scene.globe.getHeight(cartographic)?.toFixed(2)+'m'?? '' : '高度过高'
let needElevation: boolean =
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}`
}
else {
} else {
lonlatStr.value = `经度: ${Angle.DecimalDegree2DMS(nowLonStr)}, 纬度: ${Angle.DecimalDegree2DMS(nowLatStr)},
高度: ${elevStr}`
}
@ -46,10 +50,11 @@ onMounted(()=>{
function lonlatClick() {
let elevStr = lonlatStr.value.split('高度')[1]
console.log(elevStr)
if(isDecimal.value){
lonlatStr.value = `经度: ${Angle.DecimalDegree2DMS(nowLonStr)}, 纬度: ${Angle.DecimalDegree2DMS(nowLatStr)}, 高度` + elevStr
}
else {
if (isDecimal.value) {
lonlatStr.value =
`经度: ${Angle.DecimalDegree2DMS(nowLonStr)}, 纬度: ${Angle.DecimalDegree2DMS(nowLatStr)}, 高度` +
elevStr
} else {
lonlatStr.value = `经度: ${nowLonStr}°, 纬度: ${nowLatStr}°, 高度` + elevStr
}
isDecimal.value = !isDecimal.value
@ -81,13 +86,13 @@ function lonlatClick() {
align-items: center;
justify-content: center;
}
#lonlatText{
#lonlatText {
background: none;
border: none;
color: #ffffff;
font-size: 0.8rem;
}
#lonlatText:hover{
#lonlatText:hover {
cursor: pointer;
}
</style>

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

@ -0,0 +1,26 @@
/*
* @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-04-13 10:36:06
* @LastEditors: cbwu
* @LastEditTime: 2024-04-13 11:14:53
* @Description:
*/
import { Color, Cartesian2 } from 'cesium'
export interface EntityOptions {
id?: string
name?: string
show?: boolean
pixelSize?: number //点大小
outlineColor?: Color //轮廓线颜色
color?: Color //点颜色
fillColor?: Color //填充颜色
fill?: boolean //是否填充
width?: number //线宽
outlineWidth?: number
text?: string //标注内容
font?: string //字体
pixelOffset?: Cartesian2 //偏移量
image?: string //图片url
imageWidth?: number //图片宽
imageHeight?: number //图片高
}

@ -2,7 +2,7 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-07 16:04:55
* @LastEditors: cbwu
* @LastEditTime: 2024-04-02 14:01:22
* @LastEditTime: 2024-04-15 16:06:06
* @Description:
*/
// 天地图影像服务
@ -29,6 +29,7 @@ enum TDTProjectionType {
}
//天地图token
const TDT_tk = '1c5b7cbf9da7d33b221f68c32b6a1791'
const TDT_tk3D = '910a4befdfd04d5423268b0aced82248'
// 服务域名
const tdtUrl = 'https://t{s}.tianditu.gov.cn'
// 服务负载子域
@ -54,7 +55,7 @@ export function getTDTProvider(
: new WebMercatorTilingScheme()
const tileMatrixLabels =
projectionType == TDTProjectionType.WGS84
? new Array(19).fill(1).map((v, i) => `${i}`)
? new Array(19).fill(1).map((v, i) => `${i + 1}`)
: undefined
const imageryProvider = new WebMapTileServiceImageryProvider({
//影像底图
@ -84,7 +85,7 @@ export function getTDTTerrainProvider() {
const url =
tdtUrl.replace('{s}', subdomains[i]) +
'/mapservice/swdx?T=elv_c&tk=' +
TDT_tk
TDT_tk3D
terrainUrls.push(url)
}

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

@ -2,7 +2,7 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-22 09:11:54
* @LastEditors: cbwu
* @LastEditTime: 2024-04-01 09:21:17
* @LastEditTime: 2024-04-13 10:49:36
* @Description:
*/
import { Cartesian2, Viewer, Math, Cartographic, Cartesian3 } from 'cesium'

@ -2,7 +2,7 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-27 09:51:04
* @LastEditors: cbwu
* @LastEditTime: 2024-04-10 15:54:02
* @LastEditTime: 2024-04-13 10:46:43
* @Description:
*/
import {

@ -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
* @Date: 2024-03-27 08:43:44
* @LastEditors: cbwu
* @LastEditTime: 2024-04-02 13:33:25
* @LastEditTime: 2024-04-13 10:46:58
* @Description: Polyline
*/
import {
@ -178,7 +178,7 @@ export default class CreatePolyline {
this.handler.removeInputAction(ScreenSpaceEventType.MOUSE_MOVE)
this.handler.removeInputAction(ScreenSpaceEventType.LEFT_DOUBLE_CLICK)
}
//创建追踪线
createTrackingLine(positions: Cartesian3[]) {
return new Entity({
polyline: {

@ -2,7 +2,7 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-27 11:06:45
* @LastEditors: cbwu
* @LastEditTime: 2024-04-02 11:05:20
* @LastEditTime: 2024-04-13 10:47:09
* @Description:
*/
import {

@ -1,231 +0,0 @@
/*
* @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-28 09:14:45
* @LastEditors: cbwu
* @LastEditTime: 2024-03-28 17:40:14
* @Description:
*/
import {
Entity,
EntityCollection,
Cartesian3,
Color,
PrimitiveCollection,
PointPrimitiveCollection,
PolylineGeometry,
PointGraphics,
Property,
PositionProperty,
LabelGraphics,
PolylineGraphics,
PolygonGraphics,
Cartesian2,
ConstantPositionProperty,
CallbackProperty,
} from 'cesium'
type EntityOptions = {
id?: string
name?: string
show?: boolean
pixelSize?: number
outlineColor?: Color
color?: Color
fillColor?: Color
fill?: boolean
width?: number
outlineWidth?: number
text?: string
font?: string
pixelOffset?: Cartesian2
}
// 点
class PointEntity extends Entity {
static ID: number = 0
public subId: number = 0 //用于作为其他几何体的控制点时标记节点号
options: EntityOptions = {
id: 'Point' + String(PointEntity.ID),
name: 'Point' + String(PointEntity.ID + 1),
show: true,
pixelSize: 10,
color: Color.GREEN,
outlineWidth: 0,
}
constructor(
position: PositionProperty | Cartesian3,
options?: EntityOptions,
) {
super({
position: position,
})
this.options = { ...this.options, ...options }
//点对象
this.point = new PointGraphics({
pixelSize: this.options.pixelSize,
color: this.options.color,
outlineColor: this.options.outlineColor,
outlineWidth: this.options.outlineWidth,
})
// 标注对象
this.label = new LabelGraphics({
text: this.options.text,
font: this.options.font,
pixelOffset: this.options.pixelOffset,
})
PointEntity.ID++
}
}
// 线
class PolylineEntity extends EntityCollection {
static ID: number = 0
positions: Cartesian3[] = []
controlPointsID: string[] = []
options: EntityOptions = {
id: 'Polyline' + String(PolylineEntity.ID),
name: 'Polyline' + String(PolylineEntity.ID + 1),
show: true,
width: 2,
color: Color.GREEN,
}
constructor(ptArr: Cartesian3[], options?: EntityOptions) {
super()
this.options = { ...this.options, ...options }
this.positions = ptArr
const polyline = new Entity({
name: this.options.name,
polyline: {
positions: new CallbackProperty(() => {
return this.positions
}, false),
show: this.options.show,
width: this.options.width,
material: this.options.color,
},
})
this.add(polyline)
ptArr.forEach((pt, index) => {
this.createPoint(pt, index)
})
PolylineEntity.ID++
}
/**
* ,
* @param pos
* @param index 0
*/
public addPoint(pos: Cartesian3, index: number = -1) {
if (index === -1) {
//插入尾部
this.positions.push(pos)
this.createPoint(pos, this.positions.length - 1)
} else if (index >= 0 && index < this.positions.length) {
this.positions.splice(index, 0, pos)
this.createPoint(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)
this.removeById(this.controlPointsID[index])
this.controlPointsID.splice(index, 1)
} else {
return
}
}
/**
*
* @param pos
* @param index
*/
public modifyPoint(pos: Cartesian3, index: number) {
if (index >= 0 && index < this.positions.length) {
this.positions.splice(index, 1, pos)
//修改控制点坐标
const point = this.getById(this.controlPointsID[index])
if (point) {
point.position = new ConstantPositionProperty(pos)
}
}
}
/**
*
* @param pos
* @param index ,0
*/
createPoint(pos: Cartesian3, index: number) {
const point = new PointEntity(pos)
point.subId = index + 1
this.add(point)
this.controlPointsID.splice(index, 0, point.id)
}
}
// 多边形
class PolygonEntity extends Entity {
static id: number = 0
options: EntityOptions = {
id: 'Polygon' + String(PolygonEntity.id),
name: 'Polygon' + String(PolygonEntity.id + 1),
show: true,
width: 2,
color: Color.RED,
fillColor: Color.RED.withAlpha(0.5),
fill: true,
}
constructor(ptArr: Cartesian3[] | Property, options?: EntityOptions) {
super({
// id: options?.id || String(PolygonEntity.id),
})
this.options = { ...this.options, ...options }
this.name = this.options.name
this.polygon = new PolygonGraphics({
show: this.options.show,
hierarchy: ptArr,
material: this.options.fillColor, //填充颜色
fill: this.options.fill, //是否填充
outlineWidth: this.options.width, //线宽
outlineColor: this.options.color, //线颜色
})
PolygonEntity.id++
}
}
// 线
class Polyline extends PrimitiveCollection {
constructor(ptArr: Cartesian3[]) {
super()
this.add(this.createPoints(ptArr))
this.add(this.createPolyline(ptArr))
// this.id
}
private createPoints(posArr: Cartesian3[]) {
const points = new PointPrimitiveCollection()
for (const pos in posArr) {
points.add({
position: pos,
color: Color.RED,
pixelSize: 10,
})
}
return points
}
private createPolyline(posArr: Cartesian3[]) {
return new PolylineGeometry({
positions: posArr,
width: 2,
colors: new Array(posArr.length).fill(Color.fromCssColorString('green')),
})
}
}
export { PointEntity, Polyline, PolylineEntity, PolygonEntity }

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

@ -2,10 +2,17 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-22 15:42:49
* @LastEditors: cbwu
* @LastEditTime: 2024-04-01 14:05:43
* @LastEditTime: 2024-04-13 10:49:17
* @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]
@ -84,20 +91,18 @@ function isOnLineSegment(
*/
}
/**
*
* @param p1
* @param p2
*/
function getDistance(p1:Cartesian3, p2: Cartesian3): number
{
let point1cartographic = Cartographic.fromCartesian(p1);
let point2cartographic = Cartographic.fromCartesian(p2);
function getDistance(p1: Cartesian3, p2: Cartesian3): number {
let point1cartographic = Cartographic.fromCartesian(p1)
let point2cartographic = Cartographic.fromCartesian(p2)
/**根据经纬度计算出距离**/
let geodesic = new EllipsoidGeodesic()
geodesic.setEndPoints(point1cartographic, point2cartographic)
return geodesic.surfaceDistance/1000
return geodesic.surfaceDistance / 1000
}
/**
@ -106,20 +111,30 @@ function getDistance(p1:Cartesian3, p2: Cartesian3): number
* @param p2
* @param digits 1
*/
function getAzimuth(p1:Cartesian3, p2: Cartesian3, digits=1): string
{
function getAzimuth(p1: Cartesian3, p2: Cartesian3, digits = 1): string {
// 建立局部坐标系北为y东为xp1为原点
const localMatrix = Transforms.eastNorthUpToFixedFrame(p1)
//求世界坐标到局部坐标的变换矩阵
const worldToLocalMatrix = Matrix4.inverse(localMatrix, new Matrix4())
//p1在局部坐标系的位置即局部坐标原点
const localPosition1 = Matrix4.multiplyByPoint(worldToLocalMatrix, p1, new Cartesian3())
const localPosition1 = Matrix4.multiplyByPoint(
worldToLocalMatrix,
p1,
new Cartesian3(),
)
//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
return theta.toFixed(digits)
}
@ -139,4 +154,10 @@ function getPolygonArea(vertexs: Cartesian3[]) {
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
* @Date: 2024-03-28 16:22:58
* @LastEditors: cbwu
* @LastEditTime: 2024-04-02 14:09:15
* @LastEditTime: 2024-04-13 10:45:37
* @Description:
*/
import {
@ -13,7 +13,8 @@ import {
ConstantPositionProperty,
CustomDataSource,
} from 'cesium'
import { PointEntity, EntityOptions } from './pointEntity'
import { PointEntity } from './pointEntity'
import { EntityOptions } from '@/types/entityoptions'
export abstract class BaseGeometry extends CustomDataSource {
static ID: number
// abstract subId: number
@ -37,16 +38,21 @@ export abstract class BaseGeometry extends CustomDataSource {
* ,
* @param pos
* @param index 0
* @bAddControlPoint
*/
public addPoint(pos: Cartesian3, index: number = -1) {
public addPoint(
pos: Cartesian3,
index: number = -1,
bAddControlPoint: boolean = true,
) {
if (index === -1) {
//插入尾部
this.positions.push(pos)
// console.log(this.positions.length)
this.createPoint(pos, this.positions.length - 1)
if (bAddControlPoint)
this.createControlPoint(pos, this.positions.length - 1)
} else if (index >= 0 && index < this.positions.length) {
this.positions.splice(index, 0, pos)
this.createPoint(pos, index)
if (bAddControlPoint) this.createControlPoint(pos, index)
} else {
return
}
@ -62,11 +68,11 @@ export abstract class BaseGeometry extends CustomDataSource {
this.positions.pop()
} else if (index >= 0 && index < this.positions.length) {
this.positions.splice(index, 1)
this.entities.removeById(this.controlPointsID[index])
this.controlPointsID.splice(index, 1)
} else {
return
}
//移除控制点
this.removeControlPoint(index)
}
/**
*
@ -74,12 +80,17 @@ export abstract class BaseGeometry extends CustomDataSource {
* @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)
//修改控制点坐标
const point = this.entities.getById(this.controlPointsID[index])
if (point) {
point.position = new ConstantPositionProperty(pos)
if (this.controlPointsID[index]) {
//修改控制点坐标
const point = this.entities.getById(this.controlPointsID[index])
if (point) {
point.position = new ConstantPositionProperty(pos)
}
}
}
}
@ -88,7 +99,7 @@ export abstract class BaseGeometry extends CustomDataSource {
* @param pos
* @param index ,0
*/
createPoint(pos: Cartesian3, index: number) {
public createControlPoint(pos: Cartesian3, index: number) {
// if (this.geometry) {
const point = new PointEntity(pos)
point.parent = this.geometry!
@ -97,6 +108,17 @@ export abstract class BaseGeometry extends CustomDataSource {
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 +128,16 @@ export abstract class BaseGeometry extends CustomDataSource {
})
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,10 +2,10 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-04-10 08:53:12
* @LastEditors: cbwu
* @LastEditTime: 2024-04-11 09:09:38
* @LastEditTime: 2024-04-13 10:45:00
* @Description: 广
*/
import { Entity, Cartesian3, Cartesian2, Color, HeightReference } from 'cesium'
import { Entity, Cartesian3, Cartesian2, HeightReference } from 'cesium'
import { getMapAssetsFile } from '@/utils/getAssets'
export class BillBoard extends Entity {
static ID: number = 0

@ -2,35 +2,11 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-28 16:35:33
* @LastEditors: cbwu
* @LastEditTime: 2024-03-30 22:06:23
* @LastEditTime: 2024-04-13 11:15:48
* @Description:
*/
import {
Entity,
Cartesian3,
Color,
PointGraphics,
PositionProperty,
LabelGraphics,
Cartesian2,
CallbackProperty,
Property,
} from 'cesium'
type EntityOptions = {
id?: string
name?: string
show?: boolean
pixelSize?: number
outlineColor?: Color
color?: Color
fillColor?: Color
fill?: boolean
width?: number
outlineWidth?: number
text?: string
font?: string
pixelOffset?: Cartesian2
}
import { Entity, Cartesian3, Color, PointGraphics, LabelGraphics } from 'cesium'
import { EntityOptions } from '@/types/entityoptions'
// 点
class PointEntity extends Entity {
static ID: number = 0
@ -39,8 +15,9 @@ class PointEntity extends Entity {
id: 'Point' + String(PointEntity.ID),
name: 'Point' + String(PointEntity.ID + 1),
show: true,
pixelSize: 10,
color: Color.GREEN,
pixelSize: 8,
color: Color.WHITE,
outlineColor: Color.GREEN,
outlineWidth: 0,
}
constructor(position: Cartesian3, options?: EntityOptions) {
@ -66,4 +43,4 @@ class PointEntity extends Entity {
}
}
export { PointEntity, type EntityOptions }
export { PointEntity }

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

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

@ -2,7 +2,7 @@
* @Author: cbwu 504-wuchengbo@htsdfp.com
* @Date: 2024-03-13 09:32:21
* @LastEditors: cbwu
* @LastEditTime: 2024-04-10 14:02:37
* @LastEditTime: 2024-04-13 10:49:06
* @Description:
*/
// Viewer初始化

Loading…
Cancel
Save