@juun-roh/cesium-utils 0.1.1 → 0.1.2

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{Color as o,Entity as O,HeightReference as F,Rectangle as E,TileCoordinatesImageryProvider as V}from"cesium";import{DataSourceCollection as S,defined as p,EntityCollection as b,ImageryLayerCollection as x,PrimitiveCollection as M}from"cesium";var y=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;_eventCleanupFunctions=[];constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e,this._setupCacheInvalidator(e)}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(a=>a(r))}}_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],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache=()=>{this._valuesCache=null};_setupCacheInvalidator(e){e instanceof b?(e.collectionChanged.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.collectionChanged.removeEventListener(this._invalidateCache))):e instanceof M?(e.primitiveAdded.addEventListener(this._invalidateCache),e.primitiveRemoved.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.primitiveAdded.removeEventListener(this._invalidateCache),()=>e.primitiveRemoved.removeEventListener(this._invalidateCache))):e instanceof S?(e.dataSourceAdded.addEventListener(this._invalidateCache),e.dataSourceMoved.addEventListener(this._invalidateCache),e.dataSourceRemoved.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.dataSourceAdded.removeEventListener(this._invalidateCache),()=>e.dataSourceMoved.removeEventListener(this._invalidateCache),()=>e.dataSourceRemoved.removeEventListener(this._invalidateCache))):e instanceof x&&(e.layerAdded.addEventListener(this._invalidateCache),e.layerMoved.addEventListener(this._invalidateCache),e.layerRemoved.addEventListener(this._invalidateCache),e.layerShownOrHidden.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.layerAdded.removeEventListener(this._invalidateCache),()=>e.layerMoved.removeEventListener(this._invalidateCache),()=>e.layerRemoved.removeEventListener(this._invalidateCache),()=>e.layerShownOrHidden.removeEventListener(this._invalidateCache)))}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,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),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 r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let a of e)this.remove(a)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}destroy(){this._eventCleanupFunctions.forEach(e=>e()),this._eventCleanupFunctions=[],this._tagMap.clear(),this._eventListeners.clear(),this._valuesCache=null}get values(){if(this._valuesCache!==null)return this._valuesCache;let e;if(this.collection instanceof b)e=this.collection.values;else{e=[];for(let t=0;t<this.collection.length;t++)e.push(this.collection.get(t))}return this._valuesCache=e,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 i=this.get(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}show(e){let t=this.get(e);for(let i of t)p(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)p(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)p(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let a of r)if(e in a&&typeof a[e]!="function"){if(T(a,e))throw Error(`Cannot set read-only property '${String(e)}' on ${a.constructor.name}`);a[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((r,a)=>e(r,a))}map(e,t){return(t?this.get(t):this.values).map(e)}find(e,t){return(t?this.get(t):this.values).find(e)}},C=y;var v=class n{_viewer;_collection;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",o.RED],["default",o.BLUE],["fallback",o.GRAY],["grid",o.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new C({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),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,this._ensureTileCoordinatesLayer();let t=this._getVisibleRectangle();if(!t||!this._isValidRectangle(t)){console.warn("Invalid visible rectangle detected, skipping grid display");return}this._displayTileGrid(t,e),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new V({tilingScheme:this._terrainProvider.tilingScheme,color:o.YELLOW})))}_isValidRectangle(e){return e&&Number.isFinite(e.west)&&Number.isFinite(e.south)&&Number.isFinite(e.east)&&Number.isFinite(e.north)&&e.west<=e.east&&e.south<=e.north}_displayTileGrid(e,t){let i=this._terrainProvider.tilingScheme;try{let r=this._calculateTileBounds(e,t,i);this._generateVisibleTiles(r,t,i).forEach(s=>{this._collection.add(s.entity,n.tag.grid)})}catch(r){console.error("Error displaying tile grid:",r)}}_calculateTileBounds(e,t,i){let r=i.positionToTileXY(E.northwest(e),t),a=i.positionToTileXY(E.southeast(e),t);if(!r||!a)throw new Error("Failed to calculate tile bounds");return{start:r,end:a}}_generateVisibleTiles(e,t,i){let r=[],s=Math.min(e.end.x-e.start.x+1,100),l=Math.min(e.end.y-e.start.y+1,100);for(let h=e.start.x;h<e.start.x+s;h++)for(let c=e.start.y;c<e.start.y+l;c++)try{let d=this._createTileEntity(h,c,t,i);d&&r.push({entity:d})}catch(d){console.warn(`Error creating tile (${h}, ${c}, ${t}):`,d)}return r}_createTileEntity(e,t,i,r){let a=r.tileXYToRectangle(e,t,i);if(!this._isValidRectangle(a))return null;let s=this._getTileColor(e,t,i),l=n.createRectangle(a,s.withAlpha(.3));return l.properties?.addProperty("tileX",e),l.properties?.addProperty("tileY",t),l.properties?.addProperty("tileLevel",i),l}_getTileColor(e,t,i){if(!this._terrainProvider)return this._colors.get("fallback")||o.TRANSPARENT;for(let r of this._terrainProvider.terrainAreas)if(r.contains(e,t,i))return r.isCustom?this._colors.get("custom")||o.RED:this._colors.get("default")||o.BLUE;return this._terrainProvider.getTileDataAvailable(e,t,i)?this._colors.get("default")||o.BLUE:this._colors.get("fallback")||o.GRAY}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,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...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}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,a){return new O({rectangle:{coordinates:r,material:a,heightReference:F.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,a,s){let l=s?.tag||"terrain_area_visualization",h=s?.color||o.RED,c=s?.maxTilesToShow||100,d=s?.show??!0,w=s?.alpha||.7,L=s?.tileAlpha||.2,m=new C({collection:a.entities,tag:l}),{rectangle:I}=r;if(m.add(i.createRectangle(I,h.withAlpha(w)),l),d&&r.tileRanges.size>0){let{tilingScheme:R}=r.terrainProvider,g=0;r.tileRanges.forEach((u,A)=>{for(let f=u.start.x;f<=u.end.x&&g<c;f++)for(let _=u.start.y;_<=u.end.y&&g<c;_++){let P=R.tileXYToRectangle(f,_,A);m.add(e(P,h.withAlpha(L)),`${l}_tile`),g++}})}return m}i.visualize=t})(v||={});function T(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}export{v as a,T as b,C as c};
@@ -1 +1 @@
1
- "use strict";var _=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var O=(n,e)=>{for(var t in e)_(n,t,{get:e[t],enumerable:!0})},S=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of A(e))!M.call(n,r)&&r!==t&&_(n,r,{get:()=>e[r],enumerable:!(i=L(e,r))||i.enumerable});return n};var V=n=>S(_({},"__esModule",{value:!0}),n);var j={};O(j,{Collection:()=>g});module.exports=V(j);var u=require("cesium");var s=require("cesium");var m=class n{_viewer;_collection;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",s.Color.RED],["default",s.Color.BLUE],["fallback",s.Color.GRAY],["grid",s.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new g({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),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,this._ensureTileCoordinatesLayer();let t=this._getVisibleRectangle();if(!t||!this._isValidRectangle(t)){console.warn("Invalid visible rectangle detected, skipping grid display");return}this._displayTileGrid(t,e),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new s.TileCoordinatesImageryProvider({tilingScheme:this._terrainProvider.tilingScheme,color:s.Color.YELLOW})))}_isValidRectangle(e){return e&&Number.isFinite(e.west)&&Number.isFinite(e.south)&&Number.isFinite(e.east)&&Number.isFinite(e.north)&&e.west<=e.east&&e.south<=e.north}_displayTileGrid(e,t){let i=this._terrainProvider.tilingScheme;try{let r=this._calculateTileBounds(e,t,i);this._generateVisibleTiles(r,t,i).forEach(a=>{this._collection.add(a.entity,n.tag.grid)})}catch(r){console.error("Error displaying tile grid:",r)}}_calculateTileBounds(e,t,i){let r=i.positionToTileXY(s.Rectangle.northwest(e),t),o=i.positionToTileXY(s.Rectangle.southeast(e),t);if(!r||!o)throw new Error("Failed to calculate tile bounds");return{start:r,end:o}}_generateVisibleTiles(e,t,i){let r=[],a=Math.min(e.end.x-e.start.x+1,100),l=Math.min(e.end.y-e.start.y+1,100);for(let c=e.start.x;c<e.start.x+a;c++)for(let h=e.start.y;h<e.start.y+l;h++)try{let d=this._createTileEntity(c,h,t,i);d&&r.push({entity:d})}catch(d){console.warn(`Error creating tile (${c}, ${h}, ${t}):`,d)}return r}_createTileEntity(e,t,i,r){let o=r.tileXYToRectangle(e,t,i);if(!this._isValidRectangle(o))return null;let a=this._getTileColor(e,t,i),l=n.createRectangle(o,a.withAlpha(.3));return l.properties?.addProperty("tileX",e),l.properties?.addProperty("tileY",t),l.properties?.addProperty("tileLevel",i),l}_getTileColor(e,t,i){if(!this._terrainProvider)return this._colors.get("fallback")||s.Color.TRANSPARENT;for(let r of this._terrainProvider.terrainAreas)if(r.contains(e,t,i))return r.isCustom?this._colors.get("custom")||s.Color.RED:this._colors.get("default")||s.Color.BLUE;return this._terrainProvider.getTileDataAvailable(e,t,i)?this._colors.get("default")||s.Color.BLUE:this._colors.get("fallback")||s.Color.GRAY}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,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...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}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,o){return new s.Entity({rectangle:{coordinates:r,material:o,heightReference:s.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,o,a){let l=a?.tag||"terrain_area_visualization",c=a?.color||s.Color.RED,h=a?.maxTilesToShow||100,d=a?.show??!0,w=a?.alpha||.7,E=a?.tileAlpha||.2,f=new g({collection:o.entities,tag:l}),{rectangle:I}=r;if(f.add(i.createRectangle(I,c.withAlpha(w)),l),d&&r.tileRanges.size>0){let{tilingScheme:R}=r.terrainProvider,p=0;r.tileRanges.forEach((v,P)=>{for(let y=v.start.x;y<=v.end.x&&p<h;y++)for(let T=v.start.y;T<=v.end.y&&p<h;T++){let x=R.tileXYToRectangle(y,T,P);f.add(e(x,c.withAlpha(E)),`${l}_tile`),p++}})}return f}i.visualize=t})(m||={});function b(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}var C=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 i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(o=>o(r))}}_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],i=this._tagMap.get(t);i&&(i.delete(e),i.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,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),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 r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let o of e)this.remove(o)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof u.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 i=this.get(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}show(e){let t=this.get(e);for(let i of t)(0,u.defined)(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)(0,u.defined)(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)(0,u.defined)(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let o of r)if(e in o&&typeof o[e]!="function"){if(b(o,e))throw Error(`Cannot set read-only property '${String(e)}' on ${o.constructor.name}`);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((r,o)=>e(r,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)}},g=C;
1
+ "use strict";var T=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var M=(n,e)=>{for(var t in e)T(n,t,{get:e[t],enumerable:!0})},O=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of S(e))!x.call(n,r)&&r!==t&&T(n,r,{get:()=>e[r],enumerable:!(i=P(e,r))||i.enumerable});return n};var F=n=>O(T({},"__esModule",{value:!0}),n);var V={};M(V,{Collection:()=>m});module.exports=F(V);var o=require("cesium");var s=require("cesium");var u=class n{_viewer;_collection;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",s.Color.RED],["default",s.Color.BLUE],["fallback",s.Color.GRAY],["grid",s.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new m({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),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,this._ensureTileCoordinatesLayer();let t=this._getVisibleRectangle();if(!t||!this._isValidRectangle(t)){console.warn("Invalid visible rectangle detected, skipping grid display");return}this._displayTileGrid(t,e),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new s.TileCoordinatesImageryProvider({tilingScheme:this._terrainProvider.tilingScheme,color:s.Color.YELLOW})))}_isValidRectangle(e){return e&&Number.isFinite(e.west)&&Number.isFinite(e.south)&&Number.isFinite(e.east)&&Number.isFinite(e.north)&&e.west<=e.east&&e.south<=e.north}_displayTileGrid(e,t){let i=this._terrainProvider.tilingScheme;try{let r=this._calculateTileBounds(e,t,i);this._generateVisibleTiles(r,t,i).forEach(l=>{this._collection.add(l.entity,n.tag.grid)})}catch(r){console.error("Error displaying tile grid:",r)}}_calculateTileBounds(e,t,i){let r=i.positionToTileXY(s.Rectangle.northwest(e),t),a=i.positionToTileXY(s.Rectangle.southeast(e),t);if(!r||!a)throw new Error("Failed to calculate tile bounds");return{start:r,end:a}}_generateVisibleTiles(e,t,i){let r=[],l=Math.min(e.end.x-e.start.x+1,100),h=Math.min(e.end.y-e.start.y+1,100);for(let c=e.start.x;c<e.start.x+l;c++)for(let d=e.start.y;d<e.start.y+h;d++)try{let v=this._createTileEntity(c,d,t,i);v&&r.push({entity:v})}catch(v){console.warn(`Error creating tile (${c}, ${d}, ${t}):`,v)}return r}_createTileEntity(e,t,i,r){let a=r.tileXYToRectangle(e,t,i);if(!this._isValidRectangle(a))return null;let l=this._getTileColor(e,t,i),h=n.createRectangle(a,l.withAlpha(.3));return h.properties?.addProperty("tileX",e),h.properties?.addProperty("tileY",t),h.properties?.addProperty("tileLevel",i),h}_getTileColor(e,t,i){if(!this._terrainProvider)return this._colors.get("fallback")||s.Color.TRANSPARENT;for(let r of this._terrainProvider.terrainAreas)if(r.contains(e,t,i))return r.isCustom?this._colors.get("custom")||s.Color.RED:this._colors.get("default")||s.Color.BLUE;return this._terrainProvider.getTileDataAvailable(e,t,i)?this._colors.get("default")||s.Color.BLUE:this._colors.get("fallback")||s.Color.GRAY}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,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...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}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,a){return new s.Entity({rectangle:{coordinates:r,material:a,heightReference:s.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,a,l){let h=l?.tag||"terrain_area_visualization",c=l?.color||s.Color.RED,d=l?.maxTilesToShow||100,v=l?.show??!0,E=l?.alpha||.7,w=l?.tileAlpha||.2,f=new m({collection:a.entities,tag:h}),{rectangle:L}=r;if(f.add(i.createRectangle(L,c.withAlpha(E)),h),v&&r.tileRanges.size>0){let{tilingScheme:I}=r.terrainProvider,_=0;r.tileRanges.forEach((g,R)=>{for(let p=g.start.x;p<=g.end.x&&_<d;p++)for(let y=g.start.y;y<=g.end.y&&_<d;y++){let A=I.tileXYToRectangle(p,y,R);f.add(e(A,c.withAlpha(w)),`${h}_tile`),_++}})}return f}i.visualize=t})(u||={});function C(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}var b=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;_eventCleanupFunctions=[];constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e,this._setupCacheInvalidator(e)}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(a=>a(r))}}_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],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache=()=>{this._valuesCache=null};_setupCacheInvalidator(e){e instanceof o.EntityCollection?(e.collectionChanged.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.collectionChanged.removeEventListener(this._invalidateCache))):e instanceof o.PrimitiveCollection?(e.primitiveAdded.addEventListener(this._invalidateCache),e.primitiveRemoved.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.primitiveAdded.removeEventListener(this._invalidateCache),()=>e.primitiveRemoved.removeEventListener(this._invalidateCache))):e instanceof o.DataSourceCollection?(e.dataSourceAdded.addEventListener(this._invalidateCache),e.dataSourceMoved.addEventListener(this._invalidateCache),e.dataSourceRemoved.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.dataSourceAdded.removeEventListener(this._invalidateCache),()=>e.dataSourceMoved.removeEventListener(this._invalidateCache),()=>e.dataSourceRemoved.removeEventListener(this._invalidateCache))):e instanceof o.ImageryLayerCollection&&(e.layerAdded.addEventListener(this._invalidateCache),e.layerMoved.addEventListener(this._invalidateCache),e.layerRemoved.addEventListener(this._invalidateCache),e.layerShownOrHidden.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.layerAdded.removeEventListener(this._invalidateCache),()=>e.layerMoved.removeEventListener(this._invalidateCache),()=>e.layerRemoved.removeEventListener(this._invalidateCache),()=>e.layerShownOrHidden.removeEventListener(this._invalidateCache)))}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,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),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 r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let a of e)this.remove(a)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}destroy(){this._eventCleanupFunctions.forEach(e=>e()),this._eventCleanupFunctions=[],this._tagMap.clear(),this._eventListeners.clear(),this._valuesCache=null}get values(){if(this._valuesCache!==null)return this._valuesCache;let e;if(this.collection instanceof o.EntityCollection)e=this.collection.values;else{e=[];for(let t=0;t<this.collection.length;t++)e.push(this.collection.get(t))}return this._valuesCache=e,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 i=this.get(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}show(e){let t=this.get(e);for(let i of t)(0,o.defined)(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)(0,o.defined)(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)(0,o.defined)(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let a of r)if(e in a&&typeof a[e]!="function"){if(C(a,e))throw Error(`Cannot set read-only property '${String(e)}' on ${a.constructor.name}`);a[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((r,a)=>e(r,a))}map(e,t){return(t?this.get(t):this.values).map(e)}find(e,t){return(t?this.get(t):this.values).find(e)}},m=b;
@@ -1,8 +1,8 @@
1
- import { BillboardCollection, DataSourceCollection, EntityCollection, ImageryLayerCollection, LabelCollection, PointPrimitiveCollection, PolylineCollection, PrimitiveCollection, Billboard, DataSource, Entity, ImageryLayer, Label, PointPrimitive, Polyline, Primitive, Cesium3DTileset, GroundPrimitive } from 'cesium';
1
+ import { DataSourceCollection, EntityCollection, ImageryLayerCollection, PrimitiveCollection, DataSource, Entity, ImageryLayer, Billboard, Cesium3DTileset, GroundPrimitive, Label, PointPrimitive, Polyline, Primitive } from 'cesium';
2
2
 
3
- type CesiumCollection = BillboardCollection | DataSourceCollection | EntityCollection | ImageryLayerCollection | LabelCollection | PointPrimitiveCollection | PolylineCollection | PrimitiveCollection;
4
- type Primitives = Primitive | Cesium3DTileset | GroundPrimitive;
5
- type CesiumCollectionItem = Billboard | DataSource | Entity | ImageryLayer | Label | PointPrimitive | Polyline | Primitives;
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
6
  type Tag = string | number;
7
7
  interface WithTag {
8
8
  [key: symbol]: Tag;
@@ -146,6 +146,11 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
146
146
  * @private
147
147
  */
148
148
  private _eventListeners;
149
+ /**
150
+ * For cleaning up the instances
151
+ * @private
152
+ */
153
+ private _eventCleanupFunctions;
149
154
  /**
150
155
  * Creates a new Collection instance.
151
156
  *
@@ -202,6 +207,16 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
202
207
  * @private
203
208
  */
204
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;
205
220
  /**
206
221
  * Registers an event listener for collection events.
207
222
  *
@@ -287,6 +302,12 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
287
302
  * Removes all items from the collection.
288
303
  */
289
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;
290
311
  /**
291
312
  * Gets all item instances in the collection.
292
313
  * This array should not be modified directly.
@@ -1,8 +1,8 @@
1
- import { BillboardCollection, DataSourceCollection, EntityCollection, ImageryLayerCollection, LabelCollection, PointPrimitiveCollection, PolylineCollection, PrimitiveCollection, Billboard, DataSource, Entity, ImageryLayer, Label, PointPrimitive, Polyline, Primitive, Cesium3DTileset, GroundPrimitive } from 'cesium';
1
+ import { DataSourceCollection, EntityCollection, ImageryLayerCollection, PrimitiveCollection, DataSource, Entity, ImageryLayer, Billboard, Cesium3DTileset, GroundPrimitive, Label, PointPrimitive, Polyline, Primitive } from 'cesium';
2
2
 
3
- type CesiumCollection = BillboardCollection | DataSourceCollection | EntityCollection | ImageryLayerCollection | LabelCollection | PointPrimitiveCollection | PolylineCollection | PrimitiveCollection;
4
- type Primitives = Primitive | Cesium3DTileset | GroundPrimitive;
5
- type CesiumCollectionItem = Billboard | DataSource | Entity | ImageryLayer | Label | PointPrimitive | Polyline | Primitives;
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
6
  type Tag = string | number;
7
7
  interface WithTag {
8
8
  [key: symbol]: Tag;
@@ -146,6 +146,11 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
146
146
  * @private
147
147
  */
148
148
  private _eventListeners;
149
+ /**
150
+ * For cleaning up the instances
151
+ * @private
152
+ */
153
+ private _eventCleanupFunctions;
149
154
  /**
150
155
  * Creates a new Collection instance.
151
156
  *
@@ -202,6 +207,16 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
202
207
  * @private
203
208
  */
204
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;
205
220
  /**
206
221
  * Registers an event listener for collection events.
207
222
  *
@@ -287,6 +302,12 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
287
302
  * Removes all items from the collection.
288
303
  */
289
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;
290
311
  /**
291
312
  * Gets all item instances in the collection.
292
313
  * This array should not be modified directly.
@@ -1 +1 @@
1
- import"../chunk-RXMNSDKR.js";import{c as a}from"../chunk-YHYFSR66.js";export{a as Collection};
1
+ import"../chunk-RXMNSDKR.js";import{c as a}from"../chunk-I53ZQ7WC.js";export{a as Collection};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var L=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var $=(n,e)=>{for(var t in e)L(n,t,{get:e[t],enumerable:!0})},K=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of U(e))!X.call(n,r)&&r!==t&&L(n,r,{get:()=>e[r],enumerable:!(i=q(e,r))||i.enumerable});return n};var J=n=>K(L({},"__esModule",{value:!0}),n);var Q={};$(Q,{Collection:()=>y,Highlight:()=>C,HybridTerrainProvider:()=>A,TerrainArea:()=>g,TerrainAreaCollection:()=>p,TerrainVisualizer:()=>v,cloneViewer:()=>k,computeRectangle:()=>w,isGetterOnly:()=>P,syncCamera:()=>R});module.exports=J(Q);var _=require("cesium");var c=require("cesium");var v=class n{_viewer;_collection;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",c.Color.RED],["default",c.Color.BLUE],["fallback",c.Color.GRAY],["grid",c.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new y({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),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,this._ensureTileCoordinatesLayer();let t=this._getVisibleRectangle();if(!t||!this._isValidRectangle(t)){console.warn("Invalid visible rectangle detected, skipping grid display");return}this._displayTileGrid(t,e),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new c.TileCoordinatesImageryProvider({tilingScheme:this._terrainProvider.tilingScheme,color:c.Color.YELLOW})))}_isValidRectangle(e){return e&&Number.isFinite(e.west)&&Number.isFinite(e.south)&&Number.isFinite(e.east)&&Number.isFinite(e.north)&&e.west<=e.east&&e.south<=e.north}_displayTileGrid(e,t){let i=this._terrainProvider.tilingScheme;try{let r=this._calculateTileBounds(e,t,i);this._generateVisibleTiles(r,t,i).forEach(l=>{this._collection.add(l.entity,n.tag.grid)})}catch(r){console.error("Error displaying tile grid:",r)}}_calculateTileBounds(e,t,i){let r=i.positionToTileXY(c.Rectangle.northwest(e),t),o=i.positionToTileXY(c.Rectangle.southeast(e),t);if(!r||!o)throw new Error("Failed to calculate tile bounds");return{start:r,end:o}}_generateVisibleTiles(e,t,i){let r=[],l=Math.min(e.end.x-e.start.x+1,100),s=Math.min(e.end.y-e.start.y+1,100);for(let h=e.start.x;h<e.start.x+l;h++)for(let m=e.start.y;m<e.start.y+s;m++)try{let f=this._createTileEntity(h,m,t,i);f&&r.push({entity:f})}catch(f){console.warn(`Error creating tile (${h}, ${m}, ${t}):`,f)}return r}_createTileEntity(e,t,i,r){let o=r.tileXYToRectangle(e,t,i);if(!this._isValidRectangle(o))return null;let l=this._getTileColor(e,t,i),s=n.createRectangle(o,l.withAlpha(.3));return s.properties?.addProperty("tileX",e),s.properties?.addProperty("tileY",t),s.properties?.addProperty("tileLevel",i),s}_getTileColor(e,t,i){if(!this._terrainProvider)return this._colors.get("fallback")||c.Color.TRANSPARENT;for(let r of this._terrainProvider.terrainAreas)if(r.contains(e,t,i))return r.isCustom?this._colors.get("custom")||c.Color.RED:this._colors.get("default")||c.Color.BLUE;return this._terrainProvider.getTileDataAvailable(e,t,i)?this._colors.get("default")||c.Color.BLUE:this._colors.get("fallback")||c.Color.GRAY}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,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...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}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,o){return new c.Entity({rectangle:{coordinates:r,material:o,heightReference:c.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,o,l){let s=l?.tag||"terrain_area_visualization",h=l?.color||c.Color.RED,m=l?.maxTilesToShow||100,f=l?.show??!0,E=l?.alpha||.7,I=l?.tileAlpha||.2,S=new y({collection:o.entities,tag:s}),{rectangle:B}=r;if(S.add(i.createRectangle(B,h.withAlpha(E)),s),f&&r.tileRanges.size>0){let{tilingScheme:Y}=r.terrainProvider,O=0;r.tileRanges.forEach((x,j)=>{for(let V=x.start.x;V<=x.end.x&&O<m;V++)for(let M=x.start.y;M<=x.end.y&&O<m;M++){let W=Y.tileXYToRectangle(V,M,j);S.add(e(W,h.withAlpha(I)),`${s}_tile`),O++}})}return S}i.visualize=t})(v||={});function P(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}var G=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 i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(o=>o(r))}}_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],i=this._tagMap.get(t);i&&(i.delete(e),i.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,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),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 r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let o of e)this.remove(o)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}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 i=this.get(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}show(e){let t=this.get(e);for(let i of t)(0,_.defined)(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)(0,_.defined)(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)(0,_.defined)(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let o of r)if(e in o&&typeof o[e]!="function"){if(P(o,e))throw Error(`Cannot set read-only property '${String(e)}' on ${o.constructor.name}`);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((r,o)=>e(r,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)}},y=G;var d=require("cesium");var u=require("cesium"),T=class{_color=u.Color.RED;_silhouette;_composite;_stages;_entity;constructor(e){this._stages=e.scene.postProcessStages,this._silhouette=u.PostProcessStageLibrary.createEdgeDetectionStage(),this._silhouette.uniforms.color=this._color,this._silhouette.uniforms.length=.01,this._silhouette.selected=[],this._composite=u.PostProcessStageLibrary.createSilhouetteStage([this._silhouette]),this._stages.add(this._composite)}show(e,t){if(!(!(0,u.defined)(e)||this._silhouette.selected[0]===e))if(e instanceof u.Cesium3DTileFeature)this._silhouette.uniforms.color=t?.color||this._color,this._silhouette.selected.push(e);else{if(!e.model)return;this._entity=e,e.model.silhouetteSize=new u.ConstantProperty(t?.width||2),e.model.silhouetteColor=new u.ConstantProperty(t?.color||this._color)}}hide(){this._silhouette.selected.length>0&&(this._silhouette.selected=[]),this._entity?.model&&(this._entity.model.silhouetteColor=new u.ConstantProperty(u.Color.TRANSPARENT),this._entity=void 0)}destroy(){this.hide(),this._composite&&this._stages.remove(this._composite)}get color(){return this._color}set color(e){this._color=e}};var a=require("cesium"),b=class{_color=a.Color.RED;_entity;_entities;constructor(e){this._entities=e.entities,this._entity=this._entities.add(new a.Entity({id:`highlight-entity-${Math.random().toString(36).substring(2)}`,show:!1}))}show(e,t){if(!(!(0,a.defined)(e)||!this._entity)){this._clearGeometries();try{if(e instanceof a.Entity&&(e.polygon||e.polyline||e.rectangle))this._update(e,t);else if(e instanceof a.GroundPrimitive)this._update(e,t);else return;return this._entity.show=!0,this._entity}catch(i){console.error("Failed to highlight object:",i);return}}}_clearGeometries(){this._entity.polygon=void 0,this._entity.polyline=void 0,this._entity.rectangle=void 0}_update(e,t={color:this._color,outline:!1,width:2}){if(e instanceof a.Entity){if(e.polygon)if(t.outline){let i=e.polygon.hierarchy?.getValue();if(i&&i.positions){let r;i.positions.length>0&&!a.Cartesian3.equals(i.positions[0],i.positions[i.positions.length-1])?r=[...i.positions,i.positions[0]]:r=i.positions,this._entity.polyline=new a.PolylineGraphics({positions:r,material:t.color,width:t.width||2,clampToGround:!0})}}else{let i=e.polygon.hierarchy?.getValue();i&&(this._entity.polygon=new a.PolygonGraphics({hierarchy:i,material:t.color,heightReference:a.HeightReference.CLAMP_TO_GROUND,classificationType:e.polygon.classificationType?.getValue()||a.ClassificationType.BOTH}))}else if(e.polyline){let i=e.polyline.positions?.getValue();if(i){let r=e.polyline.width?.getValue();this._entity.polyline=new a.PolylineGraphics({positions:i,material:t.color,width:r+(t.width||2),clampToGround:!0})}}else if(e.rectangle)if(t.outline){let i=e.rectangle.coordinates?.getValue();if(i){let r=[a.Cartesian3.fromRadians(i.west,i.north),a.Cartesian3.fromRadians(i.east,i.north),a.Cartesian3.fromRadians(i.east,i.south),a.Cartesian3.fromRadians(i.west,i.south),a.Cartesian3.fromRadians(i.west,i.north)];this._entity.polyline=new a.PolylineGraphics({positions:r,material:t.color,width:t.width||2,clampToGround:!0})}}else{let i=e.rectangle.coordinates?.getValue();i&&(this._entity.rectangle=new a.RectangleGraphics({coordinates:i,material:t.color,heightReference:a.HeightReference.CLAMP_TO_GROUND}))}}else if(e instanceof a.GroundPrimitive){let i=e.geometryInstances,r=Array.isArray(i)?i[0]:i;if(!r.geometry.attributes.position)return;let o=r.geometry.attributes.position.values,l=[];for(let s=0;s<o.length;s+=3)l.push(new a.Cartesian3(o[s],o[s+1],o[s+2]));t.outline?this._entity.polyline=new a.PolylineGraphics({positions:l,material:t.color,width:t.width||2,clampToGround:!0}):this._entity.polygon=new a.PolygonGraphics({hierarchy:new a.PolygonHierarchy(l),material:t.color,heightReference:a.HeightReference.CLAMP_TO_GROUND,classificationType:a.ClassificationType.BOTH})}}hide(){this._entity&&(this._entity.show=!1)}destroy(){this._entities.contains(this._entity)&&this._entities.remove(this._entity)}get color(){return this._color}set color(e){this._color=e}get entity(){return this._entity}};var C=class n{static instances=new WeakMap;_surface;_silhouette;_color=d.Color.RED;constructor(e){this._surface=new b(e),this._silhouette=new T(e),this._surface.color=this._color,this._silhouette.color=this._color}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,i=n.instances.get(t);i&&(i.hide(),i._surface&&i._surface.destroy(),i._silhouette&&i._silhouette.destroy(),n.instances.delete(t))}show(e,t={color:this._color}){this.hide();let i=this._getObject(e);if((0,d.defined)(i))return i instanceof d.Cesium3DTileFeature?this._silhouette.show(i,t):i instanceof d.Entity&&i.model?this._silhouette.show(i,t):this._surface.show(i,t)}_getObject(e){if((0,d.defined)(e)){if(e instanceof d.Entity||e instanceof d.Cesium3DTileFeature||e instanceof d.GroundPrimitive)return e;if(e.id instanceof d.Entity)return e.id;if(e.primitive instanceof d.GroundPrimitive)return e.primitive}}hide(){this._surface.hide(),this._silhouette.hide()}get color(){return this._color}set color(e){this._color=e,this._surface.color=e,this._silhouette.color=e}};var F=require("cesium");var N=require("cesium");var H=require("cesium");function w(n,e){if(e.size===0)return new H.Rectangle;let t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,l=Array.from(e.keys()),s=Math.min(...l),h=e.get(s);if(h){let{start:m,end:f}=h,E=n.tileXYToRectangle(m.x,m.y,s),I=n.tileXYToRectangle(f.x,f.y,s);t=Math.min(E.west,t),i=Math.min(I.south,i),r=Math.max(I.east,r),o=Math.max(E.north,o)}return new H.Rectangle(t,i,r,o)}var g=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=w(e.terrainProvider.tilingScheme,e.tileRanges),e.tileRanges.forEach((t,i)=>{this._terrainProvider.availability?.addAvailableTileRange(i,t.start.x,t.start.y,t.end.x,t.end.y)}),this._ready=!0}contains(e,t,i){if(this._tileRanges.size===0||!this._tileRanges.has(i))return!1;let r=this._tileRanges.get(i);return e>=r.start.x&&e<=r.end.x&&t>=r.start.y&&t<=r.end.y}requestTileGeometry(e,t,i,r){if(!(!this._ready||!this.contains(e,t,i)))return this._terrainProvider.requestTileGeometry(e,t,i,r)}getTileDataAvailable(e,t,i){if(this._tileRanges.size===0||!this._tileRanges.has(i))return!1;let r=this._tileRanges.get(i);return e>=r.start.x&&e<=r.end.x&&t>=r.start.y&&t<=r.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,i,r){let o=r?.credit||"custom",l=await N.CesiumTerrainProvider.fromUrl(t,{...r,credit:o});return new e({terrainProvider:l,tileRanges:i,credit:o})}e.fromUrl=n})(g||={});var p=class extends Array{add(e){if(Array.isArray(e)){for(let i of e)this.add(i);return this.length}let t;return e instanceof g?t=e:t=new g(e),this.push(t)}remove(e){if(Array.isArray(e))return e.forEach(i=>this.remove(i)),this;let t=this.indexOf(e);return t>=0&&this.splice(t,1),this}removeAll(){this.length=0}};var A=class{_terrainAreas=new p;_terrainProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(e){this._terrainProvider=e.terrainProvider,this._fallbackProvider=e.fallbackProvider||new F.EllipsoidTerrainProvider,this._tilingScheme=e.terrainProvider.tilingScheme,this._terrainAreas=new p(...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,i){return this._terrainProvider.loadTileDataAvailability(e,t,i)}getLevelMaximumGeometricError(e){return this._terrainProvider.getLevelMaximumGeometricError(e)}requestTileGeometry(e,t,i,r){if(this._ready){for(let o of this._terrainAreas)if(o.contains(e,t,i))return o.requestTileGeometry(e,t,i,r);return this._terrainProvider.getTileDataAvailable(e,t,i)?this._terrainProvider.requestTileGeometry(e,t,i,r):this._fallbackProvider.requestTileGeometry(e,t,i,r)}}getTileDataAvailable(e,t,i){for(let r of this._terrainAreas)if(r.contains(e,t,i))return r.getTileDataAvailable(e,t,i);return this._terrainProvider.getTileDataAvailable(e,t,i)}};var z=require("cesium");var D=require("cesium");function R(n,e){if((0,D.defined)(n)&&(0,D.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 i={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},r=new z.Viewer(e,{...i,...t});R(n,r);let o=n.imageryLayers;r.imageryLayers.removeAll();for(let h=0;h<o.length;h++){let m=o.get(h);r.imageryLayers.addImageryProvider(m.imageryProvider,h)}r.clock.startTime=n.clock.startTime.clone(),r.clock.stopTime=n.clock.stopTime.clone(),r.clock.currentTime=n.clock.currentTime.clone(),r.clock.multiplier=n.clock.multiplier,r.clock.clockStep=n.clock.clockStep,r.clock.clockRange=n.clock.clockRange,r.clock.shouldAnimate=n.clock.shouldAnimate,r.scene.globe.enableLighting=n.scene.globe.enableLighting,r.scene.globe.depthTestAgainstTerrain=n.scene.globe.depthTestAgainstTerrain,r.scene.screenSpaceCameraController.enableCollisionDetection=n.scene.screenSpaceCameraController.enableCollisionDetection;let l=n.scene.screenSpaceCameraController.tiltEventTypes;l&&(r.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(l)?[...l]:l);let s=n.scene.screenSpaceCameraController.zoomEventTypes;return s&&(r.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(s)?[...s]:s),r}
1
+ "use strict";var V=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var $=(n,e)=>{for(var t in e)V(n,t,{get:e[t],enumerable:!0})},K=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of U(e))!X.call(n,r)&&r!==t&&V(n,r,{get:()=>e[r],enumerable:!(i=q(e,r))||i.enumerable});return n};var J=n=>K(V({},"__esModule",{value:!0}),n);var Q={};$(Q,{Collection:()=>C,Highlight:()=>b,HybridTerrainProvider:()=>A,SilhouetteHighlight:()=>_,SurfaceHighlight:()=>y,TerrainArea:()=>v,TerrainAreaCollection:()=>p,TerrainVisualizer:()=>T,cloneViewer:()=>k,computeRectangle:()=>w,isGetterOnly:()=>P,syncCamera:()=>E});module.exports=J(Q);var m=require("cesium");var h=require("cesium");var T=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 C({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),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,this._ensureTileCoordinatesLayer();let t=this._getVisibleRectangle();if(!t||!this._isValidRectangle(t)){console.warn("Invalid visible rectangle detected, skipping grid display");return}this._displayTileGrid(t,e),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new h.TileCoordinatesImageryProvider({tilingScheme:this._terrainProvider.tilingScheme,color:h.Color.YELLOW})))}_isValidRectangle(e){return e&&Number.isFinite(e.west)&&Number.isFinite(e.south)&&Number.isFinite(e.east)&&Number.isFinite(e.north)&&e.west<=e.east&&e.south<=e.north}_displayTileGrid(e,t){let i=this._terrainProvider.tilingScheme;try{let r=this._calculateTileBounds(e,t,i);this._generateVisibleTiles(r,t,i).forEach(l=>{this._collection.add(l.entity,n.tag.grid)})}catch(r){console.error("Error displaying tile grid:",r)}}_calculateTileBounds(e,t,i){let r=i.positionToTileXY(h.Rectangle.northwest(e),t),o=i.positionToTileXY(h.Rectangle.southeast(e),t);if(!r||!o)throw new Error("Failed to calculate tile bounds");return{start:r,end:o}}_generateVisibleTiles(e,t,i){let r=[],l=Math.min(e.end.x-e.start.x+1,100),s=Math.min(e.end.y-e.start.y+1,100);for(let c=e.start.x;c<e.start.x+l;c++)for(let g=e.start.y;g<e.start.y+s;g++)try{let f=this._createTileEntity(c,g,t,i);f&&r.push({entity:f})}catch(f){console.warn(`Error creating tile (${c}, ${g}, ${t}):`,f)}return r}_createTileEntity(e,t,i,r){let o=r.tileXYToRectangle(e,t,i);if(!this._isValidRectangle(o))return null;let l=this._getTileColor(e,t,i),s=n.createRectangle(o,l.withAlpha(.3));return s.properties?.addProperty("tileX",e),s.properties?.addProperty("tileY",t),s.properties?.addProperty("tileLevel",i),s}_getTileColor(e,t,i){if(!this._terrainProvider)return this._colors.get("fallback")||h.Color.TRANSPARENT;for(let r of this._terrainProvider.terrainAreas)if(r.contains(e,t,i))return r.isCustom?this._colors.get("custom")||h.Color.RED:this._colors.get("default")||h.Color.BLUE;return this._terrainProvider.getTileDataAvailable(e,t,i)?this._colors.get("default")||h.Color.BLUE:this._colors.get("fallback")||h.Color.GRAY}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,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...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}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,o){return new h.Entity({rectangle:{coordinates:r,material:o,heightReference:h.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,o,l){let s=l?.tag||"terrain_area_visualization",c=l?.color||h.Color.RED,g=l?.maxTilesToShow||100,f=l?.show??!0,R=l?.alpha||.7,I=l?.tileAlpha||.2,x=new C({collection:o.entities,tag:s}),{rectangle:B}=r;if(x.add(i.createRectangle(B,c.withAlpha(R)),s),f&&r.tileRanges.size>0){let{tilingScheme:Y}=r.terrainProvider,L=0;r.tileRanges.forEach((S,j)=>{for(let O=S.start.x;O<=S.end.x&&L<g;O++)for(let M=S.start.y;M<=S.end.y&&L<g;M++){let W=Y.tileXYToRectangle(O,M,j);x.add(e(W,c.withAlpha(I)),`${s}_tile`),L++}})}return x}i.visualize=t})(T||={});function P(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}var H=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;_eventCleanupFunctions=[];constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e,this._setupCacheInvalidator(e)}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(o=>o(r))}}_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],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache=()=>{this._valuesCache=null};_setupCacheInvalidator(e){e instanceof m.EntityCollection?(e.collectionChanged.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.collectionChanged.removeEventListener(this._invalidateCache))):e instanceof m.PrimitiveCollection?(e.primitiveAdded.addEventListener(this._invalidateCache),e.primitiveRemoved.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.primitiveAdded.removeEventListener(this._invalidateCache),()=>e.primitiveRemoved.removeEventListener(this._invalidateCache))):e instanceof m.DataSourceCollection?(e.dataSourceAdded.addEventListener(this._invalidateCache),e.dataSourceMoved.addEventListener(this._invalidateCache),e.dataSourceRemoved.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.dataSourceAdded.removeEventListener(this._invalidateCache),()=>e.dataSourceMoved.removeEventListener(this._invalidateCache),()=>e.dataSourceRemoved.removeEventListener(this._invalidateCache))):e instanceof m.ImageryLayerCollection&&(e.layerAdded.addEventListener(this._invalidateCache),e.layerMoved.addEventListener(this._invalidateCache),e.layerRemoved.addEventListener(this._invalidateCache),e.layerShownOrHidden.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.layerAdded.removeEventListener(this._invalidateCache),()=>e.layerMoved.removeEventListener(this._invalidateCache),()=>e.layerRemoved.removeEventListener(this._invalidateCache),()=>e.layerShownOrHidden.removeEventListener(this._invalidateCache)))}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,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),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 r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let o of e)this.remove(o)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}destroy(){this._eventCleanupFunctions.forEach(e=>e()),this._eventCleanupFunctions=[],this._tagMap.clear(),this._eventListeners.clear(),this._valuesCache=null}get values(){if(this._valuesCache!==null)return this._valuesCache;let e;if(this.collection instanceof m.EntityCollection)e=this.collection.values;else{e=[];for(let t=0;t<this.collection.length;t++)e.push(this.collection.get(t))}return this._valuesCache=e,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 i=this.get(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}show(e){let t=this.get(e);for(let i of t)(0,m.defined)(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)(0,m.defined)(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)(0,m.defined)(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let o of r)if(e in o&&typeof o[e]!="function"){if(P(o,e))throw Error(`Cannot set read-only property '${String(e)}' on ${o.constructor.name}`);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((r,o)=>e(r,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)}},C=H;var u=require("cesium");var d=require("cesium"),_=class{_color=d.Color.RED;_silhouette;_composite;_stages;_entity;constructor(e){this._stages=e.scene.postProcessStages,this._silhouette=d.PostProcessStageLibrary.createEdgeDetectionStage(),this._silhouette.uniforms.color=this._color,this._silhouette.uniforms.length=.01,this._silhouette.selected=[],this._composite=d.PostProcessStageLibrary.createSilhouetteStage([this._silhouette]),this._stages.add(this._composite)}show(e,t){if(!(!(0,d.defined)(e)||this._silhouette.selected[0]===e))if(e instanceof d.Cesium3DTileFeature)this._silhouette.uniforms.color=t?.color||this._color,this._silhouette.selected.push(e);else{if(!e.model)return;this._entity=e,e.model.silhouetteSize=new d.ConstantProperty(t?.width||2),e.model.silhouetteColor=new d.ConstantProperty(t?.color||this._color)}}hide(){this._silhouette.selected.length>0&&(this._silhouette.selected=[]),this._entity?.model&&(this._entity.model.silhouetteColor=new d.ConstantProperty(d.Color.TRANSPARENT),this._entity.model.silhouetteSize=new d.ConstantProperty(0),this._entity=void 0)}destroy(){this.hide(),this._composite&&this._stages.remove(this._composite)}get color(){return this._color}set color(e){this._color=e}};var a=require("cesium"),y=class{_color=a.Color.RED;_entity;_entities;constructor(e){this._entities=e.entities,this._entity=this._entities.add(new a.Entity({id:`highlight-entity-${Math.random().toString(36).substring(2)}`,show:!1}))}show(e,t){if(!(!(0,a.defined)(e)||!this._entity)){this._clearGeometries();try{if(e instanceof a.Entity&&(e.polygon||e.polyline||e.rectangle))this._update(e,t);else if(e instanceof a.GroundPrimitive)this._update(e,t);else return;return this._entity.show=!0,this._entity}catch(i){console.error("Failed to highlight object:",i);return}}}_clearGeometries(){this._entity.polygon=void 0,this._entity.polyline=void 0,this._entity.rectangle=void 0}_update(e,t={color:this._color,outline:!1,width:2}){if(e instanceof a.Entity){if(e.polygon)if(t.outline){let i=e.polygon.hierarchy?.getValue();if(i&&i.positions){let r;i.positions.length>0&&!a.Cartesian3.equals(i.positions[0],i.positions[i.positions.length-1])?r=[...i.positions,i.positions[0]]:r=i.positions,this._entity.polyline=new a.PolylineGraphics({positions:r,material:t.color,width:t.width||2,clampToGround:!0})}}else{let i=e.polygon.hierarchy?.getValue();i&&(this._entity.polygon=new a.PolygonGraphics({hierarchy:i,material:t.color,heightReference:a.HeightReference.CLAMP_TO_GROUND,classificationType:e.polygon.classificationType?.getValue()||a.ClassificationType.BOTH}))}else if(e.polyline){let i=e.polyline.positions?.getValue();if(i){let r=e.polyline.width?.getValue();this._entity.polyline=new a.PolylineGraphics({positions:i,material:t.color,width:r+(t.width||2),clampToGround:!0})}}else if(e.rectangle)if(t.outline){let i=e.rectangle.coordinates?.getValue();if(i){let r=[a.Cartesian3.fromRadians(i.west,i.north),a.Cartesian3.fromRadians(i.east,i.north),a.Cartesian3.fromRadians(i.east,i.south),a.Cartesian3.fromRadians(i.west,i.south),a.Cartesian3.fromRadians(i.west,i.north)];this._entity.polyline=new a.PolylineGraphics({positions:r,material:t.color,width:t.width||2,clampToGround:!0})}}else{let i=e.rectangle.coordinates?.getValue();i&&(this._entity.rectangle=new a.RectangleGraphics({coordinates:i,material:t.color,heightReference:a.HeightReference.CLAMP_TO_GROUND}))}}else if(e instanceof a.GroundPrimitive){let i=e.geometryInstances,r=Array.isArray(i)?i[0]:i;if(!r.geometry.attributes.position)return;let o=r.geometry.attributes.position.values,l=[];for(let s=0;s<o.length;s+=3)l.push(new a.Cartesian3(o[s],o[s+1],o[s+2]));t.outline?this._entity.polyline=new a.PolylineGraphics({positions:l,material:t.color,width:t.width||2,clampToGround:!0}):this._entity.polygon=new a.PolygonGraphics({hierarchy:new a.PolygonHierarchy(l),material:t.color,heightReference:a.HeightReference.CLAMP_TO_GROUND,classificationType:a.ClassificationType.BOTH})}}hide(){this._entity&&(this._entity.show=!1)}destroy(){this._entities.contains(this._entity)&&this._entities.remove(this._entity)}get color(){return this._color}set color(e){this._color=e}get entity(){return this._entity}};var b=class n{static instances=new WeakMap;_surface;_silhouette;_color=u.Color.RED;constructor(e){this._surface=new y(e),this._silhouette=new _(e),this._surface.color=this._color,this._silhouette.color=this._color}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,i=n.instances.get(t);i&&(i.hide(),i._surface&&i._surface.destroy(),i._silhouette&&i._silhouette.destroy(),n.instances.delete(t))}show(e,t={color:this._color}){this.hide();let i=this._getObject(e);if((0,u.defined)(i))return i instanceof u.Cesium3DTileFeature?this._silhouette.show(i,t):i instanceof u.Entity&&i.model?this._silhouette.show(i,t):this._surface.show(i,t)}_getObject(e){if((0,u.defined)(e)){if(e instanceof u.Entity||e instanceof u.Cesium3DTileFeature||e instanceof u.GroundPrimitive)return e;if(e.id instanceof u.Entity)return e.id;if(e.primitive instanceof u.GroundPrimitive)return e.primitive}}hide(){this._surface.hide(),this._silhouette.hide()}get color(){return this._color}set color(e){this._color=e,this._surface.color=e,this._silhouette.color=e}};var F=require("cesium");var N=require("cesium");var G=require("cesium");function w(n,e){if(e.size===0)return new G.Rectangle;let t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,l=Array.from(e.keys()),s=Math.min(...l),c=e.get(s);if(c){let{start:g,end:f}=c,R=n.tileXYToRectangle(g.x,g.y,s),I=n.tileXYToRectangle(f.x,f.y,s);t=Math.min(R.west,t),i=Math.min(I.south,i),r=Math.max(I.east,r),o=Math.max(R.north,o)}return new G.Rectangle(t,i,r,o)}var v=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=w(e.terrainProvider.tilingScheme,e.tileRanges),e.tileRanges.forEach((t,i)=>{this._terrainProvider.availability?.addAvailableTileRange(i,t.start.x,t.start.y,t.end.x,t.end.y)}),this._ready=!0}contains(e,t,i){if(this._tileRanges.size===0||!this._tileRanges.has(i))return!1;let r=this._tileRanges.get(i);return e>=r.start.x&&e<=r.end.x&&t>=r.start.y&&t<=r.end.y}requestTileGeometry(e,t,i,r){if(!(!this._ready||!this.contains(e,t,i)))return this._terrainProvider.requestTileGeometry(e,t,i,r)}getTileDataAvailable(e,t,i){if(this._tileRanges.size===0||!this._tileRanges.has(i))return!1;let r=this._tileRanges.get(i);return e>=r.start.x&&e<=r.end.x&&t>=r.start.y&&t<=r.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,i,r){let o=r?.credit||"custom",l=await N.CesiumTerrainProvider.fromUrl(t,{...r,credit:o});return new e({terrainProvider:l,tileRanges:i,credit:o})}e.fromUrl=n})(v||={});var p=class extends Array{add(e){if(Array.isArray(e)){for(let i of e)this.add(i);return this.length}let t;return e instanceof v?t=e:t=new v(e),this.push(t)}remove(e){if(Array.isArray(e))return e.forEach(i=>this.remove(i)),this;let t=this.indexOf(e);return t>=0&&this.splice(t,1),this}removeAll(){this.length=0}};var A=class{_terrainAreas=new p;_terrainProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(e){this._terrainProvider=e.terrainProvider,this._fallbackProvider=e.fallbackProvider||new F.EllipsoidTerrainProvider,this._tilingScheme=e.terrainProvider.tilingScheme,this._terrainAreas=new p(...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,i){return this._terrainProvider.loadTileDataAvailability(e,t,i)}getLevelMaximumGeometricError(e){return this._terrainProvider.getLevelMaximumGeometricError(e)}requestTileGeometry(e,t,i,r){if(this._ready){for(let o of this._terrainAreas)if(o.contains(e,t,i))return o.requestTileGeometry(e,t,i,r);return this._terrainProvider.getTileDataAvailable(e,t,i)?this._terrainProvider.requestTileGeometry(e,t,i,r):this._fallbackProvider.requestTileGeometry(e,t,i,r)}}getTileDataAvailable(e,t,i){for(let r of this._terrainAreas)if(r.contains(e,t,i))return r.getTileDataAvailable(e,t,i);return this._terrainProvider.getTileDataAvailable(e,t,i)}};var z=require("cesium");var D=require("cesium");function E(n,e){if((0,D.defined)(n)&&(0,D.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 i={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},r=new z.Viewer(e,{...i,...t});E(n,r);let o=n.imageryLayers;r.imageryLayers.removeAll();for(let c=0;c<o.length;c++){let g=o.get(c);r.imageryLayers.addImageryProvider(g.imageryProvider,c)}r.clock.startTime=n.clock.startTime.clone(),r.clock.stopTime=n.clock.stopTime.clone(),r.clock.currentTime=n.clock.currentTime.clone(),r.clock.multiplier=n.clock.multiplier,r.clock.clockStep=n.clock.clockStep,r.clock.clockRange=n.clock.clockRange,r.clock.shouldAnimate=n.clock.shouldAnimate,r.scene.globe.enableLighting=n.scene.globe.enableLighting,r.scene.globe.depthTestAgainstTerrain=n.scene.globe.depthTestAgainstTerrain,r.scene.screenSpaceCameraController.enableCollisionDetection=n.scene.screenSpaceCameraController.enableCollisionDetection;let l=n.scene.screenSpaceCameraController.tiltEventTypes;l&&(r.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(l)?[...l]:l);let s=n.scene.screenSpaceCameraController.zoomEventTypes;return s&&(r.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(s)?[...s]:s),r}
package/dist/index.d.cts CHANGED
@@ -97,4 +97,129 @@ declare class Highlight {
97
97
  set color(color: Color);
98
98
  }
99
99
 
100
- export { Highlight, type HighlightOptions, type IHighlight, type Picked, type PickedObject };
100
+ /**
101
+ * @class
102
+ * An implementation for highlighting 3D objects in Cesium.
103
+ *
104
+ * **Supported Object Types:**
105
+ * - `Entity` with model graphics. (adjustable outline width)
106
+ * - `Cesium3DTileset` instances. (fixed outline width)
107
+ *
108
+ * Currently supports outline style only.
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const viewer = new Viewer("cesiumContainer");
113
+ * const silhouetteHighlight = new SilhouetteHighlight(viewer);
114
+ *
115
+ * // Highlight an object
116
+ * const entity = viewer.entities.add(new Entity({
117
+ * model: new ModelGraphics(),
118
+ * }));
119
+ * silhouetteHighlight.show(entity);
120
+ * ```
121
+ */
122
+ declare class SilhouetteHighlight implements IHighlight {
123
+ private _color;
124
+ private _silhouette;
125
+ private _composite;
126
+ private _stages;
127
+ private _entity?;
128
+ /**
129
+ * Creates a new `Silhouette` instance.
130
+ * @param viewer A viewer to create highlight silhouette in
131
+ */
132
+ constructor(viewer: Viewer);
133
+ /**
134
+ * Highlights a picked `Cesium3DTileset` by updating silhouette composite.
135
+ * @param object The object to be highlighted.
136
+ * @param options Optional style for the highlight.
137
+ */
138
+ show(object: Cesium3DTileFeature, options?: HighlightOptions): void;
139
+ /**
140
+ * Highlights a picked `Entity` by updating the model properties.
141
+ * @param object The object to be highlighted.
142
+ * @param options Optional style for the highlight.
143
+ */
144
+ show(object: Entity, options?: HighlightOptions): void;
145
+ /** Clears the current highlight */
146
+ hide(): void;
147
+ /** Clean up the instances */
148
+ destroy(): void;
149
+ /** Gets the highlight color. */
150
+ get color(): Color;
151
+ /** Sets the highlight color. */
152
+ set color(color: Color);
153
+ }
154
+
155
+ /**
156
+ * @class
157
+ * A flyweight implementation for highlighting 2D surface objects in Cesium.
158
+ *
159
+ * This class provides highlighting for ground-clamped geometries (polygons, polylines, rectangles)
160
+ *
161
+ * **Supported Geometry Types:**
162
+ * - `Entity` with polygon, polyline, or rectangle graphics
163
+ * - `GroundPrimitive` instances
164
+ *
165
+ * **Highlighting Modes:**
166
+ * - **Fill mode** (default): Creates a filled geometry using the original shape
167
+ * - **Outline mode**: Creates a polyline outline of the original geometry
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * // Basic usage
172
+ * const viewer = new Viewer('cesiumContainer');
173
+ * const surfaceHighlight = new SurfaceHighlight(viewer);
174
+ *
175
+ * // Highlight an entity with default red fill
176
+ * const entity = viewer.entities.add(new Entity({
177
+ * polygon: {
178
+ * hierarchy: Cartesian3.fromDegreesArray([-75, 35, -74, 35, -74, 36, -75, 36]),
179
+ * material: Color.BLUE
180
+ * }
181
+ * }));
182
+ * surfaceHighlight.show(entity);
183
+ * ```
184
+ */
185
+ declare class SurfaceHighlight implements IHighlight {
186
+ private _color;
187
+ private _entity;
188
+ private _entities;
189
+ /**
190
+ * Creates a new `SurfaceHighlight` instance.
191
+ * @param viewer A viewer to create highlight entity in
192
+ */
193
+ constructor(viewer: Viewer);
194
+ /**
195
+ * Highlights a picked object by updating the reusable entity
196
+ * @param object The object to be highlighted.
197
+ * @param options Optional style for the highlight.
198
+ * @see {@link HighlightOptions}
199
+ */
200
+ show(object: Entity | GroundPrimitive, options?: HighlightOptions): Entity | undefined;
201
+ /**
202
+ * Removes all geometry properties from the highlight entity
203
+ * @private
204
+ */
205
+ private _clearGeometries;
206
+ /**
207
+ * Updates the highlight entity from an Entity object
208
+ * @private
209
+ */
210
+ private _update;
211
+ /**
212
+ * Clears the current highlight
213
+ */
214
+ hide(): void;
215
+ /** Clean up the instances */
216
+ destroy(): void;
217
+ /** Gets the highlight color. */
218
+ get color(): Color;
219
+ /** Sets the highlight color. */
220
+ set color(color: Color);
221
+ /** Gets the highlight entity */
222
+ get entity(): Entity;
223
+ }
224
+
225
+ export { Highlight, type HighlightOptions, type IHighlight, type Picked, type PickedObject, SilhouetteHighlight, SurfaceHighlight };
package/dist/index.d.ts CHANGED
@@ -97,4 +97,129 @@ declare class Highlight {
97
97
  set color(color: Color);
98
98
  }
99
99
 
100
- export { Highlight, type HighlightOptions, type IHighlight, type Picked, type PickedObject };
100
+ /**
101
+ * @class
102
+ * An implementation for highlighting 3D objects in Cesium.
103
+ *
104
+ * **Supported Object Types:**
105
+ * - `Entity` with model graphics. (adjustable outline width)
106
+ * - `Cesium3DTileset` instances. (fixed outline width)
107
+ *
108
+ * Currently supports outline style only.
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const viewer = new Viewer("cesiumContainer");
113
+ * const silhouetteHighlight = new SilhouetteHighlight(viewer);
114
+ *
115
+ * // Highlight an object
116
+ * const entity = viewer.entities.add(new Entity({
117
+ * model: new ModelGraphics(),
118
+ * }));
119
+ * silhouetteHighlight.show(entity);
120
+ * ```
121
+ */
122
+ declare class SilhouetteHighlight implements IHighlight {
123
+ private _color;
124
+ private _silhouette;
125
+ private _composite;
126
+ private _stages;
127
+ private _entity?;
128
+ /**
129
+ * Creates a new `Silhouette` instance.
130
+ * @param viewer A viewer to create highlight silhouette in
131
+ */
132
+ constructor(viewer: Viewer);
133
+ /**
134
+ * Highlights a picked `Cesium3DTileset` by updating silhouette composite.
135
+ * @param object The object to be highlighted.
136
+ * @param options Optional style for the highlight.
137
+ */
138
+ show(object: Cesium3DTileFeature, options?: HighlightOptions): void;
139
+ /**
140
+ * Highlights a picked `Entity` by updating the model properties.
141
+ * @param object The object to be highlighted.
142
+ * @param options Optional style for the highlight.
143
+ */
144
+ show(object: Entity, options?: HighlightOptions): void;
145
+ /** Clears the current highlight */
146
+ hide(): void;
147
+ /** Clean up the instances */
148
+ destroy(): void;
149
+ /** Gets the highlight color. */
150
+ get color(): Color;
151
+ /** Sets the highlight color. */
152
+ set color(color: Color);
153
+ }
154
+
155
+ /**
156
+ * @class
157
+ * A flyweight implementation for highlighting 2D surface objects in Cesium.
158
+ *
159
+ * This class provides highlighting for ground-clamped geometries (polygons, polylines, rectangles)
160
+ *
161
+ * **Supported Geometry Types:**
162
+ * - `Entity` with polygon, polyline, or rectangle graphics
163
+ * - `GroundPrimitive` instances
164
+ *
165
+ * **Highlighting Modes:**
166
+ * - **Fill mode** (default): Creates a filled geometry using the original shape
167
+ * - **Outline mode**: Creates a polyline outline of the original geometry
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * // Basic usage
172
+ * const viewer = new Viewer('cesiumContainer');
173
+ * const surfaceHighlight = new SurfaceHighlight(viewer);
174
+ *
175
+ * // Highlight an entity with default red fill
176
+ * const entity = viewer.entities.add(new Entity({
177
+ * polygon: {
178
+ * hierarchy: Cartesian3.fromDegreesArray([-75, 35, -74, 35, -74, 36, -75, 36]),
179
+ * material: Color.BLUE
180
+ * }
181
+ * }));
182
+ * surfaceHighlight.show(entity);
183
+ * ```
184
+ */
185
+ declare class SurfaceHighlight implements IHighlight {
186
+ private _color;
187
+ private _entity;
188
+ private _entities;
189
+ /**
190
+ * Creates a new `SurfaceHighlight` instance.
191
+ * @param viewer A viewer to create highlight entity in
192
+ */
193
+ constructor(viewer: Viewer);
194
+ /**
195
+ * Highlights a picked object by updating the reusable entity
196
+ * @param object The object to be highlighted.
197
+ * @param options Optional style for the highlight.
198
+ * @see {@link HighlightOptions}
199
+ */
200
+ show(object: Entity | GroundPrimitive, options?: HighlightOptions): Entity | undefined;
201
+ /**
202
+ * Removes all geometry properties from the highlight entity
203
+ * @private
204
+ */
205
+ private _clearGeometries;
206
+ /**
207
+ * Updates the highlight entity from an Entity object
208
+ * @private
209
+ */
210
+ private _update;
211
+ /**
212
+ * Clears the current highlight
213
+ */
214
+ hide(): void;
215
+ /** Clean up the instances */
216
+ destroy(): void;
217
+ /** Gets the highlight color. */
218
+ get color(): Color;
219
+ /** Sets the highlight color. */
220
+ set color(color: Color);
221
+ /** Gets the highlight entity */
222
+ get entity(): Entity;
223
+ }
224
+
225
+ export { Highlight, type HighlightOptions, type IHighlight, type Picked, type PickedObject, SilhouetteHighlight, SurfaceHighlight };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import"./chunk-RXMNSDKR.js";import{a as R,b as S,c as V,d as D}from"./chunk-D2H7O3WV.js";import{a as x,b as A}from"./chunk-2JNRK7SN.js";import{a as E,b as O,c as G}from"./chunk-YHYFSR66.js";import{Cesium3DTileFeature as P,Color as z,defined as H,Entity as y,GroundPrimitive as T}from"cesium";import{Cesium3DTileFeature as I,Color as _,ConstantProperty as p,defined as F,PostProcessStageLibrary as m}from"cesium";var n=class{_color=_.RED;_silhouette;_composite;_stages;_entity;constructor(t){this._stages=t.scene.postProcessStages,this._silhouette=m.createEdgeDetectionStage(),this._silhouette.uniforms.color=this._color,this._silhouette.uniforms.length=.01,this._silhouette.selected=[],this._composite=m.createSilhouetteStage([this._silhouette]),this._stages.add(this._composite)}show(t,i){if(!(!F(t)||this._silhouette.selected[0]===t))if(t instanceof I)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 p(i?.width||2),t.model.silhouetteColor=new p(i?.color||this._color)}}hide(){this._silhouette.selected.length>0&&(this._silhouette.selected=[]),this._entity?.model&&(this._entity.model.silhouetteColor=new p(_.TRANSPARENT),this._entity=void 0)}destroy(){this.hide(),this._composite&&this._stages.remove(this._composite)}get color(){return this._color}set color(t){this._color=t}};import{Cartesian3 as r,ClassificationType as w,Color as M,defined as N,Entity as f,GroundPrimitive as v,HeightReference as d,PolygonGraphics as C,PolygonHierarchy as L,PolylineGraphics as u,RectangleGraphics as U}from"cesium";var l=class{_color=M.RED;_entity;_entities;constructor(t){this._entities=t.entities,this._entity=this._entities.add(new f({id:`highlight-entity-${Math.random().toString(36).substring(2)}`,show:!1}))}show(t,i){if(!(!N(t)||!this._entity)){this._clearGeometries();try{if(t instanceof f&&(t.polygon||t.polyline||t.rectangle))this._update(t,i);else if(t instanceof v)this._update(t,i);else return;return this._entity.show=!0,this._entity}catch(e){console.error("Failed to highlight object:",e);return}}}_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 f){if(t.polygon)if(i.outline){let e=t.polygon.hierarchy?.getValue();if(e&&e.positions){let o;e.positions.length>0&&!r.equals(e.positions[0],e.positions[e.positions.length-1])?o=[...e.positions,e.positions[0]]:o=e.positions,this._entity.polyline=new u({positions:o,material:i.color,width:i.width||2,clampToGround:!0})}}else{let e=t.polygon.hierarchy?.getValue();e&&(this._entity.polygon=new C({hierarchy:e,material:i.color,heightReference:d.CLAMP_TO_GROUND,classificationType:t.polygon.classificationType?.getValue()||w.BOTH}))}else if(t.polyline){let e=t.polyline.positions?.getValue();if(e){let o=t.polyline.width?.getValue();this._entity.polyline=new u({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.fromRadians(e.west,e.north),r.fromRadians(e.east,e.north),r.fromRadians(e.east,e.south),r.fromRadians(e.west,e.south),r.fromRadians(e.west,e.north)];this._entity.polyline=new u({positions:o,material:i.color,width:i.width||2,clampToGround:!0})}}else{let e=t.rectangle.coordinates?.getValue();e&&(this._entity.rectangle=new U({coordinates:e,material:i.color,heightReference:d.CLAMP_TO_GROUND}))}}else if(t instanceof v){let e=t.geometryInstances,o=Array.isArray(e)?e[0]:e;if(!o.geometry.attributes.position)return;let c=o.geometry.attributes.position.values,g=[];for(let h=0;h<c.length;h+=3)g.push(new r(c[h],c[h+1],c[h+2]));i.outline?this._entity.polyline=new u({positions:g,material:i.color,width:i.width||2,clampToGround:!0}):this._entity.polygon=new C({hierarchy:new L(g),material:i.color,heightReference:d.CLAMP_TO_GROUND,classificationType:w.BOTH})}}hide(){this._entity&&(this._entity.show=!1)}destroy(){this._entities.contains(this._entity)&&this._entities.remove(this._entity)}get color(){return this._color}set color(t){this._color=t}get entity(){return this._entity}};var a=class s{static instances=new WeakMap;_surface;_silhouette;_color=z.RED;constructor(t){this._surface=new l(t),this._silhouette=new n(t),this._surface.color=this._color,this._silhouette.color=this._color}static getInstance(t){let i=t.container;return s.instances.has(i)||s.instances.set(i,new s(t)),s.instances.get(i)}static releaseInstance(t){let i=t.container,e=s.instances.get(i);e&&(e.hide(),e._surface&&e._surface.destroy(),e._silhouette&&e._silhouette.destroy(),s.instances.delete(i))}show(t,i={color:this._color}){this.hide();let e=this._getObject(t);if(H(e))return e instanceof P?this._silhouette.show(e,i):e instanceof y&&e.model?this._silhouette.show(e,i):this._surface.show(e,i)}_getObject(t){if(H(t)){if(t instanceof y||t instanceof P||t instanceof T)return t;if(t.id instanceof y)return t.id;if(t.primitive instanceof T)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}};export{G as Collection,a as Highlight,D as HybridTerrainProvider,S as TerrainArea,V as TerrainAreaCollection,E as TerrainVisualizer,A as cloneViewer,R as computeRectangle,O as isGetterOnly,x as syncCamera};
1
+ import"./chunk-RXMNSDKR.js";import{a as G,b as R,c as V,d as D}from"./chunk-D2H7O3WV.js";import{a as x,b as A}from"./chunk-2JNRK7SN.js";import{a as E,b as O,c as S}from"./chunk-I53ZQ7WC.js";import{Cesium3DTileFeature as P,Color as U,defined as H,Entity as y,GroundPrimitive as T}from"cesium";import{Cesium3DTileFeature as I,Color as _,ConstantProperty as u,defined as F,PostProcessStageLibrary as m}from"cesium";var r=class{_color=_.RED;_silhouette;_composite;_stages;_entity;constructor(t){this._stages=t.scene.postProcessStages,this._silhouette=m.createEdgeDetectionStage(),this._silhouette.uniforms.color=this._color,this._silhouette.uniforms.length=.01,this._silhouette.selected=[],this._composite=m.createSilhouetteStage([this._silhouette]),this._stages.add(this._composite)}show(t,i){if(!(!F(t)||this._silhouette.selected[0]===t))if(t instanceof I)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 u(i?.width||2),t.model.silhouetteColor=new u(i?.color||this._color)}}hide(){this._silhouette.selected.length>0&&(this._silhouette.selected=[]),this._entity?.model&&(this._entity.model.silhouetteColor=new u(_.TRANSPARENT),this._entity.model.silhouetteSize=new u(0),this._entity=void 0)}destroy(){this.hide(),this._composite&&this._stages.remove(this._composite)}get color(){return this._color}set color(t){this._color=t}};import{Cartesian3 as n,ClassificationType as w,Color as M,defined as N,Entity as f,GroundPrimitive as v,HeightReference as d,PolygonGraphics as C,PolygonHierarchy as L,PolylineGraphics as g,RectangleGraphics as z}from"cesium";var l=class{_color=M.RED;_entity;_entities;constructor(t){this._entities=t.entities,this._entity=this._entities.add(new f({id:`highlight-entity-${Math.random().toString(36).substring(2)}`,show:!1}))}show(t,i){if(!(!N(t)||!this._entity)){this._clearGeometries();try{if(t instanceof f&&(t.polygon||t.polyline||t.rectangle))this._update(t,i);else if(t instanceof v)this._update(t,i);else return;return this._entity.show=!0,this._entity}catch(e){console.error("Failed to highlight object:",e);return}}}_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 f){if(t.polygon)if(i.outline){let e=t.polygon.hierarchy?.getValue();if(e&&e.positions){let o;e.positions.length>0&&!n.equals(e.positions[0],e.positions[e.positions.length-1])?o=[...e.positions,e.positions[0]]:o=e.positions,this._entity.polyline=new g({positions:o,material:i.color,width:i.width||2,clampToGround:!0})}}else{let e=t.polygon.hierarchy?.getValue();e&&(this._entity.polygon=new C({hierarchy:e,material:i.color,heightReference:d.CLAMP_TO_GROUND,classificationType:t.polygon.classificationType?.getValue()||w.BOTH}))}else if(t.polyline){let e=t.polyline.positions?.getValue();if(e){let o=t.polyline.width?.getValue();this._entity.polyline=new g({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=[n.fromRadians(e.west,e.north),n.fromRadians(e.east,e.north),n.fromRadians(e.east,e.south),n.fromRadians(e.west,e.south),n.fromRadians(e.west,e.north)];this._entity.polyline=new g({positions:o,material:i.color,width:i.width||2,clampToGround:!0})}}else{let e=t.rectangle.coordinates?.getValue();e&&(this._entity.rectangle=new z({coordinates:e,material:i.color,heightReference:d.CLAMP_TO_GROUND}))}}else if(t instanceof v){let e=t.geometryInstances,o=Array.isArray(e)?e[0]:e;if(!o.geometry.attributes.position)return;let c=o.geometry.attributes.position.values,p=[];for(let h=0;h<c.length;h+=3)p.push(new n(c[h],c[h+1],c[h+2]));i.outline?this._entity.polyline=new g({positions:p,material:i.color,width:i.width||2,clampToGround:!0}):this._entity.polygon=new C({hierarchy:new L(p),material:i.color,heightReference:d.CLAMP_TO_GROUND,classificationType:w.BOTH})}}hide(){this._entity&&(this._entity.show=!1)}destroy(){this._entities.contains(this._entity)&&this._entities.remove(this._entity)}get color(){return this._color}set color(t){this._color=t}get entity(){return this._entity}};var a=class s{static instances=new WeakMap;_surface;_silhouette;_color=U.RED;constructor(t){this._surface=new l(t),this._silhouette=new r(t),this._surface.color=this._color,this._silhouette.color=this._color}static getInstance(t){let i=t.container;return s.instances.has(i)||s.instances.set(i,new s(t)),s.instances.get(i)}static releaseInstance(t){let i=t.container,e=s.instances.get(i);e&&(e.hide(),e._surface&&e._surface.destroy(),e._silhouette&&e._silhouette.destroy(),s.instances.delete(i))}show(t,i={color:this._color}){this.hide();let e=this._getObject(t);if(H(e))return e instanceof P?this._silhouette.show(e,i):e instanceof y&&e.model?this._silhouette.show(e,i):this._surface.show(e,i)}_getObject(t){if(H(t)){if(t instanceof y||t instanceof P||t instanceof T)return t;if(t.id instanceof y)return t.id;if(t.primitive instanceof T)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}};export{S as Collection,a as Highlight,D as HybridTerrainProvider,r as SilhouetteHighlight,l as SurfaceHighlight,R as TerrainArea,V as TerrainAreaCollection,E as TerrainVisualizer,A as cloneViewer,G as computeRectangle,O as isGetterOnly,x as syncCamera};
@@ -1 +1 @@
1
- "use strict";var _=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var O=(n,e)=>{for(var t in e)_(n,t,{get:e[t],enumerable:!0})},S=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of A(e))!M.call(n,r)&&r!==t&&_(n,r,{get:()=>e[r],enumerable:!(i=x(e,r))||i.enumerable});return n};var V=n=>S(_({},"__esModule",{value:!0}),n);var j={};O(j,{TerrainVisualizer:()=>g,isGetterOnly:()=>v});module.exports=V(j);var s=require("cesium");var u=require("cesium");var b=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 i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(o=>o(r))}}_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],i=this._tagMap.get(t);i&&(i.delete(e),i.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,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),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 r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let o of e)this.remove(o)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof u.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 i=this.get(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}show(e){let t=this.get(e);for(let i of t)(0,u.defined)(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)(0,u.defined)(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)(0,u.defined)(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let o of r)if(e in o&&typeof o[e]!="function"){if(v(o,e))throw Error(`Cannot set read-only property '${String(e)}' on ${o.constructor.name}`);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((r,o)=>e(r,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)}},C=b;var g=class n{_viewer;_collection;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",s.Color.RED],["default",s.Color.BLUE],["fallback",s.Color.GRAY],["grid",s.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new C({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),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,this._ensureTileCoordinatesLayer();let t=this._getVisibleRectangle();if(!t||!this._isValidRectangle(t)){console.warn("Invalid visible rectangle detected, skipping grid display");return}this._displayTileGrid(t,e),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new s.TileCoordinatesImageryProvider({tilingScheme:this._terrainProvider.tilingScheme,color:s.Color.YELLOW})))}_isValidRectangle(e){return e&&Number.isFinite(e.west)&&Number.isFinite(e.south)&&Number.isFinite(e.east)&&Number.isFinite(e.north)&&e.west<=e.east&&e.south<=e.north}_displayTileGrid(e,t){let i=this._terrainProvider.tilingScheme;try{let r=this._calculateTileBounds(e,t,i);this._generateVisibleTiles(r,t,i).forEach(a=>{this._collection.add(a.entity,n.tag.grid)})}catch(r){console.error("Error displaying tile grid:",r)}}_calculateTileBounds(e,t,i){let r=i.positionToTileXY(s.Rectangle.northwest(e),t),o=i.positionToTileXY(s.Rectangle.southeast(e),t);if(!r||!o)throw new Error("Failed to calculate tile bounds");return{start:r,end:o}}_generateVisibleTiles(e,t,i){let r=[],a=Math.min(e.end.x-e.start.x+1,100),l=Math.min(e.end.y-e.start.y+1,100);for(let c=e.start.x;c<e.start.x+a;c++)for(let h=e.start.y;h<e.start.y+l;h++)try{let d=this._createTileEntity(c,h,t,i);d&&r.push({entity:d})}catch(d){console.warn(`Error creating tile (${c}, ${h}, ${t}):`,d)}return r}_createTileEntity(e,t,i,r){let o=r.tileXYToRectangle(e,t,i);if(!this._isValidRectangle(o))return null;let a=this._getTileColor(e,t,i),l=n.createRectangle(o,a.withAlpha(.3));return l.properties?.addProperty("tileX",e),l.properties?.addProperty("tileY",t),l.properties?.addProperty("tileLevel",i),l}_getTileColor(e,t,i){if(!this._terrainProvider)return this._colors.get("fallback")||s.Color.TRANSPARENT;for(let r of this._terrainProvider.terrainAreas)if(r.contains(e,t,i))return r.isCustom?this._colors.get("custom")||s.Color.RED:this._colors.get("default")||s.Color.BLUE;return this._terrainProvider.getTileDataAvailable(e,t,i)?this._colors.get("default")||s.Color.BLUE:this._colors.get("fallback")||s.Color.GRAY}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,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...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}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,o){return new s.Entity({rectangle:{coordinates:r,material:o,heightReference:s.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,o,a){let l=a?.tag||"terrain_area_visualization",c=a?.color||s.Color.RED,h=a?.maxTilesToShow||100,d=a?.show??!0,w=a?.alpha||.7,E=a?.tileAlpha||.2,f=new C({collection:o.entities,tag:l}),{rectangle:I}=r;if(f.add(i.createRectangle(I,c.withAlpha(w)),l),d&&r.tileRanges.size>0){let{tilingScheme:R}=r.terrainProvider,p=0;r.tileRanges.forEach((m,P)=>{for(let y=m.start.x;y<=m.end.x&&p<h;y++)for(let T=m.start.y;T<=m.end.y&&p<h;T++){let L=R.tileXYToRectangle(y,T,P);f.add(e(L,c.withAlpha(E)),`${l}_tile`),p++}})}return f}i.visualize=t})(g||={});function v(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}
1
+ "use strict";var T=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var M=(n,e)=>{for(var t in e)T(n,t,{get:e[t],enumerable:!0})},O=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of S(e))!x.call(n,r)&&r!==t&&T(n,r,{get:()=>e[r],enumerable:!(i=P(e,r))||i.enumerable});return n};var F=n=>O(T({},"__esModule",{value:!0}),n);var V={};M(V,{TerrainVisualizer:()=>u,isGetterOnly:()=>g});module.exports=F(V);var s=require("cesium");var o=require("cesium");var C=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;_eventCleanupFunctions=[];constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e,this._setupCacheInvalidator(e)}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(a=>a(r))}}_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],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache=()=>{this._valuesCache=null};_setupCacheInvalidator(e){e instanceof o.EntityCollection?(e.collectionChanged.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.collectionChanged.removeEventListener(this._invalidateCache))):e instanceof o.PrimitiveCollection?(e.primitiveAdded.addEventListener(this._invalidateCache),e.primitiveRemoved.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.primitiveAdded.removeEventListener(this._invalidateCache),()=>e.primitiveRemoved.removeEventListener(this._invalidateCache))):e instanceof o.DataSourceCollection?(e.dataSourceAdded.addEventListener(this._invalidateCache),e.dataSourceMoved.addEventListener(this._invalidateCache),e.dataSourceRemoved.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.dataSourceAdded.removeEventListener(this._invalidateCache),()=>e.dataSourceMoved.removeEventListener(this._invalidateCache),()=>e.dataSourceRemoved.removeEventListener(this._invalidateCache))):e instanceof o.ImageryLayerCollection&&(e.layerAdded.addEventListener(this._invalidateCache),e.layerMoved.addEventListener(this._invalidateCache),e.layerRemoved.addEventListener(this._invalidateCache),e.layerShownOrHidden.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.layerAdded.removeEventListener(this._invalidateCache),()=>e.layerMoved.removeEventListener(this._invalidateCache),()=>e.layerRemoved.removeEventListener(this._invalidateCache),()=>e.layerShownOrHidden.removeEventListener(this._invalidateCache)))}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,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),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 r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let a of e)this.remove(a)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}destroy(){this._eventCleanupFunctions.forEach(e=>e()),this._eventCleanupFunctions=[],this._tagMap.clear(),this._eventListeners.clear(),this._valuesCache=null}get values(){if(this._valuesCache!==null)return this._valuesCache;let e;if(this.collection instanceof o.EntityCollection)e=this.collection.values;else{e=[];for(let t=0;t<this.collection.length;t++)e.push(this.collection.get(t))}return this._valuesCache=e,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 i=this.get(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}show(e){let t=this.get(e);for(let i of t)(0,o.defined)(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)(0,o.defined)(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)(0,o.defined)(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let a of r)if(e in a&&typeof a[e]!="function"){if(g(a,e))throw Error(`Cannot set read-only property '${String(e)}' on ${a.constructor.name}`);a[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((r,a)=>e(r,a))}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=C;var u=class n{_viewer;_collection;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",s.Color.RED],["default",s.Color.BLUE],["fallback",s.Color.GRAY],["grid",s.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(([i,r])=>{this._colors.set(i,r)}),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,this._ensureTileCoordinatesLayer();let t=this._getVisibleRectangle();if(!t||!this._isValidRectangle(t)){console.warn("Invalid visible rectangle detected, skipping grid display");return}this._displayTileGrid(t,e),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new s.TileCoordinatesImageryProvider({tilingScheme:this._terrainProvider.tilingScheme,color:s.Color.YELLOW})))}_isValidRectangle(e){return e&&Number.isFinite(e.west)&&Number.isFinite(e.south)&&Number.isFinite(e.east)&&Number.isFinite(e.north)&&e.west<=e.east&&e.south<=e.north}_displayTileGrid(e,t){let i=this._terrainProvider.tilingScheme;try{let r=this._calculateTileBounds(e,t,i);this._generateVisibleTiles(r,t,i).forEach(l=>{this._collection.add(l.entity,n.tag.grid)})}catch(r){console.error("Error displaying tile grid:",r)}}_calculateTileBounds(e,t,i){let r=i.positionToTileXY(s.Rectangle.northwest(e),t),a=i.positionToTileXY(s.Rectangle.southeast(e),t);if(!r||!a)throw new Error("Failed to calculate tile bounds");return{start:r,end:a}}_generateVisibleTiles(e,t,i){let r=[],l=Math.min(e.end.x-e.start.x+1,100),h=Math.min(e.end.y-e.start.y+1,100);for(let c=e.start.x;c<e.start.x+l;c++)for(let d=e.start.y;d<e.start.y+h;d++)try{let v=this._createTileEntity(c,d,t,i);v&&r.push({entity:v})}catch(v){console.warn(`Error creating tile (${c}, ${d}, ${t}):`,v)}return r}_createTileEntity(e,t,i,r){let a=r.tileXYToRectangle(e,t,i);if(!this._isValidRectangle(a))return null;let l=this._getTileColor(e,t,i),h=n.createRectangle(a,l.withAlpha(.3));return h.properties?.addProperty("tileX",e),h.properties?.addProperty("tileY",t),h.properties?.addProperty("tileLevel",i),h}_getTileColor(e,t,i){if(!this._terrainProvider)return this._colors.get("fallback")||s.Color.TRANSPARENT;for(let r of this._terrainProvider.terrainAreas)if(r.contains(e,t,i))return r.isCustom?this._colors.get("custom")||s.Color.RED:this._colors.get("default")||s.Color.BLUE;return this._terrainProvider.getTileDataAvailable(e,t,i)?this._colors.get("default")||s.Color.BLUE:this._colors.get("fallback")||s.Color.GRAY}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,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...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}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,a){return new s.Entity({rectangle:{coordinates:r,material:a,heightReference:s.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,a,l){let h=l?.tag||"terrain_area_visualization",c=l?.color||s.Color.RED,d=l?.maxTilesToShow||100,v=l?.show??!0,E=l?.alpha||.7,w=l?.tileAlpha||.2,f=new b({collection:a.entities,tag:h}),{rectangle:L}=r;if(f.add(i.createRectangle(L,c.withAlpha(E)),h),v&&r.tileRanges.size>0){let{tilingScheme:I}=r.terrainProvider,_=0;r.tileRanges.forEach((m,R)=>{for(let p=m.start.x;p<=m.end.x&&_<d;p++)for(let y=m.start.y;y<=m.end.y&&_<d;y++){let A=I.tileXYToRectangle(p,y,R);f.add(e(A,c.withAlpha(w)),`${h}_tile`),_++}})}return f}i.visualize=t})(u||={});function g(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}
@@ -1 +1 @@
1
- import{a,b}from"../chunk-YHYFSR66.js";export{a as TerrainVisualizer,b as isGetterOnly};
1
+ import{a,b}from"../chunk-I53ZQ7WC.js";export{a as TerrainVisualizer,b as isGetterOnly};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juun-roh/cesium-utils",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Utilities to handle Cesium classes easier.",
5
5
  "keywords": [
6
6
  "3d",
@@ -1 +0,0 @@
1
- import{Color as a,Entity as A,HeightReference as M,Rectangle as C,TileCoordinatesImageryProvider as O}from"cesium";import{defined as y,EntityCollection as x}from"cesium";var T=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 i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(o=>o(r))}}_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],i=this._tagMap.get(t);i&&(i.delete(e),i.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,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),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 r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let o of e)this.remove(o)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof x)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 i=this.get(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}show(e){let t=this.get(e);for(let i of t)y(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)y(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)y(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let o of r)if(e in o&&typeof o[e]!="function"){if(_(o,e))throw Error(`Cannot set read-only property '${String(e)}' on ${o.constructor.name}`);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((r,o)=>e(r,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=T;var u=class n{_viewer;_collection;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",a.RED],["default",a.BLUE],["fallback",a.GRAY],["grid",a.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(([i,r])=>{this._colors.set(i,r)}),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,this._ensureTileCoordinatesLayer();let t=this._getVisibleRectangle();if(!t||!this._isValidRectangle(t)){console.warn("Invalid visible rectangle detected, skipping grid display");return}this._displayTileGrid(t,e),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new O({tilingScheme:this._terrainProvider.tilingScheme,color:a.YELLOW})))}_isValidRectangle(e){return e&&Number.isFinite(e.west)&&Number.isFinite(e.south)&&Number.isFinite(e.east)&&Number.isFinite(e.north)&&e.west<=e.east&&e.south<=e.north}_displayTileGrid(e,t){let i=this._terrainProvider.tilingScheme;try{let r=this._calculateTileBounds(e,t,i);this._generateVisibleTiles(r,t,i).forEach(s=>{this._collection.add(s.entity,n.tag.grid)})}catch(r){console.error("Error displaying tile grid:",r)}}_calculateTileBounds(e,t,i){let r=i.positionToTileXY(C.northwest(e),t),o=i.positionToTileXY(C.southeast(e),t);if(!r||!o)throw new Error("Failed to calculate tile bounds");return{start:r,end:o}}_generateVisibleTiles(e,t,i){let r=[],s=Math.min(e.end.x-e.start.x+1,100),l=Math.min(e.end.y-e.start.y+1,100);for(let c=e.start.x;c<e.start.x+s;c++)for(let h=e.start.y;h<e.start.y+l;h++)try{let d=this._createTileEntity(c,h,t,i);d&&r.push({entity:d})}catch(d){console.warn(`Error creating tile (${c}, ${h}, ${t}):`,d)}return r}_createTileEntity(e,t,i,r){let o=r.tileXYToRectangle(e,t,i);if(!this._isValidRectangle(o))return null;let s=this._getTileColor(e,t,i),l=n.createRectangle(o,s.withAlpha(.3));return l.properties?.addProperty("tileX",e),l.properties?.addProperty("tileY",t),l.properties?.addProperty("tileLevel",i),l}_getTileColor(e,t,i){if(!this._terrainProvider)return this._colors.get("fallback")||a.TRANSPARENT;for(let r of this._terrainProvider.terrainAreas)if(r.contains(e,t,i))return r.isCustom?this._colors.get("custom")||a.RED:this._colors.get("default")||a.BLUE;return this._terrainProvider.getTileDataAvailable(e,t,i)?this._colors.get("default")||a.BLUE:this._colors.get("fallback")||a.GRAY}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,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...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}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,o){return new A({rectangle:{coordinates:r,material:o,heightReference:M.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,o,s){let l=s?.tag||"terrain_area_visualization",c=s?.color||a.RED,h=s?.maxTilesToShow||100,d=s?.show??!0,w=s?.alpha||.7,E=s?.tileAlpha||.2,m=new b({collection:o.entities,tag:l}),{rectangle:I}=r;if(m.add(i.createRectangle(I,c.withAlpha(w)),l),d&&r.tileRanges.size>0){let{tilingScheme:R}=r.terrainProvider,v=0;r.tileRanges.forEach((g,P)=>{for(let f=g.start.x;f<=g.end.x&&v<h;f++)for(let p=g.start.y;p<=g.end.y&&v<h;p++){let L=R.tileXYToRectangle(f,p,P);m.add(e(L,c.withAlpha(E)),`${l}_tile`),v++}})}return m}i.visualize=t})(u||={});function _(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}export{u as a,_ as b,b as c};