@juun-roh/cesium-utils 0.0.5 → 0.0.7
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-MIDZHLUZ.js +1 -0
- package/dist/collection/index.cjs +1 -1
- package/dist/collection/index.d.cts +114 -68
- package/dist/collection/index.d.ts +114 -68
- package/dist/collection/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.d.cts +10 -1
- package/dist/utils/index.d.ts +10 -1
- package/dist/utils/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-CNYZN4AC.js +0 -1
- package/dist/chunk-KDRPSZ3A.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Color as c,Entity as S,HeightReference as V,Rectangle as L,TileCoordinatesImageryProvider as j}from"cesium";import{defined as w,EntityCollection as P}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 P)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 v=class s{_viewer;_collection;_hybridTerrain;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",c.RED],["default",c.BLUE],["fallback",c.GRAY],["grid",c.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 j({tilingScheme:t,color:c.YELLOW})));let i=(o,a,u)=>{if(this._hybridTerrain){for(let g of this._hybridTerrain.terrainAreas)if(g.contains(o,a,u))return g.isCustom?this._colors.get("custom")||c.RED:this._colors.get("default")||c.BLUE;if(this._hybridTerrain.getTileDataAvailable(o,a,u))return this._colors.get("default")||c.BLUE}return this._colors.get("fallback")||c.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(L.northwest(r),e),a=t.positionToTileXY(L.southeast(r),e);if(!o||!a)return;let u=100,g=Math.min(a.x-o.x+1,u),b=Math.min(a.y-o.y+1,u);for(let h=o.x;h<=o.x+g-1;h++)for(let d=o.y;d<=o.y+b-1;d++)try{let l=t.tileXYToRectangle(h,d,e);if(!n(l)){console.warn(`Invalid rectangle for tile (${h}, ${d}, ${e}), skipping`);continue}let f=i(h,d,e),m=s.createRectangle(l,f.withAlpha(.3));m.properties?.addProperty("tileX",h),m.properties?.addProperty("tileY",d),m.properties?.addProperty("tileLevel",e),this._collection.add(m,s.tag.grid)}catch(l){console.warn(`Error creating tile (${h}, ${d}, ${e}): ${l.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.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,n){return new S({rectangle:{coordinates:r,material:n,heightReference:V.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,n,o){let a=o?.tag||"terrain_area_visualization",u=o?.color||c.RED,g=o?.maxTilesToShow||100,b=o?.show??!0,h=o?.alpha||.7,d=o?.tileAlpha||.2,l="provider"in r?r.bounds:r,f=new E({collection:n.entities,tag:a}),{rectangle:m}=l;if(f.add(i.createRectangle(m,u.withAlpha(h)),a),b&&l.levels.size>0){let{tilingScheme:R}=l;l.levels.forEach(x=>{let y=0,{tileRanges:A}=l;for(let[M,p]of A.entries())if(M===x)for(let T=p.start.x;T<=p.end.x&&y<g;T++)for(let _=p.start.y;_<=p.end.y&&y<g;_++){let O=R.tileXYToRectangle(T,_,x);f.add(e(O,u.withAlpha(d)),`${a}_tile`),y++}})}return f}i.visualize=t})(v||={});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{v as a,I as b,E as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var I=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var j=(n,e)=>{for(var t in e)I(n,t,{get:e[t],enumerable:!0})},z=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of V(e))!S.call(n,r)&&r!==t&&I(n,r,{get:()=>e[r],enumerable:!(i=P(e,r))||i.enumerable});return n};var F=n=>z(I({},"__esModule",{value:!0}),n);var H={};j(H,{Collection:()=>y});module.exports=F(H);var f=require("cesium");var s=require("cesium");var p=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 y({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),t.tile!==void 0&&(this._visible=t.tile),t.activeLevel!==void 0&&(this._level=t.activeLevel),t.terrainProvider&&this.setTerrainProvider(t.terrainProvider))}setTerrainProvider(e){this._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,u)=>{if(this._hybridTerrain){for(let m of this._hybridTerrain.terrainAreas)if(m.contains(o,l,u))return m.isCustom?this._colors.get("custom")||s.Color.RED:this._colors.get("default")||s.Color.BLUE;if(this._hybridTerrain.getTileDataAvailable(o,l,u))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 u=100,m=Math.min(l.x-o.x+1,u),T=Math.min(l.y-o.y+1,u);for(let h=o.x;h<=o.x+m-1;h++)for(let d=o.y;d<=o.y+T-1;d++)try{let c=t.tileXYToRectangle(h,d,e);if(!a(c)){console.warn(`Invalid rectangle for tile (${h}, ${d}, ${e}), skipping`);continue}let v=i(h,d,e),g=n.createRectangle(c,v.withAlpha(.3));g.properties?.addProperty("tileX",h),g.properties?.addProperty("tileY",d),g.properties?.addProperty("tileLevel",e),this._collection.add(g,n.tag.grid)}catch(c){console.warn(`Error creating tile (${h}, ${d}, ${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.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.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,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",u=o?.color||s.Color.RED,m=o?.maxTilesToShow||100,T=o?.show??!0,h=o?.alpha||.7,d=o?.tileAlpha||.2,c="provider"in r?r.bounds:r,v=new y({collection:a.entities,tag:l}),{rectangle:g}=c;if(v.add(i.createRectangle(g,u.withAlpha(h)),l),T&&c.levels.size>0){let{tilingScheme:R}=c;c.levels.forEach(L=>{let _=0,{tileRanges:A}=c;for(let[M,b]of A.entries())if(M===L)for(let C=b.start.x;C<=b.end.x&&_<m;C++)for(let w=b.start.y;w<=b.end.y&&_<m;w++){let O=R.tileXYToRectangle(C,w,L);v.add(e(O,u.withAlpha(d)),`${l}_tile`),_++}})}return v}i.visualize=t})(p||={});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 $=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)}},y=x;
|
|
@@ -19,6 +19,9 @@ type EventHandler<I> = (event: {
|
|
|
19
19
|
items?: I[];
|
|
20
20
|
tag?: Tag;
|
|
21
21
|
}) => void;
|
|
22
|
+
type NonFunction<T> = {
|
|
23
|
+
[K in keyof T]: T[K] extends Function ? never : K;
|
|
24
|
+
}[keyof T];
|
|
22
25
|
|
|
23
26
|
/**
|
|
24
27
|
* @class
|
|
@@ -46,8 +49,7 @@ type EventHandler<I> = (event: {
|
|
|
46
49
|
* entities.add(new Entity({ ... }), 'roads');
|
|
47
50
|
*
|
|
48
51
|
* // Later, show only buildings
|
|
49
|
-
* entities.show('buildings');
|
|
50
|
-
* entities.hide('roads');
|
|
52
|
+
* entities.show('buildings').hide('roads');
|
|
51
53
|
*/
|
|
52
54
|
declare class Collection<C extends CesiumCollection, I extends CesiumCollectionItem> {
|
|
53
55
|
/**
|
|
@@ -92,6 +94,22 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
92
94
|
collection: C;
|
|
93
95
|
tag?: Tag;
|
|
94
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>;
|
|
95
113
|
/**
|
|
96
114
|
* Emits an event to all registered listeners.
|
|
97
115
|
*
|
|
@@ -165,10 +183,22 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
165
183
|
/**
|
|
166
184
|
* Returns true if the provided item is in this collection, false otherwise.
|
|
167
185
|
*
|
|
168
|
-
* @param item - The item to check for
|
|
186
|
+
* @param item - The item instance to check for
|
|
169
187
|
* @returns True if the item is in the collection, false otherwise
|
|
170
188
|
*/
|
|
171
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;
|
|
172
202
|
/**
|
|
173
203
|
* Removes an item from the collection.
|
|
174
204
|
*
|
|
@@ -176,6 +206,20 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
176
206
|
* @returns True if the item was removed, false if it wasn't found
|
|
177
207
|
*/
|
|
178
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;
|
|
179
223
|
/**
|
|
180
224
|
* Removes all items from the collection.
|
|
181
225
|
*/
|
|
@@ -197,26 +241,26 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
197
241
|
* Gets all items with the specified tag from the collection.
|
|
198
242
|
* Uses an optimized internal map for faster lookups.
|
|
199
243
|
*
|
|
200
|
-
* @param
|
|
244
|
+
* @param by - The tag to filter by
|
|
201
245
|
* @returns An array of items with the specified tag, or an empty array if none found
|
|
202
246
|
*
|
|
203
247
|
* @example
|
|
204
248
|
* // Get all buildings
|
|
205
|
-
* const buildings = collection.
|
|
249
|
+
* const buildings = collection.get('buildings');
|
|
206
250
|
*/
|
|
207
|
-
|
|
251
|
+
get(by: Tag): I[];
|
|
208
252
|
/**
|
|
209
|
-
* Gets the first item matching the tag. More efficient than
|
|
253
|
+
* Gets the first item matching the tag. More efficient than `get` when
|
|
210
254
|
* you only need one item, especially for large collections.
|
|
211
255
|
*
|
|
212
|
-
* @param
|
|
256
|
+
* @param by - The tag to search for
|
|
213
257
|
* @returns The first matching item or undefined if none found
|
|
214
258
|
*
|
|
215
259
|
* @example
|
|
216
260
|
* // Get the first building
|
|
217
|
-
* const firstBuilding = collection.
|
|
261
|
+
* const firstBuilding = collection.first('buildings');
|
|
218
262
|
*/
|
|
219
|
-
|
|
263
|
+
first(by: Tag): I | undefined;
|
|
220
264
|
/**
|
|
221
265
|
* Gets all unique tags currently in use in the collection.
|
|
222
266
|
*
|
|
@@ -224,99 +268,63 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
224
268
|
*
|
|
225
269
|
* @example
|
|
226
270
|
* // Get all tags
|
|
227
|
-
* const tags = collection.
|
|
271
|
+
* const tags = collection.tags;
|
|
228
272
|
* console.log(`Collection has these tags: ${tags.join(', ')}`);
|
|
229
273
|
*/
|
|
230
|
-
|
|
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.hasTag('temporary')) {
|
|
239
|
-
* console.log('Temporary items exist');
|
|
240
|
-
* }
|
|
241
|
-
*/
|
|
242
|
-
hasTag(tag: Tag): boolean;
|
|
274
|
+
get tags(): Tag[];
|
|
243
275
|
/**
|
|
244
276
|
* Updates the tag for all items with the specified tag.
|
|
245
277
|
*
|
|
246
|
-
* @param
|
|
247
|
-
* @param
|
|
278
|
+
* @param from - The tag to replace
|
|
279
|
+
* @param to - The new tag to assign
|
|
248
280
|
* @returns The number of items updated
|
|
249
281
|
*
|
|
250
282
|
* @example
|
|
251
283
|
* // Rename a tag
|
|
252
|
-
* const count = collection.
|
|
284
|
+
* const count = collection.update('temp', 'temporary');
|
|
253
285
|
* console.log(`Updated ${count} items`);
|
|
254
286
|
*/
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Removes all items with the specified tag from the collection.
|
|
258
|
-
*
|
|
259
|
-
* @param tag - The tag identifying which items to remove
|
|
260
|
-
* @returns The number of items removed
|
|
261
|
-
*
|
|
262
|
-
* @example
|
|
263
|
-
* // Remove all temporary markers
|
|
264
|
-
* const count = collection.removeByTag('temporary');
|
|
265
|
-
* console.log(`Removed ${count} items`);
|
|
266
|
-
*/
|
|
267
|
-
removeByTag(tag: Tag): number;
|
|
268
|
-
/**
|
|
269
|
-
* Removes all items with the array of tags from the collection.
|
|
270
|
-
*
|
|
271
|
-
* @param tag - The tags identifying which items to remove
|
|
272
|
-
* @returns The number of items removed
|
|
273
|
-
*
|
|
274
|
-
* @example
|
|
275
|
-
* // Remove all items containing tags
|
|
276
|
-
* const count = collection.removeByTag('temporary', 'default', 'tag');
|
|
277
|
-
* console.log(`Removed ${count} items`);
|
|
278
|
-
*/
|
|
279
|
-
removeByTag(tag: Tag[]): number;
|
|
287
|
+
update(from: Tag, to: Tag): number;
|
|
280
288
|
/**
|
|
281
289
|
* Makes all items with the specified tag visible.
|
|
282
290
|
* Only affects items that have a 'show' property.
|
|
283
291
|
*
|
|
284
|
-
* @param
|
|
285
|
-
* @returns The
|
|
292
|
+
* @param by - The tag identifying which items to show
|
|
293
|
+
* @returns The collection itself.
|
|
286
294
|
*
|
|
287
295
|
* @example
|
|
288
296
|
* // Show all buildings
|
|
289
297
|
* collection.show('buildings');
|
|
290
298
|
*/
|
|
291
|
-
show(
|
|
299
|
+
show(by: Tag): this;
|
|
292
300
|
/**
|
|
293
301
|
* Hides all items with the specified tag.
|
|
294
302
|
* Only affects items that have a 'show' property.
|
|
295
303
|
*
|
|
296
|
-
* @param
|
|
297
|
-
* @returns The
|
|
304
|
+
* @param by - The tag identifying which items to hide
|
|
305
|
+
* @returns The collection itself.
|
|
298
306
|
*
|
|
299
307
|
* @example
|
|
300
308
|
* // Hide all buildings
|
|
301
309
|
* collection.hide('buildings');
|
|
302
310
|
*/
|
|
303
|
-
hide(
|
|
311
|
+
hide(by: Tag): this;
|
|
304
312
|
/**
|
|
305
313
|
* Toggles visibility of all items with the specified tag.
|
|
306
314
|
* Only affects items that have a 'show' property.
|
|
307
315
|
*
|
|
308
|
-
* @param
|
|
309
|
-
* @returns The
|
|
316
|
+
* @param by - The tag identifying which items to toggle
|
|
317
|
+
* @returns The collection itself.
|
|
310
318
|
*
|
|
311
319
|
* @example
|
|
312
320
|
* // Toggle visibility of all buildings
|
|
313
321
|
* collection.toggle('buildings');
|
|
314
322
|
*/
|
|
315
|
-
toggle(
|
|
323
|
+
toggle(by: Tag): this;
|
|
316
324
|
/**
|
|
317
325
|
* Sets a property value on all items with the specified tag.
|
|
318
326
|
*
|
|
319
|
-
* @param
|
|
327
|
+
* @param by - The tag identifying which items to update
|
|
320
328
|
* @param property - The property name to set
|
|
321
329
|
* @param value - The value to set
|
|
322
330
|
* @returns The number of items updated
|
|
@@ -325,13 +333,13 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
325
333
|
* // Change color of all buildings to red
|
|
326
334
|
* collection.setProperty('buildings', 'color', Color.RED);
|
|
327
335
|
*/
|
|
328
|
-
setProperty<K extends
|
|
336
|
+
setProperty<K extends NonFunction<I>, V extends Exclude<I[K], Function>>(property: K, value: V, by?: Tag): this;
|
|
329
337
|
/**
|
|
330
338
|
* Filters items in the collection based on a predicate function.
|
|
331
339
|
* Optionally only filters items with a specific tag.
|
|
332
340
|
*
|
|
333
341
|
* @param predicate - Function that tests each item
|
|
334
|
-
* @param
|
|
342
|
+
* @param by - Optional tag to filter by before applying the predicate
|
|
335
343
|
* @returns Array of items that pass the test
|
|
336
344
|
*
|
|
337
345
|
* @example
|
|
@@ -341,13 +349,13 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
341
349
|
* 'buildings'
|
|
342
350
|
* );
|
|
343
351
|
*/
|
|
344
|
-
filter(predicate: (item: I) => boolean,
|
|
352
|
+
filter(predicate: (item: I) => boolean, by?: Tag): I[];
|
|
345
353
|
/**
|
|
346
354
|
* Executes a callback function for each item in the collection.
|
|
347
355
|
* Optionally filters items by tag before execution.
|
|
348
356
|
*
|
|
349
357
|
* @param callback - Function to execute for each item
|
|
350
|
-
* @param
|
|
358
|
+
* @param by - Optional tag to filter items (if not provided, processes all items)
|
|
351
359
|
*
|
|
352
360
|
* @example
|
|
353
361
|
* // Highlight all buildings
|
|
@@ -357,7 +365,45 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
357
365
|
* }
|
|
358
366
|
* }, 'buildings');
|
|
359
367
|
*/
|
|
360
|
-
forEach(callback: (
|
|
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;
|
|
361
407
|
}
|
|
362
408
|
|
|
363
|
-
export { type CesiumCollection, type CesiumCollectionItem, Collection, type CollectionEventType, type EventHandler, type
|
|
409
|
+
export { type CesiumCollection, type CesiumCollectionItem, Collection, type CollectionEventType, type EventHandler, type NonFunction, type Tag, type WithTag };
|
|
@@ -19,6 +19,9 @@ type EventHandler<I> = (event: {
|
|
|
19
19
|
items?: I[];
|
|
20
20
|
tag?: Tag;
|
|
21
21
|
}) => void;
|
|
22
|
+
type NonFunction<T> = {
|
|
23
|
+
[K in keyof T]: T[K] extends Function ? never : K;
|
|
24
|
+
}[keyof T];
|
|
22
25
|
|
|
23
26
|
/**
|
|
24
27
|
* @class
|
|
@@ -46,8 +49,7 @@ type EventHandler<I> = (event: {
|
|
|
46
49
|
* entities.add(new Entity({ ... }), 'roads');
|
|
47
50
|
*
|
|
48
51
|
* // Later, show only buildings
|
|
49
|
-
* entities.show('buildings');
|
|
50
|
-
* entities.hide('roads');
|
|
52
|
+
* entities.show('buildings').hide('roads');
|
|
51
53
|
*/
|
|
52
54
|
declare class Collection<C extends CesiumCollection, I extends CesiumCollectionItem> {
|
|
53
55
|
/**
|
|
@@ -92,6 +94,22 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
92
94
|
collection: C;
|
|
93
95
|
tag?: Tag;
|
|
94
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>;
|
|
95
113
|
/**
|
|
96
114
|
* Emits an event to all registered listeners.
|
|
97
115
|
*
|
|
@@ -165,10 +183,22 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
165
183
|
/**
|
|
166
184
|
* Returns true if the provided item is in this collection, false otherwise.
|
|
167
185
|
*
|
|
168
|
-
* @param item - The item to check for
|
|
186
|
+
* @param item - The item instance to check for
|
|
169
187
|
* @returns True if the item is in the collection, false otherwise
|
|
170
188
|
*/
|
|
171
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;
|
|
172
202
|
/**
|
|
173
203
|
* Removes an item from the collection.
|
|
174
204
|
*
|
|
@@ -176,6 +206,20 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
176
206
|
* @returns True if the item was removed, false if it wasn't found
|
|
177
207
|
*/
|
|
178
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;
|
|
179
223
|
/**
|
|
180
224
|
* Removes all items from the collection.
|
|
181
225
|
*/
|
|
@@ -197,26 +241,26 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
197
241
|
* Gets all items with the specified tag from the collection.
|
|
198
242
|
* Uses an optimized internal map for faster lookups.
|
|
199
243
|
*
|
|
200
|
-
* @param
|
|
244
|
+
* @param by - The tag to filter by
|
|
201
245
|
* @returns An array of items with the specified tag, or an empty array if none found
|
|
202
246
|
*
|
|
203
247
|
* @example
|
|
204
248
|
* // Get all buildings
|
|
205
|
-
* const buildings = collection.
|
|
249
|
+
* const buildings = collection.get('buildings');
|
|
206
250
|
*/
|
|
207
|
-
|
|
251
|
+
get(by: Tag): I[];
|
|
208
252
|
/**
|
|
209
|
-
* Gets the first item matching the tag. More efficient than
|
|
253
|
+
* Gets the first item matching the tag. More efficient than `get` when
|
|
210
254
|
* you only need one item, especially for large collections.
|
|
211
255
|
*
|
|
212
|
-
* @param
|
|
256
|
+
* @param by - The tag to search for
|
|
213
257
|
* @returns The first matching item or undefined if none found
|
|
214
258
|
*
|
|
215
259
|
* @example
|
|
216
260
|
* // Get the first building
|
|
217
|
-
* const firstBuilding = collection.
|
|
261
|
+
* const firstBuilding = collection.first('buildings');
|
|
218
262
|
*/
|
|
219
|
-
|
|
263
|
+
first(by: Tag): I | undefined;
|
|
220
264
|
/**
|
|
221
265
|
* Gets all unique tags currently in use in the collection.
|
|
222
266
|
*
|
|
@@ -224,99 +268,63 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
224
268
|
*
|
|
225
269
|
* @example
|
|
226
270
|
* // Get all tags
|
|
227
|
-
* const tags = collection.
|
|
271
|
+
* const tags = collection.tags;
|
|
228
272
|
* console.log(`Collection has these tags: ${tags.join(', ')}`);
|
|
229
273
|
*/
|
|
230
|
-
|
|
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.hasTag('temporary')) {
|
|
239
|
-
* console.log('Temporary items exist');
|
|
240
|
-
* }
|
|
241
|
-
*/
|
|
242
|
-
hasTag(tag: Tag): boolean;
|
|
274
|
+
get tags(): Tag[];
|
|
243
275
|
/**
|
|
244
276
|
* Updates the tag for all items with the specified tag.
|
|
245
277
|
*
|
|
246
|
-
* @param
|
|
247
|
-
* @param
|
|
278
|
+
* @param from - The tag to replace
|
|
279
|
+
* @param to - The new tag to assign
|
|
248
280
|
* @returns The number of items updated
|
|
249
281
|
*
|
|
250
282
|
* @example
|
|
251
283
|
* // Rename a tag
|
|
252
|
-
* const count = collection.
|
|
284
|
+
* const count = collection.update('temp', 'temporary');
|
|
253
285
|
* console.log(`Updated ${count} items`);
|
|
254
286
|
*/
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Removes all items with the specified tag from the collection.
|
|
258
|
-
*
|
|
259
|
-
* @param tag - The tag identifying which items to remove
|
|
260
|
-
* @returns The number of items removed
|
|
261
|
-
*
|
|
262
|
-
* @example
|
|
263
|
-
* // Remove all temporary markers
|
|
264
|
-
* const count = collection.removeByTag('temporary');
|
|
265
|
-
* console.log(`Removed ${count} items`);
|
|
266
|
-
*/
|
|
267
|
-
removeByTag(tag: Tag): number;
|
|
268
|
-
/**
|
|
269
|
-
* Removes all items with the array of tags from the collection.
|
|
270
|
-
*
|
|
271
|
-
* @param tag - The tags identifying which items to remove
|
|
272
|
-
* @returns The number of items removed
|
|
273
|
-
*
|
|
274
|
-
* @example
|
|
275
|
-
* // Remove all items containing tags
|
|
276
|
-
* const count = collection.removeByTag('temporary', 'default', 'tag');
|
|
277
|
-
* console.log(`Removed ${count} items`);
|
|
278
|
-
*/
|
|
279
|
-
removeByTag(tag: Tag[]): number;
|
|
287
|
+
update(from: Tag, to: Tag): number;
|
|
280
288
|
/**
|
|
281
289
|
* Makes all items with the specified tag visible.
|
|
282
290
|
* Only affects items that have a 'show' property.
|
|
283
291
|
*
|
|
284
|
-
* @param
|
|
285
|
-
* @returns The
|
|
292
|
+
* @param by - The tag identifying which items to show
|
|
293
|
+
* @returns The collection itself.
|
|
286
294
|
*
|
|
287
295
|
* @example
|
|
288
296
|
* // Show all buildings
|
|
289
297
|
* collection.show('buildings');
|
|
290
298
|
*/
|
|
291
|
-
show(
|
|
299
|
+
show(by: Tag): this;
|
|
292
300
|
/**
|
|
293
301
|
* Hides all items with the specified tag.
|
|
294
302
|
* Only affects items that have a 'show' property.
|
|
295
303
|
*
|
|
296
|
-
* @param
|
|
297
|
-
* @returns The
|
|
304
|
+
* @param by - The tag identifying which items to hide
|
|
305
|
+
* @returns The collection itself.
|
|
298
306
|
*
|
|
299
307
|
* @example
|
|
300
308
|
* // Hide all buildings
|
|
301
309
|
* collection.hide('buildings');
|
|
302
310
|
*/
|
|
303
|
-
hide(
|
|
311
|
+
hide(by: Tag): this;
|
|
304
312
|
/**
|
|
305
313
|
* Toggles visibility of all items with the specified tag.
|
|
306
314
|
* Only affects items that have a 'show' property.
|
|
307
315
|
*
|
|
308
|
-
* @param
|
|
309
|
-
* @returns The
|
|
316
|
+
* @param by - The tag identifying which items to toggle
|
|
317
|
+
* @returns The collection itself.
|
|
310
318
|
*
|
|
311
319
|
* @example
|
|
312
320
|
* // Toggle visibility of all buildings
|
|
313
321
|
* collection.toggle('buildings');
|
|
314
322
|
*/
|
|
315
|
-
toggle(
|
|
323
|
+
toggle(by: Tag): this;
|
|
316
324
|
/**
|
|
317
325
|
* Sets a property value on all items with the specified tag.
|
|
318
326
|
*
|
|
319
|
-
* @param
|
|
327
|
+
* @param by - The tag identifying which items to update
|
|
320
328
|
* @param property - The property name to set
|
|
321
329
|
* @param value - The value to set
|
|
322
330
|
* @returns The number of items updated
|
|
@@ -325,13 +333,13 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
325
333
|
* // Change color of all buildings to red
|
|
326
334
|
* collection.setProperty('buildings', 'color', Color.RED);
|
|
327
335
|
*/
|
|
328
|
-
setProperty<K extends
|
|
336
|
+
setProperty<K extends NonFunction<I>, V extends Exclude<I[K], Function>>(property: K, value: V, by?: Tag): this;
|
|
329
337
|
/**
|
|
330
338
|
* Filters items in the collection based on a predicate function.
|
|
331
339
|
* Optionally only filters items with a specific tag.
|
|
332
340
|
*
|
|
333
341
|
* @param predicate - Function that tests each item
|
|
334
|
-
* @param
|
|
342
|
+
* @param by - Optional tag to filter by before applying the predicate
|
|
335
343
|
* @returns Array of items that pass the test
|
|
336
344
|
*
|
|
337
345
|
* @example
|
|
@@ -341,13 +349,13 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
341
349
|
* 'buildings'
|
|
342
350
|
* );
|
|
343
351
|
*/
|
|
344
|
-
filter(predicate: (item: I) => boolean,
|
|
352
|
+
filter(predicate: (item: I) => boolean, by?: Tag): I[];
|
|
345
353
|
/**
|
|
346
354
|
* Executes a callback function for each item in the collection.
|
|
347
355
|
* Optionally filters items by tag before execution.
|
|
348
356
|
*
|
|
349
357
|
* @param callback - Function to execute for each item
|
|
350
|
-
* @param
|
|
358
|
+
* @param by - Optional tag to filter items (if not provided, processes all items)
|
|
351
359
|
*
|
|
352
360
|
* @example
|
|
353
361
|
* // Highlight all buildings
|
|
@@ -357,7 +365,45 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
357
365
|
* }
|
|
358
366
|
* }, 'buildings');
|
|
359
367
|
*/
|
|
360
|
-
forEach(callback: (
|
|
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;
|
|
361
407
|
}
|
|
362
408
|
|
|
363
|
-
export { type CesiumCollection, type CesiumCollectionItem, Collection, type CollectionEventType, type EventHandler, type
|
|
409
|
+
export { type CesiumCollection, type CesiumCollectionItem, Collection, type CollectionEventType, type EventHandler, type NonFunction, type Tag, type WithTag };
|
package/dist/collection/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{c as o}from"../chunk-MIDZHLUZ.js";import"../chunk-YZ7AUGIO.js";export{o as Collection};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var k=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var W=(n,e)=>{for(var r in e)k(n,r,{get:e[r],enumerable:!0})},$=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Y(e))!q.call(n,i)&&i!==r&&k(n,i,{get:()=>e[i],enumerable:!(t=H(e,i))||t.enumerable});return n};var j=n=>$(k({},"__esModule",{value:!0}),n);var U={};W(U,{Collection:()=>A,HybridTerrainProvider:()=>w,TerrainArea:()=>h,TerrainAreas:()=>T,TerrainBounds:()=>v,TerrainVisualizer:()=>b,cloneViewer:()=>N,syncCamera:()=>R});module.exports=j(U);var C=require("cesium"),M=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:r}){this.tag=r||"default",this.collection=e}_emit(e,r){let t=this._eventListeners.get(e);if(t){let i={type:e,...r};t.forEach(o=>o(i))}}_addToTagMap(e,r){this._tagMap.has(r)||this._tagMap.set(r,new Set),this._tagMap.get(r)?.add(e)}_removeFromTagMap(e){let r=e[n.symbol],t=this._tagMap.get(r);t&&(t.delete(e),t.size===0&&this._tagMap.delete(r))}_invalidateCache(){this._valuesCache=null}addEventListener(e,r){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(r),this}removeEventListener(e,r){return this._eventListeners.get(e)?.delete(r),this}add(e,r=this.tag,t){return Array.isArray(e)?e.forEach(i=>{this.add(i,r)}):(Object.defineProperty(e,n.symbol,{value:r,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,t),this._addToTagMap(e,r),this._invalidateCache(),this._emit("add",{items:[e],tag:r})),e}contains(e){return this.collection.contains(e)}remove(e){let r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this._valuesCache)return this._valuesCache;if(this.collection instanceof C.EntityCollection)this._valuesCache=this.collection.values||[];else{let e=[];for(let r=0;r<this.collection.length;r++)e.push(this.collection.get(r));this._valuesCache=e}return this._valuesCache}get length(){return this.values?.length||0}getByTag(e){let r=this._tagMap.get(e);return r?Array.from(r):[]}getFirstByTag(e){let r=this._tagMap.get(e);if(r&&r.size>0)return r.values().next().value}getTags(){return Array.from(this._tagMap.keys())}hasTag(e){let r=this._tagMap.get(e);return!!r&&r.size>0}updateTag(e,r){let t=this.getByTag(e);for(let i of t)this._removeFromTagMap(i),Object.defineProperty(i,n.symbol,{value:r,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(i,r);return t.length>0&&this._emit("update",{items:t,tag:r}),t.length}removeByTag(e){let r=0;return Array.isArray(e)?e.forEach(t=>{this.removeByTag(t)}):this.getByTag(e).forEach(t=>{this.remove(t)&&r++}),r}show(e){let r=this.getByTag(e),t=0;for(let i of r)(0,C.defined)(i.show)&&(i.show=!0,t++);return t}hide(e){let r=this.getByTag(e),t=0;for(let i of r)(0,C.defined)(i.show)&&(i.show=!1,t++);return t}toggle(e){let r=this.getByTag(e),t=0;for(let i of r)(0,C.defined)(i.show)&&(i.show=!i.show,t++);return t}setProperty(e,r,t){let i=this.getByTag(e),o=0;for(let a of i)r in a?(a[r]=t,o++):console.warn(`${r} does not exists in ${a}`);return o}filter(e,r){return(r?this.getByTag(r):this.values).filter(e)}forEach(e,r){(r?this.getByTag(r):this.values).forEach((i,o)=>e(i,o))}},A=M;var p=require("cesium");var V=require("cesium");var u=require("cesium"),v=class{_rectangle;_tilingScheme;_tileRanges;_levels;constructor(e,r){if(this._tilingScheme=r||new u.GeographicTilingScheme,this._rectangle=new u.Rectangle,this._tileRanges=new Map,this._levels=new Set,e.type==="rectangle"&&e.rectangle)this._rectangle=u.Rectangle.clone(e.rectangle);else if(e.type==="tileRange"&&e.tileRanges)e.tileRanges instanceof Map?this._tileRanges=new Map(e.tileRanges):this._tileRanges=new Map(Object.entries(e.tileRanges).map(([t,i])=>[parseInt(t),i])),this._calculateRectangleFromTileRanges();else throw new Error("Either rectangle or tileRanges must be provided.");this._levels=new Set(Array.from(this._tileRanges.keys()))}contains(e,r,t){if(this._tileRanges.has(t)){let o=this._tileRanges.get(t);return e>=o.start.x&&e<=o.end.x&&r>=o.start.y&&r<=o.end.y}let i=this._tilingScheme.tileXYToRectangle(e,r,t);return u.Rectangle.intersection(i,this._rectangle)!==void 0}configureAvailability(e){if(e.availability){e.availability._tilingScheme&&(e.availability._tilingScheme=this._tilingScheme);for(let[r,t]of this._tileRanges.entries())e.availability.addAvailableTileRange(r,t.start.x,t.start.y,t.end.x,t.end.y)}}get rectangle(){return this._rectangle}get tilingScheme(){return this._tilingScheme}get tileRanges(){return this._tileRanges}get levels(){return this._levels}_calculateRectangleFromTileRanges(){let e=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,t=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY,o=Array.from(this._tileRanges.keys());if(o.length===0){this._rectangle=u.Rectangle.MAX_VALUE;return}let a=Math.min(...o),s=this._tileRanges.get(a);if(s){let{start:c,end:d}=s,y=this._tilingScheme.tileXYToRectangle(c.x,c.y,a),m=this._tilingScheme.tileXYToRectangle(d.x,d.y,a);e=Math.min(y.west,e),r=Math.min(m.south,r),t=Math.max(m.east,t),i=Math.max(y.north,i)}this._rectangle=new u.Rectangle(e,r,t,i)}};(r=>{function n(t,i,o,a=new u.GeographicTilingScheme){let s=new Map;return s.set(o,{start:{x:t,y:i},end:{x:t,y:i}}),new r({type:"tileRange",tileRanges:s},a)}r.fromTile=n;function e(t,i=new u.GeographicTilingScheme){return new r({type:"rectangle",rectangle:u.Rectangle.clone(t)},i)}r.fromRectangle=e})(v||={});var h=class n{_provider;_bounds;_levels;_ready=!1;_credit;_isCustom;constructor(e,r){this._bounds=e.bounds instanceof v?e.bounds:new v(e.bounds),this._levels=new Set(e.levels||[]),this._credit=e.credit||"custom",this._isCustom=e.isCustom!==void 0?e.isCustom:!0,this._provider=r,this._ready=!0,this._bounds.configureAvailability(this._provider)}static async create(e){let r;return typeof e.provider=="string"?r=await V.CesiumTerrainProvider.fromUrl(e.provider,{requestVertexNormals:!0,credit:e.credit||"custom"}):r=e.provider,new n(e,r)}contains(e,r,t){return this._levels.size>0&&!this._levels.has(t)?!1:this._bounds.contains(e,r,t)}requestTileGeometry(e,r,t,i){if(!(!this._ready||!this.contains(e,r,t)||!this._provider?.getTileDataAvailable(e,r,t)))return this._provider.requestTileGeometry(e,r,t,i)}getTileDataAvailable(e,r,t){return!this.contains(e,r,t)||!this._ready?!1:this._provider?.getTileDataAvailable(e,r,t)??!1}get isCustom(){return this._isCustom}get credit(){return this._credit}get provider(){return this._provider}get bounds(){return this._bounds}get levels(){return this._levels}get ready(){return this._ready}};(e=>{async function n(r,t,i,o="custom"){let a=new v({type:"tileRange",tileRanges:t});return await e.create({provider:r,bounds:a,levels:i||Object.keys(t).map(c=>parseInt(c)),credit:o})}e.fromUrl=n})(h||={});var T=class extends Array{async add(e){let r;return e instanceof h?r=e:r=await h.create(e),this.push(r)}remove(e){let r=this.indexOf(e);return r>=0?(this.splice(r,1),!0):!1}clear(){this.length=0}};var w=class n{_terrainAreas=new T;_terrainProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(e,r,t){this._terrainProvider=e,this._fallbackProvider=r,this._tilingScheme=e.tilingScheme||new p.GeographicTilingScheme,this._terrainAreas=new T(...t),this._availability=e.availability,this._ready=!0}static async create(e){try{let r;typeof e.terrainProvider=="string"?r=await p.CesiumTerrainProvider.fromUrl(e.terrainProvider,{requestVertexNormals:!0}):r=e.terrainProvider;let t;e.fallbackProvider?typeof e.fallbackProvider=="string"?t=await p.CesiumTerrainProvider.fromUrl(e.fallbackProvider,{requestVertexNormals:!0}):t=e.fallbackProvider:t=new p.EllipsoidTerrainProvider;let i=[];for(let o of e.terrainAreas){let a=await h.create(o);i.push(a)}return new n(r,t,i)}catch(r){throw console.error("Failed to initialize HybridTerrainProvider:",r),r}}get ready(){return this._ready}get tilingScheme(){return this._tilingScheme}get availability(){return this._availability}get terrainAreas(){return[...this._terrainAreas]}get defaultProvider(){return this._terrainProvider}get fallbackProvider(){return this._fallbackProvider}get credit(){return this._terrainProvider?.credit}get errorEvent(){return this._terrainProvider.errorEvent}get hasWaterMask(){return this._terrainProvider.hasWaterMask}get hasVertexNormals(){return this._terrainProvider.hasVertexNormals}loadTileDataAvailability(e,r,t){return this._terrainProvider.loadTileDataAvailability(e,r,t)}getLevelMaximumGeometricError(e){return this._terrainProvider.getLevelMaximumGeometricError(e)}requestTileGeometry(e,r,t,i){if(this._ready){for(let o of this._terrainAreas)if(o.contains(e,r,t))return o.requestTileGeometry(e,r,t,i);return this._terrainProvider.getTileDataAvailable(e,r,t)?this._terrainProvider.requestTileGeometry(e,r,t,i):this._fallbackProvider.requestTileGeometry(e,r,t,i)}}getTileDataAvailable(e,r,t){return this._terrainAreas.forEach(i=>{if(i.contains(e,r,t)&&i.getTileDataAvailable(e,r,t))return!0}),this._terrainProvider.getTileDataAvailable(e,r,t)||!0}};(e=>{async function n(r,t,i,o){return e.create({terrainAreas:[{provider:r,bounds:{type:"tileRange",tileRanges:i},levels:o||Object.keys(i).map(a=>parseInt(a)),credit:"custom"}],terrainProvider:t,fallbackProvider:new p.EllipsoidTerrainProvider})}e.createOverlay=n})(w||={});var l=require("cesium");var b=class n{_viewer;_collection;_hybridTerrain;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",l.Color.RED],["default",l.Color.BLUE],["fallback",l.Color.GRAY],["grid",l.Color.YELLOW]]);constructor(e,r){this._viewer=e,this._collection=new A({collection:e.entities,tag:n.tag.default}),r&&(r.colors&&Object.entries(r.colors).forEach(([t,i])=>{this._colors.set(t,i)}),r.tile!==void 0&&(this._visible=r.tile),r.activeLevel!==void 0&&(this._level=r.activeLevel),r.terrainProvider&&this.setTerrainProvider(r.terrainProvider))}setTerrainProvider(e){this._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 r=this._hybridTerrain.tilingScheme;this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new l.TileCoordinatesImageryProvider({tilingScheme:r,color:l.Color.YELLOW})));let t=(a,s,c)=>{if(this._hybridTerrain){for(let d of this._hybridTerrain.terrainAreas)if(d.contains(a,s,c))return d.isCustom?this._colors.get("custom")||l.Color.RED:this._colors.get("default")||l.Color.BLUE;if(this._hybridTerrain.getTileDataAvailable(a,s,c))return this._colors.get("default")||l.Color.BLUE}return this._colors.get("fallback")||l.Color.TRANSPARENT},i=this._getVisibleRectangle();if(!i)return;function o(a){return a&&Number.isFinite(a.west)&&Number.isFinite(a.south)&&Number.isFinite(a.east)&&Number.isFinite(a.north)&&a.west<=a.east&&a.south<=a.north}if(!o(i)){console.warn("Invalid visible rectangle detected, skipping grid display");return}try{let a=r.positionToTileXY(l.Rectangle.northwest(i),e),s=r.positionToTileXY(l.Rectangle.southeast(i),e);if(!a||!s)return;let c=100,d=Math.min(s.x-a.x+1,c),y=Math.min(s.y-a.y+1,c);for(let m=a.x;m<=a.x+d-1;m++)for(let f=a.y;f<=a.y+y-1;f++)try{let g=r.tileXYToRectangle(m,f,e);if(!o(g)){console.warn(`Invalid rectangle for tile (${m}, ${f}, ${e}), skipping`);continue}let P=t(m,f,e),_=n.createRectangle(g,P.withAlpha(.3));_.properties?.addProperty("tileX",m),_.properties?.addProperty("tileY",f),_.properties?.addProperty("tileLevel",e),this._collection.add(_,n.tag.grid)}catch(g){console.warn(`Error creating tile (${m}, ${f}, ${e}): ${g.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(a){console.error("Error displaying tile grid:",a)}}hide(){this._collection.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(([r,t])=>{this._colors.set(r,t)}),this.update()}flyTo(e,r){let{rectangle:t}=e.bounds;this._viewer.camera.flyTo({destination:t,...r,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}};(t=>{t.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(i,o){return new l.Entity({rectangle:{coordinates:i,material:o,heightReference:l.HeightReference.CLAMP_TO_GROUND}})}t.createRectangle=e;function r(i,o,a){let s=a?.tag||"terrain_area_visualization",c=a?.color||l.Color.RED,d=a?.maxTilesToShow||100,y=a?.show??!0,m=a?.alpha||.7,f=a?.tileAlpha||.2,g="provider"in i?i.bounds:i,P=new A({collection:o.entities,tag:s}),{rectangle:_}=g;if(P.add(t.createRectangle(_,c.withAlpha(m)),s),y&&g.levels.size>0){let{tilingScheme:D}=g;g.levels.forEach(B=>{let I=0,{tileRanges:z}=g;for(let[G,E]of z.entries())if(G===B)for(let x=E.start.x;x<=E.end.x&&I<d;x++)for(let S=E.start.y;S<=E.end.y&&I<d;S++){let F=D.tileXYToRectangle(x,S,B);P.add(e(F,c.withAlpha(f)),`${s}_tile`),I++}})}return P}t.visualize=r})(b||={});var L=require("cesium");function R(n,e){if((0,L.defined)(n)&&(0,L.defined)(e)){let{camera:r}=n;e.camera.position=r.positionWC.clone(),e.camera.direction=r.directionWC.clone(),e.camera.up=r.upWC.clone()}}var O=require("cesium");function N(n,e,r){let t={baseLayerPicker:n.baseLayerPicker!==void 0,geocoder:n.geocoder!==void 0,homeButton:n.homeButton!==void 0,sceneModePicker:n.sceneModePicker!==void 0,timeline:n.timeline!==void 0,navigationHelpButton:n.navigationHelpButton!==void 0,animation:n.animation!==void 0,fullscreenButton:n.fullscreenButton!==void 0,shouldAnimate:n.clock.shouldAnimate,terrainProvider:n.terrainProvider,requestRenderMode:n.scene.requestRenderMode,infoBox:n.infoBox!==void 0},i=new O.Viewer(e,{...t,...r});R(n,i);let o=n.imageryLayers;i.imageryLayers.removeAll();for(let c=0;c<o.length;c++){let d=o.get(c);i.imageryLayers.addImageryProvider(d.imageryProvider,c)}i.clock.startTime=n.clock.startTime.clone(),i.clock.stopTime=n.clock.stopTime.clone(),i.clock.currentTime=n.clock.currentTime.clone(),i.clock.multiplier=n.clock.multiplier,i.clock.clockStep=n.clock.clockStep,i.clock.clockRange=n.clock.clockRange,i.clock.shouldAnimate=n.clock.shouldAnimate,i.scene.globe.enableLighting=n.scene.globe.enableLighting,i.scene.globe.depthTestAgainstTerrain=n.scene.globe.depthTestAgainstTerrain,i.scene.screenSpaceCameraController.enableCollisionDetection=n.scene.screenSpaceCameraController.enableCollisionDetection;let a=n.scene.screenSpaceCameraController.tiltEventTypes;a&&(i.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(a)?[...a]:a);let s=n.scene.screenSpaceCameraController.zoomEventTypes;return s&&(i.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(s)?[...s]:s),i}
|
|
1
|
+
"use strict";var M=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var W=(n,e)=>{for(var t in e)M(n,t,{get:e[t],enumerable:!0})},$=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Y(e))!q.call(n,i)&&i!==t&&M(n,i,{get:()=>e[i],enumerable:!(r=H(e,i))||r.enumerable});return n};var U=n=>$(M({},"__esModule",{value:!0}),n);var X={};W(X,{Collection:()=>R,HybridTerrainProvider:()=>P,TerrainArea:()=>h,TerrainAreas:()=>T,TerrainBounds:()=>v,TerrainVisualizer:()=>p,cloneViewer:()=>D,isGetterOnly:()=>I,syncCamera:()=>w});module.exports=U(X);var C=require("cesium");var l=require("cesium");var p=class n{_viewer;_collection;_hybridTerrain;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",l.Color.RED],["default",l.Color.BLUE],["fallback",l.Color.GRAY],["grid",l.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new R({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([r,i])=>{this._colors.set(r,i)}),t.tile!==void 0&&(this._visible=t.tile),t.activeLevel!==void 0&&(this._level=t.activeLevel),t.terrainProvider&&this.setTerrainProvider(t.terrainProvider))}setTerrainProvider(e){this._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 l.TileCoordinatesImageryProvider({tilingScheme:t,color:l.Color.YELLOW})));let r=(a,s,c)=>{if(this._hybridTerrain){for(let d of this._hybridTerrain.terrainAreas)if(d.contains(a,s,c))return d.isCustom?this._colors.get("custom")||l.Color.RED:this._colors.get("default")||l.Color.BLUE;if(this._hybridTerrain.getTileDataAvailable(a,s,c))return this._colors.get("default")||l.Color.BLUE}return this._colors.get("fallback")||l.Color.TRANSPARENT},i=this._getVisibleRectangle();if(!i)return;function o(a){return a&&Number.isFinite(a.west)&&Number.isFinite(a.south)&&Number.isFinite(a.east)&&Number.isFinite(a.north)&&a.west<=a.east&&a.south<=a.north}if(!o(i)){console.warn("Invalid visible rectangle detected, skipping grid display");return}try{let a=t.positionToTileXY(l.Rectangle.northwest(i),e),s=t.positionToTileXY(l.Rectangle.southeast(i),e);if(!a||!s)return;let c=100,d=Math.min(s.x-a.x+1,c),y=Math.min(s.y-a.y+1,c);for(let m=a.x;m<=a.x+d-1;m++)for(let f=a.y;f<=a.y+y-1;f++)try{let g=t.tileXYToRectangle(m,f,e);if(!o(g)){console.warn(`Invalid rectangle for tile (${m}, ${f}, ${e}), skipping`);continue}let A=r(m,f,e),_=n.createRectangle(g,A.withAlpha(.3));_.properties?.addProperty("tileX",m),_.properties?.addProperty("tileY",f),_.properties?.addProperty("tileLevel",e),this._collection.add(_,n.tag.grid)}catch(g){console.warn(`Error creating tile (${m}, ${f}, ${e}): ${g.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(a){console.error("Error displaying tile grid:",a)}}hide(){this._collection.remove(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,r])=>{this._colors.set(t,r)}),this.update()}flyTo(e,t){let{rectangle:r}=e.bounds;this._viewer.camera.flyTo({destination:r,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}};(r=>{r.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(i,o){return new l.Entity({rectangle:{coordinates:i,material:o,heightReference:l.HeightReference.CLAMP_TO_GROUND}})}r.createRectangle=e;function t(i,o,a){let s=a?.tag||"terrain_area_visualization",c=a?.color||l.Color.RED,d=a?.maxTilesToShow||100,y=a?.show??!0,m=a?.alpha||.7,f=a?.tileAlpha||.2,g="provider"in i?i.bounds:i,A=new R({collection:o.entities,tag:s}),{rectangle:_}=g;if(A.add(r.createRectangle(_,c.withAlpha(m)),s),y&&g.levels.size>0){let{tilingScheme:G}=g;g.levels.forEach(V=>{let x=0,{tileRanges:j}=g;for(let[z,E]of j.entries())if(z===V)for(let S=E.start.x;S<=E.end.x&&x<d;S++)for(let k=E.start.y;k<=E.end.y&&x<d;k++){let F=G.tileXYToRectangle(S,k,V);A.add(e(F,c.withAlpha(f)),`${s}_tile`),x++}})}return A}r.visualize=t})(p||={});function I(n,e){let t=!1,r=Object.getOwnPropertyDescriptor(n,e);if(!r){let i=Object.getPrototypeOf(n);for(;i&&!r;)r=Object.getOwnPropertyDescriptor(i,e),i=Object.getPrototypeOf(i)}return r&&r.get&&!r.set&&(t=!0),t}var O=require("cesium");function w(n,e){if((0,O.defined)(n)&&(0,O.defined)(e)){let{camera:t}=n;e.camera.position=t.positionWC.clone(),e.camera.direction=t.directionWC.clone(),e.camera.up=t.upWC.clone()}}var L=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let r=this._eventListeners.get(e);if(r){let i={type:e,...t};r.forEach(o=>o(i))}}_addToTagMap(e,t){this._tagMap.has(t)||this._tagMap.set(t,new Set),this._tagMap.get(t)?.add(e)}_removeFromTagMap(e){let t=e[n.symbol],r=this._tagMap.get(t);r&&(r.delete(e),r.size===0&&this._tagMap.delete(t))}_invalidateCache(){this._valuesCache=null}addEventListener(e,t){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(t),this}removeEventListener(e,t){return this._eventListeners.get(e)?.delete(t),this}add(e,t=this.tag,r){return Array.isArray(e)?e.forEach(i=>{this.add(i,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,r),this._addToTagMap(e,t),this._invalidateCache(),this._emit("add",{items:[e],tag:t})),e}contains(e){if(typeof e=="object")return this.collection.contains(e);let t=this._tagMap.get(e);return!!t&&t.size>0}remove(e){if(typeof e=="object"&&!Array.isArray(e)){let i=this.collection.remove(e);return i&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),i}if(Array.isArray(e)){if(e.length===0)return!1;let i=!1;for(let o of e)this.remove(o)&&(i=!0);return i}let t=this.get(e);if(t.length===0)return!1;let r=!1;for(let i of t)this.remove(i)&&(r=!0);return r}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof C.EntityCollection)return this.collection.values;{let e=[];for(let t=0;t<this.collection.length;t++)e.push(this.collection.get(t));return e}}get length(){return this.values?.length||0}get(e){let t=this._tagMap.get(e);return t?Array.from(t):[]}first(e){let t=this._tagMap.get(e);if(t&&t.size>0)return t.values().next().value}get tags(){return Array.from(this._tagMap.keys())}update(e,t){let r=this.get(e);for(let i of r)this._removeFromTagMap(i),Object.defineProperty(i,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(i,t);return r.length>0&&this._emit("update",{items:r,tag:t}),r.length}show(e){let t=this.get(e);for(let r of t)(0,C.defined)(r.show)&&(r.show=!0);return this}hide(e){let t=this.get(e);for(let r of t)(0,C.defined)(r.show)&&(r.show=!1);return this}toggle(e){let t=this.get(e);for(let r of t)(0,C.defined)(r.show)&&(r.show=!r.show);return this}setProperty(e,t,r=this.tag){let i=this.get(r);for(let o of i)if(e in o&&typeof o[e]!="function"){if(I(o,e))throw Error(`setProperty(${o}, ${e}) failed; The property is readonly.`);o[e]=t}return this}filter(e,t){return(t?this.get(t):this.values).filter(e)}forEach(e,t){(t?this.get(t):this.values).forEach((i,o)=>e(i,o))}map(e,t){return(t?this.get(t):this.values).map(e)}find(e,t){return(t?this.get(t):this.values).find(e)}},R=L;var b=require("cesium");var N=require("cesium");var u=require("cesium"),v=class{_rectangle;_tilingScheme;_tileRanges;_levels;constructor(e,t){if(this._tilingScheme=t||new u.GeographicTilingScheme,this._rectangle=new u.Rectangle,this._tileRanges=new Map,this._levels=new Set,e.type==="rectangle"&&e.rectangle)this._rectangle=u.Rectangle.clone(e.rectangle);else if(e.type==="tileRange"&&e.tileRanges)e.tileRanges instanceof Map?this._tileRanges=new Map(e.tileRanges):this._tileRanges=new Map(Object.entries(e.tileRanges).map(([r,i])=>[parseInt(r),i])),this._calculateRectangleFromTileRanges();else throw new Error("Either rectangle or tileRanges must be provided.");this._levels=new Set(Array.from(this._tileRanges.keys()))}contains(e,t,r){if(this._tileRanges.has(r)){let o=this._tileRanges.get(r);return e>=o.start.x&&e<=o.end.x&&t>=o.start.y&&t<=o.end.y}let i=this._tilingScheme.tileXYToRectangle(e,t,r);return u.Rectangle.intersection(i,this._rectangle)!==void 0}configureAvailability(e){if(e.availability){e.availability._tilingScheme&&(e.availability._tilingScheme=this._tilingScheme);for(let[t,r]of this._tileRanges.entries())e.availability.addAvailableTileRange(t,r.start.x,r.start.y,r.end.x,r.end.y)}}get rectangle(){return this._rectangle}get tilingScheme(){return this._tilingScheme}get tileRanges(){return this._tileRanges}get levels(){return this._levels}_calculateRectangleFromTileRanges(){let e=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY,o=Array.from(this._tileRanges.keys());if(o.length===0){this._rectangle=u.Rectangle.MAX_VALUE;return}let a=Math.min(...o),s=this._tileRanges.get(a);if(s){let{start:c,end:d}=s,y=this._tilingScheme.tileXYToRectangle(c.x,c.y,a),m=this._tilingScheme.tileXYToRectangle(d.x,d.y,a);e=Math.min(y.west,e),t=Math.min(m.south,t),r=Math.max(m.east,r),i=Math.max(y.north,i)}this._rectangle=new u.Rectangle(e,t,r,i)}};(t=>{function n(r,i,o,a=new u.GeographicTilingScheme){let s=new Map;return s.set(o,{start:{x:r,y:i},end:{x:r,y:i}}),new t({type:"tileRange",tileRanges:s},a)}t.fromTile=n;function e(r,i=new u.GeographicTilingScheme){return new t({type:"rectangle",rectangle:u.Rectangle.clone(r)},i)}t.fromRectangle=e})(v||={});var h=class n{_provider;_bounds;_levels;_ready=!1;_credit;_isCustom;constructor(e,t){this._bounds=e.bounds instanceof v?e.bounds:new v(e.bounds),this._levels=new Set(e.levels||[]),this._credit=e.credit||"custom",this._isCustom=e.isCustom!==void 0?e.isCustom:!0,this._provider=t,this._ready=!0,this._bounds.configureAvailability(this._provider)}static async create(e){let t;return typeof e.provider=="string"?t=await N.CesiumTerrainProvider.fromUrl(e.provider,{requestVertexNormals:!0,credit:e.credit||"custom"}):t=e.provider,new n(e,t)}contains(e,t,r){return this._levels.size>0&&!this._levels.has(r)?!1:this._bounds.contains(e,t,r)}requestTileGeometry(e,t,r,i){if(!(!this._ready||!this.contains(e,t,r)||!this._provider?.getTileDataAvailable(e,t,r)))return this._provider.requestTileGeometry(e,t,r,i)}getTileDataAvailable(e,t,r){return!this.contains(e,t,r)||!this._ready?!1:this._provider?.getTileDataAvailable(e,t,r)??!1}get isCustom(){return this._isCustom}get credit(){return this._credit}get provider(){return this._provider}get bounds(){return this._bounds}get levels(){return this._levels}get ready(){return this._ready}};(e=>{async function n(t,r,i,o="custom"){let a=new v({type:"tileRange",tileRanges:r});return await e.create({provider:t,bounds:a,levels:i||Object.keys(r).map(c=>parseInt(c)),credit:o})}e.fromUrl=n})(h||={});var T=class extends Array{async add(e){let t;return e instanceof h?t=e:t=await h.create(e),this.push(t)}remove(e){let t=this.indexOf(e);return t>=0?(this.splice(t,1),!0):!1}clear(){this.length=0}};var P=class n{_terrainAreas=new T;_terrainProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(e,t,r){this._terrainProvider=e,this._fallbackProvider=t,this._tilingScheme=e.tilingScheme||new b.GeographicTilingScheme,this._terrainAreas=new T(...r),this._availability=e.availability,this._ready=!0}static async create(e){try{let t;typeof e.terrainProvider=="string"?t=await b.CesiumTerrainProvider.fromUrl(e.terrainProvider,{requestVertexNormals:!0}):t=e.terrainProvider;let r;e.fallbackProvider?typeof e.fallbackProvider=="string"?r=await b.CesiumTerrainProvider.fromUrl(e.fallbackProvider,{requestVertexNormals:!0}):r=e.fallbackProvider:r=new b.EllipsoidTerrainProvider;let i=[];for(let o of e.terrainAreas){let a=await h.create(o);i.push(a)}return new n(t,r,i)}catch(t){throw console.error("Failed to initialize HybridTerrainProvider:",t),t}}get ready(){return this._ready}get tilingScheme(){return this._tilingScheme}get availability(){return this._availability}get terrainAreas(){return[...this._terrainAreas]}get defaultProvider(){return this._terrainProvider}get fallbackProvider(){return this._fallbackProvider}get credit(){return this._terrainProvider?.credit}get errorEvent(){return this._terrainProvider.errorEvent}get hasWaterMask(){return this._terrainProvider.hasWaterMask}get hasVertexNormals(){return this._terrainProvider.hasVertexNormals}loadTileDataAvailability(e,t,r){return this._terrainProvider.loadTileDataAvailability(e,t,r)}getLevelMaximumGeometricError(e){return this._terrainProvider.getLevelMaximumGeometricError(e)}requestTileGeometry(e,t,r,i){if(this._ready){for(let o of this._terrainAreas)if(o.contains(e,t,r))return o.requestTileGeometry(e,t,r,i);return this._terrainProvider.getTileDataAvailable(e,t,r)?this._terrainProvider.requestTileGeometry(e,t,r,i):this._fallbackProvider.requestTileGeometry(e,t,r,i)}}getTileDataAvailable(e,t,r){return this._terrainAreas.forEach(i=>{if(i.contains(e,t,r)&&i.getTileDataAvailable(e,t,r))return!0}),this._terrainProvider.getTileDataAvailable(e,t,r)||!0}};(e=>{async function n(t,r,i,o){return e.create({terrainAreas:[{provider:t,bounds:{type:"tileRange",tileRanges:i},levels:o||Object.keys(i).map(a=>parseInt(a)),credit:"custom"}],terrainProvider:r,fallbackProvider:new b.EllipsoidTerrainProvider})}e.createOverlay=n})(P||={});var B=require("cesium");function D(n,e,t){let r={baseLayerPicker:n.baseLayerPicker!==void 0,geocoder:n.geocoder!==void 0,homeButton:n.homeButton!==void 0,sceneModePicker:n.sceneModePicker!==void 0,timeline:n.timeline!==void 0,navigationHelpButton:n.navigationHelpButton!==void 0,animation:n.animation!==void 0,fullscreenButton:n.fullscreenButton!==void 0,shouldAnimate:n.clock.shouldAnimate,terrainProvider:n.terrainProvider,requestRenderMode:n.scene.requestRenderMode,infoBox:n.infoBox!==void 0},i=new B.Viewer(e,{...r,...t});w(n,i);let o=n.imageryLayers;i.imageryLayers.removeAll();for(let c=0;c<o.length;c++){let d=o.get(c);i.imageryLayers.addImageryProvider(d.imageryProvider,c)}i.clock.startTime=n.clock.startTime.clone(),i.clock.stopTime=n.clock.stopTime.clone(),i.clock.currentTime=n.clock.currentTime.clone(),i.clock.multiplier=n.clock.multiplier,i.clock.clockStep=n.clock.clockStep,i.clock.clockRange=n.clock.clockRange,i.clock.shouldAnimate=n.clock.shouldAnimate,i.scene.globe.enableLighting=n.scene.globe.enableLighting,i.scene.globe.depthTestAgainstTerrain=n.scene.globe.depthTestAgainstTerrain,i.scene.screenSpaceCameraController.enableCollisionDetection=n.scene.screenSpaceCameraController.enableCollisionDetection;let a=n.scene.screenSpaceCameraController.tiltEventTypes;a&&(i.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(a)?[...a]:a);let s=n.scene.screenSpaceCameraController.zoomEventTypes;return s&&(i.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(s)?[...s]:s),i}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { CesiumCollection, CesiumCollectionItem, Collection, CollectionEventType, EventHandler,
|
|
1
|
+
export { CesiumCollection, CesiumCollectionItem, Collection, CollectionEventType, EventHandler, NonFunction, Tag, WithTag } from './collection/index.cjs';
|
|
2
2
|
export { H as HybridTerrainProvider, T as TerrainArea, a as TerrainBounds, b as TileRange, c as TileRanges } from './hybrid-terrain-provider-C6aXdtyo.cjs';
|
|
3
3
|
export { TerrainAreas } from './terrain/index.cjs';
|
|
4
|
-
export { TerrainVisualizer, syncCamera } from './utils/index.cjs';
|
|
4
|
+
export { TerrainVisualizer, isGetterOnly, syncCamera } from './utils/index.cjs';
|
|
5
5
|
export { cloneViewer } from './viewer/index.cjs';
|
|
6
6
|
import 'cesium';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { CesiumCollection, CesiumCollectionItem, Collection, CollectionEventType, EventHandler,
|
|
1
|
+
export { CesiumCollection, CesiumCollectionItem, Collection, CollectionEventType, EventHandler, NonFunction, Tag, WithTag } from './collection/index.js';
|
|
2
2
|
export { H as HybridTerrainProvider, T as TerrainArea, a as TerrainBounds, b as TileRange, c as TileRanges } from './hybrid-terrain-provider-C6aXdtyo.js';
|
|
3
3
|
export { TerrainAreas } from './terrain/index.js';
|
|
4
|
-
export { TerrainVisualizer, syncCamera } from './utils/index.js';
|
|
4
|
+
export { TerrainVisualizer, isGetterOnly, syncCamera } from './utils/index.js';
|
|
5
5
|
export { cloneViewer } from './viewer/index.js';
|
|
6
6
|
import 'cesium';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as t,b as m,c as p,d as n}from"./chunk-C52KJ2WP.js";import{a as r,b as o,c as i}from"./chunk-MIDZHLUZ.js";import{a}from"./chunk-STARYORM.js";import{a as e}from"./chunk-YZ7AUGIO.js";export{i as Collection,n as HybridTerrainProvider,m as TerrainArea,p as TerrainAreas,t as TerrainBounds,r as TerrainVisualizer,a as cloneViewer,o as isGetterOnly,e as syncCamera};
|
package/dist/utils/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var I=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var F=(n,e)=>{for(var t in e)I(n,t,{get:e[t],enumerable:!0})},$=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of j(e))!z.call(n,r)&&r!==t&&I(n,r,{get:()=>e[r],enumerable:!(i=S(e,r))||i.enumerable});return n};var H=n=>$(I({},"__esModule",{value:!0}),n);var N={};F(N,{TerrainVisualizer:()=>v,isGetterOnly:()=>b,syncCamera:()=>A});module.exports=H(N);var s=require("cesium");var f=require("cesium");var E=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(b(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)}},x=E;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 x({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,u)=>{if(this._hybridTerrain){for(let m of this._hybridTerrain.terrainAreas)if(m.contains(o,l,u))return m.isCustom?this._colors.get("custom")||s.Color.RED:this._colors.get("default")||s.Color.BLUE;if(this._hybridTerrain.getTileDataAvailable(o,l,u))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 u=100,m=Math.min(l.x-o.x+1,u),T=Math.min(l.y-o.y+1,u);for(let h=o.x;h<=o.x+m-1;h++)for(let d=o.y;d<=o.y+T-1;d++)try{let c=t.tileXYToRectangle(h,d,e);if(!a(c)){console.warn(`Invalid rectangle for tile (${h}, ${d}, ${e}), skipping`);continue}let p=i(h,d,e),g=n.createRectangle(c,p.withAlpha(.3));g.properties?.addProperty("tileX",h),g.properties?.addProperty("tileY",d),g.properties?.addProperty("tileLevel",e),this._collection.add(g,n.tag.grid)}catch(c){console.warn(`Error creating tile (${h}, ${d}, ${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.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.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,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",u=o?.color||s.Color.RED,m=o?.maxTilesToShow||100,T=o?.show??!0,h=o?.alpha||.7,d=o?.tileAlpha||.2,c="provider"in r?r.bounds:r,p=new x({collection:a.entities,tag:l}),{rectangle:g}=c;if(p.add(i.createRectangle(g,u.withAlpha(h)),l),T&&c.levels.size>0){let{tilingScheme:M}=c;c.levels.forEach(R=>{let _=0,{tileRanges:O}=c;for(let[P,y]of O.entries())if(P===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 V=M.tileXYToRectangle(C,w,R);p.add(e(V,u.withAlpha(d)),`${l}_tile`),_++}})}return p}i.visualize=t})(v||={});function b(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}var L=require("cesium");function A(n,e){if((0,L.defined)(n)&&(0,L.defined)(e)){let{camera:t}=n;e.camera.position=t.positionWC.clone(),e.camera.direction=t.directionWC.clone(),e.camera.up=t.upWC.clone()}}
|
package/dist/utils/index.d.cts
CHANGED
|
@@ -123,6 +123,15 @@ declare namespace TerrainVisualizer {
|
|
|
123
123
|
function visualize(terrain: TerrainArea | TerrainBounds, viewer: Viewer, options?: Options): Collection<EntityCollection, Entity>;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Examine the property descriptors at runtime
|
|
128
|
+
* to detect properties that only have getters.
|
|
129
|
+
* (read-only accessor properties)
|
|
130
|
+
* @param o The object to examine.
|
|
131
|
+
* @param k The key value of the property.
|
|
132
|
+
*/
|
|
133
|
+
declare function isGetterOnly(o: object, k: string | number | symbol): boolean;
|
|
134
|
+
|
|
126
135
|
/**
|
|
127
136
|
* Copies camera state from source viewer to destination viewer.
|
|
128
137
|
* @param source The source viewer to copy camera states from.
|
|
@@ -130,4 +139,4 @@ declare namespace TerrainVisualizer {
|
|
|
130
139
|
*/
|
|
131
140
|
declare function syncCamera(source: Viewer, dest: Viewer): void;
|
|
132
141
|
|
|
133
|
-
export { TerrainVisualizer, syncCamera };
|
|
142
|
+
export { TerrainVisualizer, isGetterOnly, syncCamera };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -123,6 +123,15 @@ declare namespace TerrainVisualizer {
|
|
|
123
123
|
function visualize(terrain: TerrainArea | TerrainBounds, viewer: Viewer, options?: Options): Collection<EntityCollection, Entity>;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Examine the property descriptors at runtime
|
|
128
|
+
* to detect properties that only have getters.
|
|
129
|
+
* (read-only accessor properties)
|
|
130
|
+
* @param o The object to examine.
|
|
131
|
+
* @param k The key value of the property.
|
|
132
|
+
*/
|
|
133
|
+
declare function isGetterOnly(o: object, k: string | number | symbol): boolean;
|
|
134
|
+
|
|
126
135
|
/**
|
|
127
136
|
* Copies camera state from source viewer to destination viewer.
|
|
128
137
|
* @param source The source viewer to copy camera states from.
|
|
@@ -130,4 +139,4 @@ declare namespace TerrainVisualizer {
|
|
|
130
139
|
*/
|
|
131
140
|
declare function syncCamera(source: Viewer, dest: Viewer): void;
|
|
132
141
|
|
|
133
|
-
export { TerrainVisualizer, syncCamera };
|
|
142
|
+
export { TerrainVisualizer, isGetterOnly, syncCamera };
|
package/dist/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a
|
|
1
|
+
import{a,b}from"../chunk-MIDZHLUZ.js";import{a as c}from"../chunk-YZ7AUGIO.js";export{a as TerrainVisualizer,b as isGetterOnly,c as syncCamera};
|
package/package.json
CHANGED
package/dist/chunk-CNYZN4AC.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{defined as r,EntityCollection as g}from"cesium";var l=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:t,tag:e}){this.tag=e||"default",this.collection=t}_emit(t,e){let a=this._eventListeners.get(t);if(a){let i={type:t,...e};a.forEach(s=>s(i))}}_addToTagMap(t,e){this._tagMap.has(e)||this._tagMap.set(e,new Set),this._tagMap.get(e)?.add(t)}_removeFromTagMap(t){let e=t[n.symbol],a=this._tagMap.get(e);a&&(a.delete(t),a.size===0&&this._tagMap.delete(e))}_invalidateCache(){this._valuesCache=null}addEventListener(t,e){return this._eventListeners.has(t)||this._eventListeners.set(t,new Set),this._eventListeners.get(t)?.add(e),this}removeEventListener(t,e){return this._eventListeners.get(t)?.delete(e),this}add(t,e=this.tag,a){return Array.isArray(t)?t.forEach(i=>{this.add(i,e)}):(Object.defineProperty(t,n.symbol,{value:e,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(t,a),this._addToTagMap(t,e),this._invalidateCache(),this._emit("add",{items:[t],tag:e})),t}contains(t){return this.collection.contains(t)}remove(t){let e=this.collection.remove(t);return e&&(this._removeFromTagMap(t),this._invalidateCache(),this._emit("remove",{items:[t]})),e}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this._valuesCache)return this._valuesCache;if(this.collection instanceof g)this._valuesCache=this.collection.values||[];else{let t=[];for(let e=0;e<this.collection.length;e++)t.push(this.collection.get(e));this._valuesCache=t}return this._valuesCache}get length(){return this.values?.length||0}getByTag(t){let e=this._tagMap.get(t);return e?Array.from(e):[]}getFirstByTag(t){let e=this._tagMap.get(t);if(e&&e.size>0)return e.values().next().value}getTags(){return Array.from(this._tagMap.keys())}hasTag(t){let e=this._tagMap.get(t);return!!e&&e.size>0}updateTag(t,e){let a=this.getByTag(t);for(let i of a)this._removeFromTagMap(i),Object.defineProperty(i,n.symbol,{value:e,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(i,e);return a.length>0&&this._emit("update",{items:a,tag:e}),a.length}removeByTag(t){let e=0;return Array.isArray(t)?t.forEach(a=>{this.removeByTag(a)}):this.getByTag(t).forEach(a=>{this.remove(a)&&e++}),e}show(t){let e=this.getByTag(t),a=0;for(let i of e)r(i.show)&&(i.show=!0,a++);return a}hide(t){let e=this.getByTag(t),a=0;for(let i of e)r(i.show)&&(i.show=!1,a++);return a}toggle(t){let e=this.getByTag(t),a=0;for(let i of e)r(i.show)&&(i.show=!i.show,a++);return a}setProperty(t,e,a){let i=this.getByTag(t),s=0;for(let o of i)e in o?(o[e]=a,s++):console.warn(`${e} does not exists in ${o}`);return s}filter(t,e){return(e?this.getByTag(e):this.values).filter(t)}forEach(t,e){(e?this.getByTag(e):this.values).forEach((i,s)=>t(i,s))}},c=l;export{c as a};
|
package/dist/chunk-KDRPSZ3A.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as w}from"./chunk-CNYZN4AC.js";import{Color as l,Entity as P,HeightReference as V,Rectangle as E,TileCoordinatesImageryProvider as O}from"cesium";var b=class u{_viewer;_collection;_hybridTerrain;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",l.RED],["default",l.BLUE],["fallback",l.GRAY],["grid",l.YELLOW]]);constructor(i,t){this._viewer=i,this._collection=new w({collection:i.entities,tag:u.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([o,r])=>{this._colors.set(o,r)}),t.tile!==void 0&&(this._visible=t.tile),t.activeLevel!==void 0&&(this._level=t.activeLevel),t.terrainProvider&&this.setTerrainProvider(t.terrainProvider))}setTerrainProvider(i){this._hybridTerrain=i,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.removeByTag(this._collection.getTags())}show(i=15){if(!this._hybridTerrain)return;this._collection.removeByTag(u.tag.grid),this._level=i;let t=this._hybridTerrain.tilingScheme;this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new O({tilingScheme:t,color:l.YELLOW})));let o=(e,n,d)=>{if(this._hybridTerrain){for(let h of this._hybridTerrain.terrainAreas)if(h.contains(e,n,d))return h.isCustom?this._colors.get("custom")||l.RED:this._colors.get("default")||l.BLUE;if(this._hybridTerrain.getTileDataAvailable(e,n,d))return this._colors.get("default")||l.BLUE}return this._colors.get("fallback")||l.TRANSPARENT},r=this._getVisibleRectangle();if(!r)return;function g(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}if(!g(r)){console.warn("Invalid visible rectangle detected, skipping grid display");return}try{let e=t.positionToTileXY(E.northwest(r),i),n=t.positionToTileXY(E.southeast(r),i);if(!e||!n)return;let d=100,h=Math.min(n.x-e.x+1,d),m=Math.min(n.y-e.y+1,d);for(let s=e.x;s<=e.x+h-1;s++)for(let c=e.y;c<=e.y+m-1;c++)try{let a=t.tileXYToRectangle(s,c,i);if(!g(a)){console.warn(`Invalid rectangle for tile (${s}, ${c}, ${i}), skipping`);continue}let y=o(s,c,i),v=u.createRectangle(a,y.withAlpha(.3));v.properties?.addProperty("tileX",s),v.properties?.addProperty("tileY",c),v.properties?.addProperty("tileLevel",i),this._collection.add(v,u.tag.grid)}catch(a){console.warn(`Error creating tile (${s}, ${c}, ${i}): ${a.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(e){console.error("Error displaying tile grid:",e)}}hide(){this._collection.removeByTag(u.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(i){Object.entries(i).forEach(([t,o])=>{this._colors.set(t,o)}),this.update()}flyTo(i,t){let{rectangle:o}=i.bounds;this._viewer.camera.flyTo({destination:o,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(i){this._level=i,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}};(o=>{o.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function i(r,g){return new P({rectangle:{coordinates:r,material:g,heightReference:V.CLAMP_TO_GROUND}})}o.createRectangle=i;function t(r,g,e){let n=e?.tag||"terrain_area_visualization",d=e?.color||l.RED,h=e?.maxTilesToShow||100,m=e?.show??!0,s=e?.alpha||.7,c=e?.tileAlpha||.2,a="provider"in r?r.bounds:r,y=new w({collection:g.entities,tag:n}),{rectangle:v}=a;if(y.add(o.createRectangle(v,d.withAlpha(s)),n),m&&a.levels.size>0){let{tilingScheme:R}=a;a.levels.forEach(C=>{let _=0,{tileRanges:L}=a;for(let[x,f]of L.entries())if(x===C)for(let p=f.start.x;p<=f.end.x&&_<h;p++)for(let T=f.start.y;T<=f.end.y&&_<h;T++){let A=R.tileXYToRectangle(p,T,C);y.add(i(A,d.withAlpha(c)),`${n}_tile`),_++}})}return y}o.visualize=t})(b||={});export{b as a};
|