@juun-roh/cesium-utils
Version:
Utilities to handle Cesium classes easier.
226 lines (220 loc) • 7.2 kB
TypeScript
export { CesiumCollection, CesiumCollectionItem, Collection, CollectionEventType, EventHandler, NonFunction, Tag, WithTag } from './collection/index.js';
import { Entity, Cesium3DTileFeature, GroundPrimitive, Primitive, Model, Cesium3DTileset, Color, Viewer } from 'cesium';
export { H as HybridTerrainProvider, T as TerrainArea, a as TileRange } from './hybrid-terrain-provider-C4b9z5pv.js';
export { TerrainAreaCollection, computeRectangle } from './terrain/index.js';
export { TerrainVisualizer, isGetterOnly } from './utils/index.js';
export { cloneViewer, syncCamera } from './viewer/index.js';
interface IHighlight {
show(object: any, options?: HighlightOptions): void;
hide(): void;
destroy(): void;
color: Color;
}
interface HighlightOptions {
/** Color of the highlight */
color?: Color;
/** To apply outline style for the highlight */
outline?: boolean;
/** Outline width */
width?: number;
}
type PickedObject = {
id?: Entity;
primitive?: Primitive | GroundPrimitive | Model | Cesium3DTileset;
tileset?: Cesium3DTileset;
detail?: {
model?: Model;
};
};
type Picked = Entity | Cesium3DTileFeature | GroundPrimitive | PickedObject;
/**
* @class
* Lightweight multiton highlight manager for Cesium using flyweight pattern.
*
* @example
* ```
* // Setup
* const viewer1 = new Viewer('cesiumContainer1');
* const viewer2 = new Viewer('cesiumContainer2');
*
* const highlighter1 = Highlight.getInstance(viewer1);
* const highlighter2 = Highlight.getInstance(viewer2);
*
* // This highlight only affects viewer1
* highlighter1.show(someEntity, { color: Color.RED });
*
* // This highlight only affects viewer2
* highlighter2.show(someEntity, { color: Color.BLUE });
*
* // When done with viewers
* Highlight.releaseInstance(viewer1);
* Highlight.releaseInstance(viewer2);
* viewer1.destroy();
* viewer2.destroy();
* ```
*/
declare class Highlight {
private static instances;
private _surface;
private _silhouette;
private _color;
/**
* Creates a new `Highlight` instance.
* @private Use {@link getInstance `Highlight.getInstance()`}
* @param viewer A viewer to create highlight entity in
*/
private constructor();
/**
* Gets or creates highlight instance from a viewer.
* @param viewer The viewer to get or create a new instance from.
*/
static getInstance(viewer: Viewer): Highlight;
/**
* Releases the highlight instance associated with a viewer.
* @param viewer The viewer whose highlight instance should be released.
*/
static releaseInstance(viewer: Viewer): void;
/**
* Highlights a picked object or a direct instance.
* @param picked The result of `Scene.pick()` or direct instance to be highlighted.
* @param options Optional style for the highlight.
* @see {@link HighlightOptions}
*/
show(picked: Picked, options?: HighlightOptions): void | Entity;
private _getObject;
/**
* Clears the current highlight effects.
*/
hide(): void;
/** Gets the highlight color. */
get color(): Color;
/**
* Sets the highlight color.
* @param color The new color for highlights
*/
set color(color: Color);
}
/**
* @class
* An implementation for highlighting 3D objects in Cesium.
*
* **Supported Object Types:**
* - `Entity` with model graphics. (adjustable outline width)
* - `Cesium3DTileset` instances. (fixed outline width)
*
* Currently supports outline style only.
*
* @example
* ```typescript
* const viewer = new Viewer("cesiumContainer");
* const silhouetteHighlight = new SilhouetteHighlight(viewer);
*
* // Highlight an object
* const entity = viewer.entities.add(new Entity({
* model: new ModelGraphics(),
* }));
* silhouetteHighlight.show(entity);
* ```
*/
declare class SilhouetteHighlight implements IHighlight {
private _color;
private _silhouette;
private _composite;
private _stages;
private _entity?;
/**
* Creates a new `Silhouette` instance.
* @param viewer A viewer to create highlight silhouette in
*/
constructor(viewer: Viewer);
/**
* Highlights a picked `Cesium3DTileset` by updating silhouette composite.
* @param object The object to be highlighted.
* @param options Optional style for the highlight.
*/
show(object: Cesium3DTileFeature, options?: HighlightOptions): void;
/**
* Highlights a picked `Entity` by updating the model properties.
* @param object The object to be highlighted.
* @param options Optional style for the highlight.
*/
show(object: Entity, options?: HighlightOptions): void;
/** Clears the current highlight */
hide(): void;
/** Clean up the instances */
destroy(): void;
/** Gets the highlight color. */
get color(): Color;
/** Sets the highlight color. */
set color(color: Color);
}
/**
* @class
* A flyweight implementation for highlighting 2D surface objects in Cesium.
*
* This class provides highlighting for ground-clamped geometries (polygons, polylines, rectangles)
*
* **Supported Geometry Types:**
* - `Entity` with polygon, polyline, or rectangle graphics
* - `GroundPrimitive` instances
*
* **Highlighting Modes:**
* - **Fill mode** (default): Creates a filled geometry using the original shape
* - **Outline mode**: Creates a polyline outline of the original geometry
*
* @example
* ```typescript
* // Basic usage
* const viewer = new Viewer('cesiumContainer');
* const surfaceHighlight = new SurfaceHighlight(viewer);
*
* // Highlight an entity with default red fill
* const entity = viewer.entities.add(new Entity({
* polygon: {
* hierarchy: Cartesian3.fromDegreesArray([-75, 35, -74, 35, -74, 36, -75, 36]),
* material: Color.BLUE
* }
* }));
* surfaceHighlight.show(entity);
* ```
*/
declare class SurfaceHighlight implements IHighlight {
private _color;
private _entity;
private _entities;
/**
* Creates a new `SurfaceHighlight` instance.
* @param viewer A viewer to create highlight entity in
*/
constructor(viewer: Viewer);
/**
* Highlights a picked object by updating the reusable entity
* @param object The object to be highlighted.
* @param options Optional style for the highlight.
* @see {@link HighlightOptions}
*/
show(object: Entity | GroundPrimitive, options?: HighlightOptions): Entity | undefined;
/**
* Removes all geometry properties from the highlight entity
* @private
*/
private _clearGeometries;
/**
* Updates the highlight entity from an Entity object
* @private
*/
private _update;
/**
* Clears the current highlight
*/
hide(): void;
/** Clean up the instances */
destroy(): void;
/** Gets the highlight color. */
get color(): Color;
/** Sets the highlight color. */
set color(color: Color);
/** Gets the highlight entity */
get entity(): Entity;
}
export { Highlight, type HighlightOptions, type IHighlight, type Picked, type PickedObject, SilhouetteHighlight, SurfaceHighlight };