@juun-roh/cesium-utils 0.3.8 → 0.3.9
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.
- package/dist/chunk-B3AVU53O.js +1 -0
- package/dist/chunk-WCOPDVHL.js +1 -0
- package/dist/collection/index.cjs +1 -1
- package/dist/collection/index.d.cts +514 -2
- package/dist/collection/index.d.ts +514 -2
- package/dist/collection/index.js +1 -1
- package/dist/dev/index.cjs +1 -1
- package/dist/dev/index.d.cts +42 -51
- package/dist/dev/index.d.ts +42 -51
- package/dist/dev/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/type-check-B-zGL1Ne.d.cts +16 -0
- package/dist/type-check-B-zGL1Ne.d.ts +16 -0
- package/package.json +20 -20
- package/dist/chunk-R4DSXQCN.js +0 -1
- package/dist/chunk-RXMNSDKR.js +0 -0
- package/dist/index-iIlou-Sq.d.cts +0 -528
- package/dist/index-iIlou-Sq.d.ts +0 -528
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as f}from"./chunk-6ABRDFE5.js";var _;(l=>{let o=new Set,r=typeof process<"u"?process.env.CESIUM_UTILS_DISABLE_DEPRECATION_WARNINGS!=="true":!0;function e(s,y={}){if(!r)return;let{once:h=!0,prefix:v="[DEPRECATED]",includeStack:u=!0,removeInVersion:b}=y;if(h&&o.has(s))return;let m=`${v} ${s}`;b&&(m+=` This feature will be removed in ${b}.`),typeof console<"u"&&console.warn&&(u?(console.warn(m),console.trace("Deprecation stack trace:")):console.warn(m)),h&&o.add(s)}l.warn=e;function i(s,y,h={}){let v=((...u)=>(e(y,h),s(...u)));return Object.defineProperty(v,"name",{value:s.name,configurable:!0}),v}l.deprecate=i;function t(){o.clear()}l.clear=t;function n(){return o.size}l.getWarningCount=n;function a(s){return o.has(s)}l.hasShown=a})(_||={});var C=_;import{Color as c,TileCoordinatesImageryProvider as P}from"cesium";import{Color as p,GridImageryProvider as w}from"cesium";var d=class extends w{_terrainProvider;_colors;constructor(r){let{terrainProvider:e,colors:i,...t}=r;super(t),this._terrainProvider=e,this._colors=i}requestImage(r,e,i){for(let t of this._terrainProvider.regions)if(this._isInRegion(t,r,e,i))return this._createCanvasElement(this._colors.get("custom")||p.RED);return this._defaultProviderCoversArea(r,e,i)?this._createCanvasElement(this._colors.get("default")||p.BLUE):this._createCanvasElement(this._colors.get("fallback")||p.GRAY)}_isInRegion(r,e,i,t){if(f.TerrainRegion.contains(r,e,i,t))return!0;if(r.tiles){let n=e,a=i,l=t;for(;l>0;)if(l--,n=Math.floor(n/2),a=Math.floor(a/2),f.TerrainRegion.contains(r,n,a,l))return!0}return!1}_defaultProviderCoversArea(r,e,i){let t=r,n=e,a=i;for(;a>=0;){if(this._terrainProvider.defaultProvider.getTileDataAvailable(t,n,a))return!0;if(a===0)break;a--,t=Math.floor(t/2),n=Math.floor(n/2)}return!1}_createCanvasElement(r){let e=document.createElement("canvas");e.width=256,e.height=256;let i=e.getContext("2d"),t=r.withAlpha(.3).toCssColorString();if(!i)throw new Error("canvas context undefined");return i.fillStyle=t,i.fillRect(0,0,256,256),Promise.resolve(e)}};var g=class{_viewer;_terrainProvider;_visible=!1;_tileCoordinatesLayer;_hybridImageryLayer;_colors=new Map([["custom",c.RED],["default",c.BLUE],["fallback",c.GRAY],["grid",c.YELLOW]]);constructor(r,e){this._viewer=r,this._terrainProvider=e.terrainProvider,e.colors&&Object.entries(e.colors).forEach(([i,t])=>{this._colors.set(i,t)}),e.tile!==void 0&&e.tile&&this.show()}setTerrainProvider(r){this._terrainProvider=r,this.update()}update(){let r=this._visible,e=!!this._tileCoordinatesLayer,i=this._hybridImageryLayer?.alpha??.5;this.clear(),r&&this.show({showTileCoordinates:e,alpha:i})}clear(){this.hide()}show(r){if(!this._terrainProvider)return;let e=r?.showTileCoordinates??!0,i=r?.alpha??.5;e&&this._ensureTileCoordinatesLayer(),this.showImageryOverlay(i),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new P({tilingScheme:this._terrainProvider.tilingScheme,color:c.YELLOW})))}hide(){this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this.hideImageryOverlay(),this._visible=!1}setColors(r){Object.entries(r).forEach(([e,i])=>{this._colors.set(e,i)}),this.update()}showImageryOverlay(r=.5){this._hybridImageryLayer&&this._viewer.imageryLayers.remove(this._hybridImageryLayer);let e=new d({terrainProvider:this._terrainProvider,colors:this._colors,tilingScheme:this._terrainProvider.tilingScheme});this._hybridImageryLayer=this._viewer.imageryLayers.addImageryProvider(e),this._hybridImageryLayer.alpha=r,console.log("HybridImageryProvider overlay enabled")}hideImageryOverlay(){this._hybridImageryLayer&&(this._viewer.imageryLayers.remove(this._hybridImageryLayer),this._hybridImageryLayer=void 0,console.log("HybridImageryProvider overlay disabled"))}showTileCoordinates(){this._ensureTileCoordinatesLayer()}hideTileCoordinates(){this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0)}setAlpha(r){this._hybridImageryLayer&&(this._hybridImageryLayer.alpha=r)}flyTo(r,e){this._viewer.camera.flyTo({destination:r,...e,complete:()=>{this._visible&&this.update()}})}get tileCoordinatesVisible(){return!!this._tileCoordinatesLayer}get visible(){return this._visible}get viewer(){return this._viewer}get colors(){return this._colors}get terrainProvider(){return this._terrainProvider}};function L(o,r){let e=!1,i=Object.getOwnPropertyDescriptor(o,r);if(!i){let t=Object.getPrototypeOf(o);for(;t&&!i;)i=Object.getOwnPropertyDescriptor(t,r),t=Object.getPrototypeOf(t)}return i&&i.get&&!i.set&&(e=!0),e}var G=C.deprecate;export{C as a,g as b,L as c,G as d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as l}from"./chunk-B3AVU53O.js";import{DataSourceCollection as d,defined as o,EntityCollection as h,ImageryLayerCollection as v,PrimitiveCollection as c}from"cesium";var r=class s{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]()}get values(){if(this._valuesCache!==null)return this._valuesCache;let e;if(this.collection instanceof h)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 tags(){return Array.from(this._tagMap.keys())}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(a=>{this.add(a,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})),this}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)&&this.collection.remove(e)&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),Array.isArray(e)){if(e.length===0)return this;for(let i of e)this.remove(i)}let t=this.get(e);if(t.length===0)return this;for(let i of t)this.remove(i);return this}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(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}update(e,t){let i=this.get(e);for(let a of i)this._removeFromTagMap(a),Object.defineProperty(a,s.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(a,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)o(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)o(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)o(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let a=this.get(i);for(let n of a)if(e in n&&typeof n[e]!="function"){if(l(n,e))throw Error(`Cannot set read-only property '${String(e)}' on ${n.constructor.name}`);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((a,n)=>e(a,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)}_emit(e,t){let i=this._eventListeners.get(e);if(i){let a={type:e,...t};i.forEach(n=>n(a))}}_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};_setupCacheInvalidator(e){e instanceof h?(e.collectionChanged.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.collectionChanged.removeEventListener(this._invalidateCache))):e instanceof c?(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 d?(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 v&&(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)))}},m=r;export{m as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var P=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var G=(a,e)=>{for(var t in e)P(a,t,{get:e[t],enumerable:!0})},V=(a,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of F(e))!k.call(a,r)&&r!==t&&P(a,r,{get:()=>e[r],enumerable:!(i=D(e,r))||i.enumerable});return a};var H=a=>V(P({},"__esModule",{value:!0}),a);var N={};G(N,{Collection:()=>b});module.exports=H(N);var u=require("cesium");var I;(d=>{let a=new Set,e=typeof process<"u"?process.env.CESIUM_UTILS_DISABLE_DEPRECATION_WARNINGS!=="true":!0;function t(l,o={}){if(!e)return;let{once:h=!0,prefix:v="[DEPRECATED]",includeStack:m=!0,removeInVersion:p}=o;if(h&&a.has(l))return;let f=`${v} ${l}`;p&&(f+=` This feature will be removed in ${p}.`),typeof console<"u"&&console.warn&&(m?(console.warn(f),console.trace("Deprecation stack trace:")):console.warn(f)),h&&a.add(l)}d.warn=t;function i(l,o,h={}){let v=((...m)=>(t(o,h),l(...m)));return Object.defineProperty(v,"name",{value:l.name,configurable:!0}),v}d.deprecate=i;function r(){a.clear()}d.clear=r;function n(){return a.size}d.getWarningCount=n;function c(l){return a.has(l)}d.hasShown=c})(I||={});var R=I;var s=require("cesium");var S=require("cesium"),y=class a{_regions;_defaultProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(e){this._defaultProvider=e.defaultProvider,this._fallbackProvider=e.fallbackProvider||new S.EllipsoidTerrainProvider,this._tilingScheme=e.defaultProvider.tilingScheme,this._regions=e.regions||[],this._availability=e.defaultProvider.availability,this._ready=!0}get ready(){return this._ready}get tilingScheme(){return this._tilingScheme}get availability(){return this._availability}get regions(){return[...this._regions]}get defaultProvider(){return this._defaultProvider}get fallbackProvider(){return this._fallbackProvider}get credit(){return this._defaultProvider?.credit}get errorEvent(){return this._defaultProvider.errorEvent}get hasWaterMask(){return this._defaultProvider.hasWaterMask}get hasVertexNormals(){return this._defaultProvider.hasVertexNormals}loadTileDataAvailability(e,t,i){return this._defaultProvider.loadTileDataAvailability(e,t,i)}getLevelMaximumGeometricError(e){return this._defaultProvider.getLevelMaximumGeometricError(e)}requestTileGeometry(e,t,i,r){if(this._ready){for(let n of this._regions)if(a.TerrainRegion.contains(n,e,t,i))return n.provider.requestTileGeometry(e,t,i,r);return this._defaultProvider.getTileDataAvailable(e,t,i)?this._defaultProvider.requestTileGeometry(e,t,i,r):this._fallbackProvider.requestTileGeometry(e,t,i,r)}}getTileDataAvailable(e,t,i){for(let r of this._regions)if(a.TerrainRegion.contains(r,e,t,i)&&r.provider.getTileDataAvailable(e,t,i))return!0;return this._defaultProvider.getTileDataAvailable(e,t,i)}};(t=>{function a(i,r,n){return new t({regions:i.map(c=>({...c})),defaultProvider:r,fallbackProvider:n})}t.fromTileRanges=a;let e;(r=>{function i(n,c,d,l){if(n.levels&&!n.levels.includes(l))return!1;if(n.tiles){let o=n.tiles.get(l);if(!o)return!1;let[h,v]=Array.isArray(o.x)?o.x:[o.x,o.x],[m,p]=Array.isArray(o.y)?o.y:[o.y,o.y];return c>=h&&c<=v&&d>=m&&d<=p}return!1}r.contains=i})(e=t.TerrainRegion||={})})(y||={});var A=y;var _=class a{_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:a.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(a.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(c=>{this._collection.add(c.entity,a.tag.grid)})}catch(r){console.error("Error displaying tile grid:",r)}}_calculateTileBounds(e,t,i){let r=i.positionToTileXY(s.Rectangle.northwest(e),t),n=i.positionToTileXY(s.Rectangle.southeast(e),t);if(!r||!n)throw new Error("Failed to calculate tile bounds");return{start:r,end:n}}_generateVisibleTiles(e,t,i){let r=[],c=Math.min(e.end.x-e.start.x+1,100),d=Math.min(e.end.y-e.start.y+1,100);for(let l=e.start.x;l<e.start.x+c;l++)for(let o=e.start.y;o<e.start.y+d;o++)try{let h=this._createTileEntity(l,o,t,i);h&&r.push({entity:h})}catch(h){console.warn(`Error creating tile (${l}, ${o}, ${t}):`,h)}return r}_createTileEntity(e,t,i,r){let n=r.tileXYToRectangle(e,t,i);if(!this._isValidRectangle(n))return null;let c=this._getTileColor(e,t,i),d=a.createRectangle(n,c.withAlpha(.3));return d.properties?.addProperty("tileX",e),d.properties?.addProperty("tileY",t),d.properties?.addProperty("tileLevel",i),d}_getTileColor(e,t,i){if(!this._terrainProvider)return this._colors.get("fallback")||s.Color.TRANSPARENT;for(let r of this._terrainProvider.regions)if(A.TerrainRegion.contains(r,e,t,i))return this._colors.get("custom")||s.Color.RED;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(a.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){this._viewer.camera.flyTo({destination:e,...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",grid:"Terrain Visualizer Tile Grid"};function e(r,n){return new s.Entity({rectangle:{coordinates:r,material:n,heightReference:s.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,n,c){let d=c?.tag||"terrain_region_visualization",l=c?.color||s.Color.RED,o=c?.maxTilesToShow||100,h=c?.show??!0,v=c?.tileAlpha||.2,m=new b({collection:n.entities,tag:d});if(h&&r.tiles&&r.tiles.size>0){let p=r.provider.tilingScheme,f=0;r.tiles.forEach((g,M)=>{let w=Array.isArray(g.x)?g.x:[g.x,g.x],L=Array.isArray(g.y)?g.y:[g.y,g.y];for(let T=w[0];T<=w[1]&&f<o;T++)for(let C=L[0];C<=L[1]&&f<o;C++){let O=p.tileXYToRectangle(T,C,M);m.add(e(O,l.withAlpha(v)),`${d}_tile`),f++}})}return m}i.visualize=t})(_||={});function E(a,e){let t=!1,i=Object.getOwnPropertyDescriptor(a,e);if(!i){let r=Object.getPrototypeOf(a);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}var te=R.deprecate;var x=class a{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]()}get values(){if(this._valuesCache!==null)return this._valuesCache;let e;if(this.collection instanceof u.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 tags(){return Array.from(this._tagMap.keys())}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,a.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})),this}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)&&this.collection.remove(e)&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),Array.isArray(e)){if(e.length===0)return this;for(let i of e)this.remove(i)}let t=this.get(e);if(t.length===0)return this;for(let i of t)this.remove(i);return this}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(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}update(e,t){let i=this.get(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,a.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 n of r)if(e in n&&typeof n[e]!="function"){if(E(n,e))throw Error(`Cannot set read-only property '${String(e)}' on ${n.constructor.name}`);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)}_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[a.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 u.EntityCollection?(e.collectionChanged.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.collectionChanged.removeEventListener(this._invalidateCache))):e instanceof u.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 u.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 u.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)))}},b=x;
|
|
1
|
+
"use strict";var y=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var M=(a,e)=>{for(var r in e)y(a,r,{get:e[r],enumerable:!0})},S=(a,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of w(e))!x.call(a,i)&&i!==r&&y(a,i,{get:()=>e[i],enumerable:!(t=E(e,i))||t.enumerable});return a};var A=a=>S(y({},"__esModule",{value:!0}),a);var R={};M(R,{Collection:()=>I});module.exports=A(R);var s=require("cesium");var _;(g=>{let a=new Set,e=typeof process<"u"?process.env.CESIUM_UTILS_DISABLE_DEPRECATION_WARNINGS!=="true":!0;function r(l,o={}){if(!e)return;let{once:d=!0,prefix:h="[DEPRECATED]",includeStack:c=!0,removeInVersion:u}=o;if(d&&a.has(l))return;let f=`${h} ${l}`;u&&(f+=` This feature will be removed in ${u}.`),typeof console<"u"&&console.warn&&(c?(console.warn(f),console.trace("Deprecation stack trace:")):console.warn(f)),d&&a.add(l)}g.warn=r;function t(l,o,d={}){let h=((...c)=>(r(o,d),l(...c)));return Object.defineProperty(h,"name",{value:l.name,configurable:!0}),h}g.deprecate=t;function i(){a.clear()}g.clear=i;function n(){return a.size}g.getWarningCount=n;function v(l){return a.has(l)}g.hasShown=v})(_||={});var C=_;var L=require("cesium");var P=require("cesium");var T=require("cesium"),m=class a{_regions;_defaultProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(e){this._defaultProvider=e.defaultProvider,this._fallbackProvider=e.fallbackProvider||new T.EllipsoidTerrainProvider,this._tilingScheme=e.defaultProvider.tilingScheme,this._regions=e.regions||[],this._availability=e.defaultProvider.availability,this._ready=!0}get ready(){return this._ready}get tilingScheme(){return this._tilingScheme}get availability(){return this._availability}get regions(){return[...this._regions]}get defaultProvider(){return this._defaultProvider}get fallbackProvider(){return this._fallbackProvider}get credit(){return this._defaultProvider?.credit}get errorEvent(){return this._defaultProvider.errorEvent}get hasWaterMask(){return this._defaultProvider.hasWaterMask}get hasVertexNormals(){return this._defaultProvider.hasVertexNormals}loadTileDataAvailability(e,r,t){return this._defaultProvider.loadTileDataAvailability(e,r,t)}getLevelMaximumGeometricError(e){return this._defaultProvider.getLevelMaximumGeometricError(e)}requestTileGeometry(e,r,t,i){if(this._ready){for(let n of this._regions)if(a.TerrainRegion.contains(n,e,r,t))return n.provider.requestTileGeometry(e,r,t,i);return this._defaultProvider.getTileDataAvailable(e,r,t)?this._defaultProvider.requestTileGeometry(e,r,t,i):this._fallbackProvider.requestTileGeometry(e,r,t,i)}}getTileDataAvailable(e,r,t){for(let i of this._regions)if(a.TerrainRegion.contains(i,e,r,t)&&i.provider.getTileDataAvailable(e,r,t))return!0;return this._defaultProvider.getTileDataAvailable(e,r,t)}};(r=>{function a(t,i,n){return new r({regions:t.map(v=>({...v})),defaultProvider:i,fallbackProvider:n})}r.fromTileRanges=a;let e;(i=>{function t(n,v,g,l){if(n.levels&&!n.levels.includes(l))return!1;if(n.tiles){let o=n.tiles.get(l);if(!o)return!1;let[d,h]=Array.isArray(o.x)?o.x:[o.x,o.x],[c,u]=Array.isArray(o.y)?o.y:[o.y,o.y];return v>=d&&v<=h&&g>=c&&g<=u}return!1}i.contains=t})(e=r.TerrainRegion||={})})(m||={});function p(a,e){let r=!1,t=Object.getOwnPropertyDescriptor(a,e);if(!t){let i=Object.getPrototypeOf(a);for(;i&&!t;)t=Object.getOwnPropertyDescriptor(i,e),i=Object.getPrototypeOf(i)}return t&&t.get&&!t.set&&(r=!0),r}var X=C.deprecate;var b=class a{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;_eventCleanupFunctions=[];constructor({collection:e,tag:r}){this.tag=r||"default",this.collection=e,this._setupCacheInvalidator(e)}[Symbol.iterator](){return this.values[Symbol.iterator]()}get values(){if(this._valuesCache!==null)return this._valuesCache;let e;if(this.collection instanceof s.EntityCollection)e=this.collection.values;else{e=[];for(let r=0;r<this.collection.length;r++)e.push(this.collection.get(r))}return this._valuesCache=e,e}get length(){return this.values?.length||0}get tags(){return Array.from(this._tagMap.keys())}addEventListener(e,r){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(r),this}removeEventListener(e,r){return this._eventListeners.get(e)?.delete(r),this}add(e,r=this.tag,t){return Array.isArray(e)?e.forEach(i=>{this.add(i,r)}):(Object.defineProperty(e,a.symbol,{value:r,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,t),this._addToTagMap(e,r),this._invalidateCache(),this._emit("add",{items:[e],tag:r})),this}contains(e){if(typeof e=="object")return this.collection.contains(e);let r=this._tagMap.get(e);return!!r&&r.size>0}remove(e){if(typeof e=="object"&&!Array.isArray(e)&&this.collection.remove(e)&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),Array.isArray(e)){if(e.length===0)return this;for(let t of e)this.remove(t)}let r=this.get(e);if(r.length===0)return this;for(let t of r)this.remove(t);return this}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(e){let r=this._tagMap.get(e);return r?Array.from(r):[]}first(e){let r=this._tagMap.get(e);if(r&&r.size>0)return r.values().next().value}update(e,r){let t=this.get(e);for(let i of t)this._removeFromTagMap(i),Object.defineProperty(i,a.symbol,{value:r,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(i,r);return t.length>0&&this._emit("update",{items:t,tag:r}),t.length}show(e){let r=this.get(e);for(let t of r)(0,s.defined)(t.show)&&(t.show=!0);return this}hide(e){let r=this.get(e);for(let t of r)(0,s.defined)(t.show)&&(t.show=!1);return this}toggle(e){let r=this.get(e);for(let t of r)(0,s.defined)(t.show)&&(t.show=!t.show);return this}setProperty(e,r,t=this.tag){let i=this.get(t);for(let n of i)if(e in n&&typeof n[e]!="function"){if(p(n,e))throw Error(`Cannot set read-only property '${String(e)}' on ${n.constructor.name}`);n[e]=r}return this}filter(e,r){return(r?this.get(r):this.values).filter(e)}forEach(e,r){(r?this.get(r):this.values).forEach((i,n)=>e(i,n))}map(e,r){return(r?this.get(r):this.values).map(e)}find(e,r){return(r?this.get(r):this.values).find(e)}_emit(e,r){let t=this._eventListeners.get(e);if(t){let i={type:e,...r};t.forEach(n=>n(i))}}_addToTagMap(e,r){this._tagMap.has(r)||this._tagMap.set(r,new Set),this._tagMap.get(r)?.add(e)}_removeFromTagMap(e){let r=e[a.symbol],t=this._tagMap.get(r);t&&(t.delete(e),t.size===0&&this._tagMap.delete(r))}_invalidateCache=()=>{this._valuesCache=null};_setupCacheInvalidator(e){e instanceof s.EntityCollection?(e.collectionChanged.addEventListener(this._invalidateCache),this._eventCleanupFunctions.push(()=>e.collectionChanged.removeEventListener(this._invalidateCache))):e instanceof s.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 s.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 s.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)))}},I=b;
|
|
@@ -1,2 +1,514 @@
|
|
|
1
|
-
|
|
2
|
-
import '
|
|
1
|
+
import { DataSourceCollection, EntityCollection, ImageryLayerCollection, PrimitiveCollection, Billboard, Cesium3DTileset, GroundPrimitive, Label, PointPrimitive, Polyline, Primitive, DataSource, Entity, ImageryLayer } from 'cesium';
|
|
2
|
+
import { N as NonFunction } from '../type-check-B-zGL1Ne.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @class
|
|
6
|
+
* A wrapper class that enhances Cesium collection objects with tagging functionality.
|
|
7
|
+
* This class provides a consistent API for working with different types of Cesium collections
|
|
8
|
+
* and allows grouping and manipulating collection items by custom tags.
|
|
9
|
+
*
|
|
10
|
+
* @template C - The type of Cesium collection (e.g., EntityCollection, PrimitiveCollection)
|
|
11
|
+
* @template I - The type of items in the collection (e.g., Entity, Primitive)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Example 1: Managing Complex Scene with Multiple Object Types
|
|
15
|
+
* class SceneOrganizer {
|
|
16
|
+
* private entities: Collection<EntityCollection, Entity>;
|
|
17
|
+
* private billboards: Collection<BillboardCollection, Billboard>;
|
|
18
|
+
* private primitives: Collection<PrimitiveCollection, Primitive>;
|
|
19
|
+
*
|
|
20
|
+
* constructor(viewer: Viewer) {
|
|
21
|
+
* this.entities = new Collection({ collection: viewer.entities });
|
|
22
|
+
* this.billboards = new Collection({
|
|
23
|
+
* collection: viewer.scene.primitives.add(new BillboardCollection())
|
|
24
|
+
* });
|
|
25
|
+
* this.primitives = new Collection({
|
|
26
|
+
* collection: viewer.scene.primitives
|
|
27
|
+
* });
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* // Unified API across different collection types!
|
|
31
|
+
* showLayer(layerName: string) {
|
|
32
|
+
* this.entities.show(layerName);
|
|
33
|
+
* this.billboards.show(layerName);
|
|
34
|
+
* this.primitives.show(layerName);
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* hideLayer(layerName: string) {
|
|
38
|
+
* this.entities.hide(layerName);
|
|
39
|
+
* this.billboards.hide(layerName);
|
|
40
|
+
* this.primitives.hide(layerName);
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* removeLayer(layerName: string) {
|
|
44
|
+
* this.entities.remove(layerName);
|
|
45
|
+
* this.billboards.remove(layerName);
|
|
46
|
+
* this.primitives.remove(layerName);
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* // Example 2: Extend the class for Domain-Specific Needs
|
|
51
|
+
* class BuildingCollection extends Collection<EntityCollection, Entity> {
|
|
52
|
+
* constructor(viewer: Viewer) {
|
|
53
|
+
* super({ collection: viewer.entities, tag: 'buildings' });
|
|
54
|
+
* }
|
|
55
|
+
*
|
|
56
|
+
* addBuilding(options: {
|
|
57
|
+
* position: Cartesian3;
|
|
58
|
+
* height: number;
|
|
59
|
+
* floors: number;
|
|
60
|
+
* type: 'residential' | 'commercial' | 'industrial';
|
|
61
|
+
* }): Entity {
|
|
62
|
+
* const building = new Entity({
|
|
63
|
+
* position: options.position,
|
|
64
|
+
* box: {
|
|
65
|
+
* dimensions: new Cartesian3(50, 50, options.height),
|
|
66
|
+
* material: this.getMaterialForType(options.type)
|
|
67
|
+
* }
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* // Tag by type AND by floor count
|
|
71
|
+
* this.add(building, options.type);
|
|
72
|
+
* this.add(building, `floors-${options.floors}`);
|
|
73
|
+
*
|
|
74
|
+
* return building;
|
|
75
|
+
* }
|
|
76
|
+
*
|
|
77
|
+
* getByFloorRange(min: number, max: number): Entity[] {
|
|
78
|
+
* const results: Entity[] = [];
|
|
79
|
+
* for (let i = min; i <= max; i++) {
|
|
80
|
+
* results.push(...this.get(`floors-${i}`));
|
|
81
|
+
* }
|
|
82
|
+
* return results;
|
|
83
|
+
* }
|
|
84
|
+
*
|
|
85
|
+
* private getMaterialForType(type: string): Material {
|
|
86
|
+
* const colors = {
|
|
87
|
+
* residential: Color.GREEN,
|
|
88
|
+
* commercial: Color.BLUE,
|
|
89
|
+
* industrial: Color.YELLOW
|
|
90
|
+
* };
|
|
91
|
+
* return new ColorMaterialProperty(colors[type] || Color.WHITE);
|
|
92
|
+
* }
|
|
93
|
+
* }
|
|
94
|
+
*/
|
|
95
|
+
declare class Collection<C extends Collection.Base, I extends Collection.ItemFor<C>> {
|
|
96
|
+
/**
|
|
97
|
+
* Symbol used as a property key to store tags on collection items.
|
|
98
|
+
* Using a Symbol ensures no property naming conflicts with the item's own properties.
|
|
99
|
+
* @readonly
|
|
100
|
+
*/
|
|
101
|
+
static readonly symbol: unique symbol;
|
|
102
|
+
/**
|
|
103
|
+
* Default tag used when adding items without specifying a tag.
|
|
104
|
+
* @protected
|
|
105
|
+
*/
|
|
106
|
+
protected tag: Collection.Tag;
|
|
107
|
+
/**
|
|
108
|
+
* The underlying Cesium collection being wrapped.
|
|
109
|
+
* @protected
|
|
110
|
+
*/
|
|
111
|
+
protected collection: C;
|
|
112
|
+
/**
|
|
113
|
+
* Cache for values array to improve performance
|
|
114
|
+
* @private
|
|
115
|
+
*/
|
|
116
|
+
private _valuesCache;
|
|
117
|
+
/**
|
|
118
|
+
* Tag to items map for faster lookups
|
|
119
|
+
* @private
|
|
120
|
+
*/
|
|
121
|
+
private _tagMap;
|
|
122
|
+
/**
|
|
123
|
+
* Event listeners
|
|
124
|
+
* @private
|
|
125
|
+
*/
|
|
126
|
+
private _eventListeners;
|
|
127
|
+
/**
|
|
128
|
+
* For cleaning up the instances
|
|
129
|
+
* @private
|
|
130
|
+
*/
|
|
131
|
+
private _eventCleanupFunctions;
|
|
132
|
+
/**
|
|
133
|
+
* Creates a new Collection instance.
|
|
134
|
+
*
|
|
135
|
+
* @param options - Configuration options
|
|
136
|
+
* @param options.collection - The Cesium collection to wrap
|
|
137
|
+
* @param options.tag - The default tag to use for items (defaults to 'default')
|
|
138
|
+
*/
|
|
139
|
+
constructor({ collection, tag }: {
|
|
140
|
+
collection: C;
|
|
141
|
+
tag?: Collection.Tag;
|
|
142
|
+
});
|
|
143
|
+
/**
|
|
144
|
+
* Makes the collection directly iterable, allowing it to be used in `for...of` loops
|
|
145
|
+
* and with spread operators.
|
|
146
|
+
*
|
|
147
|
+
* @returns An iterator for the items in the collection
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* // Iterate through all items in the collection
|
|
151
|
+
* for (const entity of collection) {
|
|
152
|
+
* console.log(entity.id);
|
|
153
|
+
* }
|
|
154
|
+
*
|
|
155
|
+
* // Convert collection to array using spread syntax
|
|
156
|
+
* const entitiesArray = [...collection];
|
|
157
|
+
*/
|
|
158
|
+
[Symbol.iterator](): Iterator<I>;
|
|
159
|
+
/**
|
|
160
|
+
* Gets all item instances in the collection.
|
|
161
|
+
* This array should not be modified directly.
|
|
162
|
+
*
|
|
163
|
+
* @returns An array of all items in the collection
|
|
164
|
+
*/
|
|
165
|
+
get values(): I[];
|
|
166
|
+
/**
|
|
167
|
+
* Gets the number of items in the collection.
|
|
168
|
+
*
|
|
169
|
+
* @returns The item count
|
|
170
|
+
*/
|
|
171
|
+
get length(): number;
|
|
172
|
+
/**
|
|
173
|
+
* Gets all unique tags currently in use in the collection.
|
|
174
|
+
*
|
|
175
|
+
* @returns An array of all unique tags
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* // Get all tags
|
|
179
|
+
* const tags = collection.tags;
|
|
180
|
+
* console.log(`Collection has these tags: ${tags.join(', ')}`);
|
|
181
|
+
*/
|
|
182
|
+
get tags(): Collection.Tag[];
|
|
183
|
+
/**
|
|
184
|
+
* Registers an event listener for collection events.
|
|
185
|
+
*
|
|
186
|
+
* @param type - The event type to listen for
|
|
187
|
+
* @param handler - The callback function
|
|
188
|
+
* @returns The collection instance for method chaining
|
|
189
|
+
*/
|
|
190
|
+
addEventListener(type: Collection.Event, handler: Collection.EventHandler<I>): this;
|
|
191
|
+
/**
|
|
192
|
+
* Removes an event listener.
|
|
193
|
+
*
|
|
194
|
+
* @param type - The event type
|
|
195
|
+
* @param handler - The callback function to remove
|
|
196
|
+
* @returns The collection instance for method chaining
|
|
197
|
+
*/
|
|
198
|
+
removeEventListener(type: Collection.Event, handler: Collection.EventHandler<I>): this;
|
|
199
|
+
/**
|
|
200
|
+
* Adds a single item with a tag to the collection.
|
|
201
|
+
*
|
|
202
|
+
* @param item - The item to add to the collection
|
|
203
|
+
* @param tag - Tag to associate with this item (defaults to the collection's default tag)
|
|
204
|
+
* @param index - The index to add the item at (if supported by the collection)
|
|
205
|
+
* @returns The collection instance for method chaining
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* const entity = collection.add(new Entity({ ... }), 'landmarks');
|
|
209
|
+
*/
|
|
210
|
+
add(item: I, tag?: Collection.Tag, index?: number): this;
|
|
211
|
+
/**
|
|
212
|
+
* Adds multiple items with the same tag to the collection.
|
|
213
|
+
*
|
|
214
|
+
* @param items - The array of items to add to the collection
|
|
215
|
+
* @param tag - Tag to associate with this item (defaults to the collection's default tag)
|
|
216
|
+
* @returns The collection instance for method chaining
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* // Add multiple entities with the same tag
|
|
220
|
+
* const entities = [new Entity({ ... }), new Entity({ ... })];
|
|
221
|
+
* const addedEntities = collection.add(entities, 'buildings');
|
|
222
|
+
*/
|
|
223
|
+
add(items: I[], tag?: Collection.Tag): this;
|
|
224
|
+
/**
|
|
225
|
+
* Returns true if the provided item is in this collection, false otherwise.
|
|
226
|
+
*
|
|
227
|
+
* @param item - The item instance to check for
|
|
228
|
+
* @returns True if the item is in the collection, false otherwise
|
|
229
|
+
*/
|
|
230
|
+
contains(item: I): boolean;
|
|
231
|
+
/**
|
|
232
|
+
* Checks if the collection has any items with the specified tag.
|
|
233
|
+
*
|
|
234
|
+
* @param tag - The tag to check for
|
|
235
|
+
* @returns True if items with the tag exist, false otherwise
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* if (collection.contains('temporary')) {
|
|
239
|
+
* console.log('Temporary items exist');
|
|
240
|
+
* }
|
|
241
|
+
*/
|
|
242
|
+
contains(tag: Collection.Tag): boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Removes an item from the collection.
|
|
245
|
+
*
|
|
246
|
+
* @param item - The item to remove
|
|
247
|
+
* @returns The collection instance for method chaining
|
|
248
|
+
*/
|
|
249
|
+
remove(item: I): this;
|
|
250
|
+
/**
|
|
251
|
+
* Removes all items with the specified tag from the collection.
|
|
252
|
+
*
|
|
253
|
+
* @param by - The tag identifying which items to remove
|
|
254
|
+
* @returns The collection instance for method chaining
|
|
255
|
+
*/
|
|
256
|
+
remove(by: Collection.Tag): this;
|
|
257
|
+
/**
|
|
258
|
+
* Removes all items with the array of tags from the collection.
|
|
259
|
+
*
|
|
260
|
+
* @param by - The tags identifying which items to remove
|
|
261
|
+
* @returns The collection instance for method chaining
|
|
262
|
+
*/
|
|
263
|
+
remove(by: Collection.Tag[]): this;
|
|
264
|
+
/**
|
|
265
|
+
* Removes all items from the collection.
|
|
266
|
+
*/
|
|
267
|
+
removeAll(): void;
|
|
268
|
+
/**
|
|
269
|
+
* Permanently destroys this Collection instance.
|
|
270
|
+
* Removes all event listeners and clears internal state.
|
|
271
|
+
* The Collection instance should not be used after calling this method.
|
|
272
|
+
*/
|
|
273
|
+
destroy(): void;
|
|
274
|
+
/**
|
|
275
|
+
* Gets all items with the specified tag from the collection.
|
|
276
|
+
* Uses an optimized internal map for faster lookups.
|
|
277
|
+
*
|
|
278
|
+
* @param by - The tag to filter by
|
|
279
|
+
* @returns An array of items with the specified tag, or an empty array if none found
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* // Get all buildings
|
|
283
|
+
* const buildings = collection.get('buildings');
|
|
284
|
+
*/
|
|
285
|
+
get(by: Collection.Tag): I[];
|
|
286
|
+
/**
|
|
287
|
+
* Gets the first item matching the tag. More efficient than `get` when
|
|
288
|
+
* you only need one item, especially for large collections.
|
|
289
|
+
*
|
|
290
|
+
* @param by - The tag to search for
|
|
291
|
+
* @returns The first matching item or undefined if none found
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* // Get the first building
|
|
295
|
+
* const firstBuilding = collection.first('buildings');
|
|
296
|
+
*/
|
|
297
|
+
first(by: Collection.Tag): I | undefined;
|
|
298
|
+
/**
|
|
299
|
+
* Updates the tag for all items with the specified tag.
|
|
300
|
+
*
|
|
301
|
+
* @param from - The tag to replace
|
|
302
|
+
* @param to - The new tag to assign
|
|
303
|
+
* @returns The number of items updated
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* // Rename a tag
|
|
307
|
+
* const count = collection.update('temp', 'temporary');
|
|
308
|
+
* console.log(`Updated ${count} items`);
|
|
309
|
+
*/
|
|
310
|
+
update(from: Collection.Tag, to: Collection.Tag): number;
|
|
311
|
+
/**
|
|
312
|
+
* Makes all items with the specified tag visible.
|
|
313
|
+
* Only affects items that have a 'show' property.
|
|
314
|
+
*
|
|
315
|
+
* @param by - The tag identifying which items to show
|
|
316
|
+
* @returns The collection itself.
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* // Show all buildings
|
|
320
|
+
* collection.show('buildings');
|
|
321
|
+
*/
|
|
322
|
+
show(by: Collection.Tag): this;
|
|
323
|
+
/**
|
|
324
|
+
* Hides all items with the specified tag.
|
|
325
|
+
* Only affects items that have a 'show' property.
|
|
326
|
+
*
|
|
327
|
+
* @param by - The tag identifying which items to hide
|
|
328
|
+
* @returns The collection itself.
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* // Hide all buildings
|
|
332
|
+
* collection.hide('buildings');
|
|
333
|
+
*/
|
|
334
|
+
hide(by: Collection.Tag): this;
|
|
335
|
+
/**
|
|
336
|
+
* Toggles visibility of all items with the specified tag.
|
|
337
|
+
* Only affects items that have a 'show' property.
|
|
338
|
+
*
|
|
339
|
+
* @param by - The tag identifying which items to toggle
|
|
340
|
+
* @returns The collection itself.
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* // Toggle visibility of all buildings
|
|
344
|
+
* collection.toggle('buildings');
|
|
345
|
+
*/
|
|
346
|
+
toggle(by: Collection.Tag): this;
|
|
347
|
+
/**
|
|
348
|
+
* Sets a property value on all items with the specified tag.
|
|
349
|
+
*
|
|
350
|
+
* @template K - A type
|
|
351
|
+
*
|
|
352
|
+
* @param property - The property name to set
|
|
353
|
+
* @param value - The value to set
|
|
354
|
+
* @param by - The tag identifying which items to update
|
|
355
|
+
* @returns The collection itself.
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* // Change color of all buildings to red
|
|
359
|
+
* collection.setProperty('color', Color.RED, 'buildings');
|
|
360
|
+
*/
|
|
361
|
+
setProperty<K extends NonFunction<I>>(property: K, value: I[K], by?: Collection.Tag): this;
|
|
362
|
+
/**
|
|
363
|
+
* Filters items in the collection based on a predicate function.
|
|
364
|
+
* Optionally only filters items with a specific tag.
|
|
365
|
+
*
|
|
366
|
+
* @param predicate - Function that tests each item
|
|
367
|
+
* @param by - Optional tag to filter by before applying the predicate
|
|
368
|
+
* @returns Array of items that pass the test
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* // Get all buildings taller than 100 meters
|
|
372
|
+
* const tallBuildings = collection.filter(
|
|
373
|
+
* entity => entity.properties?.height?.getValue() > 100,
|
|
374
|
+
* 'buildings'
|
|
375
|
+
* );
|
|
376
|
+
*/
|
|
377
|
+
filter(predicate: (item: I) => boolean, by?: Collection.Tag): I[];
|
|
378
|
+
/**
|
|
379
|
+
* Executes a callback function for each item in the collection.
|
|
380
|
+
* Optionally filters items by tag before execution.
|
|
381
|
+
*
|
|
382
|
+
* @param callback - Function to execute for each item
|
|
383
|
+
* @param by - Optional tag to filter items (if not provided, processes all items)
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* // Highlight all buildings
|
|
387
|
+
* collection.forEach((entity) => {
|
|
388
|
+
* if (entity.polygon) {
|
|
389
|
+
* entity.polygon.material = new ColorMaterialProperty(Color.YELLOW);
|
|
390
|
+
* }
|
|
391
|
+
* }, 'buildings');
|
|
392
|
+
*/
|
|
393
|
+
forEach(callback: (value: I, index: number) => void, by?: Collection.Tag): void;
|
|
394
|
+
/**
|
|
395
|
+
* Creates a new array with the results of calling a provided function on every element
|
|
396
|
+
* in the collection. Optionally filters by tag before mapping.
|
|
397
|
+
*
|
|
398
|
+
* @param callbackfn - Function that produces an element of the new array
|
|
399
|
+
* @param by - Optional tag to filter items by before mapping
|
|
400
|
+
* @returns A new array with each element being the result of the callback function
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* // Get all entity IDs
|
|
404
|
+
* const entityIds = collection.map(entity => entity.id);
|
|
405
|
+
*
|
|
406
|
+
* // Get positions of all buildings
|
|
407
|
+
* const buildingPositions = collection.map(
|
|
408
|
+
* entity => entity.position.getValue(Cesium.JulianDate.now()),
|
|
409
|
+
* 'buildings'
|
|
410
|
+
* );
|
|
411
|
+
*/
|
|
412
|
+
map<R>(callbackfn: (value: I, index: number) => R, by?: Collection.Tag): R[];
|
|
413
|
+
/**
|
|
414
|
+
* Returns the first element in the collection that satisfies the provided testing function.
|
|
415
|
+
* Optionally filters by tag before searching.
|
|
416
|
+
*
|
|
417
|
+
* @param predicate - Function to test each element
|
|
418
|
+
* @param by - Optional tag to filter items by before searching
|
|
419
|
+
* @returns The first element that passes the test, or undefined if no elements pass
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* // Find the first entity with a specific name
|
|
423
|
+
* const namedEntity = collection.find(entity => entity.name === 'Target');
|
|
424
|
+
*
|
|
425
|
+
* // Find the first building taller than 100 meters
|
|
426
|
+
* const tallBuilding = collection.find(
|
|
427
|
+
* entity => entity.properties?.height?.getValue() > 100,
|
|
428
|
+
* 'buildings'
|
|
429
|
+
* );
|
|
430
|
+
*/
|
|
431
|
+
find(predicate: (value: I) => boolean, by?: Collection.Tag): I | undefined;
|
|
432
|
+
/**
|
|
433
|
+
* Emits an event to all registered listeners.
|
|
434
|
+
*
|
|
435
|
+
* @private
|
|
436
|
+
* @param type - The event type
|
|
437
|
+
* @param data - Additional event data
|
|
438
|
+
*/
|
|
439
|
+
private _emit;
|
|
440
|
+
/**
|
|
441
|
+
* Adds an item to the internal tag map for quick lookups.
|
|
442
|
+
*
|
|
443
|
+
* @private
|
|
444
|
+
* @param item - The item to add
|
|
445
|
+
* @param tag - The tag to associate with the item
|
|
446
|
+
*/
|
|
447
|
+
private _addToTagMap;
|
|
448
|
+
/**
|
|
449
|
+
* Removes an item from the internal tag map.
|
|
450
|
+
*
|
|
451
|
+
* @private
|
|
452
|
+
* @param item - The item to remove
|
|
453
|
+
*/
|
|
454
|
+
private _removeFromTagMap;
|
|
455
|
+
/**
|
|
456
|
+
* Invalidates the values cache when collection changes.
|
|
457
|
+
*
|
|
458
|
+
* @private
|
|
459
|
+
*/
|
|
460
|
+
private _invalidateCache;
|
|
461
|
+
/**
|
|
462
|
+
* Sets up automatic cache invalidation by registering event listeners on the underlying Cesium collection.
|
|
463
|
+
*
|
|
464
|
+
* @private
|
|
465
|
+
* @param collection - The Cesium collection to monitor for changes
|
|
466
|
+
*
|
|
467
|
+
* @see {@link destroy} For cleanup of event listeners
|
|
468
|
+
* @see {@link _invalidateCache} For the actual cache invalidation logic
|
|
469
|
+
*/
|
|
470
|
+
private _setupCacheInvalidator;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* @namespace
|
|
474
|
+
*/
|
|
475
|
+
declare namespace Collection {
|
|
476
|
+
/**
|
|
477
|
+
* The underlying Cesium collection type being wrapped.
|
|
478
|
+
*/
|
|
479
|
+
export type Base = DataSourceCollection | EntityCollection | ImageryLayerCollection | PrimitiveCollection;
|
|
480
|
+
/**
|
|
481
|
+
* The item types that can be added to the `PrimitiveCollection` instance.
|
|
482
|
+
*/
|
|
483
|
+
type Primitives = Billboard | Cesium3DTileset | GroundPrimitive | Label | PointPrimitive | Polyline | Primitive;
|
|
484
|
+
/**
|
|
485
|
+
* Cesium item type that can be added to the {@link Collection.Base} instance.
|
|
486
|
+
*/
|
|
487
|
+
export type Item = DataSource | Entity | ImageryLayer | Primitives;
|
|
488
|
+
/**
|
|
489
|
+
* Gets the item type for a given collection type
|
|
490
|
+
*/
|
|
491
|
+
export type ItemFor<C extends Base> = C extends DataSourceCollection ? DataSource : C extends EntityCollection ? Entity : C extends ImageryLayerCollection ? ImageryLayer : C extends PrimitiveCollection ? Primitives : never;
|
|
492
|
+
/**
|
|
493
|
+
* Collection tag type.
|
|
494
|
+
*/
|
|
495
|
+
export type Tag = string | number;
|
|
496
|
+
export interface WithTag {
|
|
497
|
+
[key: symbol]: Tag;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Collection event types
|
|
501
|
+
*/
|
|
502
|
+
export type Event = "add" | "remove" | "update" | "clear";
|
|
503
|
+
/**
|
|
504
|
+
* Event handler function type
|
|
505
|
+
*/
|
|
506
|
+
export type EventHandler<I> = (event: {
|
|
507
|
+
type: Event;
|
|
508
|
+
items?: I[];
|
|
509
|
+
tag?: Collection.Tag;
|
|
510
|
+
}) => void;
|
|
511
|
+
export { };
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
export { Collection };
|