Merge branch 'devzpx' into dev

# Conflicts:
#	src/components/map/BottomBar.vue
#	src/utils/map/angle.ts
#	src/utils/map/geocomputation.ts
pull/6/head
zhaipx 11 months ago
commit 771a8b1c35

@ -5,18 +5,17 @@
-->
<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'
import {ScreenSpaceEventHandler, Math, ScreenSpaceEventType} from 'cesium'
import {onMounted, ref} from "vue";
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: ScreenSpaceEventHandler.MotionEvent) => {
handler.setInputAction((e:any)=> {
//
// let position: any = _viewer.scene.pickPosition(e.endPosition)
// if (!position) {
@ -28,24 +27,20 @@ onMounted(() => {
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) ?? ''
: '' //
let needElevation: boolean = camera_alt < 250 && (_viewer.camera.pitch < -(Math.PI/180)*80)
let elevStr = needElevation? _viewer.scene.globe.getHeight(cartographic)?.toFixed(2)?? '' : '' //
if (isDecimal.value) {
//
if(isDecimal.value) { //
lonlatStr.value = `经度:${nowLonStr} , 纬度:${nowLatStr} , 海拔(m)${elevStr}`
} else {
}
else {
lonlatStr.value = `经度:${Angle.DecimalDegree2DMS(nowLonStr)} , 纬度:${Angle.DecimalDegree2DMS(nowLatStr)} , 海拔(m)${elevStr}`
}
} catch (e) {}
@ -55,13 +50,11 @@ onMounted(() => {
function lonlatClick() {
let elevStr = lonlatStr.value.split('海拔')[1]
if (isDecimal.value) {
lonlatStr.value =
`经度:${Angle.DecimalDegree2DMS(nowLonStr)} , 纬度:${Angle.DecimalDegree2DMS(nowLatStr)} , 海拔(m)` +
elevStr
} else {
lonlatStr.value =
`经度:${nowLonStr} , 纬度:${nowLatStr} , 海拔(m)` + elevStr
if(isDecimal.value){
lonlatStr.value = `经度:${Angle.DecimalDegree2DMS(nowLonStr)} , 纬度:${Angle.DecimalDegree2DMS(nowLatStr)} , 海拔(m)` + elevStr
}
else {
lonlatStr.value = `经度:${nowLonStr} , 纬度:${nowLatStr} , 海拔(m)` + elevStr
}
isDecimal.value = !isDecimal.value
}
@ -91,14 +84,14 @@ function lonlatClick() {
display: flex;
align-items: center;
}
#lonlatText {
#lonlatText{
margin-left: 2rem;
background: none;
border: none;
color: #ffffff;
font-size: 0.8rem;
}
#lonlatText:hover {
#lonlatText:hover{
cursor: pointer;
}
</style>

@ -52,8 +52,7 @@ screen and (max-height: 420px) {
right: 1.8rem;
top: 65vh;
width: 2rem;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: .3rem .3rem .3rem .3rem;
border-radius: .5rem .5rem .5rem .5rem;
font-weight: 300;
-webkit-touch-callout: none;
-webkit-user-select: none;
@ -76,23 +75,27 @@ screen and (max-height: 420px) {
position: relative;
text-align: center;
font-size: 1.2rem;
color: #FFFFFF;
color: #2c2c2c;
background: #FFFFFF;
border-radius: .5rem .5rem 0 0;
padding-bottom: 4px;
}
.navigation-control-icon-zoom-in:hover {
background: rgba(204, 204, 204, 0.78);
border-radius: .3rem .3rem 0 0;
background: rgb(223, 223, 223);
border-radius: .5rem .5rem 0 0;
}
/* - 按钮*/
.navigation-control-icon-zoom-out {
position: relative;
text-align: center;
font-size: 1.4rem;
color: #FFFFFF;
background: #FFFFFF;
color: #2c2c2c;
border-radius: 0 0 .5rem .5rem;
}
.navigation-control-icon-zoom-out:hover {
background: rgba(204, 204, 204, 0.78);
border-radius: 0 0 .3rem .3rem;
background: rgb(223, 223, 223);
border-radius: 0 0 .5rem .5rem;
}
/* reset 按钮*/
.navigation-control-icon-reset {
@ -119,7 +122,7 @@ screen and (max-height: 420px) {
top: 0;
width: 6rem;;
height: 6rem;;
fill: rgba(255, 255, 255, 0.5);
fill: #5b5b5b;
}
.compass-outer-ring-background {
@ -129,7 +132,7 @@ screen and (max-height: 420px) {
width: 44px;
height: 44px;
border-radius: 44px;
border: 12px solid rgba(47, 53, 60, 0.8);
border: 12px solid rgb(255, 255, 255);
box-sizing: content-box;
}
@ -139,7 +142,7 @@ screen and (max-height: 420px) {
top: 0;
width: 95px;
height: 95px;
fill: #faf6f6;
fill: #5b5b5b;
}
.compass-gyro-active {
@ -153,7 +156,7 @@ screen and (max-height: 420px) {
width: 2rem;
height: 2rem;
border-radius: 33px;
background-color: rgba(47, 53, 60, 0.8);
background-color: rgba(250, 250, 250, 0.8);
border: 1px solid rgba(255, 255, 255, 0.2);
box-sizing: content-box;
}

@ -0,0 +1,5 @@
/*
* @Author: zhaipx
* @Date: {2024/4/11}
* @Description:
*/

@ -1,39 +1,57 @@
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) +
"''"
)
}
/**
*
* @param p1
* @param p2
* @param digits 1
*/
static getAzimuth(p1: Cartesian3, p2: Cartesian3, digits=1){
return getAzimuth(p1, p2, digits)
}
return ''
}
/**
*
* @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 }

@ -5,7 +5,7 @@
* @LastEditTime: 2024-04-01 14:05:43
* @Description:
*/
import { Cartesian3, Math as Cesium_Math } from 'cesium'
import {Cartesian3, Cartographic, EllipsoidGeodesic, Math as Cesium_Math, Matrix4, Transforms} from 'cesium'
/**
* 线
* @param lineStart 线[longitude1, latitude1, height1]
@ -84,4 +84,59 @@ function isOnLineSegment(
*/
}
export { getClosestPoint, isOnLineSegment }
/**
*
* @param p1
* @param 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
}
/**
*
* @param p1
* @param p2
* @param digits 1
*/
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())
//p2在局部坐标系的位置
const localPosition2 = Matrix4.multiplyByPoint(worldToLocalMatrix, p2, new Cartesian3())
//弧度
const angle = Math.atan2(localPosition2.x - localPosition1.x, localPosition2.y - localPosition1.y)
//转为角度
let theta = angle * (180 / Math.PI);
theta = theta < 0 ? theta + 360 : theta
return theta.toFixed(digits)
}
/**
*
* @param vertexs
*/
function getPolygonArea(vertexs: Cartesian3[]) {
let area = 0
for (let i = 0; i < vertexs.length; i++) {
let j = (i + 1) % vertexs.length
area += vertexs[i].x * vertexs[j].y
area -= vertexs[i].y * vertexs[j].x
}
area /= 2
return Math.abs(area)
}
export { getClosestPoint, isOnLineSegment, getDistance, getAzimuth, getPolygonArea }

Loading…
Cancel
Save