huweili-cesium 1.2.35 → 1.2.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/js/drawFenceNew.js +22 -16
- package/package.json +1 -1
package/js/drawFenceNew.js
CHANGED
|
@@ -966,33 +966,36 @@ export function drawFenceNew() {
|
|
|
966
966
|
|
|
967
967
|
// ==================== 辅助函数部分 ====================
|
|
968
968
|
|
|
969
|
+
const cartesianToGroundCartesian = (cartesian) => {
|
|
970
|
+
if (!Cesium.defined(cartesian)) return null
|
|
971
|
+
|
|
972
|
+
const cartographic = Cesium.Cartographic.fromCartesian(cartesian)
|
|
973
|
+
return Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0)
|
|
974
|
+
}
|
|
975
|
+
|
|
969
976
|
/**
|
|
970
|
-
*
|
|
971
|
-
*
|
|
977
|
+
* 将屏幕坐标(鼠标点击位置)转换为地表世界3D坐标(Cartesian3)
|
|
978
|
+
* 这里不使用 scene.pickPosition,避免 2D/正交视角下拾取到临时点、预览圆或深度缓存,导致小半径绘制被“卡住”。
|
|
972
979
|
*
|
|
973
980
|
* @param {Cartesian2} screenPosition - 屏幕坐标,x,y像素值
|
|
974
|
-
* @returns {Cartesian3|null} -
|
|
981
|
+
* @returns {Cartesian3|null} - 地表世界3D坐标,或null(转换失败)
|
|
975
982
|
*/
|
|
976
983
|
const getCatesianFromScreen = (screenPosition) => {
|
|
977
984
|
if (!screenPosition) return null
|
|
978
985
|
|
|
979
986
|
const scene = map.scene
|
|
980
987
|
let cartesian = null
|
|
988
|
+
const ray = map.camera.getPickRay(screenPosition)
|
|
981
989
|
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
cartesian = scene.pickPosition(screenPosition)
|
|
990
|
+
if (ray) {
|
|
991
|
+
cartesian = scene.globe.pick(ray, scene)
|
|
985
992
|
}
|
|
986
993
|
|
|
987
|
-
// 方法2:如果pickPosition失败,使用射线法(从相机→鼠标→地球)
|
|
988
994
|
if (!Cesium.defined(cartesian)) {
|
|
989
|
-
|
|
990
|
-
if (!ray) return null
|
|
991
|
-
cartesian = scene.globe.pick(ray, scene) // 射线与地球表面的交点
|
|
995
|
+
cartesian = map.camera.pickEllipsoid(screenPosition, scene.globe.ellipsoid)
|
|
992
996
|
}
|
|
993
997
|
|
|
994
|
-
|
|
995
|
-
return Cesium.defined(cartesian) ? cartesian : null
|
|
998
|
+
return cartesianToGroundCartesian(cartesian)
|
|
996
999
|
}
|
|
997
1000
|
|
|
998
1001
|
/**
|
|
@@ -1007,19 +1010,22 @@ export function drawFenceNew() {
|
|
|
1007
1010
|
return {
|
|
1008
1011
|
lng: Cesium.Math.toDegrees(cartographic.longitude), // 弧度 → 角度(经度)
|
|
1009
1012
|
lat: Cesium.Math.toDegrees(cartographic.latitude), // 弧度 → 角度(纬度)
|
|
1010
|
-
height:
|
|
1013
|
+
height: 0 // 圆形围栏绘制点统一贴地
|
|
1011
1014
|
}
|
|
1012
1015
|
}
|
|
1013
1016
|
|
|
1014
1017
|
/**
|
|
1015
|
-
*
|
|
1018
|
+
* 计算当前围栏的半径(圆心到边界点的地表距离)
|
|
1016
1019
|
*
|
|
1017
1020
|
* @returns {number} - 半径(米)
|
|
1018
1021
|
*/
|
|
1019
1022
|
const getRadius = () => {
|
|
1020
1023
|
if (!centerPosition || !edgePosition) return 0
|
|
1021
|
-
|
|
1022
|
-
|
|
1024
|
+
|
|
1025
|
+
const centerCartographic = Cesium.Cartographic.fromCartesian(centerPosition)
|
|
1026
|
+
const edgeCartographic = Cesium.Cartographic.fromCartesian(edgePosition)
|
|
1027
|
+
const geodesic = new Cesium.EllipsoidGeodesic(centerCartographic, edgeCartographic)
|
|
1028
|
+
return geodesic.surfaceDistance
|
|
1023
1029
|
}
|
|
1024
1030
|
|
|
1025
1031
|
/**
|