@juun-roh/cesium-utils 0.0.14 → 0.0.15
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-XTUDPAWI.js +1 -0
- package/dist/collection/index.cjs +1 -1
- package/dist/collection/index.d.cts +74 -11
- package/dist/collection/index.d.ts +74 -11
- package/dist/collection/index.js +1 -1
- package/dist/{hybrid-terrain-provider-CEJA1Xhw.d.cts → hybrid-terrain-provider-C4b9z5pv.d.cts} +7 -9
- package/dist/{hybrid-terrain-provider-CEJA1Xhw.d.ts → hybrid-terrain-provider-C4b9z5pv.d.ts} +7 -9
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/terrain/index.d.cts +2 -2
- package/dist/terrain/index.d.ts +2 -2
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.d.cts +8 -1
- package/dist/utils/index.d.ts +8 -1
- package/dist/utils/index.js +1 -1
- package/package.json +11 -11
- package/dist/chunk-Q4LRNVAX.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Color as a,Entity as A,HeightReference as M,Rectangle as w,TileCoordinatesImageryProvider as O}from"cesium";import{defined as y,EntityCollection as L}from"cesium";var T=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(o=>o(r))}}_addToTagMap(e,t){this._tagMap.has(t)||this._tagMap.set(t,new Set),this._tagMap.get(t)?.add(e)}_removeFromTagMap(e){let t=e[n.symbol],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache(){this._valuesCache=null}addEventListener(e,t){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(t),this}removeEventListener(e,t){return this._eventListeners.get(e)?.delete(t),this}add(e,t=this.tag,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),this._addToTagMap(e,t),this._invalidateCache(),this._emit("add",{items:[e],tag:t})),e}contains(e){if(typeof e=="object")return this.collection.contains(e);let t=this._tagMap.get(e);return!!t&&t.size>0}remove(e){if(typeof e=="object"&&!Array.isArray(e)){let r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let o of e)this.remove(o)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof L)return this.collection.values;{let e=[];for(let t=0;t<this.collection.length;t++)e.push(this.collection.get(t));return e}}get length(){return this.values?.length||0}get(e){let t=this._tagMap.get(e);return t?Array.from(t):[]}first(e){let t=this._tagMap.get(e);if(t&&t.size>0)return t.values().next().value}get tags(){return Array.from(this._tagMap.keys())}update(e,t){let i=this.get(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}show(e){let t=this.get(e);for(let i of t)y(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)y(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)y(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let o of r)if(e in o&&typeof o[e]!="function"){if(_(o,e))throw Error(`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((r,o)=>e(r,o))}map(e,t){return(t?this.get(t):this.values).map(e)}find(e,t){return(t?this.get(t):this.values).find(e)}},b=T;var u=class n{_viewer;_collection;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",a.RED],["default",a.BLUE],["fallback",a.GRAY],["grid",a.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new b({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),t.tile!==void 0&&(this._visible=t.tile),t.activeLevel!==void 0&&(this._level=t.activeLevel),t.terrainProvider&&this.setTerrainProvider(t.terrainProvider))}setTerrainProvider(e){this._terrainProvider=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.remove(this._collection.tags)}show(e=15){if(!this._terrainProvider)return;this._collection.remove(n.tag.grid),this._level=e,this._ensureTileCoordinatesLayer();let t=this._getVisibleRectangle();if(!t||!this._isValidRectangle(t)){console.warn("Invalid visible rectangle detected, skipping grid display");return}this._displayTileGrid(t,e),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new O({tilingScheme:this._terrainProvider.tilingScheme,color:a.YELLOW})))}_isValidRectangle(e){return e&&Number.isFinite(e.west)&&Number.isFinite(e.south)&&Number.isFinite(e.east)&&Number.isFinite(e.north)&&e.west<=e.east&&e.south<=e.north}_displayTileGrid(e,t){let i=this._terrainProvider.tilingScheme;try{let r=this._calculateTileBounds(e,t,i);this._generateVisibleTiles(r,t,i).forEach(s=>{this._collection.add(s.entity,n.tag.grid)})}catch(r){console.error("Error displaying tile grid:",r)}}_calculateTileBounds(e,t,i){let r=i.positionToTileXY(w.northwest(e),t),o=i.positionToTileXY(w.southeast(e),t);if(!r||!o)throw new Error("Failed to calculate tile bounds");return{start:r,end:o}}_generateVisibleTiles(e,t,i){let r=[],s=Math.min(e.end.x-e.start.x+1,100),l=Math.min(e.end.y-e.start.y+1,100);for(let c=e.start.x;c<e.start.x+s;c++)for(let h=e.start.y;h<e.start.y+l;h++)try{let d=this._createTileEntity(c,h,t,i);d&&r.push({entity:d})}catch(d){console.warn(`Error creating tile (${c}, ${h}, ${t}):`,d)}return r}_createTileEntity(e,t,i,r){let o=r.tileXYToRectangle(e,t,i);if(!this._isValidRectangle(o))return null;let s=this._getTileColor(e,t,i),l=n.createRectangle(o,s.withAlpha(.3));return l.properties?.addProperty("tileX",e),l.properties?.addProperty("tileY",t),l.properties?.addProperty("tileLevel",i),l}_getTileColor(e,t,i){if(!this._terrainProvider)return this._colors.get("fallback")||a.TRANSPARENT;for(let r of this._terrainProvider.terrainAreas)if(r.contains(e,t,i))return r.isCustom?this._colors.get("custom")||a.RED:this._colors.get("default")||a.BLUE;return this._terrainProvider.getTileDataAvailable(e,t,i)?this._colors.get("default")||a.BLUE:this._colors.get("fallback")||a.GRAY}hide(){this._collection.remove(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}get colors(){return this._colors}get terrainProvider(){return this._terrainProvider}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,o){return new A({rectangle:{coordinates:r,material:o,heightReference:M.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,o,s){let l=s?.tag||"terrain_area_visualization",c=s?.color||a.RED,h=s?.maxTilesToShow||100,d=s?.show??!0,C=s?.alpha||.7,E=s?.tileAlpha||.2,m=new b({collection:o.entities,tag:l}),{rectangle:I}=r;if(m.add(i.createRectangle(I,c.withAlpha(C)),l),d&&r.tileRanges.size>0){let{tilingScheme:R}=r.terrainProvider,v=0;r.tileRanges.forEach((g,P)=>{for(let f=g.start.x;f<=g.end.x&&v<h;f++)for(let p=g.start.y;p<=g.end.y&&v<h;p++){let x=R.tileXYToRectangle(f,p,P);m.add(e(x,c.withAlpha(E)),`${l}_tile`),v++}})}return m}i.visualize=t})(u||={});function _(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}export{u as a,_ as b,b as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var _=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var O=(n,e)=>{for(var t in e)_(n,t,{get:e[t],enumerable:!0})},S=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of A(e))!M.call(n,r)&&r!==t&&_(n,r,{get:()=>e[r],enumerable:!(i=L(e,r))||i.enumerable});return n};var V=n=>S(_({},"__esModule",{value:!0}),n);var j={};O(j,{Collection:()=>g});module.exports=V(j);var u=require("cesium");var s=require("cesium");var m=class n{_viewer;_collection;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",s.Color.RED],["default",s.Color.BLUE],["fallback",s.Color.GRAY],["grid",s.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new g({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),t.tile!==void 0&&(this._visible=t.tile),t.activeLevel!==void 0&&(this._level=t.activeLevel),t.terrainProvider&&this.setTerrainProvider(t.terrainProvider))}setTerrainProvider(e){this._terrainProvider=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.remove(this._collection.tags)}show(e=15){if(!this._terrainProvider)return;this._collection.remove(n.tag.grid),this._level=e,this._ensureTileCoordinatesLayer();let t=this._getVisibleRectangle();if(!t||!this._isValidRectangle(t)){console.warn("Invalid visible rectangle detected, skipping grid display");return}this._displayTileGrid(t,e),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new s.TileCoordinatesImageryProvider({tilingScheme:this._terrainProvider.tilingScheme,color:s.Color.YELLOW})))}_isValidRectangle(e){return e&&Number.isFinite(e.west)&&Number.isFinite(e.south)&&Number.isFinite(e.east)&&Number.isFinite(e.north)&&e.west<=e.east&&e.south<=e.north}_displayTileGrid(e,t){let i=this._terrainProvider.tilingScheme;try{let r=this._calculateTileBounds(e,t,i);this._generateVisibleTiles(r,t,i).forEach(a=>{this._collection.add(a.entity,n.tag.grid)})}catch(r){console.error("Error displaying tile grid:",r)}}_calculateTileBounds(e,t,i){let r=i.positionToTileXY(s.Rectangle.northwest(e),t),o=i.positionToTileXY(s.Rectangle.southeast(e),t);if(!r||!o)throw new Error("Failed to calculate tile bounds");return{start:r,end:o}}_generateVisibleTiles(e,t,i){let r=[],a=Math.min(e.end.x-e.start.x+1,100),l=Math.min(e.end.y-e.start.y+1,100);for(let c=e.start.x;c<e.start.x+a;c++)for(let h=e.start.y;h<e.start.y+l;h++)try{let d=this._createTileEntity(c,h,t,i);d&&r.push({entity:d})}catch(d){console.warn(`Error creating tile (${c}, ${h}, ${t}):`,d)}return r}_createTileEntity(e,t,i,r){let o=r.tileXYToRectangle(e,t,i);if(!this._isValidRectangle(o))return null;let a=this._getTileColor(e,t,i),l=n.createRectangle(o,a.withAlpha(.3));return l.properties?.addProperty("tileX",e),l.properties?.addProperty("tileY",t),l.properties?.addProperty("tileLevel",i),l}_getTileColor(e,t,i){if(!this._terrainProvider)return this._colors.get("fallback")||s.Color.TRANSPARENT;for(let r of this._terrainProvider.terrainAreas)if(r.contains(e,t,i))return r.isCustom?this._colors.get("custom")||s.Color.RED:this._colors.get("default")||s.Color.BLUE;return this._terrainProvider.getTileDataAvailable(e,t,i)?this._colors.get("default")||s.Color.BLUE:this._colors.get("fallback")||s.Color.GRAY}hide(){this._collection.remove(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}get colors(){return this._colors}get terrainProvider(){return this._terrainProvider}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,o){return new s.Entity({rectangle:{coordinates:r,material:o,heightReference:s.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,o,a){let l=a?.tag||"terrain_area_visualization",c=a?.color||s.Color.RED,h=a?.maxTilesToShow||100,d=a?.show??!0,w=a?.alpha||.7,E=a?.tileAlpha||.2,f=new g({collection:o.entities,tag:l}),{rectangle:I}=r;if(f.add(i.createRectangle(I,c.withAlpha(w)),l),d&&r.tileRanges.size>0){let{tilingScheme:R}=r.terrainProvider,p=0;r.tileRanges.forEach((v,P)=>{for(let y=v.start.x;y<=v.end.x&&p<h;y++)for(let T=v.start.y;T<=v.end.y&&p<h;T++){let x=R.tileXYToRectangle(y,T,P);f.add(e(x,c.withAlpha(E)),`${l}_tile`),p++}})}return f}i.visualize=t})(m||={});function b(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}var C=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(o=>o(r))}}_addToTagMap(e,t){this._tagMap.has(t)||this._tagMap.set(t,new Set),this._tagMap.get(t)?.add(e)}_removeFromTagMap(e){let t=e[n.symbol],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache(){this._valuesCache=null}addEventListener(e,t){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(t),this}removeEventListener(e,t){return this._eventListeners.get(e)?.delete(t),this}add(e,t=this.tag,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),this._addToTagMap(e,t),this._invalidateCache(),this._emit("add",{items:[e],tag:t})),e}contains(e){if(typeof e=="object")return this.collection.contains(e);let t=this._tagMap.get(e);return!!t&&t.size>0}remove(e){if(typeof e=="object"&&!Array.isArray(e)){let r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let o of e)this.remove(o)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof u.EntityCollection)return this.collection.values;{let e=[];for(let t=0;t<this.collection.length;t++)e.push(this.collection.get(t));return e}}get length(){return this.values?.length||0}get(e){let t=this._tagMap.get(e);return t?Array.from(t):[]}first(e){let t=this._tagMap.get(e);if(t&&t.size>0)return t.values().next().value}get tags(){return Array.from(this._tagMap.keys())}update(e,t){let i=this.get(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}show(e){let t=this.get(e);for(let i of t)(0,u.defined)(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)(0,u.defined)(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)(0,u.defined)(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let o of r)if(e in o&&typeof o[e]!="function"){if(b(o,e))throw Error(`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((r,o)=>e(r,o))}map(e,t){return(t?this.get(t):this.values).map(e)}find(e,t){return(t?this.get(t):this.values).find(e)}},g=C;
|
|
@@ -33,23 +33,86 @@ type NonFunction<T> = {
|
|
|
33
33
|
* @template I - The type of items in the collection (e.g., Entity, Primitive)
|
|
34
34
|
*
|
|
35
35
|
* @example
|
|
36
|
-
* //
|
|
37
|
-
* class
|
|
38
|
-
*
|
|
39
|
-
*
|
|
36
|
+
* // Example 1: Managing Complex Scene with Multiple Object Types
|
|
37
|
+
* class SceneOrganizer {
|
|
38
|
+
* private entities: Collection<EntityCollection, Entity>;
|
|
39
|
+
* private billboards: Collection<BillboardCollection, Billboard>;
|
|
40
|
+
* private primitives: Collection<PrimitiveCollection, Primitive>;
|
|
41
|
+
*
|
|
42
|
+
* constructor(viewer: Viewer) {
|
|
43
|
+
* this.entities = new Collection({ collection: viewer.entities });
|
|
44
|
+
* this.billboards = new Collection({
|
|
45
|
+
* collection: viewer.scene.primitives.add(new BillboardCollection())
|
|
46
|
+
* });
|
|
47
|
+
* this.primitives = new Collection({
|
|
48
|
+
* collection: viewer.scene.primitives
|
|
49
|
+
* });
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* // Unified API across different collection types!
|
|
53
|
+
* showLayer(layerName: string) {
|
|
54
|
+
* this.entities.show(layerName);
|
|
55
|
+
* this.billboards.show(layerName);
|
|
56
|
+
* this.primitives.show(layerName);
|
|
40
57
|
* }
|
|
41
58
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
59
|
+
* hideLayer(layerName: string) {
|
|
60
|
+
* this.entities.hide(layerName);
|
|
61
|
+
* this.billboards.hide(layerName);
|
|
62
|
+
* this.primitives.hide(layerName);
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* removeLayer(layerName: string) {
|
|
66
|
+
* this.entities.remove(layerName);
|
|
67
|
+
* this.billboards.remove(layerName);
|
|
68
|
+
* this.primitives.remove(layerName);
|
|
44
69
|
* }
|
|
45
70
|
* }
|
|
46
71
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
72
|
+
* // Example 2: Extend the class for Domain-Specific Needs
|
|
73
|
+
* class BuildingCollection extends Collection<EntityCollection, Entity> {
|
|
74
|
+
* constructor(viewer: Viewer) {
|
|
75
|
+
* super({ collection: viewer.entities, tag: 'buildings' });
|
|
76
|
+
* }
|
|
77
|
+
*
|
|
78
|
+
* addBuilding(options: {
|
|
79
|
+
* position: Cartesian3;
|
|
80
|
+
* height: number;
|
|
81
|
+
* floors: number;
|
|
82
|
+
* type: 'residential' | 'commercial' | 'industrial';
|
|
83
|
+
* }): Entity {
|
|
84
|
+
* const building = new Entity({
|
|
85
|
+
* position: options.position,
|
|
86
|
+
* box: {
|
|
87
|
+
* dimensions: new Cartesian3(50, 50, options.height),
|
|
88
|
+
* material: this.getMaterialForType(options.type)
|
|
89
|
+
* }
|
|
90
|
+
* });
|
|
50
91
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
92
|
+
* // Tag by type AND by floor count
|
|
93
|
+
* this.add(building, options.type);
|
|
94
|
+
* this.add(building, `floors-${options.floors}`);
|
|
95
|
+
*
|
|
96
|
+
* return building;
|
|
97
|
+
* }
|
|
98
|
+
*
|
|
99
|
+
* getByFloorRange(min: number, max: number): Entity[] {
|
|
100
|
+
* const results: Entity[] = [];
|
|
101
|
+
* for (let i = min; i <= max; i++) {
|
|
102
|
+
* results.push(...this.get(`floors-${i}`));
|
|
103
|
+
* }
|
|
104
|
+
* return results;
|
|
105
|
+
* }
|
|
106
|
+
*
|
|
107
|
+
* private getMaterialForType(type: string): Material {
|
|
108
|
+
* const colors = {
|
|
109
|
+
* residential: Color.GREEN,
|
|
110
|
+
* commercial: Color.BLUE,
|
|
111
|
+
* industrial: Color.YELLOW
|
|
112
|
+
* };
|
|
113
|
+
* return new ColorMaterialProperty(colors[type] || Color.WHITE);
|
|
114
|
+
* }
|
|
115
|
+
* }
|
|
53
116
|
*/
|
|
54
117
|
declare class Collection<C extends CesiumCollection, I extends CesiumCollectionItem> {
|
|
55
118
|
/**
|
|
@@ -33,23 +33,86 @@ type NonFunction<T> = {
|
|
|
33
33
|
* @template I - The type of items in the collection (e.g., Entity, Primitive)
|
|
34
34
|
*
|
|
35
35
|
* @example
|
|
36
|
-
* //
|
|
37
|
-
* class
|
|
38
|
-
*
|
|
39
|
-
*
|
|
36
|
+
* // Example 1: Managing Complex Scene with Multiple Object Types
|
|
37
|
+
* class SceneOrganizer {
|
|
38
|
+
* private entities: Collection<EntityCollection, Entity>;
|
|
39
|
+
* private billboards: Collection<BillboardCollection, Billboard>;
|
|
40
|
+
* private primitives: Collection<PrimitiveCollection, Primitive>;
|
|
41
|
+
*
|
|
42
|
+
* constructor(viewer: Viewer) {
|
|
43
|
+
* this.entities = new Collection({ collection: viewer.entities });
|
|
44
|
+
* this.billboards = new Collection({
|
|
45
|
+
* collection: viewer.scene.primitives.add(new BillboardCollection())
|
|
46
|
+
* });
|
|
47
|
+
* this.primitives = new Collection({
|
|
48
|
+
* collection: viewer.scene.primitives
|
|
49
|
+
* });
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* // Unified API across different collection types!
|
|
53
|
+
* showLayer(layerName: string) {
|
|
54
|
+
* this.entities.show(layerName);
|
|
55
|
+
* this.billboards.show(layerName);
|
|
56
|
+
* this.primitives.show(layerName);
|
|
40
57
|
* }
|
|
41
58
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
59
|
+
* hideLayer(layerName: string) {
|
|
60
|
+
* this.entities.hide(layerName);
|
|
61
|
+
* this.billboards.hide(layerName);
|
|
62
|
+
* this.primitives.hide(layerName);
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* removeLayer(layerName: string) {
|
|
66
|
+
* this.entities.remove(layerName);
|
|
67
|
+
* this.billboards.remove(layerName);
|
|
68
|
+
* this.primitives.remove(layerName);
|
|
44
69
|
* }
|
|
45
70
|
* }
|
|
46
71
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
72
|
+
* // Example 2: Extend the class for Domain-Specific Needs
|
|
73
|
+
* class BuildingCollection extends Collection<EntityCollection, Entity> {
|
|
74
|
+
* constructor(viewer: Viewer) {
|
|
75
|
+
* super({ collection: viewer.entities, tag: 'buildings' });
|
|
76
|
+
* }
|
|
77
|
+
*
|
|
78
|
+
* addBuilding(options: {
|
|
79
|
+
* position: Cartesian3;
|
|
80
|
+
* height: number;
|
|
81
|
+
* floors: number;
|
|
82
|
+
* type: 'residential' | 'commercial' | 'industrial';
|
|
83
|
+
* }): Entity {
|
|
84
|
+
* const building = new Entity({
|
|
85
|
+
* position: options.position,
|
|
86
|
+
* box: {
|
|
87
|
+
* dimensions: new Cartesian3(50, 50, options.height),
|
|
88
|
+
* material: this.getMaterialForType(options.type)
|
|
89
|
+
* }
|
|
90
|
+
* });
|
|
50
91
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
92
|
+
* // Tag by type AND by floor count
|
|
93
|
+
* this.add(building, options.type);
|
|
94
|
+
* this.add(building, `floors-${options.floors}`);
|
|
95
|
+
*
|
|
96
|
+
* return building;
|
|
97
|
+
* }
|
|
98
|
+
*
|
|
99
|
+
* getByFloorRange(min: number, max: number): Entity[] {
|
|
100
|
+
* const results: Entity[] = [];
|
|
101
|
+
* for (let i = min; i <= max; i++) {
|
|
102
|
+
* results.push(...this.get(`floors-${i}`));
|
|
103
|
+
* }
|
|
104
|
+
* return results;
|
|
105
|
+
* }
|
|
106
|
+
*
|
|
107
|
+
* private getMaterialForType(type: string): Material {
|
|
108
|
+
* const colors = {
|
|
109
|
+
* residential: Color.GREEN,
|
|
110
|
+
* commercial: Color.BLUE,
|
|
111
|
+
* industrial: Color.YELLOW
|
|
112
|
+
* };
|
|
113
|
+
* return new ColorMaterialProperty(colors[type] || Color.WHITE);
|
|
114
|
+
* }
|
|
115
|
+
* }
|
|
53
116
|
*/
|
|
54
117
|
declare class Collection<C extends CesiumCollection, I extends CesiumCollectionItem> {
|
|
55
118
|
/**
|
package/dist/collection/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as o}from"../chunk-
|
|
1
|
+
import{c as o}from"../chunk-XTUDPAWI.js";export{o as Collection};
|
package/dist/{hybrid-terrain-provider-CEJA1Xhw.d.cts → hybrid-terrain-provider-C4b9z5pv.d.cts}
RENAMED
|
@@ -116,17 +116,15 @@ declare namespace TerrainArea {
|
|
|
116
116
|
*
|
|
117
117
|
* @example
|
|
118
118
|
* ``` typescript
|
|
119
|
+
* // Set up tile ranges
|
|
119
120
|
* const tileRanges = new Map<number, TileRange>;
|
|
120
121
|
* tileRanges.set(15, { start: { x: 55852, y: 9556 }, end: { x: 55871, y: 9575 } });
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* ],
|
|
128
|
-
* terrainProvider: 'default-terrain-url',
|
|
129
|
-
* fallbackProvider: new EllipsoidTerrainProvider(),
|
|
122
|
+
* // Set up tile areas
|
|
123
|
+
* const area = new TerrainArea({ terrainProvider: provider, tileRanges });
|
|
124
|
+
*
|
|
125
|
+
* const hybridTerrain = new HybridTerrainProvider({
|
|
126
|
+
* terrainAreas: [area],
|
|
127
|
+
* terrainProvider: new EllipsoidTerrainProvider(),
|
|
130
128
|
* });
|
|
131
129
|
*
|
|
132
130
|
* viewer.terrainProvider = hybridTerrain;
|
package/dist/{hybrid-terrain-provider-CEJA1Xhw.d.ts → hybrid-terrain-provider-C4b9z5pv.d.ts}
RENAMED
|
@@ -116,17 +116,15 @@ declare namespace TerrainArea {
|
|
|
116
116
|
*
|
|
117
117
|
* @example
|
|
118
118
|
* ``` typescript
|
|
119
|
+
* // Set up tile ranges
|
|
119
120
|
* const tileRanges = new Map<number, TileRange>;
|
|
120
121
|
* tileRanges.set(15, { start: { x: 55852, y: 9556 }, end: { x: 55871, y: 9575 } });
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* ],
|
|
128
|
-
* terrainProvider: 'default-terrain-url',
|
|
129
|
-
* fallbackProvider: new EllipsoidTerrainProvider(),
|
|
122
|
+
* // Set up tile areas
|
|
123
|
+
* const area = new TerrainArea({ terrainProvider: provider, tileRanges });
|
|
124
|
+
*
|
|
125
|
+
* const hybridTerrain = new HybridTerrainProvider({
|
|
126
|
+
* terrainAreas: [area],
|
|
127
|
+
* terrainProvider: new EllipsoidTerrainProvider(),
|
|
130
128
|
* });
|
|
131
129
|
*
|
|
132
130
|
* viewer.terrainProvider = hybridTerrain;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var M=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var W=(n,e)=>{for(var t in e)M(n,t,{get:e[t],enumerable:!0})},q=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Y(e))!B.call(n,i)&&i!==t&&M(n,i,{get:()=>e[i],enumerable:!(r=F(e,i))||r.enumerable});return n};var $=n=>q(M({},"__esModule",{value:!0}),n);var U={};W(U,{Collection:()=>b,Highlight:()=>w,HybridTerrainProvider:()=>E,TerrainArea:()=>g,TerrainAreaCollection:()=>v,TerrainVisualizer:()=>p,cloneViewer:()=>k,computeRectangle:()=>R,isGetterOnly:()=>C,syncCamera:()=>P});module.exports=$(U);var _=require("cesium");var d=require("cesium");var p=class n{_viewer;_collection;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",d.Color.RED],["default",d.Color.BLUE],["fallback",d.Color.GRAY],["grid",d.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new b({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([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._terrainProvider=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.remove(this._collection.tags)}show(e=15){if(!this._terrainProvider)return;this._collection.remove(n.tag.grid),this._level=e;let t=this._terrainProvider.tilingScheme;this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new d.TileCoordinatesImageryProvider({tilingScheme:t,color:d.Color.YELLOW})));let r=(a,l,c)=>{if(this._terrainProvider){for(let h of this._terrainProvider.terrainAreas)if(h.contains(a,l,c))return h.isCustom?this._colors.get("custom")||d.Color.RED:this._colors.get("default")||d.Color.BLUE;if(this._terrainProvider.getTileDataAvailable(a,l,c))return this._colors.get("default")||d.Color.BLUE}return this._colors.get("fallback")||d.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(d.Rectangle.northwest(i),e),l=t.positionToTileXY(d.Rectangle.southeast(i),e);if(!a||!l)return;let c=100,h=Math.min(l.x-a.x+1,c),y=Math.min(l.y-a.y+1,c);for(let u=a.x;u<=a.x+h-1;u++)for(let m=a.y;m<=a.y+y-1;m++)try{let f=t.tileXYToRectangle(u,m,e);if(!o(f)){console.warn(`Invalid rectangle for tile (${u}, ${m}, ${e}), skipping`);continue}let I=r(u,m,e),T=n.createRectangle(f,I.withAlpha(.3));T.properties?.addProperty("tileX",u),T.properties?.addProperty("tileY",m),T.properties?.addProperty("tileLevel",e),this._collection.add(T,n.tag.grid)}catch(f){console.warn(`Error creating tile (${u}, ${m}, ${e}): ${f.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;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}get colors(){return this._colors}get terrainProvider(){return this._terrainProvider}};(r=>{r.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(i,o){return new d.Entity({rectangle:{coordinates:i,material:o,heightReference:d.HeightReference.CLAMP_TO_GROUND}})}r.createRectangle=e;function t(i,o,a){let l=a?.tag||"terrain_area_visualization",c=a?.color||d.Color.RED,h=a?.maxTilesToShow||100,y=a?.show??!0,u=a?.alpha||.7,m=a?.tileAlpha||.2,f=new b({collection:o.entities,tag:l}),{rectangle:I}=i;if(f.add(r.createRectangle(I,c.withAlpha(u)),l),y&&i.tileRanges.size>0){let{tilingScheme:T}=i.terrainProvider,x=0;i.tileRanges.forEach((A,z)=>{for(let V=A.start.x;V<=A.end.x&&x<h;V++)for(let O=A.start.y;O<=A.end.y&&x<h;O++){let j=T.tileXYToRectangle(V,O,z);f.add(e(j,c.withAlpha(m)),`${l}_tile`),x++}})}return f}r.visualize=t})(p||={});function C(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 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 _.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,_.defined)(r.show)&&(r.show=!0);return this}hide(e){let t=this.get(e);for(let r of t)(0,_.defined)(r.show)&&(r.show=!1);return this}toggle(e){let t=this.get(e);for(let r of t)(0,_.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(C(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)}},b=L;var D=require("cesium");var N=require("cesium");var S=require("cesium");function R(n,e){if(e.size===0)return new S.Rectangle;let t=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,a=Array.from(e.keys()),l=Math.min(...a),c=e.get(l);if(c){let{start:h,end:y}=c,u=n.tileXYToRectangle(h.x,h.y,l),m=n.tileXYToRectangle(y.x,y.y,l);t=Math.min(u.west,t),r=Math.min(m.south,r),i=Math.max(m.east,i),o=Math.max(u.north,o)}return new S.Rectangle(t,r,i,o)}var g=class{_terrainProvider;_rectangle;_tileRanges;_ready=!1;_credit;_isCustom;constructor(e){this._terrainProvider=e.terrainProvider,this._tileRanges=e.tileRanges,this._credit=e.credit||"custom",this._isCustom=e.isCustom!==void 0?e.isCustom:!0,this._rectangle=R(e.terrainProvider.tilingScheme,e.tileRanges),e.tileRanges.forEach((t,r)=>{this._terrainProvider.availability?.addAvailableTileRange(r,t.start.x,t.start.y,t.end.x,t.end.y)}),this._ready=!0}contains(e,t,r){if(this._tileRanges.size===0||!this._tileRanges.has(r))return!1;let i=this._tileRanges.get(r);return e>=i.start.x&&e<=i.end.x&&t>=i.start.y&&t<=i.end.y}requestTileGeometry(e,t,r,i){if(!(!this._ready||!this.contains(e,t,r)))return this._terrainProvider.requestTileGeometry(e,t,r,i)}getTileDataAvailable(e,t,r){if(this._tileRanges.size===0||!this._tileRanges.has(r))return!1;let i=this._tileRanges.get(r);return e>=i.start.x&&e<=i.end.x&&t>=i.start.y&&t<=i.end.y}get isCustom(){return this._isCustom}get credit(){return this._credit}get terrainProvider(){return this._terrainProvider}get tileRanges(){return this._tileRanges}get rectangle(){return this._rectangle}get ready(){return this._ready}};(e=>{async function n(t,r,i){let o=i?.credit||"custom",a=await N.CesiumTerrainProvider.fromUrl(t,{...i,credit:o});return new e({terrainProvider:a,tileRanges:r,credit:o})}e.fromUrl=n})(g||={});var v=class extends Array{add(e){if(Array.isArray(e)){for(let r of e)this.add(r);return this.length}let t;return e instanceof g?t=e:t=new g(e),this.push(t)}remove(e){if(Array.isArray(e))return e.forEach(r=>this.remove(r)),this;let t=this.indexOf(e);return t>=0&&this.splice(t,1),this}removeAll(){this.length=0}};var E=class{_terrainAreas=new v;_terrainProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(e){this._terrainProvider=e.terrainProvider,this._fallbackProvider=e.fallbackProvider||new D.EllipsoidTerrainProvider,this._tilingScheme=e.terrainProvider.tilingScheme,this._terrainAreas=new v(...e.terrainAreas),this._availability=e.terrainProvider.availability,this._ready=!0}get ready(){return this._ready}get tilingScheme(){return this._tilingScheme}get availability(){return this._availability}get terrainAreas(){return[...this._terrainAreas]}get defaultProvider(){return this._terrainProvider}get fallbackProvider(){return this._fallbackProvider}get credit(){return this._terrainProvider?.credit}get errorEvent(){return this._terrainProvider.errorEvent}get hasWaterMask(){return this._terrainProvider.hasWaterMask}get hasVertexNormals(){return this._terrainProvider.hasVertexNormals}loadTileDataAvailability(e,t,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){for(let i of this._terrainAreas)if(i.contains(e,t,r))return i.getTileDataAvailable(e,t,r);return this._terrainProvider.getTileDataAvailable(e,t,r)}};var H=require("cesium");var G=require("cesium");function P(n,e){if((0,G.defined)(n)&&(0,G.defined)(e)){let{camera:t}=n;e.camera.position=t.positionWC.clone(),e.camera.direction=t.directionWC.clone(),e.camera.up=t.upWC.clone()}}function k(n,e,t){let 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 H.Viewer(e,{...r,...t});P(n,i);let o=n.imageryLayers;i.imageryLayers.removeAll();for(let c=0;c<o.length;c++){let h=o.get(c);i.imageryLayers.addImageryProvider(h.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 l=n.scene.screenSpaceCameraController.zoomEventTypes;return l&&(i.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(l)?[...l]:l),i}var s=require("cesium"),w=class n{static instances=new Map;_defaultColor=s.Color.YELLOW.withAlpha(.5);_entity;_entities;constructor(e){this._entities=e.entities,this._entity=this._entities.add(new s.Entity({id:`highlight-entity-${Math.random().toString(36).substring(2)}`,show:!1}))}static getInstance(e){let t=e.container;return n.instances.has(t)||n.instances.set(t,new n(e)),n.instances.get(t)}static releaseInstance(e){let t=e.container,r=n.instances.get(t);r&&(r.hide(),r._entity&&e.entities.remove(r._entity),n.instances.delete(t))}show(e,t=this._defaultColor,r=!1){if(!(!(0,s.defined)(e)||!this._entity)){this._clearGeometries();try{if(e instanceof s.Entity)this._update(e,t,r);else if(e.id instanceof s.Entity)this._update(e.id,t,r);else if(e.primitive instanceof s.GroundPrimitive)this._update(e.primitive,t,r);else return;return this._entity.show=!0,this._entity}catch(i){console.error("Failed to highlight object:",i);return}}}_clearGeometries(){this._entity.polygon=void 0,this._entity.polyline=void 0,this._entity.rectangle=void 0}_update(e,t,r){if(e instanceof s.Entity){if(e.polygon)if(r){let i=e.polygon.hierarchy?.getValue();if(i&&i.positions){let o;i.positions.length>0&&!s.Cartesian3.equals(i.positions[0],i.positions[i.positions.length-1])?o=[...i.positions,i.positions[0]]:o=i.positions,this._entity.polyline=new s.PolylineGraphics({positions:o,material:t,width:2,clampToGround:e.polygon.heightReference?.getValue()===s.HeightReference.CLAMP_TO_GROUND})}}else{let i=e.polygon.hierarchy?.getValue();i&&(this._entity.polygon=new s.PolygonGraphics({hierarchy:i,material:t,heightReference:e.polygon.heightReference?.getValue(),classificationType:e.polygon.classificationType?.getValue()||s.ClassificationType.BOTH}))}else if(e.polyline){let i=e.polyline.positions?.getValue();if(i){let o=e.polyline.width?.getValue();this._entity.polyline=new s.PolylineGraphics({positions:i,material:t,width:o+2,clampToGround:e.polyline.clampToGround?.getValue()})}}else if(e.rectangle)if(r){let i=e.rectangle.coordinates?.getValue();if(i){let o=[s.Cartesian3.fromRadians(i.west,i.north),s.Cartesian3.fromRadians(i.east,i.north),s.Cartesian3.fromRadians(i.east,i.south),s.Cartesian3.fromRadians(i.west,i.south),s.Cartesian3.fromRadians(i.west,i.north)];this._entity.polyline=new s.PolylineGraphics({positions:o,material:t,width:2,clampToGround:e.rectangle.heightReference?.getValue()===s.HeightReference.CLAMP_TO_GROUND})}}else{let i=e.rectangle.coordinates?.getValue();i&&(this._entity.rectangle=new s.RectangleGraphics({coordinates:i,material:t,heightReference:e.rectangle.heightReference?.getValue()}))}}else if(e instanceof s.GroundPrimitive){let i=e.geometryInstances,o=Array.isArray(i)?i[0]:i;if(!o.geometry.attributes.position)return;let a=o.geometry.attributes.position.values,l=[];for(let c=0;c<a.length;c+=3)l.push(new s.Cartesian3(a[c],a[c+1],a[c+2]));r?this._entity.polyline=new s.PolylineGraphics({positions:l,material:t,width:2,clampToGround:!0}):this._entity.polygon=new s.PolygonGraphics({hierarchy:new s.PolygonHierarchy(l),material:t,heightReference:s.HeightReference.CLAMP_TO_GROUND,classificationType:s.ClassificationType.BOTH})}}hide(){this._entity&&(this._entity.show=!1)}get defaultColor(){return this._defaultColor}set defaultColor(e){this._defaultColor=e}get entity(){return this._entity}};
|
|
1
|
+
"use strict";var V=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var W=(n,e)=>{for(var t in e)V(n,t,{get:e[t],enumerable:!0})},q=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Y(e))!j.call(n,i)&&i!==t&&V(n,i,{get:()=>e[i],enumerable:!(r=F(e,i))||r.enumerable});return n};var U=n=>q(V({},"__esModule",{value:!0}),n);var X={};W(X,{Collection:()=>v,Highlight:()=>_,HybridTerrainProvider:()=>A,TerrainArea:()=>m,TerrainAreaCollection:()=>f,TerrainVisualizer:()=>g,cloneViewer:()=>S,computeRectangle:()=>w,isGetterOnly:()=>y,syncCamera:()=>T});module.exports=U(X);var p=require("cesium");var d=require("cesium");var g=class n{_viewer;_collection;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",d.Color.RED],["default",d.Color.BLUE],["fallback",d.Color.GRAY],["grid",d.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new v({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._terrainProvider=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.remove(this._collection.tags)}show(e=15){if(!this._terrainProvider)return;this._collection.remove(n.tag.grid),this._level=e,this._ensureTileCoordinatesLayer();let t=this._getVisibleRectangle();if(!t||!this._isValidRectangle(t)){console.warn("Invalid visible rectangle detected, skipping grid display");return}this._displayTileGrid(t,e),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new d.TileCoordinatesImageryProvider({tilingScheme:this._terrainProvider.tilingScheme,color:d.Color.YELLOW})))}_isValidRectangle(e){return e&&Number.isFinite(e.west)&&Number.isFinite(e.south)&&Number.isFinite(e.east)&&Number.isFinite(e.north)&&e.west<=e.east&&e.south<=e.north}_displayTileGrid(e,t){let r=this._terrainProvider.tilingScheme;try{let i=this._calculateTileBounds(e,t,r);this._generateVisibleTiles(i,t,r).forEach(s=>{this._collection.add(s.entity,n.tag.grid)})}catch(i){console.error("Error displaying tile grid:",i)}}_calculateTileBounds(e,t,r){let i=r.positionToTileXY(d.Rectangle.northwest(e),t),a=r.positionToTileXY(d.Rectangle.southeast(e),t);if(!i||!a)throw new Error("Failed to calculate tile bounds");return{start:i,end:a}}_generateVisibleTiles(e,t,r){let i=[],s=Math.min(e.end.x-e.start.x+1,100),l=Math.min(e.end.y-e.start.y+1,100);for(let c=e.start.x;c<e.start.x+s;c++)for(let h=e.start.y;h<e.start.y+l;h++)try{let u=this._createTileEntity(c,h,t,r);u&&i.push({entity:u})}catch(u){console.warn(`Error creating tile (${c}, ${h}, ${t}):`,u)}return i}_createTileEntity(e,t,r,i){let a=i.tileXYToRectangle(e,t,r);if(!this._isValidRectangle(a))return null;let s=this._getTileColor(e,t,r),l=n.createRectangle(a,s.withAlpha(.3));return l.properties?.addProperty("tileX",e),l.properties?.addProperty("tileY",t),l.properties?.addProperty("tileLevel",r),l}_getTileColor(e,t,r){if(!this._terrainProvider)return this._colors.get("fallback")||d.Color.TRANSPARENT;for(let i of this._terrainProvider.terrainAreas)if(i.contains(e,t,r))return i.isCustom?this._colors.get("custom")||d.Color.RED:this._colors.get("default")||d.Color.BLUE;return this._terrainProvider.getTileDataAvailable(e,t,r)?this._colors.get("default")||d.Color.BLUE:this._colors.get("fallback")||d.Color.GRAY}hide(){this._collection.remove(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,r])=>{this._colors.set(t,r)}),this.update()}flyTo(e,t){let{rectangle:r}=e;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}get colors(){return this._colors}get terrainProvider(){return this._terrainProvider}};(r=>{r.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(i,a){return new d.Entity({rectangle:{coordinates:i,material:a,heightReference:d.HeightReference.CLAMP_TO_GROUND}})}r.createRectangle=e;function t(i,a,s){let l=s?.tag||"terrain_area_visualization",c=s?.color||d.Color.RED,h=s?.maxTilesToShow||100,u=s?.show??!0,b=s?.alpha||.7,C=s?.tileAlpha||.2,R=new v({collection:a.entities,tag:l}),{rectangle:D}=i;if(R.add(r.createRectangle(D,c.withAlpha(b)),l),u&&i.tileRanges.size>0){let{tilingScheme:H}=i.terrainProvider,E=0;i.tileRanges.forEach((P,z)=>{for(let I=P.start.x;I<=P.end.x&&E<h;I++)for(let x=P.start.y;x<=P.end.y&&E<h;x++){let B=H.tileXYToRectangle(I,x,z);R.add(e(B,c.withAlpha(C)),`${l}_tile`),E++}})}return R}r.visualize=t})(g||={});function y(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=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(a=>a(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 a of e)this.remove(a)&&(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 p.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,p.defined)(r.show)&&(r.show=!0);return this}hide(e){let t=this.get(e);for(let r of t)(0,p.defined)(r.show)&&(r.show=!1);return this}toggle(e){let t=this.get(e);for(let r of t)(0,p.defined)(r.show)&&(r.show=!r.show);return this}setProperty(e,t,r=this.tag){let i=this.get(r);for(let a of i)if(e in a&&typeof a[e]!="function"){if(y(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((i,a)=>e(i,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)}},v=O;var k=require("cesium");var G=require("cesium");var L=require("cesium");function w(n,e){if(e.size===0)return new L.Rectangle;let t=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY,s=Array.from(e.keys()),l=Math.min(...s),c=e.get(l);if(c){let{start:h,end:u}=c,b=n.tileXYToRectangle(h.x,h.y,l),C=n.tileXYToRectangle(u.x,u.y,l);t=Math.min(b.west,t),r=Math.min(C.south,r),i=Math.max(C.east,i),a=Math.max(b.north,a)}return new L.Rectangle(t,r,i,a)}var m=class{_terrainProvider;_rectangle;_tileRanges;_ready=!1;_credit;_isCustom;constructor(e){this._terrainProvider=e.terrainProvider,this._tileRanges=e.tileRanges,this._credit=e.credit||"custom",this._isCustom=e.isCustom!==void 0?e.isCustom:!0,this._rectangle=w(e.terrainProvider.tilingScheme,e.tileRanges),e.tileRanges.forEach((t,r)=>{this._terrainProvider.availability?.addAvailableTileRange(r,t.start.x,t.start.y,t.end.x,t.end.y)}),this._ready=!0}contains(e,t,r){if(this._tileRanges.size===0||!this._tileRanges.has(r))return!1;let i=this._tileRanges.get(r);return e>=i.start.x&&e<=i.end.x&&t>=i.start.y&&t<=i.end.y}requestTileGeometry(e,t,r,i){if(!(!this._ready||!this.contains(e,t,r)))return this._terrainProvider.requestTileGeometry(e,t,r,i)}getTileDataAvailable(e,t,r){if(this._tileRanges.size===0||!this._tileRanges.has(r))return!1;let i=this._tileRanges.get(r);return e>=i.start.x&&e<=i.end.x&&t>=i.start.y&&t<=i.end.y}get isCustom(){return this._isCustom}get credit(){return this._credit}get terrainProvider(){return this._terrainProvider}get tileRanges(){return this._tileRanges}get rectangle(){return this._rectangle}get ready(){return this._ready}};(e=>{async function n(t,r,i){let a=i?.credit||"custom",s=await G.CesiumTerrainProvider.fromUrl(t,{...i,credit:a});return new e({terrainProvider:s,tileRanges:r,credit:a})}e.fromUrl=n})(m||={});var f=class extends Array{add(e){if(Array.isArray(e)){for(let r of e)this.add(r);return this.length}let t;return e instanceof m?t=e:t=new m(e),this.push(t)}remove(e){if(Array.isArray(e))return e.forEach(r=>this.remove(r)),this;let t=this.indexOf(e);return t>=0&&this.splice(t,1),this}removeAll(){this.length=0}};var A=class{_terrainAreas=new f;_terrainProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(e){this._terrainProvider=e.terrainProvider,this._fallbackProvider=e.fallbackProvider||new k.EllipsoidTerrainProvider,this._tilingScheme=e.terrainProvider.tilingScheme,this._terrainAreas=new f(...e.terrainAreas),this._availability=e.terrainProvider.availability,this._ready=!0}get ready(){return this._ready}get tilingScheme(){return this._tilingScheme}get availability(){return this._availability}get terrainAreas(){return[...this._terrainAreas]}get defaultProvider(){return this._terrainProvider}get fallbackProvider(){return this._fallbackProvider}get credit(){return this._terrainProvider?.credit}get errorEvent(){return this._terrainProvider.errorEvent}get hasWaterMask(){return this._terrainProvider.hasWaterMask}get hasVertexNormals(){return this._terrainProvider.hasVertexNormals}loadTileDataAvailability(e,t,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 a of this._terrainAreas)if(a.contains(e,t,r))return a.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){for(let i of this._terrainAreas)if(i.contains(e,t,r))return i.getTileDataAvailable(e,t,r);return this._terrainProvider.getTileDataAvailable(e,t,r)}};var N=require("cesium");var M=require("cesium");function T(n,e){if((0,M.defined)(n)&&(0,M.defined)(e)){let{camera:t}=n;e.camera.position=t.positionWC.clone(),e.camera.direction=t.directionWC.clone(),e.camera.up=t.upWC.clone()}}function S(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 N.Viewer(e,{...r,...t});T(n,i);let a=n.imageryLayers;i.imageryLayers.removeAll();for(let c=0;c<a.length;c++){let h=a.get(c);i.imageryLayers.addImageryProvider(h.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 s=n.scene.screenSpaceCameraController.tiltEventTypes;s&&(i.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(s)?[...s]:s);let l=n.scene.screenSpaceCameraController.zoomEventTypes;return l&&(i.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(l)?[...l]:l),i}var o=require("cesium"),_=class n{static instances=new Map;_defaultColor=o.Color.YELLOW.withAlpha(.5);_entity;_entities;constructor(e){this._entities=e.entities,this._entity=this._entities.add(new o.Entity({id:`highlight-entity-${Math.random().toString(36).substring(2)}`,show:!1}))}static getInstance(e){let t=e.container;return n.instances.has(t)||n.instances.set(t,new n(e)),n.instances.get(t)}static releaseInstance(e){let t=e.container,r=n.instances.get(t);r&&(r.hide(),r._entity&&e.entities.remove(r._entity),n.instances.delete(t))}show(e,t=this._defaultColor,r=!1){if(!(!(0,o.defined)(e)||!this._entity)){this._clearGeometries();try{if(e instanceof o.Entity)this._update(e,t,r);else if(e.id instanceof o.Entity)this._update(e.id,t,r);else if(e.primitive instanceof o.GroundPrimitive)this._update(e.primitive,t,r);else return;return this._entity.show=!0,this._entity}catch(i){console.error("Failed to highlight object:",i);return}}}_clearGeometries(){this._entity.polygon=void 0,this._entity.polyline=void 0,this._entity.rectangle=void 0}_update(e,t,r){if(e instanceof o.Entity){if(e.polygon)if(r){let i=e.polygon.hierarchy?.getValue();if(i&&i.positions){let a;i.positions.length>0&&!o.Cartesian3.equals(i.positions[0],i.positions[i.positions.length-1])?a=[...i.positions,i.positions[0]]:a=i.positions,this._entity.polyline=new o.PolylineGraphics({positions:a,material:t,width:2,clampToGround:e.polygon.heightReference?.getValue()===o.HeightReference.CLAMP_TO_GROUND})}}else{let i=e.polygon.hierarchy?.getValue();i&&(this._entity.polygon=new o.PolygonGraphics({hierarchy:i,material:t,heightReference:e.polygon.heightReference?.getValue(),classificationType:e.polygon.classificationType?.getValue()||o.ClassificationType.BOTH}))}else if(e.polyline){let i=e.polyline.positions?.getValue();if(i){let a=e.polyline.width?.getValue();this._entity.polyline=new o.PolylineGraphics({positions:i,material:t,width:a+2,clampToGround:e.polyline.clampToGround?.getValue()})}}else if(e.rectangle)if(r){let i=e.rectangle.coordinates?.getValue();if(i){let a=[o.Cartesian3.fromRadians(i.west,i.north),o.Cartesian3.fromRadians(i.east,i.north),o.Cartesian3.fromRadians(i.east,i.south),o.Cartesian3.fromRadians(i.west,i.south),o.Cartesian3.fromRadians(i.west,i.north)];this._entity.polyline=new o.PolylineGraphics({positions:a,material:t,width:2,clampToGround:e.rectangle.heightReference?.getValue()===o.HeightReference.CLAMP_TO_GROUND})}}else{let i=e.rectangle.coordinates?.getValue();i&&(this._entity.rectangle=new o.RectangleGraphics({coordinates:i,material:t,heightReference:e.rectangle.heightReference?.getValue()}))}}else if(e instanceof o.GroundPrimitive){let i=e.geometryInstances,a=Array.isArray(i)?i[0]:i;if(!a.geometry.attributes.position)return;let s=a.geometry.attributes.position.values,l=[];for(let c=0;c<s.length;c+=3)l.push(new o.Cartesian3(s[c],s[c+1],s[c+2]));r?this._entity.polyline=new o.PolylineGraphics({positions:l,material:t,width:2,clampToGround:!0}):this._entity.polygon=new o.PolygonGraphics({hierarchy:new o.PolygonHierarchy(l),material:t,heightReference:o.HeightReference.CLAMP_TO_GROUND,classificationType:o.ClassificationType.BOTH})}}hide(){this._entity&&(this._entity.show=!1)}get defaultColor(){return this._defaultColor}set defaultColor(e){this._defaultColor=e}get entity(){return this._entity}};
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { CesiumCollection, CesiumCollectionItem, Collection, CollectionEventType, EventHandler, NonFunction, Tag, WithTag } from './collection/index.cjs';
|
|
2
|
-
export { H as HybridTerrainProvider, T as TerrainArea, a as TileRange } from './hybrid-terrain-provider-
|
|
2
|
+
export { H as HybridTerrainProvider, T as TerrainArea, a as TileRange } from './hybrid-terrain-provider-C4b9z5pv.cjs';
|
|
3
3
|
export { TerrainAreaCollection, computeRectangle } from './terrain/index.cjs';
|
|
4
4
|
export { TerrainVisualizer, isGetterOnly } from './utils/index.cjs';
|
|
5
5
|
export { Highlight, cloneViewer, syncCamera } from './viewer/index.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { CesiumCollection, CesiumCollectionItem, Collection, CollectionEventType, EventHandler, NonFunction, Tag, WithTag } from './collection/index.js';
|
|
2
|
-
export { H as HybridTerrainProvider, T as TerrainArea, a as TileRange } from './hybrid-terrain-provider-
|
|
2
|
+
export { H as HybridTerrainProvider, T as TerrainArea, a as TileRange } from './hybrid-terrain-provider-C4b9z5pv.js';
|
|
3
3
|
export { TerrainAreaCollection, computeRectangle } from './terrain/index.js';
|
|
4
4
|
export { TerrainVisualizer, isGetterOnly } from './utils/index.js';
|
|
5
5
|
export { Highlight, cloneViewer, syncCamera } from './viewer/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as i,b as t,c as m,d as p}from"./chunk-OFZW33MB.js";import{a as r,b as o,c as e}from"./chunk-XTUDPAWI.js";import{a as n,b as a,c as l}from"./chunk-ATVZC562.js";export{e as Collection,l as Highlight,p as HybridTerrainProvider,t as TerrainArea,m as TerrainAreaCollection,r as TerrainVisualizer,a as cloneViewer,i as computeRectangle,o as isGetterOnly,n as syncCamera};
|
package/dist/terrain/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as TileRange, T as TerrainArea } from '../hybrid-terrain-provider-
|
|
2
|
-
export { H as HybridTerrainProvider } from '../hybrid-terrain-provider-
|
|
1
|
+
import { a as TileRange, T as TerrainArea } from '../hybrid-terrain-provider-C4b9z5pv.cjs';
|
|
2
|
+
export { H as HybridTerrainProvider } from '../hybrid-terrain-provider-C4b9z5pv.cjs';
|
|
3
3
|
import { TilingScheme, Rectangle } from 'cesium';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/terrain/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as TileRange, T as TerrainArea } from '../hybrid-terrain-provider-
|
|
2
|
-
export { H as HybridTerrainProvider } from '../hybrid-terrain-provider-
|
|
1
|
+
import { a as TileRange, T as TerrainArea } from '../hybrid-terrain-provider-C4b9z5pv.js';
|
|
2
|
+
export { H as HybridTerrainProvider } from '../hybrid-terrain-provider-C4b9z5pv.js';
|
|
3
3
|
import { TilingScheme, Rectangle } from 'cesium';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/utils/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var _=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var O=(n,e)=>{for(var t in e)_(n,t,{get:e[t],enumerable:!0})},S=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of A(e))!M.call(n,r)&&r!==t&&_(n,r,{get:()=>e[r],enumerable:!(i=L(e,r))||i.enumerable});return n};var V=n=>S(_({},"__esModule",{value:!0}),n);var j={};O(j,{TerrainVisualizer:()=>g,isGetterOnly:()=>v});module.exports=V(j);var s=require("cesium");var u=require("cesium");var b=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(o=>o(r))}}_addToTagMap(e,t){this._tagMap.has(t)||this._tagMap.set(t,new Set),this._tagMap.get(t)?.add(e)}_removeFromTagMap(e){let t=e[n.symbol],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache(){this._valuesCache=null}addEventListener(e,t){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(t),this}removeEventListener(e,t){return this._eventListeners.get(e)?.delete(t),this}add(e,t=this.tag,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),this._addToTagMap(e,t),this._invalidateCache(),this._emit("add",{items:[e],tag:t})),e}contains(e){if(typeof e=="object")return this.collection.contains(e);let t=this._tagMap.get(e);return!!t&&t.size>0}remove(e){if(typeof e=="object"&&!Array.isArray(e)){let r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let o of e)this.remove(o)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof u.EntityCollection)return this.collection.values;{let e=[];for(let t=0;t<this.collection.length;t++)e.push(this.collection.get(t));return e}}get length(){return this.values?.length||0}get(e){let t=this._tagMap.get(e);return t?Array.from(t):[]}first(e){let t=this._tagMap.get(e);if(t&&t.size>0)return t.values().next().value}get tags(){return Array.from(this._tagMap.keys())}update(e,t){let i=this.get(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}show(e){let t=this.get(e);for(let i of t)(0,u.defined)(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)(0,u.defined)(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)(0,u.defined)(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let o of r)if(e in o&&typeof o[e]!="function"){if(v(o,e))throw Error(`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((r,o)=>e(r,o))}map(e,t){return(t?this.get(t):this.values).map(e)}find(e,t){return(t?this.get(t):this.values).find(e)}},w=b;var g=class n{_viewer;_collection;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",s.Color.RED],["default",s.Color.BLUE],["fallback",s.Color.GRAY],["grid",s.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new w({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),t.tile!==void 0&&(this._visible=t.tile),t.activeLevel!==void 0&&(this._level=t.activeLevel),t.terrainProvider&&this.setTerrainProvider(t.terrainProvider))}setTerrainProvider(e){this._terrainProvider=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.remove(this._collection.tags)}show(e=15){if(!this._terrainProvider)return;this._collection.remove(n.tag.grid),this._level=e,this._ensureTileCoordinatesLayer();let t=this._getVisibleRectangle();if(!t||!this._isValidRectangle(t)){console.warn("Invalid visible rectangle detected, skipping grid display");return}this._displayTileGrid(t,e),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new s.TileCoordinatesImageryProvider({tilingScheme:this._terrainProvider.tilingScheme,color:s.Color.YELLOW})))}_isValidRectangle(e){return e&&Number.isFinite(e.west)&&Number.isFinite(e.south)&&Number.isFinite(e.east)&&Number.isFinite(e.north)&&e.west<=e.east&&e.south<=e.north}_displayTileGrid(e,t){let i=this._terrainProvider.tilingScheme;try{let r=this._calculateTileBounds(e,t,i);this._generateVisibleTiles(r,t,i).forEach(a=>{this._collection.add(a.entity,n.tag.grid)})}catch(r){console.error("Error displaying tile grid:",r)}}_calculateTileBounds(e,t,i){let r=i.positionToTileXY(s.Rectangle.northwest(e),t),o=i.positionToTileXY(s.Rectangle.southeast(e),t);if(!r||!o)throw new Error("Failed to calculate tile bounds");return{start:r,end:o}}_generateVisibleTiles(e,t,i){let r=[],a=Math.min(e.end.x-e.start.x+1,100),l=Math.min(e.end.y-e.start.y+1,100);for(let c=e.start.x;c<e.start.x+a;c++)for(let h=e.start.y;h<e.start.y+l;h++)try{let d=this._createTileEntity(c,h,t,i);d&&r.push({entity:d})}catch(d){console.warn(`Error creating tile (${c}, ${h}, ${t}):`,d)}return r}_createTileEntity(e,t,i,r){let o=r.tileXYToRectangle(e,t,i);if(!this._isValidRectangle(o))return null;let a=this._getTileColor(e,t,i),l=n.createRectangle(o,a.withAlpha(.3));return l.properties?.addProperty("tileX",e),l.properties?.addProperty("tileY",t),l.properties?.addProperty("tileLevel",i),l}_getTileColor(e,t,i){if(!this._terrainProvider)return this._colors.get("fallback")||s.Color.TRANSPARENT;for(let r of this._terrainProvider.terrainAreas)if(r.contains(e,t,i))return r.isCustom?this._colors.get("custom")||s.Color.RED:this._colors.get("default")||s.Color.BLUE;return this._terrainProvider.getTileDataAvailable(e,t,i)?this._colors.get("default")||s.Color.BLUE:this._colors.get("fallback")||s.Color.GRAY}hide(){this._collection.remove(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}get colors(){return this._colors}get terrainProvider(){return this._terrainProvider}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,o){return new s.Entity({rectangle:{coordinates:r,material:o,heightReference:s.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,o,a){let l=a?.tag||"terrain_area_visualization",c=a?.color||s.Color.RED,h=a?.maxTilesToShow||100,d=a?.show??!0,C=a?.alpha||.7,E=a?.tileAlpha||.2,f=new w({collection:o.entities,tag:l}),{rectangle:I}=r;if(f.add(i.createRectangle(I,c.withAlpha(C)),l),d&&r.tileRanges.size>0){let{tilingScheme:R}=r.terrainProvider,p=0;r.tileRanges.forEach((m,P)=>{for(let y=m.start.x;y<=m.end.x&&p<h;y++)for(let T=m.start.y;T<=m.end.y&&p<h;T++){let x=R.tileXYToRectangle(y,T,P);f.add(e(x,c.withAlpha(E)),`${l}_tile`),p++}})}return f}i.visualize=t})(g||={});function v(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}
|
package/dist/utils/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Viewer, Color, EntityCollection, Entity, Rectangle } from 'cesium';
|
|
2
|
-
import { H as HybridTerrainProvider, T as TerrainArea } from '../hybrid-terrain-provider-
|
|
2
|
+
import { H as HybridTerrainProvider, T as TerrainArea } from '../hybrid-terrain-provider-C4b9z5pv.cjs';
|
|
3
3
|
import { Collection } from '../collection/index.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -38,6 +38,13 @@ declare class TerrainVisualizer {
|
|
|
38
38
|
* @param level The zoom level to visualize
|
|
39
39
|
*/
|
|
40
40
|
show(level?: number): void;
|
|
41
|
+
private _ensureTileCoordinatesLayer;
|
|
42
|
+
private _isValidRectangle;
|
|
43
|
+
private _displayTileGrid;
|
|
44
|
+
private _calculateTileBounds;
|
|
45
|
+
private _generateVisibleTiles;
|
|
46
|
+
private _createTileEntity;
|
|
47
|
+
private _getTileColor;
|
|
41
48
|
/**
|
|
42
49
|
* Hides the tile grid.
|
|
43
50
|
*/
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Viewer, Color, EntityCollection, Entity, Rectangle } from 'cesium';
|
|
2
|
-
import { H as HybridTerrainProvider, T as TerrainArea } from '../hybrid-terrain-provider-
|
|
2
|
+
import { H as HybridTerrainProvider, T as TerrainArea } from '../hybrid-terrain-provider-C4b9z5pv.js';
|
|
3
3
|
import { Collection } from '../collection/index.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -38,6 +38,13 @@ declare class TerrainVisualizer {
|
|
|
38
38
|
* @param level The zoom level to visualize
|
|
39
39
|
*/
|
|
40
40
|
show(level?: number): void;
|
|
41
|
+
private _ensureTileCoordinatesLayer;
|
|
42
|
+
private _isValidRectangle;
|
|
43
|
+
private _displayTileGrid;
|
|
44
|
+
private _calculateTileBounds;
|
|
45
|
+
private _generateVisibleTiles;
|
|
46
|
+
private _createTileEntity;
|
|
47
|
+
private _getTileColor;
|
|
41
48
|
/**
|
|
42
49
|
* Hides the tile grid.
|
|
43
50
|
*/
|
package/dist/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-XTUDPAWI.js";export{a as TerrainVisualizer,b as isGetterOnly};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juun-roh/cesium-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "Utilities to handle Cesium classes easier.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Cesium",
|
|
@@ -72,30 +72,30 @@
|
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@changesets/cli": "^2.29.
|
|
75
|
+
"@changesets/cli": "^2.29.4",
|
|
76
76
|
"@commitlint/cli": "^19.8.1",
|
|
77
77
|
"@commitlint/config-conventional": "^19.8.1",
|
|
78
78
|
"@commitlint/cz-commitlint": "^19.8.1",
|
|
79
79
|
"@commitlint/format": "^19.8.1",
|
|
80
80
|
"@commitlint/types": "^19.8.1",
|
|
81
|
-
"@eslint/js": "^9.
|
|
82
|
-
"@typescript-eslint/eslint-plugin": "^8.32.
|
|
83
|
-
"@typescript-eslint/parser": "^8.32.
|
|
84
|
-
"@vitest/coverage-v8": "3.1.
|
|
81
|
+
"@eslint/js": "^9.27.0",
|
|
82
|
+
"@typescript-eslint/eslint-plugin": "^8.32.1",
|
|
83
|
+
"@typescript-eslint/parser": "^8.32.1",
|
|
84
|
+
"@vitest/coverage-v8": "3.1.4",
|
|
85
85
|
"cesium": "^1.129.0",
|
|
86
|
-
"eslint": "^9.
|
|
87
|
-
"eslint-plugin-jsdoc": "^50.6.
|
|
86
|
+
"eslint": "^9.27.0",
|
|
87
|
+
"eslint-plugin-jsdoc": "^50.6.17",
|
|
88
88
|
"eslint-plugin-prettier": "^5.4.0",
|
|
89
89
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
90
90
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
91
91
|
"husky": "^9.1.7",
|
|
92
92
|
"jsdom": "^26.1.0",
|
|
93
93
|
"rimraf": "^6.0.1",
|
|
94
|
-
"tsup": "^8.
|
|
95
|
-
"typedoc": "^0.28.
|
|
94
|
+
"tsup": "^8.5.0",
|
|
95
|
+
"typedoc": "^0.28.5",
|
|
96
96
|
"typescript": "^5.8.3",
|
|
97
97
|
"vite": "^6.3.5",
|
|
98
|
-
"vitest": "^3.1.
|
|
98
|
+
"vitest": "^3.1.4"
|
|
99
99
|
},
|
|
100
100
|
"scripts": {
|
|
101
101
|
"build": "tsup",
|
package/dist/chunk-Q4LRNVAX.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Color as l,Entity as A,HeightReference as M,Rectangle as P,TileCoordinatesImageryProvider as O}from"cesium";import{defined as w,EntityCollection as L}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 L)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;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",l.RED],["default",l.BLUE],["fallback",l.GRAY],["grid",l.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new E({collection:e.entities,tag:s.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),t.tile!==void 0&&(this._visible=t.tile),t.activeLevel!==void 0&&(this._level=t.activeLevel),t.terrainProvider&&this.setTerrainProvider(t.terrainProvider))}setTerrainProvider(e){this._terrainProvider=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.remove(this._collection.tags)}show(e=15){if(!this._terrainProvider)return;this._collection.remove(s.tag.grid),this._level=e;let t=this._terrainProvider.tilingScheme;this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new O({tilingScheme:t,color:l.YELLOW})));let i=(o,a,d)=>{if(this._terrainProvider){for(let g of this._terrainProvider.terrainAreas)if(g.contains(o,a,d))return g.isCustom?this._colors.get("custom")||l.RED:this._colors.get("default")||l.BLUE;if(this._terrainProvider.getTileDataAvailable(o,a,d))return this._colors.get("default")||l.BLUE}return this._colors.get("fallback")||l.TRANSPARENT},r=this._getVisibleRectangle();if(!r)return;function n(o){return o&&Number.isFinite(o.west)&&Number.isFinite(o.south)&&Number.isFinite(o.east)&&Number.isFinite(o.north)&&o.west<=o.east&&o.south<=o.north}if(!n(r)){console.warn("Invalid visible rectangle detected, skipping grid display");return}try{let o=t.positionToTileXY(P.northwest(r),e),a=t.positionToTileXY(P.southeast(r),e);if(!o||!a)return;let d=100,g=Math.min(a.x-o.x+1,d),p=Math.min(a.y-o.y+1,d);for(let c=o.x;c<=o.x+g-1;c++)for(let h=o.y;h<=o.y+p-1;h++)try{let u=t.tileXYToRectangle(c,h,e);if(!n(u)){console.warn(`Invalid rectangle for tile (${c}, ${h}, ${e}), skipping`);continue}let y=i(c,h,e),m=s.createRectangle(u,y.withAlpha(.3));m.properties?.addProperty("tileX",c),m.properties?.addProperty("tileY",h),m.properties?.addProperty("tileLevel",e),this._collection.add(m,s.tag.grid)}catch(u){console.warn(`Error creating tile (${c}, ${h}, ${e}): ${u.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(o){console.error("Error displaying tile grid:",o)}}hide(){this._collection.remove(s.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}get colors(){return this._colors}get terrainProvider(){return this._terrainProvider}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,n){return new A({rectangle:{coordinates:r,material:n,heightReference:M.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,n,o){let a=o?.tag||"terrain_area_visualization",d=o?.color||l.RED,g=o?.maxTilesToShow||100,p=o?.show??!0,c=o?.alpha||.7,h=o?.tileAlpha||.2,u=new E({collection:n.entities,tag:a}),{rectangle:y}=r;if(u.add(i.createRectangle(y,d.withAlpha(c)),a),p&&r.tileRanges.size>0){let{tilingScheme:m}=r.terrainProvider,b=0;r.tileRanges.forEach((f,x)=>{for(let _=f.start.x;_<=f.end.x&&b<g;_++)for(let T=f.start.y;T<=f.end.y&&b<g;T++){let R=m.tileXYToRectangle(_,T,x);u.add(e(R,d.withAlpha(h)),`${a}_tile`),b++}})}return u}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};
|