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