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.
Files changed (2) hide show
  1. package/js/drawFenceNew.js +22 -16
  2. package/package.json +1 -1
@@ -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
- * 将屏幕坐标(鼠标点击位置)转换为世界3D坐标(Cartesian3)
971
- * 这是Cesium地图交互的核心函数:从屏幕2D点 地球表面3D点
977
+ * 将屏幕坐标(鼠标点击位置)转换为地表世界3D坐标(Cartesian3)
978
+ * 这里不使用 scene.pickPosition,避免 2D/正交视角下拾取到临时点、预览圆或深度缓存,导致小半径绘制被“卡住”。
972
979
  *
973
980
  * @param {Cartesian2} screenPosition - 屏幕坐标,x,y像素值
974
- * @returns {Cartesian3|null} - 世界3D坐标,或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
- // 方法1:优先使用pickPosition(如果场景支持的话,精度更高)
983
- if (scene.pickPositionSupported) {
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
- const ray = map.camera.getPickRay(screenPosition) // 从相机发射一条射线
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: cartographic.height || 0 // 高度(米)
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
- // 使用Cesium内置的距离计算函数,返回两点之间的米数
1022
- return Cesium.Cartesian3.distance(centerPosition, edgePosition)
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
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "huweili-cesium",
3
- "version": "1.2.35",
3
+ "version": "1.2.36",
4
4
  "description": "基于 Cesium 的地图工具库(无人机态势、轨迹、围栏、工具栏等)",
5
5
  "type": "module",
6
6
  "main": "./index.js",