@juun-roh/cesium-utils 0.0.6 → 0.0.8

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.
@@ -49,8 +49,7 @@ type NonFunction<T> = {
49
49
  * entities.add(new Entity({ ... }), 'roads');
50
50
  *
51
51
  * // Later, show only buildings
52
- * entities.show('buildings');
53
- * entities.hide('roads');
52
+ * entities.show('buildings').hide('roads');
54
53
  */
55
54
  declare class Collection<C extends CesiumCollection, I extends CesiumCollectionItem> {
56
55
  /**
@@ -95,6 +94,22 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
95
94
  collection: C;
96
95
  tag?: Tag;
97
96
  });
97
+ /**
98
+ * Makes the collection directly iterable, allowing it to be used in `for...of` loops
99
+ * and with spread operators.
100
+ *
101
+ * @returns An iterator for the items in the collection
102
+ *
103
+ * @example
104
+ * // Iterate through all items in the collection
105
+ * for (const entity of collection) {
106
+ * console.log(entity.id);
107
+ * }
108
+ *
109
+ * // Convert collection to array using spread syntax
110
+ * const entitiesArray = [...collection];
111
+ */
112
+ [Symbol.iterator](): Iterator<I>;
98
113
  /**
99
114
  * Emits an event to all registered listeners.
100
115
  *
@@ -168,10 +183,22 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
168
183
  /**
169
184
  * Returns true if the provided item is in this collection, false otherwise.
170
185
  *
171
- * @param item - The item to check for
186
+ * @param item - The item instance to check for
172
187
  * @returns True if the item is in the collection, false otherwise
173
188
  */
174
189
  contains(item: I): boolean;
190
+ /**
191
+ * Checks if the collection has any items with the specified tag.
192
+ *
193
+ * @param tag - The tag to check for
194
+ * @returns True if items with the tag exist, false otherwise
195
+ *
196
+ * @example
197
+ * if (collection.contains('temporary')) {
198
+ * console.log('Temporary items exist');
199
+ * }
200
+ */
201
+ contains(tag: Tag): boolean;
175
202
  /**
176
203
  * Removes an item from the collection.
177
204
  *
@@ -179,6 +206,20 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
179
206
  * @returns True if the item was removed, false if it wasn't found
180
207
  */
181
208
  remove(item: I): boolean;
209
+ /**
210
+ * Removes all items with the specified tag from the collection.
211
+ *
212
+ * @param by - The tag identifying which items to remove
213
+ * @returns True if the item was removed, false if it wasn't found
214
+ */
215
+ remove(by: Tag): boolean;
216
+ /**
217
+ * Removes all items with the array of tags from the collection.
218
+ *
219
+ * @param by - The tags identifying which items to remove
220
+ * @returns True if the item was removed, false if it wasn't found
221
+ */
222
+ remove(by: Tag[]): boolean;
182
223
  /**
183
224
  * Removes all items from the collection.
184
225
  */
@@ -200,26 +241,26 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
200
241
  * Gets all items with the specified tag from the collection.
201
242
  * Uses an optimized internal map for faster lookups.
202
243
  *
203
- * @param tag - The tag to filter by
244
+ * @param by - The tag to filter by
204
245
  * @returns An array of items with the specified tag, or an empty array if none found
205
246
  *
206
247
  * @example
207
248
  * // Get all buildings
208
- * const buildings = collection.getByTag('buildings');
249
+ * const buildings = collection.get('buildings');
209
250
  */
210
- getByTag(tag: Tag): I[];
251
+ get(by: Tag): I[];
211
252
  /**
212
- * Gets the first item matching the tag. More efficient than getByTag when
253
+ * Gets the first item matching the tag. More efficient than `get` when
213
254
  * you only need one item, especially for large collections.
214
255
  *
215
- * @param tag - The tag to search for
256
+ * @param by - The tag to search for
216
257
  * @returns The first matching item or undefined if none found
217
258
  *
218
259
  * @example
219
260
  * // Get the first building
220
- * const firstBuilding = collection.getFirstByTag('buildings');
261
+ * const firstBuilding = collection.first('buildings');
221
262
  */
222
- getFirstByTag(tag: Tag): I | undefined;
263
+ first(by: Tag): I | undefined;
223
264
  /**
224
265
  * Gets all unique tags currently in use in the collection.
225
266
  *
@@ -227,99 +268,63 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
227
268
  *
228
269
  * @example
229
270
  * // Get all tags
230
- * const tags = collection.getTags();
271
+ * const tags = collection.tags;
231
272
  * console.log(`Collection has these tags: ${tags.join(', ')}`);
232
273
  */
233
- getTags(): Tag[];
234
- /**
235
- * Checks if the collection has any items with the specified tag.
236
- *
237
- * @param tag - The tag to check for
238
- * @returns True if items with the tag exist, false otherwise
239
- *
240
- * @example
241
- * if (collection.hasTag('temporary')) {
242
- * console.log('Temporary items exist');
243
- * }
244
- */
245
- hasTag(tag: Tag): boolean;
274
+ get tags(): Tag[];
246
275
  /**
247
276
  * Updates the tag for all items with the specified tag.
248
277
  *
249
- * @param oldTag - The tag to replace
250
- * @param newTag - The new tag to assign
278
+ * @param from - The tag to replace
279
+ * @param to - The new tag to assign
251
280
  * @returns The number of items updated
252
281
  *
253
282
  * @example
254
283
  * // Rename a tag
255
- * const count = collection.updateTag('temp', 'temporary');
284
+ * const count = collection.update('temp', 'temporary');
256
285
  * console.log(`Updated ${count} items`);
257
286
  */
258
- updateTag(oldTag: Tag, newTag: Tag): number;
259
- /**
260
- * Removes all items with the specified tag from the collection.
261
- *
262
- * @param tag - The tag identifying which items to remove
263
- * @returns The number of items removed
264
- *
265
- * @example
266
- * // Remove all temporary markers
267
- * const count = collection.removeByTag('temporary');
268
- * console.log(`Removed ${count} items`);
269
- */
270
- removeByTag(tag: Tag): number;
271
- /**
272
- * Removes all items with the array of tags from the collection.
273
- *
274
- * @param tag - The tags identifying which items to remove
275
- * @returns The number of items removed
276
- *
277
- * @example
278
- * // Remove all items containing tags
279
- * const count = collection.removeByTag('temporary', 'default', 'tag');
280
- * console.log(`Removed ${count} items`);
281
- */
282
- removeByTag(tag: Tag[]): number;
287
+ update(from: Tag, to: Tag): number;
283
288
  /**
284
289
  * Makes all items with the specified tag visible.
285
290
  * Only affects items that have a 'show' property.
286
291
  *
287
- * @param tag - The tag identifying which items to show
288
- * @returns The number of items affected
292
+ * @param by - The tag identifying which items to show
293
+ * @returns The collection itself.
289
294
  *
290
295
  * @example
291
296
  * // Show all buildings
292
297
  * collection.show('buildings');
293
298
  */
294
- show(tag: Tag): number;
299
+ show(by: Tag): this;
295
300
  /**
296
301
  * Hides all items with the specified tag.
297
302
  * Only affects items that have a 'show' property.
298
303
  *
299
- * @param tag - The tag identifying which items to hide
300
- * @returns The number of items affected
304
+ * @param by - The tag identifying which items to hide
305
+ * @returns The collection itself.
301
306
  *
302
307
  * @example
303
308
  * // Hide all buildings
304
309
  * collection.hide('buildings');
305
310
  */
306
- hide(tag: Tag): number;
311
+ hide(by: Tag): this;
307
312
  /**
308
313
  * Toggles visibility of all items with the specified tag.
309
314
  * Only affects items that have a 'show' property.
310
315
  *
311
- * @param tag - The tag identifying which items to toggle
312
- * @returns The number of items affected
316
+ * @param by - The tag identifying which items to toggle
317
+ * @returns The collection itself.
313
318
  *
314
319
  * @example
315
320
  * // Toggle visibility of all buildings
316
321
  * collection.toggle('buildings');
317
322
  */
318
- toggle(tag: Tag): number;
323
+ toggle(by: Tag): this;
319
324
  /**
320
325
  * Sets a property value on all items with the specified tag.
321
326
  *
322
- * @param tag - The tag identifying which items to update
327
+ * @param by - The tag identifying which items to update
323
328
  * @param property - The property name to set
324
329
  * @param value - The value to set
325
330
  * @returns The number of items updated
@@ -328,13 +333,13 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
328
333
  * // Change color of all buildings to red
329
334
  * collection.setProperty('buildings', 'color', Color.RED);
330
335
  */
331
- setProperty<K extends NonFunction<I>, V extends Exclude<I[K], Function>>(property: K, value: V, tag?: Tag): number;
336
+ setProperty<K extends NonFunction<I>, V extends Exclude<I[K], Function>>(property: K, value: V, by?: Tag): this;
332
337
  /**
333
338
  * Filters items in the collection based on a predicate function.
334
339
  * Optionally only filters items with a specific tag.
335
340
  *
336
341
  * @param predicate - Function that tests each item
337
- * @param tag - Optional tag to filter by before applying the predicate
342
+ * @param by - Optional tag to filter by before applying the predicate
338
343
  * @returns Array of items that pass the test
339
344
  *
340
345
  * @example
@@ -344,13 +349,13 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
344
349
  * 'buildings'
345
350
  * );
346
351
  */
347
- filter(predicate: (item: I) => boolean, tag?: Tag): I[];
352
+ filter(predicate: (item: I) => boolean, by?: Tag): I[];
348
353
  /**
349
354
  * Executes a callback function for each item in the collection.
350
355
  * Optionally filters items by tag before execution.
351
356
  *
352
357
  * @param callback - Function to execute for each item
353
- * @param tag - Optional tag to filter items (if not provided, processes all items)
358
+ * @param by - Optional tag to filter items (if not provided, processes all items)
354
359
  *
355
360
  * @example
356
361
  * // Highlight all buildings
@@ -360,7 +365,45 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
360
365
  * }
361
366
  * }, 'buildings');
362
367
  */
363
- forEach(callback: (item: I, index: number) => void, tag?: Tag): void;
368
+ forEach(callback: (value: I, index: number) => void, by?: Tag): void;
369
+ /**
370
+ * Creates a new array with the results of calling a provided function on every element
371
+ * in the collection. Optionally filters by tag before mapping.
372
+ *
373
+ * @param callbackfn - Function that produces an element of the new array
374
+ * @param by - Optional tag to filter items by before mapping
375
+ * @returns A new array with each element being the result of the callback function
376
+ *
377
+ * @example
378
+ * // Get all entity IDs
379
+ * const entityIds = collection.map(entity => entity.id);
380
+ *
381
+ * // Get positions of all buildings
382
+ * const buildingPositions = collection.map(
383
+ * entity => entity.position.getValue(Cesium.JulianDate.now()),
384
+ * 'buildings'
385
+ * );
386
+ */
387
+ map<R>(callbackfn: (value: I, index: number) => R, by?: Tag): R[];
388
+ /**
389
+ * Returns the first element in the collection that satisfies the provided testing function.
390
+ * Optionally filters by tag before searching.
391
+ *
392
+ * @param predicate - Function to test each element
393
+ * @param by - Optional tag to filter items by before searching
394
+ * @returns The first element that passes the test, or undefined if no elements pass
395
+ *
396
+ * @example
397
+ * // Find the first entity with a specific name
398
+ * const namedEntity = collection.find(entity => entity.name === 'Target');
399
+ *
400
+ * // Find the first building taller than 100 meters
401
+ * const tallBuilding = collection.find(
402
+ * entity => entity.properties?.height?.getValue() > 100,
403
+ * 'buildings'
404
+ * );
405
+ */
406
+ find(predicate: (value: I) => boolean, by?: Tag): I | undefined;
364
407
  }
365
408
 
366
409
  export { type CesiumCollection, type CesiumCollectionItem, Collection, type CollectionEventType, type EventHandler, type NonFunction, type Tag, type WithTag };
@@ -1 +1 @@
1
- import{c as o}from"../chunk-HC6YX7RQ.js";import"../chunk-YZ7AUGIO.js";export{o as Collection};
1
+ import{c as o}from"../chunk-DOPMSVYJ.js";import"../chunk-YZ7AUGIO.js";export{o as Collection};
@@ -1,4 +1,4 @@
1
- import { TilingScheme, TerrainProvider, Rectangle, Request, TerrainData, Credit, TileAvailability } from 'cesium';
1
+ import { Request, TerrainData, Credit, TerrainProvider, Rectangle, CesiumTerrainProvider, TilingScheme, TileAvailability } from 'cesium';
2
2
 
3
3
  /** A range of tiles from `start` to `end` */
4
4
  type TileRange = {
@@ -13,90 +13,6 @@ type TileRange = {
13
13
  y: number;
14
14
  };
15
15
  };
16
- /** A `TileRange` map with specific levels as their keys. */
17
- type TileRanges = Map<number, TileRange>;
18
-
19
- /**
20
- * @class
21
- * Defines the geographic boundaries for a terrain area and handles tile availability checks.
22
- */
23
- declare class TerrainBounds {
24
- private _rectangle;
25
- private _tilingScheme;
26
- private _tileRanges;
27
- private _levels;
28
- /**
29
- * Creates a new instance of TerrainBounds.
30
- * @param options {@link TerrainBounds.ConstructorOptions}
31
- * @param tilingScheme (optional) The tiling scheme to use for coordinate calculations.
32
- */
33
- constructor(options: TerrainBounds.ConstructorOptions, tilingScheme?: TilingScheme);
34
- /**
35
- * Checks if the specified tile coordinates are within the bounds.
36
- * @param x The tile X coordinate.
37
- * @param y The tile Y coordinate.
38
- * @param level The tile level.
39
- * @returns `true` if the tile is within bounds, `false` otherwise.
40
- */
41
- contains(x: number, y: number, level: number): boolean;
42
- /**
43
- *
44
- * Configures a terrain provider's availability based on these bounds.
45
- * @see WARNING This method is accessing private property of {@link https://cesium.com/learn/csiumjs/ref-doc/TileAvailability.html `TileAvailability`}.
46
- * @param provider The terrain provider to configure.
47
- */
48
- configureAvailability(provider: TerrainProvider): void;
49
- /**
50
- * Gets the rectangle representing these bounds.
51
- */
52
- get rectangle(): Rectangle;
53
- /** Gets the tiling scheme used by these bounds. */
54
- get tilingScheme(): TilingScheme;
55
- /** Gets the tile ranges defined for these bounds. */
56
- get tileRanges(): TileRanges;
57
- /** Gets the levels for which tile ranges are defined. */
58
- get levels(): Set<number>;
59
- /**
60
- * Calculates a bounding rectangle that encompasses all the specified tile ranges.
61
- * @private
62
- */
63
- private _calculateRectangleFromTileRanges;
64
- }
65
- /**
66
- * @namespace
67
- * Contains types and factory methods for creating `TerrainBounds` instances.
68
- */
69
- declare namespace TerrainBounds {
70
- /** Initialization options for Terrain Bounds constructor */
71
- interface ConstructorOptions {
72
- /** Type of bounds definition. */
73
- type: 'tileRange' | 'rectangle';
74
- /**
75
- * Tile ranges by level when using tileRange type.
76
- * Keys are zoom levels, values define the range of tiles at that level.
77
- * Can be provided either as a Map or as a plain object with numeric keys.
78
- */
79
- tileRanges?: Map<number, TileRange> | Record<string | number, TileRange>;
80
- /** Rectangle bounds when using rectangle type. */
81
- rectangle?: Rectangle;
82
- }
83
- /**
84
- * Creates `TerrainBounds` from tile coordinates at a specific level.
85
- * @param x The tile X coordinate.
86
- * @param y The tile Y coordinate.
87
- * @param level The tile level.
88
- * @param tilingScheme The tiling scheme to use.
89
- * @returns A new `TerrainBounds` instance for the specified tile.
90
- */
91
- function fromTile(x: number, y: number, level: number, tilingScheme?: TilingScheme): TerrainBounds;
92
- /**
93
- * Creates `TerrainBounds` from a rectangle.
94
- * @param rectangle The rectangle defining the bounds.
95
- * @param tilingScheme The tiling scheme to use.
96
- * @returns A new `TerrainBounds` instance for the specified rectangle.
97
- */
98
- function fromRectangle(rectangle: Rectangle, tilingScheme?: TilingScheme): TerrainBounds;
99
- }
100
16
 
101
17
  /**
102
18
  * @class
@@ -105,25 +21,22 @@ declare namespace TerrainBounds {
105
21
  */
106
22
  declare class TerrainArea {
107
23
  private _provider;
108
- private _bounds;
109
- private _levels;
24
+ private _rectangle;
25
+ private _tileRanges;
110
26
  private _ready;
111
27
  private _credit;
112
28
  private _isCustom;
113
29
  /**
114
30
  * Creates a new instance of `TerrainArea`.
115
31
  * @param options Object describing initialization options
116
- * @private Use {@link TerrainArea.create} instead.
117
32
  */
118
- private constructor();
33
+ constructor(options: TerrainArea.ConstructorOptions);
119
34
  /**
120
- * Asynchronously creates a new instance of `TerrainArea`.
121
- * @param options {@link TerrainArea.ConstructorOptions}
122
- * @returns A promise that resolves to a new `TerrainArea` instance.
123
- */
124
- static create(options: TerrainArea.ConstructorOptions): Promise<TerrainArea>;
125
- /**
126
- * @see {@link TerrainBounds.contains}
35
+ * Checks if the specified tile coordinates are within the bounds.
36
+ * @param x The tile X coordinate.
37
+ * @param y The tile Y coordinate.
38
+ * @param level The tile level.
39
+ * @returns `true` if the tile is within bounds, `false` otherwise.
127
40
  */
128
41
  contains(x: number, y: number, level: number): boolean;
129
42
  /**
@@ -151,11 +64,11 @@ declare class TerrainArea {
151
64
  /** Gets the credit associated with this terrain area. */
152
65
  get credit(): string | Credit;
153
66
  /** Gets the terrain provider for this terrain area. */
154
- get provider(): TerrainProvider | undefined;
155
- /** Gets the terrain bounds for this terrain area. */
156
- get bounds(): TerrainBounds;
157
- /** Gets available zoom levels set with this terrain area. */
158
- get levels(): Set<number>;
67
+ get provider(): TerrainProvider;
68
+ /** Gets available tile ranges with zoom levels set with this terrain area. */
69
+ get tileRanges(): Map<number, TileRange>;
70
+ /** Gets the rectangle representing this terrain area. */
71
+ get rectangle(): Rectangle;
159
72
  /** Gets if this terrain area is ready. */
160
73
  get ready(): boolean;
161
74
  }
@@ -167,14 +80,12 @@ declare namespace TerrainArea {
167
80
  /** Initialization options for `TerrainArea` constructor. */
168
81
  interface ConstructorOptions {
169
82
  /** The terrain provider for this area or a URL to create one from. */
170
- provider: TerrainProvider | string;
171
- /** The geographic bounds of this terrain area. */
172
- bounds: TerrainBounds | TerrainBounds.ConstructorOptions;
83
+ provider: TerrainProvider;
173
84
  /**
174
- * The zoom levels this terrain area applies to.
175
- * If empty, the area applies to all levels.
85
+ * Tile ranges by level when using tileRange type.
86
+ * Keys are zoom levels, values define the range of tiles at that level.
176
87
  */
177
- levels?: number[];
88
+ tileRanges: Map<number, TileRange>;
178
89
  /**
179
90
  * Credit to associate with this terrain provider.
180
91
  * Used to identify custom terrain providers.
@@ -191,11 +102,10 @@ declare namespace TerrainArea {
191
102
  * Creates a `TerrainArea` from a URL and tile ranges.
192
103
  * @param url The URL to create the terrain provider from.
193
104
  * @param tileRanges Tile ranges by level.
194
- * @param levels The zoom levels this area applies to.
195
- * @param credit Credit to associate with this terrain provider.
105
+ * @param options: Constructor options for CesiumTerrainProvider.
196
106
  * @returns A promise resolving to a new `TerrainArea`
197
107
  */
198
- function fromUrl(url: string, tileRanges: TileRanges, levels?: number[], credit?: string | Credit): Promise<Awaited<TerrainArea>>;
108
+ function fromUrl(url: string, tileRanges: Map<number, TileRange>, options?: CesiumTerrainProvider.ConstructorOptions): Promise<Awaited<TerrainArea>>;
199
109
  }
200
110
 
201
111
  /**
@@ -336,10 +246,9 @@ declare namespace HybridTerrainProvider {
336
246
  * @param customTerrainUrl URL to the custom terrain.
337
247
  * @param baseTerrainUrl URL to the base terrain.
338
248
  * @param tileRanges Tile ranges defining the custom terrain area.
339
- * @param levels Levels to apply the custom terrain.
340
249
  * @returns A promise resolving to a new `HybridTerrainProvider`.
341
250
  */
342
- function createOverlay(customTerrainUrl: string, baseTerrainUrl: string, tileRanges: TileRanges, levels?: number[]): Promise<Awaited<HybridTerrainProvider>>;
251
+ function createOverlay(customTerrainUrl: string, baseTerrainUrl: string, tileRanges: Map<number, TileRange>): Promise<Awaited<HybridTerrainProvider>>;
343
252
  }
344
253
 
345
- export { HybridTerrainProvider as H, TerrainArea as T, TerrainBounds as a, type TileRange as b, type TileRanges as c };
254
+ export { HybridTerrainProvider as H, TerrainArea as T, type TileRange as a };