huweili-cesium 1.3.2 → 1.3.3
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 +114 -27
- package/package.json +1 -1
package/js/drawFenceNew.js
CHANGED
|
@@ -1002,8 +1002,16 @@ export function drawFenceNew() {
|
|
|
1002
1002
|
let centerPointEntity = null
|
|
1003
1003
|
// activePointEntity:活动点实体(跟随鼠标的边界点)
|
|
1004
1004
|
let activePointEntity = null
|
|
1005
|
-
//
|
|
1006
|
-
let
|
|
1005
|
+
// circleWallEntity / circleOutlineEntity / radiusLineEntity:绘制过程预览(与最终围栏一致的贴地圆边)
|
|
1006
|
+
let circleWallEntity = null
|
|
1007
|
+
let circleOutlineEntity = null
|
|
1008
|
+
let radiusLineEntity = null
|
|
1009
|
+
// 预览几何缓存,仅在鼠标移动时更新,避免每帧重复计算
|
|
1010
|
+
let previewCirclePositions = []
|
|
1011
|
+
let previewWallMaxHeights = []
|
|
1012
|
+
let previewWallMinHeights = []
|
|
1013
|
+
let previewRadiusLinePositions = []
|
|
1014
|
+
let previewRenderFrameId = null
|
|
1007
1015
|
// tipEntity:提示文字实体(显示"点击确定圆心"等提示)
|
|
1008
1016
|
let tipEntity = null
|
|
1009
1017
|
// radiusLabelEntity:绘制过程中显示当前半径的标签
|
|
@@ -1018,7 +1026,9 @@ export function drawFenceNew() {
|
|
|
1018
1026
|
// ==================== 临时实体ID配置 ====================
|
|
1019
1027
|
// 这些是绘制过程中临时显示的实体,绘制完成后会清理
|
|
1020
1028
|
const tempIds = {
|
|
1021
|
-
|
|
1029
|
+
circleWall: `${options.id}_draw_circle_wall`,
|
|
1030
|
+
circleOutline: `${options.id}_draw_circle_outline`,
|
|
1031
|
+
radiusLine: `${options.id}_draw_radius_line`,
|
|
1022
1032
|
center: `${options.id}_draw_center_point`, // 临时圆心点
|
|
1023
1033
|
active: `${options.id}_draw_active_point`, // 临时边界点
|
|
1024
1034
|
tip: `${options.id}_draw_tip`, // 临时提示文字
|
|
@@ -1139,6 +1149,42 @@ export function drawFenceNew() {
|
|
|
1139
1149
|
})
|
|
1140
1150
|
}
|
|
1141
1151
|
|
|
1152
|
+
const updatePreviewGeometry = () => {
|
|
1153
|
+
if (!centerPosition || !edgePosition) {
|
|
1154
|
+
previewCirclePositions = []
|
|
1155
|
+
previewWallMaxHeights = []
|
|
1156
|
+
previewWallMinHeights = []
|
|
1157
|
+
previewRadiusLinePositions = []
|
|
1158
|
+
return
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
const radius = getRadius()
|
|
1162
|
+
previewRadiusLinePositions = [centerPosition, edgePosition]
|
|
1163
|
+
|
|
1164
|
+
if (radius <= 0) {
|
|
1165
|
+
previewCirclePositions = []
|
|
1166
|
+
previewWallMaxHeights = []
|
|
1167
|
+
previewWallMinHeights = []
|
|
1168
|
+
return
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
const centerData = cartesianToLngLatHeight(centerPosition)
|
|
1172
|
+
const circleLngLats = generateCircleLngLatPositions(centerData.lng, centerData.lat, radius)
|
|
1173
|
+
const footprint = circleLngLats.map(cartesianFootprintFromLngLat)
|
|
1174
|
+
previewCirclePositions = [...footprint, footprint[0]]
|
|
1175
|
+
previewWallMaxHeights = previewCirclePositions.map(() => height)
|
|
1176
|
+
previewWallMinHeights = previewCirclePositions.map(() => 0)
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
const schedulePreviewUpdate = () => {
|
|
1180
|
+
if (previewRenderFrameId !== null) return
|
|
1181
|
+
previewRenderFrameId = requestAnimationFrame(() => {
|
|
1182
|
+
previewRenderFrameId = null
|
|
1183
|
+
updatePreviewGeometry()
|
|
1184
|
+
map.scene.requestRender()
|
|
1185
|
+
})
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1142
1188
|
// ==================== 核心业务函数 ====================
|
|
1143
1189
|
|
|
1144
1190
|
/**
|
|
@@ -1162,25 +1208,45 @@ export function drawFenceNew() {
|
|
|
1162
1208
|
})
|
|
1163
1209
|
}
|
|
1164
1210
|
|
|
1165
|
-
// 2.
|
|
1166
|
-
if (!
|
|
1167
|
-
|
|
1168
|
-
id: tempIds.
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1211
|
+
// 2. 创建贴地圆边预览(确定圆心后显示,与最终围栏 polyline / wall 一致)
|
|
1212
|
+
if (centerPosition && !circleWallEntity) {
|
|
1213
|
+
circleWallEntity = map.entities.add({
|
|
1214
|
+
id: tempIds.circleWall,
|
|
1215
|
+
wall: {
|
|
1216
|
+
positions: new Cesium.CallbackProperty(() => previewCirclePositions, false),
|
|
1217
|
+
maximumHeights: new Cesium.CallbackProperty(() => previewWallMaxHeights, false),
|
|
1218
|
+
minimumHeights: new Cesium.CallbackProperty(() => previewWallMinHeights, false),
|
|
1219
|
+
material: color.withAlpha(0.18),
|
|
1220
|
+
outline: true,
|
|
1221
|
+
outlineColor: color,
|
|
1222
|
+
outlineWidth,
|
|
1223
|
+
},
|
|
1224
|
+
})
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
if (centerPosition && !circleOutlineEntity) {
|
|
1228
|
+
circleOutlineEntity = map.entities.add({
|
|
1229
|
+
id: tempIds.circleOutline,
|
|
1230
|
+
polyline: {
|
|
1231
|
+
positions: new Cesium.CallbackProperty(() => previewCirclePositions, false),
|
|
1232
|
+
width: outlineWidth,
|
|
1233
|
+
material: color,
|
|
1234
|
+
clampToGround: true,
|
|
1235
|
+
arcType: Cesium.ArcType.GEODESIC,
|
|
1236
|
+
},
|
|
1237
|
+
})
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
if (centerPosition && !radiusLineEntity) {
|
|
1241
|
+
radiusLineEntity = map.entities.add({
|
|
1242
|
+
id: tempIds.radiusLine,
|
|
1243
|
+
polyline: {
|
|
1244
|
+
positions: new Cesium.CallbackProperty(() => previewRadiusLinePositions, false),
|
|
1245
|
+
width: Math.max(1, outlineWidth - 1),
|
|
1246
|
+
material: color.withAlpha(0.85),
|
|
1247
|
+
clampToGround: true,
|
|
1248
|
+
arcType: Cesium.ArcType.GEODESIC,
|
|
1249
|
+
},
|
|
1184
1250
|
})
|
|
1185
1251
|
}
|
|
1186
1252
|
|
|
@@ -1241,17 +1307,28 @@ export function drawFenceNew() {
|
|
|
1241
1307
|
*/
|
|
1242
1308
|
const cleanupTempEntities = () => {
|
|
1243
1309
|
// 遍历所有临时实体,如果存在就从地图上移除
|
|
1244
|
-
;[
|
|
1310
|
+
;[circleWallEntity, circleOutlineEntity, radiusLineEntity, centerPointEntity, activePointEntity, radiusLabelEntity, tipEntity, nameLabelEntity].forEach((entity) => {
|
|
1245
1311
|
if (entity) {
|
|
1246
1312
|
map.entities.remove(entity)
|
|
1247
1313
|
}
|
|
1248
1314
|
})
|
|
1249
1315
|
// 将变量清空,防止内存泄露
|
|
1250
|
-
|
|
1316
|
+
circleWallEntity = null
|
|
1317
|
+
circleOutlineEntity = null
|
|
1318
|
+
radiusLineEntity = null
|
|
1251
1319
|
centerPointEntity = null
|
|
1252
1320
|
activePointEntity = null
|
|
1253
1321
|
radiusLabelEntity = null
|
|
1322
|
+
tipEntity = null
|
|
1254
1323
|
nameLabelEntity = null
|
|
1324
|
+
previewCirclePositions = []
|
|
1325
|
+
previewWallMaxHeights = []
|
|
1326
|
+
previewWallMinHeights = []
|
|
1327
|
+
previewRadiusLinePositions = []
|
|
1328
|
+
if (previewRenderFrameId !== null) {
|
|
1329
|
+
cancelAnimationFrame(previewRenderFrameId)
|
|
1330
|
+
previewRenderFrameId = null
|
|
1331
|
+
}
|
|
1255
1332
|
}
|
|
1256
1333
|
|
|
1257
1334
|
/**
|
|
@@ -1291,9 +1368,17 @@ export function drawFenceNew() {
|
|
|
1291
1368
|
const footprint = circleLngLats.map(cartesianFootprintFromLngLat)
|
|
1292
1369
|
const wallPositions = [...footprint, footprint[0]]
|
|
1293
1370
|
|
|
1294
|
-
if (
|
|
1295
|
-
map.entities.remove(
|
|
1296
|
-
|
|
1371
|
+
if (circleWallEntity) {
|
|
1372
|
+
map.entities.remove(circleWallEntity)
|
|
1373
|
+
circleWallEntity = null
|
|
1374
|
+
}
|
|
1375
|
+
if (circleOutlineEntity) {
|
|
1376
|
+
map.entities.remove(circleOutlineEntity)
|
|
1377
|
+
circleOutlineEntity = null
|
|
1378
|
+
}
|
|
1379
|
+
if (radiusLineEntity) {
|
|
1380
|
+
map.entities.remove(radiusLineEntity)
|
|
1381
|
+
radiusLineEntity = null
|
|
1297
1382
|
}
|
|
1298
1383
|
|
|
1299
1384
|
const fenceEntity = map.entities.add({
|
|
@@ -1451,6 +1536,7 @@ export function drawFenceNew() {
|
|
|
1451
1536
|
centerPosition = Cesium.Cartesian3.clone(cartesian)
|
|
1452
1537
|
edgePosition = Cesium.Cartesian3.clone(cartesian) // 边界点初始化为圆心
|
|
1453
1538
|
ensurePreviewEntities() // 确保预览实体都创建好
|
|
1539
|
+
schedulePreviewUpdate()
|
|
1454
1540
|
emitChange() // 触发变化回调
|
|
1455
1541
|
return
|
|
1456
1542
|
}
|
|
@@ -1473,6 +1559,7 @@ export function drawFenceNew() {
|
|
|
1473
1559
|
// 如果已经确定了圆心 → 实时更新边界点,让预览跟随鼠标
|
|
1474
1560
|
if (!centerPosition) return
|
|
1475
1561
|
edgePosition = Cesium.Cartesian3.clone(cartesian)
|
|
1562
|
+
schedulePreviewUpdate()
|
|
1476
1563
|
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
|
|
1477
1564
|
|
|
1478
1565
|
// ==================== 事件3:鼠标右键点击 ====================
|