@juun-roh/cesium-utils 0.0.19 → 0.0.20
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 +13 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
A utility library for Cesium.js that simplifies working with collections and terrain providers.
|
|
9
9
|
|
|
10
|
-
[📚 API Documentation](https://juunie-roh.github.io/cesium-utils/) | [📦 NPM Package](https://www.npmjs.com/package/@juun-roh/cesium-utils) | [▶️
|
|
10
|
+
[📚 API Documentation](https://juunie-roh.github.io/cesium-utils/) | [📦 NPM Package](https://www.npmjs.com/package/@juun-roh/cesium-utils) | [▶️ Demonstration](https://juun.vercel.app/cesium-utils)
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
@@ -29,6 +29,18 @@ This library works in both modern browsers and Node.js environments. It supports
|
|
|
29
29
|
* ESM (ECMAScript modules)
|
|
30
30
|
* CommonJS (via a bundled .cjs file)
|
|
31
31
|
|
|
32
|
+
## Modular Exports
|
|
33
|
+
|
|
34
|
+
This library supports modular exports, which enables for you to import only needed modules.
|
|
35
|
+
Though this library is about 140kB, you can minimize the size for importing this library.
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
// This imports all modules of the package
|
|
39
|
+
import { Collection } from "@juun-roh/cesium-utils";
|
|
40
|
+
// To minimize the imported modules size, try this:
|
|
41
|
+
import { Highlight } from "@juun-roh/cesium-utils/highlight";
|
|
42
|
+
```
|
|
43
|
+
|
|
32
44
|
## Development
|
|
33
45
|
|
|
34
46
|
### Building
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var L=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var $=(n,e)=>{for(var t in e)L(n,t,{get:e[t],enumerable:!0})},K=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of U(e))!X.call(n,r)&&r!==t&&L(n,r,{get:()=>e[r],enumerable:!(i=q(e,r))||i.enumerable});return n};var J=n=>K(L({},"__esModule",{value:!0}),n);var Q={};$(Q,{Collection:()=>y,Highlight:()=>C,HybridTerrainProvider:()=>A,TerrainArea:()=>g,TerrainAreaCollection:()=>p,TerrainVisualizer:()=>v,cloneViewer:()=>k,computeRectangle:()=>w,isGetterOnly:()=>P,syncCamera:()=>R});module.exports=J(Q);var _=require("cesium");var c=require("cesium");var v=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 y({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),t.tile!==void 0&&(this._visible=t.tile),t.activeLevel!==void 0&&(this._level=t.activeLevel),t.terrainProvider&&this.setTerrainProvider(t.terrainProvider))}setTerrainProvider(e){this._terrainProvider=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.remove(this._collection.tags)}show(e=15){if(!this._terrainProvider)return;this._collection.remove(n.tag.grid),this._level=e,this._ensureTileCoordinatesLayer();let t=this._getVisibleRectangle();if(!t||!this._isValidRectangle(t)){console.warn("Invalid visible rectangle detected, skipping grid display");return}this._displayTileGrid(t,e),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new c.TileCoordinatesImageryProvider({tilingScheme:this._terrainProvider.tilingScheme,color:c.Color.YELLOW})))}_isValidRectangle(e){return e&&Number.isFinite(e.west)&&Number.isFinite(e.south)&&Number.isFinite(e.east)&&Number.isFinite(e.north)&&e.west<=e.east&&e.south<=e.north}_displayTileGrid(e,t){let i=this._terrainProvider.tilingScheme;try{let r=this._calculateTileBounds(e,t,i);this._generateVisibleTiles(r,t,i).forEach(l=>{this._collection.add(l.entity,n.tag.grid)})}catch(r){console.error("Error displaying tile grid:",r)}}_calculateTileBounds(e,t,i){let r=i.positionToTileXY(c.Rectangle.northwest(e),t),o=i.positionToTileXY(c.Rectangle.southeast(e),t);if(!r||!o)throw new Error("Failed to calculate tile bounds");return{start:r,end:o}}_generateVisibleTiles(e,t,i){let r=[],l=Math.min(e.end.x-e.start.x+1,100),s=Math.min(e.end.y-e.start.y+1,100);for(let h=e.start.x;h<e.start.x+l;h++)for(let m=e.start.y;m<e.start.y+s;m++)try{let f=this._createTileEntity(h,m,t,i);f&&r.push({entity:f})}catch(f){console.warn(`Error creating tile (${h}, ${m}, ${t}):`,f)}return r}_createTileEntity(e,t,i,r){let o=r.tileXYToRectangle(e,t,i);if(!this._isValidRectangle(o))return null;let l=this._getTileColor(e,t,i),s=n.createRectangle(o,l.withAlpha(.3));return s.properties?.addProperty("tileX",e),s.properties?.addProperty("tileY",t),s.properties?.addProperty("tileLevel",i),s}_getTileColor(e,t,i){if(!this._terrainProvider)return this._colors.get("fallback")||c.Color.TRANSPARENT;for(let r of this._terrainProvider.terrainAreas)if(r.contains(e,t,i))return r.isCustom?this._colors.get("custom")||c.Color.RED:this._colors.get("default")||c.Color.BLUE;return this._terrainProvider.getTileDataAvailable(e,t,i)?this._colors.get("default")||c.Color.BLUE:this._colors.get("fallback")||c.Color.GRAY}hide(){this._collection.remove(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}get colors(){return this._colors}get terrainProvider(){return this._terrainProvider}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,o){return new c.Entity({rectangle:{coordinates:r,material:o,heightReference:c.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,o,l){let s=l?.tag||"terrain_area_visualization",h=l?.color||c.Color.RED,m=l?.maxTilesToShow||100,f=l?.show??!0,E=l?.alpha||.7,I=l?.tileAlpha||.2,S=new y({collection:o.entities,tag:s}),{rectangle:B}=r;if(S.add(i.createRectangle(B,h.withAlpha(E)),s),f&&r.tileRanges.size>0){let{tilingScheme:Y}=r.terrainProvider,O=0;r.tileRanges.forEach((x,j)=>{for(let V=x.start.x;V<=x.end.x&&O<m;V++)for(let M=x.start.y;M<=x.end.y&&O<m;M++){let W=Y.tileXYToRectangle(V,M,j);S.add(e(W,h.withAlpha(I)),`${s}_tile`),O++}})}return S}i.visualize=t})(v||={});function P(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}var G=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(o=>o(r))}}_addToTagMap(e,t){this._tagMap.has(t)||this._tagMap.set(t,new Set),this._tagMap.get(t)?.add(e)}_removeFromTagMap(e){let t=e[n.symbol],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache(){this._valuesCache=null}addEventListener(e,t){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(t),this}removeEventListener(e,t){return this._eventListeners.get(e)?.delete(t),this}add(e,t=this.tag,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),this._addToTagMap(e,t),this._invalidateCache(),this._emit("add",{items:[e],tag:t})),e}contains(e){if(typeof e=="object")return this.collection.contains(e);let t=this._tagMap.get(e);return!!t&&t.size>0}remove(e){if(typeof e=="object"&&!Array.isArray(e)){let r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let o of e)this.remove(o)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof _.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,_.defined)(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)(0,_.defined)(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)(0,_.defined)(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let o of r)if(e in o&&typeof o[e]!="function"){if(P(o,e))throw Error(`Cannot set read-only property '${String(e)}' on ${o.constructor.name}`);o[e]=t}return this}filter(e,t){return(t?this.get(t):this.values).filter(e)}forEach(e,t){(t?this.get(t):this.values).forEach((r,o)=>e(r,o))}map(e,t){return(t?this.get(t):this.values).map(e)}find(e,t){return(t?this.get(t):this.values).find(e)}},y=G;var d=require("cesium");var u=require("cesium"),T=class{_color=u.Color.RED;_silhouette;_composite;_stages;_entity;constructor(e){this._stages=e.scene.postProcessStages,this._silhouette=u.PostProcessStageLibrary.createEdgeDetectionStage(),this._silhouette.uniforms.color=this._color,this._silhouette.uniforms.length=.01,this._silhouette.selected=[],this._composite=u.PostProcessStageLibrary.createSilhouetteStage([this._silhouette]),this._stages.add(this._composite)}show(e,t){if(!(!(0,u.defined)(e)||this._silhouette.selected[0]===e))if(e instanceof u.Cesium3DTileFeature)this._composite.uniforms.color=t?.color||this._color,this._silhouette.selected.push(e);else{if(!e.model)return;this._entity=e,e.model.silhouetteSize=new u.ConstantProperty(t?.width||2),e.model.silhouetteColor=new u.ConstantProperty(t?.color||this._color)}}hide(){this._silhouette.selected.length>0&&(this._silhouette.selected=[]),this._entity?.model&&(this._entity.model.silhouetteColor=new u.ConstantProperty(u.Color.TRANSPARENT),this._entity=void 0)}destroy(){this.hide(),this._composite&&this._stages.remove(this._composite)}get color(){return this._color}set color(e){this._color=e}};var a=require("cesium"),b=class{_color=a.Color.RED;_entity;_entities;constructor(e){this._entities=e.entities,this._entity=this._entities.add(new a.Entity({id:`highlight-entity-${Math.random().toString(36).substring(2)}`,show:!1}))}show(e,t){if(!(!(0,a.defined)(e)||!this._entity)){this._clearGeometries();try{if(e instanceof a.Entity&&(e.polygon||e.polyline||e.rectangle))this._update(e,t);else if(e instanceof a.GroundPrimitive)this._update(e,t);else return;return this._entity.show=!0,this._entity}catch(i){console.error("Failed to highlight object:",i);return}}}_clearGeometries(){this._entity.polygon=void 0,this._entity.polyline=void 0,this._entity.rectangle=void 0}_update(e,t={color:this._color,outline:!1,width:2}){if(e instanceof a.Entity){if(e.polygon)if(t.outline){let i=e.polygon.hierarchy?.getValue();if(i&&i.positions){let r;i.positions.length>0&&!a.Cartesian3.equals(i.positions[0],i.positions[i.positions.length-1])?r=[...i.positions,i.positions[0]]:r=i.positions,this._entity.polyline=new a.PolylineGraphics({positions:r,material:t.color,width:t.width||2,clampToGround:!0})}}else{let i=e.polygon.hierarchy?.getValue();i&&(this._entity.polygon=new a.PolygonGraphics({hierarchy:i,material:t.color,heightReference:a.HeightReference.CLAMP_TO_GROUND,classificationType:e.polygon.classificationType?.getValue()||a.ClassificationType.BOTH}))}else if(e.polyline){let i=e.polyline.positions?.getValue();if(i){let r=e.polyline.width?.getValue();this._entity.polyline=new a.PolylineGraphics({positions:i,material:t.color,width:r+(t.width||2),clampToGround:!0})}}else if(e.rectangle)if(t.outline){let i=e.rectangle.coordinates?.getValue();if(i){let r=[a.Cartesian3.fromRadians(i.west,i.north),a.Cartesian3.fromRadians(i.east,i.north),a.Cartesian3.fromRadians(i.east,i.south),a.Cartesian3.fromRadians(i.west,i.south),a.Cartesian3.fromRadians(i.west,i.north)];this._entity.polyline=new a.PolylineGraphics({positions:r,material:t.color,width:t.width||2,clampToGround:!0})}}else{let i=e.rectangle.coordinates?.getValue();i&&(this._entity.rectangle=new a.RectangleGraphics({coordinates:i,material:t.color,heightReference:a.HeightReference.CLAMP_TO_GROUND}))}}else if(e instanceof a.GroundPrimitive){let i=e.geometryInstances,r=Array.isArray(i)?i[0]:i;if(!r.geometry.attributes.position)return;let o=r.geometry.attributes.position.values,l=[];for(let s=0;s<o.length;s+=3)l.push(new a.Cartesian3(o[s],o[s+1],o[s+2]));t.outline?this._entity.polyline=new a.PolylineGraphics({positions:l,material:t.color,width:t.width||2,clampToGround:!0}):this._entity.polygon=new a.PolygonGraphics({hierarchy:new a.PolygonHierarchy(l),material:t.color,heightReference:a.HeightReference.CLAMP_TO_GROUND,classificationType:a.ClassificationType.BOTH})}}hide(){this._entity&&(this._entity.show=!1)}destroy(){this._entities.contains(this._entity)&&this._entities.remove(this._entity)}get color(){return this._color}set color(e){this._color=e}get entity(){return this._entity}};var C=class n{static instances=new WeakMap;_surface;_silhouette;_color=d.Color.RED;constructor(e){this._surface=new b(e),this._silhouette=new T(e),this._surface.color=this._color,this._silhouette.color=this._color}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,i=n.instances.get(t);i&&(i.hide(),i._surface&&i._surface.destroy(),i._silhouette&&i._silhouette.destroy(),n.instances.delete(t))}show(e,t={color:this._color}){this.hide();let i=this._getObject(e);if((0,d.defined)(i))return i instanceof d.Cesium3DTileFeature?this._silhouette.show(i,t):i instanceof d.Entity&&i.model?this._silhouette.show(i,t):this._surface.show(i,t)}_getObject(e){if((0,d.defined)(e)){if(e instanceof d.Entity||e instanceof d.Cesium3DTileFeature||e instanceof d.GroundPrimitive)return e;if(e.id instanceof d.Entity)return e.id;if(e.primitive instanceof d.GroundPrimitive)return e.primitive}}hide(){this._surface.hide(),this._silhouette.hide()}get color(){return this._color}set color(e){this._color=e,this._surface.color=e,this._silhouette.color=e}};var F=require("cesium");var N=require("cesium");var H=require("cesium");function w(n,e){if(e.size===0)return new H.Rectangle;let t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,l=Array.from(e.keys()),s=Math.min(...l),h=e.get(s);if(h){let{start:m,end:f}=h,E=n.tileXYToRectangle(m.x,m.y,s),I=n.tileXYToRectangle(f.x,f.y,s);t=Math.min(E.west,t),i=Math.min(I.south,i),r=Math.max(I.east,r),o=Math.max(E.north,o)}return new H.Rectangle(t,i,r,o)}var g=class{_terrainProvider;_rectangle;_tileRanges;_ready=!1;_credit;_isCustom;constructor(e){this._terrainProvider=e.terrainProvider,this._tileRanges=e.tileRanges,this._credit=e.credit||"custom",this._isCustom=e.isCustom!==void 0?e.isCustom:!0,this._rectangle=w(e.terrainProvider.tilingScheme,e.tileRanges),e.tileRanges.forEach((t,i)=>{this._terrainProvider.availability?.addAvailableTileRange(i,t.start.x,t.start.y,t.end.x,t.end.y)}),this._ready=!0}contains(e,t,i){if(this._tileRanges.size===0||!this._tileRanges.has(i))return!1;let r=this._tileRanges.get(i);return e>=r.start.x&&e<=r.end.x&&t>=r.start.y&&t<=r.end.y}requestTileGeometry(e,t,i,r){if(!(!this._ready||!this.contains(e,t,i)))return this._terrainProvider.requestTileGeometry(e,t,i,r)}getTileDataAvailable(e,t,i){if(this._tileRanges.size===0||!this._tileRanges.has(i))return!1;let r=this._tileRanges.get(i);return e>=r.start.x&&e<=r.end.x&&t>=r.start.y&&t<=r.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,i,r){let o=r?.credit||"custom",l=await N.CesiumTerrainProvider.fromUrl(t,{...r,credit:o});return new e({terrainProvider:l,tileRanges:i,credit:o})}e.fromUrl=n})(g||={});var p=class extends Array{add(e){if(Array.isArray(e)){for(let i of e)this.add(i);return this.length}let t;return e instanceof g?t=e:t=new g(e),this.push(t)}remove(e){if(Array.isArray(e))return e.forEach(i=>this.remove(i)),this;let t=this.indexOf(e);return t>=0&&this.splice(t,1),this}removeAll(){this.length=0}};var A=class{_terrainAreas=new p;_terrainProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(e){this._terrainProvider=e.terrainProvider,this._fallbackProvider=e.fallbackProvider||new F.EllipsoidTerrainProvider,this._tilingScheme=e.terrainProvider.tilingScheme,this._terrainAreas=new p(...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,i){return this._terrainProvider.loadTileDataAvailability(e,t,i)}getLevelMaximumGeometricError(e){return this._terrainProvider.getLevelMaximumGeometricError(e)}requestTileGeometry(e,t,i,r){if(this._ready){for(let o of this._terrainAreas)if(o.contains(e,t,i))return o.requestTileGeometry(e,t,i,r);return this._terrainProvider.getTileDataAvailable(e,t,i)?this._terrainProvider.requestTileGeometry(e,t,i,r):this._fallbackProvider.requestTileGeometry(e,t,i,r)}}getTileDataAvailable(e,t,i){for(let r of this._terrainAreas)if(r.contains(e,t,i))return r.getTileDataAvailable(e,t,i);return this._terrainProvider.getTileDataAvailable(e,t,i)}};var z=require("cesium");var D=require("cesium");function R(n,e){if((0,D.defined)(n)&&(0,D.defined)(e)){let{camera:t}=n;e.camera.position=t.positionWC.clone(),e.camera.direction=t.directionWC.clone(),e.camera.up=t.upWC.clone()}}function k(n,e,t){let i={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},r=new z.Viewer(e,{...i,...t});R(n,r);let o=n.imageryLayers;r.imageryLayers.removeAll();for(let h=0;h<o.length;h++){let m=o.get(h);r.imageryLayers.addImageryProvider(m.imageryProvider,h)}r.clock.startTime=n.clock.startTime.clone(),r.clock.stopTime=n.clock.stopTime.clone(),r.clock.currentTime=n.clock.currentTime.clone(),r.clock.multiplier=n.clock.multiplier,r.clock.clockStep=n.clock.clockStep,r.clock.clockRange=n.clock.clockRange,r.clock.shouldAnimate=n.clock.shouldAnimate,r.scene.globe.enableLighting=n.scene.globe.enableLighting,r.scene.globe.depthTestAgainstTerrain=n.scene.globe.depthTestAgainstTerrain,r.scene.screenSpaceCameraController.enableCollisionDetection=n.scene.screenSpaceCameraController.enableCollisionDetection;let l=n.scene.screenSpaceCameraController.tiltEventTypes;l&&(r.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(l)?[...l]:l);let s=n.scene.screenSpaceCameraController.zoomEventTypes;return s&&(r.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(s)?[...s]:s),r}
|
|
1
|
+
"use strict";var L=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var $=(n,e)=>{for(var t in e)L(n,t,{get:e[t],enumerable:!0})},K=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of U(e))!X.call(n,r)&&r!==t&&L(n,r,{get:()=>e[r],enumerable:!(i=q(e,r))||i.enumerable});return n};var J=n=>K(L({},"__esModule",{value:!0}),n);var Q={};$(Q,{Collection:()=>y,Highlight:()=>C,HybridTerrainProvider:()=>A,TerrainArea:()=>g,TerrainAreaCollection:()=>p,TerrainVisualizer:()=>v,cloneViewer:()=>k,computeRectangle:()=>w,isGetterOnly:()=>P,syncCamera:()=>R});module.exports=J(Q);var _=require("cesium");var c=require("cesium");var v=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 y({collection:e.entities,tag:n.tag.default}),t&&(t.colors&&Object.entries(t.colors).forEach(([i,r])=>{this._colors.set(i,r)}),t.tile!==void 0&&(this._visible=t.tile),t.activeLevel!==void 0&&(this._level=t.activeLevel),t.terrainProvider&&this.setTerrainProvider(t.terrainProvider))}setTerrainProvider(e){this._terrainProvider=e,this.update()}update(){this.clear(),this._visible&&this.show(this._level)}clear(){this._collection.remove(this._collection.tags)}show(e=15){if(!this._terrainProvider)return;this._collection.remove(n.tag.grid),this._level=e,this._ensureTileCoordinatesLayer();let t=this._getVisibleRectangle();if(!t||!this._isValidRectangle(t)){console.warn("Invalid visible rectangle detected, skipping grid display");return}this._displayTileGrid(t,e),this._visible=!0}_ensureTileCoordinatesLayer(){this._tileCoordinatesLayer||(this._tileCoordinatesLayer=this._viewer.imageryLayers.addImageryProvider(new c.TileCoordinatesImageryProvider({tilingScheme:this._terrainProvider.tilingScheme,color:c.Color.YELLOW})))}_isValidRectangle(e){return e&&Number.isFinite(e.west)&&Number.isFinite(e.south)&&Number.isFinite(e.east)&&Number.isFinite(e.north)&&e.west<=e.east&&e.south<=e.north}_displayTileGrid(e,t){let i=this._terrainProvider.tilingScheme;try{let r=this._calculateTileBounds(e,t,i);this._generateVisibleTiles(r,t,i).forEach(l=>{this._collection.add(l.entity,n.tag.grid)})}catch(r){console.error("Error displaying tile grid:",r)}}_calculateTileBounds(e,t,i){let r=i.positionToTileXY(c.Rectangle.northwest(e),t),o=i.positionToTileXY(c.Rectangle.southeast(e),t);if(!r||!o)throw new Error("Failed to calculate tile bounds");return{start:r,end:o}}_generateVisibleTiles(e,t,i){let r=[],l=Math.min(e.end.x-e.start.x+1,100),s=Math.min(e.end.y-e.start.y+1,100);for(let h=e.start.x;h<e.start.x+l;h++)for(let m=e.start.y;m<e.start.y+s;m++)try{let f=this._createTileEntity(h,m,t,i);f&&r.push({entity:f})}catch(f){console.warn(`Error creating tile (${h}, ${m}, ${t}):`,f)}return r}_createTileEntity(e,t,i,r){let o=r.tileXYToRectangle(e,t,i);if(!this._isValidRectangle(o))return null;let l=this._getTileColor(e,t,i),s=n.createRectangle(o,l.withAlpha(.3));return s.properties?.addProperty("tileX",e),s.properties?.addProperty("tileY",t),s.properties?.addProperty("tileLevel",i),s}_getTileColor(e,t,i){if(!this._terrainProvider)return this._colors.get("fallback")||c.Color.TRANSPARENT;for(let r of this._terrainProvider.terrainAreas)if(r.contains(e,t,i))return r.isCustom?this._colors.get("custom")||c.Color.RED:this._colors.get("default")||c.Color.BLUE;return this._terrainProvider.getTileDataAvailable(e,t,i)?this._colors.get("default")||c.Color.BLUE:this._colors.get("fallback")||c.Color.GRAY}hide(){this._collection.remove(n.tag.grid),this._tileCoordinatesLayer&&(this._viewer.imageryLayers.remove(this._tileCoordinatesLayer),this._tileCoordinatesLayer=void 0),this._visible=!1}setColors(e){Object.entries(e).forEach(([t,i])=>{this._colors.set(t,i)}),this.update()}flyTo(e,t){let{rectangle:i}=e;this._viewer.camera.flyTo({destination:i,...t,complete:()=>{this._visible&&this.update()}})}_getVisibleRectangle(){return this._viewer.camera.computeViewRectangle()}get level(){return this._level}set level(e){this._level=e,this._visible&&this.update()}get visible(){return this._visible}get collection(){return this._collection}get viewer(){return this._viewer}get colors(){return this._colors}get terrainProvider(){return this._terrainProvider}};(i=>{i.tag={default:"Terrain Visualizer",boundary:"Terrain Visualizer Boundary",grid:"Terrain Visualizer Tile Grid"};function e(r,o){return new c.Entity({rectangle:{coordinates:r,material:o,heightReference:c.HeightReference.CLAMP_TO_GROUND}})}i.createRectangle=e;function t(r,o,l){let s=l?.tag||"terrain_area_visualization",h=l?.color||c.Color.RED,m=l?.maxTilesToShow||100,f=l?.show??!0,E=l?.alpha||.7,I=l?.tileAlpha||.2,S=new y({collection:o.entities,tag:s}),{rectangle:B}=r;if(S.add(i.createRectangle(B,h.withAlpha(E)),s),f&&r.tileRanges.size>0){let{tilingScheme:Y}=r.terrainProvider,O=0;r.tileRanges.forEach((x,j)=>{for(let V=x.start.x;V<=x.end.x&&O<m;V++)for(let M=x.start.y;M<=x.end.y&&O<m;M++){let W=Y.tileXYToRectangle(V,M,j);S.add(e(W,h.withAlpha(I)),`${s}_tile`),O++}})}return S}i.visualize=t})(v||={});function P(n,e){let t=!1,i=Object.getOwnPropertyDescriptor(n,e);if(!i){let r=Object.getPrototypeOf(n);for(;r&&!i;)i=Object.getOwnPropertyDescriptor(r,e),r=Object.getPrototypeOf(r)}return i&&i.get&&!i.set&&(t=!0),t}var G=class n{static symbol=Symbol("cesium-item-tag");tag;collection;_valuesCache=null;_tagMap=new Map;_eventListeners=new Map;constructor({collection:e,tag:t}){this.tag=t||"default",this.collection=e}[Symbol.iterator](){return this.values[Symbol.iterator]()}_emit(e,t){let i=this._eventListeners.get(e);if(i){let r={type:e,...t};i.forEach(o=>o(r))}}_addToTagMap(e,t){this._tagMap.has(t)||this._tagMap.set(t,new Set),this._tagMap.get(t)?.add(e)}_removeFromTagMap(e){let t=e[n.symbol],i=this._tagMap.get(t);i&&(i.delete(e),i.size===0&&this._tagMap.delete(t))}_invalidateCache(){this._valuesCache=null}addEventListener(e,t){return this._eventListeners.has(e)||this._eventListeners.set(e,new Set),this._eventListeners.get(e)?.add(t),this}removeEventListener(e,t){return this._eventListeners.get(e)?.delete(t),this}add(e,t=this.tag,i){return Array.isArray(e)?e.forEach(r=>{this.add(r,t)}):(Object.defineProperty(e,n.symbol,{value:t,enumerable:!1,writable:!0,configurable:!0}),this.collection.add(e,i),this._addToTagMap(e,t),this._invalidateCache(),this._emit("add",{items:[e],tag:t})),e}contains(e){if(typeof e=="object")return this.collection.contains(e);let t=this._tagMap.get(e);return!!t&&t.size>0}remove(e){if(typeof e=="object"&&!Array.isArray(e)){let r=this.collection.remove(e);return r&&(this._removeFromTagMap(e),this._invalidateCache(),this._emit("remove",{items:[e]})),r}if(Array.isArray(e)){if(e.length===0)return!1;let r=!1;for(let o of e)this.remove(o)&&(r=!0);return r}let t=this.get(e);if(t.length===0)return!1;let i=!1;for(let r of t)this.remove(r)&&(i=!0);return i}removeAll(){this._tagMap.clear(),this.collection.removeAll(),this._invalidateCache(),this._emit("clear")}get values(){if(this.collection instanceof _.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,_.defined)(i.show)&&(i.show=!0);return this}hide(e){let t=this.get(e);for(let i of t)(0,_.defined)(i.show)&&(i.show=!1);return this}toggle(e){let t=this.get(e);for(let i of t)(0,_.defined)(i.show)&&(i.show=!i.show);return this}setProperty(e,t,i=this.tag){let r=this.get(i);for(let o of r)if(e in o&&typeof o[e]!="function"){if(P(o,e))throw Error(`Cannot set read-only property '${String(e)}' on ${o.constructor.name}`);o[e]=t}return this}filter(e,t){return(t?this.get(t):this.values).filter(e)}forEach(e,t){(t?this.get(t):this.values).forEach((r,o)=>e(r,o))}map(e,t){return(t?this.get(t):this.values).map(e)}find(e,t){return(t?this.get(t):this.values).find(e)}},y=G;var d=require("cesium");var u=require("cesium"),T=class{_color=u.Color.RED;_silhouette;_composite;_stages;_entity;constructor(e){this._stages=e.scene.postProcessStages,this._silhouette=u.PostProcessStageLibrary.createEdgeDetectionStage(),this._silhouette.uniforms.color=this._color,this._silhouette.uniforms.length=.01,this._silhouette.selected=[],this._composite=u.PostProcessStageLibrary.createSilhouetteStage([this._silhouette]),this._stages.add(this._composite)}show(e,t){if(!(!(0,u.defined)(e)||this._silhouette.selected[0]===e))if(e instanceof u.Cesium3DTileFeature)this._silhouette.uniforms.color=t?.color||this._color,this._silhouette.selected.push(e);else{if(!e.model)return;this._entity=e,e.model.silhouetteSize=new u.ConstantProperty(t?.width||2),e.model.silhouetteColor=new u.ConstantProperty(t?.color||this._color)}}hide(){this._silhouette.selected.length>0&&(this._silhouette.selected=[]),this._entity?.model&&(this._entity.model.silhouetteColor=new u.ConstantProperty(u.Color.TRANSPARENT),this._entity=void 0)}destroy(){this.hide(),this._composite&&this._stages.remove(this._composite)}get color(){return this._color}set color(e){this._color=e}};var a=require("cesium"),b=class{_color=a.Color.RED;_entity;_entities;constructor(e){this._entities=e.entities,this._entity=this._entities.add(new a.Entity({id:`highlight-entity-${Math.random().toString(36).substring(2)}`,show:!1}))}show(e,t){if(!(!(0,a.defined)(e)||!this._entity)){this._clearGeometries();try{if(e instanceof a.Entity&&(e.polygon||e.polyline||e.rectangle))this._update(e,t);else if(e instanceof a.GroundPrimitive)this._update(e,t);else return;return this._entity.show=!0,this._entity}catch(i){console.error("Failed to highlight object:",i);return}}}_clearGeometries(){this._entity.polygon=void 0,this._entity.polyline=void 0,this._entity.rectangle=void 0}_update(e,t={color:this._color,outline:!1,width:2}){if(e instanceof a.Entity){if(e.polygon)if(t.outline){let i=e.polygon.hierarchy?.getValue();if(i&&i.positions){let r;i.positions.length>0&&!a.Cartesian3.equals(i.positions[0],i.positions[i.positions.length-1])?r=[...i.positions,i.positions[0]]:r=i.positions,this._entity.polyline=new a.PolylineGraphics({positions:r,material:t.color,width:t.width||2,clampToGround:!0})}}else{let i=e.polygon.hierarchy?.getValue();i&&(this._entity.polygon=new a.PolygonGraphics({hierarchy:i,material:t.color,heightReference:a.HeightReference.CLAMP_TO_GROUND,classificationType:e.polygon.classificationType?.getValue()||a.ClassificationType.BOTH}))}else if(e.polyline){let i=e.polyline.positions?.getValue();if(i){let r=e.polyline.width?.getValue();this._entity.polyline=new a.PolylineGraphics({positions:i,material:t.color,width:r+(t.width||2),clampToGround:!0})}}else if(e.rectangle)if(t.outline){let i=e.rectangle.coordinates?.getValue();if(i){let r=[a.Cartesian3.fromRadians(i.west,i.north),a.Cartesian3.fromRadians(i.east,i.north),a.Cartesian3.fromRadians(i.east,i.south),a.Cartesian3.fromRadians(i.west,i.south),a.Cartesian3.fromRadians(i.west,i.north)];this._entity.polyline=new a.PolylineGraphics({positions:r,material:t.color,width:t.width||2,clampToGround:!0})}}else{let i=e.rectangle.coordinates?.getValue();i&&(this._entity.rectangle=new a.RectangleGraphics({coordinates:i,material:t.color,heightReference:a.HeightReference.CLAMP_TO_GROUND}))}}else if(e instanceof a.GroundPrimitive){let i=e.geometryInstances,r=Array.isArray(i)?i[0]:i;if(!r.geometry.attributes.position)return;let o=r.geometry.attributes.position.values,l=[];for(let s=0;s<o.length;s+=3)l.push(new a.Cartesian3(o[s],o[s+1],o[s+2]));t.outline?this._entity.polyline=new a.PolylineGraphics({positions:l,material:t.color,width:t.width||2,clampToGround:!0}):this._entity.polygon=new a.PolygonGraphics({hierarchy:new a.PolygonHierarchy(l),material:t.color,heightReference:a.HeightReference.CLAMP_TO_GROUND,classificationType:a.ClassificationType.BOTH})}}hide(){this._entity&&(this._entity.show=!1)}destroy(){this._entities.contains(this._entity)&&this._entities.remove(this._entity)}get color(){return this._color}set color(e){this._color=e}get entity(){return this._entity}};var C=class n{static instances=new WeakMap;_surface;_silhouette;_color=d.Color.RED;constructor(e){this._surface=new b(e),this._silhouette=new T(e),this._surface.color=this._color,this._silhouette.color=this._color}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,i=n.instances.get(t);i&&(i.hide(),i._surface&&i._surface.destroy(),i._silhouette&&i._silhouette.destroy(),n.instances.delete(t))}show(e,t={color:this._color}){this.hide();let i=this._getObject(e);if((0,d.defined)(i))return i instanceof d.Cesium3DTileFeature?this._silhouette.show(i,t):i instanceof d.Entity&&i.model?this._silhouette.show(i,t):this._surface.show(i,t)}_getObject(e){if((0,d.defined)(e)){if(e instanceof d.Entity||e instanceof d.Cesium3DTileFeature||e instanceof d.GroundPrimitive)return e;if(e.id instanceof d.Entity)return e.id;if(e.primitive instanceof d.GroundPrimitive)return e.primitive}}hide(){this._surface.hide(),this._silhouette.hide()}get color(){return this._color}set color(e){this._color=e,this._surface.color=e,this._silhouette.color=e}};var F=require("cesium");var N=require("cesium");var H=require("cesium");function w(n,e){if(e.size===0)return new H.Rectangle;let t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,l=Array.from(e.keys()),s=Math.min(...l),h=e.get(s);if(h){let{start:m,end:f}=h,E=n.tileXYToRectangle(m.x,m.y,s),I=n.tileXYToRectangle(f.x,f.y,s);t=Math.min(E.west,t),i=Math.min(I.south,i),r=Math.max(I.east,r),o=Math.max(E.north,o)}return new H.Rectangle(t,i,r,o)}var g=class{_terrainProvider;_rectangle;_tileRanges;_ready=!1;_credit;_isCustom;constructor(e){this._terrainProvider=e.terrainProvider,this._tileRanges=e.tileRanges,this._credit=e.credit||"custom",this._isCustom=e.isCustom!==void 0?e.isCustom:!0,this._rectangle=w(e.terrainProvider.tilingScheme,e.tileRanges),e.tileRanges.forEach((t,i)=>{this._terrainProvider.availability?.addAvailableTileRange(i,t.start.x,t.start.y,t.end.x,t.end.y)}),this._ready=!0}contains(e,t,i){if(this._tileRanges.size===0||!this._tileRanges.has(i))return!1;let r=this._tileRanges.get(i);return e>=r.start.x&&e<=r.end.x&&t>=r.start.y&&t<=r.end.y}requestTileGeometry(e,t,i,r){if(!(!this._ready||!this.contains(e,t,i)))return this._terrainProvider.requestTileGeometry(e,t,i,r)}getTileDataAvailable(e,t,i){if(this._tileRanges.size===0||!this._tileRanges.has(i))return!1;let r=this._tileRanges.get(i);return e>=r.start.x&&e<=r.end.x&&t>=r.start.y&&t<=r.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,i,r){let o=r?.credit||"custom",l=await N.CesiumTerrainProvider.fromUrl(t,{...r,credit:o});return new e({terrainProvider:l,tileRanges:i,credit:o})}e.fromUrl=n})(g||={});var p=class extends Array{add(e){if(Array.isArray(e)){for(let i of e)this.add(i);return this.length}let t;return e instanceof g?t=e:t=new g(e),this.push(t)}remove(e){if(Array.isArray(e))return e.forEach(i=>this.remove(i)),this;let t=this.indexOf(e);return t>=0&&this.splice(t,1),this}removeAll(){this.length=0}};var A=class{_terrainAreas=new p;_terrainProvider;_fallbackProvider;_tilingScheme;_ready=!1;_availability;constructor(e){this._terrainProvider=e.terrainProvider,this._fallbackProvider=e.fallbackProvider||new F.EllipsoidTerrainProvider,this._tilingScheme=e.terrainProvider.tilingScheme,this._terrainAreas=new p(...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,i){return this._terrainProvider.loadTileDataAvailability(e,t,i)}getLevelMaximumGeometricError(e){return this._terrainProvider.getLevelMaximumGeometricError(e)}requestTileGeometry(e,t,i,r){if(this._ready){for(let o of this._terrainAreas)if(o.contains(e,t,i))return o.requestTileGeometry(e,t,i,r);return this._terrainProvider.getTileDataAvailable(e,t,i)?this._terrainProvider.requestTileGeometry(e,t,i,r):this._fallbackProvider.requestTileGeometry(e,t,i,r)}}getTileDataAvailable(e,t,i){for(let r of this._terrainAreas)if(r.contains(e,t,i))return r.getTileDataAvailable(e,t,i);return this._terrainProvider.getTileDataAvailable(e,t,i)}};var z=require("cesium");var D=require("cesium");function R(n,e){if((0,D.defined)(n)&&(0,D.defined)(e)){let{camera:t}=n;e.camera.position=t.positionWC.clone(),e.camera.direction=t.directionWC.clone(),e.camera.up=t.upWC.clone()}}function k(n,e,t){let i={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},r=new z.Viewer(e,{...i,...t});R(n,r);let o=n.imageryLayers;r.imageryLayers.removeAll();for(let h=0;h<o.length;h++){let m=o.get(h);r.imageryLayers.addImageryProvider(m.imageryProvider,h)}r.clock.startTime=n.clock.startTime.clone(),r.clock.stopTime=n.clock.stopTime.clone(),r.clock.currentTime=n.clock.currentTime.clone(),r.clock.multiplier=n.clock.multiplier,r.clock.clockStep=n.clock.clockStep,r.clock.clockRange=n.clock.clockRange,r.clock.shouldAnimate=n.clock.shouldAnimate,r.scene.globe.enableLighting=n.scene.globe.enableLighting,r.scene.globe.depthTestAgainstTerrain=n.scene.globe.depthTestAgainstTerrain,r.scene.screenSpaceCameraController.enableCollisionDetection=n.scene.screenSpaceCameraController.enableCollisionDetection;let l=n.scene.screenSpaceCameraController.tiltEventTypes;l&&(r.scene.screenSpaceCameraController.tiltEventTypes=Array.isArray(l)?[...l]:l);let s=n.scene.screenSpaceCameraController.zoomEventTypes;return s&&(r.scene.screenSpaceCameraController.zoomEventTypes=Array.isArray(s)?[...s]:s),r}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk-RXMNSDKR.js";import{a as R,b as S,c as V,d as D}from"./chunk-D2H7O3WV.js";import{a as x,b as A}from"./chunk-2JNRK7SN.js";import{a as E,b as O,c as G}from"./chunk-YHYFSR66.js";import{Cesium3DTileFeature as P,Color as z,defined as H,Entity as y,GroundPrimitive as T}from"cesium";import{Cesium3DTileFeature as I,Color as _,ConstantProperty as p,defined as F,PostProcessStageLibrary as m}from"cesium";var n=class{_color=_.RED;_silhouette;_composite;_stages;_entity;constructor(t){this._stages=t.scene.postProcessStages,this._silhouette=m.createEdgeDetectionStage(),this._silhouette.uniforms.color=this._color,this._silhouette.uniforms.length=.01,this._silhouette.selected=[],this._composite=m.createSilhouetteStage([this._silhouette]),this._stages.add(this._composite)}show(t,i){if(!(!F(t)||this._silhouette.selected[0]===t))if(t instanceof I)this.
|
|
1
|
+
import"./chunk-RXMNSDKR.js";import{a as R,b as S,c as V,d as D}from"./chunk-D2H7O3WV.js";import{a as x,b as A}from"./chunk-2JNRK7SN.js";import{a as E,b as O,c as G}from"./chunk-YHYFSR66.js";import{Cesium3DTileFeature as P,Color as z,defined as H,Entity as y,GroundPrimitive as T}from"cesium";import{Cesium3DTileFeature as I,Color as _,ConstantProperty as p,defined as F,PostProcessStageLibrary as m}from"cesium";var n=class{_color=_.RED;_silhouette;_composite;_stages;_entity;constructor(t){this._stages=t.scene.postProcessStages,this._silhouette=m.createEdgeDetectionStage(),this._silhouette.uniforms.color=this._color,this._silhouette.uniforms.length=.01,this._silhouette.selected=[],this._composite=m.createSilhouetteStage([this._silhouette]),this._stages.add(this._composite)}show(t,i){if(!(!F(t)||this._silhouette.selected[0]===t))if(t instanceof I)this._silhouette.uniforms.color=i?.color||this._color,this._silhouette.selected.push(t);else{if(!t.model)return;this._entity=t,t.model.silhouetteSize=new p(i?.width||2),t.model.silhouetteColor=new p(i?.color||this._color)}}hide(){this._silhouette.selected.length>0&&(this._silhouette.selected=[]),this._entity?.model&&(this._entity.model.silhouetteColor=new p(_.TRANSPARENT),this._entity=void 0)}destroy(){this.hide(),this._composite&&this._stages.remove(this._composite)}get color(){return this._color}set color(t){this._color=t}};import{Cartesian3 as r,ClassificationType as w,Color as M,defined as N,Entity as f,GroundPrimitive as v,HeightReference as d,PolygonGraphics as C,PolygonHierarchy as L,PolylineGraphics as u,RectangleGraphics as U}from"cesium";var l=class{_color=M.RED;_entity;_entities;constructor(t){this._entities=t.entities,this._entity=this._entities.add(new f({id:`highlight-entity-${Math.random().toString(36).substring(2)}`,show:!1}))}show(t,i){if(!(!N(t)||!this._entity)){this._clearGeometries();try{if(t instanceof f&&(t.polygon||t.polyline||t.rectangle))this._update(t,i);else if(t instanceof v)this._update(t,i);else return;return this._entity.show=!0,this._entity}catch(e){console.error("Failed to highlight object:",e);return}}}_clearGeometries(){this._entity.polygon=void 0,this._entity.polyline=void 0,this._entity.rectangle=void 0}_update(t,i={color:this._color,outline:!1,width:2}){if(t instanceof f){if(t.polygon)if(i.outline){let e=t.polygon.hierarchy?.getValue();if(e&&e.positions){let o;e.positions.length>0&&!r.equals(e.positions[0],e.positions[e.positions.length-1])?o=[...e.positions,e.positions[0]]:o=e.positions,this._entity.polyline=new u({positions:o,material:i.color,width:i.width||2,clampToGround:!0})}}else{let e=t.polygon.hierarchy?.getValue();e&&(this._entity.polygon=new C({hierarchy:e,material:i.color,heightReference:d.CLAMP_TO_GROUND,classificationType:t.polygon.classificationType?.getValue()||w.BOTH}))}else if(t.polyline){let e=t.polyline.positions?.getValue();if(e){let o=t.polyline.width?.getValue();this._entity.polyline=new u({positions:e,material:i.color,width:o+(i.width||2),clampToGround:!0})}}else if(t.rectangle)if(i.outline){let e=t.rectangle.coordinates?.getValue();if(e){let o=[r.fromRadians(e.west,e.north),r.fromRadians(e.east,e.north),r.fromRadians(e.east,e.south),r.fromRadians(e.west,e.south),r.fromRadians(e.west,e.north)];this._entity.polyline=new u({positions:o,material:i.color,width:i.width||2,clampToGround:!0})}}else{let e=t.rectangle.coordinates?.getValue();e&&(this._entity.rectangle=new U({coordinates:e,material:i.color,heightReference:d.CLAMP_TO_GROUND}))}}else if(t instanceof v){let e=t.geometryInstances,o=Array.isArray(e)?e[0]:e;if(!o.geometry.attributes.position)return;let c=o.geometry.attributes.position.values,g=[];for(let h=0;h<c.length;h+=3)g.push(new r(c[h],c[h+1],c[h+2]));i.outline?this._entity.polyline=new u({positions:g,material:i.color,width:i.width||2,clampToGround:!0}):this._entity.polygon=new C({hierarchy:new L(g),material:i.color,heightReference:d.CLAMP_TO_GROUND,classificationType:w.BOTH})}}hide(){this._entity&&(this._entity.show=!1)}destroy(){this._entities.contains(this._entity)&&this._entities.remove(this._entity)}get color(){return this._color}set color(t){this._color=t}get entity(){return this._entity}};var a=class s{static instances=new WeakMap;_surface;_silhouette;_color=z.RED;constructor(t){this._surface=new l(t),this._silhouette=new n(t),this._surface.color=this._color,this._silhouette.color=this._color}static getInstance(t){let i=t.container;return s.instances.has(i)||s.instances.set(i,new s(t)),s.instances.get(i)}static releaseInstance(t){let i=t.container,e=s.instances.get(i);e&&(e.hide(),e._surface&&e._surface.destroy(),e._silhouette&&e._silhouette.destroy(),s.instances.delete(i))}show(t,i={color:this._color}){this.hide();let e=this._getObject(t);if(H(e))return e instanceof P?this._silhouette.show(e,i):e instanceof y&&e.model?this._silhouette.show(e,i):this._surface.show(e,i)}_getObject(t){if(H(t)){if(t instanceof y||t instanceof P||t instanceof T)return t;if(t.id instanceof y)return t.id;if(t.primitive instanceof T)return t.primitive}}hide(){this._surface.hide(),this._silhouette.hide()}get color(){return this._color}set color(t){this._color=t,this._surface.color=t,this._silhouette.color=t}};export{G as Collection,a as Highlight,D as HybridTerrainProvider,S as TerrainArea,V as TerrainAreaCollection,E as TerrainVisualizer,A as cloneViewer,R as computeRectangle,O as isGetterOnly,x as syncCamera};
|