@juun-roh/cesium-utils 0.0.10 → 0.0.12

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/README.md CHANGED
@@ -44,6 +44,14 @@ pnpm build
44
44
  pnpm test
45
45
  ```
46
46
 
47
+ ### Demonstration
48
+
49
+ Run demonstration in local environment:
50
+
51
+ ```bash
52
+ pnpm dev
53
+ ```
54
+
47
55
  ### Documentation
48
56
 
49
57
  Generate API documentation:
@@ -0,0 +1 @@
1
+ import{c as f}from"./chunk-Q4LRNVAX.js";import{Viewer as E}from"cesium";import{defined as u}from"cesium";function y(i,e){if(u(i)&&u(e)){let{camera:n}=i;e.camera.position=n.positionWC.clone(),e.camera.direction=n.directionWC.clone(),e.camera.up=n.upWC.clone()}}function w(i,e,n){let r={baseLayerPicker:i.baseLayerPicker!==void 0,geocoder:i.geocoder!==void 0,homeButton:i.homeButton!==void 0,sceneModePicker:i.sceneModePicker!==void 0,timeline:i.timeline!==void 0,navigationHelpButton:i.navigationHelpButton!==void 0,animation:i.animation!==void 0,fullscreenButton:i.fullscreenButton!==void 0,shouldAnimate:i.clock.shouldAnimate,terrainProvider:i.terrainProvider,requestRenderMode:i.scene.requestRenderMode,infoBox:i.infoBox!==void 0},t=new E(e,{...r,...n});y(i,t);let o=i.imageryLayers;t.imageryLayers.removeAll();for(let s=0;s<o.length;s++){let h=o.get(s);t.imageryLayers.addImageryProvider(h.imageryProvider,s)}t.clock.startTime=i.clock.startTime.clone(),t.clock.stopTime=i.clock.stopTime.clone(),t.clock.currentTime=i.clock.currentTime.clone(),t.clock.multiplier=i.clock.multiplier,t.clock.clockStep=i.clock.clockStep,t.clock.clockRange=i.clock.clockRange,t.clock.shouldAnimate=i.clock.shouldAnimate,t.scene.globe.enableLighting=i.scene.globe.enableLighting,t.scene.globe.depthTestAgainstTerrain=i.scene.globe.depthTestAgainstTerrain,t.scene.screenSpaceCameraController.enableCollisionDetection=i.scene.screenSpaceCameraController.enableCollisionDetection;let a=i.scene.screenSpaceCameraController.tiltEventTypes;a&&(t.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(a)?[...a]:a);let l=i.scene.screenSpaceCameraController.zoomEventTypes;return l&&(t.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(l)?[...l]:l),t}import{Cartesian3 as c,ClassificationType as C,Color as T,defined as _,Entity as g,GroundPrimitive as v,HeightReference as m,PolygonHierarchy as A}from"cesium";var p=class i{static instances=new Map;_activeHighlights=new Set;_defaultColor=T.YELLOW.withAlpha(.5);_entities;_cache=new Map;constructor(e){this._entities=new f({collection:e.entities,tag:"Highlights"})}static getInstance(e){let n=e.container;return i.instances.has(n)||i.instances.set(n,new i(e)),i.instances.get(n)}static releaseInstance(e){let n=e.container,r=i.instances.get(n);r&&(r.removeAll(),i.instances.delete(n))}add(e,n=this._defaultColor,r=!1){if(!_(e))return;let t;if(e instanceof g){if(this._activeHighlights.has(e))return e;t=this._createEntity(e,n,r)}else if(e.id instanceof g){if(this._activeHighlights.has(e.id))return e.id;t=this._createEntity(e.id,n,r)}else if(e.primitive instanceof v){if(this._activeHighlights.has(e.primitive))return e.primitive;t=this._createEntity(e.primitive,n,r)}return t&&(this._entities.add(t),this._activeHighlights.add(t),t.isShowing||(t.show=!0)),t}remove(e){this._entities.remove(e),this._activeHighlights.delete(e)}removeAll(){this._entities.remove("Highlights"),this._activeHighlights.clear()}_getGeometryId(e){if(e.id)return`geometry-${e.id}`;if(e.geometry?.attributes?.position){let n=e.geometry.attributes.position.values,r="",t=Math.min(9,n.length/4);for(let o=0;o<t;o++)r+=Math.round(n[o])+"-";if(n.length>t*2)for(let o=n.length-t;o<n.length;o++)r+=Math.round(n[o]);return`geometry-hash-${r}`}}_createEntity(e,n,r=!1){try{if(e instanceof v){let t=e.geometryInstances,o=Array.isArray(t)?t[0]:t;if(!o||!o.geometry.attributes.position)return;let a=this._getGeometryId(o),l=o.geometry.attributes.position.values,s=[];for(let d=0;d<l.length;d+=3)s.push(new c(l[d],l[d+1],l[d+2]));let h={id:a?`highlight-${a}`:void 0};return r?h.polyline={positions:s,width:2,material:n,clampToGround:!0}:h.polygon={hierarchy:new A(s),material:n,classificationType:C.BOTH,heightReference:m.CLAMP_TO_GROUND},new g(h)}else{let t={id:`highlight-${e.id}`};if(e.polygon)r?t.polyline={positions:e.polygon.hierarchy?.getValue().positions,material:n,width:2,clampToGround:e.polygon.heightReference?.getValue()===m.CLAMP_TO_GROUND}:t.polygon={hierarchy:e.polygon.hierarchy?.getValue(),material:n,classificationType:C.BOTH};else if(e.polyline)t.polyline={positions:e.polyline.positions,width:(e.polyline.width?.getValue()||2)+2,material:n,clampToGround:e.polyline.clampToGround};else if(e.rectangle)if(r){let o=e.rectangle.coordinates?.getValue();if(o){let a=[c.fromRadians(o.west,o.north),c.fromRadians(o.east,o.north),c.fromRadians(o.east,o.south),c.fromRadians(o.west,o.south),c.fromRadians(o.west,o.north)];t.polyline={positions:a,material:n,width:2,clampToGround:e.rectangle.heightReference?.getValue()===m.CLAMP_TO_GROUND}}}else t.rectangle=e.rectangle.clone(),t.rectangle.material=n;else return;return new g(t)}}catch(t){console.error("Failed to create highlight Entity:",t);return}}get activeHighlights(){return Array.from(this._activeHighlights)}get defaultColor(){return this._defaultColor}set defaultColor(e){this._defaultColor=e}get entities(){return this._entities}};export{y as a,w as b,p as c};
@@ -0,0 +1 @@
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};
@@ -1 +1 @@
1
- "use strict";var I=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var O=(n,e)=>{for(var t in e)I(n,t,{get:e[t],enumerable:!0})},V=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of P(e))!M.call(n,r)&&r!==t&&I(n,r,{get:()=>e[r],enumerable:!(i=A(e,r))||i.enumerable});return n};var S=n=>V(I({},"__esModule",{value:!0}),n);var z={};O(z,{Collection:()=>p});module.exports=S(z);var f=require("cesium");var s=require("cesium");var v=class n{_viewer;_collection;_hybridTerrain;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",s.Color.RED],["default",s.Color.BLUE],["fallback",s.Color.GRAY],["grid",s.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new p({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),t.tile!==void 0&&(this._visible=t.tile),t.activeLevel!==void 0&&(this._level=t.activeLevel),t.terrainProvider&&this.setTerrainProvider(t.terrainProvider))}setTerrainProvider(e){this._hybridTerrain=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.remove(this._collection.tags)}show(e=15){if(!this._hybridTerrain)return;this._collection.remove(n.tag.grid),this._level=e;let t=this._hybridTerrain.tilingScheme;this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new s.TileCoordinatesImageryProvider({tilingScheme:t,color:s.Color.YELLOW})));let i=(o,l,d)=>{if(this._hybridTerrain){for(let m of this._hybridTerrain.terrainAreas)if(m.contains(o,l,d))return m.isCustom?this._colors.get("custom")||s.Color.RED:this._colors.get("default")||s.Color.BLUE;if(this._hybridTerrain.getTileDataAvailable(o,l,d))return this._colors.get("default")||s.Color.BLUE}return this._colors.get("fallback")||s.Color.TRANSPARENT},r=this._getVisibleRectangle();if(!r)return;function a(o){return o&&Number.isFinite(o.west)&&Number.isFinite(o.south)&&Number.isFinite(o.east)&&Number.isFinite(o.north)&&o.west<=o.east&&o.south<=o.north}if(!a(r)){console.warn("Invalid visible rectangle detected, skipping grid display");return}try{let o=t.positionToTileXY(s.Rectangle.northwest(r),e),l=t.positionToTileXY(s.Rectangle.southeast(r),e);if(!o||!l)return;let d=100,m=Math.min(l.x-o.x+1,d),b=Math.min(l.y-o.y+1,d);for(let c=o.x;c<=o.x+m-1;c++)for(let h=o.y;h<=o.y+b-1;h++)try{let u=t.tileXYToRectangle(c,h,e);if(!a(u)){console.warn(`Invalid rectangle for tile (${c}, ${h}, ${e}), skipping`);continue}let T=i(c,h,e),g=n.createRectangle(u,T.withAlpha(.3));g.properties?.addProperty("tileX",c),g.properties?.addProperty("tileY",h),g.properties?.addProperty("tileLevel",e),this._collection.add(g,n.tag.grid)}catch(u){console.warn(`Error creating tile (${c}, ${h}, ${e}): ${u.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(o){console.error("Error displaying tile grid:",o)}}hide(){this._collection.remove(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,a){return new s.Entity({rectangle:{coordinates:r,material:a,heightReference:s.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,a,o){let l=o?.tag||"terrain_area_visualization",d=o?.color||s.Color.RED,m=o?.maxTilesToShow||100,b=o?.show??!0,c=o?.alpha||.7,h=o?.tileAlpha||.2,u=new p({collection:a.entities,tag:l}),{rectangle:T}=r;if(u.add(i.createRectangle(T,d.withAlpha(c)),l),b&&r.tileRanges.size>0){let{tilingScheme:g}=r.terrainProvider,_=0;r.tileRanges.forEach((y,R)=>{for(let C=y.start.x;C<=y.end.x&&_<m;C++)for(let w=y.start.y;w<=y.end.y&&_<m;w++){let L=g.tileXYToRectangle(C,w,R);u.add(e(L,d.withAlpha(h)),`${l}_tile`),_++}})}return u}i.visualize=t})(v||={});function E(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}var j=require("cesium");var x=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(a=>a(r))}}_addToTagMap(e,t){this._tagMap.has(t)||this._tagMap.set(t,new Set),this._tagMap.get(t)?.add(e)}_removeFromTagMap(e){let t=e[n.symbol],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache(){this._valuesCache=null}addEventListener(e,t){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(t),this}removeEventListener(e,t){return this._eventListeners.get(e)?.delete(t),this}add(e,t=this.tag,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),this._addToTagMap(e,t),this._invalidateCache(),this._emit("add",{items:[e],tag:t})),e}contains(e){if(typeof e=="object")return this.collection.contains(e);let t=this._tagMap.get(e);return!!t&&t.size>0}remove(e){if(typeof e=="object"&&!Array.isArray(e)){let r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let a of e)this.remove(a)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof f.EntityCollection)return this.collection.values;{let e=[];for(let t=0;t<this.collection.length;t++)e.push(this.collection.get(t));return e}}get length(){return this.values?.length||0}get(e){let t=this._tagMap.get(e);return t?Array.from(t):[]}first(e){let t=this._tagMap.get(e);if(t&&t.size>0)return t.values().next().value}get tags(){return Array.from(this._tagMap.keys())}update(e,t){let i=this.get(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}show(e){let t=this.get(e);for(let i of t)(0,f.defined)(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)(0,f.defined)(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)(0,f.defined)(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let a of r)if(e in a&&typeof a[e]!="function"){if(E(a,e))throw Error(`setProperty(${a}, ${e}) failed; The property is readonly.`);a[e]=t}return this}filter(e,t){return(t?this.get(t):this.values).filter(e)}forEach(e,t){(t?this.get(t):this.values).forEach((r,a)=>e(r,a))}map(e,t){return(t?this.get(t):this.values).map(e)}find(e,t){return(t?this.get(t):this.values).find(e)}},p=x;
1
+ "use strict";var I=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var O=(n,e)=>{for(var t in e)I(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&&I(n,r,{get:()=>e[r],enumerable:!(i=L(e,r))||i.enumerable});return n};var V=n=>S(I({},"__esModule",{value:!0}),n);var j={};O(j,{Collection:()=>p});module.exports=V(j);var v=require("cesium");var s=require("cesium");var f=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 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._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 s.TileCoordinatesImageryProvider({tilingScheme:t,color:s.Color.YELLOW})));let i=(o,l,d)=>{if(this._terrainProvider){for(let g of this._terrainProvider.terrainAreas)if(g.contains(o,l,d))return g.isCustom?this._colors.get("custom")||s.Color.RED:this._colors.get("default")||s.Color.BLUE;if(this._terrainProvider.getTileDataAvailable(o,l,d))return this._colors.get("default")||s.Color.BLUE}return this._colors.get("fallback")||s.Color.TRANSPARENT},r=this._getVisibleRectangle();if(!r)return;function a(o){return o&&Number.isFinite(o.west)&&Number.isFinite(o.south)&&Number.isFinite(o.east)&&Number.isFinite(o.north)&&o.west<=o.east&&o.south<=o.north}if(!a(r)){console.warn("Invalid visible rectangle detected, skipping grid display");return}try{let o=t.positionToTileXY(s.Rectangle.northwest(r),e),l=t.positionToTileXY(s.Rectangle.southeast(r),e);if(!o||!l)return;let d=100,g=Math.min(l.x-o.x+1,d),b=Math.min(l.y-o.y+1,d);for(let c=o.x;c<=o.x+g-1;c++)for(let h=o.y;h<=o.y+b-1;h++)try{let u=t.tileXYToRectangle(c,h,e);if(!a(u)){console.warn(`Invalid rectangle for tile (${c}, ${h}, ${e}), skipping`);continue}let _=i(c,h,e),m=n.createRectangle(u,_.withAlpha(.3));m.properties?.addProperty("tileX",c),m.properties?.addProperty("tileY",h),m.properties?.addProperty("tileLevel",e),this._collection.add(m,n.tag.grid)}catch(u){console.warn(`Error creating tile (${c}, ${h}, ${e}): ${u.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(o){console.error("Error displaying tile grid:",o)}}hide(){this._collection.remove(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}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,a){return new s.Entity({rectangle:{coordinates:r,material:a,heightReference:s.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,a,o){let l=o?.tag||"terrain_area_visualization",d=o?.color||s.Color.RED,g=o?.maxTilesToShow||100,b=o?.show??!0,c=o?.alpha||.7,h=o?.tileAlpha||.2,u=new p({collection:a.entities,tag:l}),{rectangle:_}=r;if(u.add(i.createRectangle(_,d.withAlpha(c)),l),b&&r.tileRanges.size>0){let{tilingScheme:m}=r.terrainProvider,T=0;r.tileRanges.forEach((y,P)=>{for(let w=y.start.x;w<=y.end.x&&T<g;w++)for(let C=y.start.y;C<=y.end.y&&T<g;C++){let R=m.tileXYToRectangle(w,C,P);u.add(e(R,d.withAlpha(h)),`${l}_tile`),T++}})}return u}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}var x=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(a=>a(r))}}_addToTagMap(e,t){this._tagMap.has(t)||this._tagMap.set(t,new Set),this._tagMap.get(t)?.add(e)}_removeFromTagMap(e){let t=e[n.symbol],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache(){this._valuesCache=null}addEventListener(e,t){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(t),this}removeEventListener(e,t){return this._eventListeners.get(e)?.delete(t),this}add(e,t=this.tag,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),this._addToTagMap(e,t),this._invalidateCache(),this._emit("add",{items:[e],tag:t})),e}contains(e){if(typeof e=="object")return this.collection.contains(e);let t=this._tagMap.get(e);return!!t&&t.size>0}remove(e){if(typeof e=="object"&&!Array.isArray(e)){let r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let a of e)this.remove(a)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof v.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,v.defined)(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)(0,v.defined)(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)(0,v.defined)(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let a of r)if(e in a&&typeof a[e]!="function"){if(E(a,e))throw Error(`setProperty(${a}, ${e}) failed; The property is readonly.`);a[e]=t}return this}filter(e,t){return(t?this.get(t):this.values).filter(e)}forEach(e,t){(t?this.get(t):this.values).forEach((r,a)=>e(r,a))}map(e,t){return(t?this.get(t):this.values).map(e)}find(e,t){return(t?this.get(t):this.values).find(e)}},p=x;
@@ -1 +1 @@
1
- import{c as o}from"../chunk-RJNF3DQR.js";import"../chunk-YZ7AUGIO.js";export{o as Collection};
1
+ import{c as o}from"../chunk-Q4LRNVAX.js";export{o as Collection};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var M=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var H=(n,e)=>{for(var r in e)M(n,r,{get:e[r],enumerable:!0})},B=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of F(e))!Y.call(n,i)&&i!==r&&M(n,i,{get:()=>e[i],enumerable:!(t=j(e,i))||t.enumerable});return n};var q=n=>B(M({},"__esModule",{value:!0}),n);var W={};H(W,{Collection:()=>_,HybridTerrainProvider:()=>w,TerrainArea:()=>u,TerrainAreaCollection:()=>v,TerrainVisualizer:()=>f,cloneViewer:()=>D,computeRectangle:()=>P,isGetterOnly:()=>C,syncCamera:()=>b});module.exports=q(W);var y=require("cesium");var l=require("cesium");var f=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 _({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.remove(this._collection.tags)}show(e=15){if(!this._hybridTerrain)return;this._collection.remove(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),p=Math.min(s.y-a.y+1,c);for(let m=a.x;m<=a.x+d-1;m++)for(let h=a.y;h<=a.y+p-1;h++)try{let g=r.tileXYToRectangle(m,h,e);if(!o(g)){console.warn(`Invalid rectangle for tile (${m}, ${h}, ${e}), skipping`);continue}let R=t(m,h,e),T=n.createRectangle(g,R.withAlpha(.3));T.properties?.addProperty("tileX",m),T.properties?.addProperty("tileY",h),T.properties?.addProperty("tileLevel",e),this._collection.add(T,n.tag.grid)}catch(g){console.warn(`Error creating tile (${m}, ${h}, ${e}): ${g.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(a){console.error("Error displaying tile grid:",a)}}hide(){this._collection.remove(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([r,t])=>{this._colors.set(r,t)}),this.update()}flyTo(e,r){let{rectangle:t}=e;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,p=a?.show??!0,m=a?.alpha||.7,h=a?.tileAlpha||.2,g=new _({collection:o.entities,tag:s}),{rectangle:R}=i;if(g.add(t.createRectangle(R,c.withAlpha(m)),s),p&&i.tileRanges.size>0){let{tilingScheme:T}=i.terrainProvider,I=0;i.tileRanges.forEach((A,G)=>{for(let E=A.start.x;E<=A.end.x&&I<d;E++)for(let x=A.start.y;x<=A.end.y&&I<d;x++){let z=T.tileXYToRectangle(E,x,G);g.add(e(z,c.withAlpha(h)),`${s}_tile`),I++}})}return g}t.visualize=r})(f||={});function C(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 b(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}[Symbol.iterator](){return this.values[Symbol.iterator]()}_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){if(typeof e=="object")return this.collection.contains(e);let r=this._tagMap.get(e);return!!r&&r.size>0}remove(e){if(typeof e=="object"&&!Array.isArray(e)){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 r=this.get(e);if(r.length===0)return!1;let t=!1;for(let i of r)this.remove(i)&&(t=!0);return t}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof y.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}get(e){let r=this._tagMap.get(e);return r?Array.from(r):[]}first(e){let r=this._tagMap.get(e);if(r&&r.size>0)return r.values().next().value}get tags(){return Array.from(this._tagMap.keys())}update(e,r){let t=this.get(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}show(e){let r=this.get(e);for(let t of r)(0,y.defined)(t.show)&&(t.show=!0);return this}hide(e){let r=this.get(e);for(let t of r)(0,y.defined)(t.show)&&(t.show=!1);return this}toggle(e){let r=this.get(e);for(let t of r)(0,y.defined)(t.show)&&(t.show=!t.show);return this}setProperty(e,r,t=this.tag){let i=this.get(t);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]=r}return this}filter(e,r){return(r?this.get(r):this.values).filter(e)}forEach(e,r){(r?this.get(r):this.values).forEach((i,o)=>e(i,o))}map(e,r){return(r?this.get(r):this.values).map(e)}find(e,r){return(r?this.get(r):this.values).find(e)}},_=O;var V=require("cesium");var S=require("cesium");var k=require("cesium");function P(n,e){if(e.size===0)return new k.Rectangle;let r=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,a=Array.from(e.keys()),s=Math.min(...a),c=e.get(s);if(c){let{start:d,end:p}=c,m=n.tileXYToRectangle(d.x,d.y,s),h=n.tileXYToRectangle(p.x,p.y,s);r=Math.min(m.west,r),t=Math.min(h.south,t),i=Math.max(h.east,i),o=Math.max(m.north,o)}return new k.Rectangle(r,t,i,o)}var u=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=P(e.terrainProvider.tilingScheme,e.tileRanges),e.tileRanges.forEach((r,t)=>{this._terrainProvider.availability?.addAvailableTileRange(t,r.start.x,r.start.y,r.end.x,r.end.y)}),this._ready=!0}contains(e,r,t){if(this._tileRanges.size===0||!this._tileRanges.has(t))return!1;let i=this._tileRanges.get(t);return e>=i.start.x&&e<=i.end.x&&r>=i.start.y&&r<=i.end.y}requestTileGeometry(e,r,t,i){if(!(!this._ready||!this.contains(e,r,t)))return this._terrainProvider.requestTileGeometry(e,r,t,i)}getTileDataAvailable(e,r,t){if(this._tileRanges.size===0||!this._tileRanges.has(t))return!1;let i=this._tileRanges.get(t);return e>=i.start.x&&e<=i.end.x&&r>=i.start.y&&r<=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(r,t,i){let o=i?.credit||"custom",a=await S.CesiumTerrainProvider.fromUrl(r,{...i,credit:o});return new e({terrainProvider:a,tileRanges:t,credit:o})}e.fromUrl=n})(u||={});var v=class extends Array{add(e){if(Array.isArray(e)){for(let t of e)this.add(t);return this.length}let r;return e instanceof u?r=e:r=new u(e),this.push(r)}remove(e){if(Array.isArray(e))return e.forEach(t=>this.remove(t)),this;let r=this.indexOf(e);return r>=0&&this.splice(r,1),this}removeAll(){this.length=0}};var w=class{_terrainAreas=new v;_terrainProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(e){this._terrainProvider=e.terrainProvider,this._fallbackProvider=e.fallbackProvider||new V.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,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){for(let i of this._terrainAreas)if(i.contains(e,r,t))return i.getTileDataAvailable(e,r,t);return this._terrainProvider.getTileDataAvailable(e,r,t)}};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});b(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 L=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var $=(n,e)=>{for(var t in e)L(n,t,{get:e[t],enumerable:!0})},W=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of j(e))!B.call(n,i)&&i!==t&&L(n,i,{get:()=>e[i],enumerable:!(r=Y(e,i))||r.enumerable});return n};var q=n=>W(L({},"__esModule",{value:!0}),n);var U={};$(U,{Collection:()=>T,Highlight:()=>A,HybridTerrainProvider:()=>R,TerrainArea:()=>f,TerrainAreaCollection:()=>y,TerrainVisualizer:()=>p,cloneViewer:()=>H,computeRectangle:()=>E,isGetterOnly:()=>C,syncCamera:()=>P});module.exports=q(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 T({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),m=Math.min(l.y-a.y+1,c);for(let u=a.x;u<=a.x+h-1;u++)for(let g=a.y;g<=a.y+m-1;g++)try{let v=t.tileXYToRectangle(u,g,e);if(!o(v)){console.warn(`Invalid rectangle for tile (${u}, ${g}, ${e}), skipping`);continue}let I=r(u,g,e),b=n.createRectangle(v,I.withAlpha(.3));b.properties?.addProperty("tileX",u),b.properties?.addProperty("tileY",g),b.properties?.addProperty("tileLevel",e),this._collection.add(b,n.tag.grid)}catch(v){console.warn(`Error creating tile (${u}, ${g}, ${e}): ${v.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,m=a?.show??!0,u=a?.alpha||.7,g=a?.tileAlpha||.2,v=new T({collection:o.entities,tag:l}),{rectangle:I}=i;if(v.add(r.createRectangle(I,c.withAlpha(u)),l),m&&i.tileRanges.size>0){let{tilingScheme:b}=i.terrainProvider,x=0;i.tileRanges.forEach((w,z)=>{for(let M=w.start.x;M<=w.end.x&&x<h;M++)for(let O=w.start.y;O<=w.end.y&&x<h;O++){let F=b.tileXYToRectangle(M,O,z);v.add(e(F,c.withAlpha(g)),`${l}_tile`),x++}})}return v}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 V=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)}},T=V;var k=require("cesium");var N=require("cesium");var S=require("cesium");function E(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:m}=c,u=n.tileXYToRectangle(h.x,h.y,l),g=n.tileXYToRectangle(m.x,m.y,l);t=Math.min(u.west,t),r=Math.min(g.south,r),i=Math.max(g.east,i),o=Math.max(u.north,o)}return new S.Rectangle(t,r,i,o)}var f=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=E(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})(f||={});var y=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 f?t=e:t=new f(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 R=class{_terrainAreas=new y;_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 y(...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 D=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 H(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 D.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");var A=class n{static instances=new Map;_activeHighlights=new Set;_defaultColor=s.Color.YELLOW.withAlpha(.5);_entities;_cache=new Map;constructor(e){this._entities=new T({collection:e.entities,tag:"Highlights"})}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.removeAll(),n.instances.delete(t))}add(e,t=this._defaultColor,r=!1){if(!(0,s.defined)(e))return;let i;if(e instanceof s.Entity){if(this._activeHighlights.has(e))return e;i=this._createEntity(e,t,r)}else if(e.id instanceof s.Entity){if(this._activeHighlights.has(e.id))return e.id;i=this._createEntity(e.id,t,r)}else if(e.primitive instanceof s.GroundPrimitive){if(this._activeHighlights.has(e.primitive))return e.primitive;i=this._createEntity(e.primitive,t,r)}return i&&(this._entities.add(i),this._activeHighlights.add(i),i.isShowing||(i.show=!0)),i}remove(e){this._entities.remove(e),this._activeHighlights.delete(e)}removeAll(){this._entities.remove("Highlights"),this._activeHighlights.clear()}_getGeometryId(e){if(e.id)return`geometry-${e.id}`;if(e.geometry?.attributes?.position){let t=e.geometry.attributes.position.values,r="",i=Math.min(9,t.length/4);for(let o=0;o<i;o++)r+=Math.round(t[o])+"-";if(t.length>i*2)for(let o=t.length-i;o<t.length;o++)r+=Math.round(t[o]);return`geometry-hash-${r}`}}_createEntity(e,t,r=!1){try{if(e instanceof s.GroundPrimitive){let i=e.geometryInstances,o=Array.isArray(i)?i[0]:i;if(!o||!o.geometry.attributes.position)return;let a=this._getGeometryId(o),l=o.geometry.attributes.position.values,c=[];for(let m=0;m<l.length;m+=3)c.push(new s.Cartesian3(l[m],l[m+1],l[m+2]));let h={id:a?`highlight-${a}`:void 0};return r?h.polyline={positions:c,width:2,material:t,clampToGround:!0}:h.polygon={hierarchy:new s.PolygonHierarchy(c),material:t,classificationType:s.ClassificationType.BOTH,heightReference:s.HeightReference.CLAMP_TO_GROUND},new s.Entity(h)}else{let i={id:`highlight-${e.id}`};if(e.polygon)r?i.polyline={positions:e.polygon.hierarchy?.getValue().positions,material:t,width:2,clampToGround:e.polygon.heightReference?.getValue()===s.HeightReference.CLAMP_TO_GROUND}:i.polygon={hierarchy:e.polygon.hierarchy?.getValue(),material:t,classificationType:s.ClassificationType.BOTH};else if(e.polyline)i.polyline={positions:e.polyline.positions,width:(e.polyline.width?.getValue()||2)+2,material:t,clampToGround:e.polyline.clampToGround};else if(e.rectangle)if(r){let o=e.rectangle.coordinates?.getValue();if(o){let a=[s.Cartesian3.fromRadians(o.west,o.north),s.Cartesian3.fromRadians(o.east,o.north),s.Cartesian3.fromRadians(o.east,o.south),s.Cartesian3.fromRadians(o.west,o.south),s.Cartesian3.fromRadians(o.west,o.north)];i.polyline={positions:a,material:t,width:2,clampToGround:e.rectangle.heightReference?.getValue()===s.HeightReference.CLAMP_TO_GROUND}}}else i.rectangle=e.rectangle.clone(),i.rectangle.material=t;else return;return new s.Entity(i)}}catch(i){console.error("Failed to create highlight Entity:",i);return}}get activeHighlights(){return Array.from(this._activeHighlights)}get defaultColor(){return this._defaultColor}set defaultColor(e){this._defaultColor=e}get entities(){return this._entities}};
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
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 TileRange } from './hybrid-terrain-provider-CEJA1Xhw.cjs';
3
3
  export { TerrainAreaCollection, computeRectangle } from './terrain/index.cjs';
4
- export { TerrainVisualizer, isGetterOnly, syncCamera } from './utils/index.cjs';
5
- export { cloneViewer } from './viewer/index.cjs';
4
+ export { TerrainVisualizer, isGetterOnly } from './utils/index.cjs';
5
+ export { Highlight, cloneViewer, syncCamera } from './viewer/index.cjs';
6
6
  import 'cesium';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
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 TileRange } from './hybrid-terrain-provider-CEJA1Xhw.js';
3
3
  export { TerrainAreaCollection, computeRectangle } from './terrain/index.js';
4
- export { TerrainVisualizer, isGetterOnly, syncCamera } from './utils/index.js';
5
- export { cloneViewer } from './viewer/index.js';
4
+ export { TerrainVisualizer, isGetterOnly } from './utils/index.js';
5
+ export { Highlight, cloneViewer, syncCamera } from './viewer/index.js';
6
6
  import 'cesium';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as t,b as m,c as p,d as n}from"./chunk-OFZW33MB.js";import{a}from"./chunk-STARYORM.js";import{a as r,b as o,c as i}from"./chunk-RJNF3DQR.js";import{a as e}from"./chunk-YZ7AUGIO.js";export{i as Collection,n as HybridTerrainProvider,m as TerrainArea,p as TerrainAreaCollection,r as TerrainVisualizer,a as cloneViewer,t as computeRectangle,o as isGetterOnly,e as syncCamera};
1
+ import{a as i,b as t,c as m,d as p}from"./chunk-OFZW33MB.js";import{a as n,b as a,c as l}from"./chunk-P5SZETSP.js";import{a as r,b as o,c as e}from"./chunk-Q4LRNVAX.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};
@@ -1 +1 @@
1
- "use strict";var I=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var S=(n,e)=>{for(var t in e)I(n,t,{get:e[t],enumerable:!0})},j=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of O(e))!V.call(n,r)&&r!==t&&I(n,r,{get:()=>e[r],enumerable:!(i=M(e,r))||i.enumerable});return n};var z=n=>j(I({},"__esModule",{value:!0}),n);var F={};S(F,{TerrainVisualizer:()=>v,isGetterOnly:()=>y,syncCamera:()=>L});module.exports=z(F);var s=require("cesium");var f=require("cesium");var E=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(a=>a(r))}}_addToTagMap(e,t){this._tagMap.has(t)||this._tagMap.set(t,new Set),this._tagMap.get(t)?.add(e)}_removeFromTagMap(e){let t=e[n.symbol],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache(){this._valuesCache=null}addEventListener(e,t){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(t),this}removeEventListener(e,t){return this._eventListeners.get(e)?.delete(t),this}add(e,t=this.tag,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),this._addToTagMap(e,t),this._invalidateCache(),this._emit("add",{items:[e],tag:t})),e}contains(e){if(typeof e=="object")return this.collection.contains(e);let t=this._tagMap.get(e);return!!t&&t.size>0}remove(e){if(typeof e=="object"&&!Array.isArray(e)){let r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let a of e)this.remove(a)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof f.EntityCollection)return this.collection.values;{let e=[];for(let t=0;t<this.collection.length;t++)e.push(this.collection.get(t));return e}}get length(){return this.values?.length||0}get(e){let t=this._tagMap.get(e);return t?Array.from(t):[]}first(e){let t=this._tagMap.get(e);if(t&&t.size>0)return t.values().next().value}get tags(){return Array.from(this._tagMap.keys())}update(e,t){let i=this.get(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}show(e){let t=this.get(e);for(let i of t)(0,f.defined)(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)(0,f.defined)(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)(0,f.defined)(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let a of r)if(e in a&&typeof a[e]!="function"){if(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((r,a)=>e(r,a))}map(e,t){return(t?this.get(t):this.values).map(e)}find(e,t){return(t?this.get(t):this.values).find(e)}},x=E;var v=class n{_viewer;_collection;_hybridTerrain;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",s.Color.RED],["default",s.Color.BLUE],["fallback",s.Color.GRAY],["grid",s.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new x({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),t.tile!==void 0&&(this._visible=t.tile),t.activeLevel!==void 0&&(this._level=t.activeLevel),t.terrainProvider&&this.setTerrainProvider(t.terrainProvider))}setTerrainProvider(e){this._hybridTerrain=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.remove(this._collection.tags)}show(e=15){if(!this._hybridTerrain)return;this._collection.remove(n.tag.grid),this._level=e;let t=this._hybridTerrain.tilingScheme;this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new s.TileCoordinatesImageryProvider({tilingScheme:t,color:s.Color.YELLOW})));let i=(o,l,d)=>{if(this._hybridTerrain){for(let m of this._hybridTerrain.terrainAreas)if(m.contains(o,l,d))return m.isCustom?this._colors.get("custom")||s.Color.RED:this._colors.get("default")||s.Color.BLUE;if(this._hybridTerrain.getTileDataAvailable(o,l,d))return this._colors.get("default")||s.Color.BLUE}return this._colors.get("fallback")||s.Color.TRANSPARENT},r=this._getVisibleRectangle();if(!r)return;function a(o){return o&&Number.isFinite(o.west)&&Number.isFinite(o.south)&&Number.isFinite(o.east)&&Number.isFinite(o.north)&&o.west<=o.east&&o.south<=o.north}if(!a(r)){console.warn("Invalid visible rectangle detected, skipping grid display");return}try{let o=t.positionToTileXY(s.Rectangle.northwest(r),e),l=t.positionToTileXY(s.Rectangle.southeast(r),e);if(!o||!l)return;let d=100,m=Math.min(l.x-o.x+1,d),b=Math.min(l.y-o.y+1,d);for(let c=o.x;c<=o.x+m-1;c++)for(let h=o.y;h<=o.y+b-1;h++)try{let u=t.tileXYToRectangle(c,h,e);if(!a(u)){console.warn(`Invalid rectangle for tile (${c}, ${h}, ${e}), skipping`);continue}let T=i(c,h,e),g=n.createRectangle(u,T.withAlpha(.3));g.properties?.addProperty("tileX",c),g.properties?.addProperty("tileY",h),g.properties?.addProperty("tileLevel",e),this._collection.add(g,n.tag.grid)}catch(u){console.warn(`Error creating tile (${c}, ${h}, ${e}): ${u.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(o){console.error("Error displaying tile grid:",o)}}hide(){this._collection.remove(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,a){return new s.Entity({rectangle:{coordinates:r,material:a,heightReference:s.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,a,o){let l=o?.tag||"terrain_area_visualization",d=o?.color||s.Color.RED,m=o?.maxTilesToShow||100,b=o?.show??!0,c=o?.alpha||.7,h=o?.tileAlpha||.2,u=new x({collection:a.entities,tag:l}),{rectangle:T}=r;if(u.add(i.createRectangle(T,d.withAlpha(c)),l),b&&r.tileRanges.size>0){let{tilingScheme:g}=r.terrainProvider,_=0;r.tileRanges.forEach((p,A)=>{for(let C=p.start.x;C<=p.end.x&&_<m;C++)for(let w=p.start.y;w<=p.end.y&&_<m;w++){let P=g.tileXYToRectangle(C,w,A);u.add(e(P,d.withAlpha(h)),`${l}_tile`),_++}})}return u}i.visualize=t})(v||={});function y(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 R=require("cesium");function L(n,e){if((0,R.defined)(n)&&(0,R.defined)(e)){let{camera:t}=n;e.camera.position=t.positionWC.clone(),e.camera.direction=t.directionWC.clone(),e.camera.up=t.upWC.clone()}}
1
+ "use strict";var I=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var O=(n,e)=>{for(var t in e)I(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&&I(n,r,{get:()=>e[r],enumerable:!(i=L(e,r))||i.enumerable});return n};var V=n=>S(I({},"__esModule",{value:!0}),n);var j={};O(j,{TerrainVisualizer:()=>f,isGetterOnly:()=>y});module.exports=V(j);var s=require("cesium");var v=require("cesium");var E=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(a=>a(r))}}_addToTagMap(e,t){this._tagMap.has(t)||this._tagMap.set(t,new Set),this._tagMap.get(t)?.add(e)}_removeFromTagMap(e){let t=e[n.symbol],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache(){this._valuesCache=null}addEventListener(e,t){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(t),this}removeEventListener(e,t){return this._eventListeners.get(e)?.delete(t),this}add(e,t=this.tag,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),this._addToTagMap(e,t),this._invalidateCache(),this._emit("add",{items:[e],tag:t})),e}contains(e){if(typeof e=="object")return this.collection.contains(e);let t=this._tagMap.get(e);return!!t&&t.size>0}remove(e){if(typeof e=="object"&&!Array.isArray(e)){let r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let a of e)this.remove(a)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof v.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,v.defined)(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)(0,v.defined)(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)(0,v.defined)(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let a of r)if(e in a&&typeof a[e]!="function"){if(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((r,a)=>e(r,a))}map(e,t){return(t?this.get(t):this.values).map(e)}find(e,t){return(t?this.get(t):this.values).find(e)}},P=E;var f=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 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._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 s.TileCoordinatesImageryProvider({tilingScheme:t,color:s.Color.YELLOW})));let i=(o,l,d)=>{if(this._terrainProvider){for(let g of this._terrainProvider.terrainAreas)if(g.contains(o,l,d))return g.isCustom?this._colors.get("custom")||s.Color.RED:this._colors.get("default")||s.Color.BLUE;if(this._terrainProvider.getTileDataAvailable(o,l,d))return this._colors.get("default")||s.Color.BLUE}return this._colors.get("fallback")||s.Color.TRANSPARENT},r=this._getVisibleRectangle();if(!r)return;function a(o){return o&&Number.isFinite(o.west)&&Number.isFinite(o.south)&&Number.isFinite(o.east)&&Number.isFinite(o.north)&&o.west<=o.east&&o.south<=o.north}if(!a(r)){console.warn("Invalid visible rectangle detected, skipping grid display");return}try{let o=t.positionToTileXY(s.Rectangle.northwest(r),e),l=t.positionToTileXY(s.Rectangle.southeast(r),e);if(!o||!l)return;let d=100,g=Math.min(l.x-o.x+1,d),b=Math.min(l.y-o.y+1,d);for(let c=o.x;c<=o.x+g-1;c++)for(let h=o.y;h<=o.y+b-1;h++)try{let u=t.tileXYToRectangle(c,h,e);if(!a(u)){console.warn(`Invalid rectangle for tile (${c}, ${h}, ${e}), skipping`);continue}let _=i(c,h,e),m=n.createRectangle(u,_.withAlpha(.3));m.properties?.addProperty("tileX",c),m.properties?.addProperty("tileY",h),m.properties?.addProperty("tileLevel",e),this._collection.add(m,n.tag.grid)}catch(u){console.warn(`Error creating tile (${c}, ${h}, ${e}): ${u.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(o){console.error("Error displaying tile grid:",o)}}hide(){this._collection.remove(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}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,a){return new s.Entity({rectangle:{coordinates:r,material:a,heightReference:s.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,a,o){let l=o?.tag||"terrain_area_visualization",d=o?.color||s.Color.RED,g=o?.maxTilesToShow||100,b=o?.show??!0,c=o?.alpha||.7,h=o?.tileAlpha||.2,u=new P({collection:a.entities,tag:l}),{rectangle:_}=r;if(u.add(i.createRectangle(_,d.withAlpha(c)),l),b&&r.tileRanges.size>0){let{tilingScheme:m}=r.terrainProvider,T=0;r.tileRanges.forEach((p,x)=>{for(let w=p.start.x;w<=p.end.x&&T<g;w++)for(let C=p.start.y;C<=p.end.y&&T<g;C++){let R=m.tileXYToRectangle(w,C,x);u.add(e(R,d.withAlpha(h)),`${l}_tile`),T++}})}return u}i.visualize=t})(f||={});function y(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}
@@ -9,7 +9,7 @@ import { Collection } from '../collection/index.cjs';
9
9
  declare class TerrainVisualizer {
10
10
  private _viewer;
11
11
  private _collection;
12
- private _hybridTerrain?;
12
+ private _terrainProvider?;
13
13
  private _visible;
14
14
  private _level;
15
15
  private _tileCoordinatesLayer;
@@ -71,6 +71,10 @@ declare class TerrainVisualizer {
71
71
  get collection(): Collection<EntityCollection, Entity>;
72
72
  /** The viewer used in the visualizer */
73
73
  get viewer(): Viewer;
74
+ /** The colors used in the visualizer */
75
+ get colors(): Map<string, Color>;
76
+ /** The hybrid terrain instance used in the visualizer */
77
+ get terrainProvider(): HybridTerrainProvider | undefined;
74
78
  }
75
79
  /**
76
80
  * @namespace
@@ -81,8 +85,6 @@ declare namespace TerrainVisualizer {
81
85
  interface ConstructorOptions {
82
86
  /** Colors to use for different visualization elements */
83
87
  colors?: Record<string, Color>;
84
- /** Whether to show boundaries initially. */
85
- boundaries?: boolean;
86
88
  /** Whether to show tile grid initially. */
87
89
  tile?: boolean;
88
90
  /** Initial zoom level to use for visualizations. */
@@ -132,11 +134,4 @@ declare namespace TerrainVisualizer {
132
134
  */
133
135
  declare function isGetterOnly(o: object, k: string | number | symbol): boolean;
134
136
 
135
- /**
136
- * Copies camera state from source viewer to destination viewer.
137
- * @param source The source viewer to copy camera states from.
138
- * @param dest The destination viewer to apply camera properties from the source.
139
- */
140
- declare function syncCamera(source: Viewer, dest: Viewer): void;
141
-
142
- export { TerrainVisualizer, isGetterOnly, syncCamera };
137
+ export { TerrainVisualizer, isGetterOnly };
@@ -9,7 +9,7 @@ import { Collection } from '../collection/index.js';
9
9
  declare class TerrainVisualizer {
10
10
  private _viewer;
11
11
  private _collection;
12
- private _hybridTerrain?;
12
+ private _terrainProvider?;
13
13
  private _visible;
14
14
  private _level;
15
15
  private _tileCoordinatesLayer;
@@ -71,6 +71,10 @@ declare class TerrainVisualizer {
71
71
  get collection(): Collection<EntityCollection, Entity>;
72
72
  /** The viewer used in the visualizer */
73
73
  get viewer(): Viewer;
74
+ /** The colors used in the visualizer */
75
+ get colors(): Map<string, Color>;
76
+ /** The hybrid terrain instance used in the visualizer */
77
+ get terrainProvider(): HybridTerrainProvider | undefined;
74
78
  }
75
79
  /**
76
80
  * @namespace
@@ -81,8 +85,6 @@ declare namespace TerrainVisualizer {
81
85
  interface ConstructorOptions {
82
86
  /** Colors to use for different visualization elements */
83
87
  colors?: Record<string, Color>;
84
- /** Whether to show boundaries initially. */
85
- boundaries?: boolean;
86
88
  /** Whether to show tile grid initially. */
87
89
  tile?: boolean;
88
90
  /** Initial zoom level to use for visualizations. */
@@ -132,11 +134,4 @@ declare namespace TerrainVisualizer {
132
134
  */
133
135
  declare function isGetterOnly(o: object, k: string | number | symbol): boolean;
134
136
 
135
- /**
136
- * Copies camera state from source viewer to destination viewer.
137
- * @param source The source viewer to copy camera states from.
138
- * @param dest The destination viewer to apply camera properties from the source.
139
- */
140
- declare function syncCamera(source: Viewer, dest: Viewer): void;
141
-
142
- export { TerrainVisualizer, isGetterOnly, syncCamera };
137
+ export { TerrainVisualizer, isGetterOnly };
@@ -1 +1 @@
1
- import{a,b}from"../chunk-RJNF3DQR.js";import{a as c}from"../chunk-YZ7AUGIO.js";export{a as TerrainVisualizer,b as isGetterOnly,c as syncCamera};
1
+ import{a,b}from"../chunk-Q4LRNVAX.js";export{a as TerrainVisualizer,b as isGetterOnly};
@@ -1 +1 @@
1
- "use strict";var l=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var T=(e,i)=>{for(var o in i)l(e,o,{get:i[o],enumerable:!0})},v=(e,i,o,t)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of k(i))!C.call(e,n)&&n!==o&&l(e,n,{get:()=>i[n],enumerable:!(t=g(i,n))||t.enumerable});return e};var b=e=>v(l({},"__esModule",{value:!0}),e);var h={};T(h,{cloneViewer:()=>y});module.exports=b(h);var p=require("cesium");var m=require("cesium");function d(e,i){if((0,m.defined)(e)&&(0,m.defined)(i)){let{camera:o}=e;i.camera.position=o.positionWC.clone(),i.camera.direction=o.directionWC.clone(),i.camera.up=o.upWC.clone()}}function y(e,i,o){let t={baseLayerPicker:e.baseLayerPicker!==void 0,geocoder:e.geocoder!==void 0,homeButton:e.homeButton!==void 0,sceneModePicker:e.sceneModePicker!==void 0,timeline:e.timeline!==void 0,navigationHelpButton:e.navigationHelpButton!==void 0,animation:e.animation!==void 0,fullscreenButton:e.fullscreenButton!==void 0,shouldAnimate:e.clock.shouldAnimate,terrainProvider:e.terrainProvider,requestRenderMode:e.scene.requestRenderMode,infoBox:e.infoBox!==void 0},n=new p.Viewer(i,{...t,...o});d(e,n);let s=e.imageryLayers;n.imageryLayers.removeAll();for(let c=0;c<s.length;c++){let f=s.get(c);n.imageryLayers.addImageryProvider(f.imageryProvider,c)}n.clock.startTime=e.clock.startTime.clone(),n.clock.stopTime=e.clock.stopTime.clone(),n.clock.currentTime=e.clock.currentTime.clone(),n.clock.multiplier=e.clock.multiplier,n.clock.clockStep=e.clock.clockStep,n.clock.clockRange=e.clock.clockRange,n.clock.shouldAnimate=e.clock.shouldAnimate,n.scene.globe.enableLighting=e.scene.globe.enableLighting,n.scene.globe.depthTestAgainstTerrain=e.scene.globe.depthTestAgainstTerrain,n.scene.screenSpaceCameraController.enableCollisionDetection=e.scene.screenSpaceCameraController.enableCollisionDetection;let r=e.scene.screenSpaceCameraController.tiltEventTypes;r&&(n.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(r)?[...r]:r);let a=e.scene.screenSpaceCameraController.zoomEventTypes;return a&&(n.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(a)?[...a]:a),n}
1
+ "use strict";var A=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var z=(n,e)=>{for(var t in e)A(n,t,{get:e[t],enumerable:!0})},B=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of G(e))!k.call(n,i)&&i!==t&&A(n,i,{get:()=>e[i],enumerable:!(r=S(e,i))||r.enumerable});return n};var $=n=>B(A({},"__esModule",{value:!0}),n);var j={};z(j,{Highlight:()=>C,cloneViewer:()=>M,syncCamera:()=>b});module.exports=$(j);var O=require("cesium");var R=require("cesium");function b(n,e){if((0,R.defined)(n)&&(0,R.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 M(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 O.Viewer(e,{...r,...t});b(n,i);let o=n.imageryLayers;i.imageryLayers.removeAll();for(let h=0;h<o.length;h++){let d=o.get(h);i.imageryLayers.addImageryProvider(d.imageryProvider,h)}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");var p=require("cesium");var c=require("cesium");var y=class n{_viewer;_collection;_terrainProvider;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",c.Color.RED],["default",c.Color.BLUE],["fallback",c.Color.GRAY],["grid",c.Color.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new T({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 c.TileCoordinatesImageryProvider({tilingScheme:t,color:c.Color.YELLOW})));let r=(a,l,h)=>{if(this._terrainProvider){for(let d of this._terrainProvider.terrainAreas)if(d.contains(a,l,h))return d.isCustom?this._colors.get("custom")||c.Color.RED:this._colors.get("default")||c.Color.BLUE;if(this._terrainProvider.getTileDataAvailable(a,l,h))return this._colors.get("default")||c.Color.BLUE}return this._colors.get("fallback")||c.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(c.Rectangle.northwest(i),e),l=t.positionToTileXY(c.Rectangle.southeast(i),e);if(!a||!l)return;let h=100,d=Math.min(l.x-a.x+1,h),g=Math.min(l.y-a.y+1,h);for(let m=a.x;m<=a.x+d-1;m++)for(let u=a.y;u<=a.y+g-1;u++)try{let f=t.tileXYToRectangle(m,u,e);if(!o(f)){console.warn(`Invalid rectangle for tile (${m}, ${u}, ${e}), skipping`);continue}let w=r(m,u,e),v=n.createRectangle(f,w.withAlpha(.3));v.properties?.addProperty("tileX",m),v.properties?.addProperty("tileY",u),v.properties?.addProperty("tileLevel",e),this._collection.add(v,n.tag.grid)}catch(f){console.warn(`Error creating tile (${m}, ${u}, ${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 c.Entity({rectangle:{coordinates:i,material:o,heightReference:c.HeightReference.CLAMP_TO_GROUND}})}r.createRectangle=e;function t(i,o,a){let l=a?.tag||"terrain_area_visualization",h=a?.color||c.Color.RED,d=a?.maxTilesToShow||100,g=a?.show??!0,m=a?.alpha||.7,u=a?.tileAlpha||.2,f=new T({collection:o.entities,tag:l}),{rectangle:w}=i;if(f.add(r.createRectangle(w,h.withAlpha(m)),l),g&&i.tileRanges.size>0){let{tilingScheme:v}=i.terrainProvider,E=0;i.tileRanges.forEach((_,V)=>{for(let I=_.start.x;I<=_.end.x&&E<d;I++)for(let P=_.start.y;P<=_.end.y&&E<d;P++){let H=v.tileXYToRectangle(I,P,V);f.add(e(H,h.withAlpha(u)),`${l}_tile`),E++}})}return f}r.visualize=t})(y||={});function L(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 x=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let 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 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 o of i)if(e in o&&typeof o[e]!="function"){if(L(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)}},T=x;var C=class n{static instances=new Map;_activeHighlights=new Set;_defaultColor=s.Color.YELLOW.withAlpha(.5);_entities;_cache=new Map;constructor(e){this._entities=new T({collection:e.entities,tag:"Highlights"})}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.removeAll(),n.instances.delete(t))}add(e,t=this._defaultColor,r=!1){if(!(0,s.defined)(e))return;let i;if(e instanceof s.Entity){if(this._activeHighlights.has(e))return e;i=this._createEntity(e,t,r)}else if(e.id instanceof s.Entity){if(this._activeHighlights.has(e.id))return e.id;i=this._createEntity(e.id,t,r)}else if(e.primitive instanceof s.GroundPrimitive){if(this._activeHighlights.has(e.primitive))return e.primitive;i=this._createEntity(e.primitive,t,r)}return i&&(this._entities.add(i),this._activeHighlights.add(i),i.isShowing||(i.show=!0)),i}remove(e){this._entities.remove(e),this._activeHighlights.delete(e)}removeAll(){this._entities.remove("Highlights"),this._activeHighlights.clear()}_getGeometryId(e){if(e.id)return`geometry-${e.id}`;if(e.geometry?.attributes?.position){let t=e.geometry.attributes.position.values,r="",i=Math.min(9,t.length/4);for(let o=0;o<i;o++)r+=Math.round(t[o])+"-";if(t.length>i*2)for(let o=t.length-i;o<t.length;o++)r+=Math.round(t[o]);return`geometry-hash-${r}`}}_createEntity(e,t,r=!1){try{if(e instanceof s.GroundPrimitive){let i=e.geometryInstances,o=Array.isArray(i)?i[0]:i;if(!o||!o.geometry.attributes.position)return;let a=this._getGeometryId(o),l=o.geometry.attributes.position.values,h=[];for(let g=0;g<l.length;g+=3)h.push(new s.Cartesian3(l[g],l[g+1],l[g+2]));let d={id:a?`highlight-${a}`:void 0};return r?d.polyline={positions:h,width:2,material:t,clampToGround:!0}:d.polygon={hierarchy:new s.PolygonHierarchy(h),material:t,classificationType:s.ClassificationType.BOTH,heightReference:s.HeightReference.CLAMP_TO_GROUND},new s.Entity(d)}else{let i={id:`highlight-${e.id}`};if(e.polygon)r?i.polyline={positions:e.polygon.hierarchy?.getValue().positions,material:t,width:2,clampToGround:e.polygon.heightReference?.getValue()===s.HeightReference.CLAMP_TO_GROUND}:i.polygon={hierarchy:e.polygon.hierarchy?.getValue(),material:t,classificationType:s.ClassificationType.BOTH};else if(e.polyline)i.polyline={positions:e.polyline.positions,width:(e.polyline.width?.getValue()||2)+2,material:t,clampToGround:e.polyline.clampToGround};else if(e.rectangle)if(r){let o=e.rectangle.coordinates?.getValue();if(o){let a=[s.Cartesian3.fromRadians(o.west,o.north),s.Cartesian3.fromRadians(o.east,o.north),s.Cartesian3.fromRadians(o.east,o.south),s.Cartesian3.fromRadians(o.west,o.south),s.Cartesian3.fromRadians(o.west,o.north)];i.polyline={positions:a,material:t,width:2,clampToGround:e.rectangle.heightReference?.getValue()===s.HeightReference.CLAMP_TO_GROUND}}}else i.rectangle=e.rectangle.clone(),i.rectangle.material=t;else return;return new s.Entity(i)}}catch(i){console.error("Failed to create highlight Entity:",i);return}}get activeHighlights(){return Array.from(this._activeHighlights)}get defaultColor(){return this._defaultColor}set defaultColor(e){this._defaultColor=e}get entities(){return this._entities}};
@@ -1,4 +1,5 @@
1
- import { Viewer } from 'cesium';
1
+ import { Viewer, Color, Entity, EntityCollection } from 'cesium';
2
+ import { Collection } from '../collection/index.cjs';
2
3
 
3
4
  /**
4
5
  * Copies configuration and state from one Cesium Viewer to another.
@@ -9,4 +10,121 @@ import { Viewer } from 'cesium';
9
10
  */
10
11
  declare function cloneViewer(source: Viewer, container: Element | string, options?: Viewer.ConstructorOptions): Viewer;
11
12
 
12
- export { cloneViewer };
13
+ /**
14
+ * @class
15
+ * Multiton class for managing highlighted features in a Cesium scene using Entity Collection.
16
+ *
17
+ * @example
18
+ * ```
19
+ * // Setup
20
+ * const viewer1 = new Viewer('cesiumContainer1');
21
+ * const viewer2 = new Viewer('cesiumContainer2');
22
+ *
23
+ * const highlighter1 = Highlight.getInstance(viewer1);
24
+ * const highlighter2 = Highlight.getInstance(viewer2);
25
+ *
26
+ * // This highlight only affects viewer1
27
+ * highlighter1.add(someEntity, Color.RED);
28
+ *
29
+ * // This highlight only affects viewer2
30
+ * highlighter2.add(someEntity, Color.BLUE);
31
+ *
32
+ * // When done with viewers
33
+ * Highlight.releaseInstance(viewer1);
34
+ * Highlight.releaseInstance(viewer2);
35
+ * viewer1.destroy();
36
+ * viewer2.destroy();
37
+ * ```
38
+ */
39
+ declare class Highlight {
40
+ /**
41
+ * A map for viewer identification.
42
+ * @private @static
43
+ */
44
+ private static instances;
45
+ /**
46
+ * A set of highlighted entities.
47
+ * @private
48
+ */
49
+ private _activeHighlights;
50
+ /**
51
+ * The default highlight color.
52
+ * @private
53
+ */
54
+ private _defaultColor;
55
+ /**
56
+ * A collection for handling highlight entities internally.
57
+ * @private
58
+ */
59
+ private _entities;
60
+ private _cache;
61
+ /**
62
+ * Creates a new `Highlight` instance.
63
+ * @private Use {@link getInstance `Highlight.getInstance()`}
64
+ * @param viewer A viewer for the highlight collections to be derived from.
65
+ */
66
+ private constructor();
67
+ /**
68
+ * Gets or creates highlight instance from a viewer.
69
+ * @param viewer The viewer to get or create a new instance from.
70
+ */
71
+ static getInstance(viewer: Viewer): Highlight;
72
+ /**
73
+ * Releases the highlight instance associated with a viewer.
74
+ * @param viewer The viewer whose highlight instance should be released.
75
+ */
76
+ static releaseInstance(viewer: Viewer): void;
77
+ /**
78
+ * Highlights a picked object from the scene.
79
+ * @param picked The object returned from `scene.pick()` or `drillPick()`
80
+ * @param color Optional color for the highlight. Defaults to yellow with 0.5 alpha.
81
+ * @param outline Optional style for the highlight. Defaults to `false`.
82
+ * @returns The newly created highlight object
83
+ */
84
+ add(picked: any, color?: Color, outline?: boolean): Entity | undefined;
85
+ /**
86
+ * Clears a specific highlight.
87
+ * @param highlight The highlight object to clear
88
+ */
89
+ remove(highlight: Entity): void;
90
+ /**
91
+ * Clears all highlights.
92
+ */
93
+ removeAll(): void;
94
+ /**
95
+ * Gets a unique identifier for a geometry instance.
96
+ * @private
97
+ * @param instance The geometry instance
98
+ * @returns A unique string identifier
99
+ */
100
+ private _getGeometryId;
101
+ /**
102
+ * Highlights a Ground Primitive by creating a ground-clamped Entity.
103
+ * @private
104
+ * @param from The GroundPrimitive object to create from
105
+ * @param color The color to use for the highlight
106
+ * @param outline Whether to create an outline (polyline) instead of a filled polygon
107
+ * @returns The created Entity
108
+ */
109
+ private _createEntity;
110
+ /** Gets all active highlights */
111
+ get activeHighlights(): readonly Entity[];
112
+ /** Gets the default highlight color. */
113
+ get defaultColor(): Color;
114
+ /**
115
+ * Sets the default highlight color.
116
+ * @param color The new default color for highlights
117
+ */
118
+ set defaultColor(color: Color);
119
+ /** Gets a collection for `Entity` used to highlight. */
120
+ get entities(): Collection<EntityCollection, Entity>;
121
+ }
122
+
123
+ /**
124
+ * Copies camera state from source viewer to destination viewer.
125
+ * @param source The source viewer to copy camera states from.
126
+ * @param dest The destination viewer to apply camera properties from the source.
127
+ */
128
+ declare function syncCamera(source: Viewer, dest: Viewer): void;
129
+
130
+ export { Highlight, cloneViewer, syncCamera };
@@ -1,4 +1,5 @@
1
- import { Viewer } from 'cesium';
1
+ import { Viewer, Color, Entity, EntityCollection } from 'cesium';
2
+ import { Collection } from '../collection/index.js';
2
3
 
3
4
  /**
4
5
  * Copies configuration and state from one Cesium Viewer to another.
@@ -9,4 +10,121 @@ import { Viewer } from 'cesium';
9
10
  */
10
11
  declare function cloneViewer(source: Viewer, container: Element | string, options?: Viewer.ConstructorOptions): Viewer;
11
12
 
12
- export { cloneViewer };
13
+ /**
14
+ * @class
15
+ * Multiton class for managing highlighted features in a Cesium scene using Entity Collection.
16
+ *
17
+ * @example
18
+ * ```
19
+ * // Setup
20
+ * const viewer1 = new Viewer('cesiumContainer1');
21
+ * const viewer2 = new Viewer('cesiumContainer2');
22
+ *
23
+ * const highlighter1 = Highlight.getInstance(viewer1);
24
+ * const highlighter2 = Highlight.getInstance(viewer2);
25
+ *
26
+ * // This highlight only affects viewer1
27
+ * highlighter1.add(someEntity, Color.RED);
28
+ *
29
+ * // This highlight only affects viewer2
30
+ * highlighter2.add(someEntity, Color.BLUE);
31
+ *
32
+ * // When done with viewers
33
+ * Highlight.releaseInstance(viewer1);
34
+ * Highlight.releaseInstance(viewer2);
35
+ * viewer1.destroy();
36
+ * viewer2.destroy();
37
+ * ```
38
+ */
39
+ declare class Highlight {
40
+ /**
41
+ * A map for viewer identification.
42
+ * @private @static
43
+ */
44
+ private static instances;
45
+ /**
46
+ * A set of highlighted entities.
47
+ * @private
48
+ */
49
+ private _activeHighlights;
50
+ /**
51
+ * The default highlight color.
52
+ * @private
53
+ */
54
+ private _defaultColor;
55
+ /**
56
+ * A collection for handling highlight entities internally.
57
+ * @private
58
+ */
59
+ private _entities;
60
+ private _cache;
61
+ /**
62
+ * Creates a new `Highlight` instance.
63
+ * @private Use {@link getInstance `Highlight.getInstance()`}
64
+ * @param viewer A viewer for the highlight collections to be derived from.
65
+ */
66
+ private constructor();
67
+ /**
68
+ * Gets or creates highlight instance from a viewer.
69
+ * @param viewer The viewer to get or create a new instance from.
70
+ */
71
+ static getInstance(viewer: Viewer): Highlight;
72
+ /**
73
+ * Releases the highlight instance associated with a viewer.
74
+ * @param viewer The viewer whose highlight instance should be released.
75
+ */
76
+ static releaseInstance(viewer: Viewer): void;
77
+ /**
78
+ * Highlights a picked object from the scene.
79
+ * @param picked The object returned from `scene.pick()` or `drillPick()`
80
+ * @param color Optional color for the highlight. Defaults to yellow with 0.5 alpha.
81
+ * @param outline Optional style for the highlight. Defaults to `false`.
82
+ * @returns The newly created highlight object
83
+ */
84
+ add(picked: any, color?: Color, outline?: boolean): Entity | undefined;
85
+ /**
86
+ * Clears a specific highlight.
87
+ * @param highlight The highlight object to clear
88
+ */
89
+ remove(highlight: Entity): void;
90
+ /**
91
+ * Clears all highlights.
92
+ */
93
+ removeAll(): void;
94
+ /**
95
+ * Gets a unique identifier for a geometry instance.
96
+ * @private
97
+ * @param instance The geometry instance
98
+ * @returns A unique string identifier
99
+ */
100
+ private _getGeometryId;
101
+ /**
102
+ * Highlights a Ground Primitive by creating a ground-clamped Entity.
103
+ * @private
104
+ * @param from The GroundPrimitive object to create from
105
+ * @param color The color to use for the highlight
106
+ * @param outline Whether to create an outline (polyline) instead of a filled polygon
107
+ * @returns The created Entity
108
+ */
109
+ private _createEntity;
110
+ /** Gets all active highlights */
111
+ get activeHighlights(): readonly Entity[];
112
+ /** Gets the default highlight color. */
113
+ get defaultColor(): Color;
114
+ /**
115
+ * Sets the default highlight color.
116
+ * @param color The new default color for highlights
117
+ */
118
+ set defaultColor(color: Color);
119
+ /** Gets a collection for `Entity` used to highlight. */
120
+ get entities(): Collection<EntityCollection, Entity>;
121
+ }
122
+
123
+ /**
124
+ * Copies camera state from source viewer to destination viewer.
125
+ * @param source The source viewer to copy camera states from.
126
+ * @param dest The destination viewer to apply camera properties from the source.
127
+ */
128
+ declare function syncCamera(source: Viewer, dest: Viewer): void;
129
+
130
+ export { Highlight, cloneViewer, syncCamera };
@@ -1 +1 @@
1
- import{a as e}from"../chunk-STARYORM.js";import"../chunk-YZ7AUGIO.js";export{e as cloneViewer};
1
+ import{a,b,c}from"../chunk-P5SZETSP.js";import"../chunk-Q4LRNVAX.js";export{c as Highlight,b as cloneViewer,a as syncCamera};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juun-roh/cesium-utils",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "Utilities to handle Cesium classes easier.",
5
5
  "keywords": [
6
6
  "Cesium",
@@ -50,6 +50,11 @@
50
50
  "types": "./dist/utils/index.d.ts",
51
51
  "import": "./dist/utils/index.js",
52
52
  "require": "./dist/utils/index.cjs"
53
+ },
54
+ "./viewer": {
55
+ "types": "./dist/viewer/index.d.ts",
56
+ "import": "./dist/viewer/index.js",
57
+ "require": "./dist/viewer/index.cjs"
53
58
  }
54
59
  },
55
60
  "engines": {
@@ -68,22 +73,23 @@
68
73
  },
69
74
  "devDependencies": {
70
75
  "@changesets/cli": "^2.29.3",
71
- "@commitlint/cli": "^19.8.0",
72
- "@commitlint/config-conventional": "^19.8.0",
73
- "@commitlint/cz-commitlint": "^19.8.0",
74
- "@commitlint/format": "^19.8.0",
75
- "@commitlint/types": "^19.8.0",
76
+ "@commitlint/cli": "^19.8.1",
77
+ "@commitlint/config-conventional": "^19.8.1",
78
+ "@commitlint/cz-commitlint": "^19.8.1",
79
+ "@commitlint/format": "^19.8.1",
80
+ "@commitlint/types": "^19.8.1",
76
81
  "@eslint/js": "^9.26.0",
77
82
  "@typescript-eslint/eslint-plugin": "^8.32.0",
78
83
  "@typescript-eslint/parser": "^8.32.0",
79
84
  "@vitest/coverage-v8": "3.1.3",
80
85
  "cesium": "^1.129.0",
81
86
  "eslint": "^9.26.0",
82
- "eslint-plugin-jsdoc": "^50.6.11",
87
+ "eslint-plugin-jsdoc": "^50.6.14",
83
88
  "eslint-plugin-prettier": "^5.4.0",
84
89
  "eslint-plugin-simple-import-sort": "^12.1.1",
85
90
  "eslint-plugin-unused-imports": "^4.1.4",
86
91
  "husky": "^9.1.7",
92
+ "jsdom": "^26.1.0",
87
93
  "rimraf": "^6.0.1",
88
94
  "tsup": "^8.4.0",
89
95
  "typedoc": "^0.28.4",
@@ -1 +0,0 @@
1
- import{Color as l,Entity as P,HeightReference as M,Rectangle as x,TileCoordinatesImageryProvider as O}from"cesium";import{defined as w,EntityCollection as A}from"cesium";var C=class s{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(n=>n(r))}}_addToTagMap(e,t){this._tagMap.has(t)||this._tagMap.set(t,new Set),this._tagMap.get(t)?.add(e)}_removeFromTagMap(e){let t=e[s.symbol],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache(){this._valuesCache=null}addEventListener(e,t){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(t),this}removeEventListener(e,t){return this._eventListeners.get(e)?.delete(t),this}add(e,t=this.tag,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,s.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),this._addToTagMap(e,t),this._invalidateCache(),this._emit("add",{items:[e],tag:t})),e}contains(e){if(typeof e=="object")return this.collection.contains(e);let t=this._tagMap.get(e);return!!t&&t.size>0}remove(e){if(typeof e=="object"&&!Array.isArray(e)){let r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let n of e)this.remove(n)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof A)return this.collection.values;{let e=[];for(let t=0;t<this.collection.length;t++)e.push(this.collection.get(t));return e}}get length(){return this.values?.length||0}get(e){let t=this._tagMap.get(e);return t?Array.from(t):[]}first(e){let t=this._tagMap.get(e);if(t&&t.size>0)return t.values().next().value}get tags(){return Array.from(this._tagMap.keys())}update(e,t){let i=this.get(e);for(let r of i)this._removeFromTagMap(r),Object.defineProperty(r,s.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this._addToTagMap(r,t);return i.length>0&&this._emit("update",{items:i,tag:t}),i.length}show(e){let t=this.get(e);for(let i of t)w(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)w(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)w(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let n of r)if(e in n&&typeof n[e]!="function"){if(I(n,e))throw Error(`setProperty(${n}, ${e}) failed; The property is readonly.`);n[e]=t}return this}filter(e,t){return(t?this.get(t):this.values).filter(e)}forEach(e,t){(t?this.get(t):this.values).forEach((r,n)=>e(r,n))}map(e,t){return(t?this.get(t):this.values).map(e)}find(e,t){return(t?this.get(t):this.values).find(e)}},E=C;var f=class s{_viewer;_collection;_hybridTerrain;_visible=!1;_level=15;_tileCoordinatesLayer;_colors=new Map([["custom",l.RED],["default",l.BLUE],["fallback",l.GRAY],["grid",l.YELLOW]]);constructor(e,t){this._viewer=e,this._collection=new E({collection:e.entities,tag:s.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),t.tile!==void 0&&(this._visible=t.tile),t.activeLevel!==void 0&&(this._level=t.activeLevel),t.terrainProvider&&this.setTerrainProvider(t.terrainProvider))}setTerrainProvider(e){this._hybridTerrain=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.remove(this._collection.tags)}show(e=15){if(!this._hybridTerrain)return;this._collection.remove(s.tag.grid),this._level=e;let t=this._hybridTerrain.tilingScheme;this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new O({tilingScheme:t,color:l.YELLOW})));let i=(o,a,d)=>{if(this._hybridTerrain){for(let m of this._hybridTerrain.terrainAreas)if(m.contains(o,a,d))return m.isCustom?this._colors.get("custom")||l.RED:this._colors.get("default")||l.BLUE;if(this._hybridTerrain.getTileDataAvailable(o,a,d))return this._colors.get("default")||l.BLUE}return this._colors.get("fallback")||l.TRANSPARENT},r=this._getVisibleRectangle();if(!r)return;function n(o){return o&&Number.isFinite(o.west)&&Number.isFinite(o.south)&&Number.isFinite(o.east)&&Number.isFinite(o.north)&&o.west<=o.east&&o.south<=o.north}if(!n(r)){console.warn("Invalid visible rectangle detected, skipping grid display");return}try{let o=t.positionToTileXY(x.northwest(r),e),a=t.positionToTileXY(x.southeast(r),e);if(!o||!a)return;let d=100,m=Math.min(a.x-o.x+1,d),p=Math.min(a.y-o.y+1,d);for(let c=o.x;c<=o.x+m-1;c++)for(let h=o.y;h<=o.y+p-1;h++)try{let u=t.tileXYToRectangle(c,h,e);if(!n(u)){console.warn(`Invalid rectangle for tile (${c}, ${h}, ${e}), skipping`);continue}let y=i(c,h,e),g=s.createRectangle(u,y.withAlpha(.3));g.properties?.addProperty("tileX",c),g.properties?.addProperty("tileY",h),g.properties?.addProperty("tileLevel",e),this._collection.add(g,s.tag.grid)}catch(u){console.warn(`Error creating tile (${c}, ${h}, ${e}): ${u.message}`);continue}console.log("\u{1F680} ~ TerrainVisualizer ~ showGrid ~ collection:",this._collection),this._visible=!0}catch(o){console.error("Error displaying tile grid:",o)}}hide(){this._collection.remove(s.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,n){return new P({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,m=o?.maxTilesToShow||100,p=o?.show??!0,c=o?.alpha||.7,h=o?.tileAlpha||.2,u=new E({collection:n.entities,tag:a}),{rectangle:y}=r;if(u.add(i.createRectangle(y,d.withAlpha(c)),a),p&&r.tileRanges.size>0){let{tilingScheme:g}=r.terrainProvider,b=0;r.tileRanges.forEach((v,R)=>{for(let T=v.start.x;T<=v.end.x&&b<m;T++)for(let _=v.start.y;_<=v.end.y&&b<m;_++){let L=g.tileXYToRectangle(T,_,R);u.add(e(L,d.withAlpha(h)),`${a}_tile`),b++}})}return u}i.visualize=t})(f||={});function I(s,e){let t=!1,i=Object.getOwnPropertyDescriptor(s,e);if(!i){let r=Object.getPrototypeOf(s);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}export{f as a,I as b,E as c};
@@ -1 +0,0 @@
1
- import{a as r}from"./chunk-YZ7AUGIO.js";import{Viewer as d}from"cesium";function f(e,a,c){let m={baseLayerPicker:e.baseLayerPicker!==void 0,geocoder:e.geocoder!==void 0,homeButton:e.homeButton!==void 0,sceneModePicker:e.sceneModePicker!==void 0,timeline:e.timeline!==void 0,navigationHelpButton:e.navigationHelpButton!==void 0,animation:e.animation!==void 0,fullscreenButton:e.fullscreenButton!==void 0,shouldAnimate:e.clock.shouldAnimate,terrainProvider:e.terrainProvider,requestRenderMode:e.scene.requestRenderMode,infoBox:e.infoBox!==void 0},n=new d(a,{...m,...c});r(e,n);let l=e.imageryLayers;n.imageryLayers.removeAll();for(let o=0;o<l.length;o++){let s=l.get(o);n.imageryLayers.addImageryProvider(s.imageryProvider,o)}n.clock.startTime=e.clock.startTime.clone(),n.clock.stopTime=e.clock.stopTime.clone(),n.clock.currentTime=e.clock.currentTime.clone(),n.clock.multiplier=e.clock.multiplier,n.clock.clockStep=e.clock.clockStep,n.clock.clockRange=e.clock.clockRange,n.clock.shouldAnimate=e.clock.shouldAnimate,n.scene.globe.enableLighting=e.scene.globe.enableLighting,n.scene.globe.depthTestAgainstTerrain=e.scene.globe.depthTestAgainstTerrain,n.scene.screenSpaceCameraController.enableCollisionDetection=e.scene.screenSpaceCameraController.enableCollisionDetection;let t=e.scene.screenSpaceCameraController.tiltEventTypes;t&&(n.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(t)?[...t]:t);let i=e.scene.screenSpaceCameraController.zoomEventTypes;return i&&(n.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(i)?[...i]:i),n}export{f as a};
@@ -1 +0,0 @@
1
- import{defined as n}from"cesium";function a(o,e){if(n(o)&&n(e)){let{camera:i}=o;e.camera.position=i.positionWC.clone(),e.camera.direction=i.directionWC.clone(),e.camera.up=i.upWC.clone()}}export{a};