@juun-roh/cesium-utils 0.3.8 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,514 @@
1
- export { C as Collection } from '../index-iIlou-Sq.js';
2
- import 'cesium';
1
+ import { DataSourceCollection, EntityCollection, ImageryLayerCollection, PrimitiveCollection, Billboard, Cesium3DTileset, GroundPrimitive, Label, PointPrimitive, Polyline, Primitive, DataSource, Entity, ImageryLayer } from 'cesium';
2
+ import { N as NonFunction } from '../type-check-B-zGL1Ne.js';
3
+
4
+ /**
5
+ * @class
6
+ * A wrapper class that enhances Cesium collection objects with tagging functionality.
7
+ * This class provides a consistent API for working with different types of Cesium collections
8
+ * and allows grouping and manipulating collection items by custom tags.
9
+ *
10
+ * @template C - The type of Cesium collection (e.g., EntityCollection, PrimitiveCollection)
11
+ * @template I - The type of items in the collection (e.g., Entity, Primitive)
12
+ *
13
+ * @example
14
+ * // Example 1: Managing Complex Scene with Multiple Object Types
15
+ * class SceneOrganizer {
16
+ * private entities: Collection<EntityCollection, Entity>;
17
+ * private billboards: Collection<BillboardCollection, Billboard>;
18
+ * private primitives: Collection<PrimitiveCollection, Primitive>;
19
+ *
20
+ * constructor(viewer: Viewer) {
21
+ * this.entities = new Collection({ collection: viewer.entities });
22
+ * this.billboards = new Collection({
23
+ * collection: viewer.scene.primitives.add(new BillboardCollection())
24
+ * });
25
+ * this.primitives = new Collection({
26
+ * collection: viewer.scene.primitives
27
+ * });
28
+ * }
29
+ *
30
+ * // Unified API across different collection types!
31
+ * showLayer(layerName: string) {
32
+ * this.entities.show(layerName);
33
+ * this.billboards.show(layerName);
34
+ * this.primitives.show(layerName);
35
+ * }
36
+ *
37
+ * hideLayer(layerName: string) {
38
+ * this.entities.hide(layerName);
39
+ * this.billboards.hide(layerName);
40
+ * this.primitives.hide(layerName);
41
+ * }
42
+ *
43
+ * removeLayer(layerName: string) {
44
+ * this.entities.remove(layerName);
45
+ * this.billboards.remove(layerName);
46
+ * this.primitives.remove(layerName);
47
+ * }
48
+ * }
49
+ *
50
+ * // Example 2: Extend the class for Domain-Specific Needs
51
+ * class BuildingCollection extends Collection<EntityCollection, Entity> {
52
+ * constructor(viewer: Viewer) {
53
+ * super({ collection: viewer.entities, tag: 'buildings' });
54
+ * }
55
+ *
56
+ * addBuilding(options: {
57
+ * position: Cartesian3;
58
+ * height: number;
59
+ * floors: number;
60
+ * type: 'residential' | 'commercial' | 'industrial';
61
+ * }): Entity {
62
+ * const building = new Entity({
63
+ * position: options.position,
64
+ * box: {
65
+ * dimensions: new Cartesian3(50, 50, options.height),
66
+ * material: this.getMaterialForType(options.type)
67
+ * }
68
+ * });
69
+ *
70
+ * // Tag by type AND by floor count
71
+ * this.add(building, options.type);
72
+ * this.add(building, `floors-${options.floors}`);
73
+ *
74
+ * return building;
75
+ * }
76
+ *
77
+ * getByFloorRange(min: number, max: number): Entity[] {
78
+ * const results: Entity[] = [];
79
+ * for (let i = min; i <= max; i++) {
80
+ * results.push(...this.get(`floors-${i}`));
81
+ * }
82
+ * return results;
83
+ * }
84
+ *
85
+ * private getMaterialForType(type: string): Material {
86
+ * const colors = {
87
+ * residential: Color.GREEN,
88
+ * commercial: Color.BLUE,
89
+ * industrial: Color.YELLOW
90
+ * };
91
+ * return new ColorMaterialProperty(colors[type] || Color.WHITE);
92
+ * }
93
+ * }
94
+ */
95
+ declare class Collection<C extends Collection.Base, I extends Collection.ItemFor<C>> {
96
+ /**
97
+ * Symbol used as a property key to store tags on collection items.
98
+ * Using a Symbol ensures no property naming conflicts with the item's own properties.
99
+ * @readonly
100
+ */
101
+ static readonly symbol: unique symbol;
102
+ /**
103
+ * Default tag used when adding items without specifying a tag.
104
+ * @protected
105
+ */
106
+ protected tag: Collection.Tag;
107
+ /**
108
+ * The underlying Cesium collection being wrapped.
109
+ * @protected
110
+ */
111
+ protected collection: C;
112
+ /**
113
+ * Cache for values array to improve performance
114
+ * @private
115
+ */
116
+ private _valuesCache;
117
+ /**
118
+ * Tag to items map for faster lookups
119
+ * @private
120
+ */
121
+ private _tagMap;
122
+ /**
123
+ * Event listeners
124
+ * @private
125
+ */
126
+ private _eventListeners;
127
+ /**
128
+ * For cleaning up the instances
129
+ * @private
130
+ */
131
+ private _eventCleanupFunctions;
132
+ /**
133
+ * Creates a new Collection instance.
134
+ *
135
+ * @param options - Configuration options
136
+ * @param options.collection - The Cesium collection to wrap
137
+ * @param options.tag - The default tag to use for items (defaults to 'default')
138
+ */
139
+ constructor({ collection, tag }: {
140
+ collection: C;
141
+ tag?: Collection.Tag;
142
+ });
143
+ /**
144
+ * Makes the collection directly iterable, allowing it to be used in `for...of` loops
145
+ * and with spread operators.
146
+ *
147
+ * @returns An iterator for the items in the collection
148
+ *
149
+ * @example
150
+ * // Iterate through all items in the collection
151
+ * for (const entity of collection) {
152
+ * console.log(entity.id);
153
+ * }
154
+ *
155
+ * // Convert collection to array using spread syntax
156
+ * const entitiesArray = [...collection];
157
+ */
158
+ [Symbol.iterator](): Iterator<I>;
159
+ /**
160
+ * Gets all item instances in the collection.
161
+ * This array should not be modified directly.
162
+ *
163
+ * @returns An array of all items in the collection
164
+ */
165
+ get values(): I[];
166
+ /**
167
+ * Gets the number of items in the collection.
168
+ *
169
+ * @returns The item count
170
+ */
171
+ get length(): number;
172
+ /**
173
+ * Gets all unique tags currently in use in the collection.
174
+ *
175
+ * @returns An array of all unique tags
176
+ *
177
+ * @example
178
+ * // Get all tags
179
+ * const tags = collection.tags;
180
+ * console.log(`Collection has these tags: ${tags.join(', ')}`);
181
+ */
182
+ get tags(): Collection.Tag[];
183
+ /**
184
+ * Registers an event listener for collection events.
185
+ *
186
+ * @param type - The event type to listen for
187
+ * @param handler - The callback function
188
+ * @returns The collection instance for method chaining
189
+ */
190
+ addEventListener(type: Collection.Event, handler: Collection.EventHandler<I>): this;
191
+ /**
192
+ * Removes an event listener.
193
+ *
194
+ * @param type - The event type
195
+ * @param handler - The callback function to remove
196
+ * @returns The collection instance for method chaining
197
+ */
198
+ removeEventListener(type: Collection.Event, handler: Collection.EventHandler<I>): this;
199
+ /**
200
+ * Adds a single item with a tag to the collection.
201
+ *
202
+ * @param item - The item to add to the collection
203
+ * @param tag - Tag to associate with this item (defaults to the collection's default tag)
204
+ * @param index - The index to add the item at (if supported by the collection)
205
+ * @returns The collection instance for method chaining
206
+ *
207
+ * @example
208
+ * const entity = collection.add(new Entity({ ... }), 'landmarks');
209
+ */
210
+ add(item: I, tag?: Collection.Tag, index?: number): this;
211
+ /**
212
+ * Adds multiple items with the same tag to the collection.
213
+ *
214
+ * @param items - The array of items to add to the collection
215
+ * @param tag - Tag to associate with this item (defaults to the collection's default tag)
216
+ * @returns The collection instance for method chaining
217
+ *
218
+ * @example
219
+ * // Add multiple entities with the same tag
220
+ * const entities = [new Entity({ ... }), new Entity({ ... })];
221
+ * const addedEntities = collection.add(entities, 'buildings');
222
+ */
223
+ add(items: I[], tag?: Collection.Tag): this;
224
+ /**
225
+ * Returns true if the provided item is in this collection, false otherwise.
226
+ *
227
+ * @param item - The item instance to check for
228
+ * @returns True if the item is in the collection, false otherwise
229
+ */
230
+ contains(item: I): boolean;
231
+ /**
232
+ * Checks if the collection has any items with the specified tag.
233
+ *
234
+ * @param tag - The tag to check for
235
+ * @returns True if items with the tag exist, false otherwise
236
+ *
237
+ * @example
238
+ * if (collection.contains('temporary')) {
239
+ * console.log('Temporary items exist');
240
+ * }
241
+ */
242
+ contains(tag: Collection.Tag): boolean;
243
+ /**
244
+ * Removes an item from the collection.
245
+ *
246
+ * @param item - The item to remove
247
+ * @returns The collection instance for method chaining
248
+ */
249
+ remove(item: I): this;
250
+ /**
251
+ * Removes all items with the specified tag from the collection.
252
+ *
253
+ * @param by - The tag identifying which items to remove
254
+ * @returns The collection instance for method chaining
255
+ */
256
+ remove(by: Collection.Tag): this;
257
+ /**
258
+ * Removes all items with the array of tags from the collection.
259
+ *
260
+ * @param by - The tags identifying which items to remove
261
+ * @returns The collection instance for method chaining
262
+ */
263
+ remove(by: Collection.Tag[]): this;
264
+ /**
265
+ * Removes all items from the collection.
266
+ */
267
+ removeAll(): void;
268
+ /**
269
+ * Permanently destroys this Collection instance.
270
+ * Removes all event listeners and clears internal state.
271
+ * The Collection instance should not be used after calling this method.
272
+ */
273
+ destroy(): void;
274
+ /**
275
+ * Gets all items with the specified tag from the collection.
276
+ * Uses an optimized internal map for faster lookups.
277
+ *
278
+ * @param by - The tag to filter by
279
+ * @returns An array of items with the specified tag, or an empty array if none found
280
+ *
281
+ * @example
282
+ * // Get all buildings
283
+ * const buildings = collection.get('buildings');
284
+ */
285
+ get(by: Collection.Tag): I[];
286
+ /**
287
+ * Gets the first item matching the tag. More efficient than `get` when
288
+ * you only need one item, especially for large collections.
289
+ *
290
+ * @param by - The tag to search for
291
+ * @returns The first matching item or undefined if none found
292
+ *
293
+ * @example
294
+ * // Get the first building
295
+ * const firstBuilding = collection.first('buildings');
296
+ */
297
+ first(by: Collection.Tag): I | undefined;
298
+ /**
299
+ * Updates the tag for all items with the specified tag.
300
+ *
301
+ * @param from - The tag to replace
302
+ * @param to - The new tag to assign
303
+ * @returns The number of items updated
304
+ *
305
+ * @example
306
+ * // Rename a tag
307
+ * const count = collection.update('temp', 'temporary');
308
+ * console.log(`Updated ${count} items`);
309
+ */
310
+ update(from: Collection.Tag, to: Collection.Tag): number;
311
+ /**
312
+ * Makes all items with the specified tag visible.
313
+ * Only affects items that have a 'show' property.
314
+ *
315
+ * @param by - The tag identifying which items to show
316
+ * @returns The collection itself.
317
+ *
318
+ * @example
319
+ * // Show all buildings
320
+ * collection.show('buildings');
321
+ */
322
+ show(by: Collection.Tag): this;
323
+ /**
324
+ * Hides all items with the specified tag.
325
+ * Only affects items that have a 'show' property.
326
+ *
327
+ * @param by - The tag identifying which items to hide
328
+ * @returns The collection itself.
329
+ *
330
+ * @example
331
+ * // Hide all buildings
332
+ * collection.hide('buildings');
333
+ */
334
+ hide(by: Collection.Tag): this;
335
+ /**
336
+ * Toggles visibility of all items with the specified tag.
337
+ * Only affects items that have a 'show' property.
338
+ *
339
+ * @param by - The tag identifying which items to toggle
340
+ * @returns The collection itself.
341
+ *
342
+ * @example
343
+ * // Toggle visibility of all buildings
344
+ * collection.toggle('buildings');
345
+ */
346
+ toggle(by: Collection.Tag): this;
347
+ /**
348
+ * Sets a property value on all items with the specified tag.
349
+ *
350
+ * @template K - A type
351
+ *
352
+ * @param property - The property name to set
353
+ * @param value - The value to set
354
+ * @param by - The tag identifying which items to update
355
+ * @returns The collection itself.
356
+ *
357
+ * @example
358
+ * // Change color of all buildings to red
359
+ * collection.setProperty('color', Color.RED, 'buildings');
360
+ */
361
+ setProperty<K extends NonFunction<I>>(property: K, value: I[K], by?: Collection.Tag): this;
362
+ /**
363
+ * Filters items in the collection based on a predicate function.
364
+ * Optionally only filters items with a specific tag.
365
+ *
366
+ * @param predicate - Function that tests each item
367
+ * @param by - Optional tag to filter by before applying the predicate
368
+ * @returns Array of items that pass the test
369
+ *
370
+ * @example
371
+ * // Get all buildings taller than 100 meters
372
+ * const tallBuildings = collection.filter(
373
+ * entity => entity.properties?.height?.getValue() > 100,
374
+ * 'buildings'
375
+ * );
376
+ */
377
+ filter(predicate: (item: I) => boolean, by?: Collection.Tag): I[];
378
+ /**
379
+ * Executes a callback function for each item in the collection.
380
+ * Optionally filters items by tag before execution.
381
+ *
382
+ * @param callback - Function to execute for each item
383
+ * @param by - Optional tag to filter items (if not provided, processes all items)
384
+ *
385
+ * @example
386
+ * // Highlight all buildings
387
+ * collection.forEach((entity) => {
388
+ * if (entity.polygon) {
389
+ * entity.polygon.material = new ColorMaterialProperty(Color.YELLOW);
390
+ * }
391
+ * }, 'buildings');
392
+ */
393
+ forEach(callback: (value: I, index: number) => void, by?: Collection.Tag): void;
394
+ /**
395
+ * Creates a new array with the results of calling a provided function on every element
396
+ * in the collection. Optionally filters by tag before mapping.
397
+ *
398
+ * @param callbackfn - Function that produces an element of the new array
399
+ * @param by - Optional tag to filter items by before mapping
400
+ * @returns A new array with each element being the result of the callback function
401
+ *
402
+ * @example
403
+ * // Get all entity IDs
404
+ * const entityIds = collection.map(entity => entity.id);
405
+ *
406
+ * // Get positions of all buildings
407
+ * const buildingPositions = collection.map(
408
+ * entity => entity.position.getValue(Cesium.JulianDate.now()),
409
+ * 'buildings'
410
+ * );
411
+ */
412
+ map<R>(callbackfn: (value: I, index: number) => R, by?: Collection.Tag): R[];
413
+ /**
414
+ * Returns the first element in the collection that satisfies the provided testing function.
415
+ * Optionally filters by tag before searching.
416
+ *
417
+ * @param predicate - Function to test each element
418
+ * @param by - Optional tag to filter items by before searching
419
+ * @returns The first element that passes the test, or undefined if no elements pass
420
+ *
421
+ * @example
422
+ * // Find the first entity with a specific name
423
+ * const namedEntity = collection.find(entity => entity.name === 'Target');
424
+ *
425
+ * // Find the first building taller than 100 meters
426
+ * const tallBuilding = collection.find(
427
+ * entity => entity.properties?.height?.getValue() > 100,
428
+ * 'buildings'
429
+ * );
430
+ */
431
+ find(predicate: (value: I) => boolean, by?: Collection.Tag): I | undefined;
432
+ /**
433
+ * Emits an event to all registered listeners.
434
+ *
435
+ * @private
436
+ * @param type - The event type
437
+ * @param data - Additional event data
438
+ */
439
+ private _emit;
440
+ /**
441
+ * Adds an item to the internal tag map for quick lookups.
442
+ *
443
+ * @private
444
+ * @param item - The item to add
445
+ * @param tag - The tag to associate with the item
446
+ */
447
+ private _addToTagMap;
448
+ /**
449
+ * Removes an item from the internal tag map.
450
+ *
451
+ * @private
452
+ * @param item - The item to remove
453
+ */
454
+ private _removeFromTagMap;
455
+ /**
456
+ * Invalidates the values cache when collection changes.
457
+ *
458
+ * @private
459
+ */
460
+ private _invalidateCache;
461
+ /**
462
+ * Sets up automatic cache invalidation by registering event listeners on the underlying Cesium collection.
463
+ *
464
+ * @private
465
+ * @param collection - The Cesium collection to monitor for changes
466
+ *
467
+ * @see {@link destroy} For cleanup of event listeners
468
+ * @see {@link _invalidateCache} For the actual cache invalidation logic
469
+ */
470
+ private _setupCacheInvalidator;
471
+ }
472
+ /**
473
+ * @namespace
474
+ */
475
+ declare namespace Collection {
476
+ /**
477
+ * The underlying Cesium collection type being wrapped.
478
+ */
479
+ export type Base = DataSourceCollection | EntityCollection | ImageryLayerCollection | PrimitiveCollection;
480
+ /**
481
+ * The item types that can be added to the `PrimitiveCollection` instance.
482
+ */
483
+ type Primitives = Billboard | Cesium3DTileset | GroundPrimitive | Label | PointPrimitive | Polyline | Primitive;
484
+ /**
485
+ * Cesium item type that can be added to the {@link Collection.Base} instance.
486
+ */
487
+ export type Item = DataSource | Entity | ImageryLayer | Primitives;
488
+ /**
489
+ * Gets the item type for a given collection type
490
+ */
491
+ export type ItemFor<C extends Base> = C extends DataSourceCollection ? DataSource : C extends EntityCollection ? Entity : C extends ImageryLayerCollection ? ImageryLayer : C extends PrimitiveCollection ? Primitives : never;
492
+ /**
493
+ * Collection tag type.
494
+ */
495
+ export type Tag = string | number;
496
+ export interface WithTag {
497
+ [key: symbol]: Tag;
498
+ }
499
+ /**
500
+ * Collection event types
501
+ */
502
+ export type Event = "add" | "remove" | "update" | "clear";
503
+ /**
504
+ * Event handler function type
505
+ */
506
+ export type EventHandler<I> = (event: {
507
+ type: Event;
508
+ items?: I[];
509
+ tag?: Collection.Tag;
510
+ }) => void;
511
+ export { };
512
+ }
513
+
514
+ export { Collection };
@@ -1 +1 @@
1
- import"../chunk-RXMNSDKR.js";import{e as a}from"../chunk-R4DSXQCN.js";import"../chunk-6ABRDFE5.js";export{a as Collection};
1
+ import{a}from"../chunk-VWM3HSEI.js";import"../chunk-ZXZ7TVB3.js";import"../chunk-XHMLNB5Q.js";export{a as Collection};
@@ -1 +1 @@
1
- "use strict";var P=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var G=(a,e)=>{for(var t in e)P(a,t,{get:e[t],enumerable:!0})},V=(a,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of F(e))!k.call(a,r)&&r!==t&&P(a,r,{get:()=>e[r],enumerable:!(i=D(e,r))||i.enumerable});return a};var H=a=>V(P({},"__esModule",{value:!0}),a);var j={};G(j,{Deprecate:()=>E,TerrainVisualizer:()=>y,deprecate:()=>N,isGetterOnly:()=>b});module.exports=H(j);var R;(d=>{let a=new Set,e=typeof process<"u"?process.env.CESIUM_UTILS_DISABLE_DEPRECATION_WARNINGS!=="true":!0;function t(l,o={}){if(!e)return;let{once:h=!0,prefix:v="[DEPRECATED]",includeStack:m=!0,removeInVersion:p}=o;if(h&&a.has(l))return;let f=`${v} ${l}`;p&&(f+=` This feature will be removed in ${p}.`),typeof console<"u"&&console.warn&&(m?(console.warn(f),console.trace("Deprecation stack trace:")):console.warn(f)),h&&a.add(l)}d.warn=t;function i(l,o,h={}){let v=((...m)=>(t(o,h),l(...m)));return Object.defineProperty(v,"name",{value:l.name,configurable:!0}),v}d.deprecate=i;function r(){a.clear()}d.clear=r;function n(){return a.size}d.getWarningCount=n;function c(l){return a.has(l)}d.hasShown=c})(R||={});var E=R;var s=require("cesium");var u=require("cesium");var x=class a{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;_eventCleanupFunctions=[];constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e,this._setupCacheInvalidator(e)}[Symbol.iterator](){return this.values[Symbol.iterator]()}get values(){if(this._valuesCache!==null)return this._valuesCache;let e;if(this.collection instanceof u.EntityCollection)e=this.collection.values;else{e=[];for(let t=0;t<this.collection.length;t++)e.push(this.collection.get(t))}return this._valuesCache=e,e}get length(){return this.values?.length||0}get tags(){return Array.from(this._tagMap.keys())}addEventListener(e,t){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(t),this}removeEventListener(e,t){return this._eventListeners.get(e)?.delete(t),this}add(e,t=this.tag,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,a.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),this._addToTagMap(e,t),this._invalidateCache(),this._emit("add",{items:[e],tag:t})),this}contains(e){if(typeof e=="object")return this.collection.contains(e);let t=this._tagMap.get(e);return!!t&&t.size>0}remove(e){if(typeof e=="object"&&!Array.isArray(e)&&this.collection.remove(e)&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),Array.isArray(e)){if(e.length===0)return this;for(let i of e)this.remove(i)}let t=this.get(e);if(t.length===0)return this;for(let i of t)this.remove(i);return this}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}destroy(){this._eventCleanupFunctions.forEach(e=>e()),this._eventCleanupFunctions=[],this._tagMap.clear(),this._eventListeners.clear(),this._valuesCache=null}get(e){let t=this._tagMap.get(e);return t?Array.from(t):[]}first(e){let t=this._tagMap.get(e);if(t&&t.size>0)return t.values().next().value}update(e,t){let i=this.get(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,a.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}show(e){let t=this.get(e);for(let i of t)(0,u.defined)(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)(0,u.defined)(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)(0,u.defined)(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let n of r)if(e in n&&typeof n[e]!="function"){if(b(n,e))throw Error(`Cannot set read-only property '${String(e)}' on ${n.constructor.name}`);n[e]=t}return this}filter(e,t){return(t?this.get(t):this.values).filter(e)}forEach(e,t){(t?this.get(t):this.values).forEach((r,n)=>e(r,n))}map(e,t){return(t?this.get(t):this.values).map(e)}find(e,t){return(t?this.get(t):this.values).find(e)}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(n=>n(r))}}_addToTagMap(e,t){this._tagMap.has(t)||this._tagMap.set(t,new Set),this._tagMap.get(t)?.add(e)}_removeFromTagMap(e){let t=e[a.symbol],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache=()=>{this._valuesCache=null};_setupCacheInvalidator(e){e instanceof u.EntityCollection?(e.collectionChanged.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.collectionChanged.removeEventListener(this._invalidateCache))):e instanceof u.PrimitiveCollection?(e.primitiveAdded.addEventListener(this._invalidateCache),e.primitiveRemoved.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.primitiveAdded.removeEventListener(this._invalidateCache),()=>e.primitiveRemoved.removeEventListener(this._invalidateCache))):e instanceof u.DataSourceCollection?(e.dataSourceAdded.addEventListener(this._invalidateCache),e.dataSourceMoved.addEventListener(this._invalidateCache),e.dataSourceRemoved.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.dataSourceAdded.removeEventListener(this._invalidateCache),()=>e.dataSourceMoved.removeEventListener(this._invalidateCache),()=>e.dataSourceRemoved.removeEventListener(this._invalidateCache))):e instanceof u.ImageryLayerCollection&&(e.layerAdded.addEventListener(this._invalidateCache),e.layerMoved.addEventListener(this._invalidateCache),e.layerRemoved.addEventListener(this._invalidateCache),e.layerShownOrHidden.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.layerAdded.removeEventListener(this._invalidateCache),()=>e.layerMoved.removeEventListener(this._invalidateCache),()=>e.layerRemoved.removeEventListener(this._invalidateCache),()=>e.layerShownOrHidden.removeEventListener(this._invalidateCache)))}},w=x;var S=require("cesium"),_=class a{_regions;_defaultProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(e){this._defaultProvider=e.defaultProvider,this._fallbackProvider=e.fallbackProvider||new S.EllipsoidTerrainProvider,this._tilingScheme=e.defaultProvider.tilingScheme,this._regions=e.regions||[],this._availability=e.defaultProvider.availability,this._ready=!0}get ready(){return this._ready}get tilingScheme(){return this._tilingScheme}get availability(){return this._availability}get regions(){return[...this._regions]}get defaultProvider(){return this._defaultProvider}get fallbackProvider(){return this._fallbackProvider}get credit(){return this._defaultProvider?.credit}get errorEvent(){return this._defaultProvider.errorEvent}get hasWaterMask(){return this._defaultProvider.hasWaterMask}get hasVertexNormals(){return this._defaultProvider.hasVertexNormals}loadTileDataAvailability(e,t,i){return this._defaultProvider.loadTileDataAvailability(e,t,i)}getLevelMaximumGeometricError(e){return this._defaultProvider.getLevelMaximumGeometricError(e)}requestTileGeometry(e,t,i,r){if(this._ready){for(let n of this._regions)if(a.TerrainRegion.contains(n,e,t,i))return n.provider.requestTileGeometry(e,t,i,r);return this._defaultProvider.getTileDataAvailable(e,t,i)?this._defaultProvider.requestTileGeometry(e,t,i,r):this._fallbackProvider.requestTileGeometry(e,t,i,r)}}getTileDataAvailable(e,t,i){for(let r of this._regions)if(a.TerrainRegion.contains(r,e,t,i)&&r.provider.getTileDataAvailable(e,t,i))return!0;return this._defaultProvider.getTileDataAvailable(e,t,i)}};(t=>{function a(i,r,n){return new t({regions:i.map(c=>({...c})),defaultProvider:r,fallbackProvider:n})}t.fromTileRanges=a;let e;(r=>{function i(n,c,d,l){if(n.levels&&!n.levels.includes(l))return!1;if(n.tiles){let o=n.tiles.get(l);if(!o)return!1;let[h,v]=Array.isArray(o.x)?o.x:[o.x,o.x],[m,p]=Array.isArray(o.y)?o.y:[o.y,o.y];return c>=h&&c<=v&&d>=m&&d<=p}return!1}r.contains=i})(e=t.TerrainRegion||={})})(_||={});var A=_;var y=class a{_viewer;_collection;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",s.Color.RED],["default",s.Color.BLUE],["fallback",s.Color.GRAY],["grid",s.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new w({collection:e.entities,tag:a.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),t.tile!==void 0&&(this._visible=t.tile),t.activeLevel!==void 0&&(this._level=t.activeLevel),t.terrainProvider&&this.setTerrainProvider(t.terrainProvider))}setTerrainProvider(e){this._terrainProvider=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.remove(this._collection.tags)}show(e=15){if(!this._terrainProvider)return;this._collection.remove(a.tag.grid),this._level=e,this._ensureTileCoordinatesLayer();let t=this._getVisibleRectangle();if(!t||!this._isValidRectangle(t)){console.warn("Invalid visible rectangle detected, skipping grid display");return}this._displayTileGrid(t,e),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new s.TileCoordinatesImageryProvider({tilingScheme:this._terrainProvider.tilingScheme,color:s.Color.YELLOW})))}_isValidRectangle(e){return e&&Number.isFinite(e.west)&&Number.isFinite(e.south)&&Number.isFinite(e.east)&&Number.isFinite(e.north)&&e.west<=e.east&&e.south<=e.north}_displayTileGrid(e,t){let i=this._terrainProvider.tilingScheme;try{let r=this._calculateTileBounds(e,t,i);this._generateVisibleTiles(r,t,i).forEach(c=>{this._collection.add(c.entity,a.tag.grid)})}catch(r){console.error("Error displaying tile grid:",r)}}_calculateTileBounds(e,t,i){let r=i.positionToTileXY(s.Rectangle.northwest(e),t),n=i.positionToTileXY(s.Rectangle.southeast(e),t);if(!r||!n)throw new Error("Failed to calculate tile bounds");return{start:r,end:n}}_generateVisibleTiles(e,t,i){let r=[],c=Math.min(e.end.x-e.start.x+1,100),d=Math.min(e.end.y-e.start.y+1,100);for(let l=e.start.x;l<e.start.x+c;l++)for(let o=e.start.y;o<e.start.y+d;o++)try{let h=this._createTileEntity(l,o,t,i);h&&r.push({entity:h})}catch(h){console.warn(`Error creating tile (${l}, ${o}, ${t}):`,h)}return r}_createTileEntity(e,t,i,r){let n=r.tileXYToRectangle(e,t,i);if(!this._isValidRectangle(n))return null;let c=this._getTileColor(e,t,i),d=a.createRectangle(n,c.withAlpha(.3));return d.properties?.addProperty("tileX",e),d.properties?.addProperty("tileY",t),d.properties?.addProperty("tileLevel",i),d}_getTileColor(e,t,i){if(!this._terrainProvider)return this._colors.get("fallback")||s.Color.TRANSPARENT;for(let r of this._terrainProvider.regions)if(A.TerrainRegion.contains(r,e,t,i))return this._colors.get("custom")||s.Color.RED;return this._terrainProvider.getTileDataAvailable(e,t,i)?this._colors.get("default")||s.Color.BLUE:this._colors.get("fallback")||s.Color.GRAY}hide(){this._collection.remove(a.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){this._viewer.camera.flyTo({destination:e,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}get colors(){return this._colors}get terrainProvider(){return this._terrainProvider}};(i=>{i.tag={default:"Terrain Visualizer",grid:"Terrain Visualizer Tile Grid"};function e(r,n){return new s.Entity({rectangle:{coordinates:r,material:n,heightReference:s.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,n,c){let d=c?.tag||"terrain_region_visualization",l=c?.color||s.Color.RED,o=c?.maxTilesToShow||100,h=c?.show??!0,v=c?.tileAlpha||.2,m=new w({collection:n.entities,tag:d});if(h&&r.tiles&&r.tiles.size>0){let p=r.provider.tilingScheme,f=0;r.tiles.forEach((g,M)=>{let L=Array.isArray(g.x)?g.x:[g.x,g.x],I=Array.isArray(g.y)?g.y:[g.y,g.y];for(let T=L[0];T<=L[1]&&f<o;T++)for(let C=I[0];C<=I[1]&&f<o;C++){let O=p.tileXYToRectangle(T,C,M);m.add(e(O,l.withAlpha(v)),`${d}_tile`),f++}})}return m}i.visualize=t})(y||={});function b(a,e){let t=!1,i=Object.getOwnPropertyDescriptor(a,e);if(!i){let r=Object.getPrototypeOf(a);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}var N=E.deprecate;
1
+ "use strict";var _=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var E=(o,e)=>{for(var r in e)_(o,r,{get:e[r],enumerable:!0})},R=(o,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of I(e))!O.call(o,t)&&t!==r&&_(o,t,{get:()=>e[t],enumerable:!(i=x(e,t))||i.enumerable});return o};var A=o=>R(_({},"__esModule",{value:!0}),o);var M={};E(M,{Deprecate:()=>P,TerrainVisualizer:()=>g,deprecate:()=>S,isGetterOnly:()=>L});module.exports=A(M);var T;(d=>{let o=new Set,e=typeof process<"u"?process.env.CESIUM_UTILS_DISABLE_DEPRECATION_WARNINGS!=="true":!0;function r(s,n={}){if(!e)return;let{once:v=!0,prefix:c="[DEPRECATED]",includeStack:m=!0,removeInVersion:b}=n;if(v&&o.has(s))return;let p=`${c} ${s}`;b&&(p+=` This feature will be removed in ${b}.`),typeof console<"u"&&console.warn&&(m?(console.warn(p),console.trace("Deprecation stack trace:")):console.warn(p)),v&&o.add(s)}d.warn=r;function i(s,n,v={}){let c=((...m)=>(r(n,v),s(...m)));return Object.defineProperty(c,"name",{value:s.name,configurable:!0}),c}d.deprecate=i;function t(){o.clear()}d.clear=t;function a(){return o.size}d.getWarningCount=a;function l(s){return o.has(s)}d.hasShown=l})(T||={});var P=T;var u=require("cesium");var h=require("cesium");var C=require("cesium"),y=class o{_regions;_defaultProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(e){this._defaultProvider=e.defaultProvider,this._fallbackProvider=e.fallbackProvider||new C.EllipsoidTerrainProvider,this._tilingScheme=e.defaultProvider.tilingScheme,this._regions=e.regions||[],this._availability=e.defaultProvider.availability,this._ready=!0}get ready(){return this._ready}get tilingScheme(){return this._tilingScheme}get availability(){return this._availability}get regions(){return[...this._regions]}get defaultProvider(){return this._defaultProvider}get fallbackProvider(){return this._fallbackProvider}get credit(){return this._defaultProvider?.credit}get errorEvent(){return this._defaultProvider.errorEvent}get hasWaterMask(){return this._defaultProvider.hasWaterMask}get hasVertexNormals(){return this._defaultProvider.hasVertexNormals}loadTileDataAvailability(e,r,i){return this._defaultProvider.loadTileDataAvailability(e,r,i)}getLevelMaximumGeometricError(e){return this._defaultProvider.getLevelMaximumGeometricError(e)}requestTileGeometry(e,r,i,t){if(this._ready){for(let a of this._regions)if(o.TerrainRegion.contains(a,e,r,i))return a.provider.requestTileGeometry(e,r,i,t);return this._defaultProvider.getTileDataAvailable(e,r,i)?this._defaultProvider.requestTileGeometry(e,r,i,t):this._fallbackProvider.requestTileGeometry(e,r,i,t)}}getTileDataAvailable(e,r,i){for(let t of this._regions)if(o.TerrainRegion.contains(t,e,r,i))return!0;return this._defaultProvider.getTileDataAvailable(e,r,i)}};(r=>{function o(i,t,a){return new r({regions:i.map(l=>({...l})),defaultProvider:t,fallbackProvider:a})}r.fromTileRanges=o;let e;(t=>{function i(a,l,d,s){if(a.levels&&!a.levels.includes(s))return!1;if(a.tiles){let n=a.tiles.get(s);if(!n)return!1;let[v,c]=Array.isArray(n.x)?n.x:[n.x,n.x],[m,b]=Array.isArray(n.y)?n.y:[n.y,n.y];return l>=v&&l<=c&&d>=m&&d<=b}return!1}t.contains=i})(e=r.TerrainRegion||={})})(y||={});var w=y;var f=class extends h.GridImageryProvider{_terrainProvider;_colors;constructor(e){let{terrainProvider:r,colors:i,...t}=e;super(t),this._terrainProvider=r,this._colors=i}requestImage(e,r,i){for(let t of this._terrainProvider.regions)if(this._isInRegionOrUpsampled(t,e,r,i))return this._createCanvasElement(this._colors.get("custom")||h.Color.RED);return this._terrainProvider.defaultProvider.getTileDataAvailable(e,r,i)?this._createCanvasElement(this._colors.get("default")||h.Color.BLUE):this._createCanvasElement(this._colors.get("fallback")||h.Color.GRAY)}_isInRegionOrUpsampled(e,r,i,t){let a=r,l=i,d=t;for(;d>=0;){if(w.TerrainRegion.contains(e,a,l,d))return!0;if(d===0)break;d--,a=Math.floor(a/2),l=Math.floor(l/2)}return!1}_createCanvasElement(e){let r=document.createElement("canvas");r.width=256,r.height=256;let i=r.getContext("2d"),t=e.withAlpha(.3).toCssColorString();if(!i)throw new Error("canvas context undefined");return i.fillStyle=t,i.fillRect(0,0,256,256),Promise.resolve(r)}};var g=class{_viewer;_terrainProvider;_visible=!1;_tileCoordinatesLayer;_hybridImageryLayer;_colors=new Map([["custom",u.Color.RED],["default",u.Color.BLUE],["fallback",u.Color.GRAY],["grid",u.Color.YELLOW]]);constructor(e,r){this._viewer=e,this._terrainProvider=r.terrainProvider,r.colors&&Object.entries(r.colors).forEach(([i,t])=>{this._colors.set(i,t)}),r.tile!==void 0&&r.tile&&this.show()}setTerrainProvider(e){this._terrainProvider=e,this.update()}update(){let e=this._visible,r=!!this._tileCoordinatesLayer,i=this._hybridImageryLayer?.alpha??.5;this.clear(),e&&this.show({showTileCoordinates:r,alpha:i})}clear(){this.hide()}show(e){if(!this._terrainProvider)return;let r=e?.showTileCoordinates??!0,i=e?.alpha??.5;r&&this._ensureTileCoordinatesLayer(),this.showImageryOverlay(i),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new u.TileCoordinatesImageryProvider({tilingScheme:this._terrainProvider.tilingScheme,color:u.Color.YELLOW})))}hide(){this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this.hideImageryOverlay(),this._visible=!1}setColors(e){Object.entries(e).forEach(([r,i])=>{this._colors.set(r,i)}),this.update()}showImageryOverlay(e=.5){this._hybridImageryLayer&&this._viewer.imageryLayers.remove(this._hybridImageryLayer);let r=new f({terrainProvider:this._terrainProvider,colors:this._colors,tilingScheme:this._terrainProvider.tilingScheme});this._hybridImageryLayer=this._viewer.imageryLayers.addImageryProvider(r),this._hybridImageryLayer.alpha=e,console.log("HybridImageryProvider overlay enabled")}hideImageryOverlay(){this._hybridImageryLayer&&(this._viewer.imageryLayers.remove(this._hybridImageryLayer),this._hybridImageryLayer=void 0,console.log("HybridImageryProvider overlay disabled"))}showTileCoordinates(){this._ensureTileCoordinatesLayer()}hideTileCoordinates(){this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0)}setAlpha(e){this._hybridImageryLayer&&(this._hybridImageryLayer.alpha=e)}flyTo(e,r){this._viewer.camera.flyTo({destination:e,...r,complete:()=>{this._visible&&this.update()}})}get tileCoordinatesVisible(){return!!this._tileCoordinatesLayer}get visible(){return this._visible}get viewer(){return this._viewer}get colors(){return this._colors}get terrainProvider(){return this._terrainProvider}};function L(o,e){let r=!1,i=Object.getOwnPropertyDescriptor(o,e);if(!i){let t=Object.getPrototypeOf(o);for(;t&&!i;)i=Object.getOwnPropertyDescriptor(t,e),t=Object.getPrototypeOf(t)}return i&&i.get&&!i.set&&(r=!0),r}var S=P.deprecate;