@xingm/vmap-cesium-toolbar 0.0.1-beta.1 → 0.0.1-beta.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/README.md +169 -615
- package/dist/index.js +487 -277
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +18 -18
- package/dist/index.umd.js.map +1 -1
- package/dist/package.json +4 -4
- package/package.json +5 -6
- package/dist/README.md +0 -585
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as n from "cesium";
|
|
2
|
-
import { Ion as
|
|
2
|
+
import { Ion as C, Viewer as b, createWorldTerrainAsync as w } from "cesium";
|
|
3
3
|
class m {
|
|
4
4
|
viewer;
|
|
5
5
|
scene;
|
|
@@ -11,14 +11,25 @@ class m {
|
|
|
11
11
|
tempPositions = [];
|
|
12
12
|
tempEntities = [];
|
|
13
13
|
// 临时实体,用于绘制过程中
|
|
14
|
+
tempLabelEntities = [];
|
|
15
|
+
// 临时标签实体
|
|
14
16
|
finishedEntities = [];
|
|
15
17
|
// 已完成的实体
|
|
18
|
+
finishedLabelEntities = [];
|
|
19
|
+
// 已完成的标签实体
|
|
20
|
+
finishedPointEntities = [];
|
|
21
|
+
// 已完成的点实体
|
|
22
|
+
publicEntities = [];
|
|
23
|
+
// 通过公共方法创建的实体
|
|
24
|
+
_doubleClickPending = !1;
|
|
25
|
+
// 双击判断
|
|
16
26
|
// 事件处理器
|
|
17
27
|
screenSpaceEventHandler = null;
|
|
18
28
|
// 回调函数
|
|
19
29
|
onDrawStartCallback = null;
|
|
20
30
|
onDrawEndCallback = null;
|
|
21
31
|
onEntityRemovedCallback = null;
|
|
32
|
+
offsetHeight = 2;
|
|
22
33
|
/**
|
|
23
34
|
* 构造函数
|
|
24
35
|
* @param viewer Cesium Viewer 实例
|
|
@@ -26,7 +37,29 @@ class m {
|
|
|
26
37
|
constructor(e) {
|
|
27
38
|
if (!e || !(e instanceof n.Viewer))
|
|
28
39
|
throw new Error("Invalid Cesium Viewer instance provided.");
|
|
29
|
-
this.viewer = e, this.scene = e.scene, this.entities = e.entities, this.scene.
|
|
40
|
+
this.viewer = e, this.scene = e.scene, this.entities = e.entities, this.updateOffsetHeight(), this.scene.morphComplete.addEventListener(() => {
|
|
41
|
+
this.updateOffsetHeight();
|
|
42
|
+
}), this.scene.globe.depthTestAgainstTerrain = !0;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 根据场景模式更新偏移高度
|
|
46
|
+
*/
|
|
47
|
+
updateOffsetHeight() {
|
|
48
|
+
this.scene.mode === n.SceneMode.SCENE3D ? this.offsetHeight = 100 : this.offsetHeight = 0;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 手动设置偏移高度
|
|
52
|
+
* @param height 偏移高度(米)
|
|
53
|
+
*/
|
|
54
|
+
setOffsetHeight(e) {
|
|
55
|
+
this.offsetHeight = e;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 获取当前偏移高度
|
|
59
|
+
* @returns 当前偏移高度(米)
|
|
60
|
+
*/
|
|
61
|
+
getOffsetHeight() {
|
|
62
|
+
return this.offsetHeight;
|
|
30
63
|
}
|
|
31
64
|
clearFrustum() {
|
|
32
65
|
this.frustumPrimitives.forEach((e) => {
|
|
@@ -37,7 +70,7 @@ class m {
|
|
|
37
70
|
drawFrustum(e = {}) {
|
|
38
71
|
try {
|
|
39
72
|
this.clearFrustum();
|
|
40
|
-
const t = Math.max(1, Math.min(179, e.fov || 60)), i = Math.max(0.1, e.aspectRatio || 1),
|
|
73
|
+
const t = Math.max(1, Math.min(179, e.fov || 60)), i = Math.max(0.1, e.aspectRatio || 1), s = Math.max(0.1, e.near || 1), o = Math.max(s + 1, e.far || 1e3), a = e.position || this.viewer.camera.positionWC, r = e.orientation || n.Quaternion.fromRotationMatrix(
|
|
41
74
|
n.Matrix4.getRotation(
|
|
42
75
|
this.viewer.camera.transform,
|
|
43
76
|
new n.Matrix3()
|
|
@@ -45,30 +78,30 @@ class m {
|
|
|
45
78
|
), l = new n.PerspectiveFrustum({
|
|
46
79
|
fov: n.Math.toRadians(t),
|
|
47
80
|
aspectRatio: i,
|
|
48
|
-
near:
|
|
49
|
-
far:
|
|
81
|
+
near: s,
|
|
82
|
+
far: o
|
|
50
83
|
}), c = new n.FrustumGeometry({
|
|
51
84
|
frustum: l,
|
|
52
|
-
origin:
|
|
53
|
-
orientation:
|
|
85
|
+
origin: a,
|
|
86
|
+
orientation: r,
|
|
54
87
|
vertexFormat: n.VertexFormat.POSITION_ONLY
|
|
55
|
-
}),
|
|
88
|
+
}), h = new n.GeometryInstance({
|
|
56
89
|
geometry: c,
|
|
57
90
|
attributes: {
|
|
58
91
|
color: n.ColorGeometryInstanceAttribute.fromColor(
|
|
59
92
|
e.fillColor || new n.Color(1, 0, 0, 0.3)
|
|
60
93
|
)
|
|
61
94
|
}
|
|
62
|
-
}),
|
|
63
|
-
geometryInstances:
|
|
95
|
+
}), d = new n.Primitive({
|
|
96
|
+
geometryInstances: h,
|
|
64
97
|
appearance: new n.PerInstanceColorAppearance({
|
|
65
98
|
closed: !0,
|
|
66
99
|
flat: !0
|
|
67
100
|
})
|
|
68
101
|
}), g = new n.FrustumOutlineGeometry({
|
|
69
102
|
frustum: l,
|
|
70
|
-
origin:
|
|
71
|
-
orientation:
|
|
103
|
+
origin: a,
|
|
104
|
+
orientation: r
|
|
72
105
|
}), f = new n.GeometryInstance({
|
|
73
106
|
geometry: g,
|
|
74
107
|
attributes: {
|
|
@@ -83,8 +116,8 @@ class m {
|
|
|
83
116
|
flat: !0
|
|
84
117
|
})
|
|
85
118
|
});
|
|
86
|
-
this.viewer.scene.primitives.add(
|
|
87
|
-
|
|
119
|
+
this.viewer.scene.primitives.add(d), this.viewer.scene.primitives.add(p), this.frustumPrimitives.push(d, p), e.onRightClick && this.screenSpaceEventHandler && this.screenSpaceEventHandler.setInputAction((E) => {
|
|
120
|
+
E.position && e.onRightClick && e.onRightClick(a);
|
|
88
121
|
}, n.ScreenSpaceEventType.RIGHT_CLICK);
|
|
89
122
|
} catch (t) {
|
|
90
123
|
console.error("绘制视锥体时发生错误:", t), this.clearFrustum();
|
|
@@ -124,6 +157,10 @@ class m {
|
|
|
124
157
|
), this.screenSpaceEventHandler.setInputAction(
|
|
125
158
|
(t) => {
|
|
126
159
|
if (!this.isDrawing) return;
|
|
160
|
+
if (this._doubleClickPending) {
|
|
161
|
+
this._doubleClickPending = !1;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
127
164
|
const i = this.pickGlobePosition(t.position);
|
|
128
165
|
i && this.addPoint(i);
|
|
129
166
|
},
|
|
@@ -145,7 +182,7 @@ class m {
|
|
|
145
182
|
n.ScreenSpaceEventType.LEFT_DOUBLE_CLICK
|
|
146
183
|
), this.screenSpaceEventHandler.setInputAction(
|
|
147
184
|
(t) => {
|
|
148
|
-
this.isDrawing && (this.finishDrawing(), this.viewer.cesiumWidget.screenSpaceEventHandler.setInputAction(
|
|
185
|
+
this.isDrawing && (this._doubleClickPending = !0, this.finishDrawing(), e && this.viewer.cesiumWidget.screenSpaceEventHandler.setInputAction(
|
|
149
186
|
e,
|
|
150
187
|
n.ScreenSpaceEventType.LEFT_DOUBLE_CLICK
|
|
151
188
|
));
|
|
@@ -161,9 +198,9 @@ class m {
|
|
|
161
198
|
pickGlobePosition(e) {
|
|
162
199
|
const t = this.viewer.camera.getPickRay(e);
|
|
163
200
|
if (t) {
|
|
164
|
-
const
|
|
165
|
-
if (n.defined(
|
|
166
|
-
return
|
|
201
|
+
const s = this.scene.globe.pick(t, this.scene);
|
|
202
|
+
if (n.defined(s))
|
|
203
|
+
return s;
|
|
167
204
|
}
|
|
168
205
|
return this.viewer.camera.pickEllipsoid(
|
|
169
206
|
e,
|
|
@@ -176,29 +213,56 @@ class m {
|
|
|
176
213
|
*/
|
|
177
214
|
addPoint(e) {
|
|
178
215
|
this.tempPositions.push(e.clone());
|
|
179
|
-
const t =
|
|
180
|
-
|
|
216
|
+
const t = n.Cartographic.fromCartesian(e), i = n.Cartesian3.fromRadians(
|
|
217
|
+
t.longitude,
|
|
218
|
+
t.latitude,
|
|
219
|
+
(t.height || 0) + (this.drawMode !== "line" ? 0 : this.offsetHeight)
|
|
220
|
+
), s = this.entities.add({
|
|
221
|
+
position: i,
|
|
181
222
|
point: {
|
|
182
|
-
pixelSize:
|
|
223
|
+
pixelSize: 8,
|
|
183
224
|
color: n.Color.RED,
|
|
184
225
|
outlineColor: n.Color.WHITE,
|
|
185
|
-
outlineWidth:
|
|
186
|
-
heightReference: n.HeightReference.
|
|
226
|
+
outlineWidth: 3,
|
|
227
|
+
heightReference: n.HeightReference.RELATIVE_TO_GROUND,
|
|
228
|
+
scaleByDistance: new n.NearFarScalar(150, 1, 15e6, 0.5)
|
|
187
229
|
}
|
|
188
230
|
});
|
|
189
|
-
this.tempEntities.push(
|
|
231
|
+
this.tempEntities.push(s), this.updateDrawingEntity();
|
|
190
232
|
}
|
|
191
233
|
/**
|
|
192
234
|
* 删除最后一个添加的点及其相关的临时实体
|
|
193
235
|
*/
|
|
194
236
|
removeLastPoint() {
|
|
195
|
-
|
|
196
|
-
this.tempPositions.pop();
|
|
197
|
-
const e = this.tempEntities.pop();
|
|
237
|
+
this.tempPositions.length > 0 && (this.tempPositions.pop(), this.tempEntities.forEach((e) => {
|
|
198
238
|
e && this.entities.remove(e);
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
239
|
+
}), this.tempEntities = [], this.tempLabelEntities.forEach((e) => {
|
|
240
|
+
e && this.entities.remove(e);
|
|
241
|
+
}), this.tempLabelEntities = [], this.recreateRemainingEntities());
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* 重新创建剩余的点实体和绘制实体
|
|
245
|
+
* 用于右键删除点后的重建
|
|
246
|
+
*/
|
|
247
|
+
recreateRemainingEntities() {
|
|
248
|
+
this.tempPositions.forEach((e) => {
|
|
249
|
+
const t = n.Cartographic.fromCartesian(e), i = n.Cartesian3.fromRadians(
|
|
250
|
+
t.longitude,
|
|
251
|
+
t.latitude,
|
|
252
|
+
(t.height || 0) + this.offsetHeight
|
|
253
|
+
), s = this.entities.add({
|
|
254
|
+
position: i,
|
|
255
|
+
point: {
|
|
256
|
+
pixelSize: 8,
|
|
257
|
+
color: n.Color.RED,
|
|
258
|
+
outlineColor: n.Color.WHITE,
|
|
259
|
+
outlineWidth: 3,
|
|
260
|
+
heightReference: n.HeightReference.RELATIVE_TO_GROUND,
|
|
261
|
+
scaleByDistance: new n.NearFarScalar(150, 1, 15e6, 0.5)
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
this.tempEntities.push(s);
|
|
265
|
+
}), this.updateDrawingEntity();
|
|
202
266
|
}
|
|
203
267
|
/**
|
|
204
268
|
* 更新预览线/面
|
|
@@ -212,79 +276,160 @@ class m {
|
|
|
212
276
|
* @param previewPoint 可选的预览点,用于显示动态效果
|
|
213
277
|
*/
|
|
214
278
|
updateDrawingEntity(e) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
279
|
+
const t = [];
|
|
280
|
+
this.tempEntities.forEach((o) => {
|
|
281
|
+
o && (o.polyline || o.polygon || o.rectangle) && t.push(o);
|
|
282
|
+
}), t.forEach((o) => {
|
|
283
|
+
this.entities.remove(o);
|
|
284
|
+
const a = this.tempEntities.indexOf(o);
|
|
285
|
+
a > -1 && this.tempEntities.splice(a, 1);
|
|
286
|
+
}), this.tempLabelEntities.forEach((o) => {
|
|
287
|
+
o && this.entities.remove(o);
|
|
288
|
+
}), this.tempLabelEntities = [];
|
|
289
|
+
const i = [...this.tempPositions];
|
|
290
|
+
if (e && i.push(e), i.length < 2) return;
|
|
291
|
+
let s;
|
|
221
292
|
if (this.drawMode === "line") {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
293
|
+
if (this.offsetHeight > 0) {
|
|
294
|
+
const o = i.map((a) => {
|
|
295
|
+
const r = n.Cartographic.fromCartesian(a);
|
|
296
|
+
return n.Cartesian3.fromRadians(
|
|
297
|
+
r.longitude,
|
|
298
|
+
r.latitude,
|
|
299
|
+
(r.height || 0) + this.offsetHeight
|
|
300
|
+
);
|
|
301
|
+
});
|
|
302
|
+
s = this.entities.add({
|
|
303
|
+
polyline: {
|
|
304
|
+
positions: o,
|
|
305
|
+
width: 5,
|
|
306
|
+
material: n.Color.YELLOW,
|
|
307
|
+
clampToGround: !1
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
} else
|
|
311
|
+
s = this.entities.add({
|
|
312
|
+
polyline: {
|
|
313
|
+
positions: i,
|
|
314
|
+
width: 5,
|
|
315
|
+
material: n.Color.YELLOW,
|
|
316
|
+
clampToGround: !0
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
this.tempEntities.push(s);
|
|
320
|
+
for (let o = 0; o < i.length - 1; o++) {
|
|
321
|
+
const a = i[o], r = i[o + 1], l = n.Cartesian3.distance(a, r);
|
|
322
|
+
if (l > 5) {
|
|
323
|
+
const c = n.Cartesian3.midpoint(
|
|
324
|
+
a,
|
|
325
|
+
r,
|
|
326
|
+
new n.Cartesian3()
|
|
327
|
+
), h = o % 2 === 0 ? -25 : 25, d = this.entities.add({
|
|
328
|
+
position: c,
|
|
329
|
+
label: {
|
|
330
|
+
text: `${l.toFixed(2)} m`,
|
|
331
|
+
font: "16px Arial",
|
|
332
|
+
fillColor: n.Color.WHITE,
|
|
333
|
+
outlineColor: n.Color.BLACK,
|
|
334
|
+
outlineWidth: 3,
|
|
335
|
+
style: n.LabelStyle.FILL_AND_OUTLINE,
|
|
336
|
+
pixelOffset: new n.Cartesian2(0, h),
|
|
337
|
+
heightReference: this.offsetHeight > 0 ? n.HeightReference.RELATIVE_TO_GROUND : n.HeightReference.CLAMP_TO_GROUND,
|
|
338
|
+
scale: 1,
|
|
339
|
+
showBackground: !0,
|
|
340
|
+
backgroundColor: n.Color.BLACK.withAlpha(0.8),
|
|
341
|
+
backgroundPadding: new n.Cartesian2(6, 3)
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
this.tempLabelEntities.push(d);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (i.length > 1) {
|
|
348
|
+
let o = 0;
|
|
349
|
+
for (let l = 1; l < i.length; l++)
|
|
350
|
+
o += n.Cartesian3.distance(
|
|
351
|
+
i[l - 1],
|
|
352
|
+
i[l]
|
|
353
|
+
);
|
|
354
|
+
let a = i[i.length - 1];
|
|
355
|
+
if (this.offsetHeight > 0) {
|
|
356
|
+
const l = n.Cartographic.fromCartesian(a);
|
|
357
|
+
a = n.Cartesian3.fromRadians(
|
|
358
|
+
l.longitude,
|
|
359
|
+
l.latitude,
|
|
360
|
+
(l.height || 0) + this.offsetHeight
|
|
361
|
+
);
|
|
228
362
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const s = t[r], o = t[r + 1], a = n.Cartesian3.distance(s, o), l = n.Cartesian3.midpoint(s, o, new n.Cartesian3()), c = this.entities.add({
|
|
232
|
-
position: l,
|
|
363
|
+
const r = this.entities.add({
|
|
364
|
+
position: a,
|
|
233
365
|
label: {
|
|
234
|
-
text:
|
|
235
|
-
font: "
|
|
236
|
-
fillColor: n.Color.
|
|
366
|
+
text: `总长: ${o.toFixed(2)} m`,
|
|
367
|
+
font: "18px Arial",
|
|
368
|
+
fillColor: n.Color.YELLOW,
|
|
237
369
|
outlineColor: n.Color.BLACK,
|
|
238
|
-
outlineWidth:
|
|
370
|
+
outlineWidth: 3,
|
|
239
371
|
style: n.LabelStyle.FILL_AND_OUTLINE,
|
|
240
|
-
pixelOffset: new n.Cartesian2(0,
|
|
241
|
-
heightReference: n.HeightReference.CLAMP_TO_GROUND
|
|
372
|
+
pixelOffset: new n.Cartesian2(0, 40),
|
|
373
|
+
heightReference: this.offsetHeight > 0 ? n.HeightReference.NONE : n.HeightReference.CLAMP_TO_GROUND,
|
|
374
|
+
scale: 1,
|
|
375
|
+
showBackground: !0,
|
|
376
|
+
backgroundColor: n.Color.BLACK.withAlpha(0.9),
|
|
377
|
+
backgroundPadding: new n.Cartesian2(8, 4)
|
|
242
378
|
}
|
|
243
379
|
});
|
|
244
|
-
this.
|
|
380
|
+
this.tempLabelEntities.push(r);
|
|
245
381
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
r
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
382
|
+
} else if (this.drawMode === "polygon")
|
|
383
|
+
if (this.offsetHeight > 0) {
|
|
384
|
+
const o = i.map((a) => {
|
|
385
|
+
const r = n.Cartographic.fromCartesian(a);
|
|
386
|
+
return n.Cartesian3.fromRadians(
|
|
387
|
+
r.longitude,
|
|
388
|
+
r.latitude,
|
|
389
|
+
(r.height || 0) + this.offsetHeight
|
|
390
|
+
);
|
|
391
|
+
});
|
|
392
|
+
s = this.entities.add({
|
|
393
|
+
polygon: {
|
|
394
|
+
hierarchy: new n.CallbackProperty(() => new n.PolygonHierarchy(o), !1),
|
|
395
|
+
material: n.Color.LIGHTGREEN.withAlpha(0.3),
|
|
396
|
+
// 淡绿色填充
|
|
397
|
+
outline: !0,
|
|
398
|
+
outlineColor: n.Color.GREEN,
|
|
399
|
+
outlineWidth: 2,
|
|
400
|
+
heightReference: n.HeightReference.NONE
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
} else
|
|
404
|
+
s = this.entities.add({
|
|
405
|
+
polygon: {
|
|
406
|
+
hierarchy: new n.CallbackProperty(() => new n.PolygonHierarchy(i), !1),
|
|
407
|
+
material: n.Color.LIGHTGREEN.withAlpha(0.3),
|
|
408
|
+
// 淡绿色填充
|
|
409
|
+
outline: !0,
|
|
410
|
+
outlineColor: n.Color.GREEN,
|
|
257
411
|
outlineWidth: 2,
|
|
258
|
-
style: n.LabelStyle.FILL_AND_OUTLINE,
|
|
259
|
-
pixelOffset: new n.Cartesian2(0, 20),
|
|
260
412
|
heightReference: n.HeightReference.CLAMP_TO_GROUND
|
|
261
413
|
}
|
|
262
414
|
});
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
outline: !0,
|
|
272
|
-
outlineColor: n.Color.GREEN,
|
|
273
|
-
outlineWidth: 2,
|
|
274
|
-
heightReference: n.HeightReference.CLAMP_TO_GROUND
|
|
415
|
+
else if (this.drawMode === "rectangle" && i.length >= 2) {
|
|
416
|
+
const o = this.calculateRectangle(i[0], i[1]);
|
|
417
|
+
this.offsetHeight > 0 ? s = this.entities.add({
|
|
418
|
+
rectangle: {
|
|
419
|
+
coordinates: o,
|
|
420
|
+
material: n.Color.GREEN.withAlpha(0.5),
|
|
421
|
+
heightReference: n.HeightReference.NONE,
|
|
422
|
+
extrudedHeight: this.offsetHeight
|
|
275
423
|
}
|
|
276
|
-
})
|
|
277
|
-
else if (this.drawMode === "rectangle" && t.length >= 2) {
|
|
278
|
-
const r = this.calculateRectangle(t[0], t[1]);
|
|
279
|
-
i = this.entities.add({
|
|
424
|
+
}) : s = this.entities.add({
|
|
280
425
|
rectangle: {
|
|
281
|
-
coordinates:
|
|
426
|
+
coordinates: o,
|
|
282
427
|
material: n.Color.GREEN.withAlpha(0.5),
|
|
283
428
|
heightReference: n.HeightReference.CLAMP_TO_GROUND
|
|
284
429
|
}
|
|
285
430
|
});
|
|
286
431
|
}
|
|
287
|
-
|
|
432
|
+
s && this.tempEntities.push(s);
|
|
288
433
|
}
|
|
289
434
|
/**
|
|
290
435
|
* 完成当前绘制操作
|
|
@@ -296,68 +441,74 @@ class m {
|
|
|
296
441
|
}
|
|
297
442
|
let e = null;
|
|
298
443
|
const t = this.tempPositions.map((i) => i.clone());
|
|
299
|
-
if (this.drawMode === "line")
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
fillColor: n.Color.CYAN,
|
|
317
|
-
outlineColor: n.Color.BLACK,
|
|
318
|
-
outlineWidth: 1,
|
|
319
|
-
style: n.LabelStyle.FILL_AND_OUTLINE,
|
|
320
|
-
pixelOffset: new n.Cartesian2(0, -10),
|
|
321
|
-
heightReference: n.HeightReference.CLAMP_TO_GROUND
|
|
444
|
+
if (this.drawMode === "line")
|
|
445
|
+
if (this.offsetHeight > 0) {
|
|
446
|
+
const i = t.map((s) => {
|
|
447
|
+
const o = n.Cartographic.fromCartesian(s);
|
|
448
|
+
return n.Cartesian3.fromRadians(
|
|
449
|
+
o.longitude,
|
|
450
|
+
o.latitude,
|
|
451
|
+
(o.height || 0) + this.offsetHeight
|
|
452
|
+
);
|
|
453
|
+
});
|
|
454
|
+
e = this.entities.add({
|
|
455
|
+
name: "绘制的线",
|
|
456
|
+
polyline: {
|
|
457
|
+
positions: i,
|
|
458
|
+
width: 5,
|
|
459
|
+
material: n.Color.YELLOW,
|
|
460
|
+
clampToGround: !1
|
|
322
461
|
}
|
|
323
462
|
});
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
463
|
+
} else
|
|
464
|
+
e = this.entities.add({
|
|
465
|
+
name: "绘制的线",
|
|
466
|
+
polyline: {
|
|
467
|
+
positions: t,
|
|
468
|
+
width: 5,
|
|
469
|
+
material: n.Color.YELLOW,
|
|
470
|
+
clampToGround: !0
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
else if (this.drawMode === "polygon") {
|
|
474
|
+
if (this.offsetHeight > 0) {
|
|
475
|
+
const s = t.map((o) => {
|
|
476
|
+
const a = n.Cartographic.fromCartesian(o);
|
|
477
|
+
return n.Cartesian3.fromRadians(
|
|
478
|
+
a.longitude,
|
|
479
|
+
a.latitude,
|
|
480
|
+
(a.height || 0) + this.offsetHeight
|
|
481
|
+
);
|
|
482
|
+
});
|
|
483
|
+
e = this.entities.add({
|
|
484
|
+
name: "绘制的多边形区域",
|
|
485
|
+
polygon: {
|
|
486
|
+
hierarchy: new n.PolygonHierarchy(s),
|
|
487
|
+
material: n.Color.LIGHTGREEN.withAlpha(0.3),
|
|
488
|
+
// 淡绿色填充
|
|
489
|
+
outline: !0,
|
|
490
|
+
outlineColor: n.Color.GREEN,
|
|
491
|
+
outlineWidth: 2,
|
|
492
|
+
heightReference: n.HeightReference.NONE
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
} else
|
|
496
|
+
e = this.entities.add({
|
|
497
|
+
name: "绘制的多边形区域",
|
|
498
|
+
polygon: {
|
|
499
|
+
hierarchy: new n.PolygonHierarchy(t),
|
|
500
|
+
material: n.Color.LIGHTGREEN.withAlpha(0.3),
|
|
501
|
+
// 淡绿色填充
|
|
502
|
+
outline: !0,
|
|
503
|
+
outlineColor: n.Color.GREEN,
|
|
336
504
|
outlineWidth: 2,
|
|
337
|
-
style: n.LabelStyle.FILL_AND_OUTLINE,
|
|
338
|
-
pixelOffset: new n.Cartesian2(0, 20),
|
|
339
505
|
heightReference: n.HeightReference.CLAMP_TO_GROUND
|
|
340
506
|
}
|
|
341
507
|
});
|
|
342
|
-
}
|
|
343
|
-
} else if (this.drawMode === "polygon") {
|
|
344
|
-
e = this.entities.add({
|
|
345
|
-
name: "绘制的多边形区域",
|
|
346
|
-
polygon: {
|
|
347
|
-
hierarchy: new n.PolygonHierarchy(t),
|
|
348
|
-
material: n.Color.LIGHTGREEN.withAlpha(0.3),
|
|
349
|
-
// 淡绿色填充
|
|
350
|
-
outline: !0,
|
|
351
|
-
outlineColor: n.Color.GREEN,
|
|
352
|
-
outlineWidth: 2,
|
|
353
|
-
heightReference: n.HeightReference.CLAMP_TO_GROUND
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
508
|
const i = this.calculatePolygonArea(t);
|
|
357
509
|
if (i > 0) {
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
position: r,
|
|
510
|
+
const s = this.calculatePolygonCenter(t), o = this.entities.add({
|
|
511
|
+
position: s,
|
|
361
512
|
label: {
|
|
362
513
|
text: `面积: ${i.toFixed(2)} km²`,
|
|
363
514
|
font: "14px sans-serif",
|
|
@@ -369,10 +520,19 @@ class m {
|
|
|
369
520
|
heightReference: n.HeightReference.CLAMP_TO_GROUND
|
|
370
521
|
}
|
|
371
522
|
});
|
|
523
|
+
this.finishedLabelEntities.push(o);
|
|
372
524
|
}
|
|
373
525
|
} else if (this.drawMode === "rectangle" && t.length >= 2) {
|
|
374
526
|
const i = this.calculateRectangle(t[0], t[1]);
|
|
375
|
-
e = this.entities.add({
|
|
527
|
+
this.offsetHeight > 0 ? e = this.entities.add({
|
|
528
|
+
name: "绘制的矩形",
|
|
529
|
+
rectangle: {
|
|
530
|
+
coordinates: i,
|
|
531
|
+
material: n.Color.GREEN.withAlpha(0.5),
|
|
532
|
+
heightReference: n.HeightReference.NONE,
|
|
533
|
+
extrudedHeight: this.offsetHeight
|
|
534
|
+
}
|
|
535
|
+
}) : e = this.entities.add({
|
|
376
536
|
name: "绘制的矩形",
|
|
377
537
|
rectangle: {
|
|
378
538
|
coordinates: i,
|
|
@@ -380,16 +540,15 @@ class m {
|
|
|
380
540
|
heightReference: n.HeightReference.CLAMP_TO_GROUND
|
|
381
541
|
}
|
|
382
542
|
});
|
|
383
|
-
const
|
|
384
|
-
if (
|
|
385
|
-
const
|
|
386
|
-
this.entities.add({
|
|
543
|
+
const s = this.calculateRectangleArea(i);
|
|
544
|
+
if (s > 0) {
|
|
545
|
+
const o = n.Rectangle.center(i), a = this.entities.add({
|
|
387
546
|
position: n.Cartesian3.fromRadians(
|
|
388
|
-
|
|
389
|
-
|
|
547
|
+
o.longitude,
|
|
548
|
+
o.latitude
|
|
390
549
|
),
|
|
391
550
|
label: {
|
|
392
|
-
text: `面积: ${
|
|
551
|
+
text: `面积: ${s.toFixed(2)} km²`,
|
|
393
552
|
font: "14px sans-serif",
|
|
394
553
|
fillColor: n.Color.WHITE,
|
|
395
554
|
outlineColor: n.Color.BLACK,
|
|
@@ -399,9 +558,14 @@ class m {
|
|
|
399
558
|
heightReference: n.HeightReference.CLAMP_TO_GROUND
|
|
400
559
|
}
|
|
401
560
|
});
|
|
561
|
+
this.finishedLabelEntities.push(a);
|
|
402
562
|
}
|
|
403
563
|
}
|
|
404
|
-
e && this.finishedEntities.push(e), this.
|
|
564
|
+
e && this.finishedEntities.push(e), this.tempLabelEntities.forEach((i) => {
|
|
565
|
+
this.finishedLabelEntities.push(i);
|
|
566
|
+
}), this.tempLabelEntities = [], this.tempEntities.forEach((i) => {
|
|
567
|
+
i && i.point ? this.finishedPointEntities.push(i) : this.entities.remove(i);
|
|
568
|
+
}), this.tempEntities = [], this.tempPositions = [], this.drawMode = null, this.isDrawing = !1, this.deactivateDrawingHandlers(), this.onDrawEndCallback && this.onDrawEndCallback(e);
|
|
405
569
|
}
|
|
406
570
|
/**
|
|
407
571
|
* 内部方法:重置绘图状态和清理临时数据
|
|
@@ -410,7 +574,9 @@ class m {
|
|
|
410
574
|
endDrawingInternal(e) {
|
|
411
575
|
this.tempEntities.forEach((t) => {
|
|
412
576
|
this.entities.remove(t);
|
|
413
|
-
}), this.tempEntities = [], this.tempPositions = [],
|
|
577
|
+
}), this.tempEntities = [], this.tempPositions = [], this.tempLabelEntities.forEach((t) => {
|
|
578
|
+
this.entities.remove(t);
|
|
579
|
+
}), this.tempLabelEntities = [], e && (this.drawMode = null, this.isDrawing = !1, this.deactivateDrawingHandlers());
|
|
414
580
|
}
|
|
415
581
|
/**
|
|
416
582
|
* 公共方法:结束当前绘制(如果正在进行)
|
|
@@ -428,9 +594,40 @@ class m {
|
|
|
428
594
|
* 清除所有已绘制的实体
|
|
429
595
|
*/
|
|
430
596
|
clearAll() {
|
|
431
|
-
this.endDrawing(), this.finishedEntities.forEach((e) => {
|
|
597
|
+
this.endDrawing(), this.clearAllPoints(), this.finishedEntities.forEach((e) => {
|
|
432
598
|
this.entities.remove(e);
|
|
433
|
-
}), this.finishedEntities = []
|
|
599
|
+
}), this.finishedEntities = [], this.finishedLabelEntities.forEach((e) => {
|
|
600
|
+
e && this.entities.remove(e);
|
|
601
|
+
}), this.finishedLabelEntities = [], this.publicEntities.forEach((e) => {
|
|
602
|
+
e && this.entities.remove(e);
|
|
603
|
+
}), this.publicEntities = [], this.tempEntities.forEach((e) => {
|
|
604
|
+
e && this.entities.remove(e);
|
|
605
|
+
}), this.tempEntities = [], this.tempLabelEntities.forEach((e) => {
|
|
606
|
+
e && e.label && this.entities.remove(e);
|
|
607
|
+
}), this.tempLabelEntities = [], this.tempPositions = [];
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* 清除所有实体(包括未跟踪的实体)
|
|
611
|
+
* 这是一个更彻底的清理方法,会清除场景中的所有实体
|
|
612
|
+
*/
|
|
613
|
+
clearAllEntities() {
|
|
614
|
+
this.endDrawing(), this.entities.removeAll(), this.finishedEntities = [], this.finishedLabelEntities = [], this.finishedPointEntities = [], this.publicEntities = [], this.tempEntities = [], this.tempLabelEntities = [], this.tempPositions = [];
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* 强制清除所有点实体
|
|
618
|
+
* 用于解决点实体无法删除的问题
|
|
619
|
+
*/
|
|
620
|
+
clearAllPoints() {
|
|
621
|
+
this.finishedPointEntities.forEach((t) => {
|
|
622
|
+
t && this.entities.remove(t);
|
|
623
|
+
}), this.finishedPointEntities = [], this.tempEntities.forEach((t) => {
|
|
624
|
+
t && t.point && this.entities.remove(t);
|
|
625
|
+
});
|
|
626
|
+
const e = this.entities.values;
|
|
627
|
+
for (let t = e.length - 1; t >= 0; t--) {
|
|
628
|
+
const i = e[t];
|
|
629
|
+
i && i.point && this.entities.remove(i);
|
|
630
|
+
}
|
|
434
631
|
}
|
|
435
632
|
/**
|
|
436
633
|
* 删除一个指定的已完成实体
|
|
@@ -449,39 +646,39 @@ class m {
|
|
|
449
646
|
}
|
|
450
647
|
// --- 辅助计算函数 ---
|
|
451
648
|
calculateRectangle(e, t) {
|
|
452
|
-
const i = n.Cartographic.fromCartesian(e),
|
|
453
|
-
return new n.Rectangle(
|
|
649
|
+
const i = n.Cartographic.fromCartesian(e), s = n.Cartographic.fromCartesian(t), o = Math.min(i.longitude, s.longitude), a = Math.max(i.longitude, s.longitude), r = Math.min(i.latitude, s.latitude), l = Math.max(i.latitude, s.latitude);
|
|
650
|
+
return new n.Rectangle(o, r, a, l);
|
|
454
651
|
}
|
|
455
652
|
calculateRectangleArea(e) {
|
|
456
|
-
const t = e.west, i = e.south,
|
|
653
|
+
const t = e.west, i = e.south, s = e.east, o = e.north, a = n.Cartesian3.distance(
|
|
457
654
|
n.Cartesian3.fromRadians(t, i),
|
|
458
|
-
n.Cartesian3.fromRadians(
|
|
459
|
-
),
|
|
655
|
+
n.Cartesian3.fromRadians(s, i)
|
|
656
|
+
), r = n.Cartesian3.distance(
|
|
460
657
|
n.Cartesian3.fromRadians(t, i),
|
|
461
|
-
n.Cartesian3.fromRadians(t,
|
|
658
|
+
n.Cartesian3.fromRadians(t, o)
|
|
462
659
|
);
|
|
463
|
-
return
|
|
660
|
+
return a * r / 1e6;
|
|
464
661
|
}
|
|
465
662
|
calculatePolygonArea(e) {
|
|
466
663
|
if (e.length < 3) return 0;
|
|
467
664
|
const t = this.scene.globe.ellipsoid;
|
|
468
665
|
let i = 0;
|
|
469
|
-
const
|
|
470
|
-
for (let
|
|
471
|
-
const
|
|
472
|
-
i += (
|
|
666
|
+
const s = e.length;
|
|
667
|
+
for (let o = 0; o < s; o++) {
|
|
668
|
+
const a = t.cartesianToCartographic(e[o]), r = t.cartesianToCartographic(e[(o + 1) % s]);
|
|
669
|
+
i += (r.longitude - a.longitude) * (2 + Math.sin(a.latitude) + Math.sin(r.latitude));
|
|
473
670
|
}
|
|
474
671
|
return i = Math.abs(i * 6378137 * 6378137 / 2), i / 1e6;
|
|
475
672
|
}
|
|
476
673
|
calculatePolygonCenter(e) {
|
|
477
674
|
if (e.length === 0) return n.Cartesian3.ZERO;
|
|
478
|
-
let t = 0, i = 0,
|
|
479
|
-
for (let
|
|
480
|
-
t += e[
|
|
675
|
+
let t = 0, i = 0, s = 0;
|
|
676
|
+
for (let o = 0; o < e.length; o++)
|
|
677
|
+
t += e[o].x, i += e[o].y, s += e[o].z;
|
|
481
678
|
return new n.Cartesian3(
|
|
482
679
|
t / e.length,
|
|
483
680
|
i / e.length,
|
|
484
|
-
|
|
681
|
+
s / e.length
|
|
485
682
|
);
|
|
486
683
|
}
|
|
487
684
|
// --- 回调注册 ---
|
|
@@ -514,21 +711,21 @@ class m {
|
|
|
514
711
|
* @param radius 监控范围半径(米)
|
|
515
712
|
* @param options 可选配置
|
|
516
713
|
*/
|
|
517
|
-
drawMonitoringCircle(e, t, i,
|
|
518
|
-
const
|
|
519
|
-
return this.entities.add({
|
|
714
|
+
drawMonitoringCircle(e, t, i, s, o) {
|
|
715
|
+
const a = o?.borderColor || "#0062FF", r = o?.fillColor || "#0062FF", l = o?.borderWidth || 2, c = o?.name || "监控区域", h = this.entities.add({
|
|
520
716
|
name: c,
|
|
521
717
|
position: n.Cartesian3.fromDegrees(e, t, i),
|
|
522
718
|
ellipse: {
|
|
523
|
-
semiMajorAxis:
|
|
524
|
-
semiMinorAxis:
|
|
525
|
-
material: n.Color.fromCssColorString(
|
|
719
|
+
semiMajorAxis: s,
|
|
720
|
+
semiMinorAxis: s,
|
|
721
|
+
material: n.Color.fromCssColorString(r).withAlpha(0.27),
|
|
526
722
|
outline: !0,
|
|
527
|
-
outlineColor: n.Color.fromCssColorString(
|
|
723
|
+
outlineColor: n.Color.fromCssColorString(a),
|
|
528
724
|
outlineWidth: l,
|
|
529
725
|
heightReference: n.HeightReference.CLAMP_TO_GROUND
|
|
530
726
|
}
|
|
531
727
|
});
|
|
728
|
+
return this.publicEntities.push(h), h;
|
|
532
729
|
}
|
|
533
730
|
/**
|
|
534
731
|
* 绘制垂直线条
|
|
@@ -537,21 +734,29 @@ class m {
|
|
|
537
734
|
* @param height 高度
|
|
538
735
|
* @param options 可选配置
|
|
539
736
|
*/
|
|
540
|
-
drawVerticalLine(e, t, i,
|
|
541
|
-
const
|
|
542
|
-
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
|
|
737
|
+
drawVerticalLine(e, t, i, s) {
|
|
738
|
+
const o = s?.color || "#0062FF", a = s?.width || 2;
|
|
739
|
+
s?.dashPattern;
|
|
740
|
+
const r = s?.name || "垂直线条", l = s?.groundHeight || 0, c = n.Cartesian3.fromDegrees(
|
|
741
|
+
e,
|
|
742
|
+
t,
|
|
743
|
+
l
|
|
744
|
+
), h = n.Cartesian3.fromDegrees(
|
|
745
|
+
e,
|
|
746
|
+
t,
|
|
747
|
+
i
|
|
748
|
+
), d = this.entities.add({
|
|
749
|
+
name: r,
|
|
546
750
|
polyline: {
|
|
547
|
-
positions: [c,
|
|
548
|
-
width:
|
|
751
|
+
positions: [c, h],
|
|
752
|
+
width: a,
|
|
549
753
|
material: new n.PolylineDashMaterialProperty({
|
|
550
|
-
color: n.Color.fromCssColorString(
|
|
754
|
+
color: n.Color.fromCssColorString(o)
|
|
551
755
|
}),
|
|
552
756
|
clampToGround: !1
|
|
553
757
|
}
|
|
554
758
|
});
|
|
759
|
+
return this.publicEntities.push(d), d;
|
|
555
760
|
}
|
|
556
761
|
/**
|
|
557
762
|
* 销毁工具,清理所有事件监听器
|
|
@@ -624,7 +829,7 @@ class v {
|
|
|
624
829
|
})
|
|
625
830
|
}
|
|
626
831
|
];
|
|
627
|
-
constructor(e, t, i = {},
|
|
832
|
+
constructor(e, t, i = {}, s, o) {
|
|
628
833
|
this.viewer = e, this.container = t, this.config = {
|
|
629
834
|
position: "bottom-right",
|
|
630
835
|
buttonSize: 40,
|
|
@@ -635,7 +840,7 @@ class v {
|
|
|
635
840
|
boxShadow: "0 2px 10px rgba(0, 0, 0, 0.1)",
|
|
636
841
|
zIndex: 1e3,
|
|
637
842
|
...i
|
|
638
|
-
}, this.searchCallback =
|
|
843
|
+
}, this.searchCallback = s?.search, this.measurementCallback = s?.measurement, this.zoomCallback = s?.zoom, this.initialCenter = o, this.drawHelper = new m(e), this.setupDrawHelperCallbacks(), this.createToolbar();
|
|
639
844
|
}
|
|
640
845
|
/**
|
|
641
846
|
* 设置初始中心点
|
|
@@ -702,8 +907,8 @@ class v {
|
|
|
702
907
|
const t = e.polyline.positions?.getValue(n.JulianDate.now());
|
|
703
908
|
if (t && this.measurementCallback?.onDistanceComplete) {
|
|
704
909
|
let i = 0;
|
|
705
|
-
for (let
|
|
706
|
-
i += n.Cartesian3.distance(t[
|
|
910
|
+
for (let s = 1; s < t.length; s++)
|
|
911
|
+
i += n.Cartesian3.distance(t[s - 1], t[s]);
|
|
707
912
|
this.measurementCallback.onDistanceComplete(t, i);
|
|
708
913
|
}
|
|
709
914
|
} else if (e.polygon) {
|
|
@@ -725,10 +930,10 @@ class v {
|
|
|
725
930
|
if (e.length < 3) return 0;
|
|
726
931
|
const t = this.viewer.scene.globe.ellipsoid;
|
|
727
932
|
let i = 0;
|
|
728
|
-
const
|
|
729
|
-
for (let
|
|
730
|
-
const
|
|
731
|
-
i += (
|
|
933
|
+
const s = e.length;
|
|
934
|
+
for (let o = 0; o < s; o++) {
|
|
935
|
+
const a = t.cartesianToCartographic(e[o]), r = t.cartesianToCartographic(e[(o + 1) % s]);
|
|
936
|
+
i += (r.longitude - a.longitude) * (2 + Math.sin(a.latitude) + Math.sin(r.latitude));
|
|
732
937
|
}
|
|
733
938
|
return i = Math.abs(i * 6378137 * 6378137 / 2), i / 1e6;
|
|
734
939
|
}
|
|
@@ -784,14 +989,14 @@ class v {
|
|
|
784
989
|
createButton(e) {
|
|
785
990
|
const t = document.createElement("div");
|
|
786
991
|
t.className = "cesium-toolbar-button", t.setAttribute("data-tool", e.id), t.title = e.title;
|
|
787
|
-
const i = e.size || this.config.buttonSize,
|
|
992
|
+
const i = e.size || this.config.buttonSize, s = e.color || "rgba(66, 133, 244, 0.4)", o = e.hoverColor || "rgba(51, 103, 214, 0.9)";
|
|
788
993
|
return t.style.cssText = `
|
|
789
994
|
width: ${i}px;
|
|
790
995
|
height: ${i}px;
|
|
791
996
|
display: flex;
|
|
792
997
|
align-items: center;
|
|
793
998
|
justify-content: center;
|
|
794
|
-
background: ${
|
|
999
|
+
background: ${s};
|
|
795
1000
|
color: white;
|
|
796
1001
|
border: none;
|
|
797
1002
|
border-radius: 4px;
|
|
@@ -802,9 +1007,9 @@ class v {
|
|
|
802
1007
|
user-select: none;
|
|
803
1008
|
position: relative;
|
|
804
1009
|
`, this.setButtonIcon(t, e.icon), t.addEventListener("mouseenter", () => {
|
|
805
|
-
t.style.background =
|
|
1010
|
+
t.style.background = o, t.style.transform = "scale(1.05)";
|
|
806
1011
|
}), t.addEventListener("mouseleave", () => {
|
|
807
|
-
t.style.background =
|
|
1012
|
+
t.style.background = s, t.style.transform = "scale(1)";
|
|
808
1013
|
}), this.setupButtonEvents(t, e), t;
|
|
809
1014
|
}
|
|
810
1015
|
/**
|
|
@@ -817,15 +1022,17 @@ class v {
|
|
|
817
1022
|
* 设置按钮事件
|
|
818
1023
|
*/
|
|
819
1024
|
setupButtonEvents(e, t) {
|
|
820
|
-
const i = this.config.buttons?.find((
|
|
821
|
-
i?.onClick ? e.addEventListener("click", (
|
|
822
|
-
|
|
823
|
-
}) : ["search", "measure", "layers"].includes(t.id) ?
|
|
1025
|
+
const i = this.config.buttons?.find((s) => s.id === t.id);
|
|
1026
|
+
i?.onClick ? e.addEventListener("click", (s) => {
|
|
1027
|
+
s.stopPropagation(), i.onClick(t.id, e);
|
|
1028
|
+
}) : ["search", "measure", "layers"].includes(t.id) ? t.id === "search" ? e.addEventListener("click", (s) => {
|
|
1029
|
+
s.stopPropagation(), this.handleButtonClick(t.id, e);
|
|
1030
|
+
}) : (e.addEventListener("mouseenter", () => {
|
|
824
1031
|
this.handleButtonClick(t.id, e);
|
|
825
1032
|
}), e.addEventListener("mouseleave", () => {
|
|
826
1033
|
this.closeMenuOnButtonLeave(t.id);
|
|
827
|
-
})) : e.addEventListener("click", (
|
|
828
|
-
|
|
1034
|
+
})) : e.addEventListener("click", (s) => {
|
|
1035
|
+
s.stopPropagation(), this.handleButtonClick(t.id, e);
|
|
829
1036
|
});
|
|
830
1037
|
}
|
|
831
1038
|
/**
|
|
@@ -834,17 +1041,13 @@ class v {
|
|
|
834
1041
|
closeMenuOnButtonLeave(e) {
|
|
835
1042
|
setTimeout(() => {
|
|
836
1043
|
switch (e) {
|
|
837
|
-
case "search":
|
|
838
|
-
const t = this.toolbarElement.querySelector(".search-container");
|
|
839
|
-
t && !t.matches(":hover") && t.remove();
|
|
840
|
-
break;
|
|
841
1044
|
case "measure":
|
|
842
|
-
const
|
|
843
|
-
|
|
1045
|
+
const t = this.toolbarElement.querySelector(".measurement-menu");
|
|
1046
|
+
t && !t.matches(":hover") && t.remove();
|
|
844
1047
|
break;
|
|
845
1048
|
case "layers":
|
|
846
|
-
const
|
|
847
|
-
|
|
1049
|
+
const i = this.toolbarElement.querySelector(".layers-menu");
|
|
1050
|
+
i && !i.matches(":hover") && i.remove();
|
|
848
1051
|
break;
|
|
849
1052
|
}
|
|
850
1053
|
}, 100);
|
|
@@ -884,8 +1087,11 @@ class v {
|
|
|
884
1087
|
* 切换搜索功能
|
|
885
1088
|
*/
|
|
886
1089
|
toggleSearch(e) {
|
|
887
|
-
|
|
1090
|
+
const t = this.toolbarElement.querySelector(".search-container");
|
|
1091
|
+
if (t) {
|
|
1092
|
+
t.remove();
|
|
888
1093
|
return;
|
|
1094
|
+
}
|
|
889
1095
|
const i = document.createElement("div");
|
|
890
1096
|
i.className = "search-container", i.style.cssText = `
|
|
891
1097
|
position: absolute;
|
|
@@ -900,48 +1106,52 @@ class v {
|
|
|
900
1106
|
min-width: 200px;
|
|
901
1107
|
z-index: 1001;
|
|
902
1108
|
`;
|
|
903
|
-
const
|
|
904
|
-
|
|
1109
|
+
const s = document.createElement("input");
|
|
1110
|
+
s.type = "text", s.placeholder = "请输入地址", s.style.cssText = `
|
|
905
1111
|
padding: 6px 8px;
|
|
906
1112
|
border: 1px solid #ddd;
|
|
907
1113
|
border-radius: 3px;
|
|
908
1114
|
font-size: 14px;
|
|
909
1115
|
outline: none;
|
|
910
1116
|
`;
|
|
911
|
-
const
|
|
912
|
-
|
|
1117
|
+
const o = document.createElement("div");
|
|
1118
|
+
o.className = "search-results", o.style.cssText = `
|
|
913
1119
|
margin-top: 8px;
|
|
914
1120
|
max-height: 200px;
|
|
915
1121
|
overflow-y: auto;
|
|
916
|
-
`, i.appendChild(
|
|
917
|
-
let
|
|
918
|
-
|
|
919
|
-
clearTimeout(
|
|
920
|
-
const
|
|
1122
|
+
`, i.appendChild(s), i.appendChild(o), this.toolbarElement.insertBefore(i, e);
|
|
1123
|
+
let a;
|
|
1124
|
+
s.addEventListener("input", () => {
|
|
1125
|
+
clearTimeout(a);
|
|
1126
|
+
const c = s.value.trim();
|
|
921
1127
|
if (this.searchCallback?.onSearchInput) {
|
|
922
|
-
this.searchCallback.onSearchInput(
|
|
1128
|
+
this.searchCallback.onSearchInput(c, o);
|
|
923
1129
|
return;
|
|
924
1130
|
}
|
|
925
|
-
if (
|
|
926
|
-
|
|
1131
|
+
if (c.length < 2) {
|
|
1132
|
+
o.innerHTML = "";
|
|
927
1133
|
return;
|
|
928
1134
|
}
|
|
929
|
-
|
|
1135
|
+
a = setTimeout(async () => {
|
|
930
1136
|
if (this.searchCallback?.onSearch)
|
|
931
1137
|
try {
|
|
932
|
-
const
|
|
933
|
-
this.displaySearchResults(
|
|
934
|
-
} catch (
|
|
935
|
-
console.error("搜索失败:",
|
|
1138
|
+
const h = await this.searchCallback.onSearch(c);
|
|
1139
|
+
this.displaySearchResults(h, o);
|
|
1140
|
+
} catch (h) {
|
|
1141
|
+
console.error("搜索失败:", h), o.innerHTML = '<div style="padding: 8px; color: #666;">搜索失败</div>';
|
|
936
1142
|
}
|
|
937
1143
|
else
|
|
938
|
-
this.performDefaultSearch(
|
|
1144
|
+
this.performDefaultSearch(c, o);
|
|
939
1145
|
}, 300);
|
|
940
1146
|
});
|
|
941
|
-
const
|
|
942
|
-
i.remove();
|
|
1147
|
+
const r = (c) => {
|
|
1148
|
+
!i.contains(c.target) && !e.contains(c.target) && (i.remove(), document.removeEventListener("click", r), document.removeEventListener("keydown", l));
|
|
1149
|
+
}, l = (c) => {
|
|
1150
|
+
c.key === "Escape" && (i.remove(), document.removeEventListener("click", r), document.removeEventListener("keydown", l));
|
|
943
1151
|
};
|
|
944
|
-
|
|
1152
|
+
setTimeout(() => {
|
|
1153
|
+
document.addEventListener("click", r), document.addEventListener("keydown", l), s.focus();
|
|
1154
|
+
}, 100);
|
|
945
1155
|
}
|
|
946
1156
|
/**
|
|
947
1157
|
* 显示搜索结果
|
|
@@ -956,22 +1166,22 @@ class v {
|
|
|
956
1166
|
return;
|
|
957
1167
|
}
|
|
958
1168
|
e.forEach((i) => {
|
|
959
|
-
const
|
|
960
|
-
|
|
1169
|
+
const s = document.createElement("div");
|
|
1170
|
+
s.style.cssText = `
|
|
961
1171
|
padding: 8px;
|
|
962
1172
|
border-bottom: 1px solid #f0f0f0;
|
|
963
1173
|
cursor: pointer;
|
|
964
1174
|
transition: background-color 0.2s;
|
|
965
|
-
`,
|
|
1175
|
+
`, s.innerHTML = `
|
|
966
1176
|
<div style="font-weight: bold; margin-bottom: 2px;">${i.name}</div>
|
|
967
1177
|
<div style="font-size: 12px; color: #666;">${i.address}</div>
|
|
968
|
-
`,
|
|
969
|
-
|
|
970
|
-
}),
|
|
971
|
-
|
|
972
|
-
}),
|
|
1178
|
+
`, s.addEventListener("mouseenter", () => {
|
|
1179
|
+
s.style.backgroundColor = "#f5f5f5";
|
|
1180
|
+
}), s.addEventListener("mouseleave", () => {
|
|
1181
|
+
s.style.backgroundColor = "transparent";
|
|
1182
|
+
}), s.addEventListener("click", () => {
|
|
973
1183
|
this.selectSearchResult(i), t.parentElement?.remove();
|
|
974
|
-
}), t.appendChild(
|
|
1184
|
+
}), t.appendChild(s);
|
|
975
1185
|
});
|
|
976
1186
|
}
|
|
977
1187
|
/**
|
|
@@ -1039,27 +1249,27 @@ class v {
|
|
|
1039
1249
|
{ id: "measure-area", text: "测面积", icon: "📐" },
|
|
1040
1250
|
{ id: "measure-distance", text: "测距", icon: "📏" },
|
|
1041
1251
|
{ id: "clear-measurement", text: "清除", icon: "🗑️" }
|
|
1042
|
-
].forEach((
|
|
1043
|
-
const
|
|
1044
|
-
|
|
1252
|
+
].forEach((a) => {
|
|
1253
|
+
const r = document.createElement("div");
|
|
1254
|
+
r.style.cssText = `
|
|
1045
1255
|
padding: 8px 12px;
|
|
1046
1256
|
cursor: pointer;
|
|
1047
1257
|
display: flex;
|
|
1048
1258
|
align-items: center;
|
|
1049
1259
|
gap: 8px;
|
|
1050
1260
|
transition: background-color 0.2s;
|
|
1051
|
-
`,
|
|
1052
|
-
|
|
1053
|
-
}),
|
|
1054
|
-
|
|
1055
|
-
}),
|
|
1056
|
-
this.handleMeasurementAction(
|
|
1057
|
-
}), i.appendChild(
|
|
1261
|
+
`, r.innerHTML = `${a.icon} ${a.text}`, r.addEventListener("mouseenter", () => {
|
|
1262
|
+
r.style.backgroundColor = "#f5f5f5";
|
|
1263
|
+
}), r.addEventListener("mouseleave", () => {
|
|
1264
|
+
r.style.backgroundColor = "transparent";
|
|
1265
|
+
}), r.addEventListener("click", () => {
|
|
1266
|
+
this.handleMeasurementAction(a.id), i.remove();
|
|
1267
|
+
}), i.appendChild(r);
|
|
1058
1268
|
}), this.toolbarElement.insertBefore(i, e);
|
|
1059
|
-
const
|
|
1269
|
+
const o = () => {
|
|
1060
1270
|
i.remove();
|
|
1061
1271
|
};
|
|
1062
|
-
i.addEventListener("mouseleave",
|
|
1272
|
+
i.addEventListener("mouseleave", o);
|
|
1063
1273
|
}
|
|
1064
1274
|
/**
|
|
1065
1275
|
* 处理测量操作
|
|
@@ -1107,14 +1317,14 @@ class v {
|
|
|
1107
1317
|
display: flex;
|
|
1108
1318
|
flex-direction: column;
|
|
1109
1319
|
`;
|
|
1110
|
-
const
|
|
1111
|
-
|
|
1320
|
+
const s = document.createElement("div");
|
|
1321
|
+
s.style.cssText = `
|
|
1112
1322
|
display: flex;
|
|
1113
1323
|
flex-direction: column;
|
|
1114
1324
|
gap: 4px;
|
|
1115
|
-
`,
|
|
1116
|
-
const
|
|
1117
|
-
|
|
1325
|
+
`, s.innerHTML = '<div style="font-weight: bold; margin-bottom: 8px; color: #333; font-size: 14px;">地图类型</div>', this.mapTypes.forEach((a) => {
|
|
1326
|
+
const r = document.createElement("div");
|
|
1327
|
+
r.style.cssText = `
|
|
1118
1328
|
display: flex;
|
|
1119
1329
|
align-items: center;
|
|
1120
1330
|
gap: 8px;
|
|
@@ -1124,39 +1334,39 @@ class v {
|
|
|
1124
1334
|
transition: background-color 0.2s;
|
|
1125
1335
|
width: 100%;
|
|
1126
1336
|
box-sizing: border-box;
|
|
1127
|
-
${
|
|
1337
|
+
${a.id === this.currentMapType ? "background-color: #e3f2fd;" : ""}
|
|
1128
1338
|
`;
|
|
1129
1339
|
const l = document.createElement("img");
|
|
1130
|
-
l.src =
|
|
1340
|
+
l.src = a.thumbnail, l.style.cssText = `
|
|
1131
1341
|
width: 24px;
|
|
1132
1342
|
height: 24px;
|
|
1133
1343
|
border-radius: 3px;
|
|
1134
1344
|
flex-shrink: 0;
|
|
1135
1345
|
`;
|
|
1136
1346
|
const c = document.createElement("span");
|
|
1137
|
-
c.textContent =
|
|
1347
|
+
c.textContent = a.name, c.style.cssText = `
|
|
1138
1348
|
font-size: 14px;
|
|
1139
1349
|
color: #333;
|
|
1140
1350
|
flex: 1;
|
|
1141
1351
|
`;
|
|
1142
|
-
const
|
|
1143
|
-
|
|
1352
|
+
const h = document.createElement("span");
|
|
1353
|
+
a.id === this.currentMapType && (h.textContent = "✓", h.style.cssText = `
|
|
1144
1354
|
color: #1976d2;
|
|
1145
1355
|
font-weight: bold;
|
|
1146
1356
|
font-size: 16px;
|
|
1147
1357
|
flex-shrink: 0;
|
|
1148
|
-
`),
|
|
1149
|
-
|
|
1150
|
-
}),
|
|
1151
|
-
|
|
1152
|
-
}),
|
|
1153
|
-
this.switchMapType(
|
|
1154
|
-
}),
|
|
1155
|
-
}), i.appendChild(
|
|
1156
|
-
const
|
|
1358
|
+
`), r.appendChild(l), r.appendChild(c), r.appendChild(h), r.addEventListener("mouseenter", () => {
|
|
1359
|
+
a.id !== this.currentMapType && (r.style.backgroundColor = "#f5f5f5");
|
|
1360
|
+
}), r.addEventListener("mouseleave", () => {
|
|
1361
|
+
a.id !== this.currentMapType && (r.style.backgroundColor = "transparent");
|
|
1362
|
+
}), r.addEventListener("click", () => {
|
|
1363
|
+
this.switchMapType(a.id), i.remove();
|
|
1364
|
+
}), s.appendChild(r);
|
|
1365
|
+
}), i.appendChild(s), this.toolbarElement.insertBefore(i, e);
|
|
1366
|
+
const o = () => {
|
|
1157
1367
|
i.remove();
|
|
1158
1368
|
};
|
|
1159
|
-
i.addEventListener("mouseleave",
|
|
1369
|
+
i.addEventListener("mouseleave", o);
|
|
1160
1370
|
}
|
|
1161
1371
|
/**
|
|
1162
1372
|
* 切换地图类型
|
|
@@ -1240,9 +1450,9 @@ function x() {
|
|
|
1240
1450
|
credit: "© 高德地图"
|
|
1241
1451
|
});
|
|
1242
1452
|
}
|
|
1243
|
-
async function
|
|
1244
|
-
|
|
1245
|
-
const i = new b(
|
|
1453
|
+
async function L(u, e, t = { longitude: 120.2052342, latitude: 30.2489634, height: 1e3, pitch: -60, heading: 0 }) {
|
|
1454
|
+
C.defaultAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3M2M3NWU1Ni0xZmJkLTRkNjAtOTk4NC0wZDZhNWFiOWJlZDEiLCJpZCI6MzMxNTg1LCJpYXQiOjE3NTUyMjQ2MzB9.WBUG7ctHKtOrnay1ng8JNfaNgngbkNgOmRXP59OJ7ME";
|
|
1455
|
+
const i = new b(u, {
|
|
1246
1456
|
timeline: !1,
|
|
1247
1457
|
animation: !1,
|
|
1248
1458
|
baseLayerPicker: !1,
|
|
@@ -1259,15 +1469,15 @@ async function y(h, e, t = { longitude: 120.2052342, latitude: 30.2489634, heigh
|
|
|
1259
1469
|
}
|
|
1260
1470
|
}), i.cesiumWidget.creditContainer.style.display = "none", { viewer: i, initialCenter: t };
|
|
1261
1471
|
}
|
|
1262
|
-
const
|
|
1472
|
+
const I = {
|
|
1263
1473
|
CesiumMapToolbar: v,
|
|
1264
1474
|
DrawHelper: m,
|
|
1265
|
-
initCesium:
|
|
1475
|
+
initCesium: L
|
|
1266
1476
|
};
|
|
1267
1477
|
export {
|
|
1268
1478
|
v as CesiumMapToolbar,
|
|
1269
1479
|
m as DrawHelper,
|
|
1270
|
-
|
|
1271
|
-
|
|
1480
|
+
I as default,
|
|
1481
|
+
L as initCesium
|
|
1272
1482
|
};
|
|
1273
1483
|
//# sourceMappingURL=index.es.js.map
|