vesium 1.0.1-beta.44 → 1.0.1-beta.46

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,18 +1,1519 @@
1
- var Vesium = function(exports, core, shared) {
1
+ var Vesium = function(exports, core, cesium, vue) {
2
2
  "use strict";
3
- Object.keys(core).forEach((k) => {
4
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
5
- enumerable: true,
6
- get: () => core[k]
7
- });
8
- });
9
- Object.keys(shared).forEach((k) => {
10
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
11
- enumerable: true,
12
- get: () => shared[k]
13
- });
14
- });
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
+ const toString = Object.prototype.toString;
51
+ function isDef(val) {
52
+ return typeof val !== "undefined";
53
+ }
54
+ function isBoolean(val) {
55
+ return typeof val === "boolean";
56
+ }
57
+ function isFunction(val) {
58
+ return typeof val === "function";
59
+ }
60
+ function isNumber(val) {
61
+ return typeof val === "number";
62
+ }
63
+ function isString(val) {
64
+ return typeof val === "string";
65
+ }
66
+ function isObject(val) {
67
+ return toString.call(val) === "[object Object]";
68
+ }
69
+ function isWindow(val) {
70
+ return typeof window !== "undefined" && toString.call(val) === "[object Window]";
71
+ }
72
+ function isPromise(val) {
73
+ return !!val && (typeof val === "object" || typeof val === "function") && typeof val.then === "function";
74
+ }
75
+ function isElement(val) {
76
+ return !!(val && val.nodeName && val.nodeType === 1);
77
+ }
78
+ const isArray = Array.isArray;
79
+ function isBase64(val) {
80
+ const reg = /^\s*data:([a-z]+\/[\d+.a-z-]+(;[a-z-]+=[\da-z-]+)?)?(;base64)?,([\s\w!$%&'()*+,./:;=?@~-]*?)\s*$/i;
81
+ return reg.test(val);
82
+ }
83
+ function assertError(condition, error) {
84
+ if (condition) {
85
+ throw new Error(error);
86
+ }
87
+ }
88
+ function cesiumEquals(left, right) {
89
+ return left === right || isFunction(left == null ? void 0 : left.equals) && left.equals(right) || isFunction(right == null ? void 0 : right.equals) && right.equals(left);
90
+ }
91
+ function isCesiumConstant(value) {
92
+ return !cesium.defined(value) || !!value.isConstant;
93
+ }
94
+ function canvasCoordToCartesian(canvasCoord, scene, mode = "auto") {
95
+ if (mode === "pickPosition") {
96
+ return scene.pickPosition(canvasCoord);
97
+ } else if (mode === "globePick") {
98
+ const ray = scene.camera.getPickRay(canvasCoord);
99
+ return ray && scene.globe.pick(ray, scene);
100
+ } else {
101
+ if (scene.globe.depthTestAgainstTerrain) {
102
+ return scene.pickPosition(canvasCoord);
103
+ }
104
+ const position1 = scene.pickPosition(canvasCoord);
105
+ const ray = scene.camera.getPickRay(canvasCoord);
106
+ const position2 = ray && scene.globe.pick(ray, scene);
107
+ if (!position1) {
108
+ return position2;
109
+ }
110
+ const height1 = (position1 && cesium.Ellipsoid.WGS84.cartesianToCartographic(position1).height) ?? 0;
111
+ const height2 = (position2 && cesium.Ellipsoid.WGS84.cartesianToCartographic(position2).height) ?? 0;
112
+ return height1 < height2 ? position1 : position2;
113
+ }
114
+ }
115
+ function cartesianToCanvasCoord(position, scene) {
116
+ return scene.cartesianToCanvasCoordinates(position);
117
+ }
118
+ function toCoord(position, options = {}) {
119
+ if (!position) {
120
+ return void 0;
121
+ }
122
+ const { type = "Array", alt = false } = options;
123
+ let longitude, latitude, height;
124
+ if (position instanceof cesium.Cartesian3) {
125
+ const cartographic = cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
126
+ longitude = cesium.Math.toDegrees(cartographic.longitude);
127
+ latitude = cesium.Math.toDegrees(cartographic.latitude);
128
+ height = cartographic.height;
129
+ } else if (position instanceof cesium.Cartographic) {
130
+ const cartographic = position;
131
+ longitude = cesium.Math.toDegrees(cartographic.longitude);
132
+ latitude = cesium.Math.toDegrees(cartographic.latitude);
133
+ height = cartographic.height;
134
+ } else if (Array.isArray(position)) {
135
+ longitude = cesium.Math.toDegrees(position[0]);
136
+ latitude = cesium.Math.toDegrees(position[1]);
137
+ height = position[2];
138
+ } else {
139
+ longitude = position.longitude;
140
+ latitude = position.latitude;
141
+ height = position.height;
142
+ }
143
+ if (type === "Array") {
144
+ return alt ? [longitude, latitude, height] : [longitude, latitude];
145
+ } else {
146
+ return alt ? { longitude, latitude, height } : { longitude, latitude };
147
+ }
148
+ }
149
+ function dmsEncode(degrees, precision = 3) {
150
+ const str = `${degrees}`;
151
+ let i = str.indexOf(".");
152
+ const d = i < 0 ? str : str.slice(0, Math.max(0, i));
153
+ let m = "0";
154
+ let s = "0";
155
+ if (i > 0) {
156
+ m = `0${str.slice(Math.max(0, i))}`;
157
+ m = `${+m * 60}`;
158
+ i = m.indexOf(".");
159
+ if (i > 0) {
160
+ s = `0${m.slice(Math.max(0, i))}`;
161
+ m = m.slice(0, Math.max(0, i));
162
+ s = `${+s * 60}`;
163
+ i = s.indexOf(".");
164
+ s = s.slice(0, Math.max(0, i + 4));
165
+ s = (+s).toFixed(precision);
166
+ }
167
+ }
168
+ return `${Math.abs(+d)}°${+m}′${+s}″`;
169
+ }
170
+ function dmsDecode(dmsCode) {
171
+ const [dd, msStr] = dmsCode.split("°") ?? [];
172
+ const [mm, sStr] = (msStr == null ? void 0 : msStr.split("′")) ?? [];
173
+ const ss = sStr == null ? void 0 : sStr.split("″")[0];
174
+ const d = Number(dd) || 0;
175
+ const m = (Number(mm) || 0) / 60;
176
+ const s = (Number(ss) || 0) / 60 / 60;
177
+ const degrees = d + m + s;
178
+ if (degrees === 0) {
179
+ return 0;
180
+ } else {
181
+ let res = degrees;
182
+ if (["W", "w", "S", "s"].includes(dmsCode[dmsCode.length - 1])) {
183
+ res = -res;
184
+ }
185
+ return res;
186
+ }
187
+ }
188
+ function degreesToDms(position, precision = 3) {
189
+ const coord = toCoord(position, { alt: true });
190
+ if (!coord) {
191
+ return;
192
+ }
193
+ const [longitude, latitude, height] = coord;
194
+ const x = dmsEncode(longitude, precision);
195
+ const y = dmsEncode(latitude, precision);
196
+ return [`${x}${longitude > 0 ? "E" : "W"}`, `${y}${latitude > 0 ? "N" : "S"}`, height];
197
+ }
198
+ function dmsToDegrees(dms) {
199
+ const [x, y, height] = dms;
200
+ const longitude = dmsDecode(x);
201
+ const latitude = dmsDecode(y);
202
+ return [longitude, latitude, Number(height) || 0];
203
+ }
204
+ class CesiumMaterial extends cesium.Material {
205
+ constructor(options) {
206
+ super(options);
207
+ }
208
+ }
209
+ function getMaterialCache(type) {
210
+ return cesium.Material._materialCache.getMaterial(type);
211
+ }
212
+ function addMaterialCache(type, material) {
213
+ return cesium.Material._materialCache.addMaterial(type, material);
214
+ }
215
+ function resolvePick(pick = {}) {
216
+ const { primitive, id, primitiveCollection, collection } = pick;
217
+ const entityCollection = id && id.entityCollection || null;
218
+ const dataSource = entityCollection && entityCollection.owner || null;
219
+ const ids = Array.isArray(id) ? id : [id].filter(Boolean);
220
+ return [
221
+ ...ids,
222
+ primitive,
223
+ primitiveCollection,
224
+ collection,
225
+ entityCollection,
226
+ dataSource
227
+ ].filter((e) => !!e);
228
+ }
229
+ function pickHitGraphic(pick, graphic) {
230
+ if (!Array.isArray(graphic) || !graphic.length) {
231
+ return false;
232
+ }
233
+ const elements = resolvePick(pick);
234
+ if (!elements.length) {
235
+ return false;
236
+ }
237
+ return elements.some((element) => graphic.includes(element));
238
+ }
239
+ function isProperty(value) {
240
+ return value && isFunction(value.getValue);
241
+ }
242
+ function toPropertyValue(value, time) {
243
+ return isProperty(value) ? value.getValue(time) : value;
244
+ }
245
+ function toProperty(value, isConstant = false) {
246
+ return isProperty(value) ? value : isFunction(value) ? new cesium.CallbackProperty(value, isConstant) : new cesium.ConstantProperty(value);
247
+ }
248
+ function createPropertyField(scope, field, maybeProperty, readonly) {
249
+ let removeOwnerListener;
250
+ const ownerBinding = (value) => {
251
+ var _a;
252
+ removeOwnerListener == null ? void 0 : removeOwnerListener();
253
+ if (cesium.defined(value == null ? void 0 : value.definitionChanged)) {
254
+ removeOwnerListener = (_a = value == null ? void 0 : value.definitionChanged) == null ? void 0 : _a.addEventListener(() => {
255
+ scope.definitionChanged.raiseEvent(scope, field, value, value);
256
+ });
257
+ }
258
+ };
259
+ const privateField = `_${field}`;
260
+ const property = toProperty(maybeProperty);
261
+ scope[privateField] = property;
262
+ ownerBinding(property);
263
+ if (readonly) {
264
+ Object.defineProperty(scope, field, {
265
+ get() {
266
+ return scope[privateField];
267
+ }
268
+ });
269
+ } else {
270
+ Object.defineProperty(scope, field, {
271
+ get() {
272
+ return scope[privateField];
273
+ },
274
+ set(value) {
275
+ const previous = scope[privateField];
276
+ if (scope[privateField] !== value) {
277
+ scope[privateField] = value;
278
+ ownerBinding(value);
279
+ if (cesium.defined(scope.definitionChanged)) {
280
+ scope.definitionChanged.raiseEvent(scope, field, value, previous);
281
+ }
282
+ }
283
+ }
284
+ });
285
+ }
286
+ }
287
+ function createCesiumAttribute(scope, key, value, options = {}) {
288
+ const allowToProperty = !!options.toProperty;
289
+ const shallowClone = !!options.shallowClone;
290
+ const changedEventKey = options.changedEventKey || "definitionChanged";
291
+ const changedEvent = Reflect.get(scope, changedEventKey);
292
+ const privateKey = `_${String(key)}`;
293
+ const attribute = allowToProperty ? toProperty(value) : value;
294
+ Reflect.set(scope, privateKey, attribute);
295
+ const obj = {
296
+ get() {
297
+ const value2 = Reflect.get(scope, privateKey);
298
+ if (shallowClone) {
299
+ return Array.isArray(value2) ? [...value2] : { ...value2 };
300
+ } else {
301
+ return value2;
302
+ }
303
+ }
304
+ };
305
+ let previousListener;
306
+ const serial = (property, previous) => {
307
+ var _a;
308
+ previousListener == null ? void 0 : previousListener();
309
+ previousListener = (_a = property == null ? void 0 : property.definitionChanged) == null ? void 0 : _a.addEventListener(() => {
310
+ changedEvent == null ? void 0 : changedEvent.raiseEvent.bind(changedEvent)(scope, key, property, previous);
311
+ });
312
+ };
313
+ if (!options.readonly) {
314
+ if (allowToProperty && isProperty(value)) {
315
+ serial(value);
316
+ }
317
+ obj.set = (value2) => {
318
+ if (allowToProperty && !isProperty(value2)) {
319
+ throw new Error(`The value of ${String(key)} must be a Cesium.Property object`);
320
+ }
321
+ const previous = Reflect.get(scope, privateKey);
322
+ if (previous !== value2) {
323
+ Reflect.set(scope, privateKey, value2);
324
+ changedEvent == null ? void 0 : changedEvent.raiseEvent.bind(changedEvent)(scope, key, value2, previous);
325
+ if (allowToProperty) {
326
+ serial(value2);
327
+ }
328
+ }
329
+ };
330
+ }
331
+ Object.defineProperty(scope, key, obj);
332
+ }
333
+ function createCesiumProperty(scope, key, value, options = {}) {
334
+ return createCesiumAttribute(scope, key, value, { ...options, toProperty: true });
335
+ }
336
+ function throttle(callback, delay = 100, trailing = true, leading = false) {
337
+ const restList = [];
338
+ let tracked = false;
339
+ const trigger = async () => {
340
+ await core.promiseTimeout(delay);
341
+ tracked = false;
342
+ if (leading) {
343
+ try {
344
+ callback(...restList[0]);
345
+ } catch (error) {
346
+ console.error(error);
347
+ }
348
+ }
349
+ if (trailing && (!leading || restList.length > 1)) {
350
+ try {
351
+ callback(...restList[restList.length - 1]);
352
+ } catch (error) {
353
+ console.error(error);
354
+ }
355
+ }
356
+ restList.length = 0;
357
+ };
358
+ return (...rest) => {
359
+ if (restList.length < 2) {
360
+ restList.push(rest);
361
+ } else {
362
+ restList[1] = rest;
363
+ }
364
+ if (!tracked) {
365
+ tracked = true;
366
+ trigger();
367
+ }
368
+ };
369
+ }
370
+ function toCartesian3(position) {
371
+ if (!position) {
372
+ return void 0;
373
+ }
374
+ if (position instanceof cesium.Cartesian3) {
375
+ return position.clone();
376
+ } else if (position instanceof cesium.Cartographic) {
377
+ return cesium.Ellipsoid.WGS84.cartographicToCartesian(position);
378
+ } else if (Array.isArray(position)) {
379
+ return cesium.Cartesian3.fromDegrees(position[0], position[1], position[2]);
380
+ } else {
381
+ return cesium.Cartesian3.fromDegrees(position.longitude, position.latitude, position.height);
382
+ }
383
+ }
384
+ function toCartographic(position) {
385
+ if (!position) {
386
+ return void 0;
387
+ }
388
+ if (position instanceof cesium.Cartesian3) {
389
+ return cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
390
+ } else if (position instanceof cesium.Cartographic) {
391
+ return position.clone();
392
+ } else if (Array.isArray(position)) {
393
+ return cesium.Cartographic.fromDegrees(position[0], position[1], position[2]);
394
+ } else {
395
+ return cesium.Cartographic.fromDegrees(position.longitude, position.latitude, position.height);
396
+ }
397
+ }
398
+ function tryRun(fn) {
399
+ return (...args) => {
400
+ try {
401
+ return fn == null ? void 0 : fn(...args);
402
+ } catch (error) {
403
+ console.error(error);
404
+ }
405
+ };
406
+ }
407
+ function arrayDiff(list, oldList) {
408
+ const oldListSet = new Set(oldList);
409
+ const added = list.filter((obj) => !oldListSet.has(obj));
410
+ const newListSet = new Set(list);
411
+ const removed = (oldList == null ? void 0 : oldList.filter((obj) => !newListSet.has(obj))) ?? [];
412
+ return { added, removed };
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;
15
1516
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
16
1517
  return exports;
17
- }({}, VesiumCore, VesiumShared);
1518
+ }({}, VueUse, Cesium, Vue);
18
1519
  //# sourceMappingURL=index.iife.js.map