vesium 1.0.1-beta.49 → 1.0.1-beta.51

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.
@@ -1,1519 +1,1610 @@
1
- var Vesium = function(exports, core, cesium, vue) {
2
- "use strict";
3
- const CREATE_VIEWER_INJECTION_KEY = Symbol("CREATE_VIEWER_INJECTION_KEY");
4
- const CREATE_VIEWER_COLLECTION = /* @__PURE__ */ new WeakMap();
5
- function createViewer(...args) {
6
- const viewer = vue.shallowRef();
7
- const readonlyViewer = vue.shallowReadonly(viewer);
8
- vue.provide(CREATE_VIEWER_INJECTION_KEY, readonlyViewer);
9
- const scope = vue.getCurrentScope();
10
- if (scope) {
11
- CREATE_VIEWER_COLLECTION.set(scope, readonlyViewer);
12
- }
13
- const canvas = vue.computed(() => {
14
- var _a;
15
- return (_a = viewer.value) == null ? void 0 : _a.canvas;
16
- });
17
- core.useMutationObserver(document == null ? void 0 : document.body, () => {
18
- if (canvas.value && !(document == null ? void 0 : document.body.contains(canvas.value))) {
19
- viewer.value = void 0;
20
- }
21
- }, {
22
- childList: true,
23
- subtree: true
24
- });
25
- vue.watchEffect((onCleanup) => {
26
- const [arg1, arg2] = args;
27
- const value = vue.toRaw(vue.toValue(arg1));
28
- if (value instanceof cesium.Viewer) {
29
- viewer.value = vue.markRaw(value);
30
- } else if (value) {
31
- const element = value;
32
- const options = arg2;
33
- viewer.value = new cesium.Viewer(element, options);
34
- onCleanup(() => {
35
- var _a, _b;
36
- return !((_a = viewer.value) == null ? void 0 : _a.isDestroyed()) && ((_b = viewer.value) == null ? void 0 : _b.destroy());
37
- });
38
- } else {
39
- viewer.value = void 0;
40
- }
41
- });
42
- core.tryOnScopeDispose(() => {
43
- viewer.value = void 0;
44
- });
45
- return vue.computed(() => {
46
- var _a;
47
- return ((_a = viewer.value) == null ? void 0 : _a.isDestroyed()) ? void 0 : viewer.value;
48
- });
49
- }
50
- function arrayDiff(list, oldList) {
51
- const oldListSet = new Set(oldList);
52
- const added = list.filter((obj) => !oldListSet.has(obj));
53
- const newListSet = new Set(list);
54
- const removed = (oldList == null ? void 0 : oldList.filter((obj) => !newListSet.has(obj))) ?? [];
55
- return { added, removed };
56
- }
57
- function canvasCoordToCartesian(canvasCoord, scene, mode = "auto") {
58
- if (mode === "pickPosition") {
59
- return scene.pickPosition(canvasCoord);
60
- } else if (mode === "globePick") {
61
- const ray = scene.camera.getPickRay(canvasCoord);
62
- return ray && scene.globe.pick(ray, scene);
63
- } else {
64
- if (scene.globe.depthTestAgainstTerrain) {
65
- return scene.pickPosition(canvasCoord);
66
- }
67
- const position1 = scene.pickPosition(canvasCoord);
68
- const ray = scene.camera.getPickRay(canvasCoord);
69
- const position2 = ray && scene.globe.pick(ray, scene);
70
- if (!position1) {
71
- return position2;
72
- }
73
- const height1 = (position1 && cesium.Ellipsoid.WGS84.cartesianToCartographic(position1).height) ?? 0;
74
- const height2 = (position2 && cesium.Ellipsoid.WGS84.cartesianToCartographic(position2).height) ?? 0;
75
- return height1 < height2 ? position1 : position2;
76
- }
77
- }
78
- function cartesianToCanvasCoord(position, scene) {
79
- return scene.cartesianToCanvasCoordinates(position);
80
- }
81
- const toString = Object.prototype.toString;
82
- function isDef(val) {
83
- return typeof val !== "undefined";
84
- }
85
- function isBoolean(val) {
86
- return typeof val === "boolean";
87
- }
88
- function isFunction(val) {
89
- return typeof val === "function";
90
- }
91
- function isNumber(val) {
92
- return typeof val === "number";
93
- }
94
- function isString(val) {
95
- return typeof val === "string";
96
- }
97
- function isObject(val) {
98
- return toString.call(val) === "[object Object]";
99
- }
100
- function isWindow(val) {
101
- return typeof window !== "undefined" && toString.call(val) === "[object Window]";
102
- }
103
- function isPromise(val) {
104
- return !!val && (typeof val === "object" || typeof val === "function") && typeof val.then === "function";
105
- }
106
- function isElement(val) {
107
- return !!(val && val.nodeName && val.nodeType === 1);
108
- }
109
- const isArray = Array.isArray;
110
- function isBase64(val) {
111
- const reg = /^\s*data:([a-z]+\/[\d+.a-z-]+(;[a-z-]+=[\da-z-]+)?)?(;base64)?,([\s\w!$%&'()*+,./:;=?@~-]*?)\s*$/i;
112
- return reg.test(val);
113
- }
114
- function assertError(condition, error) {
115
- if (condition) {
116
- throw new Error(error);
117
- }
118
- }
119
- function cesiumEquals(left, right) {
120
- return left === right || isFunction(left == null ? void 0 : left.equals) && left.equals(right) || isFunction(right == null ? void 0 : right.equals) && right.equals(left);
121
- }
122
- function toCoord(position, options = {}) {
123
- if (!position) {
124
- return void 0;
125
- }
126
- const { type = "Array", alt = false } = options;
127
- let longitude, latitude, height;
128
- if (position instanceof cesium.Cartesian3) {
129
- const cartographic = cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
130
- longitude = cesium.Math.toDegrees(cartographic.longitude);
131
- latitude = cesium.Math.toDegrees(cartographic.latitude);
132
- height = cartographic.height;
133
- } else if (position instanceof cesium.Cartographic) {
134
- const cartographic = position;
135
- longitude = cesium.Math.toDegrees(cartographic.longitude);
136
- latitude = cesium.Math.toDegrees(cartographic.latitude);
137
- height = cartographic.height;
138
- } else if (Array.isArray(position)) {
139
- longitude = cesium.Math.toDegrees(position[0]);
140
- latitude = cesium.Math.toDegrees(position[1]);
141
- height = position[2];
142
- } else {
143
- longitude = position.longitude;
144
- latitude = position.latitude;
145
- height = position.height;
146
- }
147
- if (type === "Array") {
148
- return alt ? [longitude, latitude, height] : [longitude, latitude];
149
- } else {
150
- return alt ? { longitude, latitude, height } : { longitude, latitude };
151
- }
152
- }
153
- function dmsEncode(degrees, precision = 3) {
154
- const str = `${degrees}`;
155
- let i = str.indexOf(".");
156
- const d = i < 0 ? str : str.slice(0, Math.max(0, i));
157
- let m = "0";
158
- let s = "0";
159
- if (i > 0) {
160
- m = `0${str.slice(Math.max(0, i))}`;
161
- m = `${+m * 60}`;
162
- i = m.indexOf(".");
163
- if (i > 0) {
164
- s = `0${m.slice(Math.max(0, i))}`;
165
- m = m.slice(0, Math.max(0, i));
166
- s = `${+s * 60}`;
167
- i = s.indexOf(".");
168
- s = s.slice(0, Math.max(0, i + 4));
169
- s = (+s).toFixed(precision);
170
- }
171
- }
172
- return `${Math.abs(+d)}°${+m}′${+s}″`;
173
- }
174
- function dmsDecode(dmsCode) {
175
- const [dd, msStr] = dmsCode.split("°") ?? [];
176
- const [mm, sStr] = (msStr == null ? void 0 : msStr.split("′")) ?? [];
177
- const ss = sStr == null ? void 0 : sStr.split("″")[0];
178
- const d = Number(dd) || 0;
179
- const m = (Number(mm) || 0) / 60;
180
- const s = (Number(ss) || 0) / 60 / 60;
181
- const degrees = d + m + s;
182
- if (degrees === 0) {
183
- return 0;
184
- } else {
185
- let res = degrees;
186
- if (["W", "w", "S", "s"].includes(dmsCode[dmsCode.length - 1])) {
187
- res = -res;
188
- }
189
- return res;
190
- }
191
- }
192
- function degreesToDms(position, precision = 3) {
193
- const coord = toCoord(position, { alt: true });
194
- if (!coord) {
195
- return;
196
- }
197
- const [longitude, latitude, height] = coord;
198
- const x = dmsEncode(longitude, precision);
199
- const y = dmsEncode(latitude, precision);
200
- return [`${x}${longitude > 0 ? "E" : "W"}`, `${y}${latitude > 0 ? "N" : "S"}`, height];
201
- }
202
- function dmsToDegrees(dms) {
203
- const [x, y, height] = dms;
204
- const longitude = dmsDecode(x);
205
- const latitude = dmsDecode(y);
206
- return [longitude, latitude, Number(height) || 0];
207
- }
208
- function isCesiumConstant(value) {
209
- return !cesium.defined(value) || !!value.isConstant;
210
- }
211
- class CesiumMaterial extends cesium.Material {
212
- constructor(options) {
213
- super(options);
214
- }
215
- }
216
- function getMaterialCache(type) {
217
- return cesium.Material._materialCache.getMaterial(type);
218
- }
219
- function addMaterialCache(type, material) {
220
- return cesium.Material._materialCache.addMaterial(type, material);
221
- }
222
- function resolvePick(pick = {}) {
223
- const { primitive, id, primitiveCollection, collection } = pick;
224
- const entityCollection = id && id.entityCollection || null;
225
- const dataSource = entityCollection && entityCollection.owner || null;
226
- const ids = Array.isArray(id) ? id : [id].filter(Boolean);
227
- return [
228
- ...ids,
229
- primitive,
230
- primitiveCollection,
231
- collection,
232
- entityCollection,
233
- dataSource
234
- ].filter((e) => !!e);
235
- }
236
- function pickHitGraphic(pick, graphic) {
237
- if (!Array.isArray(graphic) || !graphic.length) {
238
- return false;
239
- }
240
- const elements = resolvePick(pick);
241
- if (!elements.length) {
242
- return false;
243
- }
244
- return elements.some((element) => graphic.includes(element));
245
- }
246
- function isProperty(value) {
247
- return value && isFunction(value.getValue);
248
- }
249
- function toPropertyValue(value, time) {
250
- return isProperty(value) ? value.getValue(time) : value;
251
- }
252
- function toProperty(value, isConstant = false) {
253
- return isProperty(value) ? value : isFunction(value) ? new cesium.CallbackProperty(value, isConstant) : new cesium.ConstantProperty(value);
254
- }
255
- function createPropertyField(scope, field, maybeProperty, readonly) {
256
- let removeOwnerListener;
257
- const ownerBinding = (value) => {
258
- var _a;
259
- removeOwnerListener == null ? void 0 : removeOwnerListener();
260
- if (cesium.defined(value == null ? void 0 : value.definitionChanged)) {
261
- removeOwnerListener = (_a = value == null ? void 0 : value.definitionChanged) == null ? void 0 : _a.addEventListener(() => {
262
- scope.definitionChanged.raiseEvent(scope, field, value, value);
263
- });
264
- }
265
- };
266
- const privateField = `_${field}`;
267
- const property = toProperty(maybeProperty);
268
- scope[privateField] = property;
269
- ownerBinding(property);
270
- if (readonly) {
271
- Object.defineProperty(scope, field, {
272
- get() {
273
- return scope[privateField];
274
- }
275
- });
276
- } else {
277
- Object.defineProperty(scope, field, {
278
- get() {
279
- return scope[privateField];
280
- },
281
- set(value) {
282
- const previous = scope[privateField];
283
- if (scope[privateField] !== value) {
284
- scope[privateField] = value;
285
- ownerBinding(value);
286
- if (cesium.defined(scope.definitionChanged)) {
287
- scope.definitionChanged.raiseEvent(scope, field, value, previous);
288
- }
289
- }
290
- }
291
- });
292
- }
293
- }
294
- function createCesiumAttribute(scope, key, value, options = {}) {
295
- const allowToProperty = !!options.toProperty;
296
- const shallowClone = !!options.shallowClone;
297
- const changedEventKey = options.changedEventKey || "definitionChanged";
298
- const changedEvent = Reflect.get(scope, changedEventKey);
299
- const privateKey = `_${String(key)}`;
300
- const attribute = allowToProperty ? toProperty(value) : value;
301
- Reflect.set(scope, privateKey, attribute);
302
- const obj = {
303
- get() {
304
- const value2 = Reflect.get(scope, privateKey);
305
- if (shallowClone) {
306
- return Array.isArray(value2) ? [...value2] : { ...value2 };
307
- } else {
308
- return value2;
309
- }
310
- }
311
- };
312
- let previousListener;
313
- const serial = (property, previous) => {
314
- var _a;
315
- previousListener == null ? void 0 : previousListener();
316
- previousListener = (_a = property == null ? void 0 : property.definitionChanged) == null ? void 0 : _a.addEventListener(() => {
317
- changedEvent == null ? void 0 : changedEvent.raiseEvent.bind(changedEvent)(scope, key, property, previous);
318
- });
319
- };
320
- if (!options.readonly) {
321
- if (allowToProperty && isProperty(value)) {
322
- serial(value);
323
- }
324
- obj.set = (value2) => {
325
- if (allowToProperty && !isProperty(value2)) {
326
- throw new Error(`The value of ${String(key)} must be a Cesium.Property object`);
327
- }
328
- const previous = Reflect.get(scope, privateKey);
329
- if (previous !== value2) {
330
- Reflect.set(scope, privateKey, value2);
331
- changedEvent == null ? void 0 : changedEvent.raiseEvent.bind(changedEvent)(scope, key, value2, previous);
332
- if (allowToProperty) {
333
- serial(value2);
334
- }
335
- }
336
- };
337
- }
338
- Object.defineProperty(scope, key, obj);
339
- }
340
- function createCesiumProperty(scope, key, value, options = {}) {
341
- return createCesiumAttribute(scope, key, value, { ...options, toProperty: true });
342
- }
343
- function throttle(callback, delay = 100, trailing = true, leading = false) {
344
- const restList = [];
345
- let tracked = false;
346
- const trigger = async () => {
347
- await core.promiseTimeout(delay);
348
- tracked = false;
349
- if (leading) {
350
- try {
351
- callback(...restList[0]);
352
- } catch (error) {
353
- console.error(error);
354
- }
355
- }
356
- if (trailing && (!leading || restList.length > 1)) {
357
- try {
358
- callback(...restList[restList.length - 1]);
359
- } catch (error) {
360
- console.error(error);
361
- }
362
- }
363
- restList.length = 0;
364
- };
365
- return (...rest) => {
366
- if (restList.length < 2) {
367
- restList.push(rest);
368
- } else {
369
- restList[1] = rest;
370
- }
371
- if (!tracked) {
372
- tracked = true;
373
- trigger();
374
- }
375
- };
376
- }
377
- function toCartesian3(position) {
378
- if (!position) {
379
- return void 0;
380
- }
381
- if (position instanceof cesium.Cartesian3) {
382
- return position.clone();
383
- } else if (position instanceof cesium.Cartographic) {
384
- return cesium.Ellipsoid.WGS84.cartographicToCartesian(position);
385
- } else if (Array.isArray(position)) {
386
- return cesium.Cartesian3.fromDegrees(position[0], position[1], position[2]);
387
- } else {
388
- return cesium.Cartesian3.fromDegrees(position.longitude, position.latitude, position.height);
389
- }
390
- }
391
- function toCartographic(position) {
392
- if (!position) {
393
- return void 0;
394
- }
395
- if (position instanceof cesium.Cartesian3) {
396
- return cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
397
- } else if (position instanceof cesium.Cartographic) {
398
- return position.clone();
399
- } else if (Array.isArray(position)) {
400
- return cesium.Cartographic.fromDegrees(position[0], position[1], position[2]);
401
- } else {
402
- return cesium.Cartographic.fromDegrees(position.longitude, position.latitude, position.height);
403
- }
404
- }
405
- function tryRun(fn) {
406
- return (...args) => {
407
- try {
408
- return fn == null ? void 0 : fn(...args);
409
- } catch (error) {
410
- console.error(error);
411
- }
412
- };
413
- }
414
- async function toPromiseValue(source, options = {}) {
415
- try {
416
- const { raw = true } = options;
417
- let value;
418
- if (isFunction(source)) {
419
- value = await source();
420
- } else {
421
- const result = vue.toValue(source);
422
- value = isPromise(result) ? await result : result;
423
- }
424
- return raw ? vue.toRaw(value) : value;
425
- } catch (error) {
426
- console.error(error);
427
- throw error;
428
- }
429
- }
430
- function useCesiumEventListener(event, listener, options = {}) {
431
- const isActive = vue.toRef(options.isActive ?? true);
432
- const cleanup = vue.watchEffect((onCleanup) => {
433
- const _event = vue.toValue(event);
434
- const events = Array.isArray(_event) ? _event : [_event];
435
- if (events) {
436
- if (events.length && isActive.value) {
437
- const stopFns = events.map((event2) => {
438
- const e = vue.toValue(event2);
439
- return e == null ? void 0 : e.addEventListener(listener, e);
440
- });
441
- onCleanup(() => stopFns.forEach((stop) => stop == null ? void 0 : stop()));
442
- }
443
- }
444
- });
445
- core.tryOnScopeDispose(cleanup.stop);
446
- return cleanup.stop;
447
- }
448
- function useViewer() {
449
- const scope = vue.getCurrentScope();
450
- const instanceViewer = scope ? CREATE_VIEWER_COLLECTION.get(scope) : void 0;
451
- if (instanceViewer) {
452
- return instanceViewer;
453
- } else {
454
- const injectViewer = vue.inject(CREATE_VIEWER_INJECTION_KEY);
455
- if (!injectViewer) {
456
- throw new Error(
457
- "The `Viewer` instance injected by `createViewer` was not found in the current component or its ancestor components. Have you called `createViewer`?"
458
- );
459
- }
460
- return injectViewer;
461
- }
462
- }
463
- function useCameraState(options = {}) {
464
- let getCamera = options.camera;
465
- if (!getCamera) {
466
- const viewer = useViewer();
467
- getCamera = () => {
468
- var _a;
469
- return (_a = viewer.value) == null ? void 0 : _a.scene.camera;
470
- };
471
- }
472
- const camera = vue.computed(() => vue.toValue(getCamera));
473
- const event = vue.computed(() => {
474
- var _a;
475
- const eventField = vue.toValue(options.event) || "changed";
476
- return (_a = camera.value) == null ? void 0 : _a[eventField];
477
- });
478
- const changedSymbol = core.refThrottled(
479
- vue.shallowRef(Symbol("camera change")),
480
- options.delay ?? 8,
481
- true,
482
- false
483
- );
484
- const setChangedSymbol = () => {
485
- changedSymbol.value = Symbol("camera change");
486
- };
487
- vue.watch(camera, () => setChangedSymbol());
488
- useCesiumEventListener(event, () => setChangedSymbol());
489
- return {
490
- camera,
491
- position: vue.computed(() => {
492
- var _a, _b;
493
- return changedSymbol.value ? (_b = (_a = camera.value) == null ? void 0 : _a.position) == null ? void 0 : _b.clone() : void 0;
494
- }),
495
- direction: vue.computed(() => {
496
- var _a, _b;
497
- return changedSymbol.value ? (_b = (_a = camera.value) == null ? void 0 : _a.direction) == null ? void 0 : _b.clone() : void 0;
498
- }),
499
- up: vue.computed(() => {
500
- var _a, _b;
501
- return changedSymbol.value ? (_b = (_a = camera.value) == null ? void 0 : _a.up) == null ? void 0 : _b.clone() : void 0;
502
- }),
503
- right: vue.computed(() => {
504
- var _a, _b;
505
- return changedSymbol.value ? (_b = (_a = camera.value) == null ? void 0 : _a.right) == null ? void 0 : _b.clone() : void 0;
506
- }),
507
- positionCartographic: vue.computed(() => {
508
- var _a, _b;
509
- return changedSymbol.value ? (_b = (_a = camera.value) == null ? void 0 : _a.positionCartographic) == null ? void 0 : _b.clone() : void 0;
510
- }),
511
- positionWC: vue.computed(() => {
512
- var _a, _b;
513
- return changedSymbol.value ? (_b = (_a = camera.value) == null ? void 0 : _a.positionWC) == null ? void 0 : _b.clone() : void 0;
514
- }),
515
- directionWC: vue.computed(() => {
516
- var _a, _b;
517
- return changedSymbol.value ? (_b = (_a = camera.value) == null ? void 0 : _a.directionWC) == null ? void 0 : _b.clone() : void 0;
518
- }),
519
- upWC: vue.computed(() => {
520
- var _a, _b;
521
- return changedSymbol.value ? (_b = (_a = camera.value) == null ? void 0 : _a.directionWC) == null ? void 0 : _b.clone() : void 0;
522
- }),
523
- rightWC: vue.computed(() => {
524
- var _a, _b;
525
- return changedSymbol.value ? (_b = (_a = camera.value) == null ? void 0 : _a.directionWC) == null ? void 0 : _b.clone() : void 0;
526
- }),
527
- viewRectangle: vue.computed(() => {
528
- var _a;
529
- return changedSymbol.value ? (_a = camera.value) == null ? void 0 : _a.computeViewRectangle() : void 0;
530
- }),
531
- heading: vue.computed(() => {
532
- var _a;
533
- return changedSymbol.value ? (_a = camera.value) == null ? void 0 : _a.heading : void 0;
534
- }),
535
- pitch: vue.computed(() => {
536
- var _a;
537
- return changedSymbol.value ? (_a = camera.value) == null ? void 0 : _a.pitch : void 0;
538
- }),
539
- roll: vue.computed(() => {
540
- var _a;
541
- return changedSymbol.value ? (_a = camera.value) == null ? void 0 : _a.roll : void 0;
542
- }),
543
- level: vue.computed(() => {
544
- var _a, _b;
545
- return changedSymbol.value && ((_b = (_a = camera.value) == null ? void 0 : _a.positionCartographic) == null ? void 0 : _b.height) ? computeLevel(camera.value.positionCartographic.height) : void 0;
546
- })
547
- };
548
- }
549
- const A = 40487.57;
550
- const B = 7096758e-11;
551
- const C = 91610.74;
552
- const D = -40467.74;
553
- function computeLevel(height) {
554
- return D + (A - D) / (1 + (height / C) ** B);
555
- }
556
- function useCesiumFps(options = {}) {
557
- const { delay = 100 } = options;
558
- const viewer = useViewer();
559
- const p = vue.shallowRef(performance.now());
560
- useCesiumEventListener(
561
- () => {
562
- var _a;
563
- return (_a = viewer.value) == null ? void 0 : _a.scene.postRender;
564
- },
565
- () => p.value = performance.now()
566
- );
567
- const interval = vue.ref(0);
568
- core.watchThrottled(p, (value, oldValue) => {
569
- interval.value = value - oldValue;
570
- }, {
571
- throttle: delay
572
- });
573
- const fps = vue.computed(() => {
574
- return 1e3 / interval.value;
575
- });
576
- return {
577
- interval: vue.readonly(interval),
578
- fps
579
- };
580
- }
581
- function useCollectionScope(addFn, removeFn, removeScopeArgs) {
582
- const scope = vue.shallowReactive(/* @__PURE__ */ new Set());
583
- const add = (instance, ...args) => {
584
- const result = addFn(instance, ...args);
585
- if (isPromise(result)) {
586
- return new Promise((resolve, reject) => {
587
- result.then((i) => {
588
- scope.add(i);
589
- resolve(i);
590
- }).catch((error) => reject(error));
591
- });
592
- } else {
593
- scope.add(result);
594
- return result;
595
- }
596
- };
597
- const remove = (instance, ...args) => {
598
- scope.delete(instance);
599
- return removeFn(instance, ...args);
600
- };
601
- const removeWhere = (predicate, ...args) => {
602
- scope.forEach((instance) => {
603
- if (predicate(instance)) {
604
- remove(instance, ...args);
605
- }
606
- });
607
- };
608
- const removeScope = (...args) => {
609
- scope.forEach((instance) => {
610
- remove(instance, ...args);
611
- });
612
- };
613
- core.tryOnScopeDispose(() => removeScope(...removeScopeArgs));
614
- return {
615
- scope: vue.shallowReadonly(scope),
616
- add,
617
- remove,
618
- removeWhere,
619
- removeScope
620
- };
621
- }
622
- function useDataSource(dataSources, options = {}) {
623
- const {
624
- destroyOnRemove,
625
- collection,
626
- isActive = true,
627
- evaluating
628
- } = options;
629
- const result = core.computedAsync(
630
- () => toPromiseValue(dataSources),
631
- void 0,
632
- {
633
- evaluating
634
- }
635
- );
636
- const viewer = useViewer();
637
- vue.watchEffect((onCleanup) => {
638
- var _a;
639
- const _isActive = vue.toValue(isActive);
640
- if (_isActive) {
641
- const list = Array.isArray(result.value) ? [...result.value] : [result.value];
642
- const _collection = collection ?? ((_a = viewer.value) == null ? void 0 : _a.dataSources);
643
- list.forEach((item) => item && (_collection == null ? void 0 : _collection.add(item)));
644
- onCleanup(() => {
645
- const destroy = vue.toValue(destroyOnRemove);
646
- !(_collection == null ? void 0 : _collection.isDestroyed()) && list.forEach((dataSource) => dataSource && (_collection == null ? void 0 : _collection.remove(dataSource, destroy)));
647
- });
648
- }
649
- });
650
- return result;
651
- }
652
- function useDataSourceScope(options = {}) {
653
- const { collection: _collection, destroyOnRemove } = options;
654
- const viewer = useViewer();
655
- const collection = vue.computed(() => {
656
- var _a;
657
- return vue.toValue(_collection) ?? ((_a = viewer.value) == null ? void 0 : _a.dataSources);
658
- });
659
- const addFn = (dataSource) => {
660
- if (!collection.value) {
661
- throw new Error("collection is not defined");
662
- }
663
- return collection.value.add(dataSource);
664
- };
665
- const removeFn = (dataSource, destroy) => {
666
- var _a;
667
- return !!((_a = collection.value) == null ? void 0 : _a.remove(dataSource, destroy));
668
- };
669
- const { scope, add, remove, removeWhere, removeScope } = useCollectionScope(addFn, removeFn, [destroyOnRemove]);
670
- return {
671
- scope,
672
- add,
673
- remove,
674
- removeWhere,
675
- removeScope
676
- };
677
- }
678
- function useElementOverlay(target, position, options = {}) {
679
- const {
680
- referenceWindow,
681
- horizontal = "center",
682
- vertical = "bottom",
683
- offset = { x: 0, y: 0 }
684
- } = options;
685
- const cartesian3 = vue.computed(() => toCartesian3(vue.toValue(position)));
686
- const viewer = useViewer();
687
- const coord = vue.shallowRef();
688
- useCesiumEventListener(
689
- () => {
690
- var _a;
691
- return (_a = viewer.value) == null ? void 0 : _a.scene.postRender;
692
- },
693
- () => {
694
- var _a;
695
- if (!((_a = viewer.value) == null ? void 0 : _a.scene)) {
696
- return;
697
- }
698
- if (!cartesian3.value) {
699
- coord.value = void 0;
700
- } else {
701
- const reslut = cartesianToCanvasCoord(cartesian3.value, viewer.value.scene);
702
- coord.value = !cesium.Cartesian2.equals(reslut, coord.value) ? reslut : coord.value;
703
- }
704
- }
705
- );
706
- const canvasBounding = core.useElementBounding(() => {
707
- var _a;
708
- return (_a = viewer.value) == null ? void 0 : _a.canvas.parentElement;
709
- });
710
- const targetBounding = core.useElementBounding(target);
711
- const finalOffset = vue.computed(() => {
712
- const _offset = vue.toValue(offset);
713
- let x2 = (_offset == null ? void 0 : _offset.x) ?? 0;
714
- const _horizontal = vue.toValue(horizontal);
715
- if (_horizontal === "center") {
716
- x2 -= targetBounding.width.value / 2;
717
- } else if (_horizontal === "right") {
718
- x2 -= targetBounding.width.value;
719
- }
720
- let y2 = (_offset == null ? void 0 : _offset.y) ?? 0;
721
- const _vertical = vue.toValue(vertical);
722
- if (_vertical === "center") {
723
- y2 -= targetBounding.height.value / 2;
724
- } else if (_vertical === "bottom") {
725
- y2 -= targetBounding.height.value;
726
- }
727
- return {
728
- x: x2,
729
- y: y2
730
- };
731
- });
732
- const location = vue.computed(() => {
733
- var _a, _b;
734
- const data = {
735
- x: ((_a = coord.value) == null ? void 0 : _a.x) ?? 0,
736
- y: ((_b = coord.value) == null ? void 0 : _b.y) ?? 0
737
- };
738
- if (vue.toValue(referenceWindow)) {
739
- data.x += canvasBounding.x.value;
740
- data.y += canvasBounding.y.value;
741
- }
742
- return {
743
- x: finalOffset.value.x + data.x,
744
- y: finalOffset.value.y + data.y
745
- };
746
- });
747
- const x = vue.computed(() => location.value.x);
748
- const y = vue.computed(() => location.value.y);
749
- const style = vue.computed(() => {
750
- var _a, _b;
751
- return { left: `${(_a = x.value) == null ? void 0 : _a.toFixed(2)}px`, top: `${(_b = y.value) == null ? void 0 : _b.toFixed(2)}px` };
752
- });
753
- vue.watchEffect(() => {
754
- var _a, _b, _c, _d;
755
- const element = vue.toValue(target);
756
- if (element && vue.toValue(options.applyStyle ?? true)) {
757
- (_b = (_a = element.style) == null ? void 0 : _a.setProperty) == null ? void 0 : _b.call(_a, "left", style.value.left);
758
- (_d = (_c = element.style) == null ? void 0 : _c.setProperty) == null ? void 0 : _d.call(_c, "top", style.value.top);
759
- }
760
- });
761
- return {
762
- x,
763
- y,
764
- style
765
- };
766
- }
767
- function useEntity(data, options = {}) {
768
- const { collection, isActive = true, evaluating } = options;
769
- const result = core.computedAsync(
770
- () => toPromiseValue(data),
771
- [],
772
- {
773
- evaluating
774
- }
775
- );
776
- const viewer = useViewer();
777
- vue.watchEffect((onCleanup) => {
778
- var _a;
779
- const _isActive = vue.toValue(isActive);
780
- if (_isActive) {
781
- const list = Array.isArray(result.value) ? [...result.value] : [result.value];
782
- const _collection = collection ?? ((_a = viewer.value) == null ? void 0 : _a.entities);
783
- list.forEach((item) => item && (_collection == null ? void 0 : _collection.add(item)));
784
- onCleanup(() => {
785
- list.forEach((item) => item && (_collection == null ? void 0 : _collection.remove(item)));
786
- });
787
- }
788
- });
789
- return result;
790
- }
791
- function useEntityScope(options = {}) {
792
- const { collection: _collection } = options;
793
- const viewer = useViewer();
794
- const collection = vue.computed(() => {
795
- var _a;
796
- return vue.toValue(_collection) ?? ((_a = viewer.value) == null ? void 0 : _a.entities);
797
- });
798
- const addFn = (entity) => {
799
- if (!collection.value) {
800
- throw new Error("collection is not defined");
801
- }
802
- if (!collection.value.contains(entity)) {
803
- collection.value.add(entity);
804
- }
805
- return entity;
806
- };
807
- const removeFn = (entity) => {
808
- var _a;
809
- return !!((_a = collection.value) == null ? void 0 : _a.remove(entity));
810
- };
811
- const { scope, add, remove, removeWhere, removeScope } = useCollectionScope(addFn, removeFn, []);
812
- return {
813
- scope,
814
- add,
815
- remove,
816
- removeWhere,
817
- removeScope
818
- };
819
- }
820
- const pickCache = /* @__PURE__ */ new WeakMap();
821
- function useScenePick(windowPosition, options = {}) {
822
- const { width = 3, height = 3, throttled = 8 } = options;
823
- const isActive = vue.toRef(options.isActive ?? true);
824
- const viewer = useViewer();
825
- const position = core.refThrottled(vue.computed(() => {
826
- var _a;
827
- return (_a = vue.toValue(windowPosition)) == null ? void 0 : _a.clone();
828
- }), throttled, false, true);
829
- const pick = vue.shallowRef();
830
- vue.watchEffect(() => {
831
- var _a;
832
- if (viewer.value && position.value && isActive.value) {
833
- const cache = pickCache.get(viewer.value);
834
- if (cache && cache[0].equals(position.value)) {
835
- pick.value = cache[1];
836
- } else {
837
- pickCache.set(viewer.value, [position.value.clone(), pick.value]);
838
- pick.value = (_a = viewer.value) == null ? void 0 : _a.scene.pick(
839
- position.value,
840
- vue.toValue(width),
841
- vue.toValue(height)
842
- );
843
- }
844
- }
845
- });
846
- return pick;
847
- }
848
- function useScreenSpaceEventHandler(type, inputAction, options = {}) {
849
- const { modifier } = options;
850
- const viewer = useViewer();
851
- const isActive = vue.toRef(options.isActive ?? true);
852
- const handler = vue.computed(() => {
853
- var _a, _b;
854
- if ((_b = (_a = viewer.value) == null ? void 0 : _a.cesiumWidget) == null ? void 0 : _b.canvas) {
855
- return new cesium.ScreenSpaceEventHandler(viewer.value.cesiumWidget.canvas);
856
- }
857
- });
858
- const cleanup1 = vue.watch(handler, (_value, previous) => {
859
- var _a;
860
- ((_a = viewer.value) == null ? void 0 : _a.cesiumWidget) && (previous == null ? void 0 : previous.destroy());
861
- });
862
- const cleanup2 = vue.watchEffect((onCleanup) => {
863
- const typeValue = vue.toValue(type);
864
- const modifierValue = vue.toValue(modifier);
865
- const handlerValue = vue.toValue(handler);
866
- if (!handlerValue || !isActive.value || !inputAction) {
867
- return;
868
- }
869
- if (isDef(typeValue)) {
870
- handlerValue.setInputAction(inputAction, typeValue, modifierValue);
871
- onCleanup(() => handlerValue.removeInputAction(typeValue, modifierValue));
872
- }
873
- });
874
- const stop = () => {
875
- cleanup1();
876
- cleanup2();
877
- };
878
- core.tryOnScopeDispose(stop);
879
- return stop;
880
- }
881
- function useDrag(listener) {
882
- const position = vue.shallowRef();
883
- const pick = useScenePick(position);
884
- const motionEvent = vue.shallowRef();
885
- const dragging = vue.ref(false);
886
- const viewer = useViewer();
887
- const cameraLocked = vue.ref(false);
888
- vue.watch(cameraLocked, (cameraLocked2) => {
889
- viewer.value && (viewer.value.scene.screenSpaceCameraController.enableRotate = !cameraLocked2);
890
- });
891
- const lockCamera = () => {
892
- cameraLocked.value = true;
893
- };
894
- const execute = (pick2, startPosition, endPosition) => {
895
- listener({
896
- event: {
897
- startPosition: startPosition.clone(),
898
- endPosition: endPosition.clone()
899
- },
900
- pick: pick2,
901
- dragging: dragging.value,
902
- lockCamera
903
- });
904
- vue.nextTick(() => {
905
- if (!dragging.value && cameraLocked.value) {
906
- cameraLocked.value = false;
907
- }
908
- });
909
- };
910
- const stopLeftDownWatch = useScreenSpaceEventHandler(
911
- cesium.ScreenSpaceEventType.LEFT_DOWN,
912
- (event) => {
913
- dragging.value = true;
914
- position.value = event.position.clone();
915
- }
916
- );
917
- const stopMouseMoveWatch = useScreenSpaceEventHandler(
918
- cesium.ScreenSpaceEventType.MOUSE_MOVE,
919
- throttle(({ startPosition, endPosition }) => {
920
- var _a;
921
- motionEvent.value = {
922
- startPosition: ((_a = motionEvent.value) == null ? void 0 : _a.endPosition.clone()) || startPosition.clone(),
923
- endPosition: endPosition.clone()
924
- };
925
- }, 8, false, true)
926
- );
927
- vue.watch([pick, motionEvent], ([pick2, motionEvent2]) => {
928
- if (pick2 && motionEvent2) {
929
- const { startPosition, endPosition } = motionEvent2;
930
- dragging.value && execute(pick2, startPosition, endPosition);
931
- }
932
- });
933
- const stopLeftUpWatch = useScreenSpaceEventHandler(
934
- cesium.ScreenSpaceEventType.LEFT_UP,
935
- (event) => {
936
- dragging.value = false;
937
- if (pick.value && motionEvent.value) {
938
- execute(pick.value, motionEvent.value.endPosition, event.position);
939
- }
940
- position.value = void 0;
941
- motionEvent.value = void 0;
942
- }
943
- );
944
- const stop = () => {
945
- stopLeftDownWatch();
946
- stopMouseMoveWatch();
947
- stopLeftUpWatch();
948
- };
949
- core.tryOnScopeDispose(stop);
950
- return stop;
951
- }
952
- function useHover(listener) {
953
- const motionEvent = vue.shallowRef();
954
- const pick = useScenePick(() => {
955
- var _a;
956
- return (_a = motionEvent.value) == null ? void 0 : _a.endPosition;
957
- });
958
- const execute = (pick2, startPosition, endPosition, hovering) => {
959
- listener({
960
- event: {
961
- startPosition: startPosition.clone(),
962
- endPosition: endPosition.clone()
963
- },
964
- pick: pick2,
965
- hovering
966
- });
967
- };
968
- useScreenSpaceEventHandler(
969
- cesium.ScreenSpaceEventType.MOUSE_MOVE,
970
- ({ startPosition, endPosition }) => {
971
- var _a, _b;
972
- if (!startPosition.equals((_a = motionEvent.value) == null ? void 0 : _a.startPosition) || !endPosition.equals((_b = motionEvent.value) == null ? void 0 : _b.endPosition)) {
973
- motionEvent.value = { startPosition: startPosition.clone(), endPosition: endPosition.clone() };
974
- }
975
- }
976
- );
977
- vue.watch([pick, motionEvent], ([pick2, motionEvent2]) => {
978
- if (pick2 && motionEvent2) {
979
- const { startPosition, endPosition } = motionEvent2;
980
- execute(pick2, startPosition, endPosition, true);
981
- }
982
- });
983
- vue.watch(pick, (pick2, prevPick) => {
984
- if (prevPick && motionEvent.value) {
985
- const { startPosition, endPosition } = motionEvent.value;
986
- execute(prevPick, startPosition, endPosition, false);
987
- }
988
- });
989
- }
990
- const EVENT_TYPE_RECORD = {
991
- LEFT_DOWN: cesium.ScreenSpaceEventType.LEFT_DOWN,
992
- LEFT_UP: cesium.ScreenSpaceEventType.LEFT_UP,
993
- LEFT_CLICK: cesium.ScreenSpaceEventType.LEFT_CLICK,
994
- LEFT_DOUBLE_CLICK: cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK,
995
- RIGHT_DOWN: cesium.ScreenSpaceEventType.RIGHT_DOWN,
996
- RIGHT_UP: cesium.ScreenSpaceEventType.RIGHT_UP,
997
- RIGHT_CLICK: cesium.ScreenSpaceEventType.RIGHT_CLICK,
998
- MIDDLE_DOWN: cesium.ScreenSpaceEventType.MIDDLE_DOWN,
999
- MIDDLE_UP: cesium.ScreenSpaceEventType.MIDDLE_UP,
1000
- MIDDLE_CLICK: cesium.ScreenSpaceEventType.MIDDLE_CLICK
1001
- };
1002
- function usePositioned(type, listener) {
1003
- const screenEvent = EVENT_TYPE_RECORD[type];
1004
- const viewer = useViewer();
1005
- useScreenSpaceEventHandler(screenEvent, (event) => {
1006
- var _a;
1007
- const position = event.position;
1008
- const pick = (_a = viewer.value) == null ? void 0 : _a.scene.pick(position);
1009
- pick && position && listener({ event: { position }, pick });
1010
- });
1011
- }
1012
- const GLOBAL_GRAPHIC_SYMBOL = Symbol("GLOBAL_GRAPHIC_SYMBOL");
1013
- const POSITIONED_EVENT_TYPES = [
1014
- "LEFT_DOWN",
1015
- "LEFT_UP",
1016
- "LEFT_CLICK",
1017
- "LEFT_DOUBLE_CLICK",
1018
- "RIGHT_DOWN",
1019
- "RIGHT_UP",
1020
- "RIGHT_CLICK",
1021
- "MIDDLE_DOWN",
1022
- "MIDDLE_UP",
1023
- "MIDDLE_CLICK"
1024
- ];
1025
- function useGraphicEvent() {
1026
- const collection = /* @__PURE__ */ new WeakMap();
1027
- const cursorCollection = /* @__PURE__ */ new WeakMap();
1028
- const dragCursorCollection = /* @__PURE__ */ new WeakMap();
1029
- const removeGraphicEvent = (graphic, type, listener) => {
1030
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
1031
- const _graphic = graphic === "global" ? GLOBAL_GRAPHIC_SYMBOL : graphic;
1032
- (_b = (_a = collection == null ? void 0 : collection.get(_graphic)) == null ? void 0 : _a.get(type)) == null ? void 0 : _b.delete(listener);
1033
- (_d = (_c = cursorCollection == null ? void 0 : cursorCollection.get(_graphic)) == null ? void 0 : _c.get(type)) == null ? void 0 : _d.delete(listener);
1034
- if (((_f = (_e = collection == null ? void 0 : collection.get(_graphic)) == null ? void 0 : _e.get(type)) == null ? void 0 : _f.size) === 0) {
1035
- collection.get(_graphic).delete(type);
1036
- }
1037
- if (((_g = collection.get(_graphic)) == null ? void 0 : _g.size) === 0) {
1038
- collection.delete(_graphic);
1039
- }
1040
- (_i = (_h = cursorCollection == null ? void 0 : cursorCollection.get(_graphic)) == null ? void 0 : _h.get(type)) == null ? void 0 : _i.delete(listener);
1041
- if (((_k = (_j = cursorCollection == null ? void 0 : cursorCollection.get(_graphic)) == null ? void 0 : _j.get(type)) == null ? void 0 : _k.size) === 0) {
1042
- (_l = cursorCollection == null ? void 0 : cursorCollection.get(_graphic)) == null ? void 0 : _l.delete(type);
1043
- }
1044
- if (((_m = cursorCollection == null ? void 0 : cursorCollection.get(_graphic)) == null ? void 0 : _m.size) === 0) {
1045
- cursorCollection == null ? void 0 : cursorCollection.delete(_graphic);
1046
- }
1047
- (_o = (_n = dragCursorCollection == null ? void 0 : dragCursorCollection.get(_graphic)) == null ? void 0 : _n.get(type)) == null ? void 0 : _o.delete(listener);
1048
- if (((_q = (_p = dragCursorCollection == null ? void 0 : dragCursorCollection.get(_graphic)) == null ? void 0 : _p.get(type)) == null ? void 0 : _q.size) === 0) {
1049
- (_r = dragCursorCollection == null ? void 0 : dragCursorCollection.get(_graphic)) == null ? void 0 : _r.delete(type);
1050
- }
1051
- if (((_s = dragCursorCollection == null ? void 0 : dragCursorCollection.get(_graphic)) == null ? void 0 : _s.size) === 0) {
1052
- dragCursorCollection == null ? void 0 : dragCursorCollection.delete(_graphic);
1053
- }
1054
- };
1055
- const addGraphicEvent = (graphic, type, listener, options = {}) => {
1056
- const _graphic = graphic === "global" ? GLOBAL_GRAPHIC_SYMBOL : graphic;
1057
- collection.get(_graphic) ?? collection.set(_graphic, /* @__PURE__ */ new Map());
1058
- const eventTypeMap = collection.get(_graphic);
1059
- eventTypeMap.get(type) ?? eventTypeMap.set(type, /* @__PURE__ */ new Set());
1060
- const listeners = eventTypeMap.get(type);
1061
- listeners.add(listener);
1062
- let { cursor = "pointer", dragCursor } = options;
1063
- if (isDef(cursor)) {
1064
- const _cursor = isFunction(cursor) ? cursor : () => cursor;
1065
- cursorCollection.get(_graphic) ?? cursorCollection.set(_graphic, /* @__PURE__ */ new Map());
1066
- cursorCollection.get(_graphic).get(type) ?? cursorCollection.get(_graphic).set(type, /* @__PURE__ */ new Map());
1067
- cursorCollection.get(_graphic).get(type).set(listener, _cursor);
1068
- }
1069
- if (type === "DRAG") {
1070
- dragCursor ?? (dragCursor = (event) => (event == null ? void 0 : event.dragging) ? "crosshair" : void 0);
1071
- }
1072
- if (isDef(dragCursor)) {
1073
- const _dragCursor = isFunction(dragCursor) ? dragCursor : () => dragCursor;
1074
- dragCursorCollection.get(_graphic) ?? dragCursorCollection.set(_graphic, /* @__PURE__ */ new Map());
1075
- dragCursorCollection.get(_graphic).get(type) ?? dragCursorCollection.get(_graphic).set(type, /* @__PURE__ */ new Map());
1076
- dragCursorCollection.get(_graphic).get(type).set(listener, _dragCursor);
1077
- }
1078
- return () => removeGraphicEvent(graphic, type, listener);
1079
- };
1080
- const clearGraphicEvent = (graphic, type) => {
1081
- var _a, _b, _c, _d, _e, _f;
1082
- const _graphic = graphic === "global" ? GLOBAL_GRAPHIC_SYMBOL : graphic;
1083
- if (type === "all") {
1084
- collection.delete(_graphic);
1085
- cursorCollection.delete(_graphic);
1086
- dragCursorCollection.delete(_graphic);
1087
- return;
1088
- }
1089
- (_a = collection.get(_graphic)) == null ? void 0 : _a.delete(type);
1090
- if (((_b = collection.get(_graphic)) == null ? void 0 : _b.size) === 0) {
1091
- collection.delete(_graphic);
1092
- }
1093
- (_c = cursorCollection == null ? void 0 : cursorCollection.get(_graphic)) == null ? void 0 : _c.delete(type);
1094
- (_d = dragCursorCollection == null ? void 0 : dragCursorCollection.get(_graphic)) == null ? void 0 : _d.delete(type);
1095
- if (((_e = cursorCollection == null ? void 0 : cursorCollection.get(_graphic)) == null ? void 0 : _e.size) === 0) {
1096
- cursorCollection == null ? void 0 : cursorCollection.delete(_graphic);
1097
- }
1098
- if (((_f = dragCursorCollection == null ? void 0 : dragCursorCollection.get(_graphic)) == null ? void 0 : _f.size) === 0) {
1099
- dragCursorCollection == null ? void 0 : dragCursorCollection.delete(_graphic);
1100
- }
1101
- };
1102
- for (const type of POSITIONED_EVENT_TYPES) {
1103
- usePositioned(type, (event) => {
1104
- const graphics = resolvePick(event.pick);
1105
- graphics.concat(GLOBAL_GRAPHIC_SYMBOL).forEach((graphic) => {
1106
- var _a, _b;
1107
- (_b = (_a = collection.get(graphic)) == null ? void 0 : _a.get(type)) == null ? void 0 : _b.forEach((fn) => {
1108
- var _a2;
1109
- return (_a2 = tryRun(fn)) == null ? void 0 : _a2(event);
1110
- });
1111
- });
1112
- });
1113
- }
1114
- const dragging = vue.ref(false);
1115
- const viewer = useViewer();
1116
- useHover((event) => {
1117
- const graphics = resolvePick(event.pick).concat(GLOBAL_GRAPHIC_SYMBOL);
1118
- graphics.forEach((graphic) => {
1119
- var _a, _b, _c;
1120
- (_b = (_a = collection.get(graphic)) == null ? void 0 : _a.get("HOVER")) == null ? void 0 : _b.forEach((fn) => {
1121
- var _a2;
1122
- return (_a2 = tryRun(fn)) == null ? void 0 : _a2(event);
1123
- });
1124
- if (!dragging.value) {
1125
- (_c = cursorCollection.get(graphic)) == null ? void 0 : _c.forEach((map) => {
1126
- map.forEach((fn) => {
1127
- var _a2, _b2;
1128
- const cursor = event.hovering ? tryRun(fn)(event) : "";
1129
- (_b2 = (_a2 = viewer.value) == null ? void 0 : _a2.canvas.style) == null ? void 0 : _b2.setProperty("cursor", cursor);
1130
- });
1131
- });
1132
- }
1133
- });
1134
- });
1135
- useDrag((event) => {
1136
- const graphics = resolvePick(event.pick).concat(GLOBAL_GRAPHIC_SYMBOL);
1137
- dragging.value = event.dragging;
1138
- graphics.forEach((graphic) => {
1139
- var _a, _b, _c;
1140
- (_b = (_a = collection.get(graphic)) == null ? void 0 : _a.get("DRAG")) == null ? void 0 : _b.forEach((fn) => tryRun(fn)(event));
1141
- (_c = dragCursorCollection.get(graphic)) == null ? void 0 : _c.forEach((map) => {
1142
- map.forEach((fn) => {
1143
- var _a2, _b2;
1144
- const cursor = event.dragging ? tryRun(fn)(event) : "";
1145
- (_b2 = (_a2 = viewer.value) == null ? void 0 : _a2.canvas.style) == null ? void 0 : _b2.setProperty("cursor", cursor);
1146
- });
1147
- });
1148
- });
1149
- });
1150
- return {
1151
- addGraphicEvent,
1152
- removeGraphicEvent,
1153
- clearGraphicEvent
1154
- };
1155
- }
1156
- function useImageryLayer(data, options = {}) {
1157
- const {
1158
- destroyOnRemove,
1159
- collection,
1160
- isActive = true,
1161
- evaluating
1162
- } = options;
1163
- const result = core.computedAsync(
1164
- () => toPromiseValue(data),
1165
- [],
1166
- {
1167
- evaluating
1168
- }
1169
- );
1170
- const viewer = useViewer();
1171
- vue.watchEffect((onCleanup) => {
1172
- var _a;
1173
- const _isActive = vue.toValue(isActive);
1174
- if (_isActive) {
1175
- const list = Array.isArray(result.value) ? [...result.value] : [result.value];
1176
- const _collection = collection ?? ((_a = viewer.value) == null ? void 0 : _a.imageryLayers);
1177
- if (collection == null ? void 0 : collection.isDestroyed()) {
1178
- return;
1179
- }
1180
- list.forEach((item) => {
1181
- if (!item) {
1182
- console.warn("ImageryLayer is undefined");
1183
- return;
1184
- }
1185
- if (item == null ? void 0 : item.isDestroyed()) {
1186
- console.warn("ImageryLayer is destroyed");
1187
- return;
1188
- }
1189
- _collection == null ? void 0 : _collection.add(item);
1190
- });
1191
- onCleanup(() => {
1192
- const destroy = vue.toValue(destroyOnRemove);
1193
- list.forEach((item) => item && (_collection == null ? void 0 : _collection.remove(item, destroy)));
1194
- });
1195
- }
1196
- });
1197
- return result;
1198
- }
1199
- function useImageryLayerScope(options = {}) {
1200
- const { collection: _collection, destroyOnRemove } = options;
1201
- const viewer = useViewer();
1202
- const collection = vue.computed(() => {
1203
- var _a;
1204
- return vue.toValue(_collection) ?? ((_a = viewer.value) == null ? void 0 : _a.imageryLayers);
1205
- });
1206
- const addFn = (imageryLayer, index) => {
1207
- if (!collection.value) {
1208
- throw new Error("collection is not defined");
1209
- }
1210
- collection.value.add(imageryLayer, index);
1211
- return imageryLayer;
1212
- };
1213
- const removeFn = (imageryLayer, destroy) => {
1214
- var _a;
1215
- return !!((_a = collection.value) == null ? void 0 : _a.remove(imageryLayer, destroy));
1216
- };
1217
- const { scope, add, remove, removeWhere, removeScope } = useCollectionScope(addFn, removeFn, [destroyOnRemove]);
1218
- return {
1219
- scope,
1220
- add,
1221
- remove,
1222
- removeWhere,
1223
- removeScope
1224
- };
1225
- }
1226
- function usePostProcessStage(data, options = {}) {
1227
- const {
1228
- collection,
1229
- isActive = true,
1230
- evaluating
1231
- } = options;
1232
- const result = core.computedAsync(
1233
- () => toPromiseValue(data),
1234
- void 0,
1235
- {
1236
- evaluating
1237
- }
1238
- );
1239
- const viewer = useViewer();
1240
- vue.watchEffect((onCleanup) => {
1241
- if (!viewer.value) {
1242
- return;
1243
- }
1244
- const _isActive = vue.toValue(isActive);
1245
- if (_isActive) {
1246
- const list = Array.isArray(result.value) ? [...result.value] : [result.value];
1247
- const _collection = collection ?? viewer.value.scene.postProcessStages;
1248
- list.forEach((item) => item && _collection.add(item));
1249
- onCleanup(() => {
1250
- list.forEach((item) => item && _collection.remove(item));
1251
- });
1252
- }
1253
- });
1254
- return result;
1255
- }
1256
- function usePostProcessStageScope(options = {}) {
1257
- const { collection: _collection } = options;
1258
- const viewer = useViewer();
1259
- const collection = vue.computed(() => {
1260
- var _a;
1261
- return vue.toValue(_collection) ?? ((_a = viewer.value) == null ? void 0 : _a.postProcessStages);
1262
- });
1263
- const addFn = (postProcessStage) => {
1264
- if (!collection.value) {
1265
- throw new Error("collection is not defined");
1266
- }
1267
- return collection.value.add(postProcessStage);
1268
- };
1269
- const removeFn = (postProcessStage) => {
1270
- var _a;
1271
- return !!((_a = collection.value) == null ? void 0 : _a.remove(postProcessStage));
1272
- };
1273
- const { scope, add, remove, removeWhere, removeScope } = useCollectionScope(addFn, removeFn, []);
1274
- return {
1275
- scope,
1276
- add,
1277
- remove,
1278
- removeWhere,
1279
- removeScope
1280
- };
1281
- }
1282
- function usePrimitive(data, options = {}) {
1283
- const {
1284
- collection,
1285
- isActive = true,
1286
- evaluating
1287
- } = options;
1288
- const result = core.computedAsync(
1289
- () => toPromiseValue(data),
1290
- void 0,
1291
- {
1292
- evaluating
1293
- }
1294
- );
1295
- const viewer = useViewer();
1296
- vue.watchEffect((onCleanup) => {
1297
- var _a, _b;
1298
- const _isActive = vue.toValue(isActive);
1299
- if (_isActive) {
1300
- const list = Array.isArray(result.value) ? [...result.value] : [result.value];
1301
- const _collection = collection === "ground" ? (_a = viewer.value) == null ? void 0 : _a.scene.groundPrimitives : collection ?? ((_b = viewer.value) == null ? void 0 : _b.scene.primitives);
1302
- list.forEach((item) => item && (_collection == null ? void 0 : _collection.add(item)));
1303
- onCleanup(() => {
1304
- !(_collection == null ? void 0 : _collection.isDestroyed()) && list.forEach((item) => item && (_collection == null ? void 0 : _collection.remove(item)));
1305
- });
1306
- }
1307
- });
1308
- return result;
1309
- }
1310
- function usePrimitiveScope(options = {}) {
1311
- const { collection: _collection } = options;
1312
- const viewer = useViewer();
1313
- const collection = vue.computed(() => {
1314
- var _a;
1315
- return vue.toValue(_collection) ?? ((_a = viewer.value) == null ? void 0 : _a.scene.primitives);
1316
- });
1317
- const addFn = (primitive) => {
1318
- if (!collection.value) {
1319
- throw new Error("collection is not defined");
1320
- }
1321
- return collection.value.add(primitive);
1322
- };
1323
- const removeFn = (primitive) => {
1324
- var _a;
1325
- return !!((_a = collection.value) == null ? void 0 : _a.remove(primitive));
1326
- };
1327
- const { scope, add, remove, removeWhere, removeScope } = useCollectionScope(addFn, removeFn, []);
1328
- return {
1329
- scope,
1330
- add,
1331
- remove,
1332
- removeWhere,
1333
- removeScope
1334
- };
1335
- }
1336
- const distances = [
1337
- 0.01,
1338
- 0.05,
1339
- 0.1,
1340
- 0.5,
1341
- 1,
1342
- 2,
1343
- 3,
1344
- 5,
1345
- 10,
1346
- 20,
1347
- 30,
1348
- 50,
1349
- 100,
1350
- 200,
1351
- 300,
1352
- 500,
1353
- 1e3,
1354
- 2e3,
1355
- 3e3,
1356
- 5e3,
1357
- 1e4,
1358
- 2e4,
1359
- 3e4,
1360
- 5e4,
1361
- 1e5,
1362
- 2e5,
1363
- 3e5,
1364
- 5e5,
1365
- 1e6,
1366
- 2e6,
1367
- 3e6,
1368
- 5e6,
1369
- 1e7,
1370
- 2e7,
1371
- 3e7,
1372
- 5e7
1373
- ].reverse();
1374
- function useScaleBar(options = {}) {
1375
- const { maxPixel = 80, delay = 8 } = options;
1376
- const maxPixelRef = vue.computed(() => vue.toValue(maxPixel));
1377
- const viewer = useViewer();
1378
- const canvasSize = core.useElementSize(() => {
1379
- var _a;
1380
- return (_a = viewer.value) == null ? void 0 : _a.canvas;
1381
- });
1382
- const pixelDistance = vue.ref();
1383
- const setPixelDistance = async () => {
1384
- var _a;
1385
- await vue.nextTick();
1386
- const scene = (_a = viewer.value) == null ? void 0 : _a.scene;
1387
- if (!scene) {
1388
- return;
1389
- }
1390
- const left = scene.camera.getPickRay(new cesium.Cartesian2(Math.floor(canvasSize.width.value / 2), canvasSize.height.value - 1));
1391
- const right = scene.camera.getPickRay(new cesium.Cartesian2(Math.floor(1 + canvasSize.width.value / 2), canvasSize.height.value - 1));
1392
- if (!left || !right) {
1393
- return;
1394
- }
1395
- const leftPosition = scene.globe.pick(left, scene);
1396
- const rightPosition = scene.globe.pick(right, scene);
1397
- if (!leftPosition || !rightPosition) {
1398
- return;
1399
- }
1400
- const leftCartographic = scene.globe.ellipsoid.cartesianToCartographic(leftPosition);
1401
- const rightCartographic = scene.globe.ellipsoid.cartesianToCartographic(rightPosition);
1402
- const geodesic = new cesium.EllipsoidGeodesic(leftCartographic, rightCartographic);
1403
- pixelDistance.value = geodesic.surfaceDistance;
1404
- };
1405
- core.watchImmediate(viewer, () => setPixelDistance());
1406
- useCesiumEventListener(
1407
- () => {
1408
- var _a;
1409
- return (_a = viewer.value) == null ? void 0 : _a.camera.changed;
1410
- },
1411
- throttle(setPixelDistance, delay)
1412
- );
1413
- const distance = vue.computed(() => {
1414
- if (pixelDistance.value) {
1415
- return distances.find((item) => pixelDistance.value * maxPixelRef.value > item);
1416
- }
1417
- });
1418
- const width = vue.computed(() => {
1419
- if (distance.value && pixelDistance.value) {
1420
- const value = distance.value / pixelDistance.value;
1421
- return value;
1422
- }
1423
- return 0;
1424
- });
1425
- const distanceText = vue.computed(() => {
1426
- if (distance.value) {
1427
- return distance.value > 1e3 ? `${distance.value / 1e3 || 0}km` : `${distance.value || 0}m`;
1428
- }
1429
- });
1430
- return {
1431
- pixelDistance: vue.readonly(pixelDistance),
1432
- width,
1433
- distance,
1434
- distanceText
1435
- };
1436
- }
1437
- function useSceneDrillPick(windowPosition, options = {}) {
1438
- const { width = 3, height = 3, limit, throttled = 8, isActive = true } = options;
1439
- const viewer = useViewer();
1440
- const position = core.refThrottled(vue.computed(() => vue.toValue(windowPosition)), throttled, false, true);
1441
- const pick = vue.computed(() => {
1442
- var _a;
1443
- if (position.value && vue.toValue(isActive)) {
1444
- return (_a = viewer.value) == null ? void 0 : _a.scene.drillPick(
1445
- position.value,
1446
- vue.toValue(limit),
1447
- vue.toValue(width),
1448
- vue.toValue(height)
1449
- );
1450
- }
1451
- });
1452
- return pick;
1453
- }
1454
- exports.CREATE_VIEWER_COLLECTION = CREATE_VIEWER_COLLECTION;
1455
- exports.CREATE_VIEWER_INJECTION_KEY = CREATE_VIEWER_INJECTION_KEY;
1456
- exports.CesiumMaterial = CesiumMaterial;
1457
- exports.addMaterialCache = addMaterialCache;
1458
- exports.arrayDiff = arrayDiff;
1459
- exports.assertError = assertError;
1460
- exports.canvasCoordToCartesian = canvasCoordToCartesian;
1461
- exports.cartesianToCanvasCoord = cartesianToCanvasCoord;
1462
- exports.cesiumEquals = cesiumEquals;
1463
- exports.createCesiumAttribute = createCesiumAttribute;
1464
- exports.createCesiumProperty = createCesiumProperty;
1465
- exports.createPropertyField = createPropertyField;
1466
- exports.createViewer = createViewer;
1467
- exports.degreesToDms = degreesToDms;
1468
- exports.dmsDecode = dmsDecode;
1469
- exports.dmsEncode = dmsEncode;
1470
- exports.dmsToDegrees = dmsToDegrees;
1471
- exports.getMaterialCache = getMaterialCache;
1472
- exports.isArray = isArray;
1473
- exports.isBase64 = isBase64;
1474
- exports.isBoolean = isBoolean;
1475
- exports.isCesiumConstant = isCesiumConstant;
1476
- exports.isDef = isDef;
1477
- exports.isElement = isElement;
1478
- exports.isFunction = isFunction;
1479
- exports.isNumber = isNumber;
1480
- exports.isObject = isObject;
1481
- exports.isPromise = isPromise;
1482
- exports.isProperty = isProperty;
1483
- exports.isString = isString;
1484
- exports.isWindow = isWindow;
1485
- exports.pickHitGraphic = pickHitGraphic;
1486
- exports.resolvePick = resolvePick;
1487
- exports.throttle = throttle;
1488
- exports.toCartesian3 = toCartesian3;
1489
- exports.toCartographic = toCartographic;
1490
- exports.toCoord = toCoord;
1491
- exports.toPromiseValue = toPromiseValue;
1492
- exports.toProperty = toProperty;
1493
- exports.toPropertyValue = toPropertyValue;
1494
- exports.tryRun = tryRun;
1495
- exports.useCameraState = useCameraState;
1496
- exports.useCesiumEventListener = useCesiumEventListener;
1497
- exports.useCesiumFps = useCesiumFps;
1498
- exports.useCollectionScope = useCollectionScope;
1499
- exports.useDataSource = useDataSource;
1500
- exports.useDataSourceScope = useDataSourceScope;
1501
- exports.useElementOverlay = useElementOverlay;
1502
- exports.useEntity = useEntity;
1503
- exports.useEntityScope = useEntityScope;
1504
- exports.useGraphicEvent = useGraphicEvent;
1505
- exports.useImageryLayer = useImageryLayer;
1506
- exports.useImageryLayerScope = useImageryLayerScope;
1507
- exports.usePostProcessStage = usePostProcessStage;
1508
- exports.usePostProcessStageScope = usePostProcessStageScope;
1509
- exports.usePrimitive = usePrimitive;
1510
- exports.usePrimitiveScope = usePrimitiveScope;
1511
- exports.useScaleBar = useScaleBar;
1512
- exports.useSceneDrillPick = useSceneDrillPick;
1513
- exports.useScenePick = useScenePick;
1514
- exports.useScreenSpaceEventHandler = useScreenSpaceEventHandler;
1515
- exports.useViewer = useViewer;
1516
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
1517
- return exports;
1518
- }({}, VueUse, Cesium, Vue);
1519
- //# sourceMappingURL=index.iife.js.map
1
+ (function(exports, __vueuse_core, cesium, vue) {
2
+
3
+ //#region rolldown:runtime
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
21
+ value: mod,
22
+ enumerable: true
23
+ }) : target, mod));
24
+
25
+ //#endregion
26
+ __vueuse_core = __toESM(__vueuse_core);
27
+ cesium = __toESM(cesium);
28
+ vue = __toESM(vue);
29
+
30
+ //#region createViewer/index.ts
31
+ /**
32
+ * @internal
33
+ */
34
+ const CREATE_VIEWER_INJECTION_KEY = Symbol("CREATE_VIEWER_INJECTION_KEY");
35
+ /**
36
+ * @internal
37
+ */
38
+ const CREATE_VIEWER_COLLECTION = /* @__PURE__ */ new WeakMap();
39
+ function createViewer(...args) {
40
+ const viewer = (0, vue.shallowRef)();
41
+ const readonlyViewer = (0, vue.shallowReadonly)(viewer);
42
+ (0, vue.provide)(CREATE_VIEWER_INJECTION_KEY, readonlyViewer);
43
+ const scope = (0, vue.getCurrentScope)();
44
+ if (scope) CREATE_VIEWER_COLLECTION.set(scope, readonlyViewer);
45
+ const canvas = (0, vue.computed)(() => viewer.value?.canvas);
46
+ (0, __vueuse_core.useMutationObserver)(document?.body, () => {
47
+ if (canvas.value && !document?.body.contains(canvas.value)) viewer.value = void 0;
48
+ }, {
49
+ childList: true,
50
+ subtree: true
51
+ });
52
+ (0, vue.watchEffect)((onCleanup) => {
53
+ const [arg1, arg2] = args;
54
+ const value = (0, vue.toRaw)((0, vue.toValue)(arg1));
55
+ if (value instanceof cesium.Viewer) viewer.value = (0, vue.markRaw)(value);
56
+ else if (value) {
57
+ const element = value;
58
+ const options = arg2;
59
+ viewer.value = new cesium.Viewer(element, options);
60
+ onCleanup(() => !viewer.value?.isDestroyed() && viewer.value?.destroy());
61
+ } else viewer.value = void 0;
62
+ });
63
+ (0, __vueuse_core.tryOnScopeDispose)(() => {
64
+ viewer.value = void 0;
65
+ });
66
+ return (0, vue.computed)(() => {
67
+ return viewer.value?.isDestroyed() ? void 0 : viewer.value;
68
+ });
69
+ }
70
+
71
+ //#endregion
72
+ //#region utils/arrayDiff.ts
73
+ /**
74
+ * 计算两个数组的差异,返回新增和删除的元素
75
+ */
76
+ function arrayDiff(list, oldList) {
77
+ const oldListSet = new Set(oldList);
78
+ const added = list.filter((obj) => !oldListSet.has(obj));
79
+ const newListSet = new Set(list);
80
+ const removed = oldList?.filter((obj) => !newListSet.has(obj)) ?? [];
81
+ return {
82
+ added,
83
+ removed
84
+ };
85
+ }
86
+
87
+ //#endregion
88
+ //#region utils/canvasCoordToCartesian.ts
89
+ /**
90
+ * Convert canvas coordinates to Cartesian coordinates
91
+ *
92
+ * @param canvasCoord Canvas coordinates
93
+ * @param scene Cesium.Scene instance
94
+ * @param mode optional values are 'pickPosition' | 'globePick' | 'auto' | 'noHeight' @default 'auto'
95
+ *
96
+ * `pickPosition`: Use scene.pickPosition for conversion, which can be used for picking models, oblique photography, etc.
97
+ * However, if depth detection is not enabled (globe.depthTestAgainstTerrain=false), picking terrain or inaccurate issues may occur
98
+ *
99
+ * `globePick`: Use camera.getPickRay for conversion, which cannot be used for picking models or oblique photography,
100
+ * but can be used for picking terrain. If terrain does not exist, the picked elevation is 0
101
+ *
102
+ * `auto`: Automatically determine which picking content to return
103
+ *
104
+ * Calculation speed comparison: globePick > auto >= pickPosition
105
+ */
106
+ function canvasCoordToCartesian(canvasCoord, scene, mode = "auto") {
107
+ if (mode === "pickPosition") return scene.pickPosition(canvasCoord);
108
+ else if (mode === "globePick") {
109
+ const ray = scene.camera.getPickRay(canvasCoord);
110
+ return ray && scene.globe.pick(ray, scene);
111
+ } else {
112
+ if (scene.globe.depthTestAgainstTerrain) return scene.pickPosition(canvasCoord);
113
+ const position1 = scene.pickPosition(canvasCoord);
114
+ const ray = scene.camera.getPickRay(canvasCoord);
115
+ const position2 = ray && scene.globe.pick(ray, scene);
116
+ if (!position1) return position2;
117
+ const height1 = (position1 && cesium.Ellipsoid.WGS84.cartesianToCartographic(position1).height) ?? 0;
118
+ const height2 = (position2 && cesium.Ellipsoid.WGS84.cartesianToCartographic(position2).height) ?? 0;
119
+ return height1 < height2 ? position1 : position2;
120
+ }
121
+ }
122
+
123
+ //#endregion
124
+ //#region utils/cartesianToCanvasCoord.ts
125
+ /**
126
+ * Convert Cartesian coordinates to canvas coordinates
127
+ *
128
+ * @param position Cartesian coordinates
129
+ * @param scene Cesium.Scene instance
130
+ */
131
+ function cartesianToCanvasCoord(position, scene) {
132
+ return scene.cartesianToCanvasCoordinates(position);
133
+ }
134
+
135
+ //#endregion
136
+ //#region utils/is.ts
137
+ const toString = Object.prototype.toString;
138
+ function isDef(val) {
139
+ return typeof val !== "undefined";
140
+ }
141
+ function isBoolean(val) {
142
+ return typeof val === "boolean";
143
+ }
144
+ function isFunction(val) {
145
+ return typeof val === "function";
146
+ }
147
+ function isNumber(val) {
148
+ return typeof val === "number";
149
+ }
150
+ function isString(val) {
151
+ return typeof val === "string";
152
+ }
153
+ function isObject(val) {
154
+ return toString.call(val) === "[object Object]";
155
+ }
156
+ function isWindow(val) {
157
+ return typeof window !== "undefined" && toString.call(val) === "[object Window]";
158
+ }
159
+ function isPromise(val) {
160
+ return !!val && (typeof val === "object" || typeof val === "function") && typeof val.then === "function";
161
+ }
162
+ function isElement(val) {
163
+ return !!(val && val.nodeName && val.nodeType === 1);
164
+ }
165
+ const isArray = Array.isArray;
166
+ function isBase64(val) {
167
+ const reg = /^\s*data:([a-z]+\/[\d+.a-z-]+(;[a-z-]+=[\da-z-]+)?)?(;base64)?,([\s\w!$%&'()*+,./:;=?@~-]*?)\s*$/i;
168
+ return reg.test(val);
169
+ }
170
+ function assertError(condition, error) {
171
+ if (condition) throw new Error(error);
172
+ }
173
+
174
+ //#endregion
175
+ //#region utils/cesiumEquals.ts
176
+ /**
177
+ * Determines if two Cesium objects are equal.
178
+ *
179
+ * This function not only judges whether the instances are equal,
180
+ * but also judges the equals method in the example.
181
+ *
182
+ * @param left The first Cesium object
183
+ * @param right The second Cesium object
184
+ * @returns Returns true if the two Cesium objects are equal, otherwise false
185
+ */
186
+ function cesiumEquals(left, right) {
187
+ return left === right || isFunction(left?.equals) && left.equals(right) || isFunction(right?.equals) && right.equals(left);
188
+ }
189
+
190
+ //#endregion
191
+ //#region utils/toCoord.ts
192
+ /**
193
+ * Converts coordinates to an array or object in the specified format.
194
+ *
195
+ * @param position The coordinate to be converted, which can be a Cartesian3, Cartographic, array, or object.
196
+ * @param options Conversion options, including conversion type and whether to include altitude information.
197
+ * @returns The converted coordinate, which may be an array or object. If the input position is empty, undefined is returned.
198
+ *
199
+ * @template T Conversion type, optional values are 'Array' or 'Object', @default 'Array'.
200
+ * @template Alt Whether to include altitude information, default is false
201
+ */
202
+ function toCoord(position, options = {}) {
203
+ if (!position) return void 0;
204
+ const { type = "Array", alt = false } = options;
205
+ let longitude, latitude, height;
206
+ if (position instanceof cesium.Cartesian3) {
207
+ const cartographic = cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
208
+ longitude = cesium.Math.toDegrees(cartographic.longitude);
209
+ latitude = cesium.Math.toDegrees(cartographic.latitude);
210
+ height = cartographic.height;
211
+ } else if (position instanceof cesium.Cartographic) {
212
+ const cartographic = position;
213
+ longitude = cesium.Math.toDegrees(cartographic.longitude);
214
+ latitude = cesium.Math.toDegrees(cartographic.latitude);
215
+ height = cartographic.height;
216
+ } else if (Array.isArray(position)) {
217
+ longitude = cesium.Math.toDegrees(position[0]);
218
+ latitude = cesium.Math.toDegrees(position[1]);
219
+ height = position[2];
220
+ } else {
221
+ longitude = position.longitude;
222
+ latitude = position.latitude;
223
+ height = position.height;
224
+ }
225
+ if (type === "Array") return alt ? [
226
+ longitude,
227
+ latitude,
228
+ height
229
+ ] : [longitude, latitude];
230
+ else return alt ? {
231
+ longitude,
232
+ latitude,
233
+ height
234
+ } : {
235
+ longitude,
236
+ latitude
237
+ };
238
+ }
239
+
240
+ //#endregion
241
+ //#region utils/convertDMS.ts
242
+ /**
243
+ * Convert degrees to DMS (Degrees Minutes Seconds) format string
244
+ *
245
+ * @param degrees The angle value
246
+ * @param precision The number of decimal places to retain for the seconds, defaults to 3
247
+ * @returns A DMS formatted string in the format: degrees° minutes′ seconds″
248
+ */
249
+ function dmsEncode(degrees, precision = 3) {
250
+ const str = `${degrees}`;
251
+ let i = str.indexOf(".");
252
+ const d = i < 0 ? str : str.slice(0, Math.max(0, i));
253
+ let m = "0";
254
+ let s = "0";
255
+ if (i > 0) {
256
+ m = `0${str.slice(Math.max(0, i))}`;
257
+ m = `${+m * 60}`;
258
+ i = m.indexOf(".");
259
+ if (i > 0) {
260
+ s = `0${m.slice(Math.max(0, i))}`;
261
+ m = m.slice(0, Math.max(0, i));
262
+ s = `${+s * 60}`;
263
+ i = s.indexOf(".");
264
+ s = s.slice(0, Math.max(0, i + 4));
265
+ s = (+s).toFixed(precision);
266
+ }
267
+ }
268
+ return `${Math.abs(+d)}°${+m}′${+s}″`;
269
+ }
270
+ /**
271
+ * Decode a DMS (Degrees Minutes Seconds) formatted string to a decimal angle value
272
+ *
273
+ * @param dmsCode DMS formatted string, e.g. "120°30′45″N"
274
+ * @returns The decoded decimal angle value, or 0 if decoding fails
275
+ */
276
+ function dmsDecode(dmsCode) {
277
+ const [dd, msStr] = dmsCode.split("°") ?? [];
278
+ const [mm, sStr] = msStr?.split("′") ?? [];
279
+ const ss = sStr?.split("″")[0];
280
+ const d = Number(dd) || 0;
281
+ const m = (Number(mm) || 0) / 60;
282
+ const s = (Number(ss) || 0) / 60 / 60;
283
+ const degrees = d + m + s;
284
+ if (degrees === 0) return 0;
285
+ else {
286
+ let res = degrees;
287
+ if ([
288
+ "W",
289
+ "w",
290
+ "S",
291
+ "s"
292
+ ].includes(dmsCode[dmsCode.length - 1])) res = -res;
293
+ return res;
294
+ }
295
+ }
296
+ /**
297
+ * Convert latitude and longitude coordinates to degrees-minutes-seconds format
298
+ *
299
+ * @param position The latitude and longitude coordinates
300
+ * @param precision The number of decimal places to retain for 'seconds', default is 3
301
+ * @returns Returns the coordinates in degrees-minutes-seconds format, or undefined if the conversion fails
302
+ */
303
+ function degreesToDms(position, precision = 3) {
304
+ const coord = toCoord(position, { alt: true });
305
+ if (!coord) return;
306
+ const [longitude, latitude, height] = coord;
307
+ const x = dmsEncode(longitude, precision);
308
+ const y = dmsEncode(latitude, precision);
309
+ return [
310
+ `${x}${longitude > 0 ? "E" : "W"}`,
311
+ `${y}${latitude > 0 ? "N" : "S"}`,
312
+ height
313
+ ];
314
+ }
315
+ /**
316
+ * Convert DMS (Degrees Minutes Seconds) format to decimal degrees for latitude and longitude coordinates
317
+ *
318
+ * @param dms The latitude or longitude coordinate in DMS format
319
+ * @returns Returns the coordinate in decimal degrees format, or undefined if the conversion fails
320
+ */
321
+ function dmsToDegrees(dms) {
322
+ const [x, y, height] = dms;
323
+ const longitude = dmsDecode(x);
324
+ const latitude = dmsDecode(y);
325
+ return [
326
+ longitude,
327
+ latitude,
328
+ Number(height) || 0
329
+ ];
330
+ }
331
+
332
+ //#endregion
333
+ //#region utils/isCesiumConstant.ts
334
+ /**
335
+ * Determines if the Cesium property is a constant.
336
+ *
337
+ * @param value Cesium property
338
+ */
339
+ function isCesiumConstant(value) {
340
+ return !(0, cesium.defined)(value) || !!value.isConstant;
341
+ }
342
+
343
+ //#endregion
344
+ //#region utils/material.ts
345
+ /**
346
+ * Only as a type fix for `Cesium.Material`
347
+ */
348
+ var CesiumMaterial = class extends cesium.Material {
349
+ constructor(options) {
350
+ super(options);
351
+ }
352
+ };
353
+ /**
354
+ * Get material from cache, alias of `Material._materialCache.getMaterial`
355
+ */
356
+ function getMaterialCache(type) {
357
+ return cesium.Material._materialCache.getMaterial(type);
358
+ }
359
+ /**
360
+ * Add material to Cesium's material cache, alias of `Material._materialCache.addMaterial`
361
+ */
362
+ function addMaterialCache(type, material) {
363
+ return cesium.Material._materialCache.addMaterial(type, material);
364
+ }
365
+
366
+ //#endregion
367
+ //#region utils/pick.ts
368
+ /**
369
+ * Analyze the result of Cesium's `scene.pick` and convert it to an array format
370
+ */
371
+ function resolvePick(pick = {}) {
372
+ const { primitive, id, primitiveCollection, collection } = pick;
373
+ const entityCollection = id && id.entityCollection || null;
374
+ const dataSource = entityCollection && entityCollection.owner || null;
375
+ const ids = Array.isArray(id) ? id : [id].filter(Boolean);
376
+ return [
377
+ ...ids,
378
+ primitive,
379
+ primitiveCollection,
380
+ collection,
381
+ entityCollection,
382
+ dataSource
383
+ ].filter((e) => !!e);
384
+ }
385
+ /**
386
+ * Determine if the given array of graphics is hit by Cesium's `scene.pick`
387
+ *
388
+ * @param pick The `scene.pick` object used for matching
389
+ * @param graphic An array of graphics to check for hits
390
+ */
391
+ function pickHitGraphic(pick, graphic) {
392
+ if (!Array.isArray(graphic) || !graphic.length) return false;
393
+ const elements = resolvePick(pick);
394
+ if (!elements.length) return false;
395
+ return elements.some((element) => graphic.includes(element));
396
+ }
397
+
398
+ //#endregion
399
+ //#region utils/property.ts
400
+ /**
401
+ * Is Cesium.Property
402
+ * @param value - The target object
403
+ */
404
+ function isProperty(value) {
405
+ return value && isFunction(value.getValue);
406
+ }
407
+ /**
408
+ * Converts a value that may be a Property into its target value, @see {toProperty} for the reverse operation
409
+ * ```typescript
410
+ * toPropertyValue('val') //=> 'val'
411
+ * toPropertyValue(new ConstantProperty('val')) //=> 'val'
412
+ * toPropertyValue(new CallbackProperty(()=>'val')) //=> 'val'
413
+ * ```
414
+ *
415
+ * @param value - The value to convert
416
+ */
417
+ function toPropertyValue(value, time) {
418
+ return isProperty(value) ? value.getValue(time) : value;
419
+ }
420
+ /**
421
+ * Converts a value that may be a Property into a Property object, @see {toPropertyValue} for the reverse operation
422
+ *
423
+ * @param value - The property value or getter to convert, can be undefined or null
424
+ * @param isConstant - The second parameter for converting to CallbackProperty
425
+ * @returns Returns the converted Property object, if value is undefined or null, returns undefined
426
+ */
427
+ function toProperty(value, isConstant = false) {
428
+ return isProperty(value) ? value : isFunction(value) ? new cesium.CallbackProperty(value, isConstant) : new cesium.ConstantProperty(value);
429
+ }
430
+ /**
431
+ * Create a Cesium property key
432
+ *
433
+ * @param scope The host object
434
+ * @param field The property name
435
+ * @param maybeProperty Optional property or getter
436
+ * @param readonly Whether the property is read-only
437
+ */
438
+ function createPropertyField(scope, field, maybeProperty, readonly$2) {
439
+ let removeOwnerListener;
440
+ const ownerBinding = (value) => {
441
+ removeOwnerListener?.();
442
+ if ((0, cesium.defined)(value?.definitionChanged)) removeOwnerListener = value?.definitionChanged?.addEventListener(() => {
443
+ scope.definitionChanged.raiseEvent(scope, field, value, value);
444
+ });
445
+ };
446
+ const privateField = `_${field}`;
447
+ const property = toProperty(maybeProperty);
448
+ scope[privateField] = property;
449
+ ownerBinding(property);
450
+ if (readonly$2) Object.defineProperty(scope, field, { get() {
451
+ return scope[privateField];
452
+ } });
453
+ else Object.defineProperty(scope, field, {
454
+ get() {
455
+ return scope[privateField];
456
+ },
457
+ set(value) {
458
+ const previous = scope[privateField];
459
+ if (scope[privateField] !== value) {
460
+ scope[privateField] = value;
461
+ ownerBinding(value);
462
+ if ((0, cesium.defined)(scope.definitionChanged)) scope.definitionChanged.raiseEvent(scope, field, value, previous);
463
+ }
464
+ }
465
+ });
466
+ }
467
+ function createCesiumAttribute(scope, key, value, options = {}) {
468
+ const allowToProperty = !!options.toProperty;
469
+ const shallowClone = !!options.shallowClone;
470
+ const changedEventKey = options.changedEventKey || "definitionChanged";
471
+ const changedEvent = Reflect.get(scope, changedEventKey);
472
+ const privateKey = `_${String(key)}`;
473
+ const attribute = allowToProperty ? toProperty(value) : value;
474
+ Reflect.set(scope, privateKey, attribute);
475
+ const obj = { get() {
476
+ const value$1 = Reflect.get(scope, privateKey);
477
+ if (shallowClone) return Array.isArray(value$1) ? [...value$1] : { ...value$1 };
478
+ else return value$1;
479
+ } };
480
+ let previousListener;
481
+ const serial = (property, previous) => {
482
+ previousListener?.();
483
+ previousListener = property?.definitionChanged?.addEventListener(() => {
484
+ changedEvent?.raiseEvent.bind(changedEvent)(scope, key, property, previous);
485
+ });
486
+ };
487
+ if (!options.readonly) {
488
+ if (allowToProperty && isProperty(value)) serial(value);
489
+ obj.set = (value$1) => {
490
+ if (allowToProperty && !isProperty(value$1)) throw new Error(`The value of ${String(key)} must be a Cesium.Property object`);
491
+ const previous = Reflect.get(scope, privateKey);
492
+ if (previous !== value$1) {
493
+ Reflect.set(scope, privateKey, value$1);
494
+ changedEvent?.raiseEvent.bind(changedEvent)(scope, key, value$1, previous);
495
+ if (allowToProperty) serial(value$1);
496
+ }
497
+ };
498
+ }
499
+ Object.defineProperty(scope, key, obj);
500
+ }
501
+ function createCesiumProperty(scope, key, value, options = {}) {
502
+ return createCesiumAttribute(scope, key, value, {
503
+ ...options,
504
+ toProperty: true
505
+ });
506
+ }
507
+
508
+ //#endregion
509
+ //#region utils/throttle.ts
510
+ /**
511
+ * Throttle function, which limits the frequency of execution of the function
512
+ *
513
+ * @param callback raw function
514
+ * @param delay Throttled delay duration (ms)
515
+ * @param trailing Trigger callback function after last call @default true
516
+ * @param leading Trigger the callback function immediately on the first call @default false
517
+ * @returns Throttle function
518
+ */
519
+ function throttle(callback, delay = 100, trailing = true, leading = false) {
520
+ const restList = [];
521
+ let tracked = false;
522
+ const trigger = async () => {
523
+ await (0, __vueuse_core.promiseTimeout)(delay);
524
+ tracked = false;
525
+ if (leading) try {
526
+ callback(...restList[0]);
527
+ } catch (error) {
528
+ console.error(error);
529
+ }
530
+ if (trailing && (!leading || restList.length > 1)) try {
531
+ callback(...restList[restList.length - 1]);
532
+ } catch (error) {
533
+ console.error(error);
534
+ }
535
+ restList.length = 0;
536
+ };
537
+ return (...rest) => {
538
+ if (restList.length < 2) restList.push(rest);
539
+ else restList[1] = rest;
540
+ if (!tracked) {
541
+ tracked = true;
542
+ trigger();
543
+ }
544
+ };
545
+ }
546
+
547
+ //#endregion
548
+ //#region utils/toCartesian3.ts
549
+ /**
550
+ * Converts position to a coordinate point in the Cartesian coordinate system
551
+ *
552
+ * @param position Position information, which can be a Cartesian coordinate point (Cartesian3), a geographic coordinate point (Cartographic), an array, or an object containing WGS84 latitude, longitude, and height information
553
+ * @returns The converted Cartesian coordinate point. If the input parameter is invalid, undefined is returned
554
+ */
555
+ function toCartesian3(position) {
556
+ if (!position) return void 0;
557
+ if (position instanceof cesium.Cartesian3) return position.clone();
558
+ else if (position instanceof cesium.Cartographic) return cesium.Ellipsoid.WGS84.cartographicToCartesian(position);
559
+ else if (Array.isArray(position)) return cesium.Cartesian3.fromDegrees(position[0], position[1], position[2]);
560
+ else return cesium.Cartesian3.fromDegrees(position.longitude, position.latitude, position.height);
561
+ }
562
+
563
+ //#endregion
564
+ //#region utils/toCartographic.ts
565
+ /**
566
+ * Converts a position to a Cartographic coordinate point
567
+ *
568
+ * @param position Position information, which can be a Cartesian3 coordinate point, a Cartographic coordinate point, an array, or an object containing WGS84 longitude, latitude, and height information
569
+ * @returns The converted Cartographic coordinate point, or undefined if the input parameter is invalid
570
+ */
571
+ function toCartographic(position) {
572
+ if (!position) return void 0;
573
+ if (position instanceof cesium.Cartesian3) return cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
574
+ else if (position instanceof cesium.Cartographic) return position.clone();
575
+ else if (Array.isArray(position)) return cesium.Cartographic.fromDegrees(position[0], position[1], position[2]);
576
+ else return cesium.Cartographic.fromDegrees(position.longitude, position.latitude, position.height);
577
+ }
578
+
579
+ //#endregion
580
+ //#region utils/tryRun.ts
581
+ /**
582
+ * Safely execute the provided function without throwing errors,
583
+ * essentially a simple wrapper around a `try...catch...` block
584
+ */
585
+ function tryRun(fn) {
586
+ return (...args) => {
587
+ try {
588
+ return fn?.(...args);
589
+ } catch (error) {
590
+ console.error(error);
591
+ }
592
+ };
593
+ }
594
+
595
+ //#endregion
596
+ //#region toPromiseValue/index.ts
597
+ /**
598
+ * Similar to Vue's built-in `toValue`, but capable of handling asynchronous functions, thus returning a `await value`.
599
+ *
600
+ * Used in conjunction with VueUse's `computedAsync`.
601
+ *
602
+ * @param source The source value, which can be a reactive reference or an asynchronous getter.
603
+ * @param options Conversion options
604
+ *
605
+ * @example
606
+ * ```ts
607
+ *
608
+ * const data = computedAsync(async ()=> {
609
+ * return await toPromiseValue(promiseRef)
610
+ * })
611
+ *
612
+ * ```
613
+ */
614
+ async function toPromiseValue(source, options = {}) {
615
+ try {
616
+ const { raw = true } = options;
617
+ let value;
618
+ if (isFunction(source)) value = await source();
619
+ else {
620
+ const result = (0, vue.toValue)(source);
621
+ value = isPromise(result) ? await result : result;
622
+ }
623
+ return raw ? (0, vue.toRaw)(value) : value;
624
+ } catch (error) {
625
+ console.error(error);
626
+ throw error;
627
+ }
628
+ }
629
+
630
+ //#endregion
631
+ //#region useCesiumEventListener/index.ts
632
+ /**
633
+ * Easily use the `addEventListener` in `Cesium.Event` instances,
634
+ * when the dependent data changes or the component is unmounted,
635
+ * the listener function will automatically reload or destroy.
636
+ */
637
+ function useCesiumEventListener(event, listener, options = {}) {
638
+ const isActive = (0, vue.toRef)(options.isActive ?? true);
639
+ const cleanup = (0, vue.watchEffect)((onCleanup) => {
640
+ const _event = (0, vue.toValue)(event);
641
+ const events = Array.isArray(_event) ? _event : [_event];
642
+ if (events) {
643
+ if (events.length && isActive.value) {
644
+ const stopFns = events.map((event$1) => {
645
+ const e = (0, vue.toValue)(event$1);
646
+ return e?.addEventListener(listener, e);
647
+ });
648
+ onCleanup(() => stopFns.forEach((stop) => stop?.()));
649
+ }
650
+ }
651
+ });
652
+ (0, __vueuse_core.tryOnScopeDispose)(cleanup.stop);
653
+ return cleanup.stop;
654
+ }
655
+
656
+ //#endregion
657
+ //#region useViewer/index.ts
658
+ /**
659
+ * Obtain the `Viewer` instance injected through `createViewer` in the current component or its ancestor components.
660
+ *
661
+ * note:
662
+ * - If `createViewer` and `useViewer` are called in the same component, the `Viewer` instance injected by `createViewer` will be used preferentially.
663
+ * - When calling `createViewer` and `useViewer` in the same component, `createViewer` should be called before `useViewer`.
664
+ */
665
+ function useViewer() {
666
+ const scope = (0, vue.getCurrentScope)();
667
+ const instanceViewer = scope ? CREATE_VIEWER_COLLECTION.get(scope) : void 0;
668
+ if (instanceViewer) return instanceViewer;
669
+ else {
670
+ const injectViewer = (0, vue.inject)(CREATE_VIEWER_INJECTION_KEY);
671
+ if (!injectViewer) throw new Error("The `Viewer` instance injected by `createViewer` was not found in the current component or its ancestor components. Have you called `createViewer`?");
672
+ return injectViewer;
673
+ }
674
+ }
675
+
676
+ //#endregion
677
+ //#region useCameraState/index.ts
678
+ /**
679
+ * Reactive Cesium Camera state
680
+ */
681
+ function useCameraState(options = {}) {
682
+ let getCamera = options.camera;
683
+ if (!getCamera) {
684
+ const viewer = useViewer();
685
+ getCamera = () => viewer.value?.scene.camera;
686
+ }
687
+ const camera = (0, vue.computed)(() => (0, vue.toValue)(getCamera));
688
+ const event = (0, vue.computed)(() => {
689
+ const eventField = (0, vue.toValue)(options.event) || "changed";
690
+ return camera.value?.[eventField];
691
+ });
692
+ const changedSymbol = (0, __vueuse_core.refThrottled)((0, vue.shallowRef)(Symbol("camera change")), options.delay ?? 8, true, false);
693
+ const setChangedSymbol = () => {
694
+ changedSymbol.value = Symbol("camera change");
695
+ };
696
+ (0, vue.watch)(camera, () => setChangedSymbol());
697
+ useCesiumEventListener(event, () => setChangedSymbol());
698
+ return {
699
+ camera,
700
+ position: (0, vue.computed)(() => changedSymbol.value ? camera.value?.position?.clone() : void 0),
701
+ direction: (0, vue.computed)(() => changedSymbol.value ? camera.value?.direction?.clone() : void 0),
702
+ up: (0, vue.computed)(() => changedSymbol.value ? camera.value?.up?.clone() : void 0),
703
+ right: (0, vue.computed)(() => changedSymbol.value ? camera.value?.right?.clone() : void 0),
704
+ positionCartographic: (0, vue.computed)(() => changedSymbol.value ? camera.value?.positionCartographic?.clone() : void 0),
705
+ positionWC: (0, vue.computed)(() => changedSymbol.value ? camera.value?.positionWC?.clone() : void 0),
706
+ directionWC: (0, vue.computed)(() => changedSymbol.value ? camera.value?.directionWC?.clone() : void 0),
707
+ upWC: (0, vue.computed)(() => changedSymbol.value ? camera.value?.directionWC?.clone() : void 0),
708
+ rightWC: (0, vue.computed)(() => changedSymbol.value ? camera.value?.directionWC?.clone() : void 0),
709
+ viewRectangle: (0, vue.computed)(() => changedSymbol.value ? camera.value?.computeViewRectangle() : void 0),
710
+ heading: (0, vue.computed)(() => changedSymbol.value ? camera.value?.heading : void 0),
711
+ pitch: (0, vue.computed)(() => changedSymbol.value ? camera.value?.pitch : void 0),
712
+ roll: (0, vue.computed)(() => changedSymbol.value ? camera.value?.roll : void 0),
713
+ level: (0, vue.computed)(() => changedSymbol.value && camera.value?.positionCartographic?.height ? computeLevel(camera.value.positionCartographic.height) : void 0)
714
+ };
715
+ }
716
+ const A = 40487.57;
717
+ const B = 7096758e-11;
718
+ const C = 91610.74;
719
+ const D = -40467.74;
720
+ /**
721
+ * Compute the camera level at a given height.
722
+ */
723
+ function computeLevel(height) {
724
+ return D + (A - D) / (1 + (height / C) ** B);
725
+ }
726
+
727
+ //#endregion
728
+ //#region useCesiumFps/index.ts
729
+ /**
730
+ * Reactive get the frame rate of Cesium
731
+ */
732
+ function useCesiumFps(options = {}) {
733
+ const { delay = 100 } = options;
734
+ const viewer = useViewer();
735
+ const p = (0, vue.shallowRef)(performance.now());
736
+ useCesiumEventListener(() => viewer.value?.scene.postRender, () => p.value = performance.now());
737
+ const interval = (0, vue.ref)(0);
738
+ (0, __vueuse_core.watchThrottled)(p, (value, oldValue) => {
739
+ interval.value = value - oldValue;
740
+ }, { throttle: delay });
741
+ const fps = (0, vue.computed)(() => {
742
+ return 1e3 / interval.value;
743
+ });
744
+ return {
745
+ interval: (0, vue.readonly)(interval),
746
+ fps
747
+ };
748
+ }
749
+
750
+ //#endregion
751
+ //#region useCollectionScope/index.ts
752
+ /**
753
+ * Scope the SideEffects of Cesium-related `Collection` and automatically remove them when unmounted.
754
+ * - note: This is a basic function that is intended to be called by other lower-level function
755
+ * @param addFn - add SideEffect function. eg.`entites.add`
756
+ * @param removeFn - Clean SideEffect function. eg.`entities.remove`
757
+ * @param removeScopeArgs - The parameters to pass for `removeScope` triggered when the component is unmounted
758
+ */
759
+ function useCollectionScope(addFn, removeFn, removeScopeArgs) {
760
+ const scope = (0, vue.shallowReactive)(/* @__PURE__ */ new Set());
761
+ const add = (instance, ...args) => {
762
+ const result = addFn(instance, ...args);
763
+ if (isPromise(result)) return new Promise((resolve, reject) => {
764
+ result.then((i) => {
765
+ scope.add(i);
766
+ resolve(i);
767
+ }).catch((error) => reject(error));
768
+ });
769
+ else {
770
+ scope.add(result);
771
+ return result;
772
+ }
773
+ };
774
+ const remove = (instance, ...args) => {
775
+ scope.delete(instance);
776
+ return removeFn(instance, ...args);
777
+ };
778
+ const removeWhere = (predicate, ...args) => {
779
+ scope.forEach((instance) => {
780
+ if (predicate(instance)) remove(instance, ...args);
781
+ });
782
+ };
783
+ const removeScope = (...args) => {
784
+ scope.forEach((instance) => {
785
+ remove(instance, ...args);
786
+ });
787
+ };
788
+ (0, __vueuse_core.tryOnScopeDispose)(() => removeScope(...removeScopeArgs));
789
+ return {
790
+ scope: (0, vue.shallowReadonly)(scope),
791
+ add,
792
+ remove,
793
+ removeWhere,
794
+ removeScope
795
+ };
796
+ }
797
+
798
+ //#endregion
799
+ //#region useDataSource/index.ts
800
+ function useDataSource(dataSources, options = {}) {
801
+ const { destroyOnRemove, collection, isActive = true, evaluating } = options;
802
+ const result = (0, __vueuse_core.computedAsync)(() => toPromiseValue(dataSources), void 0, { evaluating });
803
+ const viewer = useViewer();
804
+ (0, vue.watchEffect)((onCleanup) => {
805
+ const _isActive = (0, vue.toValue)(isActive);
806
+ if (_isActive) {
807
+ const list = Array.isArray(result.value) ? [...result.value] : [result.value];
808
+ const _collection = collection ?? viewer.value?.dataSources;
809
+ list.forEach((item) => item && _collection?.add(item));
810
+ onCleanup(() => {
811
+ const destroy = (0, vue.toValue)(destroyOnRemove);
812
+ !_collection?.isDestroyed() && list.forEach((dataSource) => dataSource && _collection?.remove(dataSource, destroy));
813
+ });
814
+ }
815
+ });
816
+ return result;
817
+ }
818
+
819
+ //#endregion
820
+ //#region useDataSourceScope/index.ts
821
+ /**
822
+ * // Scope the SideEffects of `DataSourceCollection` operations and automatically remove them when unmounted
823
+ */
824
+ function useDataSourceScope(options = {}) {
825
+ const { collection: _collection, destroyOnRemove } = options;
826
+ const viewer = useViewer();
827
+ const collection = (0, vue.computed)(() => {
828
+ return (0, vue.toValue)(_collection) ?? viewer.value?.dataSources;
829
+ });
830
+ const addFn = (dataSource) => {
831
+ if (!collection.value) throw new Error("collection is not defined");
832
+ return collection.value.add(dataSource);
833
+ };
834
+ const removeFn = (dataSource, destroy) => {
835
+ return !!collection.value?.remove(dataSource, destroy);
836
+ };
837
+ const { scope, add, remove, removeWhere, removeScope } = useCollectionScope(addFn, removeFn, [destroyOnRemove]);
838
+ return {
839
+ scope,
840
+ add,
841
+ remove,
842
+ removeWhere,
843
+ removeScope
844
+ };
845
+ }
846
+
847
+ //#endregion
848
+ //#region useElementOverlay/index.ts
849
+ /**
850
+ * Cesium HtmlElement Overlay
851
+ */
852
+ function useElementOverlay(target, position, options = {}) {
853
+ const { referenceWindow, horizontal = "center", vertical = "bottom", offset = {
854
+ x: 0,
855
+ y: 0
856
+ } } = options;
857
+ const cartesian3 = (0, vue.computed)(() => toCartesian3((0, vue.toValue)(position)));
858
+ const viewer = useViewer();
859
+ const coord = (0, vue.shallowRef)();
860
+ useCesiumEventListener(() => viewer.value?.scene.postRender, () => {
861
+ if (!viewer.value?.scene) return;
862
+ if (!cartesian3.value) coord.value = void 0;
863
+ else {
864
+ const reslut = cartesianToCanvasCoord(cartesian3.value, viewer.value.scene);
865
+ coord.value = !cesium.Cartesian2.equals(reslut, coord.value) ? reslut : coord.value;
866
+ }
867
+ });
868
+ const canvasBounding = (0, __vueuse_core.useElementBounding)(() => viewer.value?.canvas.parentElement);
869
+ const targetBounding = (0, __vueuse_core.useElementBounding)(target);
870
+ const finalOffset = (0, vue.computed)(() => {
871
+ const _offset = (0, vue.toValue)(offset);
872
+ let x$1 = _offset?.x ?? 0;
873
+ const _horizontal = (0, vue.toValue)(horizontal);
874
+ if (_horizontal === "center") x$1 -= targetBounding.width.value / 2;
875
+ else if (_horizontal === "right") x$1 -= targetBounding.width.value;
876
+ let y$1 = _offset?.y ?? 0;
877
+ const _vertical = (0, vue.toValue)(vertical);
878
+ if (_vertical === "center") y$1 -= targetBounding.height.value / 2;
879
+ else if (_vertical === "bottom") y$1 -= targetBounding.height.value;
880
+ return {
881
+ x: x$1,
882
+ y: y$1
883
+ };
884
+ });
885
+ const location = (0, vue.computed)(() => {
886
+ const data = {
887
+ x: coord.value?.x ?? 0,
888
+ y: coord.value?.y ?? 0
889
+ };
890
+ if ((0, vue.toValue)(referenceWindow)) {
891
+ data.x += canvasBounding.x.value;
892
+ data.y += canvasBounding.y.value;
893
+ }
894
+ return {
895
+ x: finalOffset.value.x + data.x,
896
+ y: finalOffset.value.y + data.y
897
+ };
898
+ });
899
+ const x = (0, vue.computed)(() => location.value.x);
900
+ const y = (0, vue.computed)(() => location.value.y);
901
+ const style = (0, vue.computed)(() => ({
902
+ left: `${x.value?.toFixed(2)}px`,
903
+ top: `${y.value?.toFixed(2)}px`
904
+ }));
905
+ (0, vue.watchEffect)(() => {
906
+ const element = (0, vue.toValue)(target);
907
+ if (element && (0, vue.toValue)(options.applyStyle ?? true)) {
908
+ element.style?.setProperty?.("left", style.value.left);
909
+ element.style?.setProperty?.("top", style.value.top);
910
+ }
911
+ });
912
+ return {
913
+ x,
914
+ y,
915
+ style
916
+ };
917
+ }
918
+
919
+ //#endregion
920
+ //#region useEntity/index.ts
921
+ function useEntity(data, options = {}) {
922
+ const { collection, isActive = true, evaluating } = options;
923
+ const result = (0, __vueuse_core.computedAsync)(() => toPromiseValue(data), [], { evaluating });
924
+ const viewer = useViewer();
925
+ (0, vue.watchEffect)((onCleanup) => {
926
+ const _isActive = (0, vue.toValue)(isActive);
927
+ if (_isActive) {
928
+ const list = Array.isArray(result.value) ? [...result.value] : [result.value];
929
+ const _collection = collection ?? viewer.value?.entities;
930
+ list.forEach((item) => item && _collection?.add(item));
931
+ onCleanup(() => {
932
+ list.forEach((item) => item && _collection?.remove(item));
933
+ });
934
+ }
935
+ });
936
+ return result;
937
+ }
938
+
939
+ //#endregion
940
+ //#region useEntityScope/index.ts
941
+ /**
942
+ * Make `add` and `remove` operations of `EntityCollection` scoped,
943
+ * automatically remove `Entity` instance when component is unmounted.
944
+ */
945
+ function useEntityScope(options = {}) {
946
+ const { collection: _collection } = options;
947
+ const viewer = useViewer();
948
+ const collection = (0, vue.computed)(() => {
949
+ return (0, vue.toValue)(_collection) ?? viewer.value?.entities;
950
+ });
951
+ const addFn = (entity) => {
952
+ if (!collection.value) throw new Error("collection is not defined");
953
+ if (!collection.value.contains(entity)) collection.value.add(entity);
954
+ return entity;
955
+ };
956
+ const removeFn = (entity) => {
957
+ return !!collection.value?.remove(entity);
958
+ };
959
+ const { scope, add, remove, removeWhere, removeScope } = useCollectionScope(addFn, removeFn, []);
960
+ return {
961
+ scope,
962
+ add,
963
+ remove,
964
+ removeWhere,
965
+ removeScope
966
+ };
967
+ }
968
+
969
+ //#endregion
970
+ //#region useScenePick/index.ts
971
+ const pickCache = /* @__PURE__ */ new WeakMap();
972
+ /**
973
+ * Uses the `scene.pick` function in Cesium's Scene object to perform screen point picking,
974
+ * return a computed property containing the pick result, or undefined if no object is picked.
975
+ *
976
+ * @param windowPosition The screen coordinates of the pick point.
977
+ */
978
+ function useScenePick(windowPosition, options = {}) {
979
+ const { width = 3, height = 3, throttled = 8 } = options;
980
+ const isActive = (0, vue.toRef)(options.isActive ?? true);
981
+ const viewer = useViewer();
982
+ const position = (0, __vueuse_core.refThrottled)((0, vue.computed)(() => (0, vue.toValue)(windowPosition)?.clone()), throttled, false, true);
983
+ const pick = (0, vue.shallowRef)();
984
+ (0, vue.watchEffect)(() => {
985
+ if (viewer.value && position.value && isActive.value) {
986
+ const cache = pickCache.get(viewer.value);
987
+ if (cache && cache[0].equals(position.value)) pick.value = cache[1];
988
+ else {
989
+ pickCache.set(viewer.value, [position.value.clone(), pick.value]);
990
+ pick.value = viewer.value?.scene.pick(position.value, (0, vue.toValue)(width), (0, vue.toValue)(height));
991
+ }
992
+ }
993
+ });
994
+ return pick;
995
+ }
996
+
997
+ //#endregion
998
+ //#region useScreenSpaceEventHandler/index.ts
999
+ /**
1000
+ * Easily use the `ScreenSpaceEventHandler`,
1001
+ * when the dependent data changes or the component is unmounted,
1002
+ * the listener function will automatically reload or destroy.
1003
+ *
1004
+ * @param type Types of mouse event
1005
+ * @param inputAction Callback function for listening
1006
+ */
1007
+ function useScreenSpaceEventHandler(type, inputAction, options = {}) {
1008
+ const { modifier } = options;
1009
+ const viewer = useViewer();
1010
+ const isActive = (0, vue.toRef)(options.isActive ?? true);
1011
+ const handler = (0, vue.computed)(() => {
1012
+ if (viewer.value?.cesiumWidget?.canvas) return new cesium.ScreenSpaceEventHandler(viewer.value.cesiumWidget.canvas);
1013
+ });
1014
+ const cleanup1 = (0, vue.watch)(handler, (_value, previous) => {
1015
+ viewer.value?.cesiumWidget && previous?.destroy();
1016
+ });
1017
+ const cleanup2 = (0, vue.watchEffect)((onCleanup) => {
1018
+ const typeValue = (0, vue.toValue)(type);
1019
+ const modifierValue = (0, vue.toValue)(modifier);
1020
+ const handlerValue = (0, vue.toValue)(handler);
1021
+ if (!handlerValue || !isActive.value || !inputAction) return;
1022
+ if (isDef(typeValue)) {
1023
+ handlerValue.setInputAction(inputAction, typeValue, modifierValue);
1024
+ onCleanup(() => handlerValue.removeInputAction(typeValue, modifierValue));
1025
+ }
1026
+ });
1027
+ const stop = () => {
1028
+ cleanup1();
1029
+ cleanup2();
1030
+ };
1031
+ (0, __vueuse_core.tryOnScopeDispose)(stop);
1032
+ return stop;
1033
+ }
1034
+
1035
+ //#endregion
1036
+ //#region useGraphicEvent/useDrag.ts
1037
+ /**
1038
+ * Use graphic drag events with ease, and remove listener automatically on unmounted.
1039
+ */
1040
+ function useDrag(listener) {
1041
+ const position = (0, vue.shallowRef)();
1042
+ const pick = useScenePick(position);
1043
+ const motionEvent = (0, vue.shallowRef)();
1044
+ const dragging = (0, vue.ref)(false);
1045
+ const viewer = useViewer();
1046
+ const cameraLocked = (0, vue.ref)(false);
1047
+ (0, vue.watch)(cameraLocked, (cameraLocked$1) => {
1048
+ viewer.value && (viewer.value.scene.screenSpaceCameraController.enableRotate = !cameraLocked$1);
1049
+ });
1050
+ const lockCamera = () => {
1051
+ cameraLocked.value = true;
1052
+ };
1053
+ const execute = (pick$1, startPosition, endPosition) => {
1054
+ listener({
1055
+ event: {
1056
+ startPosition: startPosition.clone(),
1057
+ endPosition: endPosition.clone()
1058
+ },
1059
+ pick: pick$1,
1060
+ dragging: dragging.value,
1061
+ lockCamera
1062
+ });
1063
+ (0, vue.nextTick)(() => {
1064
+ if (!dragging.value && cameraLocked.value) cameraLocked.value = false;
1065
+ });
1066
+ };
1067
+ const stopLeftDownWatch = useScreenSpaceEventHandler(cesium.ScreenSpaceEventType.LEFT_DOWN, (event) => {
1068
+ dragging.value = true;
1069
+ position.value = event.position.clone();
1070
+ });
1071
+ const stopMouseMoveWatch = useScreenSpaceEventHandler(cesium.ScreenSpaceEventType.MOUSE_MOVE, throttle(({ startPosition, endPosition }) => {
1072
+ motionEvent.value = {
1073
+ startPosition: motionEvent.value?.endPosition.clone() || startPosition.clone(),
1074
+ endPosition: endPosition.clone()
1075
+ };
1076
+ }, 8, false, true));
1077
+ (0, vue.watch)([pick, motionEvent], ([pick$1, motionEvent$1]) => {
1078
+ if (pick$1 && motionEvent$1) {
1079
+ const { startPosition, endPosition } = motionEvent$1;
1080
+ dragging.value && execute(pick$1, startPosition, endPosition);
1081
+ }
1082
+ });
1083
+ const stopLeftUpWatch = useScreenSpaceEventHandler(cesium.ScreenSpaceEventType.LEFT_UP, (event) => {
1084
+ dragging.value = false;
1085
+ if (pick.value && motionEvent.value) execute(pick.value, motionEvent.value.endPosition, event.position);
1086
+ position.value = void 0;
1087
+ motionEvent.value = void 0;
1088
+ });
1089
+ const stop = () => {
1090
+ stopLeftDownWatch();
1091
+ stopMouseMoveWatch();
1092
+ stopLeftUpWatch();
1093
+ };
1094
+ (0, __vueuse_core.tryOnScopeDispose)(stop);
1095
+ return stop;
1096
+ }
1097
+
1098
+ //#endregion
1099
+ //#region useGraphicEvent/useHover.ts
1100
+ /**
1101
+ * Use graphic hover events with ease, and remove listener automatically on unmounted.
1102
+ */
1103
+ function useHover(listener) {
1104
+ const motionEvent = (0, vue.shallowRef)();
1105
+ const pick = useScenePick(() => motionEvent.value?.endPosition);
1106
+ const execute = (pick$1, startPosition, endPosition, hovering) => {
1107
+ listener({
1108
+ event: {
1109
+ startPosition: startPosition.clone(),
1110
+ endPosition: endPosition.clone()
1111
+ },
1112
+ pick: pick$1,
1113
+ hovering
1114
+ });
1115
+ };
1116
+ useScreenSpaceEventHandler(cesium.ScreenSpaceEventType.MOUSE_MOVE, ({ startPosition, endPosition }) => {
1117
+ if (!startPosition.equals(motionEvent.value?.startPosition) || !endPosition.equals(motionEvent.value?.endPosition)) motionEvent.value = {
1118
+ startPosition: startPosition.clone(),
1119
+ endPosition: endPosition.clone()
1120
+ };
1121
+ });
1122
+ (0, vue.watch)([pick, motionEvent], ([pick$1, motionEvent$1]) => {
1123
+ if (pick$1 && motionEvent$1) {
1124
+ const { startPosition, endPosition } = motionEvent$1;
1125
+ execute(pick$1, startPosition, endPosition, true);
1126
+ }
1127
+ });
1128
+ (0, vue.watch)(pick, (pick$1, prevPick) => {
1129
+ if (prevPick && motionEvent.value) {
1130
+ const { startPosition, endPosition } = motionEvent.value;
1131
+ execute(prevPick, startPosition, endPosition, false);
1132
+ }
1133
+ });
1134
+ }
1135
+
1136
+ //#endregion
1137
+ //#region useGraphicEvent/usePositioned.ts
1138
+ /**
1139
+ * @internal
1140
+ */
1141
+ const EVENT_TYPE_RECORD = {
1142
+ LEFT_DOWN: cesium.ScreenSpaceEventType.LEFT_DOWN,
1143
+ LEFT_UP: cesium.ScreenSpaceEventType.LEFT_UP,
1144
+ LEFT_CLICK: cesium.ScreenSpaceEventType.LEFT_CLICK,
1145
+ LEFT_DOUBLE_CLICK: cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK,
1146
+ RIGHT_DOWN: cesium.ScreenSpaceEventType.RIGHT_DOWN,
1147
+ RIGHT_UP: cesium.ScreenSpaceEventType.RIGHT_UP,
1148
+ RIGHT_CLICK: cesium.ScreenSpaceEventType.RIGHT_CLICK,
1149
+ MIDDLE_DOWN: cesium.ScreenSpaceEventType.MIDDLE_DOWN,
1150
+ MIDDLE_UP: cesium.ScreenSpaceEventType.MIDDLE_UP,
1151
+ MIDDLE_CLICK: cesium.ScreenSpaceEventType.MIDDLE_CLICK
1152
+ };
1153
+ function usePositioned(type, listener) {
1154
+ const screenEvent = EVENT_TYPE_RECORD[type];
1155
+ const viewer = useViewer();
1156
+ useScreenSpaceEventHandler(screenEvent, (event) => {
1157
+ const position = event.position;
1158
+ const pick = viewer.value?.scene.pick(position);
1159
+ pick && position && listener({
1160
+ event: { position },
1161
+ pick
1162
+ });
1163
+ });
1164
+ }
1165
+
1166
+ //#endregion
1167
+ //#region useGraphicEvent/index.ts
1168
+ const GLOBAL_GRAPHIC_SYMBOL = Symbol("GLOBAL_GRAPHIC_SYMBOL");
1169
+ const POSITIONED_EVENT_TYPES = [
1170
+ "LEFT_DOWN",
1171
+ "LEFT_UP",
1172
+ "LEFT_CLICK",
1173
+ "LEFT_DOUBLE_CLICK",
1174
+ "RIGHT_DOWN",
1175
+ "RIGHT_UP",
1176
+ "RIGHT_CLICK",
1177
+ "MIDDLE_DOWN",
1178
+ "MIDDLE_UP",
1179
+ "MIDDLE_CLICK"
1180
+ ];
1181
+ /**
1182
+ * Handle graphic event listeners and cursor styles for Cesium graphics.
1183
+ * You don't need to overly worry about memory leaks from the function, as it automatically cleans up internally.
1184
+ */
1185
+ function useGraphicEvent() {
1186
+ const collection = /* @__PURE__ */ new WeakMap();
1187
+ const cursorCollection = /* @__PURE__ */ new WeakMap();
1188
+ const dragCursorCollection = /* @__PURE__ */ new WeakMap();
1189
+ const removeGraphicEvent = (graphic, type, listener) => {
1190
+ const _graphic = graphic === "global" ? GLOBAL_GRAPHIC_SYMBOL : graphic;
1191
+ collection?.get(_graphic)?.get(type)?.delete(listener);
1192
+ cursorCollection?.get(_graphic)?.get(type)?.delete(listener);
1193
+ if (collection?.get(_graphic)?.get(type)?.size === 0) collection.get(_graphic).delete(type);
1194
+ if (collection.get(_graphic)?.size === 0) collection.delete(_graphic);
1195
+ cursorCollection?.get(_graphic)?.get(type)?.delete(listener);
1196
+ if (cursorCollection?.get(_graphic)?.get(type)?.size === 0) cursorCollection?.get(_graphic)?.delete(type);
1197
+ if (cursorCollection?.get(_graphic)?.size === 0) cursorCollection?.delete(_graphic);
1198
+ dragCursorCollection?.get(_graphic)?.get(type)?.delete(listener);
1199
+ if (dragCursorCollection?.get(_graphic)?.get(type)?.size === 0) dragCursorCollection?.get(_graphic)?.delete(type);
1200
+ if (dragCursorCollection?.get(_graphic)?.size === 0) dragCursorCollection?.delete(_graphic);
1201
+ };
1202
+ const addGraphicEvent = (graphic, type, listener, options = {}) => {
1203
+ const _graphic = graphic === "global" ? GLOBAL_GRAPHIC_SYMBOL : graphic;
1204
+ collection.get(_graphic) ?? collection.set(_graphic, /* @__PURE__ */ new Map());
1205
+ const eventTypeMap = collection.get(_graphic);
1206
+ eventTypeMap.get(type) ?? eventTypeMap.set(type, /* @__PURE__ */ new Set());
1207
+ const listeners = eventTypeMap.get(type);
1208
+ listeners.add(listener);
1209
+ let { cursor = "pointer", dragCursor } = options;
1210
+ if (isDef(cursor)) {
1211
+ const _cursor = isFunction(cursor) ? cursor : () => cursor;
1212
+ cursorCollection.get(_graphic) ?? cursorCollection.set(_graphic, /* @__PURE__ */ new Map());
1213
+ cursorCollection.get(_graphic).get(type) ?? cursorCollection.get(_graphic).set(type, /* @__PURE__ */ new Map());
1214
+ cursorCollection.get(_graphic).get(type).set(listener, _cursor);
1215
+ }
1216
+ if (type === "DRAG") dragCursor ??= (event) => event?.dragging ? "crosshair" : void 0;
1217
+ if (isDef(dragCursor)) {
1218
+ const _dragCursor = isFunction(dragCursor) ? dragCursor : () => dragCursor;
1219
+ dragCursorCollection.get(_graphic) ?? dragCursorCollection.set(_graphic, /* @__PURE__ */ new Map());
1220
+ dragCursorCollection.get(_graphic).get(type) ?? dragCursorCollection.get(_graphic).set(type, /* @__PURE__ */ new Map());
1221
+ dragCursorCollection.get(_graphic).get(type).set(listener, _dragCursor);
1222
+ }
1223
+ return () => removeGraphicEvent(graphic, type, listener);
1224
+ };
1225
+ const clearGraphicEvent = (graphic, type) => {
1226
+ const _graphic = graphic === "global" ? GLOBAL_GRAPHIC_SYMBOL : graphic;
1227
+ if (type === "all") {
1228
+ collection.delete(_graphic);
1229
+ cursorCollection.delete(_graphic);
1230
+ dragCursorCollection.delete(_graphic);
1231
+ return;
1232
+ }
1233
+ collection.get(_graphic)?.delete(type);
1234
+ if (collection.get(_graphic)?.size === 0) collection.delete(_graphic);
1235
+ cursorCollection?.get(_graphic)?.delete(type);
1236
+ dragCursorCollection?.get(_graphic)?.delete(type);
1237
+ if (cursorCollection?.get(_graphic)?.size === 0) cursorCollection?.delete(_graphic);
1238
+ if (dragCursorCollection?.get(_graphic)?.size === 0) dragCursorCollection?.delete(_graphic);
1239
+ };
1240
+ for (const type of POSITIONED_EVENT_TYPES) usePositioned(type, (event) => {
1241
+ const graphics = resolvePick(event.pick);
1242
+ graphics.concat(GLOBAL_GRAPHIC_SYMBOL).forEach((graphic) => {
1243
+ collection.get(graphic)?.get(type)?.forEach((fn) => tryRun(fn)?.(event));
1244
+ });
1245
+ });
1246
+ const dragging = (0, vue.ref)(false);
1247
+ const viewer = useViewer();
1248
+ useHover((event) => {
1249
+ const graphics = resolvePick(event.pick).concat(GLOBAL_GRAPHIC_SYMBOL);
1250
+ graphics.forEach((graphic) => {
1251
+ collection.get(graphic)?.get("HOVER")?.forEach((fn) => tryRun(fn)?.(event));
1252
+ if (!dragging.value) cursorCollection.get(graphic)?.forEach((map) => {
1253
+ map.forEach((fn) => {
1254
+ const cursor = event.hovering ? tryRun(fn)(event) : "";
1255
+ viewer.value?.canvas.style?.setProperty("cursor", cursor);
1256
+ });
1257
+ });
1258
+ });
1259
+ });
1260
+ useDrag((event) => {
1261
+ const graphics = resolvePick(event.pick).concat(GLOBAL_GRAPHIC_SYMBOL);
1262
+ dragging.value = event.dragging;
1263
+ graphics.forEach((graphic) => {
1264
+ collection.get(graphic)?.get("DRAG")?.forEach((fn) => tryRun(fn)(event));
1265
+ dragCursorCollection.get(graphic)?.forEach((map) => {
1266
+ map.forEach((fn) => {
1267
+ const cursor = event.dragging ? tryRun(fn)(event) : "";
1268
+ viewer.value?.canvas.style?.setProperty("cursor", cursor);
1269
+ });
1270
+ });
1271
+ });
1272
+ });
1273
+ return {
1274
+ addGraphicEvent,
1275
+ removeGraphicEvent,
1276
+ clearGraphicEvent
1277
+ };
1278
+ }
1279
+
1280
+ //#endregion
1281
+ //#region useImageryLayer/index.ts
1282
+ function useImageryLayer(data, options = {}) {
1283
+ const { destroyOnRemove, collection, isActive = true, evaluating } = options;
1284
+ const result = (0, __vueuse_core.computedAsync)(() => toPromiseValue(data), [], { evaluating });
1285
+ const viewer = useViewer();
1286
+ (0, vue.watchEffect)((onCleanup) => {
1287
+ const _isActive = (0, vue.toValue)(isActive);
1288
+ if (_isActive) {
1289
+ const list = Array.isArray(result.value) ? [...result.value] : [result.value];
1290
+ const _collection = collection ?? viewer.value?.imageryLayers;
1291
+ if (collection?.isDestroyed()) return;
1292
+ list.forEach((item) => {
1293
+ if (!item) {
1294
+ console.warn("ImageryLayer is undefined");
1295
+ return;
1296
+ }
1297
+ if (item?.isDestroyed()) {
1298
+ console.warn("ImageryLayer is destroyed");
1299
+ return;
1300
+ }
1301
+ _collection?.add(item);
1302
+ });
1303
+ onCleanup(() => {
1304
+ const destroy = (0, vue.toValue)(destroyOnRemove);
1305
+ list.forEach((item) => item && _collection?.remove(item, destroy));
1306
+ });
1307
+ }
1308
+ });
1309
+ return result;
1310
+ }
1311
+
1312
+ //#endregion
1313
+ //#region useImageryLayerScope/index.ts
1314
+ /**
1315
+ * Make `add` and `remove` operations of `ImageryLayerCollection` scoped,
1316
+ * automatically remove `ImageryLayer` instance when component is unmounted.
1317
+ */
1318
+ function useImageryLayerScope(options = {}) {
1319
+ const { collection: _collection, destroyOnRemove } = options;
1320
+ const viewer = useViewer();
1321
+ const collection = (0, vue.computed)(() => {
1322
+ return (0, vue.toValue)(_collection) ?? viewer.value?.imageryLayers;
1323
+ });
1324
+ const addFn = (imageryLayer, index) => {
1325
+ if (!collection.value) throw new Error("collection is not defined");
1326
+ collection.value.add(imageryLayer, index);
1327
+ return imageryLayer;
1328
+ };
1329
+ const removeFn = (imageryLayer, destroy) => {
1330
+ return !!collection.value?.remove(imageryLayer, destroy);
1331
+ };
1332
+ const { scope, add, remove, removeWhere, removeScope } = useCollectionScope(addFn, removeFn, [destroyOnRemove]);
1333
+ return {
1334
+ scope,
1335
+ add,
1336
+ remove,
1337
+ removeWhere,
1338
+ removeScope
1339
+ };
1340
+ }
1341
+
1342
+ //#endregion
1343
+ //#region usePostProcessStage/index.ts
1344
+ function usePostProcessStage(data, options = {}) {
1345
+ const { collection, isActive = true, evaluating } = options;
1346
+ const result = (0, __vueuse_core.computedAsync)(() => toPromiseValue(data), void 0, { evaluating });
1347
+ const viewer = useViewer();
1348
+ (0, vue.watchEffect)((onCleanup) => {
1349
+ if (!viewer.value) return;
1350
+ const _isActive = (0, vue.toValue)(isActive);
1351
+ if (_isActive) {
1352
+ const list = Array.isArray(result.value) ? [...result.value] : [result.value];
1353
+ const _collection = collection ?? viewer.value.scene.postProcessStages;
1354
+ list.forEach((item) => item && _collection.add(item));
1355
+ onCleanup(() => {
1356
+ list.forEach((item) => item && _collection.remove(item));
1357
+ });
1358
+ }
1359
+ });
1360
+ return result;
1361
+ }
1362
+
1363
+ //#endregion
1364
+ //#region usePostProcessStageScope/index.ts
1365
+ /**
1366
+ * Make `add` and `remove` operations of `PostProcessStageCollection` scoped,
1367
+ * automatically remove `PostProcessStage` instance when component is unmounted.
1368
+ */
1369
+ function usePostProcessStageScope(options = {}) {
1370
+ const { collection: _collection } = options;
1371
+ const viewer = useViewer();
1372
+ const collection = (0, vue.computed)(() => {
1373
+ return (0, vue.toValue)(_collection) ?? viewer.value?.postProcessStages;
1374
+ });
1375
+ const addFn = (postProcessStage) => {
1376
+ if (!collection.value) throw new Error("collection is not defined");
1377
+ return collection.value.add(postProcessStage);
1378
+ };
1379
+ const removeFn = (postProcessStage) => {
1380
+ return !!collection.value?.remove(postProcessStage);
1381
+ };
1382
+ const { scope, add, remove, removeWhere, removeScope } = useCollectionScope(addFn, removeFn, []);
1383
+ return {
1384
+ scope,
1385
+ add,
1386
+ remove,
1387
+ removeWhere,
1388
+ removeScope
1389
+ };
1390
+ }
1391
+
1392
+ //#endregion
1393
+ //#region usePrimitive/index.ts
1394
+ function usePrimitive(data, options = {}) {
1395
+ const { collection, isActive = true, evaluating } = options;
1396
+ const result = (0, __vueuse_core.computedAsync)(() => toPromiseValue(data), void 0, { evaluating });
1397
+ const viewer = useViewer();
1398
+ (0, vue.watchEffect)((onCleanup) => {
1399
+ const _isActive = (0, vue.toValue)(isActive);
1400
+ if (_isActive) {
1401
+ const list = Array.isArray(result.value) ? [...result.value] : [result.value];
1402
+ const _collection = collection === "ground" ? viewer.value?.scene.groundPrimitives : collection ?? viewer.value?.scene.primitives;
1403
+ list.forEach((item) => item && _collection?.add(item));
1404
+ onCleanup(() => {
1405
+ !_collection?.isDestroyed() && list.forEach((item) => item && _collection?.remove(item));
1406
+ });
1407
+ }
1408
+ });
1409
+ return result;
1410
+ }
1411
+
1412
+ //#endregion
1413
+ //#region usePrimitiveScope/index.ts
1414
+ /**
1415
+ * Make `add` and `remove` operations of `PrimitiveCollection` scoped,
1416
+ * automatically remove `Primitive` instance when component is unmounted.
1417
+ */
1418
+ function usePrimitiveScope(options = {}) {
1419
+ const { collection: _collection } = options;
1420
+ const viewer = useViewer();
1421
+ const collection = (0, vue.computed)(() => {
1422
+ return (0, vue.toValue)(_collection) ?? viewer.value?.scene.primitives;
1423
+ });
1424
+ const addFn = (primitive) => {
1425
+ if (!collection.value) throw new Error("collection is not defined");
1426
+ return collection.value.add(primitive);
1427
+ };
1428
+ const removeFn = (primitive) => {
1429
+ return !!collection.value?.remove(primitive);
1430
+ };
1431
+ const { scope, add, remove, removeWhere, removeScope } = useCollectionScope(addFn, removeFn, []);
1432
+ return {
1433
+ scope,
1434
+ add,
1435
+ remove,
1436
+ removeWhere,
1437
+ removeScope
1438
+ };
1439
+ }
1440
+
1441
+ //#endregion
1442
+ //#region useScaleBar/index.ts
1443
+ const distances = [
1444
+ .01,
1445
+ .05,
1446
+ .1,
1447
+ .5,
1448
+ 1,
1449
+ 2,
1450
+ 3,
1451
+ 5,
1452
+ 10,
1453
+ 20,
1454
+ 30,
1455
+ 50,
1456
+ 100,
1457
+ 200,
1458
+ 300,
1459
+ 500,
1460
+ 1e3,
1461
+ 2e3,
1462
+ 3e3,
1463
+ 5e3,
1464
+ 1e4,
1465
+ 2e4,
1466
+ 3e4,
1467
+ 5e4,
1468
+ 1e5,
1469
+ 2e5,
1470
+ 3e5,
1471
+ 5e5,
1472
+ 1e6,
1473
+ 2e6,
1474
+ 3e6,
1475
+ 5e6,
1476
+ 1e7,
1477
+ 2e7,
1478
+ 3e7,
1479
+ 5e7
1480
+ ].reverse();
1481
+ /**
1482
+ * Reactive generation of scale bars
1483
+ */
1484
+ function useScaleBar(options = {}) {
1485
+ const { maxPixel = 80, delay = 8 } = options;
1486
+ const maxPixelRef = (0, vue.computed)(() => (0, vue.toValue)(maxPixel));
1487
+ const viewer = useViewer();
1488
+ const canvasSize = (0, __vueuse_core.useElementSize)(() => viewer.value?.canvas);
1489
+ const pixelDistance = (0, vue.ref)();
1490
+ const setPixelDistance = async () => {
1491
+ await (0, vue.nextTick)();
1492
+ const scene = viewer.value?.scene;
1493
+ if (!scene) return;
1494
+ const left = scene.camera.getPickRay(new cesium.Cartesian2(Math.floor(canvasSize.width.value / 2), canvasSize.height.value - 1));
1495
+ const right = scene.camera.getPickRay(new cesium.Cartesian2(Math.floor(1 + canvasSize.width.value / 2), canvasSize.height.value - 1));
1496
+ if (!left || !right) return;
1497
+ const leftPosition = scene.globe.pick(left, scene);
1498
+ const rightPosition = scene.globe.pick(right, scene);
1499
+ if (!leftPosition || !rightPosition) return;
1500
+ const leftCartographic = scene.globe.ellipsoid.cartesianToCartographic(leftPosition);
1501
+ const rightCartographic = scene.globe.ellipsoid.cartesianToCartographic(rightPosition);
1502
+ const geodesic = new cesium.EllipsoidGeodesic(leftCartographic, rightCartographic);
1503
+ pixelDistance.value = geodesic.surfaceDistance;
1504
+ };
1505
+ (0, __vueuse_core.watchImmediate)(viewer, () => setPixelDistance());
1506
+ useCesiumEventListener(() => viewer.value?.camera.changed, throttle(setPixelDistance, delay));
1507
+ const distance = (0, vue.computed)(() => {
1508
+ if (pixelDistance.value) return distances.find((item) => pixelDistance.value * maxPixelRef.value > item);
1509
+ });
1510
+ const width = (0, vue.computed)(() => {
1511
+ if (distance.value && pixelDistance.value) {
1512
+ const value = distance.value / pixelDistance.value;
1513
+ return value;
1514
+ }
1515
+ return 0;
1516
+ });
1517
+ const distanceText = (0, vue.computed)(() => {
1518
+ if (distance.value) return distance.value > 1e3 ? `${distance.value / 1e3 || 0}km` : `${distance.value || 0}m`;
1519
+ });
1520
+ return {
1521
+ pixelDistance: (0, vue.readonly)(pixelDistance),
1522
+ width,
1523
+ distance,
1524
+ distanceText
1525
+ };
1526
+ }
1527
+
1528
+ //#endregion
1529
+ //#region useSceneDrillPick/index.ts
1530
+ /**
1531
+ * Uses the `scene.drillPick` function to perform screen point picking,
1532
+ * return a computed property containing the pick result, or undefined if no object is picked.
1533
+ *
1534
+ * @param windowPosition The screen coordinates of the pick point.
1535
+ */
1536
+ function useSceneDrillPick(windowPosition, options = {}) {
1537
+ const { width = 3, height = 3, limit, throttled = 8, isActive = true } = options;
1538
+ const viewer = useViewer();
1539
+ const position = (0, __vueuse_core.refThrottled)((0, vue.computed)(() => (0, vue.toValue)(windowPosition)), throttled, false, true);
1540
+ const pick = (0, vue.computed)(() => {
1541
+ if (position.value && (0, vue.toValue)(isActive)) return viewer.value?.scene.drillPick(position.value, (0, vue.toValue)(limit), (0, vue.toValue)(width), (0, vue.toValue)(height));
1542
+ });
1543
+ return pick;
1544
+ }
1545
+
1546
+ //#endregion
1547
+ exports.CREATE_VIEWER_COLLECTION = CREATE_VIEWER_COLLECTION;
1548
+ exports.CREATE_VIEWER_INJECTION_KEY = CREATE_VIEWER_INJECTION_KEY;
1549
+ exports.CesiumMaterial = CesiumMaterial;
1550
+ exports.addMaterialCache = addMaterialCache;
1551
+ exports.arrayDiff = arrayDiff;
1552
+ exports.assertError = assertError;
1553
+ exports.canvasCoordToCartesian = canvasCoordToCartesian;
1554
+ exports.cartesianToCanvasCoord = cartesianToCanvasCoord;
1555
+ exports.cesiumEquals = cesiumEquals;
1556
+ exports.createCesiumAttribute = createCesiumAttribute;
1557
+ exports.createCesiumProperty = createCesiumProperty;
1558
+ exports.createPropertyField = createPropertyField;
1559
+ exports.createViewer = createViewer;
1560
+ exports.degreesToDms = degreesToDms;
1561
+ exports.dmsDecode = dmsDecode;
1562
+ exports.dmsEncode = dmsEncode;
1563
+ exports.dmsToDegrees = dmsToDegrees;
1564
+ exports.getMaterialCache = getMaterialCache;
1565
+ exports.isArray = isArray;
1566
+ exports.isBase64 = isBase64;
1567
+ exports.isBoolean = isBoolean;
1568
+ exports.isCesiumConstant = isCesiumConstant;
1569
+ exports.isDef = isDef;
1570
+ exports.isElement = isElement;
1571
+ exports.isFunction = isFunction;
1572
+ exports.isNumber = isNumber;
1573
+ exports.isObject = isObject;
1574
+ exports.isPromise = isPromise;
1575
+ exports.isProperty = isProperty;
1576
+ exports.isString = isString;
1577
+ exports.isWindow = isWindow;
1578
+ exports.pickHitGraphic = pickHitGraphic;
1579
+ exports.resolvePick = resolvePick;
1580
+ exports.throttle = throttle;
1581
+ exports.toCartesian3 = toCartesian3;
1582
+ exports.toCartographic = toCartographic;
1583
+ exports.toCoord = toCoord;
1584
+ exports.toPromiseValue = toPromiseValue;
1585
+ exports.toProperty = toProperty;
1586
+ exports.toPropertyValue = toPropertyValue;
1587
+ exports.tryRun = tryRun;
1588
+ exports.useCameraState = useCameraState;
1589
+ exports.useCesiumEventListener = useCesiumEventListener;
1590
+ exports.useCesiumFps = useCesiumFps;
1591
+ exports.useCollectionScope = useCollectionScope;
1592
+ exports.useDataSource = useDataSource;
1593
+ exports.useDataSourceScope = useDataSourceScope;
1594
+ exports.useElementOverlay = useElementOverlay;
1595
+ exports.useEntity = useEntity;
1596
+ exports.useEntityScope = useEntityScope;
1597
+ exports.useGraphicEvent = useGraphicEvent;
1598
+ exports.useImageryLayer = useImageryLayer;
1599
+ exports.useImageryLayerScope = useImageryLayerScope;
1600
+ exports.usePostProcessStage = usePostProcessStage;
1601
+ exports.usePostProcessStageScope = usePostProcessStageScope;
1602
+ exports.usePrimitive = usePrimitive;
1603
+ exports.usePrimitiveScope = usePrimitiveScope;
1604
+ exports.useScaleBar = useScaleBar;
1605
+ exports.useSceneDrillPick = useSceneDrillPick;
1606
+ exports.useScenePick = useScenePick;
1607
+ exports.useScreenSpaceEventHandler = useScreenSpaceEventHandler;
1608
+ exports.useViewer = useViewer;
1609
+ })(this.Vesium = this.Vesium || {}, VueUse, Cesium, Vue);
1610
+ //# sourceMappingURL=index.iife.js.map