huweili-cesium 1.3.1 → 1.3.2
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 +52 -5
- package/package.json +1 -1
package/js/drawFenceNew.js
CHANGED
|
@@ -1006,6 +1006,8 @@ export function drawFenceNew() {
|
|
|
1006
1006
|
let ellipseEntity = null
|
|
1007
1007
|
// tipEntity:提示文字实体(显示"点击确定圆心"等提示)
|
|
1008
1008
|
let tipEntity = null
|
|
1009
|
+
// radiusLabelEntity:绘制过程中显示当前半径的标签
|
|
1010
|
+
let radiusLabelEntity = null
|
|
1009
1011
|
// nameLabelEntity:围栏名称标签实体
|
|
1010
1012
|
let nameLabelEntity = null
|
|
1011
1013
|
// handler:屏幕事件处理器(监听鼠标点击、移动等)
|
|
@@ -1019,7 +1021,8 @@ export function drawFenceNew() {
|
|
|
1019
1021
|
ellipse: `${options.id}_draw_circle_wall`, // 临时椭圆围栏
|
|
1020
1022
|
center: `${options.id}_draw_center_point`, // 临时圆心点
|
|
1021
1023
|
active: `${options.id}_draw_active_point`, // 临时边界点
|
|
1022
|
-
tip: `${options.id}_draw_tip
|
|
1024
|
+
tip: `${options.id}_draw_tip`, // 临时提示文字
|
|
1025
|
+
radiusLabel: `${options.id}_draw_radius_label`, // 临时半径标签
|
|
1023
1026
|
}
|
|
1024
1027
|
|
|
1025
1028
|
// ==================== 辅助函数部分 ====================
|
|
@@ -1078,6 +1081,23 @@ export function drawFenceNew() {
|
|
|
1078
1081
|
return geodesic.surfaceDistance
|
|
1079
1082
|
}
|
|
1080
1083
|
|
|
1084
|
+
const formatRadius = (radius) => {
|
|
1085
|
+
if (!Number.isFinite(radius)) return '0 m'
|
|
1086
|
+
if (radius >= 1000) return `${(radius / 1000).toFixed(2)} km`
|
|
1087
|
+
return `${radius.toFixed(2)} m`
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
const getRadiusLabelPosition = () => {
|
|
1091
|
+
if (!centerPosition || !edgePosition) return null
|
|
1092
|
+
const centerCartographic = Cesium.Cartographic.fromCartesian(centerPosition)
|
|
1093
|
+
const edgeCartographic = Cesium.Cartographic.fromCartesian(edgePosition)
|
|
1094
|
+
return Cesium.Cartesian3.fromRadians(
|
|
1095
|
+
(centerCartographic.longitude + edgeCartographic.longitude) / 2,
|
|
1096
|
+
(centerCartographic.latitude + edgeCartographic.latitude) / 2,
|
|
1097
|
+
0,
|
|
1098
|
+
)
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1081
1101
|
/**
|
|
1082
1102
|
* 获取提示文字的位置(鼠标位置优先)
|
|
1083
1103
|
*
|
|
@@ -1099,7 +1119,7 @@ export function drawFenceNew() {
|
|
|
1099
1119
|
}
|
|
1100
1120
|
|
|
1101
1121
|
// 已经有圆心 → 提示用户"移动调整半径,点击或右键完成"
|
|
1102
|
-
return
|
|
1122
|
+
return `移动鼠标调整半径,当前半径:${formatRadius(getRadius())},点击或右键完成绘制`
|
|
1103
1123
|
}
|
|
1104
1124
|
|
|
1105
1125
|
/**
|
|
@@ -1180,7 +1200,32 @@ export function drawFenceNew() {
|
|
|
1180
1200
|
})
|
|
1181
1201
|
}
|
|
1182
1202
|
|
|
1183
|
-
// 4.
|
|
1203
|
+
// 4. 创建半径标签(确定圆心后显示)
|
|
1204
|
+
if (!radiusLabelEntity && centerPosition) {
|
|
1205
|
+
radiusLabelEntity = map.entities.add({
|
|
1206
|
+
id: tempIds.radiusLabel,
|
|
1207
|
+
position: new Cesium.CallbackProperty(() => getRadiusLabelPosition(), false),
|
|
1208
|
+
label: {
|
|
1209
|
+
text: new Cesium.CallbackProperty(() => formatRadius(getRadius()), false),
|
|
1210
|
+
font: 'bold 10px Microsoft YaHei',
|
|
1211
|
+
fillColor: Cesium.Color.WHITE,
|
|
1212
|
+
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
|
1213
|
+
outlineColor: Cesium.Color.BLACK,
|
|
1214
|
+
outlineWidth: 2,
|
|
1215
|
+
showBackground: true,
|
|
1216
|
+
backgroundColor: Cesium.Color.fromCssColorString('rgba(0, 0, 0, 0.75)'),
|
|
1217
|
+
backgroundPadding: new Cesium.Cartesian2(4, 4),
|
|
1218
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
1219
|
+
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
|
|
1220
|
+
pixelOffset: new Cesium.Cartesian2(0, -16),
|
|
1221
|
+
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
|
1222
|
+
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 2000000),
|
|
1223
|
+
scaleByDistance: new Cesium.NearFarScalar(1000, 1.2, 5000000, 0.6),
|
|
1224
|
+
},
|
|
1225
|
+
})
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
// 5. 创建提示文字实体(如果还没有)
|
|
1184
1229
|
if (!tipEntity) {
|
|
1185
1230
|
tipEntity = createMouseTipEntity(map, {
|
|
1186
1231
|
id: tempIds.tip,
|
|
@@ -1196,7 +1241,7 @@ export function drawFenceNew() {
|
|
|
1196
1241
|
*/
|
|
1197
1242
|
const cleanupTempEntities = () => {
|
|
1198
1243
|
// 遍历所有临时实体,如果存在就从地图上移除
|
|
1199
|
-
;[ellipseEntity, centerPointEntity, activePointEntity, tipEntity, nameLabelEntity].forEach((entity) => {
|
|
1244
|
+
;[ellipseEntity, centerPointEntity, activePointEntity, radiusLabelEntity, tipEntity, nameLabelEntity].forEach((entity) => {
|
|
1200
1245
|
if (entity) {
|
|
1201
1246
|
map.entities.remove(entity)
|
|
1202
1247
|
}
|
|
@@ -1205,6 +1250,7 @@ export function drawFenceNew() {
|
|
|
1205
1250
|
ellipseEntity = null
|
|
1206
1251
|
centerPointEntity = null
|
|
1207
1252
|
activePointEntity = null
|
|
1253
|
+
radiusLabelEntity = null
|
|
1208
1254
|
nameLabelEntity = null
|
|
1209
1255
|
}
|
|
1210
1256
|
|
|
@@ -1273,13 +1319,14 @@ export function drawFenceNew() {
|
|
|
1273
1319
|
|
|
1274
1320
|
await applyTerrainWallToEntity(map, fenceEntity, circleLngLats, height)
|
|
1275
1321
|
|
|
1276
|
-
;[centerPointEntity, activePointEntity, tipEntity].forEach((entity) => {
|
|
1322
|
+
;[centerPointEntity, activePointEntity, radiusLabelEntity, tipEntity].forEach((entity) => {
|
|
1277
1323
|
if (entity) {
|
|
1278
1324
|
map.entities.remove(entity)
|
|
1279
1325
|
}
|
|
1280
1326
|
})
|
|
1281
1327
|
centerPointEntity = null
|
|
1282
1328
|
activePointEntity = null
|
|
1329
|
+
radiusLabelEntity = null
|
|
1283
1330
|
tipEntity = null
|
|
1284
1331
|
|
|
1285
1332
|
const centerHeights = await sampleTerrainHeights(map, [centerData])
|