vesium 1.0.1-beta.52 → 1.0.1-beta.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +147 -699
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -555
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +50 -555
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +910 -1466
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.min.cjs +1 -1
- package/dist/index.min.cjs.map +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +121 -645
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { computedAsync,
|
|
2
|
-
import {
|
|
1
|
+
import { computedAsync, refThrottled, tryOnScopeDispose, useElementBounding, useElementSize, useMutationObserver, watchImmediate, watchThrottled } from "@vueuse/core";
|
|
2
|
+
import { Cartesian2, EllipsoidGeodesic, ScreenSpaceEventHandler, ScreenSpaceEventType, Viewer } from "cesium";
|
|
3
3
|
import { computed, getCurrentScope, inject, markRaw, nextTick, provide, readonly, ref, shallowReactive, shallowReadonly, shallowRef, toRaw, toRef, toValue, watch, watchEffect } from "vue";
|
|
4
|
+
import { cartesianToCanvasCoord, isDef, isFunction, isPromise, resolvePick, throttle, toCartesian3, tryRun } from "@vesium/shared";
|
|
5
|
+
|
|
6
|
+
export * from "@vesium/shared"
|
|
4
7
|
|
|
5
8
|
//#region createViewer/index.ts
|
|
6
9
|
/**
|
|
@@ -31,9 +34,7 @@ function createViewer(...args) {
|
|
|
31
34
|
const value = toRaw(toValue(arg1));
|
|
32
35
|
if (value instanceof Viewer) viewer.value = markRaw(value);
|
|
33
36
|
else if (value) {
|
|
34
|
-
|
|
35
|
-
const options = arg2;
|
|
36
|
-
viewer.value = new Viewer(element, options);
|
|
37
|
+
viewer.value = new Viewer(value, arg2);
|
|
37
38
|
onCleanup(() => !viewer.value?.isDestroyed() && viewer.value?.destroy());
|
|
38
39
|
} else viewer.value = void 0;
|
|
39
40
|
});
|
|
@@ -45,530 +46,6 @@ function createViewer(...args) {
|
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region utils/arrayDiff.ts
|
|
50
|
-
/**
|
|
51
|
-
* 计算两个数组的差异,返回新增和删除的元素
|
|
52
|
-
*/
|
|
53
|
-
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?.filter((obj) => !newListSet.has(obj)) ?? [];
|
|
58
|
-
return {
|
|
59
|
-
added,
|
|
60
|
-
removed
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
//#endregion
|
|
65
|
-
//#region utils/canvasCoordToCartesian.ts
|
|
66
|
-
/**
|
|
67
|
-
* Convert canvas coordinates to Cartesian coordinates
|
|
68
|
-
*
|
|
69
|
-
* @param canvasCoord Canvas coordinates
|
|
70
|
-
* @param scene Cesium.Scene instance
|
|
71
|
-
* @param mode optional values are 'pickPosition' | 'globePick' | 'auto' | 'noHeight' @default 'auto'
|
|
72
|
-
*
|
|
73
|
-
* `pickPosition`: Use scene.pickPosition for conversion, which can be used for picking models, oblique photography, etc.
|
|
74
|
-
* However, if depth detection is not enabled (globe.depthTestAgainstTerrain=false), picking terrain or inaccurate issues may occur
|
|
75
|
-
*
|
|
76
|
-
* `globePick`: Use camera.getPickRay for conversion, which cannot be used for picking models or oblique photography,
|
|
77
|
-
* but can be used for picking terrain. If terrain does not exist, the picked elevation is 0
|
|
78
|
-
*
|
|
79
|
-
* `auto`: Automatically determine which picking content to return
|
|
80
|
-
*
|
|
81
|
-
* Calculation speed comparison: globePick > auto >= pickPosition
|
|
82
|
-
*/
|
|
83
|
-
function canvasCoordToCartesian(canvasCoord, scene, mode = "auto") {
|
|
84
|
-
if (mode === "pickPosition") return scene.pickPosition(canvasCoord);
|
|
85
|
-
else if (mode === "globePick") {
|
|
86
|
-
const ray = scene.camera.getPickRay(canvasCoord);
|
|
87
|
-
return ray && scene.globe.pick(ray, scene);
|
|
88
|
-
} else {
|
|
89
|
-
if (scene.globe.depthTestAgainstTerrain) return scene.pickPosition(canvasCoord);
|
|
90
|
-
const position1 = scene.pickPosition(canvasCoord);
|
|
91
|
-
const ray = scene.camera.getPickRay(canvasCoord);
|
|
92
|
-
const position2 = ray && scene.globe.pick(ray, scene);
|
|
93
|
-
if (!position1) return position2;
|
|
94
|
-
const height1 = (position1 && Ellipsoid.WGS84.cartesianToCartographic(position1).height) ?? 0;
|
|
95
|
-
const height2 = (position2 && Ellipsoid.WGS84.cartesianToCartographic(position2).height) ?? 0;
|
|
96
|
-
return height1 < height2 ? position1 : position2;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
//#endregion
|
|
101
|
-
//#region utils/cartesianToCanvasCoord.ts
|
|
102
|
-
/**
|
|
103
|
-
* Convert Cartesian coordinates to canvas coordinates
|
|
104
|
-
*
|
|
105
|
-
* @param position Cartesian coordinates
|
|
106
|
-
* @param scene Cesium.Scene instance
|
|
107
|
-
*/
|
|
108
|
-
function cartesianToCanvasCoord(position, scene) {
|
|
109
|
-
return scene.cartesianToCanvasCoordinates(position);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region utils/is.ts
|
|
114
|
-
const toString = Object.prototype.toString;
|
|
115
|
-
function isDef(val) {
|
|
116
|
-
return typeof val !== "undefined";
|
|
117
|
-
}
|
|
118
|
-
function isBoolean(val) {
|
|
119
|
-
return typeof val === "boolean";
|
|
120
|
-
}
|
|
121
|
-
function isFunction(val) {
|
|
122
|
-
return typeof val === "function";
|
|
123
|
-
}
|
|
124
|
-
function isNumber(val) {
|
|
125
|
-
return typeof val === "number";
|
|
126
|
-
}
|
|
127
|
-
function isString(val) {
|
|
128
|
-
return typeof val === "string";
|
|
129
|
-
}
|
|
130
|
-
function isObject(val) {
|
|
131
|
-
return toString.call(val) === "[object Object]";
|
|
132
|
-
}
|
|
133
|
-
function isWindow(val) {
|
|
134
|
-
return typeof window !== "undefined" && toString.call(val) === "[object Window]";
|
|
135
|
-
}
|
|
136
|
-
function isPromise(val) {
|
|
137
|
-
return !!val && (typeof val === "object" || typeof val === "function") && typeof val.then === "function";
|
|
138
|
-
}
|
|
139
|
-
function isElement(val) {
|
|
140
|
-
return !!(val && val.nodeName && val.nodeType === 1);
|
|
141
|
-
}
|
|
142
|
-
const isArray = Array.isArray;
|
|
143
|
-
function isBase64(val) {
|
|
144
|
-
const reg = /^\s*data:([a-z]+\/[\d+.a-z-]+(;[a-z-]+=[\da-z-]+)?)?(;base64)?,([\s\w!$%&'()*+,./:;=?@~-]*?)\s*$/i;
|
|
145
|
-
return reg.test(val);
|
|
146
|
-
}
|
|
147
|
-
function assertError(condition, error) {
|
|
148
|
-
if (condition) throw new Error(error);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
//#endregion
|
|
152
|
-
//#region utils/cesiumEquals.ts
|
|
153
|
-
/**
|
|
154
|
-
* Determines if two Cesium objects are equal.
|
|
155
|
-
*
|
|
156
|
-
* This function not only judges whether the instances are equal,
|
|
157
|
-
* but also judges the equals method in the example.
|
|
158
|
-
*
|
|
159
|
-
* @param left The first Cesium object
|
|
160
|
-
* @param right The second Cesium object
|
|
161
|
-
* @returns Returns true if the two Cesium objects are equal, otherwise false
|
|
162
|
-
*/
|
|
163
|
-
function cesiumEquals(left, right) {
|
|
164
|
-
return left === right || isFunction(left?.equals) && left.equals(right) || isFunction(right?.equals) && right.equals(left);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
//#endregion
|
|
168
|
-
//#region utils/toCoord.ts
|
|
169
|
-
/**
|
|
170
|
-
* Converts coordinates to an array or object in the specified format.
|
|
171
|
-
*
|
|
172
|
-
* @param position The coordinate to be converted, which can be a Cartesian3, Cartographic, array, or object.
|
|
173
|
-
* @param options Conversion options, including conversion type and whether to include altitude information.
|
|
174
|
-
* @returns The converted coordinate, which may be an array or object. If the input position is empty, undefined is returned.
|
|
175
|
-
*
|
|
176
|
-
* @template T Conversion type, optional values are 'Array' or 'Object', @default 'Array'.
|
|
177
|
-
* @template Alt Whether to include altitude information, default is false
|
|
178
|
-
*/
|
|
179
|
-
function toCoord(position, options = {}) {
|
|
180
|
-
if (!position) return void 0;
|
|
181
|
-
const { type = "Array", alt = false } = options;
|
|
182
|
-
let longitude, latitude, height;
|
|
183
|
-
if (position instanceof Cartesian3) {
|
|
184
|
-
const cartographic = Ellipsoid.WGS84.cartesianToCartographic(position);
|
|
185
|
-
longitude = Math$1.toDegrees(cartographic.longitude);
|
|
186
|
-
latitude = Math$1.toDegrees(cartographic.latitude);
|
|
187
|
-
height = cartographic.height;
|
|
188
|
-
} else if (position instanceof Cartographic) {
|
|
189
|
-
const cartographic = position;
|
|
190
|
-
longitude = Math$1.toDegrees(cartographic.longitude);
|
|
191
|
-
latitude = Math$1.toDegrees(cartographic.latitude);
|
|
192
|
-
height = cartographic.height;
|
|
193
|
-
} else if (Array.isArray(position)) {
|
|
194
|
-
longitude = Math$1.toDegrees(position[0]);
|
|
195
|
-
latitude = Math$1.toDegrees(position[1]);
|
|
196
|
-
height = position[2];
|
|
197
|
-
} else {
|
|
198
|
-
longitude = position.longitude;
|
|
199
|
-
latitude = position.latitude;
|
|
200
|
-
height = position.height;
|
|
201
|
-
}
|
|
202
|
-
if (type === "Array") return alt ? [
|
|
203
|
-
longitude,
|
|
204
|
-
latitude,
|
|
205
|
-
height
|
|
206
|
-
] : [longitude, latitude];
|
|
207
|
-
else return alt ? {
|
|
208
|
-
longitude,
|
|
209
|
-
latitude,
|
|
210
|
-
height
|
|
211
|
-
} : {
|
|
212
|
-
longitude,
|
|
213
|
-
latitude
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
//#endregion
|
|
218
|
-
//#region utils/convertDMS.ts
|
|
219
|
-
/**
|
|
220
|
-
* Convert degrees to DMS (Degrees Minutes Seconds) format string
|
|
221
|
-
*
|
|
222
|
-
* @param degrees The angle value
|
|
223
|
-
* @param precision The number of decimal places to retain for the seconds, defaults to 3
|
|
224
|
-
* @returns A DMS formatted string in the format: degrees° minutes′ seconds″
|
|
225
|
-
*/
|
|
226
|
-
function dmsEncode(degrees, precision = 3) {
|
|
227
|
-
const str = `${degrees}`;
|
|
228
|
-
let i = str.indexOf(".");
|
|
229
|
-
const d = i < 0 ? str : str.slice(0, Math.max(0, i));
|
|
230
|
-
let m = "0";
|
|
231
|
-
let s = "0";
|
|
232
|
-
if (i > 0) {
|
|
233
|
-
m = `0${str.slice(Math.max(0, i))}`;
|
|
234
|
-
m = `${+m * 60}`;
|
|
235
|
-
i = m.indexOf(".");
|
|
236
|
-
if (i > 0) {
|
|
237
|
-
s = `0${m.slice(Math.max(0, i))}`;
|
|
238
|
-
m = m.slice(0, Math.max(0, i));
|
|
239
|
-
s = `${+s * 60}`;
|
|
240
|
-
i = s.indexOf(".");
|
|
241
|
-
s = s.slice(0, Math.max(0, i + 4));
|
|
242
|
-
s = (+s).toFixed(precision);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return `${Math.abs(+d)}°${+m}′${+s}″`;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Decode a DMS (Degrees Minutes Seconds) formatted string to a decimal angle value
|
|
249
|
-
*
|
|
250
|
-
* @param dmsCode DMS formatted string, e.g. "120°30′45″N"
|
|
251
|
-
* @returns The decoded decimal angle value, or 0 if decoding fails
|
|
252
|
-
*/
|
|
253
|
-
function dmsDecode(dmsCode) {
|
|
254
|
-
const [dd, msStr] = dmsCode.split("°") ?? [];
|
|
255
|
-
const [mm, sStr] = msStr?.split("′") ?? [];
|
|
256
|
-
const ss = sStr?.split("″")[0];
|
|
257
|
-
const d = Number(dd) || 0;
|
|
258
|
-
const m = (Number(mm) || 0) / 60;
|
|
259
|
-
const s = (Number(ss) || 0) / 60 / 60;
|
|
260
|
-
const degrees = d + m + s;
|
|
261
|
-
if (degrees === 0) return 0;
|
|
262
|
-
else {
|
|
263
|
-
let res = degrees;
|
|
264
|
-
if ([
|
|
265
|
-
"W",
|
|
266
|
-
"w",
|
|
267
|
-
"S",
|
|
268
|
-
"s"
|
|
269
|
-
].includes(dmsCode[dmsCode.length - 1])) res = -res;
|
|
270
|
-
return res;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Convert latitude and longitude coordinates to degrees-minutes-seconds format
|
|
275
|
-
*
|
|
276
|
-
* @param position The latitude and longitude coordinates
|
|
277
|
-
* @param precision The number of decimal places to retain for 'seconds', default is 3
|
|
278
|
-
* @returns Returns the coordinates in degrees-minutes-seconds format, or undefined if the conversion fails
|
|
279
|
-
*/
|
|
280
|
-
function degreesToDms(position, precision = 3) {
|
|
281
|
-
const coord = toCoord(position, { alt: true });
|
|
282
|
-
if (!coord) return;
|
|
283
|
-
const [longitude, latitude, height] = coord;
|
|
284
|
-
const x = dmsEncode(longitude, precision);
|
|
285
|
-
const y = dmsEncode(latitude, precision);
|
|
286
|
-
return [
|
|
287
|
-
`${x}${longitude > 0 ? "E" : "W"}`,
|
|
288
|
-
`${y}${latitude > 0 ? "N" : "S"}`,
|
|
289
|
-
height
|
|
290
|
-
];
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Convert DMS (Degrees Minutes Seconds) format to decimal degrees for latitude and longitude coordinates
|
|
294
|
-
*
|
|
295
|
-
* @param dms The latitude or longitude coordinate in DMS format
|
|
296
|
-
* @returns Returns the coordinate in decimal degrees format, or undefined if the conversion fails
|
|
297
|
-
*/
|
|
298
|
-
function dmsToDegrees(dms) {
|
|
299
|
-
const [x, y, height] = dms;
|
|
300
|
-
const longitude = dmsDecode(x);
|
|
301
|
-
const latitude = dmsDecode(y);
|
|
302
|
-
return [
|
|
303
|
-
longitude,
|
|
304
|
-
latitude,
|
|
305
|
-
Number(height) || 0
|
|
306
|
-
];
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
//#endregion
|
|
310
|
-
//#region utils/isCesiumConstant.ts
|
|
311
|
-
/**
|
|
312
|
-
* Determines if the Cesium property is a constant.
|
|
313
|
-
*
|
|
314
|
-
* @param value Cesium property
|
|
315
|
-
*/
|
|
316
|
-
function isCesiumConstant(value) {
|
|
317
|
-
return !defined(value) || !!value.isConstant;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
//#endregion
|
|
321
|
-
//#region utils/material.ts
|
|
322
|
-
/**
|
|
323
|
-
* Only as a type fix for `Cesium.Material`
|
|
324
|
-
*/
|
|
325
|
-
var CesiumMaterial = class extends Material {
|
|
326
|
-
constructor(options) {
|
|
327
|
-
super(options);
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
/**
|
|
331
|
-
* Get material from cache, alias of `Material._materialCache.getMaterial`
|
|
332
|
-
*/
|
|
333
|
-
function getMaterialCache(type) {
|
|
334
|
-
return Material._materialCache.getMaterial(type);
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Add material to Cesium's material cache, alias of `Material._materialCache.addMaterial`
|
|
338
|
-
*/
|
|
339
|
-
function addMaterialCache(type, material) {
|
|
340
|
-
return Material._materialCache.addMaterial(type, material);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
//#endregion
|
|
344
|
-
//#region utils/pick.ts
|
|
345
|
-
/**
|
|
346
|
-
* Analyze the result of Cesium's `scene.pick` and convert it to an array format
|
|
347
|
-
*/
|
|
348
|
-
function resolvePick(pick = {}) {
|
|
349
|
-
const { primitive, id, primitiveCollection, collection } = pick;
|
|
350
|
-
const entityCollection = id && id.entityCollection || null;
|
|
351
|
-
const dataSource = entityCollection && entityCollection.owner || null;
|
|
352
|
-
const ids = Array.isArray(id) ? id : [id].filter(Boolean);
|
|
353
|
-
return [
|
|
354
|
-
...ids,
|
|
355
|
-
primitive,
|
|
356
|
-
primitiveCollection,
|
|
357
|
-
collection,
|
|
358
|
-
entityCollection,
|
|
359
|
-
dataSource
|
|
360
|
-
].filter((e) => !!e);
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Determine if the given array of graphics is hit by Cesium's `scene.pick`
|
|
364
|
-
*
|
|
365
|
-
* @param pick The `scene.pick` object used for matching
|
|
366
|
-
* @param graphic An array of graphics to check for hits
|
|
367
|
-
*/
|
|
368
|
-
function pickHitGraphic(pick, graphic) {
|
|
369
|
-
if (!Array.isArray(graphic) || !graphic.length) return false;
|
|
370
|
-
const elements = resolvePick(pick);
|
|
371
|
-
if (!elements.length) return false;
|
|
372
|
-
return elements.some((element) => graphic.includes(element));
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
//#endregion
|
|
376
|
-
//#region utils/property.ts
|
|
377
|
-
/**
|
|
378
|
-
* Is Cesium.Property
|
|
379
|
-
* @param value - The target object
|
|
380
|
-
*/
|
|
381
|
-
function isProperty(value) {
|
|
382
|
-
return value && isFunction(value.getValue);
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Converts a value that may be a Property into its target value, @see {toProperty} for the reverse operation
|
|
386
|
-
* ```typescript
|
|
387
|
-
* toPropertyValue('val') //=> 'val'
|
|
388
|
-
* toPropertyValue(new ConstantProperty('val')) //=> 'val'
|
|
389
|
-
* toPropertyValue(new CallbackProperty(()=>'val')) //=> 'val'
|
|
390
|
-
* ```
|
|
391
|
-
*
|
|
392
|
-
* @param value - The value to convert
|
|
393
|
-
*/
|
|
394
|
-
function toPropertyValue(value, time) {
|
|
395
|
-
return isProperty(value) ? value.getValue(time) : value;
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Converts a value that may be a Property into a Property object, @see {toPropertyValue} for the reverse operation
|
|
399
|
-
*
|
|
400
|
-
* @param value - The property value or getter to convert, can be undefined or null
|
|
401
|
-
* @param isConstant - The second parameter for converting to CallbackProperty
|
|
402
|
-
* @returns Returns the converted Property object, if value is undefined or null, returns undefined
|
|
403
|
-
*/
|
|
404
|
-
function toProperty(value, isConstant = false) {
|
|
405
|
-
return isProperty(value) ? value : isFunction(value) ? new CallbackProperty(value, isConstant) : new ConstantProperty(value);
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Create a Cesium property key
|
|
409
|
-
*
|
|
410
|
-
* @param scope The host object
|
|
411
|
-
* @param field The property name
|
|
412
|
-
* @param maybeProperty Optional property or getter
|
|
413
|
-
* @param readonly Whether the property is read-only
|
|
414
|
-
*/
|
|
415
|
-
function createPropertyField(scope, field, maybeProperty, readonly$1) {
|
|
416
|
-
let removeOwnerListener;
|
|
417
|
-
const ownerBinding = (value) => {
|
|
418
|
-
removeOwnerListener?.();
|
|
419
|
-
if (defined(value?.definitionChanged)) removeOwnerListener = value?.definitionChanged?.addEventListener(() => {
|
|
420
|
-
scope.definitionChanged.raiseEvent(scope, field, value, value);
|
|
421
|
-
});
|
|
422
|
-
};
|
|
423
|
-
const privateField = `_${field}`;
|
|
424
|
-
const property = toProperty(maybeProperty);
|
|
425
|
-
scope[privateField] = property;
|
|
426
|
-
ownerBinding(property);
|
|
427
|
-
if (readonly$1) Object.defineProperty(scope, field, { get() {
|
|
428
|
-
return scope[privateField];
|
|
429
|
-
} });
|
|
430
|
-
else Object.defineProperty(scope, field, {
|
|
431
|
-
get() {
|
|
432
|
-
return scope[privateField];
|
|
433
|
-
},
|
|
434
|
-
set(value) {
|
|
435
|
-
const previous = scope[privateField];
|
|
436
|
-
if (scope[privateField] !== value) {
|
|
437
|
-
scope[privateField] = value;
|
|
438
|
-
ownerBinding(value);
|
|
439
|
-
if (defined(scope.definitionChanged)) scope.definitionChanged.raiseEvent(scope, field, value, previous);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
function createCesiumAttribute(scope, key, value, options = {}) {
|
|
445
|
-
const allowToProperty = !!options.toProperty;
|
|
446
|
-
const shallowClone = !!options.shallowClone;
|
|
447
|
-
const changedEventKey = options.changedEventKey || "definitionChanged";
|
|
448
|
-
const changedEvent = Reflect.get(scope, changedEventKey);
|
|
449
|
-
const privateKey = `_${String(key)}`;
|
|
450
|
-
const attribute = allowToProperty ? toProperty(value) : value;
|
|
451
|
-
Reflect.set(scope, privateKey, attribute);
|
|
452
|
-
const obj = { get() {
|
|
453
|
-
const value$1 = Reflect.get(scope, privateKey);
|
|
454
|
-
if (shallowClone) return Array.isArray(value$1) ? [...value$1] : { ...value$1 };
|
|
455
|
-
else return value$1;
|
|
456
|
-
} };
|
|
457
|
-
let previousListener;
|
|
458
|
-
const serial = (property, previous) => {
|
|
459
|
-
previousListener?.();
|
|
460
|
-
previousListener = property?.definitionChanged?.addEventListener(() => {
|
|
461
|
-
changedEvent?.raiseEvent.bind(changedEvent)(scope, key, property, previous);
|
|
462
|
-
});
|
|
463
|
-
};
|
|
464
|
-
if (!options.readonly) {
|
|
465
|
-
if (allowToProperty && isProperty(value)) serial(value);
|
|
466
|
-
obj.set = (value$1) => {
|
|
467
|
-
if (allowToProperty && !isProperty(value$1)) throw new Error(`The value of ${String(key)} must be a Cesium.Property object`);
|
|
468
|
-
const previous = Reflect.get(scope, privateKey);
|
|
469
|
-
if (previous !== value$1) {
|
|
470
|
-
Reflect.set(scope, privateKey, value$1);
|
|
471
|
-
changedEvent?.raiseEvent.bind(changedEvent)(scope, key, value$1, previous);
|
|
472
|
-
if (allowToProperty) serial(value$1);
|
|
473
|
-
}
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
Object.defineProperty(scope, key, obj);
|
|
477
|
-
}
|
|
478
|
-
function createCesiumProperty(scope, key, value, options = {}) {
|
|
479
|
-
return createCesiumAttribute(scope, key, value, {
|
|
480
|
-
...options,
|
|
481
|
-
toProperty: true
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
//#endregion
|
|
486
|
-
//#region utils/throttle.ts
|
|
487
|
-
/**
|
|
488
|
-
* Throttle function, which limits the frequency of execution of the function
|
|
489
|
-
*
|
|
490
|
-
* @param callback raw function
|
|
491
|
-
* @param delay Throttled delay duration (ms)
|
|
492
|
-
* @param trailing Trigger callback function after last call @default true
|
|
493
|
-
* @param leading Trigger the callback function immediately on the first call @default false
|
|
494
|
-
* @returns Throttle function
|
|
495
|
-
*/
|
|
496
|
-
function throttle(callback, delay = 100, trailing = true, leading = false) {
|
|
497
|
-
const restList = [];
|
|
498
|
-
let tracked = false;
|
|
499
|
-
const trigger = async () => {
|
|
500
|
-
await promiseTimeout(delay);
|
|
501
|
-
tracked = false;
|
|
502
|
-
if (leading) try {
|
|
503
|
-
callback(...restList[0]);
|
|
504
|
-
} catch (error) {
|
|
505
|
-
console.error(error);
|
|
506
|
-
}
|
|
507
|
-
if (trailing && (!leading || restList.length > 1)) try {
|
|
508
|
-
callback(...restList[restList.length - 1]);
|
|
509
|
-
} catch (error) {
|
|
510
|
-
console.error(error);
|
|
511
|
-
}
|
|
512
|
-
restList.length = 0;
|
|
513
|
-
};
|
|
514
|
-
return (...rest) => {
|
|
515
|
-
if (restList.length < 2) restList.push(rest);
|
|
516
|
-
else restList[1] = rest;
|
|
517
|
-
if (!tracked) {
|
|
518
|
-
tracked = true;
|
|
519
|
-
trigger();
|
|
520
|
-
}
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
//#endregion
|
|
525
|
-
//#region utils/toCartesian3.ts
|
|
526
|
-
/**
|
|
527
|
-
* Converts position to a coordinate point in the Cartesian coordinate system
|
|
528
|
-
*
|
|
529
|
-
* @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
|
|
530
|
-
* @returns The converted Cartesian coordinate point. If the input parameter is invalid, undefined is returned
|
|
531
|
-
*/
|
|
532
|
-
function toCartesian3(position) {
|
|
533
|
-
if (!position) return void 0;
|
|
534
|
-
if (position instanceof Cartesian3) return position.clone();
|
|
535
|
-
else if (position instanceof Cartographic) return Ellipsoid.WGS84.cartographicToCartesian(position);
|
|
536
|
-
else if (Array.isArray(position)) return Cartesian3.fromDegrees(position[0], position[1], position[2]);
|
|
537
|
-
else return Cartesian3.fromDegrees(position.longitude, position.latitude, position.height);
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
//#endregion
|
|
541
|
-
//#region utils/toCartographic.ts
|
|
542
|
-
/**
|
|
543
|
-
* Converts a position to a Cartographic coordinate point
|
|
544
|
-
*
|
|
545
|
-
* @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
|
|
546
|
-
* @returns The converted Cartographic coordinate point, or undefined if the input parameter is invalid
|
|
547
|
-
*/
|
|
548
|
-
function toCartographic(position) {
|
|
549
|
-
if (!position) return void 0;
|
|
550
|
-
if (position instanceof Cartesian3) return Ellipsoid.WGS84.cartesianToCartographic(position);
|
|
551
|
-
else if (position instanceof Cartographic) return position.clone();
|
|
552
|
-
else if (Array.isArray(position)) return Cartographic.fromDegrees(position[0], position[1], position[2]);
|
|
553
|
-
else return Cartographic.fromDegrees(position.longitude, position.latitude, position.height);
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
//#endregion
|
|
557
|
-
//#region utils/tryRun.ts
|
|
558
|
-
/**
|
|
559
|
-
* Safely execute the provided function without throwing errors,
|
|
560
|
-
* essentially a simple wrapper around a `try...catch...` block
|
|
561
|
-
*/
|
|
562
|
-
function tryRun(fn) {
|
|
563
|
-
return (...args) => {
|
|
564
|
-
try {
|
|
565
|
-
return fn?.(...args);
|
|
566
|
-
} catch (error) {
|
|
567
|
-
console.error(error);
|
|
568
|
-
}
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
|
|
572
49
|
//#endregion
|
|
573
50
|
//#region toPromiseValue/index.ts
|
|
574
51
|
/**
|
|
@@ -739,16 +216,13 @@ function useCesiumFps(options = {}) {
|
|
|
739
216
|
/**
|
|
740
217
|
* Scope the SideEffects of Cesium-related `Collection` and automatically remove them when unmounted.
|
|
741
218
|
* - note: This is a basic function that is intended to be called by other lower-level function
|
|
742
|
-
* @param addFn - add SideEffect function. eg.`entites.add`
|
|
743
|
-
* @param removeFn - Clean SideEffect function. eg.`entities.remove`
|
|
744
|
-
* @param removeScopeArgs - The parameters to pass for `removeScope` triggered when the component is unmounted
|
|
745
|
-
*
|
|
746
219
|
* @returns Contains side effect addition and removal functions
|
|
747
220
|
*/
|
|
748
|
-
function useCollectionScope(
|
|
221
|
+
function useCollectionScope(options) {
|
|
222
|
+
const { addEffect, removeEffect, removeScopeArgs } = options;
|
|
749
223
|
const scope = shallowReactive(/* @__PURE__ */ new Set());
|
|
750
224
|
const add = (instance, ...args) => {
|
|
751
|
-
const result =
|
|
225
|
+
const result = addEffect(instance, ...args);
|
|
752
226
|
if (isPromise(result)) return new Promise((resolve, reject) => {
|
|
753
227
|
result.then((i) => {
|
|
754
228
|
scope.add(i);
|
|
@@ -762,7 +236,7 @@ function useCollectionScope(addFn, removeFn, removeScopeArgs) {
|
|
|
762
236
|
};
|
|
763
237
|
const remove = (instance, ...args) => {
|
|
764
238
|
scope.delete(instance);
|
|
765
|
-
return
|
|
239
|
+
return removeEffect(instance, ...args);
|
|
766
240
|
};
|
|
767
241
|
const removeWhere = (predicate, ...args) => {
|
|
768
242
|
scope.forEach((instance) => {
|
|
@@ -791,8 +265,7 @@ function useDataSource(dataSources, options = {}) {
|
|
|
791
265
|
const result = computedAsync(() => toPromiseValue(dataSources), void 0, { evaluating });
|
|
792
266
|
const viewer = useViewer();
|
|
793
267
|
watchEffect((onCleanup) => {
|
|
794
|
-
|
|
795
|
-
if (_isActive) {
|
|
268
|
+
if (toValue(isActive)) {
|
|
796
269
|
const list = Array.isArray(result.value) ? [...result.value] : [result.value];
|
|
797
270
|
const _collection = collection ?? viewer.value?.dataSources;
|
|
798
271
|
list.forEach((item) => item && _collection?.add(item));
|
|
@@ -808,7 +281,7 @@ function useDataSource(dataSources, options = {}) {
|
|
|
808
281
|
//#endregion
|
|
809
282
|
//#region useDataSourceScope/index.ts
|
|
810
283
|
/**
|
|
811
|
-
*
|
|
284
|
+
* Scope the SideEffects of `DataSourceCollection` operations and automatically remove them when unmounted
|
|
812
285
|
*/
|
|
813
286
|
function useDataSourceScope(options = {}) {
|
|
814
287
|
const { collection: _collection, destroyOnRemove } = options;
|
|
@@ -816,21 +289,25 @@ function useDataSourceScope(options = {}) {
|
|
|
816
289
|
const collection = computed(() => {
|
|
817
290
|
return toValue(_collection) ?? viewer.value?.dataSources;
|
|
818
291
|
});
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
292
|
+
return useCollectionScope({
|
|
293
|
+
addEffect(instance) {
|
|
294
|
+
if (!collection.value) throw new Error("collection is not defined");
|
|
295
|
+
if (isPromise(instance)) return new Promise((resolve, reject) => {
|
|
296
|
+
instance.then((i) => {
|
|
297
|
+
collection.value.add(i);
|
|
298
|
+
resolve(i);
|
|
299
|
+
}).catch((error) => reject(error));
|
|
300
|
+
});
|
|
301
|
+
else {
|
|
302
|
+
collection.value.add(instance);
|
|
303
|
+
return instance;
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
removeEffect(instance, destroy) {
|
|
307
|
+
return !!collection.value?.remove(instance, destroy);
|
|
308
|
+
},
|
|
309
|
+
removeScopeArgs: [destroyOnRemove]
|
|
310
|
+
});
|
|
834
311
|
}
|
|
835
312
|
|
|
836
313
|
//#endregion
|
|
@@ -850,8 +327,8 @@ function useElementOverlay(target, position, options = {}) {
|
|
|
850
327
|
if (!viewer.value?.scene) return;
|
|
851
328
|
if (!cartesian3.value) coord.value = void 0;
|
|
852
329
|
else {
|
|
853
|
-
const
|
|
854
|
-
coord.value = !Cartesian2.equals(
|
|
330
|
+
const result = cartesianToCanvasCoord(cartesian3.value, viewer.value.scene);
|
|
331
|
+
coord.value = !Cartesian2.equals(result, coord.value) ? result : coord.value;
|
|
855
332
|
}
|
|
856
333
|
});
|
|
857
334
|
const canvasBounding = useElementBounding(() => viewer.value?.canvas.parentElement);
|
|
@@ -912,8 +389,7 @@ function useEntity(data, options = {}) {
|
|
|
912
389
|
const result = computedAsync(() => toPromiseValue(data), [], { evaluating });
|
|
913
390
|
const viewer = useViewer();
|
|
914
391
|
watchEffect((onCleanup) => {
|
|
915
|
-
|
|
916
|
-
if (_isActive) {
|
|
392
|
+
if (toValue(isActive)) {
|
|
917
393
|
const list = Array.isArray(result.value) ? [...result.value] : [result.value];
|
|
918
394
|
const _collection = collection ?? viewer.value?.entities;
|
|
919
395
|
list.forEach((item) => item && _collection?.add(item));
|
|
@@ -937,22 +413,25 @@ function useEntityScope(options = {}) {
|
|
|
937
413
|
const collection = computed(() => {
|
|
938
414
|
return toValue(_collection) ?? viewer.value?.entities;
|
|
939
415
|
});
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
416
|
+
return useCollectionScope({
|
|
417
|
+
addEffect(instance) {
|
|
418
|
+
if (!collection.value) throw new Error("collection is not defined");
|
|
419
|
+
if (isPromise(instance)) return new Promise((resolve, reject) => {
|
|
420
|
+
instance.then((i) => {
|
|
421
|
+
collection.value.add(i);
|
|
422
|
+
resolve(i);
|
|
423
|
+
}).catch((error) => reject(error));
|
|
424
|
+
});
|
|
425
|
+
else {
|
|
426
|
+
collection.value.add(instance);
|
|
427
|
+
return instance;
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
removeEffect(instance) {
|
|
431
|
+
return !!collection.value?.remove(instance);
|
|
432
|
+
},
|
|
433
|
+
removeScopeArgs: []
|
|
434
|
+
});
|
|
956
435
|
}
|
|
957
436
|
|
|
958
437
|
//#endregion
|
|
@@ -1175,7 +654,7 @@ function useGraphicEvent() {
|
|
|
1175
654
|
const collection = /* @__PURE__ */ new WeakMap();
|
|
1176
655
|
const cursorCollection = /* @__PURE__ */ new WeakMap();
|
|
1177
656
|
const dragCursorCollection = /* @__PURE__ */ new WeakMap();
|
|
1178
|
-
const
|
|
657
|
+
const remove = (graphic, type, listener) => {
|
|
1179
658
|
const _graphic = graphic === "global" ? GLOBAL_GRAPHIC_SYMBOL : graphic;
|
|
1180
659
|
collection?.get(_graphic)?.get(type)?.delete(listener);
|
|
1181
660
|
cursorCollection?.get(_graphic)?.get(type)?.delete(listener);
|
|
@@ -1188,13 +667,12 @@ function useGraphicEvent() {
|
|
|
1188
667
|
if (dragCursorCollection?.get(_graphic)?.get(type)?.size === 0) dragCursorCollection?.get(_graphic)?.delete(type);
|
|
1189
668
|
if (dragCursorCollection?.get(_graphic)?.size === 0) dragCursorCollection?.delete(_graphic);
|
|
1190
669
|
};
|
|
1191
|
-
const
|
|
670
|
+
const add = (graphic, type, listener, options = {}) => {
|
|
1192
671
|
const _graphic = graphic === "global" ? GLOBAL_GRAPHIC_SYMBOL : graphic;
|
|
1193
672
|
collection.get(_graphic) ?? collection.set(_graphic, /* @__PURE__ */ new Map());
|
|
1194
673
|
const eventTypeMap = collection.get(_graphic);
|
|
1195
674
|
eventTypeMap.get(type) ?? eventTypeMap.set(type, /* @__PURE__ */ new Set());
|
|
1196
|
-
|
|
1197
|
-
listeners.add(listener);
|
|
675
|
+
eventTypeMap.get(type).add(listener);
|
|
1198
676
|
let { cursor = "pointer", dragCursor } = options;
|
|
1199
677
|
if (isDef(cursor)) {
|
|
1200
678
|
const _cursor = isFunction(cursor) ? cursor : () => cursor;
|
|
@@ -1202,16 +680,16 @@ function useGraphicEvent() {
|
|
|
1202
680
|
cursorCollection.get(_graphic).get(type) ?? cursorCollection.get(_graphic).set(type, /* @__PURE__ */ new Map());
|
|
1203
681
|
cursorCollection.get(_graphic).get(type).set(listener, _cursor);
|
|
1204
682
|
}
|
|
1205
|
-
if (type === "DRAG") dragCursor ??= (event) => event?.dragging ? "crosshair" : void 0;
|
|
683
|
+
if (type === "DRAG") dragCursor ??= ((event) => event?.dragging ? "crosshair" : void 0);
|
|
1206
684
|
if (isDef(dragCursor)) {
|
|
1207
685
|
const _dragCursor = isFunction(dragCursor) ? dragCursor : () => dragCursor;
|
|
1208
686
|
dragCursorCollection.get(_graphic) ?? dragCursorCollection.set(_graphic, /* @__PURE__ */ new Map());
|
|
1209
687
|
dragCursorCollection.get(_graphic).get(type) ?? dragCursorCollection.get(_graphic).set(type, /* @__PURE__ */ new Map());
|
|
1210
688
|
dragCursorCollection.get(_graphic).get(type).set(listener, _dragCursor);
|
|
1211
689
|
}
|
|
1212
|
-
return () =>
|
|
690
|
+
return () => remove(graphic, type, listener);
|
|
1213
691
|
};
|
|
1214
|
-
const
|
|
692
|
+
const clear = (graphic, type) => {
|
|
1215
693
|
const _graphic = graphic === "global" ? GLOBAL_GRAPHIC_SYMBOL : graphic;
|
|
1216
694
|
if (type === "all") {
|
|
1217
695
|
collection.delete(_graphic);
|
|
@@ -1227,16 +705,14 @@ function useGraphicEvent() {
|
|
|
1227
705
|
if (dragCursorCollection?.get(_graphic)?.size === 0) dragCursorCollection?.delete(_graphic);
|
|
1228
706
|
};
|
|
1229
707
|
for (const type of POSITIONED_EVENT_TYPES) usePositioned(type, (event) => {
|
|
1230
|
-
|
|
1231
|
-
graphics.concat(GLOBAL_GRAPHIC_SYMBOL).forEach((graphic) => {
|
|
708
|
+
resolvePick(event.pick).concat(GLOBAL_GRAPHIC_SYMBOL).forEach((graphic) => {
|
|
1232
709
|
collection.get(graphic)?.get(type)?.forEach((fn) => tryRun(fn)?.(event));
|
|
1233
710
|
});
|
|
1234
711
|
});
|
|
1235
712
|
const dragging = ref(false);
|
|
1236
713
|
const viewer = useViewer();
|
|
1237
714
|
useHover((event) => {
|
|
1238
|
-
|
|
1239
|
-
graphics.forEach((graphic) => {
|
|
715
|
+
resolvePick(event.pick).concat(GLOBAL_GRAPHIC_SYMBOL).forEach((graphic) => {
|
|
1240
716
|
collection.get(graphic)?.get("HOVER")?.forEach((fn) => tryRun(fn)?.(event));
|
|
1241
717
|
if (!dragging.value) cursorCollection.get(graphic)?.forEach((map) => {
|
|
1242
718
|
map.forEach((fn) => {
|
|
@@ -1260,9 +736,9 @@ function useGraphicEvent() {
|
|
|
1260
736
|
});
|
|
1261
737
|
});
|
|
1262
738
|
return {
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
739
|
+
add,
|
|
740
|
+
remove,
|
|
741
|
+
clear
|
|
1266
742
|
};
|
|
1267
743
|
}
|
|
1268
744
|
|
|
@@ -1273,8 +749,7 @@ function useImageryLayer(data, options = {}) {
|
|
|
1273
749
|
const result = computedAsync(() => toPromiseValue(data), [], { evaluating });
|
|
1274
750
|
const viewer = useViewer();
|
|
1275
751
|
watchEffect((onCleanup) => {
|
|
1276
|
-
|
|
1277
|
-
if (_isActive) {
|
|
752
|
+
if (toValue(isActive)) {
|
|
1278
753
|
const list = Array.isArray(result.value) ? [...result.value] : [result.value];
|
|
1279
754
|
const _collection = collection ?? viewer.value?.imageryLayers;
|
|
1280
755
|
if (collection?.isDestroyed()) return;
|
|
@@ -1310,22 +785,25 @@ function useImageryLayerScope(options = {}) {
|
|
|
1310
785
|
const collection = computed(() => {
|
|
1311
786
|
return toValue(_collection) ?? viewer.value?.imageryLayers;
|
|
1312
787
|
});
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
788
|
+
return useCollectionScope({
|
|
789
|
+
addEffect(instance, index) {
|
|
790
|
+
if (!collection.value) throw new Error("collection is not defined");
|
|
791
|
+
if (isPromise(instance)) return new Promise((resolve, reject) => {
|
|
792
|
+
instance.then((i) => {
|
|
793
|
+
collection.value.add(i, index);
|
|
794
|
+
resolve(i);
|
|
795
|
+
}).catch((error) => reject(error));
|
|
796
|
+
});
|
|
797
|
+
else {
|
|
798
|
+
collection.value.add(instance, index);
|
|
799
|
+
return instance;
|
|
800
|
+
}
|
|
801
|
+
},
|
|
802
|
+
removeEffect(instance, destroy) {
|
|
803
|
+
return !!collection.value?.remove(instance, destroy);
|
|
804
|
+
},
|
|
805
|
+
removeScopeArgs: [destroyOnRemove]
|
|
806
|
+
});
|
|
1329
807
|
}
|
|
1330
808
|
|
|
1331
809
|
//#endregion
|
|
@@ -1336,8 +814,7 @@ function usePostProcessStage(data, options = {}) {
|
|
|
1336
814
|
const viewer = useViewer();
|
|
1337
815
|
watchEffect((onCleanup) => {
|
|
1338
816
|
if (!viewer.value) return;
|
|
1339
|
-
|
|
1340
|
-
if (_isActive) {
|
|
817
|
+
if (toValue(isActive)) {
|
|
1341
818
|
const list = Array.isArray(result.value) ? [...result.value] : [result.value];
|
|
1342
819
|
const _collection = collection ?? viewer.value.scene.postProcessStages;
|
|
1343
820
|
list.forEach((item) => item && _collection.add(item));
|
|
@@ -1361,21 +838,22 @@ function usePostProcessStageScope(options = {}) {
|
|
|
1361
838
|
const collection = computed(() => {
|
|
1362
839
|
return toValue(_collection) ?? viewer.value?.postProcessStages;
|
|
1363
840
|
});
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
841
|
+
return useCollectionScope({
|
|
842
|
+
addEffect(instance) {
|
|
843
|
+
if (!collection.value) throw new Error("collection is not defined");
|
|
844
|
+
if (isPromise(instance)) return new Promise((resolve, reject) => {
|
|
845
|
+
instance.then((instance$1) => {
|
|
846
|
+
collection.value.add(instance$1);
|
|
847
|
+
resolve(instance$1);
|
|
848
|
+
}).catch((error) => reject(error));
|
|
849
|
+
});
|
|
850
|
+
else return collection.value.add(instance);
|
|
851
|
+
},
|
|
852
|
+
removeEffect(instance, ...args) {
|
|
853
|
+
return !!collection.value?.remove(instance, ...args);
|
|
854
|
+
},
|
|
855
|
+
removeScopeArgs: []
|
|
856
|
+
});
|
|
1379
857
|
}
|
|
1380
858
|
|
|
1381
859
|
//#endregion
|
|
@@ -1385,8 +863,7 @@ function usePrimitive(data, options = {}) {
|
|
|
1385
863
|
const result = computedAsync(() => toPromiseValue(data), void 0, { evaluating });
|
|
1386
864
|
const viewer = useViewer();
|
|
1387
865
|
watchEffect((onCleanup) => {
|
|
1388
|
-
|
|
1389
|
-
if (_isActive) {
|
|
866
|
+
if (toValue(isActive)) {
|
|
1390
867
|
const list = Array.isArray(result.value) ? [...result.value] : [result.value];
|
|
1391
868
|
const _collection = collection === "ground" ? viewer.value?.scene.groundPrimitives : collection ?? viewer.value?.scene.primitives;
|
|
1392
869
|
list.forEach((item) => item && _collection?.add(item));
|
|
@@ -1408,16 +885,22 @@ function usePrimitiveScope(options = {}) {
|
|
|
1408
885
|
const { collection: _collection } = options;
|
|
1409
886
|
const viewer = useViewer();
|
|
1410
887
|
const collection = computed(() => {
|
|
1411
|
-
|
|
888
|
+
const value = toValue(_collection);
|
|
889
|
+
return value === "ground" ? viewer.value?.scene?.groundPrimitives : value || viewer.value?.scene.primitives;
|
|
890
|
+
});
|
|
891
|
+
const { scope, add, remove, removeWhere, removeScope } = useCollectionScope({
|
|
892
|
+
addEffect(instance, ...args) {
|
|
893
|
+
if (!collection.value) throw new Error("collection is not defined");
|
|
894
|
+
if (isPromise(instance)) return new Promise((resolve, reject) => {
|
|
895
|
+
instance.then((instance$1) => resolve(collection.value.add(instance$1, ...args))).catch((error) => reject(error));
|
|
896
|
+
});
|
|
897
|
+
else return collection.value.add(instance, ...args);
|
|
898
|
+
},
|
|
899
|
+
removeEffect(instance) {
|
|
900
|
+
return !!collection.value?.remove(instance);
|
|
901
|
+
},
|
|
902
|
+
removeScopeArgs: []
|
|
1412
903
|
});
|
|
1413
|
-
const addFn = (primitive) => {
|
|
1414
|
-
if (!collection.value) throw new Error("collection is not defined");
|
|
1415
|
-
return collection.value.add(primitive);
|
|
1416
|
-
};
|
|
1417
|
-
const removeFn = (primitive) => {
|
|
1418
|
-
return !!collection.value?.remove(primitive);
|
|
1419
|
-
};
|
|
1420
|
-
const { scope, add, remove, removeWhere, removeScope } = useCollectionScope(addFn, removeFn, []);
|
|
1421
904
|
return {
|
|
1422
905
|
scope,
|
|
1423
906
|
add,
|
|
@@ -1486,10 +969,7 @@ function useScaleBar(options = {}) {
|
|
|
1486
969
|
const leftPosition = scene.globe.pick(left, scene);
|
|
1487
970
|
const rightPosition = scene.globe.pick(right, scene);
|
|
1488
971
|
if (!leftPosition || !rightPosition) return;
|
|
1489
|
-
|
|
1490
|
-
const rightCartographic = scene.globe.ellipsoid.cartesianToCartographic(rightPosition);
|
|
1491
|
-
const geodesic = new EllipsoidGeodesic(leftCartographic, rightCartographic);
|
|
1492
|
-
pixelDistance.value = geodesic.surfaceDistance;
|
|
972
|
+
pixelDistance.value = new EllipsoidGeodesic(scene.globe.ellipsoid.cartesianToCartographic(leftPosition), scene.globe.ellipsoid.cartesianToCartographic(rightPosition)).surfaceDistance;
|
|
1493
973
|
};
|
|
1494
974
|
watchImmediate(viewer, () => setPixelDistance());
|
|
1495
975
|
useCesiumEventListener(() => viewer.value?.camera.changed, throttle(setPixelDistance, delay));
|
|
@@ -1497,10 +977,7 @@ function useScaleBar(options = {}) {
|
|
|
1497
977
|
if (pixelDistance.value) return distances.find((item) => pixelDistance.value * maxPixelRef.value > item);
|
|
1498
978
|
});
|
|
1499
979
|
const width = computed(() => {
|
|
1500
|
-
if (distance.value && pixelDistance.value)
|
|
1501
|
-
const value = distance.value / pixelDistance.value;
|
|
1502
|
-
return value;
|
|
1503
|
-
}
|
|
980
|
+
if (distance.value && pixelDistance.value) return distance.value / pixelDistance.value;
|
|
1504
981
|
return 0;
|
|
1505
982
|
});
|
|
1506
983
|
const distanceText = computed(() => {
|
|
@@ -1526,12 +1003,11 @@ function useSceneDrillPick(windowPosition, options = {}) {
|
|
|
1526
1003
|
const { width = 3, height = 3, limit, throttled = 8, isActive = true } = options;
|
|
1527
1004
|
const viewer = useViewer();
|
|
1528
1005
|
const position = refThrottled(computed(() => toValue(windowPosition)), throttled, false, true);
|
|
1529
|
-
|
|
1006
|
+
return computed(() => {
|
|
1530
1007
|
if (position.value && toValue(isActive)) return viewer.value?.scene.drillPick(position.value, toValue(limit), toValue(width), toValue(height));
|
|
1531
1008
|
});
|
|
1532
|
-
return pick;
|
|
1533
1009
|
}
|
|
1534
1010
|
|
|
1535
1011
|
//#endregion
|
|
1536
|
-
export { CREATE_VIEWER_COLLECTION, CREATE_VIEWER_INJECTION_KEY,
|
|
1012
|
+
export { CREATE_VIEWER_COLLECTION, CREATE_VIEWER_INJECTION_KEY, createViewer, toPromiseValue, useCameraState, useCesiumEventListener, useCesiumFps, useCollectionScope, useDataSource, useDataSourceScope, useElementOverlay, useEntity, useEntityScope, useGraphicEvent, useImageryLayer, useImageryLayerScope, usePostProcessStage, usePostProcessStageScope, usePrimitive, usePrimitiveScope, useScaleBar, useSceneDrillPick, useScenePick, useScreenSpaceEventHandler, useViewer };
|
|
1537
1013
|
//# sourceMappingURL=index.mjs.map
|