vesium 1.0.1-beta.52 → 1.0.1-beta.57
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 +151 -723
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +54 -555
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +54 -555
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +896 -1472
- 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 +130 -647
- 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, toCartographic, 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
|
|
@@ -839,19 +316,26 @@ function useDataSourceScope(options = {}) {
|
|
|
839
316
|
* Cesium HtmlElement Overlay
|
|
840
317
|
*/
|
|
841
318
|
function useElementOverlay(target, position, options = {}) {
|
|
842
|
-
const { referenceWindow, horizontal = "center", vertical = "bottom", offset = {
|
|
319
|
+
const { referenceWindow, horizontal = "center", vertical = "bottom", clampToGround, offset = {
|
|
843
320
|
x: 0,
|
|
844
321
|
y: 0
|
|
845
322
|
} } = options;
|
|
846
|
-
const cartesian3 = computed(() => toCartesian3(toValue(position)));
|
|
847
323
|
const viewer = useViewer();
|
|
324
|
+
const cartesian3 = computed(() => {
|
|
325
|
+
if (!toValue(clampToGround)) return toCartesian3(toValue(position));
|
|
326
|
+
else {
|
|
327
|
+
const cartographic = toCartographic(toValue(position));
|
|
328
|
+
cartographic.height = +(viewer.value?.scene.globe.getHeight(cartographic) || 0).toFixed(2);
|
|
329
|
+
return toCartesian3(cartographic);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
848
332
|
const coord = shallowRef();
|
|
849
333
|
useCesiumEventListener(() => viewer.value?.scene.postRender, () => {
|
|
850
334
|
if (!viewer.value?.scene) return;
|
|
851
335
|
if (!cartesian3.value) coord.value = void 0;
|
|
852
336
|
else {
|
|
853
|
-
const
|
|
854
|
-
coord.value = !Cartesian2.equals(
|
|
337
|
+
const result = cartesianToCanvasCoord(cartesian3.value, viewer.value.scene);
|
|
338
|
+
coord.value = !Cartesian2.equals(result, coord.value) ? result : coord.value;
|
|
855
339
|
}
|
|
856
340
|
});
|
|
857
341
|
const canvasBounding = useElementBounding(() => viewer.value?.canvas.parentElement);
|
|
@@ -912,8 +396,7 @@ function useEntity(data, options = {}) {
|
|
|
912
396
|
const result = computedAsync(() => toPromiseValue(data), [], { evaluating });
|
|
913
397
|
const viewer = useViewer();
|
|
914
398
|
watchEffect((onCleanup) => {
|
|
915
|
-
|
|
916
|
-
if (_isActive) {
|
|
399
|
+
if (toValue(isActive)) {
|
|
917
400
|
const list = Array.isArray(result.value) ? [...result.value] : [result.value];
|
|
918
401
|
const _collection = collection ?? viewer.value?.entities;
|
|
919
402
|
list.forEach((item) => item && _collection?.add(item));
|
|
@@ -937,22 +420,25 @@ function useEntityScope(options = {}) {
|
|
|
937
420
|
const collection = computed(() => {
|
|
938
421
|
return toValue(_collection) ?? viewer.value?.entities;
|
|
939
422
|
});
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
423
|
+
return useCollectionScope({
|
|
424
|
+
addEffect(instance) {
|
|
425
|
+
if (!collection.value) throw new Error("collection is not defined");
|
|
426
|
+
if (isPromise(instance)) return new Promise((resolve, reject) => {
|
|
427
|
+
instance.then((i) => {
|
|
428
|
+
collection.value.add(i);
|
|
429
|
+
resolve(i);
|
|
430
|
+
}).catch((error) => reject(error));
|
|
431
|
+
});
|
|
432
|
+
else {
|
|
433
|
+
collection.value.add(instance);
|
|
434
|
+
return instance;
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
removeEffect(instance) {
|
|
438
|
+
return !!collection.value?.remove(instance);
|
|
439
|
+
},
|
|
440
|
+
removeScopeArgs: []
|
|
441
|
+
});
|
|
956
442
|
}
|
|
957
443
|
|
|
958
444
|
//#endregion
|
|
@@ -1175,7 +661,7 @@ function useGraphicEvent() {
|
|
|
1175
661
|
const collection = /* @__PURE__ */ new WeakMap();
|
|
1176
662
|
const cursorCollection = /* @__PURE__ */ new WeakMap();
|
|
1177
663
|
const dragCursorCollection = /* @__PURE__ */ new WeakMap();
|
|
1178
|
-
const
|
|
664
|
+
const remove = (graphic, type, listener) => {
|
|
1179
665
|
const _graphic = graphic === "global" ? GLOBAL_GRAPHIC_SYMBOL : graphic;
|
|
1180
666
|
collection?.get(_graphic)?.get(type)?.delete(listener);
|
|
1181
667
|
cursorCollection?.get(_graphic)?.get(type)?.delete(listener);
|
|
@@ -1188,13 +674,12 @@ function useGraphicEvent() {
|
|
|
1188
674
|
if (dragCursorCollection?.get(_graphic)?.get(type)?.size === 0) dragCursorCollection?.get(_graphic)?.delete(type);
|
|
1189
675
|
if (dragCursorCollection?.get(_graphic)?.size === 0) dragCursorCollection?.delete(_graphic);
|
|
1190
676
|
};
|
|
1191
|
-
const
|
|
677
|
+
const add = (graphic, type, listener, options = {}) => {
|
|
1192
678
|
const _graphic = graphic === "global" ? GLOBAL_GRAPHIC_SYMBOL : graphic;
|
|
1193
679
|
collection.get(_graphic) ?? collection.set(_graphic, /* @__PURE__ */ new Map());
|
|
1194
680
|
const eventTypeMap = collection.get(_graphic);
|
|
1195
681
|
eventTypeMap.get(type) ?? eventTypeMap.set(type, /* @__PURE__ */ new Set());
|
|
1196
|
-
|
|
1197
|
-
listeners.add(listener);
|
|
682
|
+
eventTypeMap.get(type).add(listener);
|
|
1198
683
|
let { cursor = "pointer", dragCursor } = options;
|
|
1199
684
|
if (isDef(cursor)) {
|
|
1200
685
|
const _cursor = isFunction(cursor) ? cursor : () => cursor;
|
|
@@ -1202,16 +687,16 @@ function useGraphicEvent() {
|
|
|
1202
687
|
cursorCollection.get(_graphic).get(type) ?? cursorCollection.get(_graphic).set(type, /* @__PURE__ */ new Map());
|
|
1203
688
|
cursorCollection.get(_graphic).get(type).set(listener, _cursor);
|
|
1204
689
|
}
|
|
1205
|
-
if (type === "DRAG") dragCursor ??= (event) => event?.dragging ? "crosshair" : void 0;
|
|
690
|
+
if (type === "DRAG") dragCursor ??= ((event) => event?.dragging ? "crosshair" : void 0);
|
|
1206
691
|
if (isDef(dragCursor)) {
|
|
1207
692
|
const _dragCursor = isFunction(dragCursor) ? dragCursor : () => dragCursor;
|
|
1208
693
|
dragCursorCollection.get(_graphic) ?? dragCursorCollection.set(_graphic, /* @__PURE__ */ new Map());
|
|
1209
694
|
dragCursorCollection.get(_graphic).get(type) ?? dragCursorCollection.get(_graphic).set(type, /* @__PURE__ */ new Map());
|
|
1210
695
|
dragCursorCollection.get(_graphic).get(type).set(listener, _dragCursor);
|
|
1211
696
|
}
|
|
1212
|
-
return () =>
|
|
697
|
+
return () => remove(graphic, type, listener);
|
|
1213
698
|
};
|
|
1214
|
-
const
|
|
699
|
+
const clear = (graphic, type) => {
|
|
1215
700
|
const _graphic = graphic === "global" ? GLOBAL_GRAPHIC_SYMBOL : graphic;
|
|
1216
701
|
if (type === "all") {
|
|
1217
702
|
collection.delete(_graphic);
|
|
@@ -1227,16 +712,14 @@ function useGraphicEvent() {
|
|
|
1227
712
|
if (dragCursorCollection?.get(_graphic)?.size === 0) dragCursorCollection?.delete(_graphic);
|
|
1228
713
|
};
|
|
1229
714
|
for (const type of POSITIONED_EVENT_TYPES) usePositioned(type, (event) => {
|
|
1230
|
-
|
|
1231
|
-
graphics.concat(GLOBAL_GRAPHIC_SYMBOL).forEach((graphic) => {
|
|
715
|
+
resolvePick(event.pick).concat(GLOBAL_GRAPHIC_SYMBOL).forEach((graphic) => {
|
|
1232
716
|
collection.get(graphic)?.get(type)?.forEach((fn) => tryRun(fn)?.(event));
|
|
1233
717
|
});
|
|
1234
718
|
});
|
|
1235
719
|
const dragging = ref(false);
|
|
1236
720
|
const viewer = useViewer();
|
|
1237
721
|
useHover((event) => {
|
|
1238
|
-
|
|
1239
|
-
graphics.forEach((graphic) => {
|
|
722
|
+
resolvePick(event.pick).concat(GLOBAL_GRAPHIC_SYMBOL).forEach((graphic) => {
|
|
1240
723
|
collection.get(graphic)?.get("HOVER")?.forEach((fn) => tryRun(fn)?.(event));
|
|
1241
724
|
if (!dragging.value) cursorCollection.get(graphic)?.forEach((map) => {
|
|
1242
725
|
map.forEach((fn) => {
|
|
@@ -1260,9 +743,9 @@ function useGraphicEvent() {
|
|
|
1260
743
|
});
|
|
1261
744
|
});
|
|
1262
745
|
return {
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
746
|
+
add,
|
|
747
|
+
remove,
|
|
748
|
+
clear
|
|
1266
749
|
};
|
|
1267
750
|
}
|
|
1268
751
|
|
|
@@ -1273,8 +756,7 @@ function useImageryLayer(data, options = {}) {
|
|
|
1273
756
|
const result = computedAsync(() => toPromiseValue(data), [], { evaluating });
|
|
1274
757
|
const viewer = useViewer();
|
|
1275
758
|
watchEffect((onCleanup) => {
|
|
1276
|
-
|
|
1277
|
-
if (_isActive) {
|
|
759
|
+
if (toValue(isActive)) {
|
|
1278
760
|
const list = Array.isArray(result.value) ? [...result.value] : [result.value];
|
|
1279
761
|
const _collection = collection ?? viewer.value?.imageryLayers;
|
|
1280
762
|
if (collection?.isDestroyed()) return;
|
|
@@ -1310,22 +792,25 @@ function useImageryLayerScope(options = {}) {
|
|
|
1310
792
|
const collection = computed(() => {
|
|
1311
793
|
return toValue(_collection) ?? viewer.value?.imageryLayers;
|
|
1312
794
|
});
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
795
|
+
return useCollectionScope({
|
|
796
|
+
addEffect(instance, index) {
|
|
797
|
+
if (!collection.value) throw new Error("collection is not defined");
|
|
798
|
+
if (isPromise(instance)) return new Promise((resolve, reject) => {
|
|
799
|
+
instance.then((i) => {
|
|
800
|
+
collection.value.add(i, index);
|
|
801
|
+
resolve(i);
|
|
802
|
+
}).catch((error) => reject(error));
|
|
803
|
+
});
|
|
804
|
+
else {
|
|
805
|
+
collection.value.add(instance, index);
|
|
806
|
+
return instance;
|
|
807
|
+
}
|
|
808
|
+
},
|
|
809
|
+
removeEffect(instance, destroy) {
|
|
810
|
+
return !!collection.value?.remove(instance, destroy);
|
|
811
|
+
},
|
|
812
|
+
removeScopeArgs: [destroyOnRemove]
|
|
813
|
+
});
|
|
1329
814
|
}
|
|
1330
815
|
|
|
1331
816
|
//#endregion
|
|
@@ -1336,8 +821,7 @@ function usePostProcessStage(data, options = {}) {
|
|
|
1336
821
|
const viewer = useViewer();
|
|
1337
822
|
watchEffect((onCleanup) => {
|
|
1338
823
|
if (!viewer.value) return;
|
|
1339
|
-
|
|
1340
|
-
if (_isActive) {
|
|
824
|
+
if (toValue(isActive)) {
|
|
1341
825
|
const list = Array.isArray(result.value) ? [...result.value] : [result.value];
|
|
1342
826
|
const _collection = collection ?? viewer.value.scene.postProcessStages;
|
|
1343
827
|
list.forEach((item) => item && _collection.add(item));
|
|
@@ -1361,21 +845,22 @@ function usePostProcessStageScope(options = {}) {
|
|
|
1361
845
|
const collection = computed(() => {
|
|
1362
846
|
return toValue(_collection) ?? viewer.value?.postProcessStages;
|
|
1363
847
|
});
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
848
|
+
return useCollectionScope({
|
|
849
|
+
addEffect(instance) {
|
|
850
|
+
if (!collection.value) throw new Error("collection is not defined");
|
|
851
|
+
if (isPromise(instance)) return new Promise((resolve, reject) => {
|
|
852
|
+
instance.then((instance$1) => {
|
|
853
|
+
collection.value.add(instance$1);
|
|
854
|
+
resolve(instance$1);
|
|
855
|
+
}).catch((error) => reject(error));
|
|
856
|
+
});
|
|
857
|
+
else return collection.value.add(instance);
|
|
858
|
+
},
|
|
859
|
+
removeEffect(instance, ...args) {
|
|
860
|
+
return !!collection.value?.remove(instance, ...args);
|
|
861
|
+
},
|
|
862
|
+
removeScopeArgs: []
|
|
863
|
+
});
|
|
1379
864
|
}
|
|
1380
865
|
|
|
1381
866
|
//#endregion
|
|
@@ -1385,8 +870,7 @@ function usePrimitive(data, options = {}) {
|
|
|
1385
870
|
const result = computedAsync(() => toPromiseValue(data), void 0, { evaluating });
|
|
1386
871
|
const viewer = useViewer();
|
|
1387
872
|
watchEffect((onCleanup) => {
|
|
1388
|
-
|
|
1389
|
-
if (_isActive) {
|
|
873
|
+
if (toValue(isActive)) {
|
|
1390
874
|
const list = Array.isArray(result.value) ? [...result.value] : [result.value];
|
|
1391
875
|
const _collection = collection === "ground" ? viewer.value?.scene.groundPrimitives : collection ?? viewer.value?.scene.primitives;
|
|
1392
876
|
list.forEach((item) => item && _collection?.add(item));
|
|
@@ -1408,16 +892,22 @@ function usePrimitiveScope(options = {}) {
|
|
|
1408
892
|
const { collection: _collection } = options;
|
|
1409
893
|
const viewer = useViewer();
|
|
1410
894
|
const collection = computed(() => {
|
|
1411
|
-
|
|
895
|
+
const value = toValue(_collection);
|
|
896
|
+
return value === "ground" ? viewer.value?.scene?.groundPrimitives : value || viewer.value?.scene.primitives;
|
|
897
|
+
});
|
|
898
|
+
const { scope, add, remove, removeWhere, removeScope } = useCollectionScope({
|
|
899
|
+
addEffect(instance, ...args) {
|
|
900
|
+
if (!collection.value) throw new Error("collection is not defined");
|
|
901
|
+
if (isPromise(instance)) return new Promise((resolve, reject) => {
|
|
902
|
+
instance.then((instance$1) => resolve(collection.value.add(instance$1, ...args))).catch((error) => reject(error));
|
|
903
|
+
});
|
|
904
|
+
else return collection.value.add(instance, ...args);
|
|
905
|
+
},
|
|
906
|
+
removeEffect(instance) {
|
|
907
|
+
return !!collection.value?.remove(instance);
|
|
908
|
+
},
|
|
909
|
+
removeScopeArgs: []
|
|
1412
910
|
});
|
|
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
911
|
return {
|
|
1422
912
|
scope,
|
|
1423
913
|
add,
|
|
@@ -1486,10 +976,7 @@ function useScaleBar(options = {}) {
|
|
|
1486
976
|
const leftPosition = scene.globe.pick(left, scene);
|
|
1487
977
|
const rightPosition = scene.globe.pick(right, scene);
|
|
1488
978
|
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;
|
|
979
|
+
pixelDistance.value = new EllipsoidGeodesic(scene.globe.ellipsoid.cartesianToCartographic(leftPosition), scene.globe.ellipsoid.cartesianToCartographic(rightPosition)).surfaceDistance;
|
|
1493
980
|
};
|
|
1494
981
|
watchImmediate(viewer, () => setPixelDistance());
|
|
1495
982
|
useCesiumEventListener(() => viewer.value?.camera.changed, throttle(setPixelDistance, delay));
|
|
@@ -1497,10 +984,7 @@ function useScaleBar(options = {}) {
|
|
|
1497
984
|
if (pixelDistance.value) return distances.find((item) => pixelDistance.value * maxPixelRef.value > item);
|
|
1498
985
|
});
|
|
1499
986
|
const width = computed(() => {
|
|
1500
|
-
if (distance.value && pixelDistance.value)
|
|
1501
|
-
const value = distance.value / pixelDistance.value;
|
|
1502
|
-
return value;
|
|
1503
|
-
}
|
|
987
|
+
if (distance.value && pixelDistance.value) return distance.value / pixelDistance.value;
|
|
1504
988
|
return 0;
|
|
1505
989
|
});
|
|
1506
990
|
const distanceText = computed(() => {
|
|
@@ -1526,12 +1010,11 @@ function useSceneDrillPick(windowPosition, options = {}) {
|
|
|
1526
1010
|
const { width = 3, height = 3, limit, throttled = 8, isActive = true } = options;
|
|
1527
1011
|
const viewer = useViewer();
|
|
1528
1012
|
const position = refThrottled(computed(() => toValue(windowPosition)), throttled, false, true);
|
|
1529
|
-
|
|
1013
|
+
return computed(() => {
|
|
1530
1014
|
if (position.value && toValue(isActive)) return viewer.value?.scene.drillPick(position.value, toValue(limit), toValue(width), toValue(height));
|
|
1531
1015
|
});
|
|
1532
|
-
return pick;
|
|
1533
1016
|
}
|
|
1534
1017
|
|
|
1535
1018
|
//#endregion
|
|
1536
|
-
export { CREATE_VIEWER_COLLECTION, CREATE_VIEWER_INJECTION_KEY,
|
|
1019
|
+
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
1020
|
//# sourceMappingURL=index.mjs.map
|