@juun-roh/cesium-utils 0.1.2 → 0.2.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.
@@ -0,0 +1,245 @@
1
+ import { Viewer, Entity, Color, Primitive, GroundPrimitive, Model, Cesium3DTileset, Cesium3DTileFeature } from 'cesium';
2
+
3
+ /**
4
+ * @class
5
+ * Lightweight multiton highlight manager for Cesium using flyweight pattern.
6
+ *
7
+ * @example
8
+ * ```
9
+ * // Setup
10
+ * const viewer1 = new Viewer('cesiumContainer1');
11
+ * const viewer2 = new Viewer('cesiumContainer2');
12
+ *
13
+ * const highlighter1 = Highlight.getInstance(viewer1);
14
+ * const highlighter2 = Highlight.getInstance(viewer2);
15
+ *
16
+ * // This highlight only affects viewer1
17
+ * highlighter1.show(someEntity, { color: Color.RED });
18
+ *
19
+ * // This highlight only affects viewer2
20
+ * highlighter2.show(someEntity, { color: Color.BLUE });
21
+ *
22
+ * // When done with viewers
23
+ * Highlight.releaseInstance(viewer1);
24
+ * Highlight.releaseInstance(viewer2);
25
+ * viewer1.destroy();
26
+ * viewer2.destroy();
27
+ * ```
28
+ */
29
+ declare class Highlight {
30
+ private static instances;
31
+ private _surface;
32
+ private _silhouette;
33
+ private _color;
34
+ /**
35
+ * Creates a new `Highlight` instance.
36
+ * @private Use {@link getInstance `Highlight.getInstance()`}
37
+ * @param viewer A viewer to create highlight entity in
38
+ */
39
+ private constructor();
40
+ /**
41
+ * Gets or creates highlight instance from a viewer.
42
+ * @param viewer The viewer to get or create a new instance from.
43
+ */
44
+ static getInstance(viewer: Viewer): Highlight;
45
+ /**
46
+ * Releases the highlight instance associated with a viewer.
47
+ * @param viewer The viewer whose highlight instance should be released.
48
+ */
49
+ static releaseInstance(viewer: Viewer): void;
50
+ /**
51
+ * Highlights a picked object or a direct instance.
52
+ * @param picked The result of `Scene.pick()` or direct instance to be highlighted.
53
+ * @param options Optional style for the highlight.
54
+ * @see {@link Highlight.Options}
55
+ */
56
+ show(picked: Highlight.Picked, options?: Highlight.Options): void | Entity;
57
+ private _getObject;
58
+ /**
59
+ * Clears the current highlight effects.
60
+ */
61
+ hide(): void;
62
+ /** Gets the highlight color. */
63
+ get color(): Color;
64
+ /**
65
+ * Sets the highlight color.
66
+ * @param color The new color for highlights
67
+ */
68
+ set color(color: Color);
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
+ }
96
+
97
+ /**
98
+ * @class
99
+ * An implementation for highlighting 3D objects in Cesium.
100
+ *
101
+ * **Supported Object Types:**
102
+ * - `Entity` with model graphics. (adjustable outline width)
103
+ * - `Cesium3DTileset` instances. (fixed outline width)
104
+ *
105
+ * Currently supports outline style only.
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * const viewer = new Viewer("cesiumContainer");
110
+ * const silhouetteHighlight = new SilhouetteHighlight(viewer);
111
+ *
112
+ * // Highlight an object
113
+ * const entity = viewer.entities.add(new Entity({
114
+ * model: new ModelGraphics(),
115
+ * }));
116
+ * silhouetteHighlight.show(entity);
117
+ * ```
118
+ */
119
+ declare class SilhouetteHighlight implements Highlight.Base {
120
+ private _color;
121
+ private _silhouette;
122
+ private _composite;
123
+ private _stages;
124
+ private _entity?;
125
+ private _currentObject;
126
+ private _currentOptions;
127
+ /**
128
+ * Creates a new `Silhouette` instance.
129
+ * @param viewer A viewer to create highlight silhouette in
130
+ */
131
+ constructor(viewer: Viewer);
132
+ /**
133
+ * Highlights a picked `Cesium3DTileset` by updating silhouette composite.
134
+ * @param object The object to be highlighted.
135
+ * @param options Optional style for the highlight.
136
+ */
137
+ show(object: Cesium3DTileFeature, options?: Highlight.Options): void;
138
+ /**
139
+ * Highlights a picked `Entity` by updating the model properties.
140
+ * @param object The object to be highlighted.
141
+ * @param options Optional style for the highlight.
142
+ */
143
+ show(object: Entity, options?: Highlight.Options): void;
144
+ /**
145
+ * Compares two Highlight.Options objects for equality
146
+ * @private
147
+ */
148
+ private _optionsEqual;
149
+ /**
150
+ * Clears all current highlights
151
+ * @private
152
+ */
153
+ private _clearHighlights;
154
+ /** Clears the current highlight */
155
+ hide(): void;
156
+ /** Clean up the instances */
157
+ destroy(): void;
158
+ /** Gets the highlight color. */
159
+ get color(): Color;
160
+ /** Sets the highlight color. */
161
+ set color(color: Color);
162
+ /** Gets the currently highlighted object */
163
+ get currentObject(): Cesium3DTileFeature | Entity | undefined;
164
+ }
165
+
166
+ /**
167
+ * @class
168
+ * A flyweight implementation for highlighting 2D surface objects in Cesium.
169
+ *
170
+ * This class provides highlighting for ground-clamped geometries (polygons, polylines, rectangles)
171
+ *
172
+ * **Supported Geometry Types:**
173
+ * - `Entity` with polygon, polyline, or rectangle graphics
174
+ * - `GroundPrimitive` instances
175
+ *
176
+ * **Highlighting Modes:**
177
+ * - **Fill mode** (default): Creates a filled geometry using the original shape
178
+ * - **Outline mode**: Creates a polyline outline of the original geometry
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * // Basic usage
183
+ * const viewer = new Viewer('cesiumContainer');
184
+ * const surfaceHighlight = new SurfaceHighlight(viewer);
185
+ *
186
+ * // Highlight an entity with default red fill
187
+ * const entity = viewer.entities.add(new Entity({
188
+ * polygon: {
189
+ * hierarchy: Cartesian3.fromDegreesArray([-75, 35, -74, 35, -74, 36, -75, 36]),
190
+ * material: Color.BLUE
191
+ * }
192
+ * }));
193
+ * surfaceHighlight.show(entity);
194
+ * ```
195
+ */
196
+ declare class SurfaceHighlight implements Highlight.Base {
197
+ private _color;
198
+ private _entity;
199
+ private _entities;
200
+ private _currentObject;
201
+ private _currentOptions;
202
+ /**
203
+ * Creates a new `SurfaceHighlight` instance.
204
+ * @param viewer A viewer to create highlight entity in
205
+ */
206
+ constructor(viewer: Viewer);
207
+ /**
208
+ * Highlights a picked object by updating the reusable entity
209
+ * @param object The object to be highlighted.
210
+ * @param options Optional style for the highlight.
211
+ * @see {@link Highlight.Options}
212
+ */
213
+ show(object: Entity | GroundPrimitive, options?: Highlight.Options): Entity | undefined;
214
+ /**
215
+ * Compares two Highlight.Options objects for equality
216
+ * @private
217
+ */
218
+ private _optionsEqual;
219
+ /**
220
+ * Removes all geometry properties from the highlight entity
221
+ * @private
222
+ */
223
+ private _clearGeometries;
224
+ /**
225
+ * Updates the highlight entity from an Entity object
226
+ * @private
227
+ */
228
+ private _update;
229
+ /**
230
+ * Clears the current highlight
231
+ */
232
+ hide(): void;
233
+ /** Clean up the instances */
234
+ destroy(): void;
235
+ /** Gets the highlight color. */
236
+ get color(): Color;
237
+ /** Sets the highlight color. */
238
+ set color(color: Color);
239
+ /** Gets the highlight entity */
240
+ get entity(): Entity;
241
+ /** Gets the currently highlighted object */
242
+ get currentObject(): Entity | GroundPrimitive | undefined;
243
+ }
244
+
245
+ export { Highlight, SilhouetteHighlight, SurfaceHighlight };
@@ -0,0 +1,245 @@
1
+ import { Viewer, Entity, Color, Primitive, GroundPrimitive, Model, Cesium3DTileset, Cesium3DTileFeature } from 'cesium';
2
+
3
+ /**
4
+ * @class
5
+ * Lightweight multiton highlight manager for Cesium using flyweight pattern.
6
+ *
7
+ * @example
8
+ * ```
9
+ * // Setup
10
+ * const viewer1 = new Viewer('cesiumContainer1');
11
+ * const viewer2 = new Viewer('cesiumContainer2');
12
+ *
13
+ * const highlighter1 = Highlight.getInstance(viewer1);
14
+ * const highlighter2 = Highlight.getInstance(viewer2);
15
+ *
16
+ * // This highlight only affects viewer1
17
+ * highlighter1.show(someEntity, { color: Color.RED });
18
+ *
19
+ * // This highlight only affects viewer2
20
+ * highlighter2.show(someEntity, { color: Color.BLUE });
21
+ *
22
+ * // When done with viewers
23
+ * Highlight.releaseInstance(viewer1);
24
+ * Highlight.releaseInstance(viewer2);
25
+ * viewer1.destroy();
26
+ * viewer2.destroy();
27
+ * ```
28
+ */
29
+ declare class Highlight {
30
+ private static instances;
31
+ private _surface;
32
+ private _silhouette;
33
+ private _color;
34
+ /**
35
+ * Creates a new `Highlight` instance.
36
+ * @private Use {@link getInstance `Highlight.getInstance()`}
37
+ * @param viewer A viewer to create highlight entity in
38
+ */
39
+ private constructor();
40
+ /**
41
+ * Gets or creates highlight instance from a viewer.
42
+ * @param viewer The viewer to get or create a new instance from.
43
+ */
44
+ static getInstance(viewer: Viewer): Highlight;
45
+ /**
46
+ * Releases the highlight instance associated with a viewer.
47
+ * @param viewer The viewer whose highlight instance should be released.
48
+ */
49
+ static releaseInstance(viewer: Viewer): void;
50
+ /**
51
+ * Highlights a picked object or a direct instance.
52
+ * @param picked The result of `Scene.pick()` or direct instance to be highlighted.
53
+ * @param options Optional style for the highlight.
54
+ * @see {@link Highlight.Options}
55
+ */
56
+ show(picked: Highlight.Picked, options?: Highlight.Options): void | Entity;
57
+ private _getObject;
58
+ /**
59
+ * Clears the current highlight effects.
60
+ */
61
+ hide(): void;
62
+ /** Gets the highlight color. */
63
+ get color(): Color;
64
+ /**
65
+ * Sets the highlight color.
66
+ * @param color The new color for highlights
67
+ */
68
+ set color(color: Color);
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
+ }
96
+
97
+ /**
98
+ * @class
99
+ * An implementation for highlighting 3D objects in Cesium.
100
+ *
101
+ * **Supported Object Types:**
102
+ * - `Entity` with model graphics. (adjustable outline width)
103
+ * - `Cesium3DTileset` instances. (fixed outline width)
104
+ *
105
+ * Currently supports outline style only.
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * const viewer = new Viewer("cesiumContainer");
110
+ * const silhouetteHighlight = new SilhouetteHighlight(viewer);
111
+ *
112
+ * // Highlight an object
113
+ * const entity = viewer.entities.add(new Entity({
114
+ * model: new ModelGraphics(),
115
+ * }));
116
+ * silhouetteHighlight.show(entity);
117
+ * ```
118
+ */
119
+ declare class SilhouetteHighlight implements Highlight.Base {
120
+ private _color;
121
+ private _silhouette;
122
+ private _composite;
123
+ private _stages;
124
+ private _entity?;
125
+ private _currentObject;
126
+ private _currentOptions;
127
+ /**
128
+ * Creates a new `Silhouette` instance.
129
+ * @param viewer A viewer to create highlight silhouette in
130
+ */
131
+ constructor(viewer: Viewer);
132
+ /**
133
+ * Highlights a picked `Cesium3DTileset` by updating silhouette composite.
134
+ * @param object The object to be highlighted.
135
+ * @param options Optional style for the highlight.
136
+ */
137
+ show(object: Cesium3DTileFeature, options?: Highlight.Options): void;
138
+ /**
139
+ * Highlights a picked `Entity` by updating the model properties.
140
+ * @param object The object to be highlighted.
141
+ * @param options Optional style for the highlight.
142
+ */
143
+ show(object: Entity, options?: Highlight.Options): void;
144
+ /**
145
+ * Compares two Highlight.Options objects for equality
146
+ * @private
147
+ */
148
+ private _optionsEqual;
149
+ /**
150
+ * Clears all current highlights
151
+ * @private
152
+ */
153
+ private _clearHighlights;
154
+ /** Clears the current highlight */
155
+ hide(): void;
156
+ /** Clean up the instances */
157
+ destroy(): void;
158
+ /** Gets the highlight color. */
159
+ get color(): Color;
160
+ /** Sets the highlight color. */
161
+ set color(color: Color);
162
+ /** Gets the currently highlighted object */
163
+ get currentObject(): Cesium3DTileFeature | Entity | undefined;
164
+ }
165
+
166
+ /**
167
+ * @class
168
+ * A flyweight implementation for highlighting 2D surface objects in Cesium.
169
+ *
170
+ * This class provides highlighting for ground-clamped geometries (polygons, polylines, rectangles)
171
+ *
172
+ * **Supported Geometry Types:**
173
+ * - `Entity` with polygon, polyline, or rectangle graphics
174
+ * - `GroundPrimitive` instances
175
+ *
176
+ * **Highlighting Modes:**
177
+ * - **Fill mode** (default): Creates a filled geometry using the original shape
178
+ * - **Outline mode**: Creates a polyline outline of the original geometry
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * // Basic usage
183
+ * const viewer = new Viewer('cesiumContainer');
184
+ * const surfaceHighlight = new SurfaceHighlight(viewer);
185
+ *
186
+ * // Highlight an entity with default red fill
187
+ * const entity = viewer.entities.add(new Entity({
188
+ * polygon: {
189
+ * hierarchy: Cartesian3.fromDegreesArray([-75, 35, -74, 35, -74, 36, -75, 36]),
190
+ * material: Color.BLUE
191
+ * }
192
+ * }));
193
+ * surfaceHighlight.show(entity);
194
+ * ```
195
+ */
196
+ declare class SurfaceHighlight implements Highlight.Base {
197
+ private _color;
198
+ private _entity;
199
+ private _entities;
200
+ private _currentObject;
201
+ private _currentOptions;
202
+ /**
203
+ * Creates a new `SurfaceHighlight` instance.
204
+ * @param viewer A viewer to create highlight entity in
205
+ */
206
+ constructor(viewer: Viewer);
207
+ /**
208
+ * Highlights a picked object by updating the reusable entity
209
+ * @param object The object to be highlighted.
210
+ * @param options Optional style for the highlight.
211
+ * @see {@link Highlight.Options}
212
+ */
213
+ show(object: Entity | GroundPrimitive, options?: Highlight.Options): Entity | undefined;
214
+ /**
215
+ * Compares two Highlight.Options objects for equality
216
+ * @private
217
+ */
218
+ private _optionsEqual;
219
+ /**
220
+ * Removes all geometry properties from the highlight entity
221
+ * @private
222
+ */
223
+ private _clearGeometries;
224
+ /**
225
+ * Updates the highlight entity from an Entity object
226
+ * @private
227
+ */
228
+ private _update;
229
+ /**
230
+ * Clears the current highlight
231
+ */
232
+ hide(): void;
233
+ /** Clean up the instances */
234
+ destroy(): void;
235
+ /** Gets the highlight color. */
236
+ get color(): Color;
237
+ /** Sets the highlight color. */
238
+ set color(color: Color);
239
+ /** Gets the highlight entity */
240
+ get entity(): Entity;
241
+ /** Gets the currently highlighted object */
242
+ get currentObject(): Entity | GroundPrimitive | undefined;
243
+ }
244
+
245
+ export { Highlight, SilhouetteHighlight, SurfaceHighlight };
@@ -0,0 +1 @@
1
+ import{a,b,c}from"../chunk-RZ3PTU3G.js";export{c as Highlight,a as SilhouetteHighlight,b as SurfaceHighlight};