@juun-roh/cesium-utils 0.0.6 → 0.0.8

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{Rectangle as f}from"cesium";function b(s,r){if(r.size===0)return new f;let e=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,t=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY,l=Array.from(r.keys()),d=Math.min(...l),c=r.get(d);if(c){let{start:v,end:h}=c,T=s.tileXYToRectangle(v.x,v.y,d),g=s.tileXYToRectangle(h.x,h.y,d);e=Math.min(T.west,e),i=Math.min(g.south,i),t=Math.max(g.east,t),a=Math.max(T.north,a)}return new f(e,i,t,a)}import{CesiumTerrainProvider as _,Rectangle as A}from"cesium";var n=class{_provider;_rectangle;_tileRanges;_ready=!1;_credit;_isCustom;constructor(r){this._provider=r.provider,this._tileRanges=r.tileRanges,this._credit=r.credit||"custom",this._isCustom=r.isCustom!==void 0?r.isCustom:!0,this._rectangle=b(r.provider.tilingScheme,r.tileRanges),r.tileRanges.forEach((e,i)=>{this._provider.availability?.addAvailableTileRange(i,e.start.x,e.start.y,e.end.x,e.end.y)}),this._ready=!0}contains(r,e,i){if(this._tileRanges.size>0){if(!this._tileRanges.has(i))return!1;let a=this._tileRanges.get(i);return r>=a.start.x&&r<=a.end.x&&e>=a.start.y&&e<=a.end.y}let t=this._provider.tilingScheme.tileXYToRectangle(r,e,i);return A.intersection(t,this._rectangle)!==void 0}requestTileGeometry(r,e,i,t){if(!(!this._ready||!this.contains(r,e,i)||!this._provider.getTileDataAvailable(r,e,i)))return this._provider.requestTileGeometry(r,e,i,t)}getTileDataAvailable(r,e,i){if(this._tileRanges.size>0){if(!this._tileRanges.has(i))return!1;let t=this._tileRanges.get(i);return r>=t.start.x&&r<=t.end.x&&e>=t.start.y&&e<=t.end.y}return this._ready?this._provider.getTileDataAvailable(r,e,i)??!1:!1}get isCustom(){return this._isCustom}get credit(){return this._credit}get provider(){return this._provider}get tileRanges(){return this._tileRanges}get rectangle(){return this._rectangle}get ready(){return this._ready}};(r=>{async function s(e,i,t){let a=t?.credit||"custom",l=await _.fromUrl(e,{...t,credit:a});return new r({provider:l,tileRanges:i,credit:a})}r.fromUrl=s})(n||={});var o=class extends Array{add(r){if(Array.isArray(r)){for(let i of r)this.add(i);return this.length}let e;return r instanceof n?e=r:e=new n(r),this.push(e)}remove(r){if(Array.isArray(r))return r.forEach(i=>this.remove(i)),this;let e=this.indexOf(r);return e>=0&&this.splice(e,1),this}removeAll(){this.length=0}};import{CesiumTerrainProvider as u,EllipsoidTerrainProvider as p}from"cesium";var m=class s{_terrainAreas=new o;_terrainProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(r,e,i){this._terrainProvider=r,this._fallbackProvider=e,this._tilingScheme=r.tilingScheme,this._terrainAreas=new o(...i),this._availability=r.availability,this._ready=!0}static async create(r){try{let e;typeof r.terrainProvider=="string"?e=await u.fromUrl(r.terrainProvider,{requestVertexNormals:!0}):e=r.terrainProvider;let i;r.fallbackProvider?typeof r.fallbackProvider=="string"?i=await u.fromUrl(r.fallbackProvider,{requestVertexNormals:!0}):i=r.fallbackProvider:i=new p;let t=[];for(let a of r.terrainAreas){let l=typeof a.provider=="string"?await u.fromUrl(a.provider,{requestVertexNormals:!0}):a.provider;t.push(new n({provider:l,tileRanges:a.tileRanges,credit:a.credit,isCustom:a.isCustom}))}return new s(e,i,t)}catch(e){throw console.error("Failed to initialize HybridTerrainProvider:",e),e}}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(r,e,i){return this._terrainProvider.loadTileDataAvailability(r,e,i)}getLevelMaximumGeometricError(r){return this._terrainProvider.getLevelMaximumGeometricError(r)}requestTileGeometry(r,e,i,t){if(this._ready){for(let a of this._terrainAreas)if(a.contains(r,e,i))return a.requestTileGeometry(r,e,i,t);return this._terrainProvider.getTileDataAvailable(r,e,i)?this._terrainProvider.requestTileGeometry(r,e,i,t):this._fallbackProvider.requestTileGeometry(r,e,i,t)}}getTileDataAvailable(r,e,i){for(let t of this._terrainAreas)if(t.contains(r,e,i))return t.getTileDataAvailable(r,e,i);return this._terrainProvider.getTileDataAvailable(r,e,i)}};(r=>{async function s(e,i,t){let a=await u.fromUrl(e,{credit:"custom"});return r.create({terrainAreas:[{provider:a,tileRanges:t,credit:"custom"}],terrainProvider:i,fallbackProvider:new p})}r.createOverlay=s})(m||={});export{b as a,n as b,o as c,m as d};
@@ -0,0 +1 @@
1
+ import{Color as l,Entity as M,HeightReference as O,Rectangle as x,TileCoordinatesImageryProvider as P}from"cesium";import{defined as w,EntityCollection as A}from"cesium";var C=class s{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(n=>n(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[s.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,s.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 n of e)this.remove(n)&&(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 A)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,s.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)w(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)w(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)w(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let n of r)if(e in n&&typeof n[e]!="function"){if(I(n,e))throw Error(`setProperty(${n}, ${e}) failed; The property is readonly.`);n[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,n)=>e(r,n))}map(e,t){return(t?this.get(t):this.values).map(e)}find(e,t){return(t?this.get(t):this.values).find(e)}},E=C;var f=class s{_viewer;_collection;_hybridTerrain;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",l.RED],["default",l.BLUE],["fallback",l.GRAY],["grid",l.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new E({collection:e.entities,tag:s.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._hybridTerrain=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.remove(this._collection.tags)}show(e=15){if(!this._hybridTerrain)return;this._collection.remove(s.tag.grid),this._level=e;let t=this._hybridTerrain.tilingScheme;this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new P({tilingScheme:t,color:l.YELLOW})));let i=(o,a,d)=>{if(this._hybridTerrain){for(let m of this._hybridTerrain.terrainAreas)if(m.contains(o,a,d))return m.isCustom?this._colors.get("custom")||l.RED:this._colors.get("default")||l.BLUE;if(this._hybridTerrain.getTileDataAvailable(o,a,d))return this._colors.get("default")||l.BLUE}return this._colors.get("fallback")||l.TRANSPARENT},r=this._getVisibleRectangle();if(!r)return;function n(o){return o&&Number.isFinite(o.west)&&Number.isFinite(o.south)&&Number.isFinite(o.east)&&Number.isFinite(o.north)&&o.west<=o.east&&o.south<=o.north}if(!n(r)){console.warn("Invalid visible rectangle detected, skipping grid display");return}try{let o=t.positionToTileXY(x.northwest(r),e),a=t.positionToTileXY(x.southeast(r),e);if(!o||!a)return;let d=100,m=Math.min(a.x-o.x+1,d),p=Math.min(a.y-o.y+1,d);for(let c=o.x;c<=o.x+m-1;c++)for(let h=o.y;h<=o.y+p-1;h++)try{let u=t.tileXYToRectangle(c,h,e);if(!n(u)){console.warn(`Invalid rectangle for tile (${c}, ${h}, ${e}), skipping`);continue}let y=i(c,h,e),g=s.createRectangle(u,y.withAlpha(.3));g.properties?.addProperty("tileX",c),g.properties?.addProperty("tileY",h),g.properties?.addProperty("tileLevel",e),this._collection.add(g,s.tag.grid)}catch(u){console.warn(`Error creating tile (${c}, ${h}, ${e}): ${u.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(o){console.error("Error displaying tile grid:",o)}}hide(){this._collection.remove(s.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}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,n){return new M({rectangle:{coordinates:r,material:n,heightReference:O.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,n,o){let a=o?.tag||"terrain_area_visualization",d=o?.color||l.RED,m=o?.maxTilesToShow||100,p=o?.show??!0,c=o?.alpha||.7,h=o?.tileAlpha||.2,u=new E({collection:n.entities,tag:a}),{rectangle:y}=r;if(u.add(i.createRectangle(y,d.withAlpha(c)),a),p&&r.tileRanges.size>0){let{tilingScheme:g}=r.provider,b=0;r.tileRanges.forEach((v,R)=>{for(let T=v.start.x;T<=v.end.x&&b<m;T++)for(let _=v.start.y;_<=v.end.y&&b<m;_++){let L=g.tileXYToRectangle(T,_,R);u.add(e(L,d.withAlpha(h)),`${a}_tile`),b++}})}return u}i.visualize=t})(f||={});function I(s,e){let t=!1,i=Object.getOwnPropertyDescriptor(s,e);if(!i){let r=Object.getPrototypeOf(s);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}export{f as a,I as b,E as c};
@@ -1 +1 @@
1
- "use strict";var E=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var S=(n,e)=>{for(var t in e)E(n,t,{get:e[t],enumerable:!0})},j=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of B(e))!V.call(n,r)&&r!==t&&E(n,r,{get:()=>e[r],enumerable:!(i=P(e,r))||i.enumerable});return n};var F=n=>j(E({},"__esModule",{value:!0}),n);var W={};S(W,{Collection:()=>p});module.exports=F(W);var f=require("cesium");var a=require("cesium");var y=class n{_viewer;_collection;_hybridTerrain;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",a.Color.RED],["default",a.Color.BLUE],["fallback",a.Color.GRAY],["grid",a.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new p({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._hybridTerrain=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.removeByTag(this._collection.getTags())}show(e=15){if(!this._hybridTerrain)return;this._collection.removeByTag(n.tag.grid),this._level=e;let t=this._hybridTerrain.tilingScheme;this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new a.TileCoordinatesImageryProvider({tilingScheme:t,color:a.Color.YELLOW})));let i=(o,l,d)=>{if(this._hybridTerrain){for(let u of this._hybridTerrain.terrainAreas)if(u.contains(o,l,d))return u.isCustom?this._colors.get("custom")||a.Color.RED:this._colors.get("default")||a.Color.BLUE;if(this._hybridTerrain.getTileDataAvailable(o,l,d))return this._colors.get("default")||a.Color.BLUE}return this._colors.get("fallback")||a.Color.TRANSPARENT},r=this._getVisibleRectangle();if(!r)return;function s(o){return o&&Number.isFinite(o.west)&&Number.isFinite(o.south)&&Number.isFinite(o.east)&&Number.isFinite(o.north)&&o.west<=o.east&&o.south<=o.north}if(!s(r)){console.warn("Invalid visible rectangle detected, skipping grid display");return}try{let o=t.positionToTileXY(a.Rectangle.northwest(r),e),l=t.positionToTileXY(a.Rectangle.southeast(r),e);if(!o||!l)return;let d=100,u=Math.min(l.x-o.x+1,d),b=Math.min(l.y-o.y+1,d);for(let h=o.x;h<=o.x+u-1;h++)for(let g=o.y;g<=o.y+b-1;g++)try{let c=t.tileXYToRectangle(h,g,e);if(!s(c)){console.warn(`Invalid rectangle for tile (${h}, ${g}, ${e}), skipping`);continue}let v=i(h,g,e),m=n.createRectangle(c,v.withAlpha(.3));m.properties?.addProperty("tileX",h),m.properties?.addProperty("tileY",g),m.properties?.addProperty("tileLevel",e),this._collection.add(m,n.tag.grid)}catch(c){console.warn(`Error creating tile (${h}, ${g}, ${e}): ${c.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(o){console.error("Error displaying tile grid:",o)}}hide(){this._collection.removeByTag(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.bounds;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}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,s){return new a.Entity({rectangle:{coordinates:r,material:s,heightReference:a.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,s,o){let l=o?.tag||"terrain_area_visualization",d=o?.color||a.Color.RED,u=o?.maxTilesToShow||100,b=o?.show??!0,h=o?.alpha||.7,g=o?.tileAlpha||.2,c="provider"in r?r.bounds:r,v=new p({collection:s.entities,tag:l}),{rectangle:m}=c;if(v.add(i.createRectangle(m,d.withAlpha(h)),l),b&&c.levels.size>0){let{tilingScheme:A}=c;c.levels.forEach(L=>{let _=0,{tileRanges:R}=c;for(let[M,T]of R.entries())if(M===L)for(let C=T.start.x;C<=T.end.x&&_<u;C++)for(let w=T.start.y;w<=T.end.y&&_<u;w++){let O=A.tileXYToRectangle(C,w,L);v.add(e(O,d.withAlpha(g)),`${l}_tile`),_++}})}return v}i.visualize=t})(y||={});function I(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 z=require("cesium");var x=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}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(s=>s(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){return this.collection.contains(e)}remove(e){let t=this.collection.remove(e);return t&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),t}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof f.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}getByTag(e){let t=this._tagMap.get(e);return t?Array.from(t):[]}getFirstByTag(e){let t=this._tagMap.get(e);if(t&&t.size>0)return t.values().next().value}getTags(){return Array.from(this._tagMap.keys())}hasTag(e){let t=this._tagMap.get(e);return!!t&&t.size>0}updateTag(e,t){let i=this.getByTag(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}removeByTag(e){let t=0;return Array.isArray(e)?e.forEach(i=>{t+=this.removeByTag(i)}):this.getByTag(e).forEach(i=>{this.remove(i)&&t++}),t}show(e){let t=this.getByTag(e),i=0;for(let r of t)(0,f.defined)(r.show)&&(r.show=!0,i++);return i}hide(e){let t=this.getByTag(e),i=0;for(let r of t)(0,f.defined)(r.show)&&(r.show=!1,i++);return i}toggle(e){let t=this.getByTag(e),i=0;for(let r of t)(0,f.defined)(r.show)&&(r.show=!r.show,i++);return i}setProperty(e,t,i=this.tag){let r=this.getByTag(i),s=0;for(let o of r)if(e in o&&typeof o[e]!="function"){if(I(o,e))throw Error(`setProperty(${o}, ${e}) failed; The property is readonly.`);o[e]=t,s++}return s}filter(e,t){return(t?this.getByTag(t):this.values).filter(e)}forEach(e,t){(t?this.getByTag(t):this.values).forEach((r,s)=>e(r,s))}},p=x;
1
+ "use strict";var I=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var P=(n,e)=>{for(var t in e)I(n,t,{get:e[t],enumerable:!0})},V=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of M(e))!O.call(n,r)&&r!==t&&I(n,r,{get:()=>e[r],enumerable:!(i=A(e,r))||i.enumerable});return n};var S=n=>V(I({},"__esModule",{value:!0}),n);var z={};P(z,{Collection:()=>p});module.exports=S(z);var f=require("cesium");var s=require("cesium");var v=class n{_viewer;_collection;_hybridTerrain;_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 p({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._hybridTerrain=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.remove(this._collection.tags)}show(e=15){if(!this._hybridTerrain)return;this._collection.remove(n.tag.grid),this._level=e;let t=this._hybridTerrain.tilingScheme;this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new s.TileCoordinatesImageryProvider({tilingScheme:t,color:s.Color.YELLOW})));let i=(o,l,d)=>{if(this._hybridTerrain){for(let m of this._hybridTerrain.terrainAreas)if(m.contains(o,l,d))return m.isCustom?this._colors.get("custom")||s.Color.RED:this._colors.get("default")||s.Color.BLUE;if(this._hybridTerrain.getTileDataAvailable(o,l,d))return this._colors.get("default")||s.Color.BLUE}return this._colors.get("fallback")||s.Color.TRANSPARENT},r=this._getVisibleRectangle();if(!r)return;function a(o){return o&&Number.isFinite(o.west)&&Number.isFinite(o.south)&&Number.isFinite(o.east)&&Number.isFinite(o.north)&&o.west<=o.east&&o.south<=o.north}if(!a(r)){console.warn("Invalid visible rectangle detected, skipping grid display");return}try{let o=t.positionToTileXY(s.Rectangle.northwest(r),e),l=t.positionToTileXY(s.Rectangle.southeast(r),e);if(!o||!l)return;let d=100,m=Math.min(l.x-o.x+1,d),b=Math.min(l.y-o.y+1,d);for(let c=o.x;c<=o.x+m-1;c++)for(let h=o.y;h<=o.y+b-1;h++)try{let u=t.tileXYToRectangle(c,h,e);if(!a(u)){console.warn(`Invalid rectangle for tile (${c}, ${h}, ${e}), skipping`);continue}let T=i(c,h,e),g=n.createRectangle(u,T.withAlpha(.3));g.properties?.addProperty("tileX",c),g.properties?.addProperty("tileY",h),g.properties?.addProperty("tileLevel",e),this._collection.add(g,n.tag.grid)}catch(u){console.warn(`Error creating tile (${c}, ${h}, ${e}): ${u.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(o){console.error("Error displaying tile grid:",o)}}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}};(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,o){let l=o?.tag||"terrain_area_visualization",d=o?.color||s.Color.RED,m=o?.maxTilesToShow||100,b=o?.show??!0,c=o?.alpha||.7,h=o?.tileAlpha||.2,u=new p({collection:a.entities,tag:l}),{rectangle:T}=r;if(u.add(i.createRectangle(T,d.withAlpha(c)),l),b&&r.tileRanges.size>0){let{tilingScheme:g}=r.provider,_=0;r.tileRanges.forEach((y,R)=>{for(let C=y.start.x;C<=y.end.x&&_<m;C++)for(let w=y.start.y;w<=y.end.y&&_<m;w++){let L=g.tileXYToRectangle(C,w,R);u.add(e(L,d.withAlpha(h)),`${l}_tile`),_++}})}return u}i.visualize=t})(v||={});function E(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 j=require("cesium");var x=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(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}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")}get values(){if(this.collection instanceof f.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,f.defined)(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)(0,f.defined)(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)(0,f.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(E(a,e))throw Error(`setProperty(${a}, ${e}) failed; The property is readonly.`);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)}},p=x;
@@ -49,8 +49,7 @@ type NonFunction<T> = {
49
49
  * entities.add(new Entity({ ... }), 'roads');
50
50
  *
51
51
  * // Later, show only buildings
52
- * entities.show('buildings');
53
- * entities.hide('roads');
52
+ * entities.show('buildings').hide('roads');
54
53
  */
55
54
  declare class Collection<C extends CesiumCollection, I extends CesiumCollectionItem> {
56
55
  /**
@@ -95,6 +94,22 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
95
94
  collection: C;
96
95
  tag?: Tag;
97
96
  });
97
+ /**
98
+ * Makes the collection directly iterable, allowing it to be used in `for...of` loops
99
+ * and with spread operators.
100
+ *
101
+ * @returns An iterator for the items in the collection
102
+ *
103
+ * @example
104
+ * // Iterate through all items in the collection
105
+ * for (const entity of collection) {
106
+ * console.log(entity.id);
107
+ * }
108
+ *
109
+ * // Convert collection to array using spread syntax
110
+ * const entitiesArray = [...collection];
111
+ */
112
+ [Symbol.iterator](): Iterator<I>;
98
113
  /**
99
114
  * Emits an event to all registered listeners.
100
115
  *
@@ -168,10 +183,22 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
168
183
  /**
169
184
  * Returns true if the provided item is in this collection, false otherwise.
170
185
  *
171
- * @param item - The item to check for
186
+ * @param item - The item instance to check for
172
187
  * @returns True if the item is in the collection, false otherwise
173
188
  */
174
189
  contains(item: I): boolean;
190
+ /**
191
+ * Checks if the collection has any items with the specified tag.
192
+ *
193
+ * @param tag - The tag to check for
194
+ * @returns True if items with the tag exist, false otherwise
195
+ *
196
+ * @example
197
+ * if (collection.contains('temporary')) {
198
+ * console.log('Temporary items exist');
199
+ * }
200
+ */
201
+ contains(tag: Tag): boolean;
175
202
  /**
176
203
  * Removes an item from the collection.
177
204
  *
@@ -179,6 +206,20 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
179
206
  * @returns True if the item was removed, false if it wasn't found
180
207
  */
181
208
  remove(item: I): boolean;
209
+ /**
210
+ * Removes all items with the specified tag from the collection.
211
+ *
212
+ * @param by - The tag identifying which items to remove
213
+ * @returns True if the item was removed, false if it wasn't found
214
+ */
215
+ remove(by: Tag): boolean;
216
+ /**
217
+ * Removes all items with the array of tags from the collection.
218
+ *
219
+ * @param by - The tags identifying which items to remove
220
+ * @returns True if the item was removed, false if it wasn't found
221
+ */
222
+ remove(by: Tag[]): boolean;
182
223
  /**
183
224
  * Removes all items from the collection.
184
225
  */
@@ -200,26 +241,26 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
200
241
  * Gets all items with the specified tag from the collection.
201
242
  * Uses an optimized internal map for faster lookups.
202
243
  *
203
- * @param tag - The tag to filter by
244
+ * @param by - The tag to filter by
204
245
  * @returns An array of items with the specified tag, or an empty array if none found
205
246
  *
206
247
  * @example
207
248
  * // Get all buildings
208
- * const buildings = collection.getByTag('buildings');
249
+ * const buildings = collection.get('buildings');
209
250
  */
210
- getByTag(tag: Tag): I[];
251
+ get(by: Tag): I[];
211
252
  /**
212
- * Gets the first item matching the tag. More efficient than getByTag when
253
+ * Gets the first item matching the tag. More efficient than `get` when
213
254
  * you only need one item, especially for large collections.
214
255
  *
215
- * @param tag - The tag to search for
256
+ * @param by - The tag to search for
216
257
  * @returns The first matching item or undefined if none found
217
258
  *
218
259
  * @example
219
260
  * // Get the first building
220
- * const firstBuilding = collection.getFirstByTag('buildings');
261
+ * const firstBuilding = collection.first('buildings');
221
262
  */
222
- getFirstByTag(tag: Tag): I | undefined;
263
+ first(by: Tag): I | undefined;
223
264
  /**
224
265
  * Gets all unique tags currently in use in the collection.
225
266
  *
@@ -227,99 +268,63 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
227
268
  *
228
269
  * @example
229
270
  * // Get all tags
230
- * const tags = collection.getTags();
271
+ * const tags = collection.tags;
231
272
  * console.log(`Collection has these tags: ${tags.join(', ')}`);
232
273
  */
233
- getTags(): Tag[];
234
- /**
235
- * Checks if the collection has any items with the specified tag.
236
- *
237
- * @param tag - The tag to check for
238
- * @returns True if items with the tag exist, false otherwise
239
- *
240
- * @example
241
- * if (collection.hasTag('temporary')) {
242
- * console.log('Temporary items exist');
243
- * }
244
- */
245
- hasTag(tag: Tag): boolean;
274
+ get tags(): Tag[];
246
275
  /**
247
276
  * Updates the tag for all items with the specified tag.
248
277
  *
249
- * @param oldTag - The tag to replace
250
- * @param newTag - The new tag to assign
278
+ * @param from - The tag to replace
279
+ * @param to - The new tag to assign
251
280
  * @returns The number of items updated
252
281
  *
253
282
  * @example
254
283
  * // Rename a tag
255
- * const count = collection.updateTag('temp', 'temporary');
284
+ * const count = collection.update('temp', 'temporary');
256
285
  * console.log(`Updated ${count} items`);
257
286
  */
258
- updateTag(oldTag: Tag, newTag: Tag): number;
259
- /**
260
- * Removes all items with the specified tag from the collection.
261
- *
262
- * @param tag - The tag identifying which items to remove
263
- * @returns The number of items removed
264
- *
265
- * @example
266
- * // Remove all temporary markers
267
- * const count = collection.removeByTag('temporary');
268
- * console.log(`Removed ${count} items`);
269
- */
270
- removeByTag(tag: Tag): number;
271
- /**
272
- * Removes all items with the array of tags from the collection.
273
- *
274
- * @param tag - The tags identifying which items to remove
275
- * @returns The number of items removed
276
- *
277
- * @example
278
- * // Remove all items containing tags
279
- * const count = collection.removeByTag('temporary', 'default', 'tag');
280
- * console.log(`Removed ${count} items`);
281
- */
282
- removeByTag(tag: Tag[]): number;
287
+ update(from: Tag, to: Tag): number;
283
288
  /**
284
289
  * Makes all items with the specified tag visible.
285
290
  * Only affects items that have a 'show' property.
286
291
  *
287
- * @param tag - The tag identifying which items to show
288
- * @returns The number of items affected
292
+ * @param by - The tag identifying which items to show
293
+ * @returns The collection itself.
289
294
  *
290
295
  * @example
291
296
  * // Show all buildings
292
297
  * collection.show('buildings');
293
298
  */
294
- show(tag: Tag): number;
299
+ show(by: Tag): this;
295
300
  /**
296
301
  * Hides all items with the specified tag.
297
302
  * Only affects items that have a 'show' property.
298
303
  *
299
- * @param tag - The tag identifying which items to hide
300
- * @returns The number of items affected
304
+ * @param by - The tag identifying which items to hide
305
+ * @returns The collection itself.
301
306
  *
302
307
  * @example
303
308
  * // Hide all buildings
304
309
  * collection.hide('buildings');
305
310
  */
306
- hide(tag: Tag): number;
311
+ hide(by: Tag): this;
307
312
  /**
308
313
  * Toggles visibility of all items with the specified tag.
309
314
  * Only affects items that have a 'show' property.
310
315
  *
311
- * @param tag - The tag identifying which items to toggle
312
- * @returns The number of items affected
316
+ * @param by - The tag identifying which items to toggle
317
+ * @returns The collection itself.
313
318
  *
314
319
  * @example
315
320
  * // Toggle visibility of all buildings
316
321
  * collection.toggle('buildings');
317
322
  */
318
- toggle(tag: Tag): number;
323
+ toggle(by: Tag): this;
319
324
  /**
320
325
  * Sets a property value on all items with the specified tag.
321
326
  *
322
- * @param tag - The tag identifying which items to update
327
+ * @param by - The tag identifying which items to update
323
328
  * @param property - The property name to set
324
329
  * @param value - The value to set
325
330
  * @returns The number of items updated
@@ -328,13 +333,13 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
328
333
  * // Change color of all buildings to red
329
334
  * collection.setProperty('buildings', 'color', Color.RED);
330
335
  */
331
- setProperty<K extends NonFunction<I>, V extends Exclude<I[K], Function>>(property: K, value: V, tag?: Tag): number;
336
+ setProperty<K extends NonFunction<I>, V extends Exclude<I[K], Function>>(property: K, value: V, by?: Tag): this;
332
337
  /**
333
338
  * Filters items in the collection based on a predicate function.
334
339
  * Optionally only filters items with a specific tag.
335
340
  *
336
341
  * @param predicate - Function that tests each item
337
- * @param tag - Optional tag to filter by before applying the predicate
342
+ * @param by - Optional tag to filter by before applying the predicate
338
343
  * @returns Array of items that pass the test
339
344
  *
340
345
  * @example
@@ -344,13 +349,13 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
344
349
  * 'buildings'
345
350
  * );
346
351
  */
347
- filter(predicate: (item: I) => boolean, tag?: Tag): I[];
352
+ filter(predicate: (item: I) => boolean, by?: Tag): I[];
348
353
  /**
349
354
  * Executes a callback function for each item in the collection.
350
355
  * Optionally filters items by tag before execution.
351
356
  *
352
357
  * @param callback - Function to execute for each item
353
- * @param tag - Optional tag to filter items (if not provided, processes all items)
358
+ * @param by - Optional tag to filter items (if not provided, processes all items)
354
359
  *
355
360
  * @example
356
361
  * // Highlight all buildings
@@ -360,7 +365,45 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
360
365
  * }
361
366
  * }, 'buildings');
362
367
  */
363
- forEach(callback: (item: I, index: number) => void, tag?: Tag): void;
368
+ forEach(callback: (value: I, index: number) => void, by?: Tag): void;
369
+ /**
370
+ * Creates a new array with the results of calling a provided function on every element
371
+ * in the collection. Optionally filters by tag before mapping.
372
+ *
373
+ * @param callbackfn - Function that produces an element of the new array
374
+ * @param by - Optional tag to filter items by before mapping
375
+ * @returns A new array with each element being the result of the callback function
376
+ *
377
+ * @example
378
+ * // Get all entity IDs
379
+ * const entityIds = collection.map(entity => entity.id);
380
+ *
381
+ * // Get positions of all buildings
382
+ * const buildingPositions = collection.map(
383
+ * entity => entity.position.getValue(Cesium.JulianDate.now()),
384
+ * 'buildings'
385
+ * );
386
+ */
387
+ map<R>(callbackfn: (value: I, index: number) => R, by?: Tag): R[];
388
+ /**
389
+ * Returns the first element in the collection that satisfies the provided testing function.
390
+ * Optionally filters by tag before searching.
391
+ *
392
+ * @param predicate - Function to test each element
393
+ * @param by - Optional tag to filter items by before searching
394
+ * @returns The first element that passes the test, or undefined if no elements pass
395
+ *
396
+ * @example
397
+ * // Find the first entity with a specific name
398
+ * const namedEntity = collection.find(entity => entity.name === 'Target');
399
+ *
400
+ * // Find the first building taller than 100 meters
401
+ * const tallBuilding = collection.find(
402
+ * entity => entity.properties?.height?.getValue() > 100,
403
+ * 'buildings'
404
+ * );
405
+ */
406
+ find(predicate: (value: I) => boolean, by?: Tag): I | undefined;
364
407
  }
365
408
 
366
409
  export { type CesiumCollection, type CesiumCollectionItem, Collection, type CollectionEventType, type EventHandler, type NonFunction, type Tag, type WithTag };