@juun-roh/cesium-utils 0.0.11 → 0.0.13

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 @@
1
+ import{Viewer as w}from"cesium";import{defined as f}from"cesium";function d(t,i){if(f(t)&&f(i)){let{camera:n}=t;i.camera.position=n.positionWC.clone(),i.camera.direction=n.directionWC.clone(),i.camera.up=n.upWC.clone()}}function _(t,i,n){let o={baseLayerPicker:t.baseLayerPicker!==void 0,geocoder:t.geocoder!==void 0,homeButton:t.homeButton!==void 0,sceneModePicker:t.sceneModePicker!==void 0,timeline:t.timeline!==void 0,navigationHelpButton:t.navigationHelpButton!==void 0,animation:t.animation!==void 0,fullscreenButton:t.fullscreenButton!==void 0,shouldAnimate:t.clock.shouldAnimate,terrainProvider:t.terrainProvider,requestRenderMode:t.scene.requestRenderMode,infoBox:t.infoBox!==void 0},e=new w(i,{...o,...n});d(t,e);let a=t.imageryLayers;e.imageryLayers.removeAll();for(let r=0;r<a.length;r++){let E=a.get(r);e.imageryLayers.addImageryProvider(E.imageryProvider,r)}e.clock.startTime=t.clock.startTime.clone(),e.clock.stopTime=t.clock.stopTime.clone(),e.clock.currentTime=t.clock.currentTime.clone(),e.clock.multiplier=t.clock.multiplier,e.clock.clockStep=t.clock.clockStep,e.clock.clockRange=t.clock.clockRange,e.clock.shouldAnimate=t.clock.shouldAnimate,e.scene.globe.enableLighting=t.scene.globe.enableLighting,e.scene.globe.depthTestAgainstTerrain=t.scene.globe.depthTestAgainstTerrain,e.scene.screenSpaceCameraController.enableCollisionDetection=t.scene.screenSpaceCameraController.enableCollisionDetection;let l=t.scene.screenSpaceCameraController.tiltEventTypes;l&&(e.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(l)?[...l]:l);let s=t.scene.screenSpaceCameraController.zoomEventTypes;return s&&(e.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(s)?[...s]:s),e}import{Cartesian3 as h,ClassificationType as m,Color as v,defined as T,Entity as c,GroundPrimitive as u,HeightReference as p,PolygonGraphics as C,PolygonHierarchy as V,PolylineGraphics as g,RectangleGraphics as R}from"cesium";var y=class t{static instances=new Map;_defaultColor=v.YELLOW.withAlpha(.5);_highlightEntity;_viewerEntities;constructor(i){this._viewerEntities=i.entities,this._highlightEntity=this._viewerEntities.add(new c({id:`highlight-entity-${Math.random().toString(36).substring(2)}`,show:!1}))}static getInstance(i){let n=i.container;return t.instances.has(n)||t.instances.set(n,new t(i)),t.instances.get(n)}static releaseInstance(i){let n=i.container,o=t.instances.get(n);o&&(o.hide(),o._highlightEntity&&i.entities.remove(o._highlightEntity),t.instances.delete(n))}show(i,n=this._defaultColor,o=!1){if(!(!T(i)||!this._highlightEntity)){this._clearGeometries();try{if(i instanceof c)this._update(i,n,o);else if(i.id instanceof c)this._update(i.id,n,o);else if(i.primitive instanceof u)this._update(i.primitive,n,o);else return;return this._highlightEntity.show=!0,this._highlightEntity}catch(e){console.error("Failed to highlight object:",e);return}}}_clearGeometries(){this._highlightEntity&&(this._highlightEntity.polygon=void 0,this._highlightEntity.polyline=void 0,this._highlightEntity.rectangle=void 0)}_update(i,n,o){if(this._highlightEntity){if(i instanceof c){if(i.polygon)if(o){let e=i.polygon.hierarchy?.getValue();if(e&&e.positions){let a;e.positions.length>0&&!h.equals(e.positions[0],e.positions[e.positions.length-1])?a=[...e.positions,e.positions[0]]:a=e.positions,this._highlightEntity.polyline=new g({positions:a,material:n,width:2,clampToGround:i.polygon.heightReference?.getValue()===p.CLAMP_TO_GROUND})}}else{let e=i.polygon.hierarchy?.getValue();e&&(this._highlightEntity.polygon=new C({hierarchy:e,material:n,heightReference:i.polygon.heightReference?.getValue(),classificationType:i.polygon.classificationType?.getValue()||m.BOTH}))}else if(i.polyline){let e=i.polyline.positions?.getValue();if(e){let a=i.polyline.width?.getValue()||2;this._highlightEntity.polyline=new g({positions:e,material:n,width:a+2,clampToGround:i.polyline.clampToGround?.getValue()})}}else if(i.rectangle)if(o){let e=i.rectangle.coordinates?.getValue();if(e){let a=[h.fromRadians(e.west,e.north),h.fromRadians(e.east,e.north),h.fromRadians(e.east,e.south),h.fromRadians(e.west,e.south),h.fromRadians(e.west,e.north)];this._highlightEntity.polyline=new g({positions:a,material:n,width:2,clampToGround:i.rectangle.heightReference?.getValue()===p.CLAMP_TO_GROUND})}}else{let e=i.rectangle.coordinates?.getValue();e&&(this._highlightEntity.rectangle=new R({coordinates:e,material:n,heightReference:i.rectangle.heightReference?.getValue()}))}}else if(i instanceof u){let e=i.geometryInstances,a=Array.isArray(e)?e[0]:e;if(!a||!a.geometry.attributes.position)return;let l=a.geometry.attributes.position.values,s=[];for(let r=0;r<l.length;r+=3)s.push(new h(l[r],l[r+1],l[r+2]));o?this._highlightEntity.polyline=new g({positions:s,material:n,width:2,clampToGround:!0}):this._highlightEntity.polygon=new C({hierarchy:new V(s),material:n,heightReference:p.CLAMP_TO_GROUND,classificationType:m.BOTH})}}}hide(){this._highlightEntity&&(this._highlightEntity.show=!1)}get defaultColor(){return this._defaultColor}set defaultColor(i){this._defaultColor=i}get highlightEntity(){return this._highlightEntity}};export{d as a,_ as b,y as c};
@@ -25,7 +25,7 @@ type NonFunction<T> = {
25
25
 
26
26
  /**
27
27
  * @class
28
- * Abstract class that enhances Cesium collection objects with tagging functionality.
28
+ * A wrapper class that enhances Cesium collection objects with tagging functionality.
29
29
  * This class provides a consistent API for working with different types of Cesium collections
30
30
  * and allows grouping and manipulating collection items by custom tags.
31
31
  *
@@ -25,7 +25,7 @@ type NonFunction<T> = {
25
25
 
26
26
  /**
27
27
  * @class
28
- * Abstract class that enhances Cesium collection objects with tagging functionality.
28
+ * A wrapper class that enhances Cesium collection objects with tagging functionality.
29
29
  * This class provides a consistent API for working with different types of Cesium collections
30
30
  * and allows grouping and manipulating collection items by custom tags.
31
31
  *
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var M=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var H=(n,e)=>{for(var r in e)M(n,r,{get:e[r],enumerable:!0})},B=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of F(e))!Y.call(n,i)&&i!==r&&M(n,i,{get:()=>e[i],enumerable:!(t=j(e,i))||t.enumerable});return n};var q=n=>B(M({},"__esModule",{value:!0}),n);var W={};H(W,{Collection:()=>y,HybridTerrainProvider:()=>w,TerrainArea:()=>h,TerrainAreaCollection:()=>f,TerrainVisualizer:()=>v,cloneViewer:()=>S,computeRectangle:()=>A,isGetterOnly:()=>_,syncCamera:()=>C});module.exports=q(W);var b=require("cesium");var l=require("cesium");var v=class n{_viewer;_collection;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",l.Color.RED],["default",l.Color.BLUE],["fallback",l.Color.GRAY],["grid",l.Color.YELLOW]]);constructor(e,r){this._viewer=e,this._collection=new y({collection:e.entities,tag:n.tag.default}),r&&(r.colors&&Object.entries(r.colors).forEach(([t,i])=>{this._colors.set(t,i)}),r.tile!==void 0&&(this._visible=r.tile),r.activeLevel!==void 0&&(this._level=r.activeLevel),r.terrainProvider&&this.setTerrainProvider(r.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(n.tag.grid),this._level=e;let r=this._terrainProvider.tilingScheme;this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new l.TileCoordinatesImageryProvider({tilingScheme:r,color:l.Color.YELLOW})));let t=(a,s,c)=>{if(this._terrainProvider){for(let d of this._terrainProvider.terrainAreas)if(d.contains(a,s,c))return d.isCustom?this._colors.get("custom")||l.Color.RED:this._colors.get("default")||l.Color.BLUE;if(this._terrainProvider.getTileDataAvailable(a,s,c))return this._colors.get("default")||l.Color.BLUE}return this._colors.get("fallback")||l.Color.TRANSPARENT},i=this._getVisibleRectangle();if(!i)return;function o(a){return a&&Number.isFinite(a.west)&&Number.isFinite(a.south)&&Number.isFinite(a.east)&&Number.isFinite(a.north)&&a.west<=a.east&&a.south<=a.north}if(!o(i)){console.warn("Invalid visible rectangle detected, skipping grid display");return}try{let a=r.positionToTileXY(l.Rectangle.northwest(i),e),s=r.positionToTileXY(l.Rectangle.southeast(i),e);if(!a||!s)return;let c=100,d=Math.min(s.x-a.x+1,c),p=Math.min(s.y-a.y+1,c);for(let m=a.x;m<=a.x+d-1;m++)for(let u=a.y;u<=a.y+p-1;u++)try{let g=r.tileXYToRectangle(m,u,e);if(!o(g)){console.warn(`Invalid rectangle for tile (${m}, ${u}, ${e}), skipping`);continue}let R=t(m,u,e),T=n.createRectangle(g,R.withAlpha(.3));T.properties?.addProperty("tileX",m),T.properties?.addProperty("tileY",u),T.properties?.addProperty("tileLevel",e),this._collection.add(T,n.tag.grid)}catch(g){console.warn(`Error creating tile (${m}, ${u}, ${e}): ${g.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(a){console.error("Error displaying tile grid:",a)}}hide(){this._collection.remove(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([r,t])=>{this._colors.set(r,t)}),this.update()}flyTo(e,r){let{rectangle:t}=e;this._viewer.camera.flyTo({destination:t,...r,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}};(t=>{t.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(i,o){return new l.Entity({rectangle:{coordinates:i,material:o,heightReference:l.HeightReference.CLAMP_TO_GROUND}})}t.createRectangle=e;function r(i,o,a){let s=a?.tag||"terrain_area_visualization",c=a?.color||l.Color.RED,d=a?.maxTilesToShow||100,p=a?.show??!0,m=a?.alpha||.7,u=a?.tileAlpha||.2,g=new y({collection:o.entities,tag:s}),{rectangle:R}=i;if(g.add(t.createRectangle(R,c.withAlpha(m)),s),p&&i.tileRanges.size>0){let{tilingScheme:T}=i.terrainProvider,I=0;i.tileRanges.forEach((P,G)=>{for(let E=P.start.x;E<=P.end.x&&I<d;E++)for(let x=P.start.y;x<=P.end.y&&I<d;x++){let z=T.tileXYToRectangle(E,x,G);g.add(e(z,c.withAlpha(u)),`${s}_tile`),I++}})}return g}t.visualize=r})(v||={});function _(n,e){let r=!1,t=Object.getOwnPropertyDescriptor(n,e);if(!t){let i=Object.getPrototypeOf(n);for(;i&&!t;)t=Object.getOwnPropertyDescriptor(i,e),i=Object.getPrototypeOf(i)}return t&&t.get&&!t.set&&(r=!0),r}var L=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:r}){this.tag=r||"default",this.collection=e}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,r){let t=this._eventListeners.get(e);if(t){let i={type:e,...r};t.forEach(o=>o(i))}}_addToTagMap(e,r){this._tagMap.has(r)||this._tagMap.set(r,new Set),this._tagMap.get(r)?.add(e)}_removeFromTagMap(e){let r=e[n.symbol],t=this._tagMap.get(r);t&&(t.delete(e),t.size===0&&this._tagMap.delete(r))}_invalidateCache(){this._valuesCache=null}addEventListener(e,r){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(r),this}removeEventListener(e,r){return this._eventListeners.get(e)?.delete(r),this}add(e,r=this.tag,t){return Array.isArray(e)?e.forEach(i=>{this.add(i,r)}):(Object.defineProperty(e,n.symbol,{value:r,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,t),this._addToTagMap(e,r),this._invalidateCache(),this._emit("add",{items:[e],tag:r})),e}contains(e){if(typeof e=="object")return this.collection.contains(e);let r=this._tagMap.get(e);return!!r&&r.size>0}remove(e){if(typeof e=="object"&&!Array.isArray(e)){let i=this.collection.remove(e);return i&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),i}if(Array.isArray(e)){if(e.length===0)return!1;let i=!1;for(let o of e)this.remove(o)&&(i=!0);return i}let r=this.get(e);if(r.length===0)return!1;let t=!1;for(let i of r)this.remove(i)&&(t=!0);return t}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof b.EntityCollection)return this.collection.values;{let e=[];for(let r=0;r<this.collection.length;r++)e.push(this.collection.get(r));return e}}get length(){return this.values?.length||0}get(e){let r=this._tagMap.get(e);return r?Array.from(r):[]}first(e){let r=this._tagMap.get(e);if(r&&r.size>0)return r.values().next().value}get tags(){return Array.from(this._tagMap.keys())}update(e,r){let t=this.get(e);for(let i of t)this._removeFromTagMap(i),Object.defineProperty(i,n.symbol,{value:r,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(i,r);return t.length>0&&this._emit("update",{items:t,tag:r}),t.length}show(e){let r=this.get(e);for(let t of r)(0,b.defined)(t.show)&&(t.show=!0);return this}hide(e){let r=this.get(e);for(let t of r)(0,b.defined)(t.show)&&(t.show=!1);return this}toggle(e){let r=this.get(e);for(let t of r)(0,b.defined)(t.show)&&(t.show=!t.show);return this}setProperty(e,r,t=this.tag){let i=this.get(t);for(let o of i)if(e in o&&typeof o[e]!="function"){if(_(o,e))throw Error(`setProperty(${o}, ${e}) failed; The property is readonly.`);o[e]=r}return this}filter(e,r){return(r?this.get(r):this.values).filter(e)}forEach(e,r){(r?this.get(r):this.values).forEach((i,o)=>e(i,o))}map(e,r){return(r?this.get(r):this.values).map(e)}find(e,r){return(r?this.get(r):this.values).find(e)}},y=L;var N=require("cesium");var V=require("cesium");var O=require("cesium");function A(n,e){if(e.size===0)return new O.Rectangle;let r=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,a=Array.from(e.keys()),s=Math.min(...a),c=e.get(s);if(c){let{start:d,end:p}=c,m=n.tileXYToRectangle(d.x,d.y,s),u=n.tileXYToRectangle(p.x,p.y,s);r=Math.min(m.west,r),t=Math.min(u.south,t),i=Math.max(u.east,i),o=Math.max(m.north,o)}return new O.Rectangle(r,t,i,o)}var h=class{_terrainProvider;_rectangle;_tileRanges;_ready=!1;_credit;_isCustom;constructor(e){this._terrainProvider=e.terrainProvider,this._tileRanges=e.tileRanges,this._credit=e.credit||"custom",this._isCustom=e.isCustom!==void 0?e.isCustom:!0,this._rectangle=A(e.terrainProvider.tilingScheme,e.tileRanges),e.tileRanges.forEach((r,t)=>{this._terrainProvider.availability?.addAvailableTileRange(t,r.start.x,r.start.y,r.end.x,r.end.y)}),this._ready=!0}contains(e,r,t){if(this._tileRanges.size===0||!this._tileRanges.has(t))return!1;let i=this._tileRanges.get(t);return e>=i.start.x&&e<=i.end.x&&r>=i.start.y&&r<=i.end.y}requestTileGeometry(e,r,t,i){if(!(!this._ready||!this.contains(e,r,t)))return this._terrainProvider.requestTileGeometry(e,r,t,i)}getTileDataAvailable(e,r,t){if(this._tileRanges.size===0||!this._tileRanges.has(t))return!1;let i=this._tileRanges.get(t);return e>=i.start.x&&e<=i.end.x&&r>=i.start.y&&r<=i.end.y}get isCustom(){return this._isCustom}get credit(){return this._credit}get terrainProvider(){return this._terrainProvider}get tileRanges(){return this._tileRanges}get rectangle(){return this._rectangle}get ready(){return this._ready}};(e=>{async function n(r,t,i){let o=i?.credit||"custom",a=await V.CesiumTerrainProvider.fromUrl(r,{...i,credit:o});return new e({terrainProvider:a,tileRanges:t,credit:o})}e.fromUrl=n})(h||={});var f=class extends Array{add(e){if(Array.isArray(e)){for(let t of e)this.add(t);return this.length}let r;return e instanceof h?r=e:r=new h(e),this.push(r)}remove(e){if(Array.isArray(e))return e.forEach(t=>this.remove(t)),this;let r=this.indexOf(e);return r>=0&&this.splice(r,1),this}removeAll(){this.length=0}};var w=class{_terrainAreas=new f;_terrainProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(e){this._terrainProvider=e.terrainProvider,this._fallbackProvider=e.fallbackProvider||new N.EllipsoidTerrainProvider,this._tilingScheme=e.terrainProvider.tilingScheme,this._terrainAreas=new f(...e.terrainAreas),this._availability=e.terrainProvider.availability,this._ready=!0}get ready(){return this._ready}get tilingScheme(){return this._tilingScheme}get availability(){return this._availability}get terrainAreas(){return[...this._terrainAreas]}get defaultProvider(){return this._terrainProvider}get fallbackProvider(){return this._fallbackProvider}get credit(){return this._terrainProvider?.credit}get errorEvent(){return this._terrainProvider.errorEvent}get hasWaterMask(){return this._terrainProvider.hasWaterMask}get hasVertexNormals(){return this._terrainProvider.hasVertexNormals}loadTileDataAvailability(e,r,t){return this._terrainProvider.loadTileDataAvailability(e,r,t)}getLevelMaximumGeometricError(e){return this._terrainProvider.getLevelMaximumGeometricError(e)}requestTileGeometry(e,r,t,i){if(this._ready){for(let o of this._terrainAreas)if(o.contains(e,r,t))return o.requestTileGeometry(e,r,t,i);return this._terrainProvider.getTileDataAvailable(e,r,t)?this._terrainProvider.requestTileGeometry(e,r,t,i):this._fallbackProvider.requestTileGeometry(e,r,t,i)}}getTileDataAvailable(e,r,t){for(let i of this._terrainAreas)if(i.contains(e,r,t))return i.getTileDataAvailable(e,r,t);return this._terrainProvider.getTileDataAvailable(e,r,t)}};var D=require("cesium");var k=require("cesium");function C(n,e){if((0,k.defined)(n)&&(0,k.defined)(e)){let{camera:r}=n;e.camera.position=r.positionWC.clone(),e.camera.direction=r.directionWC.clone(),e.camera.up=r.upWC.clone()}}function S(n,e,r){let t={baseLayerPicker:n.baseLayerPicker!==void 0,geocoder:n.geocoder!==void 0,homeButton:n.homeButton!==void 0,sceneModePicker:n.sceneModePicker!==void 0,timeline:n.timeline!==void 0,navigationHelpButton:n.navigationHelpButton!==void 0,animation:n.animation!==void 0,fullscreenButton:n.fullscreenButton!==void 0,shouldAnimate:n.clock.shouldAnimate,terrainProvider:n.terrainProvider,requestRenderMode:n.scene.requestRenderMode,infoBox:n.infoBox!==void 0},i=new D.Viewer(e,{...t,...r});C(n,i);let o=n.imageryLayers;i.imageryLayers.removeAll();for(let c=0;c<o.length;c++){let d=o.get(c);i.imageryLayers.addImageryProvider(d.imageryProvider,c)}i.clock.startTime=n.clock.startTime.clone(),i.clock.stopTime=n.clock.stopTime.clone(),i.clock.currentTime=n.clock.currentTime.clone(),i.clock.multiplier=n.clock.multiplier,i.clock.clockStep=n.clock.clockStep,i.clock.clockRange=n.clock.clockRange,i.clock.shouldAnimate=n.clock.shouldAnimate,i.scene.globe.enableLighting=n.scene.globe.enableLighting,i.scene.globe.depthTestAgainstTerrain=n.scene.globe.depthTestAgainstTerrain,i.scene.screenSpaceCameraController.enableCollisionDetection=n.scene.screenSpaceCameraController.enableCollisionDetection;let a=n.scene.screenSpaceCameraController.tiltEventTypes;a&&(i.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(a)?[...a]:a);let s=n.scene.screenSpaceCameraController.zoomEventTypes;return s&&(i.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(s)?[...s]:s),i}
1
+ "use strict";var M=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var W=(n,e)=>{for(var t in e)M(n,t,{get:e[t],enumerable:!0})},q=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Y(e))!B.call(n,i)&&i!==t&&M(n,i,{get:()=>e[i],enumerable:!(r=F(e,i))||r.enumerable});return n};var $=n=>q(M({},"__esModule",{value:!0}),n);var U={};W(U,{Collection:()=>b,Highlight:()=>w,HybridTerrainProvider:()=>R,TerrainArea:()=>m,TerrainAreaCollection:()=>v,TerrainVisualizer:()=>p,cloneViewer:()=>k,computeRectangle:()=>E,isGetterOnly:()=>C,syncCamera:()=>P});module.exports=$(U);var _=require("cesium");var h=require("cesium");var p=class n{_viewer;_collection;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",h.Color.RED],["default",h.Color.BLUE],["fallback",h.Color.GRAY],["grid",h.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new b({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([r,i])=>{this._colors.set(r,i)}),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(n.tag.grid),this._level=e;let t=this._terrainProvider.tilingScheme;this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new h.TileCoordinatesImageryProvider({tilingScheme:t,color:h.Color.YELLOW})));let r=(a,l,c)=>{if(this._terrainProvider){for(let d of this._terrainProvider.terrainAreas)if(d.contains(a,l,c))return d.isCustom?this._colors.get("custom")||h.Color.RED:this._colors.get("default")||h.Color.BLUE;if(this._terrainProvider.getTileDataAvailable(a,l,c))return this._colors.get("default")||h.Color.BLUE}return this._colors.get("fallback")||h.Color.TRANSPARENT},i=this._getVisibleRectangle();if(!i)return;function o(a){return a&&Number.isFinite(a.west)&&Number.isFinite(a.south)&&Number.isFinite(a.east)&&Number.isFinite(a.north)&&a.west<=a.east&&a.south<=a.north}if(!o(i)){console.warn("Invalid visible rectangle detected, skipping grid display");return}try{let a=t.positionToTileXY(h.Rectangle.northwest(i),e),l=t.positionToTileXY(h.Rectangle.southeast(i),e);if(!a||!l)return;let c=100,d=Math.min(l.x-a.x+1,c),y=Math.min(l.y-a.y+1,c);for(let u=a.x;u<=a.x+d-1;u++)for(let g=a.y;g<=a.y+y-1;g++)try{let f=t.tileXYToRectangle(u,g,e);if(!o(f)){console.warn(`Invalid rectangle for tile (${u}, ${g}, ${e}), skipping`);continue}let I=r(u,g,e),T=n.createRectangle(f,I.withAlpha(.3));T.properties?.addProperty("tileX",u),T.properties?.addProperty("tileY",g),T.properties?.addProperty("tileLevel",e),this._collection.add(T,n.tag.grid)}catch(f){console.warn(`Error creating tile (${u}, ${g}, ${e}): ${f.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(a){console.error("Error displaying tile grid:",a)}}hide(){this._collection.remove(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,r])=>{this._colors.set(t,r)}),this.update()}flyTo(e,t){let{rectangle:r}=e;this._viewer.camera.flyTo({destination:r,...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}};(r=>{r.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(i,o){return new h.Entity({rectangle:{coordinates:i,material:o,heightReference:h.HeightReference.CLAMP_TO_GROUND}})}r.createRectangle=e;function t(i,o,a){let l=a?.tag||"terrain_area_visualization",c=a?.color||h.Color.RED,d=a?.maxTilesToShow||100,y=a?.show??!0,u=a?.alpha||.7,g=a?.tileAlpha||.2,f=new b({collection:o.entities,tag:l}),{rectangle:I}=i;if(f.add(r.createRectangle(I,c.withAlpha(u)),l),y&&i.tileRanges.size>0){let{tilingScheme:T}=i.terrainProvider,x=0;i.tileRanges.forEach((A,z)=>{for(let V=A.start.x;V<=A.end.x&&x<d;V++)for(let O=A.start.y;O<=A.end.y&&x<d;O++){let j=T.tileXYToRectangle(V,O,z);f.add(e(j,c.withAlpha(g)),`${l}_tile`),x++}})}return f}r.visualize=t})(p||={});function C(n,e){let t=!1,r=Object.getOwnPropertyDescriptor(n,e);if(!r){let i=Object.getPrototypeOf(n);for(;i&&!r;)r=Object.getOwnPropertyDescriptor(i,e),i=Object.getPrototypeOf(i)}return r&&r.get&&!r.set&&(t=!0),t}var L=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let r=this._eventListeners.get(e);if(r){let i={type:e,...t};r.forEach(o=>o(i))}}_addToTagMap(e,t){this._tagMap.has(t)||this._tagMap.set(t,new Set),this._tagMap.get(t)?.add(e)}_removeFromTagMap(e){let t=e[n.symbol],r=this._tagMap.get(t);r&&(r.delete(e),r.size===0&&this._tagMap.delete(t))}_invalidateCache(){this._valuesCache=null}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,r){return Array.isArray(e)?e.forEach(i=>{this.add(i,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,r),this._addToTagMap(e,t),this._invalidateCache(),this._emit("add",{items:[e],tag:t})),e}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)){let i=this.collection.remove(e);return i&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),i}if(Array.isArray(e)){if(e.length===0)return!1;let i=!1;for(let o of e)this.remove(o)&&(i=!0);return i}let t=this.get(e);if(t.length===0)return!1;let r=!1;for(let i of t)this.remove(i)&&(r=!0);return r}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof _.EntityCollection)return this.collection.values;{let e=[];for(let t=0;t<this.collection.length;t++)e.push(this.collection.get(t));return e}}get length(){return this.values?.length||0}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}get tags(){return Array.from(this._tagMap.keys())}update(e,t){let r=this.get(e);for(let i of r)this._removeFromTagMap(i),Object.defineProperty(i,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(i,t);return r.length>0&&this._emit("update",{items:r,tag:t}),r.length}show(e){let t=this.get(e);for(let r of t)(0,_.defined)(r.show)&&(r.show=!0);return this}hide(e){let t=this.get(e);for(let r of t)(0,_.defined)(r.show)&&(r.show=!1);return this}toggle(e){let t=this.get(e);for(let r of t)(0,_.defined)(r.show)&&(r.show=!r.show);return this}setProperty(e,t,r=this.tag){let i=this.get(r);for(let o of i)if(e in o&&typeof o[e]!="function"){if(C(o,e))throw Error(`setProperty(${o}, ${e}) failed; The property is readonly.`);o[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((i,o)=>e(i,o))}map(e,t){return(t?this.get(t):this.values).map(e)}find(e,t){return(t?this.get(t):this.values).find(e)}},b=L;var D=require("cesium");var N=require("cesium");var S=require("cesium");function E(n,e){if(e.size===0)return new S.Rectangle;let t=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,a=Array.from(e.keys()),l=Math.min(...a),c=e.get(l);if(c){let{start:d,end:y}=c,u=n.tileXYToRectangle(d.x,d.y,l),g=n.tileXYToRectangle(y.x,y.y,l);t=Math.min(u.west,t),r=Math.min(g.south,r),i=Math.max(g.east,i),o=Math.max(u.north,o)}return new S.Rectangle(t,r,i,o)}var m=class{_terrainProvider;_rectangle;_tileRanges;_ready=!1;_credit;_isCustom;constructor(e){this._terrainProvider=e.terrainProvider,this._tileRanges=e.tileRanges,this._credit=e.credit||"custom",this._isCustom=e.isCustom!==void 0?e.isCustom:!0,this._rectangle=E(e.terrainProvider.tilingScheme,e.tileRanges),e.tileRanges.forEach((t,r)=>{this._terrainProvider.availability?.addAvailableTileRange(r,t.start.x,t.start.y,t.end.x,t.end.y)}),this._ready=!0}contains(e,t,r){if(this._tileRanges.size===0||!this._tileRanges.has(r))return!1;let i=this._tileRanges.get(r);return e>=i.start.x&&e<=i.end.x&&t>=i.start.y&&t<=i.end.y}requestTileGeometry(e,t,r,i){if(!(!this._ready||!this.contains(e,t,r)))return this._terrainProvider.requestTileGeometry(e,t,r,i)}getTileDataAvailable(e,t,r){if(this._tileRanges.size===0||!this._tileRanges.has(r))return!1;let i=this._tileRanges.get(r);return e>=i.start.x&&e<=i.end.x&&t>=i.start.y&&t<=i.end.y}get isCustom(){return this._isCustom}get credit(){return this._credit}get terrainProvider(){return this._terrainProvider}get tileRanges(){return this._tileRanges}get rectangle(){return this._rectangle}get ready(){return this._ready}};(e=>{async function n(t,r,i){let o=i?.credit||"custom",a=await N.CesiumTerrainProvider.fromUrl(t,{...i,credit:o});return new e({terrainProvider:a,tileRanges:r,credit:o})}e.fromUrl=n})(m||={});var v=class extends Array{add(e){if(Array.isArray(e)){for(let r of e)this.add(r);return this.length}let t;return e instanceof m?t=e:t=new m(e),this.push(t)}remove(e){if(Array.isArray(e))return e.forEach(r=>this.remove(r)),this;let t=this.indexOf(e);return t>=0&&this.splice(t,1),this}removeAll(){this.length=0}};var R=class{_terrainAreas=new v;_terrainProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(e){this._terrainProvider=e.terrainProvider,this._fallbackProvider=e.fallbackProvider||new D.EllipsoidTerrainProvider,this._tilingScheme=e.terrainProvider.tilingScheme,this._terrainAreas=new v(...e.terrainAreas),this._availability=e.terrainProvider.availability,this._ready=!0}get ready(){return this._ready}get tilingScheme(){return this._tilingScheme}get availability(){return this._availability}get terrainAreas(){return[...this._terrainAreas]}get defaultProvider(){return this._terrainProvider}get fallbackProvider(){return this._fallbackProvider}get credit(){return this._terrainProvider?.credit}get errorEvent(){return this._terrainProvider.errorEvent}get hasWaterMask(){return this._terrainProvider.hasWaterMask}get hasVertexNormals(){return this._terrainProvider.hasVertexNormals}loadTileDataAvailability(e,t,r){return this._terrainProvider.loadTileDataAvailability(e,t,r)}getLevelMaximumGeometricError(e){return this._terrainProvider.getLevelMaximumGeometricError(e)}requestTileGeometry(e,t,r,i){if(this._ready){for(let o of this._terrainAreas)if(o.contains(e,t,r))return o.requestTileGeometry(e,t,r,i);return this._terrainProvider.getTileDataAvailable(e,t,r)?this._terrainProvider.requestTileGeometry(e,t,r,i):this._fallbackProvider.requestTileGeometry(e,t,r,i)}}getTileDataAvailable(e,t,r){for(let i of this._terrainAreas)if(i.contains(e,t,r))return i.getTileDataAvailable(e,t,r);return this._terrainProvider.getTileDataAvailable(e,t,r)}};var H=require("cesium");var G=require("cesium");function P(n,e){if((0,G.defined)(n)&&(0,G.defined)(e)){let{camera:t}=n;e.camera.position=t.positionWC.clone(),e.camera.direction=t.directionWC.clone(),e.camera.up=t.upWC.clone()}}function k(n,e,t){let r={baseLayerPicker:n.baseLayerPicker!==void 0,geocoder:n.geocoder!==void 0,homeButton:n.homeButton!==void 0,sceneModePicker:n.sceneModePicker!==void 0,timeline:n.timeline!==void 0,navigationHelpButton:n.navigationHelpButton!==void 0,animation:n.animation!==void 0,fullscreenButton:n.fullscreenButton!==void 0,shouldAnimate:n.clock.shouldAnimate,terrainProvider:n.terrainProvider,requestRenderMode:n.scene.requestRenderMode,infoBox:n.infoBox!==void 0},i=new H.Viewer(e,{...r,...t});P(n,i);let o=n.imageryLayers;i.imageryLayers.removeAll();for(let c=0;c<o.length;c++){let d=o.get(c);i.imageryLayers.addImageryProvider(d.imageryProvider,c)}i.clock.startTime=n.clock.startTime.clone(),i.clock.stopTime=n.clock.stopTime.clone(),i.clock.currentTime=n.clock.currentTime.clone(),i.clock.multiplier=n.clock.multiplier,i.clock.clockStep=n.clock.clockStep,i.clock.clockRange=n.clock.clockRange,i.clock.shouldAnimate=n.clock.shouldAnimate,i.scene.globe.enableLighting=n.scene.globe.enableLighting,i.scene.globe.depthTestAgainstTerrain=n.scene.globe.depthTestAgainstTerrain,i.scene.screenSpaceCameraController.enableCollisionDetection=n.scene.screenSpaceCameraController.enableCollisionDetection;let a=n.scene.screenSpaceCameraController.tiltEventTypes;a&&(i.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(a)?[...a]:a);let l=n.scene.screenSpaceCameraController.zoomEventTypes;return l&&(i.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(l)?[...l]:l),i}var s=require("cesium"),w=class n{static instances=new Map;_defaultColor=s.Color.YELLOW.withAlpha(.5);_highlightEntity;_viewerEntities;constructor(e){this._viewerEntities=e.entities,this._highlightEntity=this._viewerEntities.add(new s.Entity({id:`highlight-entity-${Math.random().toString(36).substring(2)}`,show:!1}))}static getInstance(e){let t=e.container;return n.instances.has(t)||n.instances.set(t,new n(e)),n.instances.get(t)}static releaseInstance(e){let t=e.container,r=n.instances.get(t);r&&(r.hide(),r._highlightEntity&&e.entities.remove(r._highlightEntity),n.instances.delete(t))}show(e,t=this._defaultColor,r=!1){if(!(!(0,s.defined)(e)||!this._highlightEntity)){this._clearGeometries();try{if(e instanceof s.Entity)this._update(e,t,r);else if(e.id instanceof s.Entity)this._update(e.id,t,r);else if(e.primitive instanceof s.GroundPrimitive)this._update(e.primitive,t,r);else return;return this._highlightEntity.show=!0,this._highlightEntity}catch(i){console.error("Failed to highlight object:",i);return}}}_clearGeometries(){this._highlightEntity&&(this._highlightEntity.polygon=void 0,this._highlightEntity.polyline=void 0,this._highlightEntity.rectangle=void 0)}_update(e,t,r){if(this._highlightEntity){if(e instanceof s.Entity){if(e.polygon)if(r){let i=e.polygon.hierarchy?.getValue();if(i&&i.positions){let o;i.positions.length>0&&!s.Cartesian3.equals(i.positions[0],i.positions[i.positions.length-1])?o=[...i.positions,i.positions[0]]:o=i.positions,this._highlightEntity.polyline=new s.PolylineGraphics({positions:o,material:t,width:2,clampToGround:e.polygon.heightReference?.getValue()===s.HeightReference.CLAMP_TO_GROUND})}}else{let i=e.polygon.hierarchy?.getValue();i&&(this._highlightEntity.polygon=new s.PolygonGraphics({hierarchy:i,material:t,heightReference:e.polygon.heightReference?.getValue(),classificationType:e.polygon.classificationType?.getValue()||s.ClassificationType.BOTH}))}else if(e.polyline){let i=e.polyline.positions?.getValue();if(i){let o=e.polyline.width?.getValue()||2;this._highlightEntity.polyline=new s.PolylineGraphics({positions:i,material:t,width:o+2,clampToGround:e.polyline.clampToGround?.getValue()})}}else if(e.rectangle)if(r){let i=e.rectangle.coordinates?.getValue();if(i){let o=[s.Cartesian3.fromRadians(i.west,i.north),s.Cartesian3.fromRadians(i.east,i.north),s.Cartesian3.fromRadians(i.east,i.south),s.Cartesian3.fromRadians(i.west,i.south),s.Cartesian3.fromRadians(i.west,i.north)];this._highlightEntity.polyline=new s.PolylineGraphics({positions:o,material:t,width:2,clampToGround:e.rectangle.heightReference?.getValue()===s.HeightReference.CLAMP_TO_GROUND})}}else{let i=e.rectangle.coordinates?.getValue();i&&(this._highlightEntity.rectangle=new s.RectangleGraphics({coordinates:i,material:t,heightReference:e.rectangle.heightReference?.getValue()}))}}else if(e instanceof s.GroundPrimitive){let i=e.geometryInstances,o=Array.isArray(i)?i[0]:i;if(!o||!o.geometry.attributes.position)return;let a=o.geometry.attributes.position.values,l=[];for(let c=0;c<a.length;c+=3)l.push(new s.Cartesian3(a[c],a[c+1],a[c+2]));r?this._highlightEntity.polyline=new s.PolylineGraphics({positions:l,material:t,width:2,clampToGround:!0}):this._highlightEntity.polygon=new s.PolygonGraphics({hierarchy:new s.PolygonHierarchy(l),material:t,heightReference:s.HeightReference.CLAMP_TO_GROUND,classificationType:s.ClassificationType.BOTH})}}}hide(){this._highlightEntity&&(this._highlightEntity.show=!1)}get defaultColor(){return this._defaultColor}set defaultColor(e){this._defaultColor=e}get highlightEntity(){return this._highlightEntity}};
package/dist/index.d.cts CHANGED
@@ -2,5 +2,5 @@ export { CesiumCollection, CesiumCollectionItem, Collection, CollectionEventType
2
2
  export { H as HybridTerrainProvider, T as TerrainArea, a as TileRange } from './hybrid-terrain-provider-CEJA1Xhw.cjs';
3
3
  export { TerrainAreaCollection, computeRectangle } from './terrain/index.cjs';
4
4
  export { TerrainVisualizer, isGetterOnly } from './utils/index.cjs';
5
- export { cloneViewer, syncCamera } from './viewer/index.cjs';
5
+ export { Highlight, cloneViewer, syncCamera } from './viewer/index.cjs';
6
6
  import 'cesium';
package/dist/index.d.ts CHANGED
@@ -2,5 +2,5 @@ export { CesiumCollection, CesiumCollectionItem, Collection, CollectionEventType
2
2
  export { H as HybridTerrainProvider, T as TerrainArea, a as TileRange } from './hybrid-terrain-provider-CEJA1Xhw.js';
3
3
  export { TerrainAreaCollection, computeRectangle } from './terrain/index.js';
4
4
  export { TerrainVisualizer, isGetterOnly } from './utils/index.js';
5
- export { cloneViewer, syncCamera } from './viewer/index.js';
5
+ export { Highlight, cloneViewer, syncCamera } from './viewer/index.js';
6
6
  import 'cesium';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as i,b as t,c as m,d as p}from"./chunk-OFZW33MB.js";import{a as r,b as o,c as e}from"./chunk-Q4LRNVAX.js";import{a as n,b as a}from"./chunk-2JNRK7SN.js";export{e as Collection,p as HybridTerrainProvider,t as TerrainArea,m as TerrainAreaCollection,r as TerrainVisualizer,a as cloneViewer,i as computeRectangle,o as isGetterOnly,n as syncCamera};
1
+ import{a as i,b as t,c as m,d as p}from"./chunk-OFZW33MB.js";import{a as r,b as o,c as e}from"./chunk-Q4LRNVAX.js";import{a as n,b as a,c as l}from"./chunk-6ED7EA2J.js";export{e as Collection,l as Highlight,p as HybridTerrainProvider,t as TerrainArea,m as TerrainAreaCollection,r as TerrainVisualizer,a as cloneViewer,i as computeRectangle,o as isGetterOnly,n as syncCamera};
@@ -1 +1 @@
1
- "use strict";var m=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var T=(e,i)=>{for(var o in i)m(e,o,{get:i[o],enumerable:!0})},v=(e,i,o,t)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of k(i))!C.call(e,n)&&n!==o&&m(e,n,{get:()=>i[n],enumerable:!(t=g(i,n))||t.enumerable});return e};var b=e=>v(m({},"__esModule",{value:!0}),e);var h={};T(h,{cloneViewer:()=>y,syncCamera:()=>l});module.exports=b(h);var p=require("cesium");var d=require("cesium");function l(e,i){if((0,d.defined)(e)&&(0,d.defined)(i)){let{camera:o}=e;i.camera.position=o.positionWC.clone(),i.camera.direction=o.directionWC.clone(),i.camera.up=o.upWC.clone()}}function y(e,i,o){let t={baseLayerPicker:e.baseLayerPicker!==void 0,geocoder:e.geocoder!==void 0,homeButton:e.homeButton!==void 0,sceneModePicker:e.sceneModePicker!==void 0,timeline:e.timeline!==void 0,navigationHelpButton:e.navigationHelpButton!==void 0,animation:e.animation!==void 0,fullscreenButton:e.fullscreenButton!==void 0,shouldAnimate:e.clock.shouldAnimate,terrainProvider:e.terrainProvider,requestRenderMode:e.scene.requestRenderMode,infoBox:e.infoBox!==void 0},n=new p.Viewer(i,{...t,...o});l(e,n);let s=e.imageryLayers;n.imageryLayers.removeAll();for(let c=0;c<s.length;c++){let f=s.get(c);n.imageryLayers.addImageryProvider(f.imageryProvider,c)}n.clock.startTime=e.clock.startTime.clone(),n.clock.stopTime=e.clock.stopTime.clone(),n.clock.currentTime=e.clock.currentTime.clone(),n.clock.multiplier=e.clock.multiplier,n.clock.clockStep=e.clock.clockStep,n.clock.clockRange=e.clock.clockRange,n.clock.shouldAnimate=e.clock.shouldAnimate,n.scene.globe.enableLighting=e.scene.globe.enableLighting,n.scene.globe.depthTestAgainstTerrain=e.scene.globe.depthTestAgainstTerrain,n.scene.screenSpaceCameraController.enableCollisionDetection=e.scene.screenSpaceCameraController.enableCollisionDetection;let r=e.scene.screenSpaceCameraController.tiltEventTypes;r&&(n.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(r)?[...r]:r);let a=e.scene.screenSpaceCameraController.zoomEventTypes;return a&&(n.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(a)?[...a]:a),n}
1
+ "use strict";var d=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var w=(t,i)=>{for(var o in i)d(t,o,{get:i[o],enumerable:!0})},_=(t,i,o,a)=>{if(i&&typeof i=="object"||typeof i=="function")for(let e of C(i))!E.call(t,e)&&e!==o&&d(t,e,{get:()=>i[e],enumerable:!(a=u(i,e))||a.enumerable});return t};var v=t=>_(d({},"__esModule",{value:!0}),t);var T={};w(T,{Highlight:()=>g,cloneViewer:()=>f,syncCamera:()=>c});module.exports=v(T);var y=require("cesium");var p=require("cesium");function c(t,i){if((0,p.defined)(t)&&(0,p.defined)(i)){let{camera:o}=t;i.camera.position=o.positionWC.clone(),i.camera.direction=o.directionWC.clone(),i.camera.up=o.upWC.clone()}}function f(t,i,o){let a={baseLayerPicker:t.baseLayerPicker!==void 0,geocoder:t.geocoder!==void 0,homeButton:t.homeButton!==void 0,sceneModePicker:t.sceneModePicker!==void 0,timeline:t.timeline!==void 0,navigationHelpButton:t.navigationHelpButton!==void 0,animation:t.animation!==void 0,fullscreenButton:t.fullscreenButton!==void 0,shouldAnimate:t.clock.shouldAnimate,terrainProvider:t.terrainProvider,requestRenderMode:t.scene.requestRenderMode,infoBox:t.infoBox!==void 0},e=new y.Viewer(i,{...a,...o});c(t,e);let r=t.imageryLayers;e.imageryLayers.removeAll();for(let l=0;l<r.length;l++){let m=r.get(l);e.imageryLayers.addImageryProvider(m.imageryProvider,l)}e.clock.startTime=t.clock.startTime.clone(),e.clock.stopTime=t.clock.stopTime.clone(),e.clock.currentTime=t.clock.currentTime.clone(),e.clock.multiplier=t.clock.multiplier,e.clock.clockStep=t.clock.clockStep,e.clock.clockRange=t.clock.clockRange,e.clock.shouldAnimate=t.clock.shouldAnimate,e.scene.globe.enableLighting=t.scene.globe.enableLighting,e.scene.globe.depthTestAgainstTerrain=t.scene.globe.depthTestAgainstTerrain,e.scene.screenSpaceCameraController.enableCollisionDetection=t.scene.screenSpaceCameraController.enableCollisionDetection;let s=t.scene.screenSpaceCameraController.tiltEventTypes;s&&(e.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(s)?[...s]:s);let h=t.scene.screenSpaceCameraController.zoomEventTypes;return h&&(e.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(h)?[...h]:h),e}var n=require("cesium"),g=class t{static instances=new Map;_defaultColor=n.Color.YELLOW.withAlpha(.5);_highlightEntity;_viewerEntities;constructor(i){this._viewerEntities=i.entities,this._highlightEntity=this._viewerEntities.add(new n.Entity({id:`highlight-entity-${Math.random().toString(36).substring(2)}`,show:!1}))}static getInstance(i){let o=i.container;return t.instances.has(o)||t.instances.set(o,new t(i)),t.instances.get(o)}static releaseInstance(i){let o=i.container,a=t.instances.get(o);a&&(a.hide(),a._highlightEntity&&i.entities.remove(a._highlightEntity),t.instances.delete(o))}show(i,o=this._defaultColor,a=!1){if(!(!(0,n.defined)(i)||!this._highlightEntity)){this._clearGeometries();try{if(i instanceof n.Entity)this._update(i,o,a);else if(i.id instanceof n.Entity)this._update(i.id,o,a);else if(i.primitive instanceof n.GroundPrimitive)this._update(i.primitive,o,a);else return;return this._highlightEntity.show=!0,this._highlightEntity}catch(e){console.error("Failed to highlight object:",e);return}}}_clearGeometries(){this._highlightEntity&&(this._highlightEntity.polygon=void 0,this._highlightEntity.polyline=void 0,this._highlightEntity.rectangle=void 0)}_update(i,o,a){if(this._highlightEntity){if(i instanceof n.Entity){if(i.polygon)if(a){let e=i.polygon.hierarchy?.getValue();if(e&&e.positions){let r;e.positions.length>0&&!n.Cartesian3.equals(e.positions[0],e.positions[e.positions.length-1])?r=[...e.positions,e.positions[0]]:r=e.positions,this._highlightEntity.polyline=new n.PolylineGraphics({positions:r,material:o,width:2,clampToGround:i.polygon.heightReference?.getValue()===n.HeightReference.CLAMP_TO_GROUND})}}else{let e=i.polygon.hierarchy?.getValue();e&&(this._highlightEntity.polygon=new n.PolygonGraphics({hierarchy:e,material:o,heightReference:i.polygon.heightReference?.getValue(),classificationType:i.polygon.classificationType?.getValue()||n.ClassificationType.BOTH}))}else if(i.polyline){let e=i.polyline.positions?.getValue();if(e){let r=i.polyline.width?.getValue()||2;this._highlightEntity.polyline=new n.PolylineGraphics({positions:e,material:o,width:r+2,clampToGround:i.polyline.clampToGround?.getValue()})}}else if(i.rectangle)if(a){let e=i.rectangle.coordinates?.getValue();if(e){let r=[n.Cartesian3.fromRadians(e.west,e.north),n.Cartesian3.fromRadians(e.east,e.north),n.Cartesian3.fromRadians(e.east,e.south),n.Cartesian3.fromRadians(e.west,e.south),n.Cartesian3.fromRadians(e.west,e.north)];this._highlightEntity.polyline=new n.PolylineGraphics({positions:r,material:o,width:2,clampToGround:i.rectangle.heightReference?.getValue()===n.HeightReference.CLAMP_TO_GROUND})}}else{let e=i.rectangle.coordinates?.getValue();e&&(this._highlightEntity.rectangle=new n.RectangleGraphics({coordinates:e,material:o,heightReference:i.rectangle.heightReference?.getValue()}))}}else if(i instanceof n.GroundPrimitive){let e=i.geometryInstances,r=Array.isArray(e)?e[0]:e;if(!r||!r.geometry.attributes.position)return;let s=r.geometry.attributes.position.values,h=[];for(let l=0;l<s.length;l+=3)h.push(new n.Cartesian3(s[l],s[l+1],s[l+2]));a?this._highlightEntity.polyline=new n.PolylineGraphics({positions:h,material:o,width:2,clampToGround:!0}):this._highlightEntity.polygon=new n.PolygonGraphics({hierarchy:new n.PolygonHierarchy(h),material:o,heightReference:n.HeightReference.CLAMP_TO_GROUND,classificationType:n.ClassificationType.BOTH})}}}hide(){this._highlightEntity&&(this._highlightEntity.show=!1)}get defaultColor(){return this._defaultColor}set defaultColor(i){this._defaultColor=i}get highlightEntity(){return this._highlightEntity}};
@@ -1,4 +1,4 @@
1
- import { Viewer } from 'cesium';
1
+ import { Viewer, Color, Entity } from 'cesium';
2
2
 
3
3
  /**
4
4
  * Copies configuration and state from one Cesium Viewer to another.
@@ -9,6 +9,86 @@ import { Viewer } from 'cesium';
9
9
  */
10
10
  declare function cloneViewer(source: Viewer, container: Element | string, options?: Viewer.ConstructorOptions): Viewer;
11
11
 
12
+ /**
13
+ * @class
14
+ * Lightweight multiton highlight manager for Cesium using a single reusable entity.
15
+ *
16
+ * @example
17
+ * ```
18
+ * // Setup
19
+ * const viewer1 = new Viewer('cesiumContainer1');
20
+ * const viewer2 = new Viewer('cesiumContainer2');
21
+ *
22
+ * const highlighter1 = Highlight.getInstance(viewer1);
23
+ * const highlighter2 = Highlight.getInstance(viewer2);
24
+ *
25
+ * // This highlight only affects viewer1
26
+ * highlighter1.show(someEntity, Color.RED);
27
+ *
28
+ * // This highlight only affects viewer2
29
+ * highlighter2.show(someEntity, Color.BLUE);
30
+ *
31
+ * // When done with viewers
32
+ * Highlight.releaseInstance(viewer1);
33
+ * Highlight.releaseInstance(viewer2);
34
+ * viewer1.destroy();
35
+ * viewer2.destroy();
36
+ * ```
37
+ */
38
+ declare class Highlight {
39
+ private static instances;
40
+ private _defaultColor;
41
+ private _highlightEntity?;
42
+ private _viewerEntities;
43
+ /**
44
+ * Creates a new `Highlight` instance.
45
+ * @private Use {@link getInstance `Highlight.getInstance()`}
46
+ * @param viewer A viewer to create highlight entity in
47
+ */
48
+ private constructor();
49
+ /**
50
+ * Gets or creates highlight instance from a viewer.
51
+ * @param viewer The viewer to get or create a new instance from.
52
+ */
53
+ static getInstance(viewer: Viewer): Highlight;
54
+ /**
55
+ * Releases the highlight instance associated with a viewer.
56
+ * @param viewer The viewer whose highlight instance should be released.
57
+ */
58
+ static releaseInstance(viewer: Viewer): void;
59
+ /**
60
+ * Highlights a picked object by updating the reusable entity
61
+ * @param picked The object returned from `scene.pick()` or `drillPick()`
62
+ * @param color Optional color for the highlight. Defaults to yellow with 0.5 alpha.
63
+ * @param outline Optional style for the highlight. Defaults to `false`.
64
+ * @returns The entity being used for highlighting
65
+ */
66
+ show(picked: any, color?: Color, outline?: boolean): Entity | undefined;
67
+ /**
68
+ * Removes all geometry properties from the highlight entity
69
+ * @private
70
+ */
71
+ private _clearGeometries;
72
+ /**
73
+ * Updates the highlight entity from an Entity object
74
+ * @private
75
+ */
76
+ private _update;
77
+ /**
78
+ * Clears the current highlight
79
+ */
80
+ hide(): void;
81
+ /** Gets the default highlight color. */
82
+ get defaultColor(): Color;
83
+ /**
84
+ * Sets the default highlight color.
85
+ * @param color The new default color for highlights
86
+ */
87
+ set defaultColor(color: Color);
88
+ /** Gets the highlight entity */
89
+ get highlightEntity(): Entity | undefined;
90
+ }
91
+
12
92
  /**
13
93
  * Copies camera state from source viewer to destination viewer.
14
94
  * @param source The source viewer to copy camera states from.
@@ -16,4 +96,4 @@ declare function cloneViewer(source: Viewer, container: Element | string, option
16
96
  */
17
97
  declare function syncCamera(source: Viewer, dest: Viewer): void;
18
98
 
19
- export { cloneViewer, syncCamera };
99
+ export { Highlight, cloneViewer, syncCamera };
@@ -1,4 +1,4 @@
1
- import { Viewer } from 'cesium';
1
+ import { Viewer, Color, Entity } from 'cesium';
2
2
 
3
3
  /**
4
4
  * Copies configuration and state from one Cesium Viewer to another.
@@ -9,6 +9,86 @@ import { Viewer } from 'cesium';
9
9
  */
10
10
  declare function cloneViewer(source: Viewer, container: Element | string, options?: Viewer.ConstructorOptions): Viewer;
11
11
 
12
+ /**
13
+ * @class
14
+ * Lightweight multiton highlight manager for Cesium using a single reusable entity.
15
+ *
16
+ * @example
17
+ * ```
18
+ * // Setup
19
+ * const viewer1 = new Viewer('cesiumContainer1');
20
+ * const viewer2 = new Viewer('cesiumContainer2');
21
+ *
22
+ * const highlighter1 = Highlight.getInstance(viewer1);
23
+ * const highlighter2 = Highlight.getInstance(viewer2);
24
+ *
25
+ * // This highlight only affects viewer1
26
+ * highlighter1.show(someEntity, Color.RED);
27
+ *
28
+ * // This highlight only affects viewer2
29
+ * highlighter2.show(someEntity, Color.BLUE);
30
+ *
31
+ * // When done with viewers
32
+ * Highlight.releaseInstance(viewer1);
33
+ * Highlight.releaseInstance(viewer2);
34
+ * viewer1.destroy();
35
+ * viewer2.destroy();
36
+ * ```
37
+ */
38
+ declare class Highlight {
39
+ private static instances;
40
+ private _defaultColor;
41
+ private _highlightEntity?;
42
+ private _viewerEntities;
43
+ /**
44
+ * Creates a new `Highlight` instance.
45
+ * @private Use {@link getInstance `Highlight.getInstance()`}
46
+ * @param viewer A viewer to create highlight entity in
47
+ */
48
+ private constructor();
49
+ /**
50
+ * Gets or creates highlight instance from a viewer.
51
+ * @param viewer The viewer to get or create a new instance from.
52
+ */
53
+ static getInstance(viewer: Viewer): Highlight;
54
+ /**
55
+ * Releases the highlight instance associated with a viewer.
56
+ * @param viewer The viewer whose highlight instance should be released.
57
+ */
58
+ static releaseInstance(viewer: Viewer): void;
59
+ /**
60
+ * Highlights a picked object by updating the reusable entity
61
+ * @param picked The object returned from `scene.pick()` or `drillPick()`
62
+ * @param color Optional color for the highlight. Defaults to yellow with 0.5 alpha.
63
+ * @param outline Optional style for the highlight. Defaults to `false`.
64
+ * @returns The entity being used for highlighting
65
+ */
66
+ show(picked: any, color?: Color, outline?: boolean): Entity | undefined;
67
+ /**
68
+ * Removes all geometry properties from the highlight entity
69
+ * @private
70
+ */
71
+ private _clearGeometries;
72
+ /**
73
+ * Updates the highlight entity from an Entity object
74
+ * @private
75
+ */
76
+ private _update;
77
+ /**
78
+ * Clears the current highlight
79
+ */
80
+ hide(): void;
81
+ /** Gets the default highlight color. */
82
+ get defaultColor(): Color;
83
+ /**
84
+ * Sets the default highlight color.
85
+ * @param color The new default color for highlights
86
+ */
87
+ set defaultColor(color: Color);
88
+ /** Gets the highlight entity */
89
+ get highlightEntity(): Entity | undefined;
90
+ }
91
+
12
92
  /**
13
93
  * Copies camera state from source viewer to destination viewer.
14
94
  * @param source The source viewer to copy camera states from.
@@ -16,4 +96,4 @@ declare function cloneViewer(source: Viewer, container: Element | string, option
16
96
  */
17
97
  declare function syncCamera(source: Viewer, dest: Viewer): void;
18
98
 
19
- export { cloneViewer, syncCamera };
99
+ export { Highlight, cloneViewer, syncCamera };
@@ -1 +1 @@
1
- import{a,b}from"../chunk-2JNRK7SN.js";export{b as cloneViewer,a as syncCamera};
1
+ import{a,b,c}from"../chunk-6ED7EA2J.js";export{c as Highlight,b as cloneViewer,a as syncCamera};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juun-roh/cesium-utils",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "Utilities to handle Cesium classes easier.",
5
5
  "keywords": [
6
6
  "Cesium",
@@ -50,6 +50,11 @@
50
50
  "types": "./dist/utils/index.d.ts",
51
51
  "import": "./dist/utils/index.js",
52
52
  "require": "./dist/utils/index.cjs"
53
+ },
54
+ "./viewer": {
55
+ "types": "./dist/viewer/index.d.ts",
56
+ "import": "./dist/viewer/index.js",
57
+ "require": "./dist/viewer/index.cjs"
53
58
  }
54
59
  },
55
60
  "engines": {
@@ -68,18 +73,18 @@
68
73
  },
69
74
  "devDependencies": {
70
75
  "@changesets/cli": "^2.29.3",
71
- "@commitlint/cli": "^19.8.0",
72
- "@commitlint/config-conventional": "^19.8.0",
73
- "@commitlint/cz-commitlint": "^19.8.0",
74
- "@commitlint/format": "^19.8.0",
75
- "@commitlint/types": "^19.8.0",
76
+ "@commitlint/cli": "^19.8.1",
77
+ "@commitlint/config-conventional": "^19.8.1",
78
+ "@commitlint/cz-commitlint": "^19.8.1",
79
+ "@commitlint/format": "^19.8.1",
80
+ "@commitlint/types": "^19.8.1",
76
81
  "@eslint/js": "^9.26.0",
77
82
  "@typescript-eslint/eslint-plugin": "^8.32.0",
78
83
  "@typescript-eslint/parser": "^8.32.0",
79
84
  "@vitest/coverage-v8": "3.1.3",
80
85
  "cesium": "^1.129.0",
81
86
  "eslint": "^9.26.0",
82
- "eslint-plugin-jsdoc": "^50.6.11",
87
+ "eslint-plugin-jsdoc": "^50.6.14",
83
88
  "eslint-plugin-prettier": "^5.4.0",
84
89
  "eslint-plugin-simple-import-sort": "^12.1.1",
85
90
  "eslint-plugin-unused-imports": "^4.1.4",
@@ -1 +0,0 @@
1
- import{Viewer as p}from"cesium";import{defined as m}from"cesium";function c(e,i){if(m(e)&&m(i)){let{camera:o}=e;i.camera.position=o.positionWC.clone(),i.camera.direction=o.directionWC.clone(),i.camera.up=o.upWC.clone()}}function y(e,i,o){let d={baseLayerPicker:e.baseLayerPicker!==void 0,geocoder:e.geocoder!==void 0,homeButton:e.homeButton!==void 0,sceneModePicker:e.sceneModePicker!==void 0,timeline:e.timeline!==void 0,navigationHelpButton:e.navigationHelpButton!==void 0,animation:e.animation!==void 0,fullscreenButton:e.fullscreenButton!==void 0,shouldAnimate:e.clock.shouldAnimate,terrainProvider:e.terrainProvider,requestRenderMode:e.scene.requestRenderMode,infoBox:e.infoBox!==void 0},n=new p(i,{...d,...o});c(e,n);let l=e.imageryLayers;n.imageryLayers.removeAll();for(let a=0;a<l.length;a++){let s=l.get(a);n.imageryLayers.addImageryProvider(s.imageryProvider,a)}n.clock.startTime=e.clock.startTime.clone(),n.clock.stopTime=e.clock.stopTime.clone(),n.clock.currentTime=e.clock.currentTime.clone(),n.clock.multiplier=e.clock.multiplier,n.clock.clockStep=e.clock.clockStep,n.clock.clockRange=e.clock.clockRange,n.clock.shouldAnimate=e.clock.shouldAnimate,n.scene.globe.enableLighting=e.scene.globe.enableLighting,n.scene.globe.depthTestAgainstTerrain=e.scene.globe.depthTestAgainstTerrain,n.scene.screenSpaceCameraController.enableCollisionDetection=e.scene.screenSpaceCameraController.enableCollisionDetection;let t=e.scene.screenSpaceCameraController.tiltEventTypes;t&&(n.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(t)?[...t]:t);let r=e.scene.screenSpaceCameraController.zoomEventTypes;return r&&(n.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(r)?[...r]:r),n}export{c as a,y as b};