@juun-roh/cesium-utils 0.0.4 → 0.0.6
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-HC6YX7RQ.js +1 -0
- package/dist/collection/index.cjs +1 -1
- package/dist/collection/index.d.cts +6 -3
- package/dist/collection/index.d.ts +6 -3
- 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/sync-camera-CFIMO7Ut.d.cts +133 -0
- package/dist/sync-camera-DHUVJ-Fl.d.ts +133 -0
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.d.cts +11 -129
- package/dist/utils/index.d.ts +11 -129
- package/dist/utils/index.js +1 -1
- package/package.json +6 -3
- package/dist/chunk-4XCQZPKH.js +0 -1
- package/dist/chunk-H3FSQZZE.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Color as c,Entity as B,HeightReference as V,Rectangle as L,TileCoordinatesImageryProvider as S}from"cesium";import{defined as C,EntityCollection as P}from"cesium";var w=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(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){return this.collection.contains(e)}remove(e){let t=this.collection.remove(e);return t&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),t}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof 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}getByTag(e){let t=this._tagMap.get(e);return t?Array.from(t):[]}getFirstByTag(e){let t=this._tagMap.get(e);if(t&&t.size>0)return t.values().next().value}getTags(){return Array.from(this._tagMap.keys())}hasTag(e){let t=this._tagMap.get(e);return!!t&&t.size>0}updateTag(e,t){let i=this.getByTag(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}removeByTag(e){let t=0;return Array.isArray(e)?e.forEach(i=>{t+=this.removeByTag(i)}):this.getByTag(e).forEach(i=>{this.remove(i)&&t++}),t}show(e){let t=this.getByTag(e),i=0;for(let r of t)C(r.show)&&(r.show=!0,i++);return i}hide(e){let t=this.getByTag(e),i=0;for(let r of t)C(r.show)&&(r.show=!1,i++);return i}toggle(e){let t=this.getByTag(e),i=0;for(let r of t)C(r.show)&&(r.show=!r.show,i++);return i}setProperty(e,t,i=this.tag){let r=this.getByTag(i),a=0;for(let o of r)if(e in o&&typeof o[e]!="function"){if(E(o,e))throw Error(`setProperty(${o}, ${e}) failed; The property is readonly.`);o[e]=t,a++}return a}filter(e,t){return(t?this.getByTag(t):this.values).filter(e)}forEach(e,t){(t?this.getByTag(t):this.values).forEach((r,a)=>e(r,a))}},I=w;var f=class n{_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 I({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),t.tile!==void 0&&(this._visible=t.tile),t.activeLevel!==void 0&&(this._level=t.activeLevel),t.terrainProvider&&this.setTerrainProvider(t.terrainProvider))}setTerrainProvider(e){this._hybridTerrain=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.removeByTag(this._collection.getTags())}show(e=15){if(!this._hybridTerrain)return;this._collection.removeByTag(n.tag.grid),this._level=e;let t=this._hybridTerrain.tilingScheme;this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new S({tilingScheme:t,color:c.YELLOW})));let i=(o,s,d)=>{if(this._hybridTerrain){for(let u of this._hybridTerrain.terrainAreas)if(u.contains(o,s,d))return u.isCustom?this._colors.get("custom")||c.RED:this._colors.get("default")||c.BLUE;if(this._hybridTerrain.getTileDataAvailable(o,s,d))return this._colors.get("default")||c.BLUE}return this._colors.get("fallback")||c.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(L.northwest(r),e),s=t.positionToTileXY(L.southeast(r),e);if(!o||!s)return;let d=100,u=Math.min(s.x-o.x+1,d),T=Math.min(s.y-o.y+1,d);for(let h=o.x;h<=o.x+u-1;h++)for(let g=o.y;g<=o.y+T-1;g++)try{let l=t.tileXYToRectangle(h,g,e);if(!a(l)){console.warn(`Invalid rectangle for tile (${h}, ${g}, ${e}), skipping`);continue}let v=i(h,g,e),m=n.createRectangle(l,v.withAlpha(.3));m.properties?.addProperty("tileX",h),m.properties?.addProperty("tileY",g),m.properties?.addProperty("tileLevel",e),this._collection.add(m,n.tag.grid)}catch(l){console.warn(`Error creating tile (${h}, ${g}, ${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.removeByTag(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e.bounds;this._viewer.camera.flyTo({destination:i,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,a){return new B({rectangle:{coordinates:r,material:a,heightReference:V.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,a,o){let s=o?.tag||"terrain_area_visualization",d=o?.color||c.RED,u=o?.maxTilesToShow||100,T=o?.show??!0,h=o?.alpha||.7,g=o?.tileAlpha||.2,l="provider"in r?r.bounds:r,v=new I({collection:a.entities,tag:s}),{rectangle:m}=l;if(v.add(i.createRectangle(m,d.withAlpha(h)),s),T&&l.levels.size>0){let{tilingScheme:A}=l;l.levels.forEach(x=>{let p=0,{tileRanges:R}=l;for(let[M,y]of R.entries())if(M===x)for(let b=y.start.x;b<=y.end.x&&p<u;b++)for(let _=y.start.y;_<=y.end.y&&p<u;_++){let O=A.tileXYToRectangle(b,_,x);v.add(e(O,d.withAlpha(g)),`${s}_tile`),p++}})}return v}i.visualize=t})(f||={});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}export{f as a,E as b,I as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var E=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var S=(n,e)=>{for(var t in e)E(n,t,{get:e[t],enumerable:!0})},j=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of B(e))!V.call(n,r)&&r!==t&&E(n,r,{get:()=>e[r],enumerable:!(i=P(e,r))||i.enumerable});return n};var F=n=>j(E({},"__esModule",{value:!0}),n);var W={};S(W,{Collection:()=>p});module.exports=F(W);var f=require("cesium");var a=require("cesium");var y=class n{_viewer;_collection;_hybridTerrain;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",a.Color.RED],["default",a.Color.BLUE],["fallback",a.Color.GRAY],["grid",a.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new p({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),t.tile!==void 0&&(this._visible=t.tile),t.activeLevel!==void 0&&(this._level=t.activeLevel),t.terrainProvider&&this.setTerrainProvider(t.terrainProvider))}setTerrainProvider(e){this._hybridTerrain=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.removeByTag(this._collection.getTags())}show(e=15){if(!this._hybridTerrain)return;this._collection.removeByTag(n.tag.grid),this._level=e;let t=this._hybridTerrain.tilingScheme;this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new a.TileCoordinatesImageryProvider({tilingScheme:t,color:a.Color.YELLOW})));let i=(o,l,d)=>{if(this._hybridTerrain){for(let u of this._hybridTerrain.terrainAreas)if(u.contains(o,l,d))return u.isCustom?this._colors.get("custom")||a.Color.RED:this._colors.get("default")||a.Color.BLUE;if(this._hybridTerrain.getTileDataAvailable(o,l,d))return this._colors.get("default")||a.Color.BLUE}return this._colors.get("fallback")||a.Color.TRANSPARENT},r=this._getVisibleRectangle();if(!r)return;function s(o){return o&&Number.isFinite(o.west)&&Number.isFinite(o.south)&&Number.isFinite(o.east)&&Number.isFinite(o.north)&&o.west<=o.east&&o.south<=o.north}if(!s(r)){console.warn("Invalid visible rectangle detected, skipping grid display");return}try{let o=t.positionToTileXY(a.Rectangle.northwest(r),e),l=t.positionToTileXY(a.Rectangle.southeast(r),e);if(!o||!l)return;let d=100,u=Math.min(l.x-o.x+1,d),b=Math.min(l.y-o.y+1,d);for(let h=o.x;h<=o.x+u-1;h++)for(let g=o.y;g<=o.y+b-1;g++)try{let c=t.tileXYToRectangle(h,g,e);if(!s(c)){console.warn(`Invalid rectangle for tile (${h}, ${g}, ${e}), skipping`);continue}let v=i(h,g,e),m=n.createRectangle(c,v.withAlpha(.3));m.properties?.addProperty("tileX",h),m.properties?.addProperty("tileY",g),m.properties?.addProperty("tileLevel",e),this._collection.add(m,n.tag.grid)}catch(c){console.warn(`Error creating tile (${h}, ${g}, ${e}): ${c.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(o){console.error("Error displaying tile grid:",o)}}hide(){this._collection.removeByTag(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e.bounds;this._viewer.camera.flyTo({destination:i,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,s){return new a.Entity({rectangle:{coordinates:r,material:s,heightReference:a.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,s,o){let l=o?.tag||"terrain_area_visualization",d=o?.color||a.Color.RED,u=o?.maxTilesToShow||100,b=o?.show??!0,h=o?.alpha||.7,g=o?.tileAlpha||.2,c="provider"in r?r.bounds:r,v=new p({collection:s.entities,tag:l}),{rectangle:m}=c;if(v.add(i.createRectangle(m,d.withAlpha(h)),l),b&&c.levels.size>0){let{tilingScheme:A}=c;c.levels.forEach(L=>{let _=0,{tileRanges:R}=c;for(let[M,T]of R.entries())if(M===L)for(let C=T.start.x;C<=T.end.x&&_<u;C++)for(let w=T.start.y;w<=T.end.y&&_<u;w++){let O=A.tileXYToRectangle(C,w,L);v.add(e(O,d.withAlpha(g)),`${l}_tile`),_++}})}return v}i.visualize=t})(y||={});function I(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}var z=require("cesium");var x=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(s=>s(r))}}_addToTagMap(e,t){this._tagMap.has(t)||this._tagMap.set(t,new Set),this._tagMap.get(t)?.add(e)}_removeFromTagMap(e){let t=e[n.symbol],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache(){this._valuesCache=null}addEventListener(e,t){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(t),this}removeEventListener(e,t){return this._eventListeners.get(e)?.delete(t),this}add(e,t=this.tag,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),this._addToTagMap(e,t),this._invalidateCache(),this._emit("add",{items:[e],tag:t})),e}contains(e){return this.collection.contains(e)}remove(e){let t=this.collection.remove(e);return t&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),t}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof f.EntityCollection)return this.collection.values;{let e=[];for(let t=0;t<this.collection.length;t++)e.push(this.collection.get(t));return e}}get length(){return this.values?.length||0}getByTag(e){let t=this._tagMap.get(e);return t?Array.from(t):[]}getFirstByTag(e){let t=this._tagMap.get(e);if(t&&t.size>0)return t.values().next().value}getTags(){return Array.from(this._tagMap.keys())}hasTag(e){let t=this._tagMap.get(e);return!!t&&t.size>0}updateTag(e,t){let i=this.getByTag(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}removeByTag(e){let t=0;return Array.isArray(e)?e.forEach(i=>{t+=this.removeByTag(i)}):this.getByTag(e).forEach(i=>{this.remove(i)&&t++}),t}show(e){let t=this.getByTag(e),i=0;for(let r of t)(0,f.defined)(r.show)&&(r.show=!0,i++);return i}hide(e){let t=this.getByTag(e),i=0;for(let r of t)(0,f.defined)(r.show)&&(r.show=!1,i++);return i}toggle(e){let t=this.getByTag(e),i=0;for(let r of t)(0,f.defined)(r.show)&&(r.show=!r.show,i++);return i}setProperty(e,t,i=this.tag){let r=this.getByTag(i),s=0;for(let o of r)if(e in o&&typeof o[e]!="function"){if(I(o,e))throw Error(`setProperty(${o}, ${e}) failed; The property is readonly.`);o[e]=t,s++}return s}filter(e,t){return(t?this.getByTag(t):this.values).filter(e)}forEach(e,t){(t?this.getByTag(t):this.values).forEach((r,s)=>e(r,s))}},p=x;
|
|
@@ -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
|
|
@@ -175,7 +178,7 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
175
178
|
* @param item - The item to remove
|
|
176
179
|
* @returns True if the item was removed, false if it wasn't found
|
|
177
180
|
*/
|
|
178
|
-
remove(item: I
|
|
181
|
+
remove(item: I): boolean;
|
|
179
182
|
/**
|
|
180
183
|
* Removes all items from the collection.
|
|
181
184
|
*/
|
|
@@ -325,7 +328,7 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
325
328
|
* // Change color of all buildings to red
|
|
326
329
|
* collection.setProperty('buildings', 'color', Color.RED);
|
|
327
330
|
*/
|
|
328
|
-
setProperty<K extends
|
|
331
|
+
setProperty<K extends NonFunction<I>, V extends Exclude<I[K], Function>>(property: K, value: V, tag?: Tag): number;
|
|
329
332
|
/**
|
|
330
333
|
* Filters items in the collection based on a predicate function.
|
|
331
334
|
* Optionally only filters items with a specific tag.
|
|
@@ -360,4 +363,4 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
360
363
|
forEach(callback: (item: I, index: number) => void, tag?: Tag): void;
|
|
361
364
|
}
|
|
362
365
|
|
|
363
|
-
export { type CesiumCollection, type CesiumCollectionItem, Collection, type CollectionEventType, type EventHandler, type
|
|
366
|
+
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
|
|
@@ -175,7 +178,7 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
175
178
|
* @param item - The item to remove
|
|
176
179
|
* @returns True if the item was removed, false if it wasn't found
|
|
177
180
|
*/
|
|
178
|
-
remove(item: I
|
|
181
|
+
remove(item: I): boolean;
|
|
179
182
|
/**
|
|
180
183
|
* Removes all items from the collection.
|
|
181
184
|
*/
|
|
@@ -325,7 +328,7 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
325
328
|
* // Change color of all buildings to red
|
|
326
329
|
* collection.setProperty('buildings', 'color', Color.RED);
|
|
327
330
|
*/
|
|
328
|
-
setProperty<K extends
|
|
331
|
+
setProperty<K extends NonFunction<I>, V extends Exclude<I[K], Function>>(property: K, value: V, tag?: Tag): number;
|
|
329
332
|
/**
|
|
330
333
|
* Filters items in the collection based on a predicate function.
|
|
331
334
|
* Optionally only filters items with a specific tag.
|
|
@@ -360,4 +363,4 @@ declare class Collection<C extends CesiumCollection, I extends CesiumCollectionI
|
|
|
360
363
|
forEach(callback: (item: I, index: number) => void, tag?: Tag): void;
|
|
361
364
|
}
|
|
362
365
|
|
|
363
|
-
export { type CesiumCollection, type CesiumCollectionItem, Collection, type CollectionEventType, type EventHandler, type
|
|
366
|
+
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-HC6YX7RQ.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)}):(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,r),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 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 U=n=>$(k({},"__esModule",{value:!0}),n);var X={};W(X,{Collection:()=>R,HybridTerrainProvider:()=>P,TerrainArea:()=>g,TerrainAreas:()=>p,TerrainBounds:()=>v,TerrainVisualizer:()=>T,cloneViewer:()=>D,syncCamera:()=>C});module.exports=U(X);var w=require("cesium");var l=require("cesium");var T=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 R({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 h=r.tileXYToRectangle(m,f,e);if(!o(h)){console.warn(`Invalid rectangle for tile (${m}, ${f}, ${e}), skipping`);continue}let A=t(m,f,e),_=n.createRectangle(h,A.withAlpha(.3));_.properties?.addProperty("tileX",m),_.properties?.addProperty("tileY",f),_.properties?.addProperty("tileLevel",e),this._collection.add(_,n.tag.grid)}catch(h){console.warn(`Error creating tile (${m}, ${f}, ${e}): ${h.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,h="provider"in i?i.bounds:i,A=new R({collection:o.entities,tag:s}),{rectangle:_}=h;if(A.add(t.createRectangle(_,c.withAlpha(m)),s),y&&h.levels.size>0){let{tilingScheme:G}=h;h.levels.forEach(B=>{let I=0,{tileRanges:F}=h;for(let[z,E]of F.entries())if(z===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 j=G.tileXYToRectangle(x,S,B);A.add(e(j,c.withAlpha(f)),`${s}_tile`),I++}})}return A}t.visualize=r})(T||={});function M(n,e){let r=!1,t=Object.getOwnPropertyDescriptor(n,e);if(!t){let i=Object.getPrototypeOf(n);for(;i&&!t;)t=Object.getOwnPropertyDescriptor(i,e),i=Object.getPrototypeOf(i)}return t&&t.get&&!t.set&&(r=!0),r}var L=require("cesium");function C(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=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.collection instanceof w.EntityCollection)return this.collection.values;{let e=[];for(let r=0;r<this.collection.length;r++)e.push(this.collection.get(r));return e}}get length(){return this.values?.length||0}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=>{r+=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,w.defined)(i.show)&&(i.show=!0,t++);return t}hide(e){let r=this.getByTag(e),t=0;for(let i of r)(0,w.defined)(i.show)&&(i.show=!1,t++);return t}toggle(e){let r=this.getByTag(e),t=0;for(let i of r)(0,w.defined)(i.show)&&(i.show=!i.show,t++);return t}setProperty(e,r,t=this.tag){let i=this.getByTag(t),o=0;for(let a of i)if(e in a&&typeof a[e]!="function"){if(M(a,e))throw Error(`setProperty(${a}, ${e}) failed; The property is readonly.`);a[e]=r,o++}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))}},R=O;var b=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 g=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})(g||={});var p=class extends Array{async add(e){let r;return e instanceof g?r=e:r=await g.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 P=class n{_terrainAreas=new p;_terrainProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(e,r,t){this._terrainProvider=e,this._fallbackProvider=r,this._tilingScheme=e.tilingScheme||new b.GeographicTilingScheme,this._terrainAreas=new p(...t),this._availability=e.availability,this._ready=!0}static async create(e){try{let r;typeof e.terrainProvider=="string"?r=await b.CesiumTerrainProvider.fromUrl(e.terrainProvider,{requestVertexNormals:!0}):r=e.terrainProvider;let t;e.fallbackProvider?typeof e.fallbackProvider=="string"?t=await b.CesiumTerrainProvider.fromUrl(e.fallbackProvider,{requestVertexNormals:!0}):t=e.fallbackProvider:t=new b.EllipsoidTerrainProvider;let i=[];for(let o of e.terrainAreas){let a=await g.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 b.EllipsoidTerrainProvider})}e.createOverlay=n})(P||={});var N=require("cesium");function D(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 N.Viewer(e,{...t,...r});C(n,i);let o=n.imageryLayers;i.imageryLayers.removeAll();for(let c=0;c<o.length;c++){let d=o.get(c);i.imageryLayers.addImageryProvider(d.imageryProvider,c)}i.clock.startTime=n.clock.startTime.clone(),i.clock.stopTime=n.clock.stopTime.clone(),i.clock.currentTime=n.clock.currentTime.clone(),i.clock.multiplier=n.clock.multiplier,i.clock.clockStep=n.clock.clockStep,i.clock.clockRange=n.clock.clockRange,i.clock.shouldAnimate=n.clock.shouldAnimate,i.scene.globe.enableLighting=n.scene.globe.enableLighting,i.scene.globe.depthTestAgainstTerrain=n.scene.globe.depthTestAgainstTerrain,i.scene.screenSpaceCameraController.enableCollisionDetection=n.scene.screenSpaceCameraController.enableCollisionDetection;let a=n.scene.screenSpaceCameraController.tiltEventTypes;a&&(i.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(a)?[...a]:a);let s=n.scene.screenSpaceCameraController.zoomEventTypes;return s&&(i.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(s)?[...s]:s),i}
|
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 './
|
|
4
|
+
export { T as TerrainVisualizer, s as syncCamera } from './sync-camera-CFIMO7Ut.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 './
|
|
4
|
+
export { T as TerrainVisualizer, s as syncCamera } from './sync-camera-DHUVJ-Fl.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 r,c as e}from"./chunk-HC6YX7RQ.js";import{a}from"./chunk-STARYORM.js";import{a as o}from"./chunk-YZ7AUGIO.js";import{a as i,b as t,c as m,d as p}from"./chunk-C52KJ2WP.js";export{e as Collection,p as HybridTerrainProvider,t as TerrainArea,m as TerrainAreas,i as TerrainBounds,r as TerrainVisualizer,a as cloneViewer,o as syncCamera};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Viewer, Color, EntityCollection, Entity, Rectangle } from 'cesium';
|
|
2
|
+
import { H as HybridTerrainProvider, T as TerrainArea, a as TerrainBounds } from './hybrid-terrain-provider-C6aXdtyo.cjs';
|
|
3
|
+
import { Collection } from './collection/index.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @class
|
|
7
|
+
* Utility class for visualizing terrain provider boundaries and debugging terrain loading.
|
|
8
|
+
*/
|
|
9
|
+
declare class TerrainVisualizer {
|
|
10
|
+
private _viewer;
|
|
11
|
+
private _collection;
|
|
12
|
+
private _hybridTerrain?;
|
|
13
|
+
private _visible;
|
|
14
|
+
private _level;
|
|
15
|
+
private _tileCoordinatesLayer;
|
|
16
|
+
private _colors;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new `TerrainVisualizer`.
|
|
19
|
+
* @param viewer The Cesium viewer instance
|
|
20
|
+
* @param options {@link TerrainVisualizer.ConstructorOptions}
|
|
21
|
+
*/
|
|
22
|
+
constructor(viewer: Viewer, options?: TerrainVisualizer.ConstructorOptions);
|
|
23
|
+
/**
|
|
24
|
+
* Sets the terrain provider to visualize.
|
|
25
|
+
* @param terrainProvider The terrain provider to visualize.
|
|
26
|
+
*/
|
|
27
|
+
setTerrainProvider(terrainProvider: HybridTerrainProvider): void;
|
|
28
|
+
/**
|
|
29
|
+
* Updates all active visualizations.
|
|
30
|
+
*/
|
|
31
|
+
update(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Clears all visualizations.
|
|
34
|
+
*/
|
|
35
|
+
clear(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Shows a grid of tiles at the specified level.
|
|
38
|
+
* @param level The zoom level to visualize
|
|
39
|
+
*/
|
|
40
|
+
show(level?: number): void;
|
|
41
|
+
/**
|
|
42
|
+
* Hides the tile grid.
|
|
43
|
+
*/
|
|
44
|
+
hide(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Sets the colors used for visualization.
|
|
47
|
+
* @param colors Map of role names to colors
|
|
48
|
+
*/
|
|
49
|
+
setColors(colors: Record<string, Color>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Flies the camera to focus on a terrain area.
|
|
52
|
+
* @param area The terrain area to focus on.
|
|
53
|
+
* @param options {@link Viewer.flyTo}
|
|
54
|
+
*/
|
|
55
|
+
flyTo(area: TerrainArea, options?: {
|
|
56
|
+
duration?: number;
|
|
57
|
+
}): void;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the rectangle representing the current view.
|
|
60
|
+
* @returns The current view rectangle or undefined.
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
private _getVisibleRectangle;
|
|
64
|
+
/** The current zoom level set on the visualizer. */
|
|
65
|
+
get level(): number;
|
|
66
|
+
/** Set zoom level on the visualizer. */
|
|
67
|
+
set level(level: number);
|
|
68
|
+
/** Whether the grid is currently visible. */
|
|
69
|
+
get visible(): boolean;
|
|
70
|
+
/** The collection used in the visualizer. */
|
|
71
|
+
get collection(): Collection<EntityCollection, Entity>;
|
|
72
|
+
/** The viewer used in the visualizer */
|
|
73
|
+
get viewer(): Viewer;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @namespace
|
|
77
|
+
* Contains types, utility functions, and constants for terrain visualization.
|
|
78
|
+
*/
|
|
79
|
+
declare namespace TerrainVisualizer {
|
|
80
|
+
/** Initialization options for `TerrainVisualizer` constructor. */
|
|
81
|
+
interface ConstructorOptions {
|
|
82
|
+
/** Colors to use for different visualization elements */
|
|
83
|
+
colors?: Record<string, Color>;
|
|
84
|
+
/** Whether to show boundaries initially. */
|
|
85
|
+
boundaries?: boolean;
|
|
86
|
+
/** Whether to show tile grid initially. */
|
|
87
|
+
tile?: boolean;
|
|
88
|
+
/** Initial zoom level to use for visualizations. */
|
|
89
|
+
activeLevel?: number;
|
|
90
|
+
/** Terrain provider to visualize. */
|
|
91
|
+
terrainProvider?: HybridTerrainProvider;
|
|
92
|
+
}
|
|
93
|
+
/** Tag constants for entity collection management. */
|
|
94
|
+
const tag: {
|
|
95
|
+
default: string;
|
|
96
|
+
boundary: string;
|
|
97
|
+
grid: string;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Creates a ground-clamped rectangle entity for visualization.
|
|
101
|
+
* @param rectangle The rectangle to visualize
|
|
102
|
+
* @param color The color to use
|
|
103
|
+
* @returns A new entity
|
|
104
|
+
*/
|
|
105
|
+
function createRectangle(rectangle: Rectangle, color: Color): Entity;
|
|
106
|
+
/** Options for {@link TerrainVisualizer.visualize} */
|
|
107
|
+
interface Options {
|
|
108
|
+
color?: Color;
|
|
109
|
+
show?: boolean;
|
|
110
|
+
maxTilesToShow?: number;
|
|
111
|
+
levels?: number[];
|
|
112
|
+
tag?: string;
|
|
113
|
+
alpha?: number;
|
|
114
|
+
tileAlpha?: number;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Visualizes a specific terrain area in a viewer.
|
|
118
|
+
* @param terrain The terrain area to visualize.
|
|
119
|
+
* @param viewer The Cesium viewer.
|
|
120
|
+
* @param options Visualization options.
|
|
121
|
+
* @returns Collection of created entities.
|
|
122
|
+
*/
|
|
123
|
+
function visualize(terrain: TerrainArea | TerrainBounds, viewer: Viewer, options?: Options): Collection<EntityCollection, Entity>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Copies camera state from source viewer to destination viewer.
|
|
128
|
+
* @param source The source viewer to copy camera states from.
|
|
129
|
+
* @param dest The destination viewer to apply camera properties from the source.
|
|
130
|
+
*/
|
|
131
|
+
declare function syncCamera(source: Viewer, dest: Viewer): void;
|
|
132
|
+
|
|
133
|
+
export { TerrainVisualizer as T, syncCamera as s };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Viewer, Color, EntityCollection, Entity, Rectangle } from 'cesium';
|
|
2
|
+
import { H as HybridTerrainProvider, T as TerrainArea, a as TerrainBounds } from './hybrid-terrain-provider-C6aXdtyo.js';
|
|
3
|
+
import { Collection } from './collection/index.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @class
|
|
7
|
+
* Utility class for visualizing terrain provider boundaries and debugging terrain loading.
|
|
8
|
+
*/
|
|
9
|
+
declare class TerrainVisualizer {
|
|
10
|
+
private _viewer;
|
|
11
|
+
private _collection;
|
|
12
|
+
private _hybridTerrain?;
|
|
13
|
+
private _visible;
|
|
14
|
+
private _level;
|
|
15
|
+
private _tileCoordinatesLayer;
|
|
16
|
+
private _colors;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new `TerrainVisualizer`.
|
|
19
|
+
* @param viewer The Cesium viewer instance
|
|
20
|
+
* @param options {@link TerrainVisualizer.ConstructorOptions}
|
|
21
|
+
*/
|
|
22
|
+
constructor(viewer: Viewer, options?: TerrainVisualizer.ConstructorOptions);
|
|
23
|
+
/**
|
|
24
|
+
* Sets the terrain provider to visualize.
|
|
25
|
+
* @param terrainProvider The terrain provider to visualize.
|
|
26
|
+
*/
|
|
27
|
+
setTerrainProvider(terrainProvider: HybridTerrainProvider): void;
|
|
28
|
+
/**
|
|
29
|
+
* Updates all active visualizations.
|
|
30
|
+
*/
|
|
31
|
+
update(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Clears all visualizations.
|
|
34
|
+
*/
|
|
35
|
+
clear(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Shows a grid of tiles at the specified level.
|
|
38
|
+
* @param level The zoom level to visualize
|
|
39
|
+
*/
|
|
40
|
+
show(level?: number): void;
|
|
41
|
+
/**
|
|
42
|
+
* Hides the tile grid.
|
|
43
|
+
*/
|
|
44
|
+
hide(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Sets the colors used for visualization.
|
|
47
|
+
* @param colors Map of role names to colors
|
|
48
|
+
*/
|
|
49
|
+
setColors(colors: Record<string, Color>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Flies the camera to focus on a terrain area.
|
|
52
|
+
* @param area The terrain area to focus on.
|
|
53
|
+
* @param options {@link Viewer.flyTo}
|
|
54
|
+
*/
|
|
55
|
+
flyTo(area: TerrainArea, options?: {
|
|
56
|
+
duration?: number;
|
|
57
|
+
}): void;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the rectangle representing the current view.
|
|
60
|
+
* @returns The current view rectangle or undefined.
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
private _getVisibleRectangle;
|
|
64
|
+
/** The current zoom level set on the visualizer. */
|
|
65
|
+
get level(): number;
|
|
66
|
+
/** Set zoom level on the visualizer. */
|
|
67
|
+
set level(level: number);
|
|
68
|
+
/** Whether the grid is currently visible. */
|
|
69
|
+
get visible(): boolean;
|
|
70
|
+
/** The collection used in the visualizer. */
|
|
71
|
+
get collection(): Collection<EntityCollection, Entity>;
|
|
72
|
+
/** The viewer used in the visualizer */
|
|
73
|
+
get viewer(): Viewer;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @namespace
|
|
77
|
+
* Contains types, utility functions, and constants for terrain visualization.
|
|
78
|
+
*/
|
|
79
|
+
declare namespace TerrainVisualizer {
|
|
80
|
+
/** Initialization options for `TerrainVisualizer` constructor. */
|
|
81
|
+
interface ConstructorOptions {
|
|
82
|
+
/** Colors to use for different visualization elements */
|
|
83
|
+
colors?: Record<string, Color>;
|
|
84
|
+
/** Whether to show boundaries initially. */
|
|
85
|
+
boundaries?: boolean;
|
|
86
|
+
/** Whether to show tile grid initially. */
|
|
87
|
+
tile?: boolean;
|
|
88
|
+
/** Initial zoom level to use for visualizations. */
|
|
89
|
+
activeLevel?: number;
|
|
90
|
+
/** Terrain provider to visualize. */
|
|
91
|
+
terrainProvider?: HybridTerrainProvider;
|
|
92
|
+
}
|
|
93
|
+
/** Tag constants for entity collection management. */
|
|
94
|
+
const tag: {
|
|
95
|
+
default: string;
|
|
96
|
+
boundary: string;
|
|
97
|
+
grid: string;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Creates a ground-clamped rectangle entity for visualization.
|
|
101
|
+
* @param rectangle The rectangle to visualize
|
|
102
|
+
* @param color The color to use
|
|
103
|
+
* @returns A new entity
|
|
104
|
+
*/
|
|
105
|
+
function createRectangle(rectangle: Rectangle, color: Color): Entity;
|
|
106
|
+
/** Options for {@link TerrainVisualizer.visualize} */
|
|
107
|
+
interface Options {
|
|
108
|
+
color?: Color;
|
|
109
|
+
show?: boolean;
|
|
110
|
+
maxTilesToShow?: number;
|
|
111
|
+
levels?: number[];
|
|
112
|
+
tag?: string;
|
|
113
|
+
alpha?: number;
|
|
114
|
+
tileAlpha?: number;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Visualizes a specific terrain area in a viewer.
|
|
118
|
+
* @param terrain The terrain area to visualize.
|
|
119
|
+
* @param viewer The Cesium viewer.
|
|
120
|
+
* @param options Visualization options.
|
|
121
|
+
* @returns Collection of created entities.
|
|
122
|
+
*/
|
|
123
|
+
function visualize(terrain: TerrainArea | TerrainBounds, viewer: Viewer, options?: Options): Collection<EntityCollection, Entity>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Copies camera state from source viewer to destination viewer.
|
|
128
|
+
* @param source The source viewer to copy camera states from.
|
|
129
|
+
* @param dest The destination viewer to apply camera properties from the source.
|
|
130
|
+
*/
|
|
131
|
+
declare function syncCamera(source: Viewer, dest: Viewer): void;
|
|
132
|
+
|
|
133
|
+
export { TerrainVisualizer as T, syncCamera as s };
|
package/dist/utils/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var E=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var j=(n,e)=>{for(var t in e)E(n,t,{get:e[t],enumerable:!0})},z=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of S(e))!F.call(n,r)&&r!==t&&E(n,r,{get:()=>e[r],enumerable:!(i=V(e,r))||i.enumerable});return n};var W=n=>z(E({},"__esModule",{value:!0}),n);var $={};j($,{TerrainVisualizer:()=>v,isGetterOnly:()=>p,syncCamera:()=>R});module.exports=W($);var a=require("cesium");var f=require("cesium");var I=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(s=>s(r))}}_addToTagMap(e,t){this._tagMap.has(t)||this._tagMap.set(t,new Set),this._tagMap.get(t)?.add(e)}_removeFromTagMap(e){let t=e[n.symbol],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache(){this._valuesCache=null}addEventListener(e,t){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(t),this}removeEventListener(e,t){return this._eventListeners.get(e)?.delete(t),this}add(e,t=this.tag,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),this._addToTagMap(e,t),this._invalidateCache(),this._emit("add",{items:[e],tag:t})),e}contains(e){return this.collection.contains(e)}remove(e){let t=this.collection.remove(e);return t&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),t}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof f.EntityCollection)return this.collection.values;{let e=[];for(let t=0;t<this.collection.length;t++)e.push(this.collection.get(t));return e}}get length(){return this.values?.length||0}getByTag(e){let t=this._tagMap.get(e);return t?Array.from(t):[]}getFirstByTag(e){let t=this._tagMap.get(e);if(t&&t.size>0)return t.values().next().value}getTags(){return Array.from(this._tagMap.keys())}hasTag(e){let t=this._tagMap.get(e);return!!t&&t.size>0}updateTag(e,t){let i=this.getByTag(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}removeByTag(e){let t=0;return Array.isArray(e)?e.forEach(i=>{t+=this.removeByTag(i)}):this.getByTag(e).forEach(i=>{this.remove(i)&&t++}),t}show(e){let t=this.getByTag(e),i=0;for(let r of t)(0,f.defined)(r.show)&&(r.show=!0,i++);return i}hide(e){let t=this.getByTag(e),i=0;for(let r of t)(0,f.defined)(r.show)&&(r.show=!1,i++);return i}toggle(e){let t=this.getByTag(e),i=0;for(let r of t)(0,f.defined)(r.show)&&(r.show=!r.show,i++);return i}setProperty(e,t,i=this.tag){let r=this.getByTag(i),s=0;for(let o of r)if(e in o&&typeof o[e]!="function"){if(p(o,e))throw Error(`setProperty(${o}, ${e}) failed; The property is readonly.`);o[e]=t,s++}return s}filter(e,t){return(t?this.getByTag(t):this.values).filter(e)}forEach(e,t){(t?this.getByTag(t):this.values).forEach((r,s)=>e(r,s))}},x=I;var v=class n{_viewer;_collection;_hybridTerrain;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",a.Color.RED],["default",a.Color.BLUE],["fallback",a.Color.GRAY],["grid",a.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new 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.removeByTag(this._collection.getTags())}show(e=15){if(!this._hybridTerrain)return;this._collection.removeByTag(n.tag.grid),this._level=e;let t=this._hybridTerrain.tilingScheme;this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new a.TileCoordinatesImageryProvider({tilingScheme:t,color:a.Color.YELLOW})));let i=(o,l,d)=>{if(this._hybridTerrain){for(let u of this._hybridTerrain.terrainAreas)if(u.contains(o,l,d))return u.isCustom?this._colors.get("custom")||a.Color.RED:this._colors.get("default")||a.Color.BLUE;if(this._hybridTerrain.getTileDataAvailable(o,l,d))return this._colors.get("default")||a.Color.BLUE}return this._colors.get("fallback")||a.Color.TRANSPARENT},r=this._getVisibleRectangle();if(!r)return;function s(o){return o&&Number.isFinite(o.west)&&Number.isFinite(o.south)&&Number.isFinite(o.east)&&Number.isFinite(o.north)&&o.west<=o.east&&o.south<=o.north}if(!s(r)){console.warn("Invalid visible rectangle detected, skipping grid display");return}try{let o=t.positionToTileXY(a.Rectangle.northwest(r),e),l=t.positionToTileXY(a.Rectangle.southeast(r),e);if(!o||!l)return;let d=100,u=Math.min(l.x-o.x+1,d),b=Math.min(l.y-o.y+1,d);for(let h=o.x;h<=o.x+u-1;h++)for(let g=o.y;g<=o.y+b-1;g++)try{let c=t.tileXYToRectangle(h,g,e);if(!s(c)){console.warn(`Invalid rectangle for tile (${h}, ${g}, ${e}), skipping`);continue}let y=i(h,g,e),m=n.createRectangle(c,y.withAlpha(.3));m.properties?.addProperty("tileX",h),m.properties?.addProperty("tileY",g),m.properties?.addProperty("tileLevel",e),this._collection.add(m,n.tag.grid)}catch(c){console.warn(`Error creating tile (${h}, ${g}, ${e}): ${c.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(o){console.error("Error displaying tile grid:",o)}}hide(){this._collection.removeByTag(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e.bounds;this._viewer.camera.flyTo({destination:i,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,s){return new a.Entity({rectangle:{coordinates:r,material:s,heightReference:a.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,s,o){let l=o?.tag||"terrain_area_visualization",d=o?.color||a.Color.RED,u=o?.maxTilesToShow||100,b=o?.show??!0,h=o?.alpha||.7,g=o?.tileAlpha||.2,c="provider"in r?r.bounds:r,y=new x({collection:s.entities,tag:l}),{rectangle:m}=c;if(y.add(i.createRectangle(m,d.withAlpha(h)),l),b&&c.levels.size>0){let{tilingScheme:M}=c;c.levels.forEach(A=>{let _=0,{tileRanges:O}=c;for(let[P,T]of O.entries())if(P===A)for(let C=T.start.x;C<=T.end.x&&_<u;C++)for(let w=T.start.y;w<=T.end.y&&_<u;w++){let B=M.tileXYToRectangle(C,w,A);y.add(e(B,d.withAlpha(g)),`${l}_tile`),_++}})}return y}i.visualize=t})(v||={});function p(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}var L=require("cesium");function R(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
|
@@ -1,133 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
export { T as TerrainVisualizer, s as syncCamera } from '../sync-camera-CFIMO7Ut.cjs';
|
|
2
|
+
import 'cesium';
|
|
3
|
+
import '../hybrid-terrain-provider-C6aXdtyo.cjs';
|
|
4
|
+
import '../collection/index.cjs';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
7
|
+
* Examine the property descriptors at runtime
|
|
8
|
+
* to detect properties that only have getters.
|
|
9
|
+
* (read-only accessor properties)
|
|
10
|
+
* @param o The object to examine.
|
|
11
|
+
* @param k The key value of the property.
|
|
8
12
|
*/
|
|
9
|
-
declare
|
|
10
|
-
private _viewer;
|
|
11
|
-
private _collection;
|
|
12
|
-
private _hybridTerrain?;
|
|
13
|
-
private _visible;
|
|
14
|
-
private _level;
|
|
15
|
-
private _tileCoordinatesLayer;
|
|
16
|
-
private _colors;
|
|
17
|
-
/**
|
|
18
|
-
* Creates a new `TerrainVisualizer`.
|
|
19
|
-
* @param viewer The Cesium viewer instance
|
|
20
|
-
* @param options {@link TerrainVisualizer.ConstructorOptions}
|
|
21
|
-
*/
|
|
22
|
-
constructor(viewer: Viewer, options?: TerrainVisualizer.ConstructorOptions);
|
|
23
|
-
/**
|
|
24
|
-
* Sets the terrain provider to visualize.
|
|
25
|
-
* @param terrainProvider The terrain provider to visualize.
|
|
26
|
-
*/
|
|
27
|
-
setTerrainProvider(terrainProvider: HybridTerrainProvider): void;
|
|
28
|
-
/**
|
|
29
|
-
* Updates all active visualizations.
|
|
30
|
-
*/
|
|
31
|
-
update(): void;
|
|
32
|
-
/**
|
|
33
|
-
* Clears all visualizations.
|
|
34
|
-
*/
|
|
35
|
-
clear(): void;
|
|
36
|
-
/**
|
|
37
|
-
* Shows a grid of tiles at the specified level.
|
|
38
|
-
* @param level The zoom level to visualize
|
|
39
|
-
*/
|
|
40
|
-
show(level?: number): void;
|
|
41
|
-
/**
|
|
42
|
-
* Hides the tile grid.
|
|
43
|
-
*/
|
|
44
|
-
hide(): void;
|
|
45
|
-
/**
|
|
46
|
-
* Sets the colors used for visualization.
|
|
47
|
-
* @param colors Map of role names to colors
|
|
48
|
-
*/
|
|
49
|
-
setColors(colors: Record<string, Color>): void;
|
|
50
|
-
/**
|
|
51
|
-
* Flies the camera to focus on a terrain area.
|
|
52
|
-
* @param area The terrain area to focus on.
|
|
53
|
-
* @param options {@link Viewer.flyTo}
|
|
54
|
-
*/
|
|
55
|
-
flyTo(area: TerrainArea, options?: {
|
|
56
|
-
duration?: number;
|
|
57
|
-
}): void;
|
|
58
|
-
/**
|
|
59
|
-
* Gets the rectangle representing the current view.
|
|
60
|
-
* @returns The current view rectangle or undefined.
|
|
61
|
-
* @private
|
|
62
|
-
*/
|
|
63
|
-
private _getVisibleRectangle;
|
|
64
|
-
/** The current zoom level set on the visualizer. */
|
|
65
|
-
get level(): number;
|
|
66
|
-
/** Set zoom level on the visualizer. */
|
|
67
|
-
set level(level: number);
|
|
68
|
-
/** Whether the grid is currently visible. */
|
|
69
|
-
get visible(): boolean;
|
|
70
|
-
/** The collection used in the visualizer. */
|
|
71
|
-
get collection(): Collection<EntityCollection, Entity>;
|
|
72
|
-
/** The viewer used in the visualizer */
|
|
73
|
-
get viewer(): Viewer;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* @namespace
|
|
77
|
-
* Contains types, utility functions, and constants for terrain visualization.
|
|
78
|
-
*/
|
|
79
|
-
declare namespace TerrainVisualizer {
|
|
80
|
-
/** Initialization options for `TerrainVisualizer` constructor. */
|
|
81
|
-
interface ConstructorOptions {
|
|
82
|
-
/** Colors to use for different visualization elements */
|
|
83
|
-
colors?: Record<string, Color>;
|
|
84
|
-
/** Whether to show boundaries initially. */
|
|
85
|
-
boundaries?: boolean;
|
|
86
|
-
/** Whether to show tile grid initially. */
|
|
87
|
-
tile?: boolean;
|
|
88
|
-
/** Initial zoom level to use for visualizations. */
|
|
89
|
-
activeLevel?: number;
|
|
90
|
-
/** Terrain provider to visualize. */
|
|
91
|
-
terrainProvider?: HybridTerrainProvider;
|
|
92
|
-
}
|
|
93
|
-
/** Tag constants for entity collection management. */
|
|
94
|
-
const tag: {
|
|
95
|
-
default: string;
|
|
96
|
-
boundary: string;
|
|
97
|
-
grid: string;
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* Creates a ground-clamped rectangle entity for visualization.
|
|
101
|
-
* @param rectangle The rectangle to visualize
|
|
102
|
-
* @param color The color to use
|
|
103
|
-
* @returns A new entity
|
|
104
|
-
*/
|
|
105
|
-
function createRectangle(rectangle: Rectangle, color: Color): Entity;
|
|
106
|
-
/** Options for {@link TerrainVisualizer.visualize} */
|
|
107
|
-
interface Options {
|
|
108
|
-
color?: Color;
|
|
109
|
-
show?: boolean;
|
|
110
|
-
maxTilesToShow?: number;
|
|
111
|
-
levels?: number[];
|
|
112
|
-
tag?: string;
|
|
113
|
-
alpha?: number;
|
|
114
|
-
tileAlpha?: number;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Visualizes a specific terrain area in a viewer.
|
|
118
|
-
* @param terrain The terrain area to visualize.
|
|
119
|
-
* @param viewer The Cesium viewer.
|
|
120
|
-
* @param options Visualization options.
|
|
121
|
-
* @returns Collection of created entities.
|
|
122
|
-
*/
|
|
123
|
-
function visualize(terrain: TerrainArea | TerrainBounds, viewer: Viewer, options?: Options): Collection<EntityCollection, Entity>;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Copies camera state from source viewer to destination viewer.
|
|
128
|
-
* @param source The source viewer to copy camera states from.
|
|
129
|
-
* @param dest The destination viewer to apply camera properties from the source.
|
|
130
|
-
*/
|
|
131
|
-
declare function syncCamera(source: Viewer, dest: Viewer): void;
|
|
13
|
+
declare function isGetterOnly(o: object, k: string | number | symbol): boolean;
|
|
132
14
|
|
|
133
|
-
export {
|
|
15
|
+
export { isGetterOnly };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,133 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
export { T as TerrainVisualizer, s as syncCamera } from '../sync-camera-DHUVJ-Fl.js';
|
|
2
|
+
import 'cesium';
|
|
3
|
+
import '../hybrid-terrain-provider-C6aXdtyo.js';
|
|
4
|
+
import '../collection/index.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
7
|
+
* Examine the property descriptors at runtime
|
|
8
|
+
* to detect properties that only have getters.
|
|
9
|
+
* (read-only accessor properties)
|
|
10
|
+
* @param o The object to examine.
|
|
11
|
+
* @param k The key value of the property.
|
|
8
12
|
*/
|
|
9
|
-
declare
|
|
10
|
-
private _viewer;
|
|
11
|
-
private _collection;
|
|
12
|
-
private _hybridTerrain?;
|
|
13
|
-
private _visible;
|
|
14
|
-
private _level;
|
|
15
|
-
private _tileCoordinatesLayer;
|
|
16
|
-
private _colors;
|
|
17
|
-
/**
|
|
18
|
-
* Creates a new `TerrainVisualizer`.
|
|
19
|
-
* @param viewer The Cesium viewer instance
|
|
20
|
-
* @param options {@link TerrainVisualizer.ConstructorOptions}
|
|
21
|
-
*/
|
|
22
|
-
constructor(viewer: Viewer, options?: TerrainVisualizer.ConstructorOptions);
|
|
23
|
-
/**
|
|
24
|
-
* Sets the terrain provider to visualize.
|
|
25
|
-
* @param terrainProvider The terrain provider to visualize.
|
|
26
|
-
*/
|
|
27
|
-
setTerrainProvider(terrainProvider: HybridTerrainProvider): void;
|
|
28
|
-
/**
|
|
29
|
-
* Updates all active visualizations.
|
|
30
|
-
*/
|
|
31
|
-
update(): void;
|
|
32
|
-
/**
|
|
33
|
-
* Clears all visualizations.
|
|
34
|
-
*/
|
|
35
|
-
clear(): void;
|
|
36
|
-
/**
|
|
37
|
-
* Shows a grid of tiles at the specified level.
|
|
38
|
-
* @param level The zoom level to visualize
|
|
39
|
-
*/
|
|
40
|
-
show(level?: number): void;
|
|
41
|
-
/**
|
|
42
|
-
* Hides the tile grid.
|
|
43
|
-
*/
|
|
44
|
-
hide(): void;
|
|
45
|
-
/**
|
|
46
|
-
* Sets the colors used for visualization.
|
|
47
|
-
* @param colors Map of role names to colors
|
|
48
|
-
*/
|
|
49
|
-
setColors(colors: Record<string, Color>): void;
|
|
50
|
-
/**
|
|
51
|
-
* Flies the camera to focus on a terrain area.
|
|
52
|
-
* @param area The terrain area to focus on.
|
|
53
|
-
* @param options {@link Viewer.flyTo}
|
|
54
|
-
*/
|
|
55
|
-
flyTo(area: TerrainArea, options?: {
|
|
56
|
-
duration?: number;
|
|
57
|
-
}): void;
|
|
58
|
-
/**
|
|
59
|
-
* Gets the rectangle representing the current view.
|
|
60
|
-
* @returns The current view rectangle or undefined.
|
|
61
|
-
* @private
|
|
62
|
-
*/
|
|
63
|
-
private _getVisibleRectangle;
|
|
64
|
-
/** The current zoom level set on the visualizer. */
|
|
65
|
-
get level(): number;
|
|
66
|
-
/** Set zoom level on the visualizer. */
|
|
67
|
-
set level(level: number);
|
|
68
|
-
/** Whether the grid is currently visible. */
|
|
69
|
-
get visible(): boolean;
|
|
70
|
-
/** The collection used in the visualizer. */
|
|
71
|
-
get collection(): Collection<EntityCollection, Entity>;
|
|
72
|
-
/** The viewer used in the visualizer */
|
|
73
|
-
get viewer(): Viewer;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* @namespace
|
|
77
|
-
* Contains types, utility functions, and constants for terrain visualization.
|
|
78
|
-
*/
|
|
79
|
-
declare namespace TerrainVisualizer {
|
|
80
|
-
/** Initialization options for `TerrainVisualizer` constructor. */
|
|
81
|
-
interface ConstructorOptions {
|
|
82
|
-
/** Colors to use for different visualization elements */
|
|
83
|
-
colors?: Record<string, Color>;
|
|
84
|
-
/** Whether to show boundaries initially. */
|
|
85
|
-
boundaries?: boolean;
|
|
86
|
-
/** Whether to show tile grid initially. */
|
|
87
|
-
tile?: boolean;
|
|
88
|
-
/** Initial zoom level to use for visualizations. */
|
|
89
|
-
activeLevel?: number;
|
|
90
|
-
/** Terrain provider to visualize. */
|
|
91
|
-
terrainProvider?: HybridTerrainProvider;
|
|
92
|
-
}
|
|
93
|
-
/** Tag constants for entity collection management. */
|
|
94
|
-
const tag: {
|
|
95
|
-
default: string;
|
|
96
|
-
boundary: string;
|
|
97
|
-
grid: string;
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* Creates a ground-clamped rectangle entity for visualization.
|
|
101
|
-
* @param rectangle The rectangle to visualize
|
|
102
|
-
* @param color The color to use
|
|
103
|
-
* @returns A new entity
|
|
104
|
-
*/
|
|
105
|
-
function createRectangle(rectangle: Rectangle, color: Color): Entity;
|
|
106
|
-
/** Options for {@link TerrainVisualizer.visualize} */
|
|
107
|
-
interface Options {
|
|
108
|
-
color?: Color;
|
|
109
|
-
show?: boolean;
|
|
110
|
-
maxTilesToShow?: number;
|
|
111
|
-
levels?: number[];
|
|
112
|
-
tag?: string;
|
|
113
|
-
alpha?: number;
|
|
114
|
-
tileAlpha?: number;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Visualizes a specific terrain area in a viewer.
|
|
118
|
-
* @param terrain The terrain area to visualize.
|
|
119
|
-
* @param viewer The Cesium viewer.
|
|
120
|
-
* @param options Visualization options.
|
|
121
|
-
* @returns Collection of created entities.
|
|
122
|
-
*/
|
|
123
|
-
function visualize(terrain: TerrainArea | TerrainBounds, viewer: Viewer, options?: Options): Collection<EntityCollection, Entity>;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Copies camera state from source viewer to destination viewer.
|
|
128
|
-
* @param source The source viewer to copy camera states from.
|
|
129
|
-
* @param dest The destination viewer to apply camera properties from the source.
|
|
130
|
-
*/
|
|
131
|
-
declare function syncCamera(source: Viewer, dest: Viewer): void;
|
|
13
|
+
declare function isGetterOnly(o: object, k: string | number | symbol): boolean;
|
|
132
14
|
|
|
133
|
-
export {
|
|
15
|
+
export { isGetterOnly };
|
package/dist/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a
|
|
1
|
+
import{a,b}from"../chunk-HC6YX7RQ.js";import{a as c}from"../chunk-YZ7AUGIO.js";export{a as TerrainVisualizer,b as isGetterOnly,c as syncCamera};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juun-roh/cesium-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Utilities to handle Cesium classes easier.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Cesium",
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"@eslint/js": "^9.24.0",
|
|
77
77
|
"@typescript-eslint/eslint-plugin": "^8.30.1",
|
|
78
78
|
"@typescript-eslint/parser": "^8.30.1",
|
|
79
|
+
"@vitest/coverage-v8": "3.1.1",
|
|
79
80
|
"cesium": "^1.128.0",
|
|
80
81
|
"eslint": "^9.24.0",
|
|
81
82
|
"eslint-plugin-jsdoc": "^50.6.9",
|
|
@@ -88,7 +89,8 @@
|
|
|
88
89
|
"typedoc": "^0.28.2",
|
|
89
90
|
"typedoc-material-theme": "^1.4.0",
|
|
90
91
|
"typescript": "^5.8.3",
|
|
91
|
-
"vite": "^6.2.6"
|
|
92
|
+
"vite": "^6.2.6",
|
|
93
|
+
"vitest": "^3.1.1"
|
|
92
94
|
},
|
|
93
95
|
"scripts": {
|
|
94
96
|
"build": "tsup",
|
|
@@ -97,7 +99,8 @@
|
|
|
97
99
|
"lint": "eslint .",
|
|
98
100
|
"ci:publish": "pnpm build && pnpm publish --no-git-checks",
|
|
99
101
|
"prebuild": "pnpm clean",
|
|
100
|
-
"test": "
|
|
102
|
+
"test": "vitest run",
|
|
103
|
+
"test:watch": "vitest watch --coverage",
|
|
101
104
|
"dev": "pnpm build && vite"
|
|
102
105
|
}
|
|
103
106
|
}
|
package/dist/chunk-4XCQZPKH.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 i=this._eventListeners.get(t);if(i){let a={type:t,...e};i.forEach(s=>s(a))}}_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],i=this._tagMap.get(e);i&&(i.delete(t),i.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,i){return Array.isArray(t)?t.forEach(a=>{this.add(a)}):(Object.defineProperty(t,n.symbol,{value:e,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(t,i),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 i=this.getByTag(t);for(let a of i)this._removeFromTagMap(a),Object.defineProperty(a,n.symbol,e),this._addToTagMap(a,e);return i.length>0&&this._emit("update",{items:i,tag:e}),i.length}removeByTag(t){let e=0;return Array.isArray(t)?t.forEach(i=>{this.removeByTag(i)}):this.getByTag(t).forEach(i=>{this.remove(i)&&e++}),e}show(t){let e=this.getByTag(t),i=0;for(let a of e)r(a.show)&&(a.show=!0,i++);return i}hide(t){let e=this.getByTag(t),i=0;for(let a of e)r(a.show)&&(a.show=!1,i++);return i}toggle(t){let e=this.getByTag(t),i=0;for(let a of e)r(a.show)&&(a.show=!a.show,i++);return i}setProperty(t,e,i){let a=this.getByTag(t),s=0;for(let o of a)e in o?(o[e]=i,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((a,s)=>t(a,s))}},c=l;export{c as a};
|
package/dist/chunk-H3FSQZZE.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as w}from"./chunk-4XCQZPKH.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};
|