@juun-roh/cesium-utils 0.1.3 → 0.2.1

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,493 +1,2 @@
1
- import { DataSourceCollection, EntityCollection, ImageryLayerCollection, PrimitiveCollection, DataSource, Entity, ImageryLayer, Billboard, Cesium3DTileset, GroundPrimitive, Label, PointPrimitive, Polyline, Primitive } from 'cesium';
2
-
3
- type CesiumCollection = DataSourceCollection | EntityCollection | ImageryLayerCollection | PrimitiveCollection;
4
- type Primitives = Billboard | Cesium3DTileset | GroundPrimitive | Label | PointPrimitive | Polyline | Primitive;
5
- type CesiumCollectionItem = DataSource | Entity | ImageryLayer | Primitives;
6
- type Tag = string | number;
7
- interface WithTag {
8
- [key: symbol]: Tag;
9
- }
10
- /**
11
- * Collection event types
12
- */
13
- type CollectionEventType = "add" | "remove" | "update" | "clear";
14
- /**
15
- * Event handler function type
16
- */
17
- type EventHandler<I> = (event: {
18
- type: CollectionEventType;
19
- items?: I[];
20
- tag?: Tag;
21
- }) => void;
22
- type NonFunction<T> = {
23
- [K in keyof T]: T[K] extends Function ? never : K;
24
- }[keyof T];
25
-
26
- /**
27
- * @class
28
- * A wrapper class that enhances Cesium collection objects with tagging functionality.
29
- * This class provides a consistent API for working with different types of Cesium collections
30
- * and allows grouping and manipulating collection items by custom tags.
31
- *
32
- * @template C - The type of Cesium collection (e.g., EntityCollection, PrimitiveCollection)
33
- * @template I - The type of items in the collection (e.g., Entity, Primitive)
34
- *
35
- * @example
36
- * // Example 1: Managing Complex Scene with Multiple Object Types
37
- * class SceneOrganizer {
38
- * private entities: Collection<EntityCollection, Entity>;
39
- * private billboards: Collection<BillboardCollection, Billboard>;
40
- * private primitives: Collection<PrimitiveCollection, Primitive>;
41
- *
42
- * constructor(viewer: Viewer) {
43
- * this.entities = new Collection({ collection: viewer.entities });
44
- * this.billboards = new Collection({
45
- * collection: viewer.scene.primitives.add(new BillboardCollection())
46
- * });
47
- * this.primitives = new Collection({
48
- * collection: viewer.scene.primitives
49
- * });
50
- * }
51
- *
52
- * // Unified API across different collection types!
53
- * showLayer(layerName: string) {
54
- * this.entities.show(layerName);
55
- * this.billboards.show(layerName);
56
- * this.primitives.show(layerName);
57
- * }
58
- *
59
- * hideLayer(layerName: string) {
60
- * this.entities.hide(layerName);
61
- * this.billboards.hide(layerName);
62
- * this.primitives.hide(layerName);
63
- * }
64
- *
65
- * removeLayer(layerName: string) {
66
- * this.entities.remove(layerName);
67
- * this.billboards.remove(layerName);
68
- * this.primitives.remove(layerName);
69
- * }
70
- * }
71
- *
72
- * // Example 2: Extend the class for Domain-Specific Needs
73
- * class BuildingCollection extends Collection<EntityCollection, Entity> {
74
- * constructor(viewer: Viewer) {
75
- * super({ collection: viewer.entities, tag: 'buildings' });
76
- * }
77
- *
78
- * addBuilding(options: {
79
- * position: Cartesian3;
80
- * height: number;
81
- * floors: number;
82
- * type: 'residential' | 'commercial' | 'industrial';
83
- * }): Entity {
84
- * const building = new Entity({
85
- * position: options.position,
86
- * box: {
87
- * dimensions: new Cartesian3(50, 50, options.height),
88
- * material: this.getMaterialForType(options.type)
89
- * }
90
- * });
91
- *
92
- * // Tag by type AND by floor count
93
- * this.add(building, options.type);
94
- * this.add(building, `floors-${options.floors}`);
95
- *
96
- * return building;
97
- * }
98
- *
99
- * getByFloorRange(min: number, max: number): Entity[] {
100
- * const results: Entity[] = [];
101
- * for (let i = min; i <= max; i++) {
102
- * results.push(...this.get(`floors-${i}`));
103
- * }
104
- * return results;
105
- * }
106
- *
107
- * private getMaterialForType(type: string): Material {
108
- * const colors = {
109
- * residential: Color.GREEN,
110
- * commercial: Color.BLUE,
111
- * industrial: Color.YELLOW
112
- * };
113
- * return new ColorMaterialProperty(colors[type] || Color.WHITE);
114
- * }
115
- * }
116
- */
117
- declare class Collection<C extends CesiumCollection, I extends CesiumCollectionItem> {
118
- /**
119
- * Symbol used as a property key to store tags on collection items.
120
- * Using a Symbol ensures no property naming conflicts with the item's own properties.
121
- * @readonly
122
- */
123
- static readonly symbol: unique symbol;
124
- /**
125
- * Default tag used when adding items without specifying a tag.
126
- * @protected
127
- */
128
- protected tag: Tag;
129
- /**
130
- * The underlying Cesium collection being wrapped.
131
- * @protected
132
- */
133
- protected collection: C;
134
- /**
135
- * Cache for values array to improve performance
136
- * @private
137
- */
138
- private _valuesCache;
139
- /**
140
- * Tag to items map for faster lookups
141
- * @private
142
- */
143
- private _tagMap;
144
- /**
145
- * Event listeners
146
- * @private
147
- */
148
- private _eventListeners;
149
- /**
150
- * For cleaning up the instances
151
- * @private
152
- */
153
- private _eventCleanupFunctions;
154
- /**
155
- * Creates a new Collection instance.
156
- *
157
- * @param options - Configuration options
158
- * @param options.collection - The Cesium collection to wrap
159
- * @param options.tag - The default tag to use for items (defaults to 'default')
160
- */
161
- constructor({ collection, tag }: {
162
- collection: C;
163
- tag?: Tag;
164
- });
165
- /**
166
- * Makes the collection directly iterable, allowing it to be used in `for...of` loops
167
- * and with spread operators.
168
- *
169
- * @returns An iterator for the items in the collection
170
- *
171
- * @example
172
- * // Iterate through all items in the collection
173
- * for (const entity of collection) {
174
- * console.log(entity.id);
175
- * }
176
- *
177
- * // Convert collection to array using spread syntax
178
- * const entitiesArray = [...collection];
179
- */
180
- [Symbol.iterator](): Iterator<I>;
181
- /**
182
- * Emits an event to all registered listeners.
183
- *
184
- * @private
185
- * @param type - The event type
186
- * @param data - Additional event data
187
- */
188
- private _emit;
189
- /**
190
- * Adds an item to the internal tag map for quick lookups.
191
- *
192
- * @private
193
- * @param item - The item to add
194
- * @param tag - The tag to associate with the item
195
- */
196
- private _addToTagMap;
197
- /**
198
- * Removes an item from the internal tag map.
199
- *
200
- * @private
201
- * @param item - The item to remove
202
- */
203
- private _removeFromTagMap;
204
- /**
205
- * Invalidates the values cache when collection changes.
206
- *
207
- * @private
208
- */
209
- private _invalidateCache;
210
- /**
211
- * Sets up automatic cache invalidation by registering event listeners on the underlying Cesium collection.
212
- *
213
- * @private
214
- * @param collection - The Cesium collection to monitor for changes
215
- *
216
- * @see {@link destroy} For cleanup of event listeners
217
- * @see {@link _invalidateCache} For the actual cache invalidation logic
218
- */
219
- private _setupCacheInvalidator;
220
- /**
221
- * Registers an event listener for collection events.
222
- *
223
- * @param type - The event type to listen for
224
- * @param handler - The callback function
225
- * @returns The collection instance for method chaining
226
- */
227
- addEventListener(type: CollectionEventType, handler: EventHandler<I>): this;
228
- /**
229
- * Removes an event listener.
230
- *
231
- * @param type - The event type
232
- * @param handler - The callback function to remove
233
- * @returns The collection instance for method chaining
234
- */
235
- removeEventListener(type: CollectionEventType, handler: EventHandler<I>): this;
236
- /**
237
- * Adds a single item with a tag to the collection.
238
- *
239
- * @param item - The item to add to the collection
240
- * @param tag - Tag to associate with this item (defaults to the collection's default tag)
241
- * @param index - The index to add the item at (if supported by the collection)
242
- * @returns The collection instance for method chaining
243
- *
244
- * @example
245
- * const entity = collection.add(new Entity({ ... }), 'landmarks');
246
- */
247
- add(item: I, tag?: Tag, index?: number): this;
248
- /**
249
- * Adds multiple items with the same tag to the collection.
250
- *
251
- * @param items - The array of items to add to the collection
252
- * @param tag - Tag to associate with this item (defaults to the collection's default tag)
253
- * @returns The collection instance for method chaining
254
- *
255
- * @example
256
- * // Add multiple entities with the same tag
257
- * const entities = [new Entity({ ... }), new Entity({ ... })];
258
- * const addedEntities = collection.add(entities, 'buildings');
259
- */
260
- add(items: I[], tag?: Tag): this;
261
- /**
262
- * Returns true if the provided item is in this collection, false otherwise.
263
- *
264
- * @param item - The item instance to check for
265
- * @returns True if the item is in the collection, false otherwise
266
- */
267
- contains(item: I): boolean;
268
- /**
269
- * Checks if the collection has any items with the specified tag.
270
- *
271
- * @param tag - The tag to check for
272
- * @returns True if items with the tag exist, false otherwise
273
- *
274
- * @example
275
- * if (collection.contains('temporary')) {
276
- * console.log('Temporary items exist');
277
- * }
278
- */
279
- contains(tag: Tag): boolean;
280
- /**
281
- * Removes an item from the collection.
282
- *
283
- * @param item - The item to remove
284
- * @returns The collection instance for method chaining
285
- */
286
- remove(item: I): this;
287
- /**
288
- * Removes all items with the specified tag from the collection.
289
- *
290
- * @param by - The tag identifying which items to remove
291
- * @returns The collection instance for method chaining
292
- */
293
- remove(by: Tag): this;
294
- /**
295
- * Removes all items with the array of tags from the collection.
296
- *
297
- * @param by - The tags identifying which items to remove
298
- * @returns The collection instance for method chaining
299
- */
300
- remove(by: Tag[]): this;
301
- /**
302
- * Removes all items from the collection.
303
- */
304
- removeAll(): void;
305
- /**
306
- * Permanently destroys this Collection instance.
307
- * Removes all event listeners and clears internal state.
308
- * The Collection instance should not be used after calling this method.
309
- */
310
- destroy(): void;
311
- /**
312
- * Gets all item instances in the collection.
313
- * This array should not be modified directly.
314
- *
315
- * @returns An array of all items in the collection
316
- */
317
- get values(): I[];
318
- /**
319
- * Gets the number of items in the collection.
320
- *
321
- * @returns The item count
322
- */
323
- get length(): number;
324
- /**
325
- * Gets all items with the specified tag from the collection.
326
- * Uses an optimized internal map for faster lookups.
327
- *
328
- * @param by - The tag to filter by
329
- * @returns An array of items with the specified tag, or an empty array if none found
330
- *
331
- * @example
332
- * // Get all buildings
333
- * const buildings = collection.get('buildings');
334
- */
335
- get(by: Tag): I[];
336
- /**
337
- * Gets the first item matching the tag. More efficient than `get` when
338
- * you only need one item, especially for large collections.
339
- *
340
- * @param by - The tag to search for
341
- * @returns The first matching item or undefined if none found
342
- *
343
- * @example
344
- * // Get the first building
345
- * const firstBuilding = collection.first('buildings');
346
- */
347
- first(by: Tag): I | undefined;
348
- /**
349
- * Gets all unique tags currently in use in the collection.
350
- *
351
- * @returns An array of all unique tags
352
- *
353
- * @example
354
- * // Get all tags
355
- * const tags = collection.tags;
356
- * console.log(`Collection has these tags: ${tags.join(', ')}`);
357
- */
358
- get tags(): Tag[];
359
- /**
360
- * Updates the tag for all items with the specified tag.
361
- *
362
- * @param from - The tag to replace
363
- * @param to - The new tag to assign
364
- * @returns The number of items updated
365
- *
366
- * @example
367
- * // Rename a tag
368
- * const count = collection.update('temp', 'temporary');
369
- * console.log(`Updated ${count} items`);
370
- */
371
- update(from: Tag, to: Tag): number;
372
- /**
373
- * Makes all items with the specified tag visible.
374
- * Only affects items that have a 'show' property.
375
- *
376
- * @param by - The tag identifying which items to show
377
- * @returns The collection itself.
378
- *
379
- * @example
380
- * // Show all buildings
381
- * collection.show('buildings');
382
- */
383
- show(by: Tag): this;
384
- /**
385
- * Hides all items with the specified tag.
386
- * Only affects items that have a 'show' property.
387
- *
388
- * @param by - The tag identifying which items to hide
389
- * @returns The collection itself.
390
- *
391
- * @example
392
- * // Hide all buildings
393
- * collection.hide('buildings');
394
- */
395
- hide(by: Tag): this;
396
- /**
397
- * Toggles visibility of all items with the specified tag.
398
- * Only affects items that have a 'show' property.
399
- *
400
- * @param by - The tag identifying which items to toggle
401
- * @returns The collection itself.
402
- *
403
- * @example
404
- * // Toggle visibility of all buildings
405
- * collection.toggle('buildings');
406
- */
407
- toggle(by: Tag): this;
408
- /**
409
- * Sets a property value on all items with the specified tag.
410
- *
411
- * @param by - The tag identifying which items to update
412
- * @param property - The property name to set
413
- * @param value - The value to set
414
- * @returns The collection itself.
415
- *
416
- * @example
417
- * // Change color of all buildings to red
418
- * collection.setProperty('buildings', 'color', Color.RED);
419
- */
420
- setProperty<K extends NonFunction<I>>(property: K, value: I[K], by?: Tag): this;
421
- /**
422
- * Filters items in the collection based on a predicate function.
423
- * Optionally only filters items with a specific tag.
424
- *
425
- * @param predicate - Function that tests each item
426
- * @param by - Optional tag to filter by before applying the predicate
427
- * @returns Array of items that pass the test
428
- *
429
- * @example
430
- * // Get all buildings taller than 100 meters
431
- * const tallBuildings = collection.filter(
432
- * entity => entity.properties?.height?.getValue() > 100,
433
- * 'buildings'
434
- * );
435
- */
436
- filter(predicate: (item: I) => boolean, by?: Tag): I[];
437
- /**
438
- * Executes a callback function for each item in the collection.
439
- * Optionally filters items by tag before execution.
440
- *
441
- * @param callback - Function to execute for each item
442
- * @param by - Optional tag to filter items (if not provided, processes all items)
443
- *
444
- * @example
445
- * // Highlight all buildings
446
- * collection.forEach((entity) => {
447
- * if (entity.polygon) {
448
- * entity.polygon.material = new ColorMaterialProperty(Color.YELLOW);
449
- * }
450
- * }, 'buildings');
451
- */
452
- forEach(callback: (value: I, index: number) => void, by?: Tag): void;
453
- /**
454
- * Creates a new array with the results of calling a provided function on every element
455
- * in the collection. Optionally filters by tag before mapping.
456
- *
457
- * @param callbackfn - Function that produces an element of the new array
458
- * @param by - Optional tag to filter items by before mapping
459
- * @returns A new array with each element being the result of the callback function
460
- *
461
- * @example
462
- * // Get all entity IDs
463
- * const entityIds = collection.map(entity => entity.id);
464
- *
465
- * // Get positions of all buildings
466
- * const buildingPositions = collection.map(
467
- * entity => entity.position.getValue(Cesium.JulianDate.now()),
468
- * 'buildings'
469
- * );
470
- */
471
- map<R>(callbackfn: (value: I, index: number) => R, by?: Tag): R[];
472
- /**
473
- * Returns the first element in the collection that satisfies the provided testing function.
474
- * Optionally filters by tag before searching.
475
- *
476
- * @param predicate - Function to test each element
477
- * @param by - Optional tag to filter items by before searching
478
- * @returns The first element that passes the test, or undefined if no elements pass
479
- *
480
- * @example
481
- * // Find the first entity with a specific name
482
- * const namedEntity = collection.find(entity => entity.name === 'Target');
483
- *
484
- * // Find the first building taller than 100 meters
485
- * const tallBuilding = collection.find(
486
- * entity => entity.properties?.height?.getValue() > 100,
487
- * 'buildings'
488
- * );
489
- */
490
- find(predicate: (value: I) => boolean, by?: Tag): I | undefined;
491
- }
492
-
493
- export { type CesiumCollection, type CesiumCollectionItem, Collection, type CollectionEventType, type EventHandler, type NonFunction, type Tag, type WithTag };
1
+ export { C as Collection } from '../index-Bd_-DTWl.js';
2
+ import 'cesium';
@@ -1 +1 @@
1
- import"../chunk-RXMNSDKR.js";import{c as a}from"../chunk-ZV7FKRP6.js";export{a as Collection};
1
+ import"../chunk-RXMNSDKR.js";import{c as a}from"../chunk-NO7SO2WH.js";export{a as Collection};
@@ -1 +1 @@
1
- "use strict";var f=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var m=(n,t)=>{for(var i in t)f(n,i,{get:t[i],enumerable:!0})},O=(n,t,i,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of p(t))!y.call(n,s)&&s!==i&&f(n,s,{get:()=>t[s],enumerable:!(e=_(t,s))||e.enumerable});return n};var w=n=>O(f({},"__esModule",{value:!0}),n);var v={};m(v,{Highlight:()=>a,SilhouetteHighlight:()=>l,SurfaceHighlight:()=>c});module.exports=w(v);var h=require("cesium");var o=require("cesium"),l=class{_color=o.Color.RED;_silhouette;_composite;_stages;_entity;_currentObject;_currentOptions;constructor(t){this._stages=t.scene.postProcessStages,this._silhouette=o.PostProcessStageLibrary.createEdgeDetectionStage(),this._silhouette.uniforms.color=this._color,this._silhouette.uniforms.length=.01,this._silhouette.selected=[],this._composite=o.PostProcessStageLibrary.createSilhouetteStage([this._silhouette]),this._stages.add(this._composite)}show(t,i){if((0,o.defined)(t)&&!(this._currentObject===t&&this._optionsEqual(this._currentOptions,i))){this._clearHighlights();try{if(t instanceof o.Cesium3DTileFeature)this._silhouette.uniforms.color=i?.color||this._color,this._silhouette.selected.push(t);else{if(!t.model)return;this._entity=t,t.model.silhouetteSize=new o.ConstantProperty(i?.width||2),t.model.silhouetteColor=new o.ConstantProperty(i?.color||this._color)}this._currentObject=t,this._currentOptions=i?{...i}:void 0}catch(e){console.error("Failed to highlight object:",e),this._currentObject=void 0,this._currentOptions=void 0}}}_optionsEqual(t,i){return!t&&!i?!0:!t||!i?!1:t.outline===i.outline&&t.width===i.width&&o.Color.equals(t.color||this._color,i.color||this._color)}_clearHighlights(){this._silhouette.selected.length>0&&(this._silhouette.selected=[]),this._entity?.model&&(this._entity.model.silhouetteColor=new o.ConstantProperty(o.Color.TRANSPARENT),this._entity.model.silhouetteSize=new o.ConstantProperty(0),this._entity=void 0)}hide(){this._clearHighlights(),this._currentObject=void 0,this._currentOptions=void 0}destroy(){this.hide(),this._composite&&this._stages.remove(this._composite),this._currentObject=void 0,this._currentOptions=void 0}get color(){return this._color}set color(t){this._color=t}get currentObject(){return this._currentObject}};var r=require("cesium"),c=class{_color=r.Color.RED;_entity;_entities;_currentObject;_currentOptions;constructor(t){this._entities=t.entities,this._entity=this._entities.add(new r.Entity({id:`highlight-entity-${Math.random().toString(36).substring(2)}`,show:!1}))}show(t,i){if(!(!(0,r.defined)(t)||!this._entity)){if(this._currentObject===t&&this._optionsEqual(this._currentOptions,i))return this._entity;this._clearGeometries();try{if(t instanceof r.Entity&&(t.polygon||t.polyline||t.rectangle))this._update(t,i);else if(t instanceof r.GroundPrimitive)this._update(t,i);else{this._currentObject=void 0,this._currentOptions=void 0;return}return this._currentObject=t,this._currentOptions=i?{...i}:void 0,this._entity.show=!0,this._entity}catch(e){console.error("Failed to highlight object:",e),this._currentObject=void 0,this._currentOptions=void 0;return}}}_optionsEqual(t,i){return!t&&!i?!0:!t||!i?!1:t.outline===i.outline&&t.width===i.width&&r.Color.equals(t.color||this._color,i.color||this._color)}_clearGeometries(){this._entity.polygon=void 0,this._entity.polyline=void 0,this._entity.rectangle=void 0}_update(t,i={color:this._color,outline:!1,width:2}){if(t instanceof r.Entity){if(t.polygon)if(i.outline){let e=t.polygon.hierarchy?.getValue();if(e&&e.positions){let s;e.positions.length>0&&!r.Cartesian3.equals(e.positions[0],e.positions[e.positions.length-1])?s=[...e.positions,e.positions[0]]:s=e.positions,this._entity.polyline=new r.PolylineGraphics({positions:s,material:i.color,width:i.width||2,clampToGround:!0})}}else{let e=t.polygon.hierarchy?.getValue();e&&(this._entity.polygon=new r.PolygonGraphics({hierarchy:e,material:i.color,heightReference:r.HeightReference.CLAMP_TO_GROUND,classificationType:t.polygon.classificationType?.getValue()||r.ClassificationType.BOTH}))}else if(t.polyline){let e=t.polyline.positions?.getValue();if(e){let s=t.polyline.width?.getValue();this._entity.polyline=new r.PolylineGraphics({positions:e,material:i.color,width:s+(i.width||2),clampToGround:!0})}}else if(t.rectangle)if(i.outline){let e=t.rectangle.coordinates?.getValue();if(e){let s=[r.Cartesian3.fromRadians(e.west,e.north),r.Cartesian3.fromRadians(e.east,e.north),r.Cartesian3.fromRadians(e.east,e.south),r.Cartesian3.fromRadians(e.west,e.south),r.Cartesian3.fromRadians(e.west,e.north)];this._entity.polyline=new r.PolylineGraphics({positions:s,material:i.color,width:i.width||2,clampToGround:!0})}}else{let e=t.rectangle.coordinates?.getValue();e&&(this._entity.rectangle=new r.RectangleGraphics({coordinates:e,material:i.color,heightReference:r.HeightReference.CLAMP_TO_GROUND}))}}else if(t instanceof r.GroundPrimitive){let e=t.geometryInstances,s=Array.isArray(e)?e[0]:e;if(!s.geometry.attributes.position)return;let d=s.geometry.attributes.position.values,g=[];for(let u=0;u<d.length;u+=3)g.push(new r.Cartesian3(d[u],d[u+1],d[u+2]));i.outline?this._entity.polyline=new r.PolylineGraphics({positions:g,material:i.color,width:i.width||2,clampToGround:!0}):this._entity.polygon=new r.PolygonGraphics({hierarchy:new r.PolygonHierarchy(g),material:i.color,heightReference:r.HeightReference.CLAMP_TO_GROUND,classificationType:r.ClassificationType.BOTH})}}hide(){this._entity&&(this._entity.show=!1),this._currentObject=void 0,this._currentOptions=void 0}destroy(){this._entities.contains(this._entity)&&this._entities.remove(this._entity),this._currentObject=void 0,this._currentOptions=void 0}get color(){return this._color}set color(t){this._color=t}get entity(){return this._entity}get currentObject(){return this._currentObject}};var a=class n{static instances=new WeakMap;_surface;_silhouette;_color=h.Color.RED;constructor(t){this._surface=new c(t),this._silhouette=new l(t),this._surface.color=this._color,this._silhouette.color=this._color}static getInstance(t){let i=t.container;return n.instances.has(i)||n.instances.set(i,new n(t)),n.instances.get(i)}static releaseInstance(t){let i=t.container,e=n.instances.get(i);e&&(e.hide(),e._surface&&e._surface.destroy(),e._silhouette&&e._silhouette.destroy(),n.instances.delete(i))}show(t,i={color:this._color}){let e=this._getObject(t);if((0,h.defined)(e))return e instanceof h.Cesium3DTileFeature?this._silhouette.show(e,i):e instanceof h.Entity&&e.model?this._silhouette.show(e,i):this._surface.show(e,i)}_getObject(t){if((0,h.defined)(t)){if(t instanceof h.Entity||t instanceof h.Cesium3DTileFeature||t instanceof h.GroundPrimitive)return t;if(t.id instanceof h.Entity)return t.id;if(t.primitive instanceof h.GroundPrimitive)return t.primitive}}hide(){this._surface.hide(),this._silhouette.hide()}get color(){return this._color}set color(t){this._color=t,this._surface.color=t,this._silhouette.color=t}};
1
+ "use strict";var f=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var v=(n,t)=>{for(var i in t)f(n,i,{get:t[i],enumerable:!0})},O=(n,t,i,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of y(t))!m.call(n,o)&&o!==i&&f(n,o,{get:()=>t[o],enumerable:!(e=p(t,o))||e.enumerable});return n};var w=n=>O(f({},"__esModule",{value:!0}),n);var C={};v(C,{Highlight:()=>_,SilhouetteHighlight:()=>h,SurfaceHighlight:()=>c});module.exports=w(C);var l=require("cesium");var s=require("cesium"),h=class{_color=s.Color.RED;_silhouette;_composite;_stages;_entity;_currentObject;_currentOptions;constructor(t){this._stages=t.scene.postProcessStages,this._silhouette=s.PostProcessStageLibrary.createEdgeDetectionStage(),this._silhouette.uniforms.color=this._color,this._silhouette.uniforms.length=.01,this._silhouette.selected=[],this._composite=s.PostProcessStageLibrary.createSilhouetteStage([this._silhouette]),this._stages.add(this._composite)}show(t,i){if((0,s.defined)(t)&&!(this._currentObject===t&&this._optionsEqual(this._currentOptions,i))){this._clearHighlights();try{if(t instanceof s.Cesium3DTileFeature)this._silhouette.uniforms.color=i?.color||this._color,this._silhouette.selected.push(t);else{if(!t.model)return;this._entity=t,t.model.silhouetteSize=new s.ConstantProperty(i?.width||2),t.model.silhouetteColor=new s.ConstantProperty(i?.color||this._color)}this._currentObject=t,this._currentOptions=i?{...i}:void 0}catch(e){console.error("Failed to highlight object:",e),this._currentObject=void 0,this._currentOptions=void 0}}}_optionsEqual(t,i){return!t&&!i?!0:!t||!i?!1:t.outline===i.outline&&t.width===i.width&&s.Color.equals(t.color||this._color,i.color||this._color)}_clearHighlights(){this._silhouette.selected.length>0&&(this._silhouette.selected=[]),this._entity?.model&&(this._entity.model.silhouetteColor=new s.ConstantProperty(s.Color.TRANSPARENT),this._entity.model.silhouetteSize=new s.ConstantProperty(0),this._entity=void 0)}hide(){this._clearHighlights(),this._currentObject=void 0,this._currentOptions=void 0}destroy(){this.hide(),this._composite&&this._stages.remove(this._composite),this._currentObject=void 0,this._currentOptions=void 0}get color(){return this._color}set color(t){this._color=t}get currentObject(){return this._currentObject}};var r=require("cesium"),c=class{_color=r.Color.RED;_entity;_entities;_currentObject;_currentOptions;constructor(t){this._entities=t.entities,this._entity=this._entities.add(new r.Entity({id:`highlight-entity-${Math.random().toString(36).substring(2)}`,show:!1}))}show(t,i){if(!(!(0,r.defined)(t)||!this._entity)){if(this._currentObject===t&&this._optionsEqual(this._currentOptions,i))return this._entity;this._clearGeometries();try{if(t instanceof r.Entity&&(t.polygon||t.polyline||t.rectangle))this._update(t,i);else if(t instanceof r.GroundPrimitive)this._update(t,i);else{this._currentObject=void 0,this._currentOptions=void 0;return}return this._currentObject=t,this._currentOptions=i?{...i}:void 0,this._entity.show=!0,this._entity}catch(e){console.error("Failed to highlight object:",e),this._currentObject=void 0,this._currentOptions=void 0;return}}}_optionsEqual(t,i){return!t&&!i?!0:!t||!i?!1:t.outline===i.outline&&t.width===i.width&&r.Color.equals(t.color||this._color,i.color||this._color)}_clearGeometries(){this._entity.polygon=void 0,this._entity.polyline=void 0,this._entity.rectangle=void 0}_update(t,i={color:this._color,outline:!1,width:2}){if(t instanceof r.Entity){if(t.polygon)if(i.outline){let e=t.polygon.hierarchy?.getValue();if(e&&e.positions){let o;e.positions.length>0&&!r.Cartesian3.equals(e.positions[0],e.positions[e.positions.length-1])?o=[...e.positions,e.positions[0]]:o=e.positions,this._entity.polyline=new r.PolylineGraphics({positions:o,material:i.color,width:i.width||2,clampToGround:!0})}}else{let e=t.polygon.hierarchy?.getValue();e&&(this._entity.polygon=new r.PolygonGraphics({hierarchy:e,material:i.color,heightReference:r.HeightReference.CLAMP_TO_GROUND,classificationType:t.polygon.classificationType?.getValue()||r.ClassificationType.BOTH}))}else if(t.polyline){let e=t.polyline.positions?.getValue();if(e){let o=t.polyline.width?.getValue();this._entity.polyline=new r.PolylineGraphics({positions:e,material:i.color,width:o+(i.width||2),clampToGround:!0})}}else if(t.rectangle)if(i.outline){let e=t.rectangle.coordinates?.getValue();if(e){let o=[r.Cartesian3.fromRadians(e.west,e.north),r.Cartesian3.fromRadians(e.east,e.north),r.Cartesian3.fromRadians(e.east,e.south),r.Cartesian3.fromRadians(e.west,e.south),r.Cartesian3.fromRadians(e.west,e.north)];this._entity.polyline=new r.PolylineGraphics({positions:o,material:i.color,width:i.width||2,clampToGround:!0})}}else{let e=t.rectangle.coordinates?.getValue();e&&(this._entity.rectangle=new r.RectangleGraphics({coordinates:e,material:i.color,heightReference:r.HeightReference.CLAMP_TO_GROUND}))}}else if(t instanceof r.GroundPrimitive){let e=t.geometryInstances,o=Array.isArray(e)?e[0]:e;if(!o.geometry.attributes.position)return;let a=o.geometry.attributes.position.values,d=[];for(let u=0;u<a.length;u+=3)d.push(new r.Cartesian3(a[u],a[u+1],a[u+2]));i.outline?this._entity.polyline=new r.PolylineGraphics({positions:d,material:i.color,width:i.width||2,clampToGround:!0}):this._entity.polygon=new r.PolygonGraphics({hierarchy:new r.PolygonHierarchy(d),material:i.color,heightReference:r.HeightReference.CLAMP_TO_GROUND,classificationType:r.ClassificationType.BOTH})}}hide(){this._entity&&(this._entity.show=!1),this._currentObject=void 0,this._currentOptions=void 0}destroy(){this._entities.contains(this._entity)&&this._entities.remove(this._entity),this._currentObject=void 0,this._currentOptions=void 0}get color(){return this._color}set color(t){this._color=t}get entity(){return this._entity}get currentObject(){return this._currentObject}};var g=class n{static instances=new WeakMap;_surface;_silhouette;_color=l.Color.RED;constructor(t){this._surface=new c(t),this._silhouette=new h(t),this._surface.color=this._color,this._silhouette.color=this._color}static getInstance(t){let i=t.container;return n.instances.has(i)||n.instances.set(i,new n(t)),n.instances.get(i)}static releaseInstance(t){let i=t.container,e=n.instances.get(i);e&&(e.hide(),e._surface&&e._surface.destroy(),e._silhouette&&e._silhouette.destroy(),n.instances.delete(i))}show(t,i={color:this._color}){let e=this._getObject(t);if((0,l.defined)(e))return e instanceof l.Cesium3DTileFeature?this._silhouette.show(e,i):e instanceof l.Entity&&e.model?this._silhouette.show(e,i):this._surface.show(e,i)}_getObject(t){if((0,l.defined)(t)){if(t instanceof l.Entity||t instanceof l.Cesium3DTileFeature||t instanceof l.GroundPrimitive)return t;if(t.id instanceof l.Entity)return t.id;if(t.primitive instanceof l.GroundPrimitive)return t.primitive}}hide(){this._surface.hide(),this._silhouette.hide()}get color(){return this._color}set color(t){this._color=t,this._surface.color=t,this._silhouette.color=t}},_=g;
@@ -1,28 +1,4 @@
1
- import { Entity, Cesium3DTileFeature, GroundPrimitive, Primitive, Model, Cesium3DTileset, Color, Viewer } from 'cesium';
2
-
3
- interface IHighlight {
4
- show(object: any, options?: HighlightOptions): void;
5
- hide(): void;
6
- destroy(): void;
7
- color: Color;
8
- }
9
- interface HighlightOptions {
10
- /** Color of the highlight */
11
- color?: Color;
12
- /** To apply outline style for the highlight */
13
- outline?: boolean;
14
- /** Outline width */
15
- width?: number;
16
- }
17
- type PickedObject = {
18
- id?: Entity;
19
- primitive?: Primitive | GroundPrimitive | Model | Cesium3DTileset;
20
- tileset?: Cesium3DTileset;
21
- detail?: {
22
- model?: Model;
23
- };
24
- };
25
- type Picked = Entity | Cesium3DTileFeature | GroundPrimitive | PickedObject;
1
+ import { Viewer, Entity, Color, Primitive, GroundPrimitive, Model, Cesium3DTileset, Cesium3DTileFeature } from 'cesium';
26
2
 
27
3
  /**
28
4
  * @class
@@ -75,9 +51,9 @@ declare class Highlight {
75
51
  * Highlights a picked object or a direct instance.
76
52
  * @param picked The result of `Scene.pick()` or direct instance to be highlighted.
77
53
  * @param options Optional style for the highlight.
78
- * @see {@link HighlightOptions}
54
+ * @see {@link Highlight.Options}
79
55
  */
80
- show(picked: Picked, options?: HighlightOptions): void | Entity;
56
+ show(picked: Highlight.Picked, options?: Highlight.Options): void | Entity;
81
57
  private _getObject;
82
58
  /**
83
59
  * Clears the current highlight effects.
@@ -91,6 +67,32 @@ declare class Highlight {
91
67
  */
92
68
  set color(color: Color);
93
69
  }
70
+ declare namespace Highlight {
71
+ export interface Base {
72
+ show(object: any, options?: Highlight.Options): void;
73
+ hide(): void;
74
+ destroy(): void;
75
+ color: Color;
76
+ }
77
+ export interface Options {
78
+ /** Color of the highlight */
79
+ color?: Color;
80
+ /** To apply outline style for the highlight */
81
+ outline?: boolean;
82
+ /** Outline width */
83
+ width?: number;
84
+ }
85
+ type PickedObject = {
86
+ id?: Entity;
87
+ primitive?: Primitive | GroundPrimitive | Model | Cesium3DTileset;
88
+ tileset?: Cesium3DTileset;
89
+ detail?: {
90
+ model?: Model;
91
+ };
92
+ };
93
+ export type Picked = Entity | Cesium3DTileFeature | GroundPrimitive | PickedObject;
94
+ export { };
95
+ }
94
96
 
95
97
  /**
96
98
  * @class
@@ -114,7 +116,7 @@ declare class Highlight {
114
116
  * silhouetteHighlight.show(entity);
115
117
  * ```
116
118
  */
117
- declare class SilhouetteHighlight implements IHighlight {
119
+ declare class SilhouetteHighlight implements Highlight.Base {
118
120
  private _color;
119
121
  private _silhouette;
120
122
  private _composite;
@@ -132,15 +134,15 @@ declare class SilhouetteHighlight implements IHighlight {
132
134
  * @param object The object to be highlighted.
133
135
  * @param options Optional style for the highlight.
134
136
  */
135
- show(object: Cesium3DTileFeature, options?: HighlightOptions): void;
137
+ show(object: Cesium3DTileFeature, options?: Highlight.Options): void;
136
138
  /**
137
139
  * Highlights a picked `Entity` by updating the model properties.
138
140
  * @param object The object to be highlighted.
139
141
  * @param options Optional style for the highlight.
140
142
  */
141
- show(object: Entity, options?: HighlightOptions): void;
143
+ show(object: Entity, options?: Highlight.Options): void;
142
144
  /**
143
- * Compares two HighlightOptions objects for equality
145
+ * Compares two Highlight.Options objects for equality
144
146
  * @private
145
147
  */
146
148
  private _optionsEqual;
@@ -191,7 +193,7 @@ declare class SilhouetteHighlight implements IHighlight {
191
193
  * surfaceHighlight.show(entity);
192
194
  * ```
193
195
  */
194
- declare class SurfaceHighlight implements IHighlight {
196
+ declare class SurfaceHighlight implements Highlight.Base {
195
197
  private _color;
196
198
  private _entity;
197
199
  private _entities;
@@ -206,11 +208,11 @@ declare class SurfaceHighlight implements IHighlight {
206
208
  * Highlights a picked object by updating the reusable entity
207
209
  * @param object The object to be highlighted.
208
210
  * @param options Optional style for the highlight.
209
- * @see {@link HighlightOptions}
211
+ * @see {@link Highlight.Options}
210
212
  */
211
- show(object: Entity | GroundPrimitive, options?: HighlightOptions): Entity | undefined;
213
+ show(object: Entity | GroundPrimitive, options?: Highlight.Options): Entity | undefined;
212
214
  /**
213
- * Compares two HighlightOptions objects for equality
215
+ * Compares two Highlight.Options objects for equality
214
216
  * @private
215
217
  */
216
218
  private _optionsEqual;
@@ -240,4 +242,4 @@ declare class SurfaceHighlight implements IHighlight {
240
242
  get currentObject(): Entity | GroundPrimitive | undefined;
241
243
  }
242
244
 
243
- export { Highlight, type HighlightOptions, type IHighlight, type Picked, type PickedObject, SilhouetteHighlight, SurfaceHighlight };
245
+ export { Highlight, SilhouetteHighlight, SurfaceHighlight };