leiting-bim 2.1.135 → 2.1.136
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/leiting-bim.es.js +1 -1
- package/leiting-bim.umd.js +1 -1
- package/leitingbim.css +1 -1
- package/package.json +1 -1
- package/plugins/cesium-core/dist/cesium-core.mjs +1505 -1315
- package/plugins/cesium-core/dist/cesium-core.mjs.map +1 -1
- package/plugins/cesium-core/dist/cesium-core.umd.js +25 -25
- package/plugins/cesium-core/dist/cesium-core.umd.js.map +1 -1
- package/plugins/cesium-core/dist/components/HtmlOverlayLabelPool.d.ts +36 -0
- package/plugins/cesium-core/dist/components/draw/handlers/LineDrawer.d.ts +1 -0
- package/plugins/cesium-core/dist/components/draw/handlers/PolygonDrawer.d.ts +1 -0
- package/plugins/cesium-core/package.json +1 -1
- package/plugins/cesium-vue/dist/HtmlOverlayLabelPool-CbiNlyAM.js +510 -0
- package/plugins/cesium-vue/dist/HtmlOverlayLabelPool-CbiNlyAM.js.map +1 -0
- package/plugins/cesium-vue/dist/cesium-vue/src/components/marker-bubble/index.d.ts +87 -1
- package/plugins/cesium-vue/dist/cesium-vue/src/components/marker-manage/index.d.ts +12 -0
- package/plugins/cesium-vue/dist/cesium-vue/src/index.d.ts +3 -2
- package/plugins/cesium-vue/dist/components/marker-bubble.js +200 -73
- package/plugins/cesium-vue/dist/components/marker-bubble.js.map +1 -1
- package/plugins/cesium-vue/dist/components/marker-manage.js +536 -511
- package/plugins/cesium-vue/dist/components/marker-manage.js.map +1 -1
- package/plugins/cesium-vue/dist/components/measurement.js +1 -1
- package/plugins/cesium-vue/dist/index.js +39 -37
- package/plugins/cesium-vue/dist/index.js.map +1 -1
- package/plugins/cesium-vue/package.json +1 -1
- package/plugins/theme-chalk/dist/theme-chalk.css +33 -0
- package/plugins/theme-chalk/package.json +1 -1
- package/plugins/utils/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(D,te){typeof exports=="object"&&typeof module<"u"?te(exports):typeof define=="function"&&define.amd?define(["exports"],te):(D=typeof globalThis<"u"?globalThis:D||self,te(D.CesiumCore={}))})(this,(function(D){"use strict";var Oo=Object.defineProperty;var Ro=(D,te,V)=>te in D?Oo(D,te,{enumerable:!0,configurable:!0,writable:!0,value:V}):D[te]=V;var h=(D,te,V)=>Ro(D,typeof te!="symbol"?te+"":te,V);class te{constructor(t,e,i){h(this,"Cesium");h(this,"viewer");h(this,"labelPool");h(this,"threshold");h(this,"displayLimit");h(this,"maxLevel");h(this,"debugCurrentGrids");h(this,"levels");h(this,"points",[]);h(this,"gridLayers",new Map);h(this,"debugGrids",[]);h(this,"_updateFn");h(this,"clusterTheme");h(this,"pointTheme");h(this,"centralPointMode");h(this,"minGlobalPointCount");h(this,"groupByTheme");h(this,"tilingScheme");h(this,"terrainLevelOffset");h(this,"debugTileCoordLayer",null);h(this,"levelIndexByTileLevel",new Map);h(this,"_lastTileProvider",null);h(this,"_updateTimer",null);h(this,"_updateDelay",100);h(this,"_tilesRetryCount",0);h(this,"_tilesRetryMax",100);h(this,"_cameraDirty",!1);h(this,"_tileLoadListener",null);h(this,"_cameraChangedHandler",null);h(this,"defaultMinLevel",0);h(this,"defaultMaxLevel",28);h(this,"maxRefineLevels",2);this.Cesium=t,this.viewer=e,this.labelPool=i.labelPool,this.threshold=i.threshold??10,this.displayLimit=i.displayLimit??100,this.maxLevel=i.maxLevel??5,this.debugCurrentGrids=i.debugCurrentGrids??!1,this.clusterTheme=i.clusterTheme??"cluster-label",this.pointTheme=i.pointTheme??"point-label",this.centralPointMode=i.centralPointMode??"central",this.minGlobalPointCount=i.minGlobalPointCount??0,this.groupByTheme=i.groupByTheme??!1,this.terrainLevelOffset=i.terrainLevelOffset??2;const o=this.viewer.scene&&this.viewer.scene.globe,s=o&&o._surface,r=s&&s._tileProvider,n=(r==null?void 0:r.tilingScheme)||new this.Cesium.GeographicTilingScheme;this._lastTileProvider=r,this.tilingScheme=n,this.levels=this._createLevels(),this._buildLevels(),this._updateFn=this._update.bind(this),this.debugCurrentGrids&&this._ensureDebugImageryLayer(),o&&(this._tileLoadListener=l=>{l===0&&this._cameraDirty&&(this._cameraDirty=!1,this._scheduleUpdate())},o.tileLoadProgressEvent.addEventListener(this._tileLoadListener)),this._cameraChangedHandler=()=>{this._update()},this.viewer.camera.changed.addEventListener(this._cameraChangedHandler)}setGroupByTheme(t,e=!0,i=!0){if(this.groupByTheme===t){i&&this._update();return}this.groupByTheme=t,e&&this._buildLevels(),i&&this._update()}setMinGlobalPointCount(t,e=!0){this.minGlobalPointCount=t,e&&this._update()}setThreshold(t,e=!0){this.threshold=t,e&&this._update()}setDebugCurrentGrids(t,e=!0){this.debugCurrentGrids=t,t?this._ensureDebugImageryLayer():(this._clearDebugGrids(),this._removeDebugImageryLayer()),e&&this._update()}_syncTilingSchemeAndLevels(){const t=this.viewer.scene&&this.viewer.scene.globe,e=t&&t._surface,i=e&&e._tileProvider,o=(i==null?void 0:i.tilingScheme)||new this.Cesium.GeographicTilingScheme,s=i!==this._lastTileProvider,r=this.tilingScheme!==o;!s&&!r&&this.levels&&this.levels.length>0||(this._lastTileProvider=i,this.tilingScheme=o,this.levels=this._createLevels(),this._buildLevels(),this.debugCurrentGrids&&(this._removeDebugImageryLayer(),this._ensureDebugImageryLayer()))}_createLevels(){const t=[];this.levelIndexByTileLevel=new Map;const e=0,i=this.maxLevel;let o=0;for(let s=e;s<=i;s++,o++){const r=360/Math.pow(2,s);t.push({level:s,size:r,minViewWidth:r*4}),this.levelIndexByTileLevel.set(s,o)}return t}addPoints(t){this.points=t,this._buildLevels()}appendPoints(t,e=!0){for(const i of t)this._preparePointLevelRange(i),this.points.push(i);for(const i of t)this._addPointToGrid(i);e&&this._scheduleUpdate()}_scheduleUpdate(){this._updateTimer!==null&&clearTimeout(this._updateTimer),this._updateTimer=window.setTimeout(()=>{this._update(),this._cameraDirty=!0,this._updateTimer=null},this._updateDelay)}updatePoint(t){var s,r,n,l;const e=this.points.findIndex(c=>c.id===t.id);if(e===-1)return;const i=this.points[e];for(const c of this.levels){const d=c.level,u=this.gridLayers.get(d);if(!u)continue;const m=this.Cesium.Cartographic.fromDegrees(i.lon,i.lat),g=this.tilingScheme.positionToTileXY(m,d,new this.Cesium.Cartesian2);if(!g)continue;const p=`${g.x}_${g.y}`,y=u.get(p);if(y){const w=y.allPoints.findIndex(f=>f.id===t.id);if(w!==-1&&y.allPoints.splice(w,1),(n=(r=(s=i.data)==null?void 0:s.billboard)==null?void 0:r[0])!=null&&n.skipAggregation){const f=y.skipPoints.findIndex(v=>v.id===t.id);f!==-1&&y.skipPoints.splice(f,1)}else{const f=this.groupByTheme?(l=i.data)==null?void 0:l.theme:this.clusterTheme,v=y.groups.get(f);if(v){const C=v.findIndex(b=>b.id===t.id);C!==-1&&v.splice(C,1),v.length===0&&y.groups.delete(f)}}}}const o={...i,...t};this.points[e]=o,this._addPointToGrid(o),this._update()}removePointsById(t){const e=new Set(t);this.points=this.points.filter(i=>!e.has(i.id));for(const i of this.levels){const o=this.gridLayers.get(i.level);if(o)for(const[s,r]of o.entries()){r.allPoints=r.allPoints.filter(n=>!e.has(n.id)),r.skipPoints=r.skipPoints.filter(n=>!e.has(n.id));for(const[n,l]of r.groups.entries()){const c=l.filter(d=>!e.has(d.id));c.length===0?r.groups.delete(n):r.groups.set(n,c)}r.allPoints.length===0&&o.delete(s)}}this._update()}_buildLevels(){this.gridLayers.clear();for(const t of this.levels)this.gridLayers.set(t.level,new Map);for(const t of this.points)this._addPointToGrid(t)}_addPointToGrid(t){var e,i,o,s,r,n;for(const l of this.levels){const c=l.level,d=this.gridLayers.get(c);if(!d)continue;const u=this.Cesium.Cartographic.fromDegrees(t.lon,t.lat),m=this.tilingScheme.positionToTileXY(u,c,new this.Cesium.Cartesian2);if(!m)continue;const g=`${m.x}_${m.y}`;let p=d.get(g);if(p||(p={allPoints:[],groups:new Map,skipPoints:[]},d.set(g,p)),p.allPoints.push(t),(o=(i=(e=t.data)==null?void 0:e.billboard)==null?void 0:i[0])!=null&&o.skipAggregation)p.skipPoints.push(t);else{const y=this.groupByTheme?(n=(r=(s=t.data)==null?void 0:s.billboard)==null?void 0:r[0])==null?void 0:n.theme:this.clusterTheme;p.groups.has(y)||p.groups.set(y,[]),p.groups.get(y).push(t)}}}_preparePointLevelRange(t){const e=t.data||{};let i=e.minLevel,o=e.maxLevel;const s=e.levelRange;Array.isArray(s)?(s.length>0&&i==null&&(i=s[0]),s.length>1&&o==null&&(o=s[1])):s&&typeof s=="object"&&(i==null&&typeof s.min=="number"&&(i=s.min),o==null&&typeof s.max=="number"&&(o=s.max));const r=i==null?this.defaultMinLevel:Number(i)||this.defaultMinLevel,n=o==null?this.defaultMaxLevel:Number(o)||this.defaultMaxLevel;t.__minLevel=r,t.__maxLevel=n}_isVisibleAtLevel(t,e){if(e==null)return!0;(t.__minLevel===void 0||t.__maxLevel===void 0)&&this._preparePointLevelRange(t);const i=t.__minLevel??this.defaultMinLevel,o=t.__maxLevel??this.defaultMaxLevel;return e>=i&&e<=o}_update(){if(!this.labelPool)return;this._syncTilingSchemeAndLevels(),this.labelPool.reset(),this.debugCurrentGrids&&this._clearDebugGrids();const t=this.points.length<this.minGlobalPointCount?1/0:this.threshold;let e=0;const i=(o,s,r,n)=>{e=this._processCell(o,s,r,n,t,e)};try{const o=this._getSurfaceTiles();if(!o||o.length===0){this._handleNoSurfaceTiles(e);return}this._tilesRetryCount=0,this._processTiles(o,i)}catch{this.labelPool.cleanup();return}this.labelPool.cleanup()}_getSurfaceTiles(){const t=this.viewer.scene&&this.viewer.scene.globe,e=t&&t._surface;if(e)return e._tilesToRender||e._tilesToRenderByTextureCount}_handleNoSurfaceTiles(t){var e,i,o,s;for(const r of this.points){if(t>=this.displayLimit)break;((e=r.data)==null?void 0:e.show)!==!1&&(this.labelPool.add(r.data,{id:`point-${r.id}`,lon:r.lon,lat:r.lat,height:r.height,theme:((s=(o=(i=r.data)==null?void 0:i.billboard)==null?void 0:o[0])==null?void 0:s.theme)||this.pointTheme,style:r.style}),t++)}this.labelPool.cleanup(),this.points.length>0&&this._tilesRetryCount<this._tilesRetryMax&&(this._tilesRetryCount++,this._scheduleUpdate())}_resolveLevelIndex(t){let e=this.levelIndexByTileLevel.get(t);if(e!==void 0)return e;if(this.levels.length===0)return;const i=this.levels[0].level,o=this.levels[this.levels.length-1].level;if(t>o)return this.levels.length-1;if(t<i)return 0;let s=0,r=1/0;for(let n=0;n<this.levels.length;n++){const l=Math.abs(this.levels[n].level-t);l<r&&(r=l,s=n)}return s}_isTerrainEnabled(){const t=this.viewer.terrainProvider,e=this.viewer.scene,i=e&&e.globe,o=i&&i.terrainProvider,s=t||o;return s?!(s instanceof this.Cesium.EllipsoidTerrainProvider):!1}_getGridRefLevel(t){let e=t;if(this._isTerrainEnabled()&&(e+=this.terrainLevelOffset),this.levels.length>0){const i=this.levels[this.levels.length-1].level;e>i&&(e=i)}return e}_processTiles(t,e){const i=new Set,o=this.viewer.scene,s=o&&o.globe,r=s&&s.ellipsoid,n=r&&o.camera.computeViewRectangle(r),l=(c,d,u)=>{if(!n)return!0;const m=this.tilingScheme.tileXYToRectangle(c,d,u);return!(!m||m.east<=n.west||m.west>=n.east||m.north<=n.south||m.south>=n.north)};for(const c of t){const d=c.rectangle,u=c._level??c.level;if(!d||typeof u!="number")continue;const m=this._getGridRefLevel(u),g=this._resolveLevelIndex(m);if(g===void 0)continue;const p=this.levels[g].level,y=c._x??c.x,w=c._y??c.y;if(typeof y=="number"&&typeof w=="number"){const x=u-p;if(x>=0){const T=1<<x,A=Math.floor(y/T),$=Math.floor(w/T),R=`${p}_${A}_${$}`;if(i.has(R))continue;i.add(R),e(g,A,$,u)}else{const A=1<<Math.min(-x,this.maxRefineLevels),$=y*A,R=w*A;for(let _=0;_<A;_++)for(let O=0;O<A;O++){const k=$+_,G=R+O;if(!l(k,G,p))continue;const B=`${p}_${k}_${G}`;i.has(B)||(i.add(B),e(g,k,G,u))}}continue}const v=this.levels[g].size,C=this.Cesium.Math.toDegrees(d.west),b=this.Cesium.Math.toDegrees(d.east),M=this.Cesium.Math.toDegrees(d.south),P=this.Cesium.Math.toDegrees(d.north),L=Math.floor((C- -180)/v),E=Math.floor((b- -180)/v),I=Math.floor((M- -90)/v),S=Math.floor((P- -90)/v);for(let x=L;x<=E;x++)for(let T=I;T<=S;T++){if(!l(x,T,p))continue;const A=`${p}_${x}_${T}`;i.has(A)||(i.add(A),e(g,x,T,u))}}}_processCell(t,e,i,o,s,r){if(r>=this.displayLimit||t<0)return r;t>=this.levels.length&&(t=this.levels.length-1);const n=this._getCellContext(t,e,i,o);return n?(r=this._processCellSkipPoints(n,r),r>=this.displayLimit?(this._debugDrawCell(n),r):(r=this._processCellGroups(n,s,r),this._debugDrawCell(n),r)):r}_getCellContext(t,e,i,o){const r=this.levels[t].level,n=this.gridLayers.get(r);if(!n)return null;const l=`${e}_${i}`,c=n.get(l);if(!c)return null;const d=this.tilingScheme.tileXYToRectangle(e,i,r),u=this.Cesium.Math.toDegrees(d.west),m=this.Cesium.Math.toDegrees(d.south),g=this.Cesium.Math.toDegrees(d.east),p=this.Cesium.Math.toDegrees(d.north),y=(u+g)/2,w=(m+p)/2;return{levelIdx:t,tileLevel:r,lonIdx:e,latIdx:i,key:l,cell:c,rect:d,west:u,south:m,east:g,north:p,centerLon:y,centerLat:w,viewTileLevel:o}}_processCellSkipPoints(t,e){var r,n,l,c;const{cell:i,viewTileLevel:o}=t,s=o;for(const d of i.skipPoints)if(((r=d.data)==null?void 0:r.show)!==!1){if(e>=this.displayLimit)break;this._isVisibleAtLevel(d,s)&&(this.labelPool.add(d.data,{id:`point-${d.id}`,lon:d.lon,lat:d.lat,height:d.height,theme:((c=(l=(n=d.data)==null?void 0:n.billboard)==null?void 0:l[0])==null?void 0:c.theme)||this.pointTheme,style:d.style}),e++)}return e}_processCellGroups(t,e,i){var m,g,p,y,w,f,v,C,b,M,P,L,E;const{levelIdx:o,lonIdx:s,latIdx:r,cell:n,centerLon:l,centerLat:c,viewTileLevel:d}=t,u=d;for(const[I,S]of n.groups){const x=S.filter(_=>{var O;return((O=_.data)==null?void 0:O.show)!==!1});if(x.length===0)continue;let T=l,A=c,$=((m=x[0])==null?void 0:m.height)||0;if(this.centralPointMode=="firstPoint"&&(T=((g=x[0])==null?void 0:g.lon)||0,A=((p=x[0])==null?void 0:p.lat)||0,$=((y=x[0])==null?void 0:y.height)||0),o===this.levels.length-1||x.length<e)for(const _ of x){if(i>=this.displayLimit)break;this._isVisibleAtLevel(_,u)&&(this.labelPool.add(_.data,{id:`point-${_.id}`,lon:_.lon,lat:_.lat,height:_.height,theme:((v=(f=(w=_.data)==null?void 0:w.billboard)==null?void 0:f[0])==null?void 0:v.theme)||this.pointTheme,style:_.style}),i++)}else{if(i>=this.displayLimit)return i;const _=u==null?x:x.filter(B=>this._isVisibleAtLevel(B,u));if(!_.length)return i;const k=((P=(M=(b=(C=_[0])==null?void 0:C.data)==null?void 0:b.billboard)==null?void 0:M[0])==null?void 0:P.theme)||this.clusterTheme,G=this.groupByTheme?`cluster-${o}-${s}-${r}-${I}`:`cluster-${o}-${s}-${r}`;this.labelPool.add({id:G,billboard:((E=(L=_[0])==null?void 0:L.data)==null?void 0:E.billboard)||[],count:_.length,gridKey:`${s}_${r}`,points:_,aggregationGroup:I},{id:G,lon:T,lat:A,height:$,theme:k}),i++}}return i}_debugDrawCell(t){if(!this.debugCurrentGrids)return;const{levelIdx:e,west:i,south:o,east:s,north:r,lonIdx:n,latIdx:l}=t,c=this.levels[e].level;this._drawDebugGrid(i,o,s,r,`L:${c} X:${n} Y:${l}`)}refresh(){this._update()}_drawDebugGrid(t,e,i,o,s){const r=this.Cesium.Rectangle.fromDegrees(t,e,i,o),n=this.Cesium.Cartesian3.fromDegreesArray([t,e,i,e,i,o,t,o,t,e]),l=this.viewer.entities.add({rectangle:{coordinates:r,material:this.Cesium.Color.YELLOW.withAlpha(.2),outline:!0,outlineColor:this.Cesium.Color.RED,heightReference:this.Cesium.HeightReference.CLAMP_TO_GROUND,classificationType:this.Cesium.ClassificationType.TERRAIN},polyline:{positions:n,width:2,material:this.Cesium.Color.RED,clampToGround:!0},label:{text:s,font:"14px sans-serif",fillColor:this.Cesium.Color.BLACK,outlineColor:this.Cesium.Color.WHITE,outlineWidth:2,style:this.Cesium.LabelStyle.FILL_AND_OUTLINE,verticalOrigin:this.Cesium.VerticalOrigin.CENTER,horizontalOrigin:this.Cesium.HorizontalOrigin.CENTER}});this.debugGrids.push(l)}_clearDebugGrids(){for(const t of this.debugGrids)this.viewer.entities.remove(t);this.debugGrids=[]}_ensureDebugImageryLayer(){if(this.debugTileCoordLayer||!this.viewer||!this.viewer.imageryLayers)return;const t={tilingScheme:this.tilingScheme};this.debugTileCoordLayer=this.viewer.imageryLayers.addImageryProvider(new this.Cesium.TileCoordinatesImageryProvider(t))}_removeDebugImageryLayer(){if(!(!this.debugTileCoordLayer||!this.viewer||!this.viewer.imageryLayers)){try{this.viewer.imageryLayers.remove(this.debugTileCoordLayer,!1)}catch{}this.debugTileCoordLayer=null}}destroy(){this._cameraChangedHandler&&(this.viewer.camera.changed.removeEventListener(this._cameraChangedHandler),this._cameraChangedHandler=null);const t=this.viewer.scene,e=t&&t.globe;e&&this._tileLoadListener&&(e.tileLoadProgressEvent.removeEventListener(this._tileLoadListener),this._tileLoadListener=null),this._updateTimer!==null&&(clearTimeout(this._updateTimer),this._updateTimer=null),this.labelPool.reset(),this._clearDebugGrids(),this._removeDebugImageryLayer()}}var V=(a=>(a.Click="marker:click",a.DoubleClick="marker:dblclick",a.RightClick="marker:rightclick",a.MouseEnter="marker:mouseenter",a.MouseLeave="marker:mouseleave",a.MouseDown="marker:mousedown",a.MouseUp="marker:mouseup",a))(V||{});class tt{constructor(){h(this,"listenerMap",new Map)}addListener(t,e,i=!1){let o=this.listenerMap.get(t);return o||(o=new Map,this.listenerMap.set(t,o)),o.has(e.name)?i?(console.warn(`[MarkerEventBus] Overwriting listener "${e.name}" for event "${t}".`),o.set(e.name,e),!0):(console.warn(`[MarkerEventBus] Listener "${e.name}" for event "${t}" already exists. Use overwrite=true to replace it.`),!1):(o.set(e.name,e),!0)}removeListenerByKey(t){const e=this.listenerMap.has(t);return this.listenerMap.set(t,new Map),e}removeListenerByKeyAndName(t,e){const i=this.listenerMap.get(t);return i?i.delete(e):!1}runListener(t,e,i){const o=this.listenerMap.get(t);if(o)for(const[s,r]of o.entries()){try{r.fn(e,i)}catch(n){console.error(`Error in listener "${s}" for event "${t}":`,n)}r.once&&o.delete(s)}}}const it={[V.Click]:"click",[V.DoubleClick]:"dblclick",[V.RightClick]:"contextmenu",[V.MouseEnter]:"mouseenter",[V.MouseLeave]:"mouseleave",[V.MouseDown]:"mousedown",[V.MouseUp]:"mouseup"};class N{constructor(t,e,i="html-label-container",o,s=!0){h(this,"viewer");h(this,"Cesium");h(this,"container");h(this,"labels",new Map);h(this,"activeIds",new Set);h(this,"_updateFn");h(this,"themes",{});h(this,"eventBus");h(this,"openWheel",!0);this.Cesium=t,this.viewer=e,this.container=this._createContainer(i),this._updateFn=this._update.bind(this),this.viewer.scene.postRender.addEventListener(this._updateFn),this.eventBus=o||new tt,this.openWheel=s}_createContainer(t){let e=document.getElementById(t);return e||(e=document.createElement("div"),e.id=t,Object.assign(e.style,{position:"absolute",top:"0",left:"0",pointerEvents:"none",width:"100%",height:"100%",zIndex:"100",overflow:"hidden"}),document.body.appendChild(e)),e}registerTheme(t,e){this.themes[t]=e}add(t,e){const{id:i,lon:o,lat:s,height:r=0,theme:n,show:l=!0,notCreateElement:c=!1,style:d}=e,u=this.themes[n];if(!u){console.warn(`Theme "${n}" not registered`);return}let m=this.labels.get(i);if(m){m.theme=n,m.data=t,m.notCreateElement=c;try{m.unload=u.createElement(m.el,{id:i,theme:n,data:t},u),(!c||l)&&this.container.appendChild(m.el)}catch(g){console.error(`Error updating label element for id "${i}":`,g)}}else{const g=document.createElement("div");Object.assign(g.style,{position:"absolute",transform:"translate(0, 0)",pointerEvents:"auto",...e.style||{}});for(const[y,w]of Object.entries(it)){g.addEventListener(w,v=>{v.stopPropagation();const C=this.labels.get(i);this.eventBus.runListener(y,C,v)});let f=0;g.addEventListener("wheel",v=>{if(!this.openWheel)return;const C=v.currentTarget;f=Date.now();const b=f;C.style.pointerEvents="none",setTimeout(()=>{f===b&&(C.style.pointerEvents="auto")},2e3)})}let p=null;if(!c||l){try{p=u.createElement(g,{id:i,theme:n,data:t},u)||{}}catch(y){console.error(`Error updating label element for id "${i}":`,y)}this.container.appendChild(g)}m={id:i,el:g,theme:n,data:t,notCreateElement:c,unload:p},this.labels.set(i,m)}m.el.dataset.lon=String(o),m.el.dataset.lat=String(s),m.el.dataset.height=String(r),m.el.style.zIndex=(d==null?void 0:d.zIndex)||"1",m.el.style.display=l?"block":"none",l&&this.activeIds.add(i)}addBatch(t){for(const{data:e,options:i}of t)this.add(e,i)}removeByIds(t){for(const e of t){const i=this.labels.get(e);i&&(this.unloadByLabel(i),this.labels.delete(e),this.activeIds.delete(e))}}unloadByLabel(t){t.el.remove(),t!=null&&t.unload&&typeof t.unload=="function"&&(t==null||t.unload()),t.unload=null}removeAll(){for(const t of this.labels.values())this.unloadByLabel(t);this.labels.clear(),this.activeIds.clear()}update(t,e){const i=this.labels.get(t);if(!i){console.warn(`Label with id "${t}" not found for update.`);return}const o=this.themes[i.theme];if(!o){console.warn(`Theme "${i.theme}" not registered.`);return}try{o.createElement(i.el,{id:t,theme:i.theme,data:e},o)}catch(s){console.error(`Failed to update label "${t}":`,s)}}hideByIds(t){for(const e of t){const i=this.labels.get(e);i&&(i.notCreateElement&&this.unloadByLabel(i),i.el.style.display="none",this.activeIds.delete(e))}}hideAll(){for(const t of this.labels.values())t.notCreateElement&&this.unloadByLabel(t),t.el.style.display="none",this.activeIds.delete(t.id)}hideFilter(t){for(const e of this.labels.values())t(e.data)&&(e.notCreateElement&&this.unloadByLabel(e),e.el.style.display="none",this.activeIds.delete(e.id))}showByIds(t){for(const e of t){const i=this.labels.get(e);if(i){if((i.notCreateElement||!i.el.parentNode)&&this.container.appendChild(i.el),!i.unload)try{const o=this.themes[i.theme];if(!o){console.warn(`Theme "${i.theme}" not registered`);return}i.unload=o.createElement(i.el,{id:e,theme:i.theme,data:i.data},o)||{}}catch(o){console.error(`Error creating label element for theme "${i.theme}":`,o);return}i.el.style.display="block",this.activeIds.add(e)}}}has(t){return this.labels.has(t)}reset(){for(const t of this.activeIds.values()){let e=this.labels.get(t);e&&this.unloadByLabel(e)}this.activeIds.clear()}cleanup(){for(const[t,e]of this.labels.entries())this.activeIds.has(t)||(e.el.style.display="none")}async toWindowPositionByLonLat(t,e){const i=this.Cesium,o=this.viewer.scene,s=[i.Cartographic.fromDegrees(t,e)];let r;try{r=await o.clampToHeightMostDetailed(s)}catch{console.warn("clampToHeightMostDetailed failed, fallback to ellipsoid height.")}let n=0;r&&r[0]&&r[0].height!=null?n=r[0].height:n=0;const l=i.Cartesian3.fromDegrees(t,e,n);return this.toWindowCoordinates(l)}toWindowCoordinates(t){const e=this.viewer.scene,i=this.Cesium.SceneTransforms;if(typeof(i==null?void 0:i.wgs84ToWindowCoordinates)=="function")return i.wgs84ToWindowCoordinates(e,t);if(typeof(i==null?void 0:i.worldToWindowCoordinates)=="function")return i.worldToWindowCoordinates(e,t);console.warn("No compatible window coordinate transform function found.")}_isValidCoordinate(t,e){return!(Number.isNaN(t)||Number.isNaN(e)||t===0&&e===0||t<-180||t>180||e<-90||e>90)}async _update(){var t;for(const e of this.activeIds){const i=this.labels.get(e);if(!i)continue;const o=parseFloat(i.el.dataset.lon),s=parseFloat(i.el.dataset.lat),r=parseFloat(i.el.dataset.height||"0");if(!this._isValidCoordinate(o,s)){i.el.style.display="none";continue}const n=this.Cesium.Cartesian3.fromDegrees(o,s,r),l=this.toWindowCoordinates(n);if(this.Cesium.defined(l)){const d=((t=this.themes[i.theme].options)==null?void 0:t.offset)||{},u=d.x||0,m=d.y||0;i.el.style.left=`${l.x}px`,i.el.style.top=`${l.y}px`,i.el.style.transform=`translate(${u}px, ${m}px)`,i.el.style.display="block"}else i.el.style.display="none"}}destroy(){this.viewer.scene.postRender.removeEventListener(this._updateFn),this.labels.clear(),this.activeIds.clear()}}class xe{constructor(){h(this,"tooltipEl");h(this,"visible",!1);h(this,"offsetX",10);h(this,"offsetY",-20);h(this,"onMouseMove",null);this.tooltipEl=document.createElement("div"),this.tooltipEl.style.position="fixed",this.tooltipEl.style.pointerEvents="none",this.tooltipEl.style.zIndex="10000",this.tooltipEl.style.padding="4px 8px",this.tooltipEl.style.borderRadius="4px",this.tooltipEl.style.background="rgba(0, 0, 0, 0.7)",this.tooltipEl.style.color="#fff",this.tooltipEl.style.fontSize="13px",this.tooltipEl.style.transition="opacity 0.1s ease",this.tooltipEl.style.opacity="0",document.body.appendChild(this.tooltipEl),this.onMouseMove=t=>{this.visible&&(this.tooltipEl.style.left=`${t.clientX+this.offsetX}px`,this.tooltipEl.style.top=`${t.clientY+this.offsetY}px`)},window.addEventListener("mousemove",this.onMouseMove)}show(t){this.tooltipEl.innerText=t,this.tooltipEl.style.opacity="1",this.visible=!0}hide(){this.tooltipEl.style.opacity="0",this.visible=!1}destroy(){this.onMouseMove&&(window.removeEventListener("mousemove",this.onMouseMove),this.onMouseMove=null),this.tooltipEl.parentElement&&this.tooltipEl.parentElement.removeChild(this.tooltipEl)}}class Gt{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"entity",null);h(this,"tooltip",null);this.Cesium=t,this.viewer=e}startDrawing(t){const{Cesium:e,viewer:i}=this;this.tooltip=new xe,this.tooltip.show("左键添加点"),this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(o=>{var m,g;const s=i.scene.pickPosition(o.position);if(!s)return;const r=e.Cartographic.fromCartesian(s),n=e.Math.toDegrees(r.longitude),l=e.Math.toDegrees(r.latitude),c=r.height,d=i.entities.add({position:s,point:{pixelSize:10,color:t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.entity=d;const u={entity:d,position:s,lnglat:{lng:n,lat:l,height:c},clear:()=>{this.clear()}};(m=t.onComplete)==null||m.call(t,u),this.stopDrawing(),(g=this.tooltip)==null||g.hide(),this.tooltip=null},e.ScreenSpaceEventType.LEFT_CLICK)}stopDrawing(){var t;(t=this.handler)==null||t.destroy(),this.handler=null}clear(){this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.stopDrawing()}}class Bt{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"positions",[]);h(this,"entity",null);h(this,"tooltip",null);h(this,"tempPoints",[]);this.Cesium=t,this.viewer=e}startDrawing(t){const{Cesium:e,viewer:i}=this;this.positions=[],this.tempPoints=[],this.entity=null,this.tooltip=new xe,this.tooltip.show("单击左键添加点,双击左键结束"),this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(o=>{var n,l;const s=i.scene.pickPosition(o.position);if(!s)return;this.positions.push(s);const r=i.entities.add({position:s,point:{pixelSize:8,color:e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(r),this.entity?this.entity.polyline.positions=this.positions.slice():this.entity=i.entities.add({polyline:{positions:this.positions.slice(),width:3,material:t.color||e.Color.YELLOW,depthFailMaterial:((l=(n=t.color)==null?void 0:n.withAlpha)==null?void 0:l.call(n,.5))||e.Color.YELLOW.withAlpha(.5)}})},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(()=>{var r,n;if(this.stopDrawing(),(r=this.tooltip)==null||r.hide(),this.tooltip=null,this.positions.length<2)return;this.positions.length=this.positions.length-1,this.entity&&(this.entity.polyline.positions=this.positions.slice());const o=this.positions.map(l=>{const c=e.Cartographic.fromCartesian(l);return{lng:e.Math.toDegrees(c.longitude),lat:e.Math.toDegrees(c.latitude),height:c.height}}),s={entity:this.entity,positions:this.positions,lnglats:o,clear:()=>{this.clear()}};(n=t.onComplete)==null||n.call(t,s)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)}stopDrawing(){var t;(t=this.handler)==null||t.destroy(),this.handler=null}clear(){var e;const{viewer:t}=this;this.entity&&(t.entities.remove(this.entity),this.entity=null),this.tempPoints.forEach(i=>t.entities.remove(i)),this.tempPoints=[],(e=this.tooltip)==null||e.hide(),this.tooltip=null,this.positions=[],this.stopDrawing()}}class jt{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"startPoint",null);h(this,"endPoint",null);h(this,"entity",null);this.Cesium=t,this.viewer=e}startDrawing(t){const{Cesium:e,viewer:i}=this;this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(o=>{var r;const s=i.scene.pickPosition(o.position);if(s)if(!this.startPoint)this.startPoint=s,this.entity=i.entities.add({rectangle:{coordinates:new e.CallbackProperty(()=>{if(!(!this.startPoint||!this.endPoint))try{const n=e.Cartographic.fromCartesian(this.startPoint),l=e.Cartographic.fromCartesian(this.endPoint),c=Math.min(n.longitude,l.longitude),d=Math.max(n.longitude,l.longitude),u=Math.min(n.latitude,l.latitude),m=Math.max(n.latitude,l.latitude);return new e.Rectangle(c,u,d,m)}catch(n){console.warn("Rectangle calculation error:",n);return}},!1),material:t.color||e.Color.YELLOW.withAlpha(.5),outline:!0,outlineColor:e.Color.BLACK,disableDepthTestDistance:Number.POSITIVE_INFINITY}});else{this.stopDrawing();const n=e.Cartographic.fromCartesian(this.startPoint),l=e.Cartographic.fromCartesian(this.endPoint),c={lng:e.Math.toDegrees(Math.min(n.longitude,l.longitude)),lat:e.Math.toDegrees(Math.min(n.latitude,l.latitude)),height:0},d={lng:e.Math.toDegrees(Math.max(n.longitude,l.longitude)),lat:e.Math.toDegrees(Math.max(n.latitude,l.latitude)),height:0},u={entity:this.entity,position:this.startPoint,lnglat:{lng:e.Math.toDegrees(n.longitude),lat:e.Math.toDegrees(n.latitude),height:n.height},positions:[this.startPoint,this.endPoint],lnglats:[c,d],clear:()=>{this.clear()}};(r=t.onComplete)==null||r.call(t,u)}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(o=>{if(!this.startPoint)return;const s=i.scene.pickPosition(o.endPosition);s&&(this.endPoint=s)},e.ScreenSpaceEventType.MOUSE_MOVE)}stopDrawing(){var t;(t=this.handler)==null||t.destroy(),this.handler=null}clear(){this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.startPoint=null,this.endPoint=null,this.stopDrawing()}}class Yt{constructor(t,e){h(this,"viewer");h(this,"Cesium");h(this,"handler",null);h(this,"entity",null);h(this,"positions",[]);h(this,"_isDrawing",!1);h(this,"currentRadius",0);this.Cesium=t,this.viewer=e}startDrawing(t){this.clear(),this.handler=new this.Cesium.ScreenSpaceEventHandler(this.viewer.canvas),this._isDrawing=!0,this.handler.setInputAction(e=>{const i=this.viewer.scene.pickPosition(e.position);i&&(this.positions.push(i),this.positions.length===2&&(this.stopDrawing(),this.drawFinalCircle(t)))},this.Cesium.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(e=>{if(this.positions.length!==1)return;const i=this.positions[0],o=this.viewer.camera.getPickRay(e.endPosition),s=this.viewer.scene.globe.pick(o,this.viewer.scene);s&&this.drawPreviewCircle(i,s,t)},this.Cesium.ScreenSpaceEventType.MOUSE_MOVE)}drawPreviewCircle(t,e,i){const o=this.Cesium.Cartesian3.distance(t,e);if(this.entity)Math.abs(this.currentRadius-o)>.5&&(this.currentRadius=o);else{this.currentRadius=o;const s=new this.Cesium.CallbackProperty(()=>this.currentRadius,!1);this.entity=this.viewer.entities.add({position:t,ellipse:{semiMajorAxis:s,semiMinorAxis:s,material:i.color||this.Cesium.Color.YELLOW.withAlpha(.5),outline:!0,outlineColor:i.color||this.Cesium.Color.YELLOW,heightReference:this.Cesium.HeightReference.NONE,disableDepthTestDistance:Number.POSITIVE_INFINITY}})}}drawFinalCircle(t){var u;const[e,i]=this.positions,o=this.Cesium.Cartesian3.distance(e,i),s=this.Cesium.Cartographic.fromCartesian(e),r={lng:this.Cesium.Math.toDegrees(s.longitude),lat:this.Cesium.Math.toDegrees(s.latitude),height:s.height},n=(t==null?void 0:t.step)||1,l=[],c=[];for(let m=0;m<360;m+=n){const g=this.Cesium.Math.toRadians(m),p=new this.Cesium.EllipsoidGeodesic;p.setEndPoints(s,new this.Cesium.Cartographic(s.longitude+1e-4*Math.cos(g),s.latitude+1e-4*Math.sin(g)));const y=p.interpolateUsingSurfaceDistance(o),w=this.Cesium.Ellipsoid.WGS84.cartographicToCartesian(y);l.push(w);const f=this.Cesium.Cartographic.fromCartesian(w);c.push({lng:this.Cesium.Math.toDegrees(f.longitude),lat:this.Cesium.Math.toDegrees(f.latitude),height:f.height})}c.push(c[0]);const d=this.positions.map(m=>{const g=this.Cesium.Cartographic.fromCartesian(m);return{lng:this.Cesium.Math.toDegrees(g.longitude),lat:this.Cesium.Math.toDegrees(g.latitude),height:g.height}});(u=t.onComplete)==null||u.call(t,{entity:this.entity,positions:this.positions,lnglats:d,circlePoints:l,circleLnglats:c,center:r,radius:o,clear:()=>{this.clear()}})}stopDrawing(){this.handler&&(this.handler.destroy(),this.handler=null),this._isDrawing=!1}clear(){this.stopDrawing(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.positions=[],this.currentRadius=0}}class Vt{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"positions",[]);h(this,"entity",null);h(this,"tooltip",null);h(this,"tempPoints",[]);this.Cesium=t,this.viewer=e}startDrawing(t){const{Cesium:e,viewer:i}=this;this.positions=[],this.tempPoints=[],this.tooltip=new xe,this.tooltip.show("单击左键添加点,双击左键结束"),this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(o=>{const s=i.scene.pickPosition(o.position);if(!s)return;this.positions.push(s);const r=i.entities.add({position:s,point:{pixelSize:8,color:e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY,heightReference:e.HeightReference.CLAMP_TO_GROUND}});this.tempPoints.push(r),this.entity||(this.entity=i.entities.add({polygon:{hierarchy:new e.CallbackProperty(()=>({positions:this.positions}),!1),material:t.color||e.Color.YELLOW.withAlpha(.5)}}))},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(()=>{var r,n;if(this.stopDrawing(),(r=this.tooltip)==null||r.hide(),this.tooltip=null,this.positions.length<3)return;this.positions.length=this.positions.length-1;const o=this.positions.map(l=>{const c=e.Cartographic.fromCartesian(l);return{lng:e.Math.toDegrees(c.longitude),lat:e.Math.toDegrees(c.latitude),height:c.height}}),s={entity:this.entity,positions:this.positions,lnglats:o,clear:()=>{this.clear()}};(n=t.onComplete)==null||n.call(t,s)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)}stopDrawing(){var t;(t=this.handler)==null||t.destroy(),this.handler=null}clear(){var e;const{viewer:t}=this;this.entity&&(t.entities.remove(this.entity),this.entity=null),this.tempPoints.forEach(i=>t.entities.remove(i)),this.tempPoints=[],(e=this.tooltip)==null||e.hide(),this.tooltip=null,this.positions=[],this.stopDrawing()}}class Wt{constructor(t,e){h(this,"viewer");h(this,"Cesium");h(this,"activeDrawer",null);this.viewer=e,this.Cesium=t}draw(t,e){var i;switch(this.clear(),t){case"point":this.activeDrawer=new Gt(this.Cesium,this.viewer);break;case"line":this.activeDrawer=new Bt(this.Cesium,this.viewer);break;case"rectangle":this.activeDrawer=new jt(this.Cesium,this.viewer);break;case"circle":this.activeDrawer=new Yt(this.Cesium,this.viewer);break;case"polygon":this.activeDrawer=new Vt(this.Cesium,this.viewer);break;default:throw new Error(`Unsupported draw type: ${t}`)}(i=this.activeDrawer)==null||i.startDrawing(e)}clear(){this.activeDrawer&&(this.activeDrawer.stopDrawing(),this.activeDrawer.clear(),this.activeDrawer=null)}cancel(){this.clear()}}var st=typeof global=="object"&&global&&global.Object===Object&&global,Ut=typeof self=="object"&&self&&self.Object===Object&&self,se=st||Ut||Function("return this")(),me=se.Symbol,rt=Object.prototype,Kt=rt.hasOwnProperty,qt=rt.toString,be=me?me.toStringTag:void 0;function Xt(a){var t=Kt.call(a,be),e=a[be];try{a[be]=void 0;var i=!0}catch{}var o=qt.call(a);return i&&(t?a[be]=e:delete a[be]),o}var Jt=Object.prototype,Qt=Jt.toString;function Zt(a){return Qt.call(a)}var ei="[object Null]",ti="[object Undefined]",ot=me?me.toStringTag:void 0;function Pe(a){return a==null?a===void 0?ti:ei:ot&&ot in Object(a)?Xt(a):Zt(a)}function Le(a){return a!=null&&typeof a=="object"}var _e=Array.isArray;function De(a){var t=typeof a;return a!=null&&(t=="object"||t=="function")}var ii="[object AsyncFunction]",si="[object Function]",ri="[object GeneratorFunction]",oi="[object Proxy]";function nt(a){if(!De(a))return!1;var t=Pe(a);return t==si||t==ri||t==ii||t==oi}var Fe=se["__core-js_shared__"],at=(function(){var a=/[^.]+$/.exec(Fe&&Fe.keys&&Fe.keys.IE_PROTO||"");return a?"Symbol(src)_1."+a:""})();function ni(a){return!!at&&at in a}var ai=Function.prototype,li=ai.toString;function ce(a){if(a!=null){try{return li.call(a)}catch{}try{return a+""}catch{}}return""}var hi=/[\\^$.*+?()[\]{}|]/g,ci=/^\[object .+?Constructor\]$/,di=Function.prototype,pi=Object.prototype,ui=di.toString,mi=pi.hasOwnProperty,gi=RegExp("^"+ui.call(mi).replace(hi,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function fi(a){if(!De(a)||ni(a))return!1;var t=nt(a)?gi:ci;return t.test(ce(a))}function yi(a,t){return a==null?void 0:a[t]}function de(a,t){var e=yi(a,t);return fi(e)?e:void 0}var ke=de(se,"WeakMap"),lt=Object.create,wi=(function(){function a(){}return function(t){if(!De(t))return{};if(lt)return lt(t);a.prototype=t;var e=new a;return a.prototype=void 0,e}})(),ht=(function(){try{var a=de(Object,"defineProperty");return a({},"",{}),a}catch{}})();function vi(a,t){for(var e=-1,i=a==null?0:a.length;++e<i&&t(a[e],e,a)!==!1;);return a}var Ci=9007199254740991,bi=/^(?:0|[1-9]\d*)$/;function Pi(a,t){var e=typeof a;return t=t??Ci,!!t&&(e=="number"||e!="symbol"&&bi.test(a))&&a>-1&&a%1==0&&a<t}function Li(a,t,e){t=="__proto__"&&ht?ht(a,t,{configurable:!0,enumerable:!0,value:e,writable:!0}):a[t]=e}function ct(a,t){return a===t||a!==a&&t!==t}var Ei=Object.prototype,Mi=Ei.hasOwnProperty;function Ii(a,t,e){var i=a[t];(!(Mi.call(a,t)&&ct(i,e))||e===void 0&&!(t in a))&&Li(a,t,e)}var Ti=9007199254740991;function dt(a){return typeof a=="number"&&a>-1&&a%1==0&&a<=Ti}function xi(a){return a!=null&&dt(a.length)&&!nt(a)}var _i=Object.prototype;function pt(a){var t=a&&a.constructor,e=typeof t=="function"&&t.prototype||_i;return a===e}function Di(a,t){for(var e=-1,i=Array(a);++e<a;)i[e]=t(e);return i}var Si="[object Arguments]";function ut(a){return Le(a)&&Pe(a)==Si}var mt=Object.prototype,Ai=mt.hasOwnProperty,$i=mt.propertyIsEnumerable,Oi=ut((function(){return arguments})())?ut:function(a){return Le(a)&&Ai.call(a,"callee")&&!$i.call(a,"callee")};function Ri(){return!1}var gt=typeof D=="object"&&D&&!D.nodeType&&D,ft=gt&&typeof module=="object"&&module&&!module.nodeType&&module,Fi=ft&&ft.exports===gt,yt=Fi?se.Buffer:void 0,ki=yt?yt.isBuffer:void 0,wt=ki||Ri,Hi="[object Arguments]",zi="[object Array]",Ni="[object Boolean]",Gi="[object Date]",Bi="[object Error]",ji="[object Function]",Yi="[object Map]",Vi="[object Number]",Wi="[object Object]",Ui="[object RegExp]",Ki="[object Set]",qi="[object String]",Xi="[object WeakMap]",Ji="[object ArrayBuffer]",Qi="[object DataView]",Zi="[object Float32Array]",es="[object Float64Array]",ts="[object Int8Array]",is="[object Int16Array]",ss="[object Int32Array]",rs="[object Uint8Array]",os="[object Uint8ClampedArray]",ns="[object Uint16Array]",as="[object Uint32Array]",z={};z[Zi]=z[es]=z[ts]=z[is]=z[ss]=z[rs]=z[os]=z[ns]=z[as]=!0,z[Hi]=z[zi]=z[Ji]=z[Ni]=z[Qi]=z[Gi]=z[Bi]=z[ji]=z[Yi]=z[Vi]=z[Wi]=z[Ui]=z[Ki]=z[qi]=z[Xi]=!1;function ls(a){return Le(a)&&dt(a.length)&&!!z[Pe(a)]}function He(a){return function(t){return a(t)}}var vt=typeof D=="object"&&D&&!D.nodeType&&D,Ee=vt&&typeof module=="object"&&module&&!module.nodeType&&module,hs=Ee&&Ee.exports===vt,ze=hs&&st.process,ge=(function(){try{var a=Ee&&Ee.require&&Ee.require("util").types;return a||ze&&ze.binding&&ze.binding("util")}catch{}})(),Ct=ge&&ge.isTypedArray,cs=Ct?He(Ct):ls,ds=Object.prototype,ps=ds.hasOwnProperty;function us(a,t){var e=_e(a),i=!e&&Oi(a),o=!e&&!i&&wt(a),s=!e&&!i&&!o&&cs(a),r=e||i||o||s,n=r?Di(a.length,String):[],l=n.length;for(var c in a)ps.call(a,c)&&!(r&&(c=="length"||o&&(c=="offset"||c=="parent")||s&&(c=="buffer"||c=="byteLength"||c=="byteOffset")||Pi(c,l)))&&n.push(c);return n}function bt(a,t){return function(e){return a(t(e))}}var ms=bt(Object.keys,Object),gs=Object.prototype,fs=gs.hasOwnProperty;function ys(a){if(!pt(a))return ms(a);var t=[];for(var e in Object(a))fs.call(a,e)&&e!="constructor"&&t.push(e);return t}function ws(a){return xi(a)?us(a):ys(a)}var Me=de(Object,"create");function vs(){this.__data__=Me?Me(null):{},this.size=0}function Cs(a){var t=this.has(a)&&delete this.__data__[a];return this.size-=t?1:0,t}var bs="__lodash_hash_undefined__",Ps=Object.prototype,Ls=Ps.hasOwnProperty;function Es(a){var t=this.__data__;if(Me){var e=t[a];return e===bs?void 0:e}return Ls.call(t,a)?t[a]:void 0}var Ms=Object.prototype,Is=Ms.hasOwnProperty;function Ts(a){var t=this.__data__;return Me?t[a]!==void 0:Is.call(t,a)}var xs="__lodash_hash_undefined__";function _s(a,t){var e=this.__data__;return this.size+=this.has(a)?0:1,e[a]=Me&&t===void 0?xs:t,this}function pe(a){var t=-1,e=a==null?0:a.length;for(this.clear();++t<e;){var i=a[t];this.set(i[0],i[1])}}pe.prototype.clear=vs,pe.prototype.delete=Cs,pe.prototype.get=Es,pe.prototype.has=Ts,pe.prototype.set=_s;function Ds(){this.__data__=[],this.size=0}function Se(a,t){for(var e=a.length;e--;)if(ct(a[e][0],t))return e;return-1}var Ss=Array.prototype,As=Ss.splice;function $s(a){var t=this.__data__,e=Se(t,a);if(e<0)return!1;var i=t.length-1;return e==i?t.pop():As.call(t,e,1),--this.size,!0}function Os(a){var t=this.__data__,e=Se(t,a);return e<0?void 0:t[e][1]}function Rs(a){return Se(this.__data__,a)>-1}function Fs(a,t){var e=this.__data__,i=Se(e,a);return i<0?(++this.size,e.push([a,t])):e[i][1]=t,this}function oe(a){var t=-1,e=a==null?0:a.length;for(this.clear();++t<e;){var i=a[t];this.set(i[0],i[1])}}oe.prototype.clear=Ds,oe.prototype.delete=$s,oe.prototype.get=Os,oe.prototype.has=Rs,oe.prototype.set=Fs;var Ie=de(se,"Map");function ks(){this.size=0,this.__data__={hash:new pe,map:new(Ie||oe),string:new pe}}function Hs(a){var t=typeof a;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?a!=="__proto__":a===null}function Ae(a,t){var e=a.__data__;return Hs(t)?e[typeof t=="string"?"string":"hash"]:e.map}function zs(a){var t=Ae(this,a).delete(a);return this.size-=t?1:0,t}function Ns(a){return Ae(this,a).get(a)}function Gs(a){return Ae(this,a).has(a)}function Bs(a,t){var e=Ae(this,a),i=e.size;return e.set(a,t),this.size+=e.size==i?0:1,this}function fe(a){var t=-1,e=a==null?0:a.length;for(this.clear();++t<e;){var i=a[t];this.set(i[0],i[1])}}fe.prototype.clear=ks,fe.prototype.delete=zs,fe.prototype.get=Ns,fe.prototype.has=Gs,fe.prototype.set=Bs;function js(a,t){for(var e=-1,i=t.length,o=a.length;++e<i;)a[o+e]=t[e];return a}var Ys=bt(Object.getPrototypeOf,Object);function Vs(){this.__data__=new oe,this.size=0}function Ws(a){var t=this.__data__,e=t.delete(a);return this.size=t.size,e}function Us(a){return this.__data__.get(a)}function Ks(a){return this.__data__.has(a)}var qs=200;function Xs(a,t){var e=this.__data__;if(e instanceof oe){var i=e.__data__;if(!Ie||i.length<qs-1)return i.push([a,t]),this.size=++e.size,this;e=this.__data__=new fe(i)}return e.set(a,t),this.size=e.size,this}function ye(a){var t=this.__data__=new oe(a);this.size=t.size}ye.prototype.clear=Vs,ye.prototype.delete=Ws,ye.prototype.get=Us,ye.prototype.has=Ks,ye.prototype.set=Xs;var Pt=typeof D=="object"&&D&&!D.nodeType&&D,Lt=Pt&&typeof module=="object"&&module&&!module.nodeType&&module,Js=Lt&&Lt.exports===Pt,Et=Js?se.Buffer:void 0;Et&&Et.allocUnsafe;function Qs(a,t){return a.slice()}function Zs(a,t){for(var e=-1,i=a==null?0:a.length,o=0,s=[];++e<i;){var r=a[e];t(r,e,a)&&(s[o++]=r)}return s}function er(){return[]}var tr=Object.prototype,ir=tr.propertyIsEnumerable,Mt=Object.getOwnPropertySymbols,sr=Mt?function(a){return a==null?[]:(a=Object(a),Zs(Mt(a),function(t){return ir.call(a,t)}))}:er;function rr(a,t,e){var i=t(a);return _e(a)?i:js(i,e(a))}function or(a){return rr(a,ws,sr)}var Ne=de(se,"DataView"),Ge=de(se,"Promise"),Be=de(se,"Set"),It="[object Map]",nr="[object Object]",Tt="[object Promise]",xt="[object Set]",_t="[object WeakMap]",Dt="[object DataView]",ar=ce(Ne),lr=ce(Ie),hr=ce(Ge),cr=ce(Be),dr=ce(ke),ne=Pe;(Ne&&ne(new Ne(new ArrayBuffer(1)))!=Dt||Ie&&ne(new Ie)!=It||Ge&&ne(Ge.resolve())!=Tt||Be&&ne(new Be)!=xt||ke&&ne(new ke)!=_t)&&(ne=function(a){var t=Pe(a),e=t==nr?a.constructor:void 0,i=e?ce(e):"";if(i)switch(i){case ar:return Dt;case lr:return It;case hr:return Tt;case cr:return xt;case dr:return _t}return t});var pr=Object.prototype,ur=pr.hasOwnProperty;function mr(a){var t=a.length,e=new a.constructor(t);return t&&typeof a[0]=="string"&&ur.call(a,"index")&&(e.index=a.index,e.input=a.input),e}var St=se.Uint8Array;function je(a){var t=new a.constructor(a.byteLength);return new St(t).set(new St(a)),t}function gr(a,t){var e=je(a.buffer);return new a.constructor(e,a.byteOffset,a.byteLength)}var fr=/\w*$/;function yr(a){var t=new a.constructor(a.source,fr.exec(a));return t.lastIndex=a.lastIndex,t}var At=me?me.prototype:void 0,$t=At?At.valueOf:void 0;function wr(a){return $t?Object($t.call(a)):{}}function vr(a,t){var e=je(a.buffer);return new a.constructor(e,a.byteOffset,a.length)}var Cr="[object Boolean]",br="[object Date]",Pr="[object Map]",Lr="[object Number]",Er="[object RegExp]",Mr="[object Set]",Ir="[object String]",Tr="[object Symbol]",xr="[object ArrayBuffer]",_r="[object DataView]",Dr="[object Float32Array]",Sr="[object Float64Array]",Ar="[object Int8Array]",$r="[object Int16Array]",Or="[object Int32Array]",Rr="[object Uint8Array]",Fr="[object Uint8ClampedArray]",kr="[object Uint16Array]",Hr="[object Uint32Array]";function zr(a,t,e){var i=a.constructor;switch(t){case xr:return je(a);case Cr:case br:return new i(+a);case _r:return gr(a);case Dr:case Sr:case Ar:case $r:case Or:case Rr:case Fr:case kr:case Hr:return vr(a);case Pr:return new i;case Lr:case Ir:return new i(a);case Er:return yr(a);case Mr:return new i;case Tr:return wr(a)}}function Nr(a){return typeof a.constructor=="function"&&!pt(a)?wi(Ys(a)):{}}var Gr="[object Map]";function Br(a){return Le(a)&&ne(a)==Gr}var Ot=ge&&ge.isMap,jr=Ot?He(Ot):Br,Yr="[object Set]";function Vr(a){return Le(a)&&ne(a)==Yr}var Rt=ge&&ge.isSet,Wr=Rt?He(Rt):Vr,Ft="[object Arguments]",Ur="[object Array]",Kr="[object Boolean]",qr="[object Date]",Xr="[object Error]",kt="[object Function]",Jr="[object GeneratorFunction]",Qr="[object Map]",Zr="[object Number]",Ht="[object Object]",eo="[object RegExp]",to="[object Set]",io="[object String]",so="[object Symbol]",ro="[object WeakMap]",oo="[object ArrayBuffer]",no="[object DataView]",ao="[object Float32Array]",lo="[object Float64Array]",ho="[object Int8Array]",co="[object Int16Array]",po="[object Int32Array]",uo="[object Uint8Array]",mo="[object Uint8ClampedArray]",go="[object Uint16Array]",fo="[object Uint32Array]",H={};H[Ft]=H[Ur]=H[oo]=H[no]=H[Kr]=H[qr]=H[ao]=H[lo]=H[ho]=H[co]=H[po]=H[Qr]=H[Zr]=H[Ht]=H[eo]=H[to]=H[io]=H[so]=H[uo]=H[mo]=H[go]=H[fo]=!0,H[Xr]=H[kt]=H[ro]=!1;function $e(a,t,e,i,o,s){var r;if(r!==void 0)return r;if(!De(a))return a;var n=_e(a);if(n)r=mr(a);else{var l=ne(a),c=l==kt||l==Jr;if(wt(a))return Qs(a);if(l==Ht||l==Ft||c&&!o)r=c?{}:Nr(a);else{if(!H[l])return o?a:{};r=zr(a,l)}}s||(s=new ye);var d=s.get(a);if(d)return d;s.set(a,r),Wr(a)?a.forEach(function(g){r.add($e(g,t,e,g,a,s))}):jr(a)&&a.forEach(function(g,p){r.set(p,$e(g,t,e,p,a,s))});var u=or,m=n?void 0:u(a);return vi(m||a,function(g,p){m&&(p=g,g=a[p]),Ii(r,p,$e(g,t,e,p,a,s))}),r}var yo=1,wo=4;function Oe(a){return $e(a,yo|wo)}var zt=(a=>(a.Rotate="rotate",a.Move="move",a.Scale="scale",a.MoveHeight="moveHeight",a.Empty="",a))(zt||{}),Nt=(a=>(a.Scale="addScale",a.Rotate="rotate",a.Translation="translation",a.Remove="removeById",a.Add="add",a))(Nt||{});class vo{constructor(t){h(this,"primitives",new Map);h(this,"eventListener",new Map);h(this,"Cesium");h(this,"viewer");h(this,"handler");h(this,"rotationRing");h(this,"translationSquare");h(this,"heightArrow");h(this,"editMode","");h(this,"dragEndCallbackMap",new Map);this.Cesium=t.Cesium,this.viewer=t.viewer,this.handler=new this.Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas)}init(t,e=!1){const i=this.viewer;this.primitives.forEach(o=>{i.scene.primitives.remove(o)}),t.forEach(o=>{this.primitives.has(o.id)||this.add(o,e)})}get(t){return this.primitives.get(t)}add(t,e=!0){var u,m,g;const i=this.viewer,o=this.Cesium,s=o.Math.toRadians(((u=t.headingPitchRoll)==null?void 0:u.heading)||0),r=o.Math.toRadians(((m=t.headingPitchRoll)==null?void 0:m.pitch)||0),n=o.Math.toRadians(((g=t.headingPitchRoll)==null?void 0:g.roll)||0),l=new o.HeadingPitchRoll(s,r,n),c=o.Transforms.headingPitchRollToFixedFrame(t.position,l,i.scene.globe.ellipsoid,o.Transforms.eastNorthUpToFixedFrame,new o.Matrix4);let d=i.scene.primitives.add(o.Model.fromGltf({id:t.id,...t.model,modelMatrix:c}));d.scale=t.scale||1,this.primitives.set(t.id,d),d.show=e,this.runEventListener("add",{info:t,gltf:d})}flyTo(t){const e=this.viewer,i=this.Cesium;let o=this.primitives.get(t);const s=o.boundingSphere,r=i.Matrix4.multiplyByPoint(o.modelMatrix,s.center,new i.Cartesian3),n=new i.BoundingSphere(r,s.radius);e.camera.flyToBoundingSphere(n,{duration:1.5,offset:new i.HeadingPitchRange(0,-.5,s.radius*2)})}removeById(t){var o;const e=this.viewer;let i=this.primitives.get(t);if(!i){console.error(`No model found with id: ${t}`);return}e.scene.primitives.remove(i),this.primitives.delete(t),(!((o=this.rotationRing)!=null&&o._instanceIds.includes(`rotationRing_${t}`))||!this.rotationRing)&&this.removeTool(),this.runEventListener("removeById",{id:t,gltf:i})}show(t){let e=this.primitives.get(t);e&&(e.show=!0)}hide(t){let e=this.primitives.get(t);e&&(e.show=!1)}addScale(t,e=.1){let i=this.primitives.get(t.id);i&&(i.scale=i.scale+e,this.updatedTool(i.modelMatrix),this.runEventListener("addScale",{id:t.id,scale:i.scale}))}setScale(t,e=.1){let i=this.primitives.get(t);i&&(i.scale=e,this.updatedTool(i.modelMatrix),this.runEventListener("addScale",{id:t,scale:i.scale}))}setEditMode(t){this.editMode=t}lockCamera(){const t=this.viewer.scene.screenSpaceCameraController;t.enableRotate=!1,t.enableTranslate=!1,t.enableZoom=!1}unlockCamera(){const t=this.viewer.scene.screenSpaceCameraController;t.enableRotate=!0,t.enableTranslate=!0,t.enableZoom=!0}toCartographic(t){const e=this.Cesium.Cartographic.fromCartesian(t);return{longitude:e.longitude,latitude:e.latitude}}calculateHeading(t,e){const i=e.longitude-t.longitude,o=e.latitude-t.latitude;return Math.atan2(o,i)}getModelHeadingPitchRoll(t){const e=this.Cesium,i=this.viewer,o=e.Transforms.eastNorthUpToFixedFrame(e.Matrix4.getTranslation(t,new e.Cartesian3),i.scene.globe.ellipsoid,new e.Matrix4),s=e.Matrix4.multiply(e.Matrix4.inverse(o,new e.Matrix4),t,new e.Matrix4),r=e.Matrix4.getRotation(s,new e.Matrix3),n=e.Quaternion.fromRotationMatrix(r);return e.HeadingPitchRoll.fromQuaternion(n)}addEventListener(t,e,i){let o={f:e,options:i};return this.eventListener.get(t)?(this.eventListener.get(t)||[]).push(o):this.eventListener.set(t,[o]),o}removeEventListener(t,e){let i=this.eventListener.get(t);if(!i)return console.error("key不存在");let o=i.findIndex(s=>s==e);o>=0?i.splice(o,1):console.error("instantiation不存在")}runEventListener(t,e){let i=this.eventListener.get(t);return i?(i.forEach(o=>{typeof o.f=="function"&&o.f(e)}),!0):!1}initEditBox(t){const e=this.Cesium,i=this.viewer,o=i.scene;let s=null,r=null,n=null,l=null,c=null;const d=()=>{s=null,r=null,n=null,c=null,l=null,this.setEditMode(""),this.unlockCamera()},u=(m,g)=>{if(s=this.primitives.get(m),s){r=e.Matrix4.clone(s.modelMatrix);const p=e.Matrix4.getTranslation(r,new e.Cartesian3);n=this.toCartographic(p),c=g.position;const y=o.globe.pick(i.camera.getPickRay(g.position),o);l=this.toCartographic(y),this.lockCamera()}};this.handler.setInputAction(m=>{var y,w,f,v,C,b,M,P,L,E;if(!t())return;const p=o.pick(m.position);if(p&&p.id&&((y=p.id)!=null&&y.includes("rotationRing"))){let I=p.id.split("rotationRing_")[1];this.setEditMode("rotate"),u(I,m)}else if(p&&p.id&&((w=p.id)!=null&&w.includes("translationSquare_"))){let I=p.id.split("translationSquare_")[1];this.setEditMode("move"),u(I,m)}else if(p&&p.id&&((f=p.id)!=null&&f.includes("heightArrow-line_"))){let I=p.id.split("heightArrow-line_")[1];this.setEditMode("moveHeight"),u(I,m)}else if(p&&p.id&&((v=p.id)!=null&&v.includes("heightArrow-arrow_"))){let I=p.id.split("heightArrow-arrow_")[1];this.setEditMode("moveHeight"),u(I,m)}else if(p&&p.id){if(s=this.primitives.get(p.id),!s)return;(!this.rotationRing||!((b=(C=this.rotationRing)==null?void 0:C._instanceIds)!=null&&b.includes(`rotationRing_${s.id}`)))&&this.createRotationRing(s),(!this.translationSquare||!((P=(M=this.translationSquare)==null?void 0:M._instanceIds)!=null&&P.includes(`translationSquare_${s.id}`)))&&this.createTranslationSquare(s),(!this.heightArrow||!((E=(L=this.heightArrow)==null?void 0:L._instanceIds)!=null&&E.includes(`heightArrow_${s.id}`)))&&this.createHeightArrow(s)}else d()},e.ScreenSpaceEventType.LEFT_DOWN),this.handler.setInputAction(m=>{if(t()&&this.editMode!=""&&s){const p=o.globe.pick(i.camera.getPickRay(m.endPosition),o),y=this.toCartographic(p);let w=0;if(this.editMode==="rotate"){let f=this.calculateHeading(n,y);w=this.calculateHeading(n,l)-f,this.rotateModel(s,r,w)}else this.editMode==="move"?this.moveModel(s,r,m):this.editMode==="moveHeight"&&this.moveModelHeight(s,r,m,c)}},e.ScreenSpaceEventType.MOUSE_MOVE),this.handler.setInputAction(()=>{if(!t())return;let g=this.dragEndCallbackMap.get(s==null?void 0:s.id);if(g&&(this.editMode==="move"||this.editMode==="moveHeight")){let p=g.get("translation");p&&(this.runEventListener("translation",p),g.delete("translation"))}else if(g&&this.editMode==="rotate"){let p=g.get("rotate");p&&(this.runEventListener("rotate",p),g.delete("rotate"))}d()},e.ScreenSpaceEventType.LEFT_UP),this.handler.setInputAction(()=>{this.removeTool()},e.ScreenSpaceEventType.RIGHT_UP)}createRotationRing(t){const e=this.Cesium,i=this.viewer;this.rotationRing&&i.scene.primitives.remove(this.rotationRing);const o=[];for(let n=0;n<=360;n+=3){const l=Math.sin(e.Math.toRadians(n)),c=Math.cos(e.Math.toRadians(n)),d=t.boundingSphere.radius*c,u=t.boundingSphere.radius*l;o.push(new e.Cartesian3(d,u,0))}const s=new e.PolylineGeometry({positions:o,width:Math.max(t.boundingSphere.radius*.05,1)}),r=new e.GeometryInstance({id:`rotationRing_${t.id}`,geometry:s,attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(e.Color.RED)}});this.rotationRing=new e.Primitive({geometryInstances:r,appearance:new e.PolylineColorAppearance({translucent:!0}),depthFailAppearance:new e.PolylineMaterialAppearance({material:e.Material.fromType("Color",{color:e.Color.RED.withAlpha(.3)}),translucent:!0}),modelMatrix:t.modelMatrix,cull:!1}),i.scene.primitives.add(this.rotationRing)}createTranslationSquare(t){const e=this.Cesium,i=this.viewer;this.translationSquare&&i.scene.primitives.remove(this.translationSquare);const s=Math.max(t.boundingSphere.radius*.2,1)/2,r=new e.BoxGeometry({maximum:new e.Cartesian3(s,s,s),minimum:new e.Cartesian3(-s,-s,-s)}),n=new e.GeometryInstance({id:`translationSquare_${t.id}`,geometry:r,attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(e.Color.BLUE)}});this.translationSquare=new e.Primitive({geometryInstances:n,appearance:new e.PolylineColorAppearance({translucent:!0}),depthFailAppearance:new e.PolylineMaterialAppearance({material:e.Material.fromType("Color",{color:e.Color.BLUE.withAlpha(.3)}),translucent:!0}),cull:!1,modelMatrix:t.modelMatrix}),i.scene.primitives.add(this.translationSquare)}createHeightArrow(t){const e=this.Cesium,i=this.viewer;this.heightArrow&&i.scene.primitives.remove(this.heightArrow);let o=e.Color.GREEN,s=Math.max(t.boundingSphere.radius*.025,1),r=2*s,n=t.boundingSphere.radius+50,l=n*.1;const c=Math.max(t.boundingSphere.radius*.2,1),d=e.CylinderGeometry.createGeometry(new e.CylinderGeometry({length:n,topRadius:s,bottomRadius:s})),u=e.CylinderGeometry.createGeometry(new e.CylinderGeometry({length:l,topRadius:0,bottomRadius:r}));let m=n+c,g=(n+c)/2;this.translate(d,[0,0,g]),this.translate(u,[0,0,m]),this.heightArrow=new e.Primitive({modelMatrix:t.modelMatrix,geometryInstances:[new e.GeometryInstance({id:`heightArrow-line_${t.id}`,geometry:d}),new e.GeometryInstance({id:`heightArrow-arrow_${t.id}`,geometry:u})],appearance:new e.PolylineMaterialAppearance({material:e.Material.fromType("Color",{color:o}),translucent:!0}),depthFailAppearance:new e.PolylineMaterialAppearance({material:e.Material.fromType("Color",{color:o.withAlpha(.3)}),translucent:!0}),cull:!1}),i.scene.primitives.add(this.heightArrow)}translate(t,e){let i=this.Cesium;const o=new i.Cartesian3;_e(e)?(o.x=e[0],o.y=e[1],o.z=e[2]):i.Cartesian3.clone(e,o);for(let s=0;s<t.attributes.position.values.length;s+=3)t.attributes.position.values[s]+=o.x,t.attributes.position.values[s+1]+=o.y,t.attributes.position.values[s+2]+=o.z}removeTool(){this.rotationRing&&this.viewer.scene.primitives.remove(this.rotationRing),this.translationSquare&&this.viewer.scene.primitives.remove(this.translationSquare),this.heightArrow&&this.viewer.scene.primitives.remove(this.heightArrow)}updatedTool(t){this.rotationRing&&(this.rotationRing.modelMatrix=t),this.translationSquare&&(this.translationSquare.modelMatrix=t),this.heightArrow&&(this.heightArrow.modelMatrix=t)}moveModel(t,e,i){const o=this.Cesium,s=this.viewer,r=s.scene,n=r.globe.pick(s.camera.getPickRay(i.endPosition),r);if(n){const l=o.Matrix4.getTranslation(e,new o.Cartesian3),c=o.Cartographic.fromCartesian(l),d=o.Cartographic.fromCartesian(n),u=new o.Cartographic(d.longitude,d.latitude,c.height),m=o.Cartographic.toCartesian(u),g=o.Matrix4.getRotation(e,new o.Matrix3),p=o.Matrix4.fromRotationTranslation(g,m);t.modelMatrix=p,this.updatedTool(p);let y=new o.Cartesian3(p[12],p[13],p[14]),w=this.dragEndCallbackMap.get(t.id);w||(w=new Map,this.dragEndCallbackMap.set(t.id,w)),w.set("translation",{id:t.id,position:y})}}moveModelHeight(t,e,i,o){const s=this.Cesium,r=this.viewer,n=r.scene,l=o.y-i.endPosition.y;if(n.globe.pick(r.camera.getPickRay(i.endPosition),n)){const d=s.Matrix4.getTranslation(e,new s.Cartesian3),u=s.Cartographic.fromCartesian(d),m=new s.Cartographic(u.longitude,u.latitude,u.height+l*.001*Math.max(r.camera.positionCartographic.height,1)),g=s.Cartographic.toCartesian(m),p=s.Matrix4.getRotation(e,new s.Matrix3),y=s.Matrix4.fromRotationTranslation(p,g);t.modelMatrix=y,this.updatedTool(y);let w=new s.Cartesian3(y[12],y[13],y[14]),f=this.dragEndCallbackMap.get(t.id);f||(f=new Map,this.dragEndCallbackMap.set(t.id,f)),f.set("translation",{id:t.id,position:w})}}rotateModel(t,e,i){const o=this.Cesium,s=this.viewer,r=this.getModelHeadingPitchRoll(e),n=r.heading+i,l=new o.HeadingPitchRoll(n,r.pitch,r.roll),c=o.Transforms.headingPitchRollToFixedFrame(o.Matrix4.getTranslation(t.modelMatrix,new o.Cartesian3),l,s.scene.globe.ellipsoid,o.Transforms.eastNorthUpToFixedFrame,new o.Matrix4);t.modelMatrix=c;let d=this.dragEndCallbackMap.get(t.id);d||(d=new Map,this.dragEndCallbackMap.set(t.id,d)),d.set("rotate",{id:t.id,headingPitchRoll:{heading:o.Math.toDegrees(n),pitch:o.Math.toDegrees(r.pitch),roll:o.Math.toDegrees(r.roll)}})}cleanup(){this.handler&&(this.handler.destroy(),this.handler=null)}}function Co(a,t){const e=t.materialType||"DynamicImgMaterial"+Date.now()+Math.floor(Math.random()*1e3);function i(s){this._definitionChanged=new a.Event,this._color=s.color,this._colorSubscription=void 0,this.color=s.color,this.duration=s.duration,this._time=Date.now()}Object.defineProperties(i.prototype,{isConstant:{get(){return!1}},definitionChanged:{get(){return this._definitionChanged}},color:a.createPropertyDescriptor("color")}),i.prototype.getType=function(){return e},i.prototype.getValue=function(s,r){return a.defined(r)||(r={}),r.color=a.Property.getValueOrClonedDefault(this._color,s,a.Color.WHITE,r.color),r.image=t.image,r},i.prototype.equals=function(s){return this===s||s instanceof i&&a.Property.equals(this._color,s._color)};const o=function(s){return`
|
|
1
|
+
(function(S,te){typeof exports=="object"&&typeof module<"u"?te(exports):typeof define=="function"&&define.amd?define(["exports"],te):(S=typeof globalThis<"u"?globalThis:S||self,te(S.CesiumCore={}))})(this,(function(S){"use strict";var kn=Object.defineProperty;var Fn=(S,te,V)=>te in S?kn(S,te,{enumerable:!0,configurable:!0,writable:!0,value:V}):S[te]=V;var h=(S,te,V)=>Fn(S,typeof te!="symbol"?te+"":te,V);class te{constructor(t,e,i){h(this,"Cesium");h(this,"viewer");h(this,"labelPool");h(this,"threshold");h(this,"displayLimit");h(this,"maxLevel");h(this,"debugCurrentGrids");h(this,"levels");h(this,"points",[]);h(this,"gridLayers",new Map);h(this,"debugGrids",[]);h(this,"_updateFn");h(this,"clusterTheme");h(this,"pointTheme");h(this,"centralPointMode");h(this,"minGlobalPointCount");h(this,"groupByTheme");h(this,"tilingScheme");h(this,"terrainLevelOffset");h(this,"debugTileCoordLayer",null);h(this,"levelIndexByTileLevel",new Map);h(this,"_lastTileProvider",null);h(this,"_updateTimer",null);h(this,"_updateDelay",100);h(this,"_tilesRetryCount",0);h(this,"_tilesRetryMax",100);h(this,"_cameraDirty",!1);h(this,"_tileLoadListener",null);h(this,"_cameraChangedHandler",null);h(this,"defaultMinLevel",0);h(this,"defaultMaxLevel",28);h(this,"maxRefineLevels",2);this.Cesium=t,this.viewer=e,this.labelPool=i.labelPool,this.threshold=i.threshold??10,this.displayLimit=i.displayLimit??100,this.maxLevel=i.maxLevel??5,this.debugCurrentGrids=i.debugCurrentGrids??!1,this.clusterTheme=i.clusterTheme??"cluster-label",this.pointTheme=i.pointTheme??"point-label",this.centralPointMode=i.centralPointMode??"central",this.minGlobalPointCount=i.minGlobalPointCount??0,this.groupByTheme=i.groupByTheme??!1,this.terrainLevelOffset=i.terrainLevelOffset??2;const n=this.viewer.scene&&this.viewer.scene.globe,s=n&&n._surface,o=s&&s._tileProvider,r=(o==null?void 0:o.tilingScheme)||new this.Cesium.GeographicTilingScheme;this._lastTileProvider=o,this.tilingScheme=r,this.levels=this._createLevels(),this._buildLevels(),this._updateFn=this._update.bind(this),this.debugCurrentGrids&&this._ensureDebugImageryLayer(),n&&(this._tileLoadListener=l=>{l===0&&this._cameraDirty&&(this._cameraDirty=!1,this._scheduleUpdate())},n.tileLoadProgressEvent.addEventListener(this._tileLoadListener)),this._cameraChangedHandler=()=>{this._update()},this.viewer.camera.changed.addEventListener(this._cameraChangedHandler)}setGroupByTheme(t,e=!0,i=!0){if(this.groupByTheme===t){i&&this._update();return}this.groupByTheme=t,e&&this._buildLevels(),i&&this._update()}setMinGlobalPointCount(t,e=!0){this.minGlobalPointCount=t,e&&this._update()}setThreshold(t,e=!0){this.threshold=t,e&&this._update()}setDebugCurrentGrids(t,e=!0){this.debugCurrentGrids=t,t?this._ensureDebugImageryLayer():(this._clearDebugGrids(),this._removeDebugImageryLayer()),e&&this._update()}_syncTilingSchemeAndLevels(){const t=this.viewer.scene&&this.viewer.scene.globe,e=t&&t._surface,i=e&&e._tileProvider,n=(i==null?void 0:i.tilingScheme)||new this.Cesium.GeographicTilingScheme,s=i!==this._lastTileProvider,o=this.tilingScheme!==n;!s&&!o&&this.levels&&this.levels.length>0||(this._lastTileProvider=i,this.tilingScheme=n,this.levels=this._createLevels(),this._buildLevels(),this.debugCurrentGrids&&(this._removeDebugImageryLayer(),this._ensureDebugImageryLayer()))}_createLevels(){const t=[];this.levelIndexByTileLevel=new Map;const e=0,i=this.maxLevel;let n=0;for(let s=e;s<=i;s++,n++){const o=360/Math.pow(2,s);t.push({level:s,size:o,minViewWidth:o*4}),this.levelIndexByTileLevel.set(s,n)}return t}addPoints(t){this.points=t,this._buildLevels()}appendPoints(t,e=!0){for(const i of t)this._preparePointLevelRange(i),this.points.push(i);for(const i of t)this._addPointToGrid(i);e&&this._scheduleUpdate()}_scheduleUpdate(){this._updateTimer!==null&&clearTimeout(this._updateTimer),this._updateTimer=window.setTimeout(()=>{this._update(),this._cameraDirty=!0,this._updateTimer=null},this._updateDelay)}updatePoint(t){var s,o,r,l;const e=this.points.findIndex(c=>c.id===t.id);if(e===-1)return;const i=this.points[e];for(const c of this.levels){const d=c.level,u=this.gridLayers.get(d);if(!u)continue;const m=this.Cesium.Cartographic.fromDegrees(i.lon,i.lat),g=this.tilingScheme.positionToTileXY(m,d,new this.Cesium.Cartesian2);if(!g)continue;const p=`${g.x}_${g.y}`,f=u.get(p);if(f){const w=f.allPoints.findIndex(y=>y.id===t.id);if(w!==-1&&f.allPoints.splice(w,1),(r=(o=(s=i.data)==null?void 0:s.billboard)==null?void 0:o[0])!=null&&r.skipAggregation){const y=f.skipPoints.findIndex(v=>v.id===t.id);y!==-1&&f.skipPoints.splice(y,1)}else{const y=this.groupByTheme?(l=i.data)==null?void 0:l.theme:this.clusterTheme,v=f.groups.get(y);if(v){const C=v.findIndex(b=>b.id===t.id);C!==-1&&v.splice(C,1),v.length===0&&f.groups.delete(y)}}}}const n={...i,...t};this.points[e]=n,this._addPointToGrid(n),this._update()}removePointsById(t){const e=new Set(t);this.points=this.points.filter(i=>!e.has(i.id));for(const i of this.levels){const n=this.gridLayers.get(i.level);if(n)for(const[s,o]of n.entries()){o.allPoints=o.allPoints.filter(r=>!e.has(r.id)),o.skipPoints=o.skipPoints.filter(r=>!e.has(r.id));for(const[r,l]of o.groups.entries()){const c=l.filter(d=>!e.has(d.id));c.length===0?o.groups.delete(r):o.groups.set(r,c)}o.allPoints.length===0&&n.delete(s)}}this._update()}_buildLevels(){this.gridLayers.clear();for(const t of this.levels)this.gridLayers.set(t.level,new Map);for(const t of this.points)this._addPointToGrid(t)}_addPointToGrid(t){var e,i,n,s,o,r;for(const l of this.levels){const c=l.level,d=this.gridLayers.get(c);if(!d)continue;const u=this.Cesium.Cartographic.fromDegrees(t.lon,t.lat),m=this.tilingScheme.positionToTileXY(u,c,new this.Cesium.Cartesian2);if(!m)continue;const g=`${m.x}_${m.y}`;let p=d.get(g);if(p||(p={allPoints:[],groups:new Map,skipPoints:[]},d.set(g,p)),p.allPoints.push(t),(n=(i=(e=t.data)==null?void 0:e.billboard)==null?void 0:i[0])!=null&&n.skipAggregation)p.skipPoints.push(t);else{const f=this.groupByTheme?(r=(o=(s=t.data)==null?void 0:s.billboard)==null?void 0:o[0])==null?void 0:r.theme:this.clusterTheme;p.groups.has(f)||p.groups.set(f,[]),p.groups.get(f).push(t)}}}_preparePointLevelRange(t){const e=t.data||{};let i=e.minLevel,n=e.maxLevel;const s=e.levelRange;Array.isArray(s)?(s.length>0&&i==null&&(i=s[0]),s.length>1&&n==null&&(n=s[1])):s&&typeof s=="object"&&(i==null&&typeof s.min=="number"&&(i=s.min),n==null&&typeof s.max=="number"&&(n=s.max));const o=i==null?this.defaultMinLevel:Number(i)||this.defaultMinLevel,r=n==null?this.defaultMaxLevel:Number(n)||this.defaultMaxLevel;t.__minLevel=o,t.__maxLevel=r}_isVisibleAtLevel(t,e){if(e==null)return!0;(t.__minLevel===void 0||t.__maxLevel===void 0)&&this._preparePointLevelRange(t);const i=t.__minLevel??this.defaultMinLevel,n=t.__maxLevel??this.defaultMaxLevel;return e>=i&&e<=n}_update(){if(!this.labelPool)return;this._syncTilingSchemeAndLevels(),this.labelPool.reset(),this.debugCurrentGrids&&this._clearDebugGrids();const t=this.points.length<this.minGlobalPointCount?1/0:this.threshold;let e=0;const i=(n,s,o,r)=>{e=this._processCell(n,s,o,r,t,e)};try{const n=this._getSurfaceTiles();if(!n||n.length===0){this._handleNoSurfaceTiles(e);return}this._tilesRetryCount=0,this._processTiles(n,i)}catch{this.labelPool.cleanup();return}this.labelPool.cleanup()}_getSurfaceTiles(){const t=this.viewer.scene&&this.viewer.scene.globe,e=t&&t._surface;if(e)return e._tilesToRender||e._tilesToRenderByTextureCount}_handleNoSurfaceTiles(t){var e,i,n,s;for(const o of this.points){if(t>=this.displayLimit)break;((e=o.data)==null?void 0:e.show)!==!1&&(this.labelPool.add(o.data,{id:`point-${o.id}`,lon:o.lon,lat:o.lat,height:o.height,theme:((s=(n=(i=o.data)==null?void 0:i.billboard)==null?void 0:n[0])==null?void 0:s.theme)||this.pointTheme,style:o.style}),t++)}this.labelPool.cleanup(),this.points.length>0&&this._tilesRetryCount<this._tilesRetryMax&&(this._tilesRetryCount++,this._scheduleUpdate())}_resolveLevelIndex(t){let e=this.levelIndexByTileLevel.get(t);if(e!==void 0)return e;if(this.levels.length===0)return;const i=this.levels[0].level,n=this.levels[this.levels.length-1].level;if(t>n)return this.levels.length-1;if(t<i)return 0;let s=0,o=1/0;for(let r=0;r<this.levels.length;r++){const l=Math.abs(this.levels[r].level-t);l<o&&(o=l,s=r)}return s}_isTerrainEnabled(){const t=this.viewer.terrainProvider,e=this.viewer.scene,i=e&&e.globe,n=i&&i.terrainProvider,s=t||n;return s?!(s instanceof this.Cesium.EllipsoidTerrainProvider):!1}_getGridRefLevel(t){let e=t;if(this._isTerrainEnabled()&&(e+=this.terrainLevelOffset),this.levels.length>0){const i=this.levels[this.levels.length-1].level;e>i&&(e=i)}return e}_processTiles(t,e){const i=new Set,n=!this._isTerrainEnabled(),s=this.viewer.scene,o=s&&s.globe,r=o&&o.ellipsoid,l=r&&s.camera.computeViewRectangle(r),c=(d,u,m)=>{if(!n||!l)return!0;const g=this.tilingScheme.tileXYToRectangle(d,u,m);return!(!g||g.east<=l.west||g.west>=l.east||g.north<=l.south||g.south>=l.north)};for(const d of t){const u=d.rectangle,m=d._level??d.level;if(!u||typeof m!="number")continue;const g=this._getGridRefLevel(m),p=this._resolveLevelIndex(g);if(p===void 0)continue;const f=this.levels[p].level,w=d._x??d.x,y=d._y??d.y;if(typeof w=="number"&&typeof y=="number"){const T=m-f;if(T>=0){const $=1<<T,D=Math.floor(w/$),k=Math.floor(y/$),_=`${f}_${D}_${k}`;if(i.has(_))continue;i.add(_),e(p,D,k,m)}else{const D=1<<Math.min(-T,this.maxRefineLevels),k=w*D,_=y*D;for(let O=0;O<D;O++)for(let R=0;R<D;R++){const G=k+O,B=_+R;if(!c(G,B,f))continue;const j=`${f}_${G}_${B}`;i.has(j)||(i.add(j),e(p,G,B,m))}}continue}const C=this.levels[p].size,b=this.Cesium.Math.toDegrees(u.west),M=this.Cesium.Math.toDegrees(u.east),P=this.Cesium.Math.toDegrees(u.south),L=this.Cesium.Math.toDegrees(u.north),E=Math.floor((b- -180)/C),I=Math.floor((M- -180)/C),A=Math.floor((P- -90)/C),x=Math.floor((L- -90)/C);for(let T=E;T<=I;T++)for(let $=A;$<=x;$++){if(!c(T,$,f))continue;const D=`${f}_${T}_${$}`;i.has(D)||(i.add(D),e(p,T,$,m))}}}_processCell(t,e,i,n,s,o){if(o>=this.displayLimit||t<0)return o;t>=this.levels.length&&(t=this.levels.length-1);const r=this._getCellContext(t,e,i,n);return r?(o=this._processCellSkipPoints(r,o),o>=this.displayLimit?(this._debugDrawCell(r),o):(o=this._processCellGroups(r,s,o),this._debugDrawCell(r),o)):o}_getCellContext(t,e,i,n){const o=this.levels[t].level,r=this.gridLayers.get(o);if(!r)return null;const l=`${e}_${i}`,c=r.get(l);if(!c)return null;const d=this.tilingScheme.tileXYToRectangle(e,i,o),u=this.Cesium.Math.toDegrees(d.west),m=this.Cesium.Math.toDegrees(d.south),g=this.Cesium.Math.toDegrees(d.east),p=this.Cesium.Math.toDegrees(d.north),f=(u+g)/2,w=(m+p)/2;return{levelIdx:t,tileLevel:o,lonIdx:e,latIdx:i,key:l,cell:c,rect:d,west:u,south:m,east:g,north:p,centerLon:f,centerLat:w,viewTileLevel:n}}_processCellSkipPoints(t,e){var o,r,l,c;const{cell:i,viewTileLevel:n}=t,s=n;for(const d of i.skipPoints)if(((o=d.data)==null?void 0:o.show)!==!1){if(e>=this.displayLimit)break;this._isVisibleAtLevel(d,s)&&(this.labelPool.add(d.data,{id:`point-${d.id}`,lon:d.lon,lat:d.lat,height:d.height,theme:((c=(l=(r=d.data)==null?void 0:r.billboard)==null?void 0:l[0])==null?void 0:c.theme)||this.pointTheme,style:d.style}),e++)}return e}_processCellGroups(t,e,i){var m,g,p,f,w,y,v,C,b,M,P,L,E;const{levelIdx:n,lonIdx:s,latIdx:o,cell:r,centerLon:l,centerLat:c,viewTileLevel:d}=t,u=d;for(const[I,A]of r.groups){const x=A.filter(_=>{var O;return((O=_.data)==null?void 0:O.show)!==!1});if(x.length===0)continue;let T=l,$=c,D=((m=x[0])==null?void 0:m.height)||0;if(this.centralPointMode=="firstPoint"&&(T=((g=x[0])==null?void 0:g.lon)||0,$=((p=x[0])==null?void 0:p.lat)||0,D=((f=x[0])==null?void 0:f.height)||0),n===this.levels.length-1||x.length<e)for(const _ of x){if(i>=this.displayLimit)break;this._isVisibleAtLevel(_,u)&&(this.labelPool.add(_.data,{id:`point-${_.id}`,lon:_.lon,lat:_.lat,height:_.height,theme:((v=(y=(w=_.data)==null?void 0:w.billboard)==null?void 0:y[0])==null?void 0:v.theme)||this.pointTheme,style:_.style}),i++)}else{if(i>=this.displayLimit)return i;const _=u==null?x:x.filter(B=>this._isVisibleAtLevel(B,u));if(!_.length)return i;const R=((P=(M=(b=(C=_[0])==null?void 0:C.data)==null?void 0:b.billboard)==null?void 0:M[0])==null?void 0:P.theme)||this.clusterTheme,G=this.groupByTheme?`cluster-${n}-${s}-${o}-${I}`:`cluster-${n}-${s}-${o}`;this.labelPool.add({id:G,billboard:((E=(L=_[0])==null?void 0:L.data)==null?void 0:E.billboard)||[],count:_.length,gridKey:`${s}_${o}`,points:_,aggregationGroup:I},{id:G,lon:T,lat:$,height:D,theme:R}),i++}}return i}_debugDrawCell(t){if(!this.debugCurrentGrids)return;const{levelIdx:e,west:i,south:n,east:s,north:o,lonIdx:r,latIdx:l}=t,c=this.levels[e].level;this._drawDebugGrid(i,n,s,o,`L:${c} X:${r} Y:${l}`)}refresh(){this._update()}_drawDebugGrid(t,e,i,n,s){const o=this.Cesium.Rectangle.fromDegrees(t,e,i,n),r=this.Cesium.Cartesian3.fromDegreesArray([t,e,i,e,i,n,t,n,t,e]),l=this.viewer.entities.add({rectangle:{coordinates:o,material:this.Cesium.Color.YELLOW.withAlpha(.2),outline:!0,outlineColor:this.Cesium.Color.RED,heightReference:this.Cesium.HeightReference.CLAMP_TO_GROUND,classificationType:this.Cesium.ClassificationType.TERRAIN},polyline:{positions:r,width:2,material:this.Cesium.Color.RED,clampToGround:!0},label:{text:s,font:"14px sans-serif",fillColor:this.Cesium.Color.BLACK,outlineColor:this.Cesium.Color.WHITE,outlineWidth:2,style:this.Cesium.LabelStyle.FILL_AND_OUTLINE,verticalOrigin:this.Cesium.VerticalOrigin.CENTER,horizontalOrigin:this.Cesium.HorizontalOrigin.CENTER}});this.debugGrids.push(l)}_clearDebugGrids(){for(const t of this.debugGrids)this.viewer.entities.remove(t);this.debugGrids=[]}_ensureDebugImageryLayer(){if(this.debugTileCoordLayer||!this.viewer||!this.viewer.imageryLayers)return;const t={tilingScheme:this.tilingScheme};this.debugTileCoordLayer=this.viewer.imageryLayers.addImageryProvider(new this.Cesium.TileCoordinatesImageryProvider(t))}_removeDebugImageryLayer(){if(!(!this.debugTileCoordLayer||!this.viewer||!this.viewer.imageryLayers)){try{this.viewer.imageryLayers.remove(this.debugTileCoordLayer,!1)}catch{}this.debugTileCoordLayer=null}}destroy(){this._cameraChangedHandler&&(this.viewer.camera.changed.removeEventListener(this._cameraChangedHandler),this._cameraChangedHandler=null);const t=this.viewer.scene,e=t&&t.globe;e&&this._tileLoadListener&&(e.tileLoadProgressEvent.removeEventListener(this._tileLoadListener),this._tileLoadListener=null),this._updateTimer!==null&&(clearTimeout(this._updateTimer),this._updateTimer=null),this.labelPool.reset(),this._clearDebugGrids(),this._removeDebugImageryLayer()}}var V=(a=>(a.Click="marker:click",a.DoubleClick="marker:dblclick",a.RightClick="marker:rightclick",a.MouseEnter="marker:mouseenter",a.MouseLeave="marker:mouseleave",a.MouseDown="marker:mousedown",a.MouseUp="marker:mouseup",a))(V||{});class tt{constructor(){h(this,"listenerMap",new Map)}addListener(t,e,i=!1){let n=this.listenerMap.get(t);return n||(n=new Map,this.listenerMap.set(t,n)),n.has(e.name)?i?(console.warn(`[MarkerEventBus] Overwriting listener "${e.name}" for event "${t}".`),n.set(e.name,e),!0):(console.warn(`[MarkerEventBus] Listener "${e.name}" for event "${t}" already exists. Use overwrite=true to replace it.`),!1):(n.set(e.name,e),!0)}removeListenerByKey(t){const e=this.listenerMap.has(t);return this.listenerMap.set(t,new Map),e}removeListenerByKeyAndName(t,e){const i=this.listenerMap.get(t);return i?i.delete(e):!1}runListener(t,e,i){const n=this.listenerMap.get(t);if(n)for(const[s,o]of n.entries()){try{o.fn(e,i)}catch(r){console.error(`Error in listener "${s}" for event "${t}":`,r)}o.once&&n.delete(s)}}}const it={[V.Click]:"click",[V.DoubleClick]:"dblclick",[V.RightClick]:"contextmenu",[V.MouseEnter]:"mouseenter",[V.MouseLeave]:"mouseleave",[V.MouseDown]:"mousedown",[V.MouseUp]:"mouseup"};class N{constructor(t,e,i="html-label-container",n,s=!0){h(this,"viewer");h(this,"Cesium");h(this,"container");h(this,"labels",new Map);h(this,"activeIds",new Set);h(this,"occludedIds",new Set);h(this,"_updateFn");h(this,"_cameraChangedFn");h(this,"themes",{});h(this,"occlusionCheckLogs",[]);h(this,"occlusionLogEnabled",!1);h(this,"occlusionLogMax",1e4);h(this,"occlusionOptions",{enabled:!1,throttleMs:120,distanceEpsilon:1});h(this,"_occlusionTimer",null);h(this,"_lastOcclusionAt",0);h(this,"_occlusionChecking",!1);h(this,"_occlusionPending",!1);h(this,"eventBus");h(this,"openWheel",!0);this.Cesium=t,this.viewer=e,this.container=this._createContainer(i),this._updateFn=this._update.bind(this),this.viewer.scene.postRender.addEventListener(this._updateFn),this._cameraChangedFn=this._scheduleOcclusionCheck.bind(this),this.viewer.camera.changed.addEventListener(this._cameraChangedFn),this.eventBus=n||new tt,this.openWheel=s,this.runOcclusionCheckNow()}_createContainer(t){let e=document.getElementById(t);return e||(e=document.createElement("div"),e.id=t,Object.assign(e.style,{position:"absolute",top:"0",left:"0",pointerEvents:"none",width:"100%",height:"100%",zIndex:"100",overflow:"hidden"}),document.body.appendChild(e)),e}registerTheme(t,e){this.themes[t]=e}add(t,e){const{id:i,lon:n,lat:s,height:o=0,theme:r,show:l=!0,notCreateElement:c=!1,style:d}=e,u=this.themes[r];if(!u){console.warn(`Theme "${r}" not registered`);return}let m=this.labels.get(i);if(m){m.theme=r,m.data=t,m.notCreateElement=c;try{m.unload=u.createElement(m.el,{id:i,theme:r,data:t},u),(!c||l)&&this.container.appendChild(m.el)}catch(g){console.error(`Error updating label element for id "${i}":`,g)}}else{const g=document.createElement("div");Object.assign(g.style,{position:"absolute",transform:"translate(0, 0)",pointerEvents:"auto",...e.style||{}});for(const[f,w]of Object.entries(it)){g.addEventListener(w,v=>{v.stopPropagation();const C=this.labels.get(i);this.eventBus.runListener(f,C,v)});let y=0;g.addEventListener("wheel",v=>{if(!this.openWheel)return;const C=v.currentTarget;y=Date.now();const b=y;C.style.pointerEvents="none",setTimeout(()=>{y===b&&(C.style.pointerEvents="auto")},2e3)})}let p=null;if(!c||l){try{p=u.createElement(g,{id:i,theme:r,data:t},u)||{}}catch(f){console.error(`Error updating label element for id "${i}":`,f)}this.container.appendChild(g)}m={id:i,el:g,theme:r,data:t,notCreateElement:c,unload:p},this.labels.set(i,m)}m.el.dataset.lon=String(n),m.el.dataset.lat=String(s),m.el.dataset.height=String(o),m.el.style.zIndex=(d==null?void 0:d.zIndex)||"1",m.el.style.display=l?"block":"none",l&&this.activeIds.add(i),l?this._scheduleOcclusionCheck():this.occludedIds.delete(i)}addBatch(t){for(const{data:e,options:i}of t)this.add(e,i)}removeByIds(t){for(const e of t){const i=this.labels.get(e);i&&(this.unloadByLabel(i),this.labels.delete(e),this.activeIds.delete(e),this.occludedIds.delete(e))}}unloadByLabel(t){t.el.remove(),t!=null&&t.unload&&typeof t.unload=="function"&&(t==null||t.unload()),t.unload=null}removeAll(){for(const t of this.labels.values())this.unloadByLabel(t);this.labels.clear(),this.activeIds.clear(),this.occludedIds.clear()}update(t,e){const i=this.labels.get(t);if(!i){console.warn(`Label with id "${t}" not found for update.`);return}const n=this.themes[i.theme];if(!n){console.warn(`Theme "${i.theme}" not registered.`);return}try{n.createElement(i.el,{id:t,theme:i.theme,data:e},n)}catch(s){console.error(`Failed to update label "${t}":`,s)}}hideByIds(t){for(const e of t){const i=this.labels.get(e);i&&(i.notCreateElement&&this.unloadByLabel(i),i.el.style.display="none",this.activeIds.delete(e),this.occludedIds.delete(e))}}hideAll(){for(const t of this.labels.values())t.notCreateElement&&this.unloadByLabel(t),t.el.style.display="none",this.activeIds.delete(t.id),this.occludedIds.delete(t.id)}hideFilter(t){for(const e of this.labels.values())t(e.data)&&(e.notCreateElement&&this.unloadByLabel(e),e.el.style.display="none",this.activeIds.delete(e.id),this.occludedIds.delete(e.id))}showByIds(t){for(const e of t){const i=this.labels.get(e);if(i){if((i.notCreateElement||!i.el.parentNode)&&this.container.appendChild(i.el),!i.unload)try{const n=this.themes[i.theme];if(!n){console.warn(`Theme "${i.theme}" not registered`);return}i.unload=n.createElement(i.el,{id:e,theme:i.theme,data:i.data},n)||{}}catch(n){console.error(`Error creating label element for theme "${i.theme}":`,n);return}i.el.style.display="block",this.activeIds.add(e),this.occludedIds.delete(e)}}this._scheduleOcclusionCheck()}has(t){return this.labels.has(t)}reset(){for(const t of this.activeIds.values()){let e=this.labels.get(t);e&&this.unloadByLabel(e)}this.activeIds.clear()}cleanup(){for(const[t,e]of this.labels.entries())this.activeIds.has(t)||(e.el.style.display="none",this.occludedIds.delete(t))}async toWindowPositionByLonLat(t,e){const i=this.Cesium,n=this.viewer.scene,s=[i.Cartographic.fromDegrees(t,e)];let o;try{o=await n.clampToHeightMostDetailed(s)}catch{console.warn("clampToHeightMostDetailed failed, fallback to ellipsoid height.")}let r=0;o&&o[0]&&o[0].height!=null?r=o[0].height:r=0;const l=i.Cartesian3.fromDegrees(t,e,r);return this.toWindowCoordinates(l)}toWindowCoordinates(t){const e=this.viewer.scene,i=this.Cesium.SceneTransforms;if(typeof(i==null?void 0:i.wgs84ToWindowCoordinates)=="function")return i.wgs84ToWindowCoordinates(e,t);if(typeof(i==null?void 0:i.worldToWindowCoordinates)=="function")return i.worldToWindowCoordinates(e,t);console.warn("No compatible window coordinate transform function found.")}_isValidCoordinate(t,e){return!(Number.isNaN(t)||Number.isNaN(e)||t===0&&e===0||t<-180||t>180||e<-90||e>90)}async _update(){var t;for(const e of this.activeIds){const i=this.labels.get(e);if(!i)continue;const n=parseFloat(i.el.dataset.lon),s=parseFloat(i.el.dataset.lat),o=parseFloat(i.el.dataset.height||"0");if(!this._isValidCoordinate(n,s)){i.el.style.display="none";continue}const r=this.Cesium.Cartesian3.fromDegrees(n,s,o),l=this.toWindowCoordinates(r);if(this.Cesium.defined(l)){const d=((t=this.themes[i.theme].options)==null?void 0:t.offset)||{},u=d.x||0,m=d.y||0,g=this.occludedIds.has(e);i.el.style.left=`${l.x}px`,i.el.style.top=`${l.y}px`,i.el.style.transform=`translate(${u}px, ${m}px)`,i.el.style.display=g?"none":"block"}else i.el.style.display="none"}}_scheduleOcclusionCheck(){if(!this.occlusionOptions.enabled)return;const t=Date.now(),e=Math.max(0,Number(this.occlusionOptions.throttleMs)||0),i=t-this._lastOcclusionAt,n=Math.max(0,e-i);if(n===0){this.runOcclusionCheckNow();return}this._occlusionTimer===null&&(this._occlusionTimer=window.setTimeout(()=>{this._occlusionTimer=null,this.runOcclusionCheckNow()},n))}_pushOcclusionLog(t){this.occlusionLogEnabled&&(this.occlusionCheckLogs.push(t),this.occlusionCheckLogs.length>this.occlusionLogMax&&this.occlusionCheckLogs.splice(0,this.occlusionCheckLogs.length-this.occlusionLogMax))}_computeLabelOccluded(t,e,i,n,s,o){var d,u;const r=(d=this.viewer)==null?void 0:d.scene,l=(u=this.viewer)==null?void 0:u.camera,c=this.Cesium;if(!r||!l||!c)return this._pushOcclusionLog({timestamp:Date.now(),id:t,lon:n,lat:s,height:o,occluded:!0,reason:"runtime-missing"}),!0;if(!r.pickPositionSupported||!i)return this._pushOcclusionLog({timestamp:Date.now(),id:t,lon:n,lat:s,height:o,occluded:!0,reason:"pick-unsupported"}),!0;try{const m=r.pickPosition(i);if(!m||!l.positionWC)return this._pushOcclusionLog({timestamp:Date.now(),id:t,lon:n,lat:s,height:o,occluded:!0,reason:"pick-empty"}),!0;const g=Number(this.occlusionOptions.distanceEpsilon)||0,p=c.Cartesian3.distance(l.positionWC,e),f=c.Cartesian3.distance(l.positionWC,m),w=f+g<p;return this._pushOcclusionLog({timestamp:Date.now(),id:t,lon:n,lat:s,height:o,occluded:w,reason:"distance-compare",epsilon:g,labelDistance:p,pickedDistance:f}),w}catch{return this._pushOcclusionLog({timestamp:Date.now(),id:t,lon:n,lat:s,height:o,occluded:!0,reason:"pick-error"}),!0}}runOcclusionCheckNow(){if(!this.occlusionOptions.enabled){this.occludedIds.clear();return}if(this._occlusionChecking){this._occlusionPending=!0;return}this._occlusionChecking=!0;try{for(const t of this.activeIds){const e=this.labels.get(t);if(!e){this.occludedIds.delete(t),this._pushOcclusionLog({timestamp:Date.now(),id:t,occluded:!1,reason:"label-missing"});continue}const i=parseFloat(e.el.dataset.lon),n=parseFloat(e.el.dataset.lat),s=parseFloat(e.el.dataset.height||"0");if(!this._isValidCoordinate(i,n)){this.occludedIds.delete(t),this._pushOcclusionLog({timestamp:Date.now(),id:t,lon:i,lat:n,height:s,occluded:!1,reason:"invalid-coordinate"});continue}const o=this.Cesium.Cartesian3.fromDegrees(i,n,s),r=this.toWindowCoordinates(o);if(!this.Cesium.defined(r)){this.occludedIds.delete(t),this._pushOcclusionLog({timestamp:Date.now(),id:t,lon:i,lat:n,height:s,occluded:!1,reason:"screen-position-undefined"});continue}this._computeLabelOccluded(t,o,r,i,n,s)?this.occludedIds.add(t):this.occludedIds.delete(t)}}finally{this._lastOcclusionAt=Date.now(),this._occlusionChecking=!1,this._occlusionPending&&(this._occlusionPending=!1,this._scheduleOcclusionCheck())}}setOcclusionEnabled(t){this.occlusionOptions.enabled=!!t,this.occlusionOptions.enabled?this.runOcclusionCheckNow():(this.occludedIds.clear(),this._occlusionTimer!==null&&(clearTimeout(this._occlusionTimer),this._occlusionTimer=null))}getOcclusionOptions(){return{enabled:this.occlusionOptions.enabled,throttleMs:this.occlusionOptions.throttleMs,distanceEpsilon:this.occlusionOptions.distanceEpsilon}}setOcclusionOptions(t){t.throttleMs!=null&&(this.occlusionOptions.throttleMs=Math.max(0,Number(t.throttleMs)||0)),t.distanceEpsilon!=null&&(this.occlusionOptions.distanceEpsilon=Math.max(0,Number(t.distanceEpsilon)||0)),this.occlusionOptions.enabled&&this._scheduleOcclusionCheck()}setOcclusionLogEnabled(t,e=!1){this.occlusionLogEnabled=!!t,e&&(this.occlusionCheckLogs=[])}destroy(){this.viewer.scene.postRender.removeEventListener(this._updateFn),this.viewer.camera.changed.removeEventListener(this._cameraChangedFn),this._occlusionTimer!==null&&(clearTimeout(this._occlusionTimer),this._occlusionTimer=null),this.labels.clear(),this.activeIds.clear(),this.occludedIds.clear()}}class _e{constructor(){h(this,"tooltipEl");h(this,"visible",!1);h(this,"offsetX",10);h(this,"offsetY",-20);h(this,"onMouseMove",null);this.tooltipEl=document.createElement("div"),this.tooltipEl.style.position="fixed",this.tooltipEl.style.pointerEvents="none",this.tooltipEl.style.zIndex="10000",this.tooltipEl.style.padding="4px 8px",this.tooltipEl.style.borderRadius="4px",this.tooltipEl.style.background="rgba(0, 0, 0, 0.7)",this.tooltipEl.style.color="#fff",this.tooltipEl.style.fontSize="13px",this.tooltipEl.style.transition="opacity 0.1s ease",this.tooltipEl.style.opacity="0",document.body.appendChild(this.tooltipEl),this.onMouseMove=t=>{this.visible&&(this.tooltipEl.style.left=`${t.clientX+this.offsetX}px`,this.tooltipEl.style.top=`${t.clientY+this.offsetY}px`)},window.addEventListener("mousemove",this.onMouseMove)}show(t){this.tooltipEl.innerText=t,this.tooltipEl.style.opacity="1",this.visible=!0}hide(){this.tooltipEl.style.opacity="0",this.visible=!1}destroy(){this.onMouseMove&&(window.removeEventListener("mousemove",this.onMouseMove),this.onMouseMove=null),this.tooltipEl.parentElement&&this.tooltipEl.parentElement.removeChild(this.tooltipEl)}}class Gt{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"entity",null);h(this,"tooltip",null);this.Cesium=t,this.viewer=e}startDrawing(t){const{Cesium:e,viewer:i}=this;this.tooltip=new _e,this.tooltip.show("左键添加点"),this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var m,g;const s=i.scene.pickPosition(n.position);if(!s)return;const o=e.Cartographic.fromCartesian(s),r=e.Math.toDegrees(o.longitude),l=e.Math.toDegrees(o.latitude),c=o.height,d=i.entities.add({position:s,point:{pixelSize:10,color:t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.entity=d;const u={entity:d,position:s,lnglat:{lng:r,lat:l,height:c},clear:()=>{this.clear()}};(m=t.onComplete)==null||m.call(t,u),this.stopDrawing(),(g=this.tooltip)==null||g.hide(),this.tooltip=null},e.ScreenSpaceEventType.LEFT_CLICK)}stopDrawing(){var t;(t=this.handler)==null||t.destroy(),this.handler=null}clear(){this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.stopDrawing()}}class Bt{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"positions",[]);h(this,"entity",null);h(this,"tooltip",null);h(this,"tempPoints",[]);this.Cesium=t,this.viewer=e}getPickPosition(t){var s,o,r,l;const{viewer:e}=this,i=e==null?void 0:e.scene;if(!i||!t)return null;let n=null;try{i.pickPositionSupported&&(n=i.pickPosition(t))}catch(c){console.warn("[LineDrawer] pickPosition failed:",c)}if(!n){const c=(o=(s=e.camera)==null?void 0:s.getPickRay)==null?void 0:o.call(s,t);c&&(n=((l=(r=i.globe)==null?void 0:r.pick)==null?void 0:l.call(r,c,i))||null)}return n}startDrawing(t){const{Cesium:e,viewer:i}=this;this.positions=[],this.tempPoints=[],this.entity=null,this.tooltip=new _e,this.tooltip.show("单击左键添加点,双击左键结束"),this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var r,l;const s=this.getPickPosition(n.position);if(!s)return;this.positions.push(s);const o=i.entities.add({position:s,point:{pixelSize:8,color:e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(o),this.entity?this.entity.polyline.positions=this.positions.slice():this.entity=i.entities.add({polyline:{positions:this.positions.slice(),width:3,material:t.color||e.Color.YELLOW,depthFailMaterial:((l=(r=t.color)==null?void 0:r.withAlpha)==null?void 0:l.call(r,.5))||e.Color.YELLOW.withAlpha(.5)}})},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(()=>{var o,r;if(this.stopDrawing(),(o=this.tooltip)==null||o.hide(),this.tooltip=null,this.positions.length<2)return;this.positions.length=this.positions.length-1,this.entity&&(this.entity.polyline.positions=this.positions.slice());const n=this.positions.map(l=>{const c=e.Cartographic.fromCartesian(l);return{lng:e.Math.toDegrees(c.longitude),lat:e.Math.toDegrees(c.latitude),height:c.height}}),s={entity:this.entity,positions:this.positions,lnglats:n,clear:()=>{this.clear()}};(r=t.onComplete)==null||r.call(t,s)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)}stopDrawing(){var t;(t=this.handler)==null||t.destroy(),this.handler=null}clear(){var e;const{viewer:t}=this;this.entity&&(t.entities.remove(this.entity),this.entity=null),this.tempPoints.forEach(i=>t.entities.remove(i)),this.tempPoints=[],(e=this.tooltip)==null||e.hide(),this.tooltip=null,this.positions=[],this.stopDrawing()}}class jt{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"startPoint",null);h(this,"endPoint",null);h(this,"entity",null);this.Cesium=t,this.viewer=e}startDrawing(t){const{Cesium:e,viewer:i}=this;this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var o;const s=i.scene.pickPosition(n.position);if(s)if(!this.startPoint)this.startPoint=s,this.entity=i.entities.add({rectangle:{coordinates:new e.CallbackProperty(()=>{if(!(!this.startPoint||!this.endPoint))try{const r=e.Cartographic.fromCartesian(this.startPoint),l=e.Cartographic.fromCartesian(this.endPoint),c=Math.min(r.longitude,l.longitude),d=Math.max(r.longitude,l.longitude),u=Math.min(r.latitude,l.latitude),m=Math.max(r.latitude,l.latitude);return new e.Rectangle(c,u,d,m)}catch(r){console.warn("Rectangle calculation error:",r);return}},!1),material:t.color||e.Color.YELLOW.withAlpha(.5),outline:!0,outlineColor:e.Color.BLACK,disableDepthTestDistance:Number.POSITIVE_INFINITY}});else{this.stopDrawing();const r=e.Cartographic.fromCartesian(this.startPoint),l=e.Cartographic.fromCartesian(this.endPoint),c={lng:e.Math.toDegrees(Math.min(r.longitude,l.longitude)),lat:e.Math.toDegrees(Math.min(r.latitude,l.latitude)),height:0},d={lng:e.Math.toDegrees(Math.max(r.longitude,l.longitude)),lat:e.Math.toDegrees(Math.max(r.latitude,l.latitude)),height:0},u={entity:this.entity,position:this.startPoint,lnglat:{lng:e.Math.toDegrees(r.longitude),lat:e.Math.toDegrees(r.latitude),height:r.height},positions:[this.startPoint,this.endPoint],lnglats:[c,d],clear:()=>{this.clear()}};(o=t.onComplete)==null||o.call(t,u)}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(n=>{if(!this.startPoint)return;const s=i.scene.pickPosition(n.endPosition);s&&(this.endPoint=s)},e.ScreenSpaceEventType.MOUSE_MOVE)}stopDrawing(){var t;(t=this.handler)==null||t.destroy(),this.handler=null}clear(){this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.startPoint=null,this.endPoint=null,this.stopDrawing()}}class Yt{constructor(t,e){h(this,"viewer");h(this,"Cesium");h(this,"handler",null);h(this,"entity",null);h(this,"positions",[]);h(this,"_isDrawing",!1);h(this,"currentRadius",0);this.Cesium=t,this.viewer=e}startDrawing(t){this.clear(),this.handler=new this.Cesium.ScreenSpaceEventHandler(this.viewer.canvas),this._isDrawing=!0,this.handler.setInputAction(e=>{const i=this.viewer.scene.pickPosition(e.position);i&&(this.positions.push(i),this.positions.length===2&&(this.stopDrawing(),this.drawFinalCircle(t)))},this.Cesium.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(e=>{if(this.positions.length!==1)return;const i=this.positions[0],n=this.viewer.camera.getPickRay(e.endPosition),s=this.viewer.scene.globe.pick(n,this.viewer.scene);s&&this.drawPreviewCircle(i,s,t)},this.Cesium.ScreenSpaceEventType.MOUSE_MOVE)}drawPreviewCircle(t,e,i){const n=this.Cesium.Cartesian3.distance(t,e);if(this.entity)Math.abs(this.currentRadius-n)>.5&&(this.currentRadius=n);else{this.currentRadius=n;const s=new this.Cesium.CallbackProperty(()=>this.currentRadius,!1);this.entity=this.viewer.entities.add({position:t,ellipse:{semiMajorAxis:s,semiMinorAxis:s,material:i.color||this.Cesium.Color.YELLOW.withAlpha(.5),outline:!0,outlineColor:i.color||this.Cesium.Color.YELLOW,heightReference:this.Cesium.HeightReference.NONE,disableDepthTestDistance:Number.POSITIVE_INFINITY}})}}drawFinalCircle(t){var u;const[e,i]=this.positions,n=this.Cesium.Cartesian3.distance(e,i),s=this.Cesium.Cartographic.fromCartesian(e),o={lng:this.Cesium.Math.toDegrees(s.longitude),lat:this.Cesium.Math.toDegrees(s.latitude),height:s.height},r=(t==null?void 0:t.step)||1,l=[],c=[];for(let m=0;m<360;m+=r){const g=this.Cesium.Math.toRadians(m),p=new this.Cesium.EllipsoidGeodesic;p.setEndPoints(s,new this.Cesium.Cartographic(s.longitude+1e-4*Math.cos(g),s.latitude+1e-4*Math.sin(g)));const f=p.interpolateUsingSurfaceDistance(n),w=this.Cesium.Ellipsoid.WGS84.cartographicToCartesian(f);l.push(w);const y=this.Cesium.Cartographic.fromCartesian(w);c.push({lng:this.Cesium.Math.toDegrees(y.longitude),lat:this.Cesium.Math.toDegrees(y.latitude),height:y.height})}c.push(c[0]);const d=this.positions.map(m=>{const g=this.Cesium.Cartographic.fromCartesian(m);return{lng:this.Cesium.Math.toDegrees(g.longitude),lat:this.Cesium.Math.toDegrees(g.latitude),height:g.height}});(u=t.onComplete)==null||u.call(t,{entity:this.entity,positions:this.positions,lnglats:d,circlePoints:l,circleLnglats:c,center:o,radius:n,clear:()=>{this.clear()}})}stopDrawing(){this.handler&&(this.handler.destroy(),this.handler=null),this._isDrawing=!1}clear(){this.stopDrawing(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.positions=[],this.currentRadius=0}}class Vt{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"positions",[]);h(this,"entity",null);h(this,"tooltip",null);h(this,"tempPoints",[]);this.Cesium=t,this.viewer=e}getPickPosition(t){var s,o,r,l;const{viewer:e}=this,i=e==null?void 0:e.scene;if(!i||!t)return null;let n=null;try{i.pickPositionSupported&&(n=i.pickPosition(t))}catch(c){console.warn("[PolygonDrawer] pickPosition failed:",c)}if(!n){const c=(o=(s=e.camera)==null?void 0:s.getPickRay)==null?void 0:o.call(s,t);c&&(n=((l=(r=i.globe)==null?void 0:r.pick)==null?void 0:l.call(r,c,i))||null)}return n}startDrawing(t){const{Cesium:e,viewer:i}=this;this.positions=[],this.tempPoints=[],this.entity=null,this.tooltip=new _e,this.tooltip.show("单击左键添加点,双击左键结束"),this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{const s=this.getPickPosition(n.position);if(!s)return;this.positions.push(s);const o=i.entities.add({position:s,point:{pixelSize:8,color:e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(o),this.entity||(this.entity=i.entities.add({polygon:{hierarchy:new e.CallbackProperty(()=>({positions:this.positions}),!1),material:t.color||e.Color.YELLOW.withAlpha(.5)}}))},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(()=>{var o,r;if(this.stopDrawing(),(o=this.tooltip)==null||o.hide(),this.tooltip=null,this.positions.length<3)return;this.positions.length=this.positions.length-1;const n=this.positions.map(l=>{const c=e.Cartographic.fromCartesian(l);return{lng:e.Math.toDegrees(c.longitude),lat:e.Math.toDegrees(c.latitude),height:c.height}}),s={entity:this.entity,positions:this.positions,lnglats:n,clear:()=>{this.clear()}};(r=t.onComplete)==null||r.call(t,s)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)}stopDrawing(){var t;(t=this.handler)==null||t.destroy(),this.handler=null}clear(){var e;const{viewer:t}=this;this.entity&&(t.entities.remove(this.entity),this.entity=null),this.tempPoints.forEach(i=>t.entities.remove(i)),this.tempPoints=[],(e=this.tooltip)==null||e.hide(),this.tooltip=null,this.positions=[],this.stopDrawing()}}class Wt{constructor(t,e){h(this,"viewer");h(this,"Cesium");h(this,"activeDrawer",null);this.viewer=e,this.Cesium=t}draw(t,e){var i;switch(this.clear(),t){case"point":this.activeDrawer=new Gt(this.Cesium,this.viewer);break;case"line":this.activeDrawer=new Bt(this.Cesium,this.viewer);break;case"rectangle":this.activeDrawer=new jt(this.Cesium,this.viewer);break;case"circle":this.activeDrawer=new Yt(this.Cesium,this.viewer);break;case"polygon":this.activeDrawer=new Vt(this.Cesium,this.viewer);break;default:throw new Error(`Unsupported draw type: ${t}`)}(i=this.activeDrawer)==null||i.startDrawing(e)}clear(){this.activeDrawer&&(this.activeDrawer.stopDrawing(),this.activeDrawer.clear(),this.activeDrawer=null)}cancel(){this.clear()}}var st=typeof global=="object"&&global&&global.Object===Object&&global,Ut=typeof self=="object"&&self&&self.Object===Object&&self,se=st||Ut||Function("return this")(),me=se.Symbol,ot=Object.prototype,Kt=ot.hasOwnProperty,qt=ot.toString,be=me?me.toStringTag:void 0;function Xt(a){var t=Kt.call(a,be),e=a[be];try{a[be]=void 0;var i=!0}catch{}var n=qt.call(a);return i&&(t?a[be]=e:delete a[be]),n}var Jt=Object.prototype,Qt=Jt.toString;function Zt(a){return Qt.call(a)}var ei="[object Null]",ti="[object Undefined]",nt=me?me.toStringTag:void 0;function Pe(a){return a==null?a===void 0?ti:ei:nt&&nt in Object(a)?Xt(a):Zt(a)}function Le(a){return a!=null&&typeof a=="object"}var xe=Array.isArray;function De(a){var t=typeof a;return a!=null&&(t=="object"||t=="function")}var ii="[object AsyncFunction]",si="[object Function]",oi="[object GeneratorFunction]",ni="[object Proxy]";function rt(a){if(!De(a))return!1;var t=Pe(a);return t==si||t==oi||t==ii||t==ni}var Fe=se["__core-js_shared__"],at=(function(){var a=/[^.]+$/.exec(Fe&&Fe.keys&&Fe.keys.IE_PROTO||"");return a?"Symbol(src)_1."+a:""})();function ri(a){return!!at&&at in a}var ai=Function.prototype,li=ai.toString;function ce(a){if(a!=null){try{return li.call(a)}catch{}try{return a+""}catch{}}return""}var hi=/[\\^$.*+?()[\]{}|]/g,ci=/^\[object .+?Constructor\]$/,di=Function.prototype,pi=Object.prototype,ui=di.toString,mi=pi.hasOwnProperty,gi=RegExp("^"+ui.call(mi).replace(hi,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function fi(a){if(!De(a)||ri(a))return!1;var t=rt(a)?gi:ci;return t.test(ce(a))}function yi(a,t){return a==null?void 0:a[t]}function de(a,t){var e=yi(a,t);return fi(e)?e:void 0}var Re=de(se,"WeakMap"),lt=Object.create,wi=(function(){function a(){}return function(t){if(!De(t))return{};if(lt)return lt(t);a.prototype=t;var e=new a;return a.prototype=void 0,e}})(),ht=(function(){try{var a=de(Object,"defineProperty");return a({},"",{}),a}catch{}})();function vi(a,t){for(var e=-1,i=a==null?0:a.length;++e<i&&t(a[e],e,a)!==!1;);return a}var Ci=9007199254740991,bi=/^(?:0|[1-9]\d*)$/;function Pi(a,t){var e=typeof a;return t=t??Ci,!!t&&(e=="number"||e!="symbol"&&bi.test(a))&&a>-1&&a%1==0&&a<t}function Li(a,t,e){t=="__proto__"&&ht?ht(a,t,{configurable:!0,enumerable:!0,value:e,writable:!0}):a[t]=e}function ct(a,t){return a===t||a!==a&&t!==t}var Ei=Object.prototype,Mi=Ei.hasOwnProperty;function Ii(a,t,e){var i=a[t];(!(Mi.call(a,t)&&ct(i,e))||e===void 0&&!(t in a))&&Li(a,t,e)}var Ti=9007199254740991;function dt(a){return typeof a=="number"&&a>-1&&a%1==0&&a<=Ti}function _i(a){return a!=null&&dt(a.length)&&!rt(a)}var xi=Object.prototype;function pt(a){var t=a&&a.constructor,e=typeof t=="function"&&t.prototype||xi;return a===e}function Di(a,t){for(var e=-1,i=Array(a);++e<a;)i[e]=t(e);return i}var Si="[object Arguments]";function ut(a){return Le(a)&&Pe(a)==Si}var mt=Object.prototype,Ai=mt.hasOwnProperty,$i=mt.propertyIsEnumerable,Oi=ut((function(){return arguments})())?ut:function(a){return Le(a)&&Ai.call(a,"callee")&&!$i.call(a,"callee")};function ki(){return!1}var gt=typeof S=="object"&&S&&!S.nodeType&&S,ft=gt&&typeof module=="object"&&module&&!module.nodeType&&module,Fi=ft&&ft.exports===gt,yt=Fi?se.Buffer:void 0,Ri=yt?yt.isBuffer:void 0,wt=Ri||ki,Hi="[object Arguments]",zi="[object Array]",Ni="[object Boolean]",Gi="[object Date]",Bi="[object Error]",ji="[object Function]",Yi="[object Map]",Vi="[object Number]",Wi="[object Object]",Ui="[object RegExp]",Ki="[object Set]",qi="[object String]",Xi="[object WeakMap]",Ji="[object ArrayBuffer]",Qi="[object DataView]",Zi="[object Float32Array]",es="[object Float64Array]",ts="[object Int8Array]",is="[object Int16Array]",ss="[object Int32Array]",os="[object Uint8Array]",ns="[object Uint8ClampedArray]",rs="[object Uint16Array]",as="[object Uint32Array]",z={};z[Zi]=z[es]=z[ts]=z[is]=z[ss]=z[os]=z[ns]=z[rs]=z[as]=!0,z[Hi]=z[zi]=z[Ji]=z[Ni]=z[Qi]=z[Gi]=z[Bi]=z[ji]=z[Yi]=z[Vi]=z[Wi]=z[Ui]=z[Ki]=z[qi]=z[Xi]=!1;function ls(a){return Le(a)&&dt(a.length)&&!!z[Pe(a)]}function He(a){return function(t){return a(t)}}var vt=typeof S=="object"&&S&&!S.nodeType&&S,Ee=vt&&typeof module=="object"&&module&&!module.nodeType&&module,hs=Ee&&Ee.exports===vt,ze=hs&&st.process,ge=(function(){try{var a=Ee&&Ee.require&&Ee.require("util").types;return a||ze&&ze.binding&&ze.binding("util")}catch{}})(),Ct=ge&&ge.isTypedArray,cs=Ct?He(Ct):ls,ds=Object.prototype,ps=ds.hasOwnProperty;function us(a,t){var e=xe(a),i=!e&&Oi(a),n=!e&&!i&&wt(a),s=!e&&!i&&!n&&cs(a),o=e||i||n||s,r=o?Di(a.length,String):[],l=r.length;for(var c in a)ps.call(a,c)&&!(o&&(c=="length"||n&&(c=="offset"||c=="parent")||s&&(c=="buffer"||c=="byteLength"||c=="byteOffset")||Pi(c,l)))&&r.push(c);return r}function bt(a,t){return function(e){return a(t(e))}}var ms=bt(Object.keys,Object),gs=Object.prototype,fs=gs.hasOwnProperty;function ys(a){if(!pt(a))return ms(a);var t=[];for(var e in Object(a))fs.call(a,e)&&e!="constructor"&&t.push(e);return t}function ws(a){return _i(a)?us(a):ys(a)}var Me=de(Object,"create");function vs(){this.__data__=Me?Me(null):{},this.size=0}function Cs(a){var t=this.has(a)&&delete this.__data__[a];return this.size-=t?1:0,t}var bs="__lodash_hash_undefined__",Ps=Object.prototype,Ls=Ps.hasOwnProperty;function Es(a){var t=this.__data__;if(Me){var e=t[a];return e===bs?void 0:e}return Ls.call(t,a)?t[a]:void 0}var Ms=Object.prototype,Is=Ms.hasOwnProperty;function Ts(a){var t=this.__data__;return Me?t[a]!==void 0:Is.call(t,a)}var _s="__lodash_hash_undefined__";function xs(a,t){var e=this.__data__;return this.size+=this.has(a)?0:1,e[a]=Me&&t===void 0?_s:t,this}function pe(a){var t=-1,e=a==null?0:a.length;for(this.clear();++t<e;){var i=a[t];this.set(i[0],i[1])}}pe.prototype.clear=vs,pe.prototype.delete=Cs,pe.prototype.get=Es,pe.prototype.has=Ts,pe.prototype.set=xs;function Ds(){this.__data__=[],this.size=0}function Se(a,t){for(var e=a.length;e--;)if(ct(a[e][0],t))return e;return-1}var Ss=Array.prototype,As=Ss.splice;function $s(a){var t=this.__data__,e=Se(t,a);if(e<0)return!1;var i=t.length-1;return e==i?t.pop():As.call(t,e,1),--this.size,!0}function Os(a){var t=this.__data__,e=Se(t,a);return e<0?void 0:t[e][1]}function ks(a){return Se(this.__data__,a)>-1}function Fs(a,t){var e=this.__data__,i=Se(e,a);return i<0?(++this.size,e.push([a,t])):e[i][1]=t,this}function ne(a){var t=-1,e=a==null?0:a.length;for(this.clear();++t<e;){var i=a[t];this.set(i[0],i[1])}}ne.prototype.clear=Ds,ne.prototype.delete=$s,ne.prototype.get=Os,ne.prototype.has=ks,ne.prototype.set=Fs;var Ie=de(se,"Map");function Rs(){this.size=0,this.__data__={hash:new pe,map:new(Ie||ne),string:new pe}}function Hs(a){var t=typeof a;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?a!=="__proto__":a===null}function Ae(a,t){var e=a.__data__;return Hs(t)?e[typeof t=="string"?"string":"hash"]:e.map}function zs(a){var t=Ae(this,a).delete(a);return this.size-=t?1:0,t}function Ns(a){return Ae(this,a).get(a)}function Gs(a){return Ae(this,a).has(a)}function Bs(a,t){var e=Ae(this,a),i=e.size;return e.set(a,t),this.size+=e.size==i?0:1,this}function fe(a){var t=-1,e=a==null?0:a.length;for(this.clear();++t<e;){var i=a[t];this.set(i[0],i[1])}}fe.prototype.clear=Rs,fe.prototype.delete=zs,fe.prototype.get=Ns,fe.prototype.has=Gs,fe.prototype.set=Bs;function js(a,t){for(var e=-1,i=t.length,n=a.length;++e<i;)a[n+e]=t[e];return a}var Ys=bt(Object.getPrototypeOf,Object);function Vs(){this.__data__=new ne,this.size=0}function Ws(a){var t=this.__data__,e=t.delete(a);return this.size=t.size,e}function Us(a){return this.__data__.get(a)}function Ks(a){return this.__data__.has(a)}var qs=200;function Xs(a,t){var e=this.__data__;if(e instanceof ne){var i=e.__data__;if(!Ie||i.length<qs-1)return i.push([a,t]),this.size=++e.size,this;e=this.__data__=new fe(i)}return e.set(a,t),this.size=e.size,this}function ye(a){var t=this.__data__=new ne(a);this.size=t.size}ye.prototype.clear=Vs,ye.prototype.delete=Ws,ye.prototype.get=Us,ye.prototype.has=Ks,ye.prototype.set=Xs;var Pt=typeof S=="object"&&S&&!S.nodeType&&S,Lt=Pt&&typeof module=="object"&&module&&!module.nodeType&&module,Js=Lt&&Lt.exports===Pt,Et=Js?se.Buffer:void 0;Et&&Et.allocUnsafe;function Qs(a,t){return a.slice()}function Zs(a,t){for(var e=-1,i=a==null?0:a.length,n=0,s=[];++e<i;){var o=a[e];t(o,e,a)&&(s[n++]=o)}return s}function eo(){return[]}var to=Object.prototype,io=to.propertyIsEnumerable,Mt=Object.getOwnPropertySymbols,so=Mt?function(a){return a==null?[]:(a=Object(a),Zs(Mt(a),function(t){return io.call(a,t)}))}:eo;function oo(a,t,e){var i=t(a);return xe(a)?i:js(i,e(a))}function no(a){return oo(a,ws,so)}var Ne=de(se,"DataView"),Ge=de(se,"Promise"),Be=de(se,"Set"),It="[object Map]",ro="[object Object]",Tt="[object Promise]",_t="[object Set]",xt="[object WeakMap]",Dt="[object DataView]",ao=ce(Ne),lo=ce(Ie),ho=ce(Ge),co=ce(Be),po=ce(Re),re=Pe;(Ne&&re(new Ne(new ArrayBuffer(1)))!=Dt||Ie&&re(new Ie)!=It||Ge&&re(Ge.resolve())!=Tt||Be&&re(new Be)!=_t||Re&&re(new Re)!=xt)&&(re=function(a){var t=Pe(a),e=t==ro?a.constructor:void 0,i=e?ce(e):"";if(i)switch(i){case ao:return Dt;case lo:return It;case ho:return Tt;case co:return _t;case po:return xt}return t});var uo=Object.prototype,mo=uo.hasOwnProperty;function go(a){var t=a.length,e=new a.constructor(t);return t&&typeof a[0]=="string"&&mo.call(a,"index")&&(e.index=a.index,e.input=a.input),e}var St=se.Uint8Array;function je(a){var t=new a.constructor(a.byteLength);return new St(t).set(new St(a)),t}function fo(a,t){var e=je(a.buffer);return new a.constructor(e,a.byteOffset,a.byteLength)}var yo=/\w*$/;function wo(a){var t=new a.constructor(a.source,yo.exec(a));return t.lastIndex=a.lastIndex,t}var At=me?me.prototype:void 0,$t=At?At.valueOf:void 0;function vo(a){return $t?Object($t.call(a)):{}}function Co(a,t){var e=je(a.buffer);return new a.constructor(e,a.byteOffset,a.length)}var bo="[object Boolean]",Po="[object Date]",Lo="[object Map]",Eo="[object Number]",Mo="[object RegExp]",Io="[object Set]",To="[object String]",_o="[object Symbol]",xo="[object ArrayBuffer]",Do="[object DataView]",So="[object Float32Array]",Ao="[object Float64Array]",$o="[object Int8Array]",Oo="[object Int16Array]",ko="[object Int32Array]",Fo="[object Uint8Array]",Ro="[object Uint8ClampedArray]",Ho="[object Uint16Array]",zo="[object Uint32Array]";function No(a,t,e){var i=a.constructor;switch(t){case xo:return je(a);case bo:case Po:return new i(+a);case Do:return fo(a);case So:case Ao:case $o:case Oo:case ko:case Fo:case Ro:case Ho:case zo:return Co(a);case Lo:return new i;case Eo:case To:return new i(a);case Mo:return wo(a);case Io:return new i;case _o:return vo(a)}}function Go(a){return typeof a.constructor=="function"&&!pt(a)?wi(Ys(a)):{}}var Bo="[object Map]";function jo(a){return Le(a)&&re(a)==Bo}var Ot=ge&&ge.isMap,Yo=Ot?He(Ot):jo,Vo="[object Set]";function Wo(a){return Le(a)&&re(a)==Vo}var kt=ge&&ge.isSet,Uo=kt?He(kt):Wo,Ft="[object Arguments]",Ko="[object Array]",qo="[object Boolean]",Xo="[object Date]",Jo="[object Error]",Rt="[object Function]",Qo="[object GeneratorFunction]",Zo="[object Map]",en="[object Number]",Ht="[object Object]",tn="[object RegExp]",sn="[object Set]",on="[object String]",nn="[object Symbol]",rn="[object WeakMap]",an="[object ArrayBuffer]",ln="[object DataView]",hn="[object Float32Array]",cn="[object Float64Array]",dn="[object Int8Array]",pn="[object Int16Array]",un="[object Int32Array]",mn="[object Uint8Array]",gn="[object Uint8ClampedArray]",fn="[object Uint16Array]",yn="[object Uint32Array]",H={};H[Ft]=H[Ko]=H[an]=H[ln]=H[qo]=H[Xo]=H[hn]=H[cn]=H[dn]=H[pn]=H[un]=H[Zo]=H[en]=H[Ht]=H[tn]=H[sn]=H[on]=H[nn]=H[mn]=H[gn]=H[fn]=H[yn]=!0,H[Jo]=H[Rt]=H[rn]=!1;function $e(a,t,e,i,n,s){var o;if(o!==void 0)return o;if(!De(a))return a;var r=xe(a);if(r)o=go(a);else{var l=re(a),c=l==Rt||l==Qo;if(wt(a))return Qs(a);if(l==Ht||l==Ft||c&&!n)o=c?{}:Go(a);else{if(!H[l])return n?a:{};o=No(a,l)}}s||(s=new ye);var d=s.get(a);if(d)return d;s.set(a,o),Uo(a)?a.forEach(function(g){o.add($e(g,t,e,g,a,s))}):Yo(a)&&a.forEach(function(g,p){o.set(p,$e(g,t,e,p,a,s))});var u=no,m=r?void 0:u(a);return vi(m||a,function(g,p){m&&(p=g,g=a[p]),Ii(o,p,$e(g,t,e,p,a,s))}),o}var wn=1,vn=4;function Oe(a){return $e(a,wn|vn)}var zt=(a=>(a.Rotate="rotate",a.Move="move",a.Scale="scale",a.MoveHeight="moveHeight",a.Empty="",a))(zt||{}),Nt=(a=>(a.Scale="addScale",a.Rotate="rotate",a.Translation="translation",a.Remove="removeById",a.Add="add",a))(Nt||{});class Cn{constructor(t){h(this,"primitives",new Map);h(this,"eventListener",new Map);h(this,"Cesium");h(this,"viewer");h(this,"handler");h(this,"rotationRing");h(this,"translationSquare");h(this,"heightArrow");h(this,"editMode","");h(this,"dragEndCallbackMap",new Map);this.Cesium=t.Cesium,this.viewer=t.viewer,this.handler=new this.Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas)}init(t,e=!1){const i=this.viewer;this.primitives.forEach(n=>{i.scene.primitives.remove(n)}),t.forEach(n=>{this.primitives.has(n.id)||this.add(n,e)})}get(t){return this.primitives.get(t)}add(t,e=!0){var u,m,g;const i=this.viewer,n=this.Cesium,s=n.Math.toRadians(((u=t.headingPitchRoll)==null?void 0:u.heading)||0),o=n.Math.toRadians(((m=t.headingPitchRoll)==null?void 0:m.pitch)||0),r=n.Math.toRadians(((g=t.headingPitchRoll)==null?void 0:g.roll)||0),l=new n.HeadingPitchRoll(s,o,r),c=n.Transforms.headingPitchRollToFixedFrame(t.position,l,i.scene.globe.ellipsoid,n.Transforms.eastNorthUpToFixedFrame,new n.Matrix4);let d=i.scene.primitives.add(n.Model.fromGltf({id:t.id,...t.model,modelMatrix:c}));d.scale=t.scale||1,this.primitives.set(t.id,d),d.show=e,this.runEventListener("add",{info:t,gltf:d})}flyTo(t){const e=this.viewer,i=this.Cesium;let n=this.primitives.get(t);const s=n.boundingSphere,o=i.Matrix4.multiplyByPoint(n.modelMatrix,s.center,new i.Cartesian3),r=new i.BoundingSphere(o,s.radius);e.camera.flyToBoundingSphere(r,{duration:1.5,offset:new i.HeadingPitchRange(0,-.5,s.radius*2)})}removeById(t){var n;const e=this.viewer;let i=this.primitives.get(t);if(!i){console.error(`No model found with id: ${t}`);return}e.scene.primitives.remove(i),this.primitives.delete(t),(!((n=this.rotationRing)!=null&&n._instanceIds.includes(`rotationRing_${t}`))||!this.rotationRing)&&this.removeTool(),this.runEventListener("removeById",{id:t,gltf:i})}show(t){let e=this.primitives.get(t);e&&(e.show=!0)}hide(t){let e=this.primitives.get(t);e&&(e.show=!1)}addScale(t,e=.1){let i=this.primitives.get(t.id);i&&(i.scale=i.scale+e,this.updatedTool(i.modelMatrix),this.runEventListener("addScale",{id:t.id,scale:i.scale}))}setScale(t,e=.1){let i=this.primitives.get(t);i&&(i.scale=e,this.updatedTool(i.modelMatrix),this.runEventListener("addScale",{id:t,scale:i.scale}))}setEditMode(t){this.editMode=t}lockCamera(){const t=this.viewer.scene.screenSpaceCameraController;t.enableRotate=!1,t.enableTranslate=!1,t.enableZoom=!1}unlockCamera(){const t=this.viewer.scene.screenSpaceCameraController;t.enableRotate=!0,t.enableTranslate=!0,t.enableZoom=!0}toCartographic(t){const e=this.Cesium.Cartographic.fromCartesian(t);return{longitude:e.longitude,latitude:e.latitude}}calculateHeading(t,e){const i=e.longitude-t.longitude,n=e.latitude-t.latitude;return Math.atan2(n,i)}getModelHeadingPitchRoll(t){const e=this.Cesium,i=this.viewer,n=e.Transforms.eastNorthUpToFixedFrame(e.Matrix4.getTranslation(t,new e.Cartesian3),i.scene.globe.ellipsoid,new e.Matrix4),s=e.Matrix4.multiply(e.Matrix4.inverse(n,new e.Matrix4),t,new e.Matrix4),o=e.Matrix4.getRotation(s,new e.Matrix3),r=e.Quaternion.fromRotationMatrix(o);return e.HeadingPitchRoll.fromQuaternion(r)}addEventListener(t,e,i){let n={f:e,options:i};return this.eventListener.get(t)?(this.eventListener.get(t)||[]).push(n):this.eventListener.set(t,[n]),n}removeEventListener(t,e){let i=this.eventListener.get(t);if(!i)return console.error("key不存在");let n=i.findIndex(s=>s==e);n>=0?i.splice(n,1):console.error("instantiation不存在")}runEventListener(t,e){let i=this.eventListener.get(t);return i?(i.forEach(n=>{typeof n.f=="function"&&n.f(e)}),!0):!1}initEditBox(t){const e=this.Cesium,i=this.viewer,n=i.scene;let s=null,o=null,r=null,l=null,c=null;const d=()=>{s=null,o=null,r=null,c=null,l=null,this.setEditMode(""),this.unlockCamera()},u=(m,g)=>{if(s=this.primitives.get(m),s){o=e.Matrix4.clone(s.modelMatrix);const p=e.Matrix4.getTranslation(o,new e.Cartesian3);r=this.toCartographic(p),c=g.position;const f=n.globe.pick(i.camera.getPickRay(g.position),n);l=this.toCartographic(f),this.lockCamera()}};this.handler.setInputAction(m=>{var f,w,y,v,C,b,M,P,L,E;if(!t())return;const p=n.pick(m.position);if(p&&p.id&&((f=p.id)!=null&&f.includes("rotationRing"))){let I=p.id.split("rotationRing_")[1];this.setEditMode("rotate"),u(I,m)}else if(p&&p.id&&((w=p.id)!=null&&w.includes("translationSquare_"))){let I=p.id.split("translationSquare_")[1];this.setEditMode("move"),u(I,m)}else if(p&&p.id&&((y=p.id)!=null&&y.includes("heightArrow-line_"))){let I=p.id.split("heightArrow-line_")[1];this.setEditMode("moveHeight"),u(I,m)}else if(p&&p.id&&((v=p.id)!=null&&v.includes("heightArrow-arrow_"))){let I=p.id.split("heightArrow-arrow_")[1];this.setEditMode("moveHeight"),u(I,m)}else if(p&&p.id){if(s=this.primitives.get(p.id),!s)return;(!this.rotationRing||!((b=(C=this.rotationRing)==null?void 0:C._instanceIds)!=null&&b.includes(`rotationRing_${s.id}`)))&&this.createRotationRing(s),(!this.translationSquare||!((P=(M=this.translationSquare)==null?void 0:M._instanceIds)!=null&&P.includes(`translationSquare_${s.id}`)))&&this.createTranslationSquare(s),(!this.heightArrow||!((E=(L=this.heightArrow)==null?void 0:L._instanceIds)!=null&&E.includes(`heightArrow_${s.id}`)))&&this.createHeightArrow(s)}else d()},e.ScreenSpaceEventType.LEFT_DOWN),this.handler.setInputAction(m=>{if(t()&&this.editMode!=""&&s){const p=n.globe.pick(i.camera.getPickRay(m.endPosition),n),f=this.toCartographic(p);let w=0;if(this.editMode==="rotate"){let y=this.calculateHeading(r,f);w=this.calculateHeading(r,l)-y,this.rotateModel(s,o,w)}else this.editMode==="move"?this.moveModel(s,o,m):this.editMode==="moveHeight"&&this.moveModelHeight(s,o,m,c)}},e.ScreenSpaceEventType.MOUSE_MOVE),this.handler.setInputAction(()=>{if(!t())return;let g=this.dragEndCallbackMap.get(s==null?void 0:s.id);if(g&&(this.editMode==="move"||this.editMode==="moveHeight")){let p=g.get("translation");p&&(this.runEventListener("translation",p),g.delete("translation"))}else if(g&&this.editMode==="rotate"){let p=g.get("rotate");p&&(this.runEventListener("rotate",p),g.delete("rotate"))}d()},e.ScreenSpaceEventType.LEFT_UP),this.handler.setInputAction(()=>{this.removeTool()},e.ScreenSpaceEventType.RIGHT_UP)}createRotationRing(t){const e=this.Cesium,i=this.viewer;this.rotationRing&&i.scene.primitives.remove(this.rotationRing);const n=[];for(let r=0;r<=360;r+=3){const l=Math.sin(e.Math.toRadians(r)),c=Math.cos(e.Math.toRadians(r)),d=t.boundingSphere.radius*c,u=t.boundingSphere.radius*l;n.push(new e.Cartesian3(d,u,0))}const s=new e.PolylineGeometry({positions:n,width:Math.max(t.boundingSphere.radius*.05,1)}),o=new e.GeometryInstance({id:`rotationRing_${t.id}`,geometry:s,attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(e.Color.RED)}});this.rotationRing=new e.Primitive({geometryInstances:o,appearance:new e.PolylineColorAppearance({translucent:!0}),depthFailAppearance:new e.PolylineMaterialAppearance({material:e.Material.fromType("Color",{color:e.Color.RED.withAlpha(.3)}),translucent:!0}),modelMatrix:t.modelMatrix,cull:!1}),i.scene.primitives.add(this.rotationRing)}createTranslationSquare(t){const e=this.Cesium,i=this.viewer;this.translationSquare&&i.scene.primitives.remove(this.translationSquare);const s=Math.max(t.boundingSphere.radius*.2,1)/2,o=new e.BoxGeometry({maximum:new e.Cartesian3(s,s,s),minimum:new e.Cartesian3(-s,-s,-s)}),r=new e.GeometryInstance({id:`translationSquare_${t.id}`,geometry:o,attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(e.Color.BLUE)}});this.translationSquare=new e.Primitive({geometryInstances:r,appearance:new e.PolylineColorAppearance({translucent:!0}),depthFailAppearance:new e.PolylineMaterialAppearance({material:e.Material.fromType("Color",{color:e.Color.BLUE.withAlpha(.3)}),translucent:!0}),cull:!1,modelMatrix:t.modelMatrix}),i.scene.primitives.add(this.translationSquare)}createHeightArrow(t){const e=this.Cesium,i=this.viewer;this.heightArrow&&i.scene.primitives.remove(this.heightArrow);let n=e.Color.GREEN,s=Math.max(t.boundingSphere.radius*.025,1),o=2*s,r=t.boundingSphere.radius+50,l=r*.1;const c=Math.max(t.boundingSphere.radius*.2,1),d=e.CylinderGeometry.createGeometry(new e.CylinderGeometry({length:r,topRadius:s,bottomRadius:s})),u=e.CylinderGeometry.createGeometry(new e.CylinderGeometry({length:l,topRadius:0,bottomRadius:o}));let m=r+c,g=(r+c)/2;this.translate(d,[0,0,g]),this.translate(u,[0,0,m]),this.heightArrow=new e.Primitive({modelMatrix:t.modelMatrix,geometryInstances:[new e.GeometryInstance({id:`heightArrow-line_${t.id}`,geometry:d}),new e.GeometryInstance({id:`heightArrow-arrow_${t.id}`,geometry:u})],appearance:new e.PolylineMaterialAppearance({material:e.Material.fromType("Color",{color:n}),translucent:!0}),depthFailAppearance:new e.PolylineMaterialAppearance({material:e.Material.fromType("Color",{color:n.withAlpha(.3)}),translucent:!0}),cull:!1}),i.scene.primitives.add(this.heightArrow)}translate(t,e){let i=this.Cesium;const n=new i.Cartesian3;xe(e)?(n.x=e[0],n.y=e[1],n.z=e[2]):i.Cartesian3.clone(e,n);for(let s=0;s<t.attributes.position.values.length;s+=3)t.attributes.position.values[s]+=n.x,t.attributes.position.values[s+1]+=n.y,t.attributes.position.values[s+2]+=n.z}removeTool(){this.rotationRing&&this.viewer.scene.primitives.remove(this.rotationRing),this.translationSquare&&this.viewer.scene.primitives.remove(this.translationSquare),this.heightArrow&&this.viewer.scene.primitives.remove(this.heightArrow)}updatedTool(t){this.rotationRing&&(this.rotationRing.modelMatrix=t),this.translationSquare&&(this.translationSquare.modelMatrix=t),this.heightArrow&&(this.heightArrow.modelMatrix=t)}moveModel(t,e,i){const n=this.Cesium,s=this.viewer,o=s.scene,r=o.globe.pick(s.camera.getPickRay(i.endPosition),o);if(r){const l=n.Matrix4.getTranslation(e,new n.Cartesian3),c=n.Cartographic.fromCartesian(l),d=n.Cartographic.fromCartesian(r),u=new n.Cartographic(d.longitude,d.latitude,c.height),m=n.Cartographic.toCartesian(u),g=n.Matrix4.getRotation(e,new n.Matrix3),p=n.Matrix4.fromRotationTranslation(g,m);t.modelMatrix=p,this.updatedTool(p);let f=new n.Cartesian3(p[12],p[13],p[14]),w=this.dragEndCallbackMap.get(t.id);w||(w=new Map,this.dragEndCallbackMap.set(t.id,w)),w.set("translation",{id:t.id,position:f})}}moveModelHeight(t,e,i,n){const s=this.Cesium,o=this.viewer,r=o.scene,l=n.y-i.endPosition.y;if(r.globe.pick(o.camera.getPickRay(i.endPosition),r)){const d=s.Matrix4.getTranslation(e,new s.Cartesian3),u=s.Cartographic.fromCartesian(d),m=new s.Cartographic(u.longitude,u.latitude,u.height+l*.001*Math.max(o.camera.positionCartographic.height,1)),g=s.Cartographic.toCartesian(m),p=s.Matrix4.getRotation(e,new s.Matrix3),f=s.Matrix4.fromRotationTranslation(p,g);t.modelMatrix=f,this.updatedTool(f);let w=new s.Cartesian3(f[12],f[13],f[14]),y=this.dragEndCallbackMap.get(t.id);y||(y=new Map,this.dragEndCallbackMap.set(t.id,y)),y.set("translation",{id:t.id,position:w})}}rotateModel(t,e,i){const n=this.Cesium,s=this.viewer,o=this.getModelHeadingPitchRoll(e),r=o.heading+i,l=new n.HeadingPitchRoll(r,o.pitch,o.roll),c=n.Transforms.headingPitchRollToFixedFrame(n.Matrix4.getTranslation(t.modelMatrix,new n.Cartesian3),l,s.scene.globe.ellipsoid,n.Transforms.eastNorthUpToFixedFrame,new n.Matrix4);t.modelMatrix=c;let d=this.dragEndCallbackMap.get(t.id);d||(d=new Map,this.dragEndCallbackMap.set(t.id,d)),d.set("rotate",{id:t.id,headingPitchRoll:{heading:n.Math.toDegrees(r),pitch:n.Math.toDegrees(o.pitch),roll:n.Math.toDegrees(o.roll)}})}cleanup(){this.handler&&(this.handler.destroy(),this.handler=null)}}function bn(a,t){const e=t.materialType||"DynamicImgMaterial"+Date.now()+Math.floor(Math.random()*1e3);function i(s){this._definitionChanged=new a.Event,this._color=s.color,this._colorSubscription=void 0,this.color=s.color,this.duration=s.duration,this._time=Date.now()}Object.defineProperties(i.prototype,{isConstant:{get(){return!1}},definitionChanged:{get(){return this._definitionChanged}},color:a.createPropertyDescriptor("color")}),i.prototype.getType=function(){return e},i.prototype.getValue=function(s,o){return a.defined(o)||(o={}),o.color=a.Property.getValueOrClonedDefault(this._color,s,a.Color.WHITE,o.color),o.image=t.image,o},i.prototype.equals=function(s){return this===s||s instanceof i&&a.Property.equals(this._color,s._color)};const n=function(s){return`
|
|
2
2
|
czm_material czm_getMaterial(czm_materialInput materialInput)
|
|
3
3
|
{
|
|
4
4
|
czm_material material = czm_getDefaultMaterial(materialInput);
|
|
@@ -8,23 +8,23 @@
|
|
|
8
8
|
${s.isCustomColor?"material.diffuse = color.rgb;":"material.diffuse = colorImage.rgb;"}
|
|
9
9
|
material.alpha = colorImage.a;
|
|
10
10
|
return material;
|
|
11
|
-
}`};return a.Material._materialCache.addMaterial(e,{fabric:{type:e,uniforms:{color:t.color,image:t.image,time:1e3},source:
|
|
11
|
+
}`};return a.Material._materialCache.addMaterial(e,{fabric:{type:e,uniforms:{color:t.color,image:t.image,time:1e3},source:n({count:t.count,freely:t.freely||"",direction:t.direction,duration:t.duration||100,isCustomColor:t.isCustomColor})},translucent(){return!0}}),new i(t)}function Pn(a,t){const e=t.MaterialType||"wallType"+new Date().getTime()+parseInt(Math.random()*1e3+"");function i(s){this._definitionChanged=new a.Event,this._color=void 0,this._colorSubscription=void 0,this.color=s.color,this.duration=s.duration,this._time=new Date().getTime()}Object.defineProperties(i.prototype,{isConstant:{get:function(){return!1}},definitionChanged:{get:function(){return this._definitionChanged}},color:a.createPropertyDescriptor("color")}),i.prototype.getType=function(){return e},i.prototype.getValue=function(s,o){return a.defined(o)||(o={}),o.image=t.image,this.duration&&(o.time=(new Date().getTime()-this._time)%this.duration/this.duration),o},i.prototype.equals=function(s){return this===s||s instanceof i&&a.Property.equals(this._color,s._color)};const n=function(s){let o=`czm_material czm_getMaterial(czm_materialInput materialInput)
|
|
12
12
|
{
|
|
13
13
|
czm_material material = czm_getDefaultMaterial(materialInput);
|
|
14
14
|
vec2 st = materialInput.st;
|
|
15
15
|
|
|
16
|
-
`;return s.freely=="vertical"?
|
|
17
|
-
`:
|
|
18
|
-
`,
|
|
16
|
+
`;return s.freely=="vertical"?o+="vec4 colorImage = texture(image, vec2(fract(float("+s.count+")*st.t "+s.direction+` time), fract(st.s)));
|
|
17
|
+
`:o+="vec4 colorImage = texture(image, vec2(fract(float("+s.count+")*st.s "+s.direction+` time), fract(st.t)));
|
|
18
|
+
`,o+=`vec4 fragColor;
|
|
19
19
|
fragColor.rgb = (color.rgb) / 1.0;
|
|
20
20
|
fragColor = czm_gammaCorrect(fragColor);
|
|
21
|
-
`,
|
|
21
|
+
`,o+=` material.diffuse = color.rgb;
|
|
22
22
|
material.alpha = colorImage.a * color.a;
|
|
23
23
|
material.emission = fragColor.rgb;
|
|
24
24
|
|
|
25
25
|
return material;
|
|
26
26
|
}
|
|
27
|
-
`,
|
|
27
|
+
`,o};return a.Material._materialCache.addMaterial(e,{fabric:{type:e,uniforms:{color:t.color||new a.Color(1,1,1,1),image:t.image,time:0},source:n({count:t.count,freely:t.freely,direction:t.direction})},translucent:function(){return!0}}),new i(t)}function Ln(a,t){const e=a.Color,i=Object.defineProperties,n=a.Event,s=a.createPropertyDescriptor,o=a.Property,r=(u,m)=>u===void 0?m:u,l={};let c=t.materialType||"PolylineFlow"+Date.now()+Math.floor(Math.random()*1e3);function d(u){u=r(u,l),this._definitionChanged=new n,this._color=void 0,this._colorSubscription=void 0,this.color=u.color||e.fromBytes(0,255,255,255),this._duration=void 0,this._durationSubscription=void 0,this.duration=r(u.duration,45)}return i(d.prototype,{isConstant:{get(){return!1}},definitionChanged:{get(){return this._definitionChanged}}}),d.prototype.getType=function(u){return c},d.prototype.getValue=function(u,m){return m||(m={}),m.color=o.getValueOrClonedDefault(this._color,u,a.Color.WHITE,m.color),m.duration=this._duration,m},d.prototype.equals=function(u){return this===u||u instanceof d&&o.equals(this._color,u._color)},i(d.prototype,{color:s("color"),duration:s("duration")}),a.PolylineFlowMaterialProperty=d,a.Material._materialCache.addMaterial(c,{fabric:{type:c,uniforms:{color:new e(1,1,1,1),duration:45},source:(function(){return`uniform vec4 color;
|
|
28
28
|
uniform float duration;
|
|
29
29
|
czm_material czm_getMaterial(czm_materialInput materialInput){
|
|
30
30
|
czm_material material = czm_getDefaultMaterial(materialInput);
|
|
@@ -40,38 +40,38 @@
|
|
|
40
40
|
material.alpha = alpha;
|
|
41
41
|
material.emission = fragColor.rgb;
|
|
42
42
|
return material;
|
|
43
|
-
}`})()},translucent(){return!0}}),new d(t)}class Lo{constructor(){h(this,"categoryMap",new Map);h(this,"CategoryGet",{})}registerCategoryGet(t,e){if(!t)return console.warn("分类不能为空");this.CategoryGet[t]=e}register(t){const{themeKey:e,material:i,force:o=!1,category:s="default"}=t;this.categoryMap.has(s)||this.categoryMap.set(s,new Map);const r=this.categoryMap.get(s);if(r.has(e))if(o)console.info(`[MaterialManager] themeKey '${e}' 在分类 '${s}' 已被覆盖`);else{console.warn(`[MaterialManager] 已存在 themeKey '${e}' 在分类 '${s}',如需覆盖请设置 force = true`);return}r.set(e,i)}get({themeKey:t,category:e,options:i}){var o;return e=e||"default",this.CategoryGet[e]?this.CategoryGet[e]({themeKey:t,materialMap:this.categoryMap,options:i||{}}):(o=this.categoryMap.get(e))==null?void 0:o.get(t)}has(t,e="default"){var i;return((i=this.categoryMap.get(e))==null?void 0:i.has(t))??!1}remove(t,e="default"){const i=this.categoryMap.get(e);if(!i)return;const o=i.get(t);o!=null&&o.destroy&&o.destroy(),i.delete(t),i.size===0&&this.categoryMap.delete(e)}keys(t="default"){var e;return[...((e=this.categoryMap.get(t))==null?void 0:e.keys())||[]]}clearCategory(t="default"){var i;const e=this.categoryMap.get(t);if(e){for(const o of e.values())(i=o==null?void 0:o.destroy)==null||i.call(o);e.clear(),this.categoryMap.delete(t)}}clearAll(){var t;for(const e of this.categoryMap.values())for(const i of e.values())(t=i==null?void 0:i.destroy)==null||t.call(i);this.categoryMap.clear()}categories(){return[...this.categoryMap.keys()]}}class Eo{constructor(t){h(this,"id");h(this,"entities",[]);h(this,"primitives",[]);h(this,"dataItem",{});h(this,"aggregator");h(this,"cardPool");const{id:e,entities:i=[],primitives:o=[],dataItem:s={},aggregator:r,cardPool:n}=t;this.id=e,this.entities=i,this.primitives=o,this.dataItem=s,this.aggregator=r,this.cardPool=n}setVisible(t){this.entities.forEach(e=>{e&&(e.show=t)}),this.primitives.forEach(e=>{e&&(e.show=t)}),this.aggregator&&Array.isArray(this.dataItem.billboard)&&this.dataItem.billboard.map((i,o)=>{var r;return{id:this.dataItem.id,data:{...this.dataItem,show:t&&(((r=i.data)==null?void 0:r.show)??!0)}}}).forEach(i=>{var o;(o=this.aggregator)==null||o.updatePoint(i)}),this.cardPool&&this.dataItem.card&&(t?this.cardPool.showByIds([this.dataItem.id]):this.cardPool.hideByIds([this.dataItem.id]))}removeAll(t,e=!0){return this.entities.forEach(i=>{i&&t.entities.remove(i)}),this.entities=[],this.primitives.forEach(i=>{i&&t.scene.primitives.remove(i)}),this.primitives=[],e&&this.aggregator&&Array.isArray(this.dataItem.billboard)&&this.aggregator.removePointsById([this.dataItem.id]),e&&this.cardPool&&this.dataItem.card&&this.cardPool.removeByIds([this.dataItem.id]),this.dataItem.id}}class Mo{constructor(t,e,i,o,s,r){h(this,"id");h(this,"groupMap",new Map);h(this,"Cesium");h(this,"viewer");h(this,"materialManager");h(this,"aggregator");h(this,"cardPool");this.id=t,this.Cesium=e,this.viewer=i,this.materialManager=o,this.aggregator=s,this.cardPool=r,this.aggregator.labelPool.eventBus.addListener(V.Click,{name:"BufferedHierarchicalAggregator_maker_click",fn:(l,c)=>{this.cardPool.showByIds([l.data.id])}}),new e.ScreenSpaceEventHandler(i.scene.canvas).setInputAction(()=>{this.cardPool.hideFilter(l=>!l.initShow)},e.ScreenSpaceEventType.LEFT_CLICK)}createPolyline(t,e){if(!t.positions||t.positions.length<1)return null;const i=this.materialManager.get({themeKey:t.theme,category:"polyline",options:t}),o=Array.isArray(t.positions[0])?t.positions.flat():t.positions;let s={...t};return i&&(s.material=i),this.viewer.entities.add({polyline:{...s,positions:this.Cesium.Cartesian3.fromDegreesArrayHeights(o)},show:(t.show??!0)&&e})}createWall(t,e){var l,c;if(!t.positions||t.positions.length<1)return null;const i=this.materialManager.get({themeKey:t.theme,category:"wall",options:t}),o=t.positions.length===((l=t.minimumHeights)==null?void 0:l.length)?t.minimumHeights.map(d=>d-Number(t.minHeight||0)):t.positions.map(d=>(d[2]||0)-Number(t.minHeight||0)),s=t.positions.length===((c=t.maximumHeights)==null?void 0:c.length)?t.maximumHeights.map(d=>d+Number(t.maxHeight||0)):t.positions.map(d=>(d[2]||0)+Number(t.maxHeight||0)),r=t.positions.map(d=>this.Cesium.Cartesian3.fromDegrees(d[0],d[1],d[2]||0));let n={...t};return i&&(n.material=i),this.viewer.entities.add({wall:{...n,positions:r,minimumHeights:o,maximumHeights:s},show:(t.show??!0)&&e})}createPolygon(t,e){var c;if(!t.hierarchy||t.hierarchy.length<1)return null;const i=this.materialManager.get({themeKey:t.theme,category:"polygon",options:t}),o=Array.isArray(t.hierarchy[0])?t.hierarchy.flat():t.hierarchy,s=this.Cesium.Cartesian3.fromDegreesArrayHeights(o),r=((c=t.holes)==null?void 0:c.map(d=>{let u=Array.isArray(d[0])?t.hierarchy.flat():t.hole;return this.Cesium.Cartesian3.fromDegreesArrayHeights(u.flat())}))||[],n=new this.Cesium.PolygonHierarchy(s,r);let l={...t};return i&&(l.material=i),this.viewer.entities.add({polygon:{...l,hierarchy:n},show:(t.show??!0)&&e})}createBillboardPoints(t){var e;return!((e=t.billboard)!=null&&e.length)||!this.aggregator?[]:t.billboard.map(i=>{var n;const[o,s,r=0]=i.position||[0,0,0];return{id:t.id,lon:o,lat:s,height:r,name:((n=i.options)==null?void 0:n.text)||"",data:t,style:{zIndex:t.zIndex||"1"}}})}createCard(t){var e,i,o;(i=(e=t.card)==null?void 0:e.data)!=null&&i.length&&this.cardPool.add(t.card,{id:t.id,lon:t.card.position[0],lat:t.card.position[1],height:t.card.position[3]||0,theme:t.card.theme,show:t.show?t.card.initShow??!1:!1,notCreateElement:!0,style:{width:"0",height:"0",zIndex:((o=t==null?void 0:t.card)==null?void 0:o.zIndex)||"110"}})}addGroup(t,e=!0){const i=t.id||`${Date.now()}`;this.removeGroup(i);const o=[],s=t.show!==!1;(t.polyline||[]).forEach(l=>{const c=this.createPolyline(l,s);c&&o.push(c)}),(t.wall||[]).forEach(l=>{const c=this.createWall(l,s);c&&o.push(c)}),(t.polygon||[]).forEach(l=>{const c=this.createPolygon(l,s);c&&o.push(c)});const r=this.createBillboardPoints(t);r.length&&e&&this.aggregator.appendPoints(r,!1),this.createCard(t);const n=new Eo({id:i,entities:o,primitives:[],dataItem:t,aggregator:this.aggregator,cardPool:this.cardPool});return this.groupMap.set(i,n),r}async addGroups(t){const i=t.map(o=>this.addGroup(o,!1)).flat();i.length>0&&this.aggregator&&this.aggregator.appendPoints(i,!1)}removeGroup(t){const e=this.groupMap.get(t);e&&(e.removeAll(this.viewer),this.groupMap.delete(t))}removeGroups(t){let e=[];for(const i of t){const o=this.groupMap.get(i);if(o){let s=o.removeAll(this.viewer,!1);this.groupMap.delete(i),e.push(s)}}this.aggregator.removePointsById(e),this.cardPool.removeByIds(e)}updateGroup(t){const e=this.groupMap.get(t.id);e&&(e.removeAll(this.viewer),this.groupMap.delete(t.id)),this.addGroup(t)}async updateGroups(t){this.aggregator.removePointsById(t.map(o=>o.id)),this.cardPool.removeByIds(t.map(o=>o.id));const i=t.map(o=>{const s=this.groupMap.get(o.id);return s&&(s.removeAll(this.viewer,!1),this.groupMap.delete(o.id)),this.addGroup(o,!1)}).flat();i.length>0&&this.aggregator&&this.aggregator.appendPoints(i,!1)}setGroupVisible(t,e){var i;(i=this.groupMap.get(t))==null||i.setVisible(e)}clearAllGroups(){this.groupMap.forEach(t=>t.removeAll(this.viewer)),this.groupMap.clear()}}class Io{constructor(t,e,i,o,s){h(this,"Cesium");h(this,"viewer");h(this,"layerMap",new Map);h(this,"materialManager");h(this,"aggregator");h(this,"cardPool");this.Cesium=t,this.viewer=e,this.materialManager=i,this.aggregator=o,this.cardPool=s}addLayer(t){this.layerMap.has(t)||this.layerMap.set(t,new Mo(t,this.Cesium,this.viewer,this.materialManager,this.aggregator,this.cardPool))}removeLayer(t){const e=this.layerMap.get(t);e&&(e.clearAllGroups(),this.layerMap.delete(t))}getLayer(t){return this.layerMap.get(t)}async addGroupsToLayer(t,e){const i=this.layerMap.get(t);i&&(i.addGroups(e),this.aggregator.refresh())}updateGroupToLayer(t,e){const i=this.layerMap.get(t);i&&(i.updateGroups(e),this.aggregator.refresh())}setGroupVisible(t,e,i){var o;(o=this.layerMap.get(t))==null||o.setGroupVisible(e,i)}removeGroup(t,e){var i;(i=this.layerMap.get(t))==null||i.removeGroup(e)}removeGroups(t,e){var i;(i=this.layerMap.get(t))==null||i.removeGroups(e)}}function To(a){const t=[];return a.features.forEach((e,i)=>{if(e.geometry&&e.properties){const o=e.geometry,s=e.properties,r={id:s.id||`${Date.now()}`,show:!0,zIndex:s.zIndex||1,name:`${s.layer}_${i}`||"",billboard:[],polyline:[],wall:[],polygon:[],card:s.card||null};switch(o.type){case"Point":r.billboard.push({position:o.coordinates,options:s,name:`${s.layer}_${i}`});break;case"LineString":r.polyline.push({positions:o.coordinates,theme:s.theme||"default"});break;case"Polygon":r.polygon.push({hierarchy:o.coordinates[0],theme:s.theme||"default"});break;case"MultiLineString":o.coordinates.forEach(n=>{r.polyline.push({positions:n})});break;case"MultiPolygon":o.coordinates.forEach(n=>{r.polygon.push({hierarchy:n[0]})});break;case"GeometryCollection":o.geometries.forEach(n=>{n.type==="Point"?r.billboard.push({position:n.coordinates}):n.type==="LineString"?r.polyline.push({positions:n.coordinates}):n.type==="Polygon"&&r.polygon.push({hierarchy:n.coordinates[0]})});break;default:console.warn(`Unsupported geometry type: ${o.type}`);break}t.push(r)}}),t}class xo{constructor(t){h(this,"Cesium");h(this,"viewer");h(this,"layerMap");h(this,"hideLayerMap");h(this,"entityLayerManager");h(this,"PrimitiveThemeMap");h(this,"materialManager");let{Cesium:e,viewer:i,materialManager:o,entityLayerManager:s}=t;this.Cesium=e,this.viewer=i,this.layerMap=new Map,this.PrimitiveThemeMap=new Map,this.hideLayerMap=new Map,this.materialManager=o,this.entityLayerManager=s}createGeometryInstance(t){let e;return t.category==="polyline"&&t.positions?e=this.createPolyline(t):t.category==="polygon"&&t.hierarchy&&(e=this.createPolygon(t)),e}carateThemePrimitive(t){let e=Oe(t),i=this.PrimitiveThemeMap.get(e.theme);if(!i){this.initTheme(e);let o=this.createAppearance(e);i={Primitive:null,ids:new Map,appearance:o,geometryInstances:new Map},this.PrimitiveThemeMap.set(e.theme,i)}return i}initTheme(t){var o,s,r,n,l,c,d,u,m,g,p,y;let e=this.materialManager,i=this.Cesium;if(t.category=="polyline"){const w=((s=(o=t.properties)==null?void 0:o.lineType)==null?void 0:s.pattern)&&((n=(r=t.properties)==null?void 0:r.lineType)==null?void 0:n.patternLength);let f="";if(w){const v=((c=(l=t.properties)==null?void 0:l.lineType)==null?void 0:c.pattern)||[.25,-.125],C=((u=(d=t.properties)==null?void 0:d.lineType)==null?void 0:u.patternLength)||.375;let b=this.convertCadPatternToCesiumDash(v,C);f=`DashedLineMaterial_pattern_${b.dashPattern}_dashLength_${b.dashLength}_color_${(m=t.properties)==null?void 0:m.color}`,e.has(f)||e.register({themeKey:f,material:i.Material.fromType("PolylineDash",{color:i.Color.fromCssColorString(t.properties.color||"#FFFFFF").withAlpha(.8),dashLength:b.dashLength,dashPattern:b.dashPattern})})}else f=`LineMaterial_color_${(g=t.properties)==null?void 0:g.color}`,e.has(f)||e.register({themeKey:f,material:i.Material.fromType("Color",{color:i.Color.fromCssColorString(t.properties.color||"#FFFFFF").withAlpha(.8)})})}else if(t.category=="polygon"){let w=`polygonMaterial_color_${(p=t.properties)==null?void 0:p.color}`;e.has(w)||e.register({themeKey:w,material:i.Material.fromType("Color",{color:i.Color.fromCssColorString(((y=t.properties)==null?void 0:y.color)||"#FFFFFF").withAlpha(.8)})})}}convertCadPatternToCesiumDash(t,e){const o=e/16;let s=[],r=0;for(let l of t){const c=Math.floor(Math.abs(l)/o),d=l>=0?1:0;for(let u=0;u<c&&(s.push(d),r++,!(r>=16));u++);if(r>=16)break}for(;s.length<16;)s.push(0);s.length>16&&(s.length=16);let n=0;for(let l=0;l<16;l++)n=n<<1|s[l];return{dashPattern:n,dashLength:e}}async processBatch(t){const e=new Map;t.forEach(i=>{let{layerId:o,dataList:s}=i;Oe(s).forEach(n=>{let l=this.createGeometryInstance(n);if(l){let c=this.carateThemePrimitive(n);c.ids.set(n.id,n),c.geometryInstances.set(n.id,l);const d=this.layerMap.get(o);if(d)d.set(n.id,n);else{let u=new Map;this.layerMap.set(o,u),u.set(n.id,n)}e.set(n.theme,n)}})}),e.forEach(i=>{this.updatePrimitive(i)})}createPolyline(t){const e=Array.isArray(t.positions[0])?t.positions.flat():t.positions;return new this.Cesium.GeometryInstance({id:t.id,geometry:new this.Cesium.GroundPolylineGeometry({positions:this.Cesium.Cartesian3.fromDegreesArrayHeights(e),width:Math.max(t.width||2,2)})})}createPolygon(t){var r;const e=Array.isArray(t.hierarchy[0])?t.hierarchy.flat():t.hierarchy,i=this.Cesium.Cartesian3.fromDegreesArrayHeights(e),o=((r=t.holes)==null?void 0:r.map(n=>{let l=Array.isArray(n[0])?n.flat():n,c=this.Cesium.Cartesian3.fromDegreesArrayHeights(l.flat());return new this.Cesium.PolygonHierarchy(c)}))||[],s=new this.Cesium.PolygonHierarchy(i,o);return new this.Cesium.GeometryInstance({id:t.id,geometry:new this.Cesium.PolygonGeometry({polygonHierarchy:s})})}getMaterial(t){let e=this.materialManager.get({themeKey:t.theme,options:t});return e||(e=this.Cesium.Material.fromType("Color",{color:new this.Cesium.Color(1,0,0,1)})),e}updateGeometryInstance(t){let e=Oe(t);const i=this.layerMap.get(e.layerId);if(!i){console.warn(`没有找到图层 ${e.layerId}`);return}let o=i.get(e.id);if(i.set(e.id,e),!o){console.warn(`没有找到图元 ${e.id} 在图层 ${e.layerId} 中`);return}if(o.theme!==e.theme){let r=this.PrimitiveThemeMap.get(o.theme);r==null||r.geometryInstances.delete(e.id),r==null||r.ids.delete(e.id),this.updatePrimitive(o)}let s=this.carateThemePrimitive(e);if(s){const r=this.createGeometryInstance(e);s.geometryInstances.set(e.id,r),s.ids.set(e.id,e),this.updatePrimitive(e)}}deleteGeometryInstance(t){let e=new Set;t.forEach(i=>{let{layerId:o,ids:s}=i;const r=this.layerMap.get(o);if(!r){console.warn(`没有找到图层 ${o}`);return}s.forEach(n=>{let l=r.get(n);if(!l){console.warn(`没有找到图元 ${n} 在图层 ${o} 中`);return}let c=this.PrimitiveThemeMap.get(l.theme);c&&(c.geometryInstances.delete(l.id),c.ids.delete(l.id),e.add(l))})}),Array.from(e.values()).forEach(i=>{this.updatePrimitive(i)})}addGeometryInstance(t){let e=Oe(t);const i=this.layerMap.get(e.layerId);if(!i){console.warn(`没有找到图层 ${e.layerId}`);return}if(i.get(e.id)){console.warn(`图元 ${e.id} 已经存在图层 ${e.layerId} 中`);return}i.set(e.id,e);let s=this.carateThemePrimitive(e);if(s){const r=this.createGeometryInstance(e);s.geometryInstances.set(e.id,r),s.ids.set(e.id,e),this.updatePrimitive(e)}}createAppearance(t){let e=this.getMaterial({theme:t.theme}),i;return t.category==="polyline"?i=new this.Cesium.PolylineMaterialAppearance({material:e,translucent:!0}):t.category==="polygon"&&(i=new this.Cesium.MaterialAppearance({material:e,translucent:!0})),i}updatePrimitive(t){const e=this.PrimitiveThemeMap.get(t.theme);if(!e)return;e.Primitive&&(this.viewer.scene.primitives.remove(e.Primitive),e.Primitive=null);let o=Array.from(e.geometryInstances,([s,r])=>({key:s,value:r})).filter(s=>!Array.from(this.hideLayerMap.values()).some(r=>r.has(s.key))).map(s=>s.value);o.length<=0||(t.category==="polyline"?(e.Primitive=new this.Cesium.GroundPolylinePrimitive({geometryInstances:o,appearance:e.appearance}),this.viewer.scene.primitives.add(e.Primitive)):(e.Primitive=new this.Cesium.GroundPrimitive({geometryInstances:o,appearance:e.appearance}),this.viewer.scene.primitives.add(e.Primitive)))}hideByLayerAndId(t){let e=new Map;t.forEach(i=>{let{layerId:o,ids:s}=i,r=this.hideLayerMap.get(o);r||(r=new Set,this.hideLayerMap.set(o,r)),s.forEach(n=>{r.add(n);let l=this.getGeometryInstanceInfo(o,n);l&&e.set(l.theme,l)})}),Array.from(e.values()).forEach(i=>{this.updatePrimitive(i)})}showByLayerAndId(t){let e=new Map;t.forEach(i=>{let{layerId:o,ids:s}=i,r=this.hideLayerMap.get(o);r||(r=new Set,this.hideLayerMap.set(o,r)),s.forEach(n=>{r.delete(n);let l=this.getGeometryInstanceInfo(o,n);l&&e.set(l.theme,l)})}),Array.from(e.values()).forEach(i=>{this.updatePrimitive(i)})}hasGeometryInstance(t,e){const i=this.layerMap.get(t);if(!i)return!1;const o=i.get(e);if(!o)return!1;let s=this.PrimitiveThemeMap.get(o.theme);return!(!s||!s.geometryInstances.get(e))}getGeometryInstanceInfo(t,e){const i=this.layerMap.get(t);return i?i.get(e):null}focusOnGeometryInstance(t,e){const i=this.layerMap.get(t);if(!i){console.warn(`图层 ${t} 不存在`);return}const o=i.get(e);if(!o){console.warn(`没有找到图元 ${e} 在图层 ${t} 中`);return}let s=this.PrimitiveThemeMap.get(o.theme);if(!s){console.warn(`没有找到 ${e} 图元相关的Primitive`);return}const r=s.geometryInstances.get(e);if(!r){console.warn(`没有找到图元的几何体 ${e}`);return}const n=r.geometry,l=n._positions||n._polygonHierarchy.positions;if(l&&l.length>0){let c=l[0].x,d=l[0].y,u=l[0].z,m=l[0].x,g=l[0].y,p=l[0].z;l.forEach(C=>{c=Math.min(c,C.x),d=Math.min(d,C.y),u=Math.min(u,C.z),m=Math.max(m,C.x),g=Math.max(g,C.y),p=Math.max(p,C.z)});const y=new this.Cesium.Cartesian3((c+m)/2,(d+g)/2,(u+p)/2),f=new this.Cesium.Cartesian3(m-c,g-d,p-u).z,v=Math.abs(f||1)*1.5;this.viewer.camera.flyTo({destination:y,duration:2,complete:()=>{console.log(`已定位到图元 ${e}`)},offset:new this.Cesium.Cartesian3(0,0,v)})}else console.warn(`无法获取图元 ${e} 的顶点信息`)}}class Ye{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"positions",[]);h(this,"tempPoints",[]);h(this,"segmentEntities",[]);h(this,"segmentLabelIds",[]);h(this,"previewEntity",null);h(this,"previewGroundEntity",null);h(this,"hoverPos",null);h(this,"htmlLabelPool",null);h(this,"totalLabelId",null);h(this,"previewLabelId",null);h(this,"labelEntity",null);h(this,"firstHeight",null);h(this,"groundLineEntities",[]);h(this,"previewPos",null);h(this,"previewGroundPos",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const o=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,o),this.htmlLabelPool.registerTheme("measure-horizontal-total",{createElement:(s,r)=>{var n;s.innerHTML=String(((n=r==null?void 0:r.data)==null?void 0:n.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-horizontal-seg",{createElement:(s,r)=>{var n;s.innerHTML=String(((n=r==null?void 0:r.data)==null?void 0:n.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(o=>{var y,w,f,v;const s=i.scene.pickPosition(o.position);if(!s)return;const r=e.Cartographic.fromCartesian(s),n=e.Math.toDegrees(r.longitude),l=e.Math.toDegrees(r.latitude);this.positions.length===0&&(this.firstHeight=r.height||0);const c=e.Cartesian3.fromDegrees(n,l,this.firstHeight||0);this.positions.push(c);const d=i.entities.add({position:c,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(d);const u=i.scene.globe.getHeight(new e.Cartographic(r.longitude,r.latitude,0))||0,m=e.Cartesian3.fromDegrees(n,l,u),g=((w=(y=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:w.call(y,.9))||e.Color.RED,p=i.entities.add({polyline:{positions:[m,c],width:t.width||3,material:new e.PolylineDashMaterialProperty({color:g,dashLength:12,dashPattern:255})}});if(this.groundLineEntities.push(p),this.positions.length>=2){const C=this.positions[this.positions.length-2],b=this.positions[this.positions.length-1],M=e.Cartographic.fromCartesian(C),P=e.Cartographic.fromCartesian(b),L=i.entities.add({polyline:{positions:[C,b],width:t.width||3,material:t.lineColor||t.color||e.Color.YELLOW,depthFailMaterial:new e.PolylineDashMaterialProperty({color:((v=(f=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:v.call(f,.9))||e.Color.RED,dashLength:12,dashPattern:255})}});this.segmentEntities.push(L);const I=new e.EllipsoidGeodesic(M,P).surfaceDistance,S=new e.Cartesian3((C.x+b.x)/2,(C.y+b.y)/2,(C.z+b.z)/2),x=e.Cartographic.fromCartesian(S),T=`measure_horizontal_seg_${this.segmentLabelIds.length}_${Date.now()}`;this.segmentLabelIds.push(T),this.htmlLabelPool.add({text:`${I.toFixed(2)} m`},{id:T,lon:e.Math.toDegrees(x.longitude),lat:e.Math.toDegrees(x.latitude),height:x.height||this.firstHeight||0,theme:"measure-horizontal-seg",show:!0})}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(()=>{var c;if(this.positions.length<2){this.stop();return}this.stop(),this.previewLabelId&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.hoverPos&&(this.hoverPos=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewGroundEntity&&(this.viewer.entities.remove(this.previewGroundEntity),this.previewGroundEntity=null);let o=0;for(let d=1;d<this.positions.length;d++){const u=this.positions[d-1],m=this.positions[d],g=e.Cartographic.fromCartesian(u),p=e.Cartographic.fromCartesian(m),y=new e.EllipsoidGeodesic(g,p);o+=y.surfaceDistance}const s=this.positions[this.positions.length-1],r=e.Cartographic.fromCartesian(s),n=this.totalLabelId||`measure_horizontal_total_${Date.now()}`;this.totalLabelId=n,this.htmlLabelPool.add({text:`${o.toFixed(2)} m`},{id:n,lon:e.Math.toDegrees(r.longitude),lat:e.Math.toDegrees(r.latitude),height:r.height||this.firstHeight||0,theme:"measure-horizontal-total",show:!0}),this.labelEntity=this.totalLabelId;const l={entity:this.segmentEntities,label:this.labelEntity,segmentLabels:this.segmentLabelIds,positions:this.positions,distance:o,clear:()=>this.clear()};(c=t.onComplete)==null||c.call(t,l)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK),this.handler.setInputAction(o=>{var M,P,L,E;if(this.positions.length===0)return;const s=i.scene.pickPosition(o.endPosition);if(!s)return;this.hoverPos=s;const r=e.Cartographic.fromCartesian(s),n=e.Math.toDegrees(r.longitude),l=e.Math.toDegrees(r.latitude),c=e.Cartesian3.fromDegrees(n,l,this.firstHeight||0);this.previewPos=c;const d=i.scene.globe.getHeight(new e.Cartographic(r.longitude,r.latitude,0))||0,u=e.Cartesian3.fromDegrees(n,l,d);this.previewGroundPos=u;const m=this.positions[this.positions.length-1],g=e.Cartographic.fromCartesian(m),p=e.Cartographic.fromCartesian(c),w=new e.EllipsoidGeodesic(g,p).surfaceDistance,f=new e.Cartesian3((m.x+c.x)/2,(m.y+c.y)/2,(m.z+c.z)/2),v=e.Cartographic.fromCartesian(f),C=this.previewLabelId||"measure_horizontal_preview";this.previewLabelId=C,this.htmlLabelPool.add({text:`${w.toFixed(2)} m`},{id:C,lon:e.Math.toDegrees(v.longitude),lat:e.Math.toDegrees(v.latitude),height:v.height||this.firstHeight||0,theme:"measure-horizontal-seg",show:!0});const b=((P=(M=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:P.call(M,.9))||e.Color.RED;this.previewGroundEntity||(this.previewGroundEntity=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewPos||!this.previewGroundPos?[]:[this.previewGroundPos,this.previewPos],!1),width:t.width||3,material:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}})),this.previewEntity||(this.previewEntity=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewPos||!this.positions.length?[]:[this.positions[this.positions.length-1],this.previewPos],!1),width:t.width||3,material:t.lineColor||t.color||e.Color.YELLOW,depthFailMaterial:new e.PolylineDashMaterialProperty({color:((E=(L=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:E.call(L,.9))||e.Color.RED,dashLength:12,dashPattern:255})}}))},e.ScreenSpaceEventType.MOUSE_MOVE)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){this.stop(),this.segmentEntities.forEach(t=>this.viewer.entities.remove(t)),this.segmentEntities=[],this.groundLineEntities.forEach(t=>this.viewer.entities.remove(t)),this.groundLineEntities=[],this.tempPoints.forEach(t=>this.viewer.entities.remove(t)),this.tempPoints=[],this.totalLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.totalLabelId]),this.totalLabelId=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewGroundEntity&&(this.viewer.entities.remove(this.previewGroundEntity),this.previewGroundEntity=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.segmentLabelIds.length&&this.htmlLabelPool&&this.htmlLabelPool.removeByIds(this.segmentLabelIds.slice()),this.segmentLabelIds=[],this.positions=[],this.hoverPos=null,this.labelEntity=null,this.firstHeight=null,this.previewPos=null,this.previewGroundPos=null}rehydrate(t,e){var p,y;const i=this.Cesium,o=this.viewer,s=t.options||{},r=s.lineColor||s.color||i.Color.YELLOW,n=((y=(p=s.dashLineColor||s.lineColor||s.color||i.Color.RED).withAlpha)==null?void 0:y.call(p,.9))||i.Color.RED,l=s.width||3,c=(t.positions||[]).map(w=>new i.Cartesian3(w[0],w[1],w[2]));if(!c.length)return;if(!this.htmlLabelPool){const w=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,o,w),this.htmlLabelPool.registerTheme("measure-horizontal-total",{createElement:(f,v)=>{var C;f.innerHTML=String(((C=v==null?void 0:v.data)==null?void 0:C.text)||""),f.style.background="rgba(0,0,0,0.6)",f.style.color="#fff",f.style.font="14px sans-serif",f.style.padding="4px 6px",f.style.borderRadius="4px",f.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-horizontal-seg",{createElement:(f,v)=>{var C;f.innerHTML=String(((C=v==null?void 0:v.data)==null?void 0:C.text)||""),f.style.background="rgba(0,0,0,0.6)",f.style.color="#fff",f.style.font="14px sans-serif",f.style.padding="4px 6px",f.style.borderRadius="4px",f.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}for(const w of c){const f=o.entities.add({position:w,point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(f);const v=i.Cartographic.fromCartesian(w),C=i.Math.toDegrees(v.longitude),b=i.Math.toDegrees(v.latitude),M=o.scene.globe.getHeight(new i.Cartographic(v.longitude,v.latitude,0))||0,P=i.Cartesian3.fromDegrees(C,b,M),L=o.entities.add({polyline:{positions:[P,w],width:l,material:new i.PolylineDashMaterialProperty({color:n,dashLength:12,dashPattern:255})}});this.groundLineEntities.push(L)}for(let w=1;w<c.length;w++){const f=c[w-1],v=c[w],C=o.entities.add({polyline:{positions:[f,v],width:l,material:r,depthFailMaterial:new i.PolylineDashMaterialProperty({color:n,dashLength:12,dashPattern:255})}});this.segmentEntities.push(C);const b=i.Cartographic.fromCartesian(f),M=i.Cartographic.fromCartesian(v),L=new i.EllipsoidGeodesic(b,M).surfaceDistance,E=new i.Cartesian3((f.x+v.x)/2,(f.y+v.y)/2,(f.z+v.z)/2),I=i.Cartographic.fromCartesian(E),S=t.id+`_seg_${w-1}`;this.segmentLabelIds.push(S),this.htmlLabelPool.add({text:`${L.toFixed(2)} m`},{id:S,lon:i.Math.toDegrees(I.longitude),lat:i.Math.toDegrees(I.latitude),height:I.height||0,theme:"measure-horizontal-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})}let d=0;for(let w=1;w<c.length;w++){const f=i.Cartographic.fromCartesian(c[w-1]),v=i.Cartographic.fromCartesian(c[w]),C=new i.EllipsoidGeodesic(f,v);d+=C.surfaceDistance}const u=c[c.length-1],m=i.Cartographic.fromCartesian(u),g=t.id+"_total";this.totalLabelId=g,this.htmlLabelPool.add({text:`${d.toFixed(2)} m`},{id:g,lon:i.Math.toDegrees(m.longitude),lat:i.Math.toDegrees(m.latitude),height:m.height||0,theme:"measure-horizontal-total",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})}}class Ve{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"entity",null);h(this,"labelEntity",null);h(this,"positions",[]);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);h(this,"previewLabelId",null);h(this,"baseCarto",null);h(this,"baseUp",null);h(this,"tempPoints",[]);h(this,"previewPointEntity",null);h(this,"previewEntity",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const o=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,o),this.htmlLabelPool.registerTheme("measure-vertical",{createElement:(s,r)=>{var n;s.innerHTML=String(((n=r==null?void 0:r.data)==null?void 0:n.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(o=>{var n,l,c,d,u;const s=i.camera.getPickRay(o.position);let r=s?i.scene.globe.pick(s,i.scene):null;if(r||(r=i.camera.pickEllipsoid(o.position,e.Ellipsoid.WGS84)),r||(r=i.scene.pickPosition(o.position)),!!r)if(this.positions.length===0){const m=e.Cartographic.fromCartesian(r);this.baseCarto=new e.Cartographic(m.longitude,m.latitude,0);const g=e.Ellipsoid.WGS84.cartographicToCartesian(this.baseCarto);this.baseUp=e.Ellipsoid.WGS84.geodeticSurfaceNormalCartographic(this.baseCarto),this.positions.push(g);const p=i.entities.add({position:g,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(p);const y=t.lineColor||t.color||e.Color.CYAN,w=((l=(n=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:l.call(n,.9))||e.Color.RED;this.previewEntity=i.entities.add({polyline:{positions:[g,g],width:t.width||3,material:y,depthFailMaterial:new e.PolylineDashMaterialProperty({color:w,dashLength:12,dashPattern:255})}})}else{if(!this.baseCarto||!this.baseUp)return;const m=this.positions[0],g=i.camera.getPickRay(o.position);if(!g)return;const p=g.origin,y=e.Cartesian3.normalize(g.direction,new e.Cartesian3),w=m,f=this.baseUp,v=e.Cartesian3.subtract(p,w,new e.Cartesian3),C=e.Cartesian3.dot(y,y),b=-e.Cartesian3.dot(y,f),M=e.Cartesian3.dot(f,f),P=-e.Cartesian3.dot(y,v),L=e.Cartesian3.dot(f,v),E=C*M-b*b;if(Math.abs(E)<1e-6)return;const I=(C*L-b*P)/E,S=e.Cartesian3.add(w,e.Cartesian3.multiplyByScalar(f,I,new e.Cartesian3),new e.Cartesian3);this.positions[1]=S,this.stop(),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewPointEntity&&(this.viewer.entities.remove(this.previewPointEntity),this.previewPointEntity=null);const x=t.lineColor||t.color||e.Color.CYAN,T=((d=(c=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:d.call(c,.9))||e.Color.RED;this.entity=i.entities.add({polyline:{positions:[m,S],width:t.width||3,material:x,depthFailMaterial:new e.PolylineDashMaterialProperty({color:T,dashLength:12,dashPattern:255})}});const A=i.entities.add({position:S,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(A);const $=this.baseCarto,R=e.Cartographic.fromCartesian(S),_=Math.abs((R.height||0)-($.height||0)),O=new e.Cartesian3((this.positions[0].x+this.positions[1].x)/2,(this.positions[0].y+this.positions[1].y)/2,(this.positions[0].z+this.positions[1].z)/2),k=e.Cartographic.fromCartesian(O);this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null);const G=this.htmlLabelId||`measure_vertical_${Date.now()}`;this.htmlLabelId=G,this.htmlLabelPool.add({text:`${_.toFixed(2)} m`},{id:G,lon:e.Math.toDegrees(k.longitude),lat:e.Math.toDegrees(k.latitude),height:k.height||0,theme:"measure-vertical",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const B={entity:this.entity,label:this.labelEntity,positions:this.positions,vertical:_,clear:()=>this.clear()};(u=t.onComplete)==null||u.call(t,B)}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(o=>{var S,x;if(this.positions.length<1)return;if(!this.baseCarto||!this.baseUp){const T=e.Cartographic.fromCartesian(this.positions[0]);this.baseCarto=new e.Cartographic(T.longitude,T.latitude,T.height||0),this.baseUp=e.Ellipsoid.WGS84.geodeticSurfaceNormalCartographic(this.baseCarto)}const s=this.positions[0],r=i.camera.getPickRay(o.endPosition);if(!r)return;const n=r.origin,l=e.Cartesian3.normalize(r.direction,new e.Cartesian3),c=s,d=this.baseUp,u=e.Cartesian3.subtract(n,c,new e.Cartesian3),m=e.Cartesian3.dot(l,l),g=-e.Cartesian3.dot(l,d),p=e.Cartesian3.dot(d,d),y=-e.Cartesian3.dot(l,u),w=e.Cartesian3.dot(d,u),f=m*p-g*g;if(Math.abs(f)<1e-6)return;const v=(m*w-g*y)/f,C=e.Cartesian3.add(c,e.Cartesian3.multiplyByScalar(d,v,new e.Cartesian3),new e.Cartesian3);if(this.positions[1]=C,!this.previewEntity){const T=t.lineColor||t.color||e.Color.CYAN,A=((x=(S=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:x.call(S,.9))||e.Color.RED;this.previewEntity=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>this.positions.length<2?[]:[this.positions[0],this.positions[1]],!1),width:t.width||3,material:T,depthFailMaterial:new e.PolylineDashMaterialProperty({color:A,dashLength:12,dashPattern:255})}})}this.previewPointEntity?this.previewPointEntity.position=C:this.previewPointEntity=i.entities.add({position:C,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});const b=this.baseCarto,M=e.Cartographic.fromCartesian(C),P=Math.abs((M.height||0)-(b.height||0)),L=new e.Cartesian3((this.positions[0].x+C.x)/2,(this.positions[0].y+C.y)/2,(this.positions[0].z+C.z)/2),E=e.Cartographic.fromCartesian(L),I=this.previewLabelId||"measure_vertical_preview";this.previewLabelId=I,this.htmlLabelPool.add({text:`${P.toFixed(2)} m`},{id:I,lon:e.Math.toDegrees(E.longitude),lat:e.Math.toDegrees(E.latitude),height:E.height||0,theme:"measure-vertical",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})},e.ScreenSpaceEventType.MOUSE_MOVE)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){this.stop(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.labelEntity&&(this.viewer.entities.remove(this.labelEntity),this.labelEntity=null),this.tempPoints.forEach(t=>this.viewer.entities.remove(t)),this.tempPoints=[],this.previewPointEntity&&(this.viewer.entities.remove(this.previewPointEntity),this.previewPointEntity=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.htmlLabelPool&&this.htmlLabelId&&(this.htmlLabelPool.removeByIds([this.htmlLabelId]),this.htmlLabelId=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.positions=[]}rehydrate(t,e){var b,M;const i=this.Cesium,o=this.viewer,s=t.options||{},r=s.lineColor||s.color||i.Color.CYAN,n=((M=(b=s.dashLineColor||s.lineColor||s.color||i.Color.RED).withAlpha)==null?void 0:M.call(b,.9))||i.Color.RED,l=s.width||3,c=(t.positions||[]).map(P=>new i.Cartesian3(P[0],P[1],P[2]));if(c.length<2)return;if(!this.htmlLabelPool){const P=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,o,P),this.htmlLabelPool.registerTheme("measure-vertical",{createElement:(L,E)=>{var I;L.innerHTML=String(((I=E==null?void 0:E.data)==null?void 0:I.text)||""),L.style.background="rgba(0,0,0,0.6)",L.style.color="#fff",L.style.font="14px sans-serif",L.style.padding="4px 6px",L.style.borderRadius="4px",L.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}const d=c[0],u=c[1],m=o.entities.add({position:d,point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),g=o.entities.add({position:u,point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(m),this.tempPoints.push(g),this.entity=o.entities.add({polyline:{positions:[d,u],width:l,material:r,depthFailMaterial:new i.PolylineDashMaterialProperty({color:n,dashLength:12,dashPattern:255})}});const p=i.Cartographic.fromCartesian(d),y=i.Cartographic.fromCartesian(u),w=Math.abs((y.height||0)-(p.height||0)),f=new i.Cartesian3((d.x+u.x)/2,(d.y+u.y)/2,(d.z+u.z)/2),v=i.Cartographic.fromCartesian(f),C=t.id+"_label";this.htmlLabelId=C,this.htmlLabelPool.add({text:`${w.toFixed(2)} m`},{id:C,lon:i.Math.toDegrees(v.longitude),lat:i.Math.toDegrees(v.latitude),height:v.height||0,theme:"measure-vertical",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})}}class We{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"positions",[]);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);h(this,"segmentEntities",[]);h(this,"angleMarkerEntities",[]);h(this,"pointEntities",[]);h(this,"segmentLabelIds",[]);h(this,"angleLabelIds",[]);h(this,"previewLabelId",null);h(this,"previewSegmentEntities",[]);h(this,"previewAngleMarkerEntities",[]);h(this,"previewPointEntity",null);h(this,"previewLow",null);h(this,"previewHigh",null);h(this,"previewThird",null);h(this,"previewMarkerP1",null);h(this,"previewMarkerP2",null);h(this,"previewMarkerCorner",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const o=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,o),this.htmlLabelPool.registerTheme("measure-triangle",{createElement:(s,r)=>{var n;s.innerHTML=String(((n=r==null?void 0:r.data)==null?void 0:n.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-triangle-seg",{createElement:(s,r)=>{var n;s.innerHTML=String(((n=r==null?void 0:r.data)==null?void 0:n.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-triangle-angle",{createElement:(s,r)=>{var n;s.innerHTML=String(((n=r==null?void 0:r.data)==null?void 0:n.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(o=>{var n,l,c;const s=i.scene.pickPosition(o.position);if(!s)return;this.positions.push(s);const r=i.entities.add({position:s,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});if(this.pointEntities.push(r),this.positions.length===2){this.stop(),this.previewSegmentEntities.forEach(J=>i.entities.remove(J)),this.previewSegmentEntities=[],this.previewAngleMarkerEntities.forEach(J=>i.entities.remove(J)),this.previewAngleMarkerEntities=[],this.previewPointEntity&&(i.entities.remove(this.previewPointEntity),this.previewPointEntity=null);const d=e.Cartographic.fromCartesian(this.positions[0]),u=e.Cartographic.fromCartesian(this.positions[1]),m=d.height||0,g=u.height||0,p=m<=g?this.positions[0]:this.positions[1],y=m>g?this.positions[0]:this.positions[1],w=e.Cartographic.fromCartesian(p);e.Cartographic.fromCartesian(y);const f=Math.max(m,g),v=e.Cartesian3.fromDegrees(e.Math.toDegrees(w.longitude),e.Math.toDegrees(w.latitude),f),C=t.lineColor||t.color||e.Color.YELLOW,b=((l=(n=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:l.call(n,.9))||e.Color.RED,M=i.entities.add({polyline:{positions:[p,v],width:t.width||3,material:C,depthFailMaterial:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}}),P=i.entities.add({polyline:{positions:[v,y],width:t.width||3,material:C,depthFailMaterial:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}}),L=i.entities.add({polyline:{positions:[p,y],width:t.width||3,material:C,depthFailMaterial:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}});this.segmentEntities.push(M,P,L);const E=e.Cartesian3.distance(p,v),I=e.Cartesian3.distance(v,y),S=e.Cartesian3.distance(p,y),x=new e.Cartesian3((p.x+v.x)/2,(p.y+v.y)/2,(p.z+v.z)/2),T=new e.Cartesian3((v.x+y.x)/2,(v.y+y.y)/2,(v.z+y.z)/2),A=new e.Cartesian3((p.x+y.x)/2,(p.y+y.y)/2,(p.z+y.z)/2),$=e.Cartographic.fromCartesian(x),R=e.Cartographic.fromCartesian(T),_=e.Cartographic.fromCartesian(A),O="measure_triangle_seg_v",k="measure_triangle_seg_h",G="measure_triangle_seg_hyp";this.segmentLabelIds=[O,k,G],this.htmlLabelPool.add({text:`${E.toFixed(2)} m`},{id:O,lon:e.Math.toDegrees($.longitude),lat:e.Math.toDegrees($.latitude),height:$.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${I.toFixed(2)} m`},{id:k,lon:e.Math.toDegrees(R.longitude),lat:e.Math.toDegrees(R.latitude),height:R.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${S.toFixed(2)} m`},{id:G,lon:e.Math.toDegrees(_.longitude),lat:e.Math.toDegrees(_.latitude),height:_.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const B=e.Cartesian3.subtract(y,p,new e.Cartesian3),j=e.Cartesian3.subtract(v,p,new e.Cartesian3),X=e.Cartesian3.subtract(v,y,new e.Cartesian3),Q=e.Cartesian3.subtract(p,y,new e.Cartesian3),ae=e.Cartesian3.dot(B,j),we=Math.sqrt(e.Cartesian3.dot(B,B))*Math.sqrt(e.Cartesian3.dot(j,j)),ve=e.Cartesian3.dot(X,Q),Te=Math.sqrt(e.Cartesian3.dot(X,X))*Math.sqrt(e.Cartesian3.dot(Q,Q)),Y=Math.acos(Math.min(Math.max(ae/(we||1),-1),1)),ue=Math.acos(Math.min(Math.max(ve/(Te||1),-1),1)),re=e.Cartographic.fromCartesian(p),W=e.Cartographic.fromCartesian(y),Z="measure_triangle_angle_a",le="measure_triangle_angle_b";this.angleLabelIds=[Z,le],this.htmlLabelPool.add({text:`${(Y*180/Math.PI).toFixed(2)}°`},{id:Z,lon:e.Math.toDegrees(re.longitude),lat:e.Math.toDegrees(re.latitude),height:re.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${(ue*180/Math.PI).toFixed(2)}°`},{id:le,lon:e.Math.toDegrees(W.longitude),lat:e.Math.toDegrees(W.latitude),height:W.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const Ce=Math.max(.01,Math.min(.5,t.angleMarkerRatio??.2)),U=Math.min(E,I)*Ce;if(E>.001&&I>.001){const J=e.Cartesian3.normalize(e.Cartesian3.subtract(p,v,new e.Cartesian3),new e.Cartesian3),he=e.Cartesian3.normalize(e.Cartesian3.subtract(y,v,new e.Cartesian3),new e.Cartesian3),ee=new e.Cartesian3(v.x+J.x*U,v.y+J.y*U,v.z+J.z*U),F=new e.Cartesian3(v.x+he.x*U,v.y+he.y*U,v.z+he.z*U),q=new e.Cartesian3(v.x+J.x*U+he.x*U,v.y+J.y*U+he.y*U,v.z+J.z*U+he.z*U),ie=i.entities.add({polyline:{positions:[ee,q],width:t.width||3,material:C,depthFailMaterial:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}}),Re=i.entities.add({polyline:{positions:[F,q],width:t.width||3,material:C,depthFailMaterial:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}});this.angleMarkerEntities.push(ie,Re)}this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null);const K={entity:this.segmentEntities,positions:[p,y,v],lengths:{vertical:E,horizontal:I,hypotenuse:S},angles:{acuteA:Y,acuteB:ue},clear:()=>this.clear()};(c=t.onComplete)==null||c.call(t,K)}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(o=>{var ue,re;if(this.positions.length!==1)return;const s=i.scene.pickPosition(o.endPosition);if(!s)return;const r=e.Cartographic.fromCartesian(this.positions[0]),n=e.Cartographic.fromCartesian(s),l=r.height||0,c=n.height||0,d=l<=c?this.positions[0]:s,u=l>c?this.positions[0]:s,m=e.Cartographic.fromCartesian(d),g=Math.max(l,c),p=e.Cartesian3.fromDegrees(this.Cesium.Math.toDegrees(m.longitude),this.Cesium.Math.toDegrees(m.latitude),g);this.previewLow=d,this.previewHigh=u,this.previewThird=p;const y=t.lineColor||t.color||e.Color.YELLOW,w=((re=(ue=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:re.call(ue,.9))||e.Color.RED;if(this.previewPointEntity?this.previewPointEntity.position=s:this.previewPointEntity=i.entities.add({position:s,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),!this.previewSegmentEntities.length){const W=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewLow||!this.previewThird?[]:[this.previewLow,this.previewThird],!1),width:t.width||3,material:y,depthFailMaterial:new e.PolylineDashMaterialProperty({color:w,dashLength:12,dashPattern:255})}}),Z=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewThird||!this.previewHigh?[]:[this.previewThird,this.previewHigh],!1),width:t.width||3,material:y,depthFailMaterial:new e.PolylineDashMaterialProperty({color:w,dashLength:12,dashPattern:255})}}),le=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewLow||!this.previewHigh?[]:[this.previewLow,this.previewHigh],!1),width:t.width||3,material:y,depthFailMaterial:new e.PolylineDashMaterialProperty({color:w,dashLength:12,dashPattern:255})}});this.previewSegmentEntities.push(W,Z,le)}const f=e.Cartesian3.distance(d,p),v=e.Cartesian3.distance(p,u),C=e.Cartesian3.distance(d,u),b=e.Cartesian3.subtract(u,d,new e.Cartesian3),M=e.Cartesian3.subtract(p,d,new e.Cartesian3),P=e.Cartesian3.subtract(p,u,new e.Cartesian3),L=e.Cartesian3.subtract(d,u,new e.Cartesian3),E=e.Cartesian3.dot(b,M),I=Math.sqrt(e.Cartesian3.dot(b,b))*Math.sqrt(e.Cartesian3.dot(M,M)),S=e.Cartesian3.dot(P,L),x=Math.sqrt(e.Cartesian3.dot(P,P))*Math.sqrt(e.Cartesian3.dot(L,L)),T=Math.acos(Math.min(Math.max(E/(I||1),-1),1)),A=Math.acos(Math.min(Math.max(S/(x||1),-1),1)),$=new e.Cartesian3((d.x+p.x)/2,(d.y+p.y)/2,(d.z+p.z)/2),R=new e.Cartesian3((p.x+u.x)/2,(p.y+u.y)/2,(p.z+u.z)/2),_=new e.Cartesian3((d.x+u.x)/2,(d.y+u.y)/2,(d.z+u.z)/2),O=e.Cartographic.fromCartesian($),k=e.Cartographic.fromCartesian(R),G=e.Cartographic.fromCartesian(_),B=e.Cartographic.fromCartesian(d),j=e.Cartographic.fromCartesian(u),X="measure_triangle_seg_v",Q="measure_triangle_seg_h",ae="measure_triangle_seg_hyp",we="measure_triangle_angle_a",ve="measure_triangle_angle_b";this.segmentLabelIds.length===0&&(this.segmentLabelIds=[X,Q,ae]),this.angleLabelIds.length===0&&(this.angleLabelIds=[we,ve]),this.htmlLabelPool.add({text:`${f.toFixed(2)} m`},{id:X,lon:e.Math.toDegrees(O.longitude),lat:e.Math.toDegrees(O.latitude),height:O.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${v.toFixed(2)} m`},{id:Q,lon:e.Math.toDegrees(k.longitude),lat:e.Math.toDegrees(k.latitude),height:k.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${C.toFixed(2)} m`},{id:ae,lon:e.Math.toDegrees(G.longitude),lat:e.Math.toDegrees(G.latitude),height:G.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${(T*180/Math.PI).toFixed(2)}°`},{id:we,lon:e.Math.toDegrees(B.longitude),lat:e.Math.toDegrees(B.latitude),height:B.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${(A*180/Math.PI).toFixed(2)}°`},{id:ve,lon:e.Math.toDegrees(j.longitude),lat:e.Math.toDegrees(j.latitude),height:j.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const Te=Math.max(.01,Math.min(.5,t.angleMarkerRatio??.2)),Y=Math.min(f,v)*Te;if(f>.001&&v>.001){const W=e.Cartesian3.normalize(e.Cartesian3.subtract(d,p,new e.Cartesian3),new e.Cartesian3),Z=e.Cartesian3.normalize(e.Cartesian3.subtract(u,p,new e.Cartesian3),new e.Cartesian3),le=new e.Cartesian3(p.x+W.x*Y,p.y+W.y*Y,p.z+W.z*Y),Ce=new e.Cartesian3(p.x+Z.x*Y,p.y+Z.y*Y,p.z+Z.z*Y),U=new e.Cartesian3(p.x+W.x*Y+Z.x*Y,p.y+W.y*Y+Z.y*Y,p.z+W.z*Y+Z.z*Y);if(this.previewMarkerP1=le,this.previewMarkerP2=Ce,this.previewMarkerCorner=U,!this.previewAngleMarkerEntities.length){const K=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewMarkerP1||!this.previewMarkerCorner?[]:[this.previewMarkerP1,this.previewMarkerCorner],!1),width:t.width||3,material:y,depthFailMaterial:new e.PolylineDashMaterialProperty({color:w,dashLength:12,dashPattern:255})}}),J=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewMarkerP2||!this.previewMarkerCorner?[]:[this.previewMarkerP2,this.previewMarkerCorner],!1),width:t.width||3,material:y,depthFailMaterial:new e.PolylineDashMaterialProperty({color:w,dashLength:12,dashPattern:255})}});this.previewAngleMarkerEntities.push(K,J)}}},e.ScreenSpaceEventType.MOUSE_MOVE)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){this.stop(),this.segmentEntities.forEach(t=>this.viewer.entities.remove(t)),this.segmentEntities=[],this.angleMarkerEntities.forEach(t=>this.viewer.entities.remove(t)),this.angleMarkerEntities=[],this.pointEntities.forEach(t=>this.viewer.entities.remove(t)),this.pointEntities=[],this.previewSegmentEntities.forEach(t=>this.viewer.entities.remove(t)),this.previewSegmentEntities=[],this.previewAngleMarkerEntities.forEach(t=>this.viewer.entities.remove(t)),this.previewAngleMarkerEntities=[],this.previewPointEntity&&(this.viewer.entities.remove(this.previewPointEntity),this.previewPointEntity=null),this.htmlLabelPool&&this.htmlLabelId&&(this.htmlLabelPool.removeByIds([this.htmlLabelId]),this.htmlLabelId=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.segmentLabelIds.length&&this.htmlLabelPool&&this.htmlLabelPool.removeByIds(this.segmentLabelIds.slice()),this.angleLabelIds.length&&this.htmlLabelPool&&this.htmlLabelPool.removeByIds(this.angleLabelIds.slice()),this.segmentLabelIds=[],this.angleLabelIds=[],this.positions=[]}rehydrate(t,e){var J,he;const i=this.Cesium,o=this.viewer,s=t.options||{},r=s.lineColor||s.color||i.Color.YELLOW,n=((he=(J=s.dashLineColor||s.lineColor||s.color||i.Color.RED).withAlpha)==null?void 0:he.call(J,.9))||i.Color.RED,l=s.width||3,c=(t.positions||[]).map(ee=>new i.Cartesian3(ee[0],ee[1],ee[2]));if(c.length<2)return;if(!this.htmlLabelPool){const ee=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,o,ee),this.htmlLabelPool.registerTheme("measure-triangle",{createElement:(F,q)=>{var ie;F.innerHTML=String(((ie=q==null?void 0:q.data)==null?void 0:ie.text)||""),F.style.background="rgba(0,0,0,0.6)",F.style.color="#fff",F.style.font="14px sans-serif",F.style.padding="4px 6px",F.style.borderRadius="4px",F.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-triangle-seg",{createElement:(F,q)=>{var ie;F.innerHTML=String(((ie=q==null?void 0:q.data)==null?void 0:ie.text)||""),F.style.background="rgba(0,0,0,0.6)",F.style.color="#fff",F.style.font="14px sans-serif",F.style.padding="4px 6px",F.style.borderRadius="4px",F.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-triangle-angle",{createElement:(F,q)=>{var ie;F.innerHTML=String(((ie=q==null?void 0:q.data)==null?void 0:ie.text)||""),F.style.background="rgba(0,0,0,0.6)",F.style.color="#fff",F.style.font="14px sans-serif",F.style.padding="4px 6px",F.style.borderRadius="4px",F.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}const d=i.Cartographic.fromCartesian(c[0]),u=i.Cartographic.fromCartesian(c[1]),m=d.height||0,g=u.height||0,p=m<=g?c[0]:c[1],y=m>g?c[0]:c[1],w=o.entities.add({position:p,point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),f=o.entities.add({position:y,point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.pointEntities.push(w,f);const v=i.Cartographic.fromCartesian(p),C=Math.max(m,g),b=i.Cartesian3.fromDegrees(i.Math.toDegrees(v.longitude),i.Math.toDegrees(v.latitude),C),M=o.entities.add({polyline:{positions:[p,b],width:l,material:r,depthFailMaterial:new i.PolylineDashMaterialProperty({color:n,dashLength:12,dashPattern:255})}}),P=o.entities.add({polyline:{positions:[b,y],width:l,material:r,depthFailMaterial:new i.PolylineDashMaterialProperty({color:n,dashLength:12,dashPattern:255})}}),L=o.entities.add({polyline:{positions:[p,y],width:l,material:r,depthFailMaterial:new i.PolylineDashMaterialProperty({color:n,dashLength:12,dashPattern:255})}});this.segmentEntities.push(M,P,L);const E=i.Cartesian3.distance(p,b),I=i.Cartesian3.distance(b,y),S=i.Cartesian3.distance(p,y),x=new i.Cartesian3((p.x+b.x)/2,(p.y+b.y)/2,(p.z+b.z)/2),T=new i.Cartesian3((b.x+y.x)/2,(b.y+y.y)/2,(b.z+y.z)/2),A=new i.Cartesian3((p.x+y.x)/2,(p.y+y.y)/2,(p.z+y.z)/2),$=i.Cartographic.fromCartesian(x),R=i.Cartographic.fromCartesian(T),_=i.Cartographic.fromCartesian(A),O=t.id+"_tri_v",k=t.id+"_tri_h",G=t.id+"_tri_hyp";this.segmentLabelIds=[O,k,G],this.htmlLabelPool.add({text:`${E.toFixed(2)} m`},{id:O,lon:i.Math.toDegrees($.longitude),lat:i.Math.toDegrees($.latitude),height:$.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${I.toFixed(2)} m`},{id:k,lon:i.Math.toDegrees(R.longitude),lat:i.Math.toDegrees(R.latitude),height:R.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${S.toFixed(2)} m`},{id:G,lon:i.Math.toDegrees(_.longitude),lat:i.Math.toDegrees(_.latitude),height:_.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const B=i.Cartesian3.subtract(y,p,new i.Cartesian3),j=i.Cartesian3.subtract(b,p,new i.Cartesian3),X=i.Cartesian3.subtract(b,y,new i.Cartesian3),Q=i.Cartesian3.subtract(p,y,new i.Cartesian3),ae=i.Cartesian3.dot(B,j),we=Math.sqrt(i.Cartesian3.dot(B,B))*Math.sqrt(i.Cartesian3.dot(j,j)),ve=i.Cartesian3.dot(X,Q),Te=Math.sqrt(i.Cartesian3.dot(X,X))*Math.sqrt(i.Cartesian3.dot(Q,Q)),Y=Math.acos(Math.min(Math.max(ae/(we||1),-1),1)),ue=Math.acos(Math.min(Math.max(ve/(Te||1),-1),1)),re=i.Cartographic.fromCartesian(p),W=i.Cartographic.fromCartesian(y),Z=s.labelText||{angle:"角度"},le=t.id+"_tri_angA",Ce=t.id+"_tri_angB";this.angleLabelIds=[le,Ce],this.htmlLabelPool.add({text:`${Z.angle}:${(Y*180/Math.PI).toFixed(2)}°`},{id:le,lon:i.Math.toDegrees(re.longitude),lat:i.Math.toDegrees(re.latitude),height:re.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${Z.angle}:${(ue*180/Math.PI).toFixed(2)}°`},{id:Ce,lon:i.Math.toDegrees(W.longitude),lat:i.Math.toDegrees(W.latitude),height:W.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const U=Math.max(.01,Math.min(.5,s.angleMarkerRatio??.2)),K=Math.min(E,I)*U;if(E>.001&&I>.001){const ee=i.Cartesian3.normalize(i.Cartesian3.subtract(p,b,new i.Cartesian3),new i.Cartesian3),F=i.Cartesian3.normalize(i.Cartesian3.subtract(y,b,new i.Cartesian3),new i.Cartesian3),q=new i.Cartesian3(b.x+ee.x*K,b.y+ee.y*K,b.z+ee.z*K),ie=new i.Cartesian3(b.x+F.x*K,b.y+F.y*K,b.z+F.z*K),Re=new i.Cartesian3(b.x+ee.x*K+F.x*K,b.y+ee.y*K+F.y*K,b.z+ee.z*K+F.z*K),Ao=o.entities.add({polyline:{positions:[q,Re],width:l,material:r,depthFailMaterial:new i.PolylineDashMaterialProperty({color:n,dashLength:12,dashPattern:255})}}),$o=o.entities.add({polyline:{positions:[ie,Re],width:l,material:r,depthFailMaterial:new i.PolylineDashMaterialProperty({color:n,dashLength:12,dashPattern:255})}});this.angleMarkerEntities.push(Ao,$o)}}}class Ue{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"entity",null);h(this,"labelEntity",null);h(this,"positions",[]);h(this,"tempPoints",[]);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);h(this,"previewEntity",null);h(this,"previewPos",null);h(this,"previewLabelId",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const o=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,o),this.htmlLabelPool.registerTheme("measure-space",{createElement:(s,r)=>{var n;s.innerHTML=String(((n=r==null?void 0:r.data)==null?void 0:n.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(o=>{var n,l,c;const s=i.scene.pickPosition(o.position);if(!s)return;this.positions.push(s);const r=i.entities.add({position:s,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});if(this.tempPoints.push(r),this.positions.length===2){this.stop(),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null);const d=this.positions[0],u=this.positions[1],m=t.lineColor||t.color||e.Color.YELLOW,g=((l=(n=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:l.call(n,.9))||e.Color.RED;this.entity=i.entities.add({polyline:{positions:[d,u],width:t.width||3,material:m,depthFailMaterial:new e.PolylineDashMaterialProperty({color:g,dashLength:12,dashPattern:255})}});const p=e.Cartesian3.distance(d,u),y=u,w=e.Cartographic.fromCartesian(y),f=this.htmlLabelId||`measure_space_${Date.now()}`;this.htmlLabelId=f,this.htmlLabelPool.add({text:`${p.toFixed(2)} m`},{id:f,lon:e.Math.toDegrees(w.longitude),lat:e.Math.toDegrees(w.latitude),height:w.height||0,theme:"measure-space",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const v={entity:this.entity,label:this.labelEntity,positions:this.positions,distance:p,clear:()=>this.clear()};(c=t.onComplete)==null||c.call(t,v)}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(o=>{var g,p;if(this.positions.length!==1)return;const s=i.scene.pickPosition(o.endPosition);if(!s)return;this.previewPos=s;const r=this.positions[0],n=e.Cartesian3.distance(r,s),l=new e.Cartesian3((r.x+s.x)/2,(r.y+s.y)/2,(r.z+s.z)/2),c=e.Cartographic.fromCartesian(l),d=this.previewLabelId||"measure_space_preview";this.previewLabelId=d,this.htmlLabelPool.add({text:`${n.toFixed(2)} m`},{id:d,lon:e.Math.toDegrees(c.longitude),lat:e.Math.toDegrees(c.latitude),height:c.height||0,theme:"measure-space",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const u=t.lineColor||t.color||e.Color.YELLOW,m=((p=(g=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:p.call(g,.9))||e.Color.RED;this.previewEntity||(this.previewEntity=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewPos||!this.positions.length?[]:[this.positions[0],this.previewPos],!1),width:t.width||3,material:u,depthFailMaterial:new e.PolylineDashMaterialProperty({color:m,dashLength:12,dashPattern:255})}}))},e.ScreenSpaceEventType.MOUSE_MOVE)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){this.stop(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.labelEntity&&(this.viewer.entities.remove(this.labelEntity),this.labelEntity=null),this.htmlLabelPool&&this.htmlLabelId&&(this.htmlLabelPool.removeByIds([this.htmlLabelId]),this.htmlLabelId=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.tempPoints.forEach(t=>this.viewer.entities.remove(t)),this.tempPoints=[],this.positions=[]}rehydrate(t,e){var d,u;const i=this.Cesium,o=this.viewer,s=t.options||{},r=s.lineColor||s.color||i.Color.YELLOW,n=((u=(d=s.dashLineColor||s.lineColor||s.color||i.Color.RED).withAlpha)==null?void 0:u.call(d,.9))||i.Color.RED,l=s.width||3,c=(t.positions||[]).map(m=>new i.Cartesian3(m[0],m[1],m[2]));if(c.length){if(!this.htmlLabelPool){const m=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,o,m),this.htmlLabelPool.registerTheme("measure-space",{createElement:(g,p)=>{var y;g.innerHTML=String(((y=p==null?void 0:p.data)==null?void 0:y.text)||""),g.style.background="rgba(0,0,0,0.6)",g.style.color="#fff",g.style.font="14px sans-serif",g.style.padding="4px 6px",g.style.borderRadius="4px",g.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}if(c.length>=1){const m=o.entities.add({position:c[0],point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(m)}if(c.length>=2){const m=o.entities.add({position:c[1],point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(m),this.entity=o.entities.add({polyline:{positions:[c[0],c[1]],width:l,material:r,depthFailMaterial:new i.PolylineDashMaterialProperty({color:n,dashLength:12,dashPattern:255})}});const g=i.Cartesian3.distance(c[0],c[1]),p=i.Cartographic.fromCartesian(c[1]),y=t.id+"_label";this.htmlLabelId=y,this.htmlLabelPool.add({text:`${g.toFixed(2)} m`},{id:y,lon:i.Math.toDegrees(p.longitude),lat:i.Math.toDegrees(p.latitude),height:p.height||0,theme:"measure-space",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})}}}}class Ke{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"entity",null);h(this,"labelEntity",null);h(this,"positions",[]);h(this,"tempPoints",[]);h(this,"primitive",null);h(this,"previewEntity",null);h(this,"previewPos",null);h(this,"edgeEntities",[]);h(this,"pointEntities",[]);h(this,"previewEdgeEntity",null);h(this,"previewPointEntities",[]);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);h(this,"previewLabelId",null);h(this,"segmentLabelIds",[]);h(this,"angleLabelIds",[]);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const o=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,o),this.htmlLabelPool.registerTheme("measure-area",{createElement:(s,r)=>{var n;s.innerHTML=String(((n=r==null?void 0:r.data)==null?void 0:n.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-area-seg",{createElement:(s,r)=>{var n;s.innerHTML=String(((n=r==null?void 0:r.data)==null?void 0:n.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-area-angle",{createElement:(s,r)=>{var n;s.innerHTML=String(((n=r==null?void 0:r.data)==null?void 0:n.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(o=>{var m,g;const s=i.scene.pickPosition(o.position);if(!s)return;this.positions.push(s);const r=i.entities.add({position:s,point:{pixelSize:8,color:t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(r),this.primitive&&(i.scene.primitives.remove(this.primitive),this.primitive=null);const n=new e.PolygonHierarchy(this.positions.slice()),l=new e.PolygonGeometry({polygonHierarchy:n,vertexFormat:e.MaterialAppearance.VERTEX_FORMAT,perPositionHeight:!0,arcType:e.ArcType.NONE}),c=new e.GeometryInstance({geometry:l}),d=t.color||e.Color.YELLOW.withAlpha(.4),u=t.color&&t.color.withAlpha?t.color.withAlpha(.25):e.Color.RED.withAlpha(.4);if(this.primitive=new e.Primitive({geometryInstances:c,appearance:new e.MaterialAppearance({material:e.Material.fromType("Color",{color:d}),translucent:!0,closed:!0}),depthFailAppearance:new e.MaterialAppearance({material:e.Material.fromType("Color",{color:u}),translucent:!0,closed:!0})}),i.scene.primitives.add(this.primitive),this.positions.length>=2){if(this.edgeEntities.length){for(const v of this.edgeEntities)try{i.entities.remove(v)}catch{}this.edgeEntities=[]}const p=t.lineColor||t.color||e.Color.YELLOW,y=((g=(m=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:g.call(m,.9))||e.Color.RED,w=this.positions.concat([this.positions[0]]),f=i.entities.add({polyline:{positions:w,width:t.width||2,material:p,clampToGround:!1,arcType:e.ArcType.NONE,depthFailMaterial:new e.PolylineDashMaterialProperty({color:y,dashLength:12,dashPattern:255})}});this.edgeEntities.push(f)}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(o=>{var p,y;if(this.positions.length===0)return;const s=i.scene.pickPosition(o.endPosition);if(!s)return;this.previewPos=s;const r=this.positions.concat([s]),n=new e.Cartesian3(r.reduce((w,f)=>w+f.x,0)/r.length,r.reduce((w,f)=>w+f.y,0)/r.length,r.reduce((w,f)=>w+f.z,0)/r.length),c=new e.EllipsoidTangentPlane(n,e.Ellipsoid.WGS84).projectPointsOntoPlane(r);let d=0;for(let w=0;w<c.length;w++){const f=(w+1)%c.length;d+=c[w].x*c[f].y-c[f].x*c[w].y}d=Math.abs(d)/2;const u=e.Cartographic.fromCartesian(n),m=this.previewLabelId||"measure_area_preview";this.previewLabelId=m;const g=t.labelText||{area:"面积"};if(this.htmlLabelPool.add({text:`${g.area}:${d.toFixed(2)} m²`},{id:m,lon:e.Math.toDegrees(u.longitude),lat:e.Math.toDegrees(u.latitude),height:u.height||0,theme:"measure-area",show:!0}),!this.previewEntity){const w=t.color||e.Color.YELLOW.withAlpha(.4);this.previewEntity=i.entities.add({polygon:{hierarchy:new e.CallbackProperty(()=>{if(!this.previewPos||!this.positions.length)return;const M=this.positions.concat([this.previewPos]);return new e.PolygonHierarchy(M)},!1),material:w,perPositionHeight:!0,arcType:e.ArcType.NONE}});const f=t.lineColor||t.color||e.Color.YELLOW,v=((y=(p=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:y.call(p,.9))||e.Color.RED;this.previewEdgeEntity=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewPos||!this.positions.length?[]:this.positions.concat([this.previewPos,this.positions[0]]),!1),width:t.width||2,material:f,clampToGround:!1,arcType:e.ArcType.NONE,depthFailMaterial:new e.PolylineDashMaterialProperty({color:v,dashLength:12,dashPattern:255})}});const C=t.pointColor||t.color||e.Color.YELLOW,b=i.entities.add({position:new e.CallbackProperty(()=>this.previewPos||this.positions[this.positions.length-1],!1),point:{pixelSize:8,color:C,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.previewPointEntities.push(b)}},e.ScreenSpaceEventType.MOUSE_MOVE),this.handler.setInputAction(()=>{var g;if(this.positions.length<3){this.stop();return}if(this.positions.length>=3){this.positions.pop();const p=this.tempPoints.pop();p&&this.viewer.entities.remove(p)}if(this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewEdgeEntity&&(this.viewer.entities.remove(this.previewEdgeEntity),this.previewEdgeEntity=null),this.previewPointEntities.length){for(const p of this.previewPointEntities)try{this.viewer.entities.remove(p)}catch{}this.previewPointEntities=[]}this.previewPos=null,this.stop();const o=new e.Cartesian3(this.positions.reduce((p,y)=>p+y.x,0)/this.positions.length,this.positions.reduce((p,y)=>p+y.y,0)/this.positions.length,this.positions.reduce((p,y)=>p+y.z,0)/this.positions.length),r=new e.EllipsoidTangentPlane(o,e.Ellipsoid.WGS84).projectPointsOntoPlane(this.positions);let n=0;for(let p=0;p<r.length;p++){const y=(p+1)%r.length;n+=r[p].x*r[y].y-r[y].x*r[p].y}n=Math.abs(n)/2;const l=e.Cartographic.fromCartesian(o),c=this.htmlLabelId||`measure_area_${Date.now()}`;this.htmlLabelId=c;const d=t.labelText||{area:"面积",side:"边长",angle:"角度"};this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.htmlLabelPool.add({text:`${d.area}:${n.toFixed(2)} m²`},{id:c,lon:e.Math.toDegrees(l.longitude),lat:e.Math.toDegrees(l.latitude),height:l.height||0,theme:"measure-area",show:!0}),this.labelEntity=this.htmlLabelId;for(let p=0;p<this.positions.length;p++){const y=(p+1)%this.positions.length,w=this.positions[p],f=this.positions[y],v=e.Cartographic.fromCartesian(w),C=e.Cartographic.fromCartesian(f),M=new e.EllipsoidGeodesic(v,C).surfaceDistance,P=new e.Cartesian3((w.x+f.x)/2,(w.y+f.y)/2,(w.z+f.z)/2),L=e.Cartographic.fromCartesian(P),E=`measure_area_seg_${Date.now()}_${p}`;this.segmentLabelIds.push(E),this.htmlLabelPool.add({text:`${d.side}:${M.toFixed(2)} m`},{id:E,lon:e.Math.toDegrees(L.longitude),lat:e.Math.toDegrees(L.latitude),height:L.height||0,theme:"measure-area-seg",show:!0})}const u=r;for(let p=0;p<u.length;p++){const y=u[(p-1+u.length)%u.length],w=u[p],f=u[(p+1)%u.length],v=y.x-w.x,C=y.y-w.y,b=f.x-w.x,M=f.y-w.y,P=Math.sqrt(v*v+C*C),L=Math.sqrt(b*b+M*M);if(!P||!L)continue;const E=v/P*(b/L)+C/P*(M/L),I=Math.acos(Math.min(1,Math.max(-1,E)))*(180/Math.PI),S=e.Cartographic.fromCartesian(this.positions[p]),x=`measure_area_angle_${Date.now()}_${p}`;this.angleLabelIds.push(x),this.htmlLabelPool.add({text:`${d.angle}:${I.toFixed(2)} °`},{id:x,lon:e.Math.toDegrees(S.longitude),lat:e.Math.toDegrees(S.latitude),height:S.height||0,theme:"measure-area-angle",show:!0})}const m={entity:this.primitive,label:this.labelEntity,positions:this.positions,area:n,clear:()=>this.clear()};(g=t.onComplete)==null||g.call(t,m)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){if(this.stop(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.primitive&&(this.viewer.scene.primitives.remove(this.primitive),this.primitive=null),this.edgeEntities.length){for(const t of this.edgeEntities)try{this.viewer.entities.remove(t)}catch{}this.edgeEntities=[]}if(this.pointEntities.length){for(const t of this.pointEntities)try{this.viewer.entities.remove(t)}catch{}this.pointEntities=[]}if(this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null,this.previewPos=null),this.previewEdgeEntity&&(this.viewer.entities.remove(this.previewEdgeEntity),this.previewEdgeEntity=null),this.previewPointEntities.length){for(const t of this.previewPointEntities)try{this.viewer.entities.remove(t)}catch{}this.previewPointEntities=[]}this.labelEntity&&(this.viewer.entities.remove(this.labelEntity),this.labelEntity=null),this.htmlLabelPool&&this.htmlLabelId&&(this.htmlLabelPool.removeByIds([this.htmlLabelId]),this.htmlLabelId=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.segmentLabelIds.length&&this.htmlLabelPool&&this.htmlLabelPool.removeByIds(this.segmentLabelIds.slice()),this.angleLabelIds.length&&this.htmlLabelPool&&this.htmlLabelPool.removeByIds(this.angleLabelIds.slice()),this.segmentLabelIds=[],this.angleLabelIds=[],this.tempPoints.forEach(t=>this.viewer.entities.remove(t)),this.tempPoints=[],this.positions=[]}rehydrate(t,e){const i=this.Cesium,o=this.viewer,s=t.options||{},r=(t.positions||[]).map(M=>new i.Cartesian3(M[0],M[1],M[2]));if(r.length<3)return;if(!this.htmlLabelPool){const M=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,o,M),this.htmlLabelPool.registerTheme("measure-area",{createElement:(P,L)=>{var E;P.innerHTML=String(((E=L==null?void 0:L.data)==null?void 0:E.text)||""),P.style.background="rgba(0,0,0,0.6)",P.style.color="#fff",P.style.font="14px sans-serif",P.style.padding="4px 6px",P.style.borderRadius="4px",P.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-area-seg",{createElement:(P,L)=>{var E;P.innerHTML=String(((E=L==null?void 0:L.data)==null?void 0:E.text)||""),P.style.background="rgba(0,0,0,0.6)",P.style.color="#fff",P.style.font="14px sans-serif",P.style.padding="4px 6px",P.style.borderRadius="4px",P.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-area-angle",{createElement:(P,L)=>{var E;P.innerHTML=String(((E=L==null?void 0:L.data)==null?void 0:E.text)||""),P.style.background="rgba(0,0,0,0.6)",P.style.color="#fff",P.style.font="14px sans-serif",P.style.padding="4px 6px",P.style.borderRadius="4px",P.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}for(const M of r){const P=o.entities.add({position:M,point:{pixelSize:8,color:s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(P)}const n=new i.Cartesian3(r.reduce((M,P)=>M+P.x,0)/r.length,r.reduce((M,P)=>M+P.y,0)/r.length,r.reduce((M,P)=>M+P.z,0)/r.length),c=new i.EllipsoidTangentPlane(n,i.Ellipsoid.WGS84).projectPointsOntoPlane(r);let d=0;for(let M=0;M<c.length;M++){const P=(M+1)%c.length;d+=c[M].x*c[P].y-c[P].x*c[M].y}d=Math.abs(d)/2;const u=i.Cartographic.fromCartesian(n),m=t.id+"_area";this.htmlLabelId=m;const g=s.labelText||{area:"面积",side:"边长",angle:"角度"};this.htmlLabelPool.add({text:`${g.area}:${d.toFixed(2)} m²`},{id:m,lon:i.Math.toDegrees(u.longitude),lat:i.Math.toDegrees(u.latitude),height:u.height||0,theme:"measure-area",show:!0});const p=new i.PolygonHierarchy(r),y=new i.PolygonGeometry({polygonHierarchy:p,vertexFormat:i.MaterialAppearance.VERTEX_FORMAT,perPositionHeight:!0}),w=new i.GeometryInstance({geometry:y}),f=s.color||i.Color.YELLOW.withAlpha(.4),v=s.color&&s.color.withAlpha?s.color.withAlpha(.25):i.Color.RED.withAlpha(.4),C=new i.Primitive({geometryInstances:w,appearance:new i.MaterialAppearance({material:i.Material.fromType("Color",{color:f}),translucent:!0,closed:!0}),depthFailAppearance:new i.MaterialAppearance({material:i.Material.fromType("Color",{color:v}),translucent:!0,closed:!0})});o.scene.primitives.add(C),this.primitive=C;for(let M=0;M<r.length;M++){const P=(M+1)%r.length,L=r[M],E=r[P],I=i.Cartographic.fromCartesian(L),S=i.Cartographic.fromCartesian(E),T=new i.EllipsoidGeodesic(I,S).surfaceDistance,A=new i.Cartesian3((L.x+E.x)/2,(L.y+E.y)/2,(L.z+E.z)/2),$=i.Cartographic.fromCartesian(A),R=t.id+`_area_seg_${M}`;this.segmentLabelIds.push(R),this.htmlLabelPool.add({text:`${g.side}:${T.toFixed(2)} m`},{id:R,lon:i.Math.toDegrees($.longitude),lat:i.Math.toDegrees($.latitude),height:$.height||0,theme:"measure-area-seg",show:!0})}const b=c;for(let M=0;M<b.length;M++){const P=b[(M-1+b.length)%b.length],L=b[M],E=b[(M+1)%b.length],I=P.x-L.x,S=P.y-L.y,x=E.x-L.x,T=E.y-L.y,A=Math.sqrt(I*I+S*S),$=Math.sqrt(x*x+T*T);if(!A||!$)continue;const R=I/A*(x/$)+S/A*(T/$),_=Math.acos(Math.min(1,Math.max(-1,R)))*(180/Math.PI),O=i.Cartographic.fromCartesian(r[M]),k=t.id+`_area_angle_${M}`;this.angleLabelIds.push(k),this.htmlLabelPool.add({text:`${g.angle}:${_.toFixed(2)} °`},{id:k,lon:i.Math.toDegrees(O.longitude),lat:i.Math.toDegrees(O.latitude),height:O.height||0,theme:"measure-area-angle",show:!0})}}}class qe{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"entity",null);h(this,"positions",[]);h(this,"currentRadius",0);h(this,"labelEntity",null);h(this,"previewLabel",null);h(this,"ellipsePrimitive",null);h(this,"previewEntity",null);h(this,"isPrimitive",!1);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const o=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,o),this.htmlLabelPool.registerTheme("measure-circle",{createElement:(s,r)=>{var l;const n=((l=r==null?void 0:r.data)==null?void 0:l.text)||"";s.innerHTML=String(n),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(o=>{var r;const s=i.scene.pickPosition(o.position);if(s&&(this.positions.push(s),this.positions.length===2)){this.stop();const n=this.positions[0],l=this.positions[1],c=e.Cartesian3.distance(n,l),d=Math.PI*c*c,u=2*Math.PI*c,m=t.labelText||{radius:"半径",area:"面积",circumference:"周长"},g=n;this.labelEntity?(this.labelEntity.position=g,this.labelEntity.label.text=`${m.radius}:${c.toFixed(2)} m
|
|
43
|
+
}`})()},translucent(){return!0}}),new d(t)}class En{constructor(){h(this,"categoryMap",new Map);h(this,"CategoryGet",{})}registerCategoryGet(t,e){if(!t)return console.warn("分类不能为空");this.CategoryGet[t]=e}register(t){const{themeKey:e,material:i,force:n=!1,category:s="default"}=t;this.categoryMap.has(s)||this.categoryMap.set(s,new Map);const o=this.categoryMap.get(s);if(o.has(e))if(n)console.info(`[MaterialManager] themeKey '${e}' 在分类 '${s}' 已被覆盖`);else{console.warn(`[MaterialManager] 已存在 themeKey '${e}' 在分类 '${s}',如需覆盖请设置 force = true`);return}o.set(e,i)}get({themeKey:t,category:e,options:i}){var n;return e=e||"default",this.CategoryGet[e]?this.CategoryGet[e]({themeKey:t,materialMap:this.categoryMap,options:i||{}}):(n=this.categoryMap.get(e))==null?void 0:n.get(t)}has(t,e="default"){var i;return((i=this.categoryMap.get(e))==null?void 0:i.has(t))??!1}remove(t,e="default"){const i=this.categoryMap.get(e);if(!i)return;const n=i.get(t);n!=null&&n.destroy&&n.destroy(),i.delete(t),i.size===0&&this.categoryMap.delete(e)}keys(t="default"){var e;return[...((e=this.categoryMap.get(t))==null?void 0:e.keys())||[]]}clearCategory(t="default"){var i;const e=this.categoryMap.get(t);if(e){for(const n of e.values())(i=n==null?void 0:n.destroy)==null||i.call(n);e.clear(),this.categoryMap.delete(t)}}clearAll(){var t;for(const e of this.categoryMap.values())for(const i of e.values())(t=i==null?void 0:i.destroy)==null||t.call(i);this.categoryMap.clear()}categories(){return[...this.categoryMap.keys()]}}class Mn{constructor(t){h(this,"id");h(this,"entities",[]);h(this,"primitives",[]);h(this,"dataItem",{});h(this,"aggregator");h(this,"cardPool");const{id:e,entities:i=[],primitives:n=[],dataItem:s={},aggregator:o,cardPool:r}=t;this.id=e,this.entities=i,this.primitives=n,this.dataItem=s,this.aggregator=o,this.cardPool=r}setVisible(t){this.entities.forEach(e=>{e&&(e.show=t)}),this.primitives.forEach(e=>{e&&(e.show=t)}),this.aggregator&&Array.isArray(this.dataItem.billboard)&&this.dataItem.billboard.map((i,n)=>{var o;return{id:this.dataItem.id,data:{...this.dataItem,show:t&&(((o=i.data)==null?void 0:o.show)??!0)}}}).forEach(i=>{var n;(n=this.aggregator)==null||n.updatePoint(i)}),this.cardPool&&this.dataItem.card&&(t?this.cardPool.showByIds([this.dataItem.id]):this.cardPool.hideByIds([this.dataItem.id]))}removeAll(t,e=!0){return this.entities.forEach(i=>{i&&t.entities.remove(i)}),this.entities=[],this.primitives.forEach(i=>{i&&t.scene.primitives.remove(i)}),this.primitives=[],e&&this.aggregator&&Array.isArray(this.dataItem.billboard)&&this.aggregator.removePointsById([this.dataItem.id]),e&&this.cardPool&&this.dataItem.card&&this.cardPool.removeByIds([this.dataItem.id]),this.dataItem.id}}class In{constructor(t,e,i,n,s,o){h(this,"id");h(this,"groupMap",new Map);h(this,"Cesium");h(this,"viewer");h(this,"materialManager");h(this,"aggregator");h(this,"cardPool");this.id=t,this.Cesium=e,this.viewer=i,this.materialManager=n,this.aggregator=s,this.cardPool=o,this.aggregator.labelPool.eventBus.addListener(V.Click,{name:"BufferedHierarchicalAggregator_maker_click",fn:(l,c)=>{this.cardPool.showByIds([l.data.id])}}),new e.ScreenSpaceEventHandler(i.scene.canvas).setInputAction(()=>{this.cardPool.hideFilter(l=>!l.initShow)},e.ScreenSpaceEventType.LEFT_CLICK)}createPolyline(t,e){if(!t.positions||t.positions.length<1)return null;const i=this.materialManager.get({themeKey:t.theme,category:"polyline",options:t}),n=Array.isArray(t.positions[0])?t.positions.flat():t.positions;let s={...t};return i&&(s.material=i),this.viewer.entities.add({polyline:{...s,positions:this.Cesium.Cartesian3.fromDegreesArrayHeights(n)},show:(t.show??!0)&&e})}createWall(t,e){var l,c;if(!t.positions||t.positions.length<1)return null;const i=this.materialManager.get({themeKey:t.theme,category:"wall",options:t}),n=t.positions.length===((l=t.minimumHeights)==null?void 0:l.length)?t.minimumHeights.map(d=>d-Number(t.minHeight||0)):t.positions.map(d=>(d[2]||0)-Number(t.minHeight||0)),s=t.positions.length===((c=t.maximumHeights)==null?void 0:c.length)?t.maximumHeights.map(d=>d+Number(t.maxHeight||0)):t.positions.map(d=>(d[2]||0)+Number(t.maxHeight||0)),o=t.positions.map(d=>this.Cesium.Cartesian3.fromDegrees(d[0],d[1],d[2]||0));let r={...t};return i&&(r.material=i),this.viewer.entities.add({wall:{...r,positions:o,minimumHeights:n,maximumHeights:s},show:(t.show??!0)&&e})}createPolygon(t,e){var c;if(!t.hierarchy||t.hierarchy.length<1)return null;const i=this.materialManager.get({themeKey:t.theme,category:"polygon",options:t}),n=Array.isArray(t.hierarchy[0])?t.hierarchy.flat():t.hierarchy,s=this.Cesium.Cartesian3.fromDegreesArrayHeights(n),o=((c=t.holes)==null?void 0:c.map(d=>{let u=Array.isArray(d[0])?t.hierarchy.flat():t.hole;return this.Cesium.Cartesian3.fromDegreesArrayHeights(u.flat())}))||[],r=new this.Cesium.PolygonHierarchy(s,o);let l={...t};return i&&(l.material=i),this.viewer.entities.add({polygon:{...l,hierarchy:r},show:(t.show??!0)&&e})}createBillboardPoints(t){var e;return!((e=t.billboard)!=null&&e.length)||!this.aggregator?[]:t.billboard.map(i=>{var r;const[n,s,o=0]=i.position||[0,0,0];return{id:t.id,lon:n,lat:s,height:o,name:((r=i.options)==null?void 0:r.text)||"",data:t,style:{zIndex:t.zIndex||"1"}}})}createCard(t){var e,i,n;(i=(e=t.card)==null?void 0:e.data)!=null&&i.length&&this.cardPool.add(t.card,{id:t.id,lon:t.card.position[0],lat:t.card.position[1],height:t.card.position[3]||0,theme:t.card.theme,show:t.show?t.card.initShow??!1:!1,notCreateElement:!0,style:{width:"0",height:"0",zIndex:((n=t==null?void 0:t.card)==null?void 0:n.zIndex)||"110"}})}addGroup(t,e=!0){const i=t.id||`${Date.now()}`;this.removeGroup(i);const n=[],s=t.show!==!1;(t.polyline||[]).forEach(l=>{const c=this.createPolyline(l,s);c&&n.push(c)}),(t.wall||[]).forEach(l=>{const c=this.createWall(l,s);c&&n.push(c)}),(t.polygon||[]).forEach(l=>{const c=this.createPolygon(l,s);c&&n.push(c)});const o=this.createBillboardPoints(t);o.length&&e&&this.aggregator.appendPoints(o,!1),this.createCard(t);const r=new Mn({id:i,entities:n,primitives:[],dataItem:t,aggregator:this.aggregator,cardPool:this.cardPool});return this.groupMap.set(i,r),o}async addGroups(t){const i=t.map(n=>this.addGroup(n,!1)).flat();i.length>0&&this.aggregator&&this.aggregator.appendPoints(i,!1)}removeGroup(t){const e=this.groupMap.get(t);e&&(e.removeAll(this.viewer),this.groupMap.delete(t))}removeGroups(t){let e=[];for(const i of t){const n=this.groupMap.get(i);if(n){let s=n.removeAll(this.viewer,!1);this.groupMap.delete(i),e.push(s)}}this.aggregator.removePointsById(e),this.cardPool.removeByIds(e)}updateGroup(t){const e=this.groupMap.get(t.id);e&&(e.removeAll(this.viewer),this.groupMap.delete(t.id)),this.addGroup(t)}async updateGroups(t){this.aggregator.removePointsById(t.map(n=>n.id)),this.cardPool.removeByIds(t.map(n=>n.id));const i=t.map(n=>{const s=this.groupMap.get(n.id);return s&&(s.removeAll(this.viewer,!1),this.groupMap.delete(n.id)),this.addGroup(n,!1)}).flat();i.length>0&&this.aggregator&&this.aggregator.appendPoints(i,!1)}setGroupVisible(t,e){var i;(i=this.groupMap.get(t))==null||i.setVisible(e)}clearAllGroups(){this.groupMap.forEach(t=>t.removeAll(this.viewer)),this.groupMap.clear()}}class Tn{constructor(t,e,i,n,s){h(this,"Cesium");h(this,"viewer");h(this,"layerMap",new Map);h(this,"materialManager");h(this,"aggregator");h(this,"cardPool");this.Cesium=t,this.viewer=e,this.materialManager=i,this.aggregator=n,this.cardPool=s}addLayer(t){this.layerMap.has(t)||this.layerMap.set(t,new In(t,this.Cesium,this.viewer,this.materialManager,this.aggregator,this.cardPool))}removeLayer(t){const e=this.layerMap.get(t);e&&(e.clearAllGroups(),this.layerMap.delete(t))}getLayer(t){return this.layerMap.get(t)}async addGroupsToLayer(t,e){const i=this.layerMap.get(t);i&&(i.addGroups(e),this.aggregator.refresh())}updateGroupToLayer(t,e){const i=this.layerMap.get(t);i&&(i.updateGroups(e),this.aggregator.refresh())}setGroupVisible(t,e,i){var n;(n=this.layerMap.get(t))==null||n.setGroupVisible(e,i)}removeGroup(t,e){var i;(i=this.layerMap.get(t))==null||i.removeGroup(e)}removeGroups(t,e){var i;(i=this.layerMap.get(t))==null||i.removeGroups(e)}}function _n(a){const t=[];return a.features.forEach((e,i)=>{if(e.geometry&&e.properties){const n=e.geometry,s=e.properties,o={id:s.id||`${Date.now()}`,show:!0,zIndex:s.zIndex||1,name:`${s.layer}_${i}`||"",billboard:[],polyline:[],wall:[],polygon:[],card:s.card||null};switch(n.type){case"Point":o.billboard.push({position:n.coordinates,options:s,name:`${s.layer}_${i}`});break;case"LineString":o.polyline.push({positions:n.coordinates,theme:s.theme||"default"});break;case"Polygon":o.polygon.push({hierarchy:n.coordinates[0],theme:s.theme||"default"});break;case"MultiLineString":n.coordinates.forEach(r=>{o.polyline.push({positions:r})});break;case"MultiPolygon":n.coordinates.forEach(r=>{o.polygon.push({hierarchy:r[0]})});break;case"GeometryCollection":n.geometries.forEach(r=>{r.type==="Point"?o.billboard.push({position:r.coordinates}):r.type==="LineString"?o.polyline.push({positions:r.coordinates}):r.type==="Polygon"&&o.polygon.push({hierarchy:r.coordinates[0]})});break;default:console.warn(`Unsupported geometry type: ${n.type}`);break}t.push(o)}}),t}class xn{constructor(t){h(this,"Cesium");h(this,"viewer");h(this,"layerMap");h(this,"hideLayerMap");h(this,"entityLayerManager");h(this,"PrimitiveThemeMap");h(this,"materialManager");let{Cesium:e,viewer:i,materialManager:n,entityLayerManager:s}=t;this.Cesium=e,this.viewer=i,this.layerMap=new Map,this.PrimitiveThemeMap=new Map,this.hideLayerMap=new Map,this.materialManager=n,this.entityLayerManager=s}createGeometryInstance(t){let e;return t.category==="polyline"&&t.positions?e=this.createPolyline(t):t.category==="polygon"&&t.hierarchy&&(e=this.createPolygon(t)),e}carateThemePrimitive(t){let e=Oe(t),i=this.PrimitiveThemeMap.get(e.theme);if(!i){this.initTheme(e);let n=this.createAppearance(e);i={Primitive:null,ids:new Map,appearance:n,geometryInstances:new Map},this.PrimitiveThemeMap.set(e.theme,i)}return i}initTheme(t){var n,s,o,r,l,c,d,u,m,g,p,f;let e=this.materialManager,i=this.Cesium;if(t.category=="polyline"){const w=((s=(n=t.properties)==null?void 0:n.lineType)==null?void 0:s.pattern)&&((r=(o=t.properties)==null?void 0:o.lineType)==null?void 0:r.patternLength);let y="";if(w){const v=((c=(l=t.properties)==null?void 0:l.lineType)==null?void 0:c.pattern)||[.25,-.125],C=((u=(d=t.properties)==null?void 0:d.lineType)==null?void 0:u.patternLength)||.375;let b=this.convertCadPatternToCesiumDash(v,C);y=`DashedLineMaterial_pattern_${b.dashPattern}_dashLength_${b.dashLength}_color_${(m=t.properties)==null?void 0:m.color}`,e.has(y)||e.register({themeKey:y,material:i.Material.fromType("PolylineDash",{color:i.Color.fromCssColorString(t.properties.color||"#FFFFFF").withAlpha(.8),dashLength:b.dashLength,dashPattern:b.dashPattern})})}else y=`LineMaterial_color_${(g=t.properties)==null?void 0:g.color}`,e.has(y)||e.register({themeKey:y,material:i.Material.fromType("Color",{color:i.Color.fromCssColorString(t.properties.color||"#FFFFFF").withAlpha(.8)})})}else if(t.category=="polygon"){let w=`polygonMaterial_color_${(p=t.properties)==null?void 0:p.color}`;e.has(w)||e.register({themeKey:w,material:i.Material.fromType("Color",{color:i.Color.fromCssColorString(((f=t.properties)==null?void 0:f.color)||"#FFFFFF").withAlpha(.8)})})}}convertCadPatternToCesiumDash(t,e){const n=e/16;let s=[],o=0;for(let l of t){const c=Math.floor(Math.abs(l)/n),d=l>=0?1:0;for(let u=0;u<c&&(s.push(d),o++,!(o>=16));u++);if(o>=16)break}for(;s.length<16;)s.push(0);s.length>16&&(s.length=16);let r=0;for(let l=0;l<16;l++)r=r<<1|s[l];return{dashPattern:r,dashLength:e}}async processBatch(t){const e=new Map;t.forEach(i=>{let{layerId:n,dataList:s}=i;Oe(s).forEach(r=>{let l=this.createGeometryInstance(r);if(l){let c=this.carateThemePrimitive(r);c.ids.set(r.id,r),c.geometryInstances.set(r.id,l);const d=this.layerMap.get(n);if(d)d.set(r.id,r);else{let u=new Map;this.layerMap.set(n,u),u.set(r.id,r)}e.set(r.theme,r)}})}),e.forEach(i=>{this.updatePrimitive(i)})}createPolyline(t){const e=Array.isArray(t.positions[0])?t.positions.flat():t.positions;return new this.Cesium.GeometryInstance({id:t.id,geometry:new this.Cesium.GroundPolylineGeometry({positions:this.Cesium.Cartesian3.fromDegreesArrayHeights(e),width:Math.max(t.width||2,2)})})}createPolygon(t){var o;const e=Array.isArray(t.hierarchy[0])?t.hierarchy.flat():t.hierarchy,i=this.Cesium.Cartesian3.fromDegreesArrayHeights(e),n=((o=t.holes)==null?void 0:o.map(r=>{let l=Array.isArray(r[0])?r.flat():r,c=this.Cesium.Cartesian3.fromDegreesArrayHeights(l.flat());return new this.Cesium.PolygonHierarchy(c)}))||[],s=new this.Cesium.PolygonHierarchy(i,n);return new this.Cesium.GeometryInstance({id:t.id,geometry:new this.Cesium.PolygonGeometry({polygonHierarchy:s})})}getMaterial(t){let e=this.materialManager.get({themeKey:t.theme,options:t});return e||(e=this.Cesium.Material.fromType("Color",{color:new this.Cesium.Color(1,0,0,1)})),e}updateGeometryInstance(t){let e=Oe(t);const i=this.layerMap.get(e.layerId);if(!i){console.warn(`没有找到图层 ${e.layerId}`);return}let n=i.get(e.id);if(i.set(e.id,e),!n){console.warn(`没有找到图元 ${e.id} 在图层 ${e.layerId} 中`);return}if(n.theme!==e.theme){let o=this.PrimitiveThemeMap.get(n.theme);o==null||o.geometryInstances.delete(e.id),o==null||o.ids.delete(e.id),this.updatePrimitive(n)}let s=this.carateThemePrimitive(e);if(s){const o=this.createGeometryInstance(e);s.geometryInstances.set(e.id,o),s.ids.set(e.id,e),this.updatePrimitive(e)}}deleteGeometryInstance(t){let e=new Set;t.forEach(i=>{let{layerId:n,ids:s}=i;const o=this.layerMap.get(n);if(!o){console.warn(`没有找到图层 ${n}`);return}s.forEach(r=>{let l=o.get(r);if(!l){console.warn(`没有找到图元 ${r} 在图层 ${n} 中`);return}let c=this.PrimitiveThemeMap.get(l.theme);c&&(c.geometryInstances.delete(l.id),c.ids.delete(l.id),e.add(l))})}),Array.from(e.values()).forEach(i=>{this.updatePrimitive(i)})}addGeometryInstance(t){let e=Oe(t);const i=this.layerMap.get(e.layerId);if(!i){console.warn(`没有找到图层 ${e.layerId}`);return}if(i.get(e.id)){console.warn(`图元 ${e.id} 已经存在图层 ${e.layerId} 中`);return}i.set(e.id,e);let s=this.carateThemePrimitive(e);if(s){const o=this.createGeometryInstance(e);s.geometryInstances.set(e.id,o),s.ids.set(e.id,e),this.updatePrimitive(e)}}createAppearance(t){let e=this.getMaterial({theme:t.theme}),i;return t.category==="polyline"?i=new this.Cesium.PolylineMaterialAppearance({material:e,translucent:!0}):t.category==="polygon"&&(i=new this.Cesium.MaterialAppearance({material:e,translucent:!0})),i}updatePrimitive(t){const e=this.PrimitiveThemeMap.get(t.theme);if(!e)return;e.Primitive&&(this.viewer.scene.primitives.remove(e.Primitive),e.Primitive=null);let n=Array.from(e.geometryInstances,([s,o])=>({key:s,value:o})).filter(s=>!Array.from(this.hideLayerMap.values()).some(o=>o.has(s.key))).map(s=>s.value);n.length<=0||(t.category==="polyline"?(e.Primitive=new this.Cesium.GroundPolylinePrimitive({geometryInstances:n,appearance:e.appearance}),this.viewer.scene.primitives.add(e.Primitive)):(e.Primitive=new this.Cesium.GroundPrimitive({geometryInstances:n,appearance:e.appearance}),this.viewer.scene.primitives.add(e.Primitive)))}hideByLayerAndId(t){let e=new Map;t.forEach(i=>{let{layerId:n,ids:s}=i,o=this.hideLayerMap.get(n);o||(o=new Set,this.hideLayerMap.set(n,o)),s.forEach(r=>{o.add(r);let l=this.getGeometryInstanceInfo(n,r);l&&e.set(l.theme,l)})}),Array.from(e.values()).forEach(i=>{this.updatePrimitive(i)})}showByLayerAndId(t){let e=new Map;t.forEach(i=>{let{layerId:n,ids:s}=i,o=this.hideLayerMap.get(n);o||(o=new Set,this.hideLayerMap.set(n,o)),s.forEach(r=>{o.delete(r);let l=this.getGeometryInstanceInfo(n,r);l&&e.set(l.theme,l)})}),Array.from(e.values()).forEach(i=>{this.updatePrimitive(i)})}hasGeometryInstance(t,e){const i=this.layerMap.get(t);if(!i)return!1;const n=i.get(e);if(!n)return!1;let s=this.PrimitiveThemeMap.get(n.theme);return!(!s||!s.geometryInstances.get(e))}getGeometryInstanceInfo(t,e){const i=this.layerMap.get(t);return i?i.get(e):null}focusOnGeometryInstance(t,e){const i=this.layerMap.get(t);if(!i){console.warn(`图层 ${t} 不存在`);return}const n=i.get(e);if(!n){console.warn(`没有找到图元 ${e} 在图层 ${t} 中`);return}let s=this.PrimitiveThemeMap.get(n.theme);if(!s){console.warn(`没有找到 ${e} 图元相关的Primitive`);return}const o=s.geometryInstances.get(e);if(!o){console.warn(`没有找到图元的几何体 ${e}`);return}const r=o.geometry,l=r._positions||r._polygonHierarchy.positions;if(l&&l.length>0){let c=l[0].x,d=l[0].y,u=l[0].z,m=l[0].x,g=l[0].y,p=l[0].z;l.forEach(C=>{c=Math.min(c,C.x),d=Math.min(d,C.y),u=Math.min(u,C.z),m=Math.max(m,C.x),g=Math.max(g,C.y),p=Math.max(p,C.z)});const f=new this.Cesium.Cartesian3((c+m)/2,(d+g)/2,(u+p)/2),y=new this.Cesium.Cartesian3(m-c,g-d,p-u).z,v=Math.abs(y||1)*1.5;this.viewer.camera.flyTo({destination:f,duration:2,complete:()=>{console.log(`已定位到图元 ${e}`)},offset:new this.Cesium.Cartesian3(0,0,v)})}else console.warn(`无法获取图元 ${e} 的顶点信息`)}}class Ye{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"positions",[]);h(this,"tempPoints",[]);h(this,"segmentEntities",[]);h(this,"segmentLabelIds",[]);h(this,"previewEntity",null);h(this,"previewGroundEntity",null);h(this,"hoverPos",null);h(this,"htmlLabelPool",null);h(this,"totalLabelId",null);h(this,"previewLabelId",null);h(this,"labelEntity",null);h(this,"firstHeight",null);h(this,"groundLineEntities",[]);h(this,"previewPos",null);h(this,"previewGroundPos",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const n=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,n),this.htmlLabelPool.registerTheme("measure-horizontal-total",{createElement:(s,o)=>{var r;s.innerHTML=String(((r=o==null?void 0:o.data)==null?void 0:r.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-horizontal-seg",{createElement:(s,o)=>{var r;s.innerHTML=String(((r=o==null?void 0:o.data)==null?void 0:r.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var f,w,y,v;const s=i.scene.pickPosition(n.position);if(!s)return;const o=e.Cartographic.fromCartesian(s),r=e.Math.toDegrees(o.longitude),l=e.Math.toDegrees(o.latitude);this.positions.length===0&&(this.firstHeight=o.height||0);const c=e.Cartesian3.fromDegrees(r,l,this.firstHeight||0);this.positions.push(c);const d=i.entities.add({position:c,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(d);const u=i.scene.globe.getHeight(new e.Cartographic(o.longitude,o.latitude,0))||0,m=e.Cartesian3.fromDegrees(r,l,u),g=((w=(f=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:w.call(f,.9))||e.Color.RED,p=i.entities.add({polyline:{positions:[m,c],width:t.width||3,material:new e.PolylineDashMaterialProperty({color:g,dashLength:12,dashPattern:255})}});if(this.groundLineEntities.push(p),this.positions.length>=2){const C=this.positions[this.positions.length-2],b=this.positions[this.positions.length-1],M=e.Cartographic.fromCartesian(C),P=e.Cartographic.fromCartesian(b),L=i.entities.add({polyline:{positions:[C,b],width:t.width||3,material:t.lineColor||t.color||e.Color.YELLOW,depthFailMaterial:new e.PolylineDashMaterialProperty({color:((v=(y=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:v.call(y,.9))||e.Color.RED,dashLength:12,dashPattern:255})}});this.segmentEntities.push(L);const I=new e.EllipsoidGeodesic(M,P).surfaceDistance,A=new e.Cartesian3((C.x+b.x)/2,(C.y+b.y)/2,(C.z+b.z)/2),x=e.Cartographic.fromCartesian(A),T=`measure_horizontal_seg_${this.segmentLabelIds.length}_${Date.now()}`;this.segmentLabelIds.push(T),this.htmlLabelPool.add({text:`${I.toFixed(2)} m`},{id:T,lon:e.Math.toDegrees(x.longitude),lat:e.Math.toDegrees(x.latitude),height:x.height||this.firstHeight||0,theme:"measure-horizontal-seg",show:!0})}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(()=>{var c;if(this.positions.length<2){this.stop();return}this.stop(),this.previewLabelId&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.hoverPos&&(this.hoverPos=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewGroundEntity&&(this.viewer.entities.remove(this.previewGroundEntity),this.previewGroundEntity=null);let n=0;for(let d=1;d<this.positions.length;d++){const u=this.positions[d-1],m=this.positions[d],g=e.Cartographic.fromCartesian(u),p=e.Cartographic.fromCartesian(m),f=new e.EllipsoidGeodesic(g,p);n+=f.surfaceDistance}const s=this.positions[this.positions.length-1],o=e.Cartographic.fromCartesian(s),r=this.totalLabelId||`measure_horizontal_total_${Date.now()}`;this.totalLabelId=r,this.htmlLabelPool.add({text:`${n.toFixed(2)} m`},{id:r,lon:e.Math.toDegrees(o.longitude),lat:e.Math.toDegrees(o.latitude),height:o.height||this.firstHeight||0,theme:"measure-horizontal-total",show:!0}),this.labelEntity=this.totalLabelId;const l={entity:this.segmentEntities,label:this.labelEntity,segmentLabels:this.segmentLabelIds,positions:this.positions,distance:n,clear:()=>this.clear()};(c=t.onComplete)==null||c.call(t,l)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK),this.handler.setInputAction(n=>{var M,P,L,E;if(this.positions.length===0)return;const s=i.scene.pickPosition(n.endPosition);if(!s)return;this.hoverPos=s;const o=e.Cartographic.fromCartesian(s),r=e.Math.toDegrees(o.longitude),l=e.Math.toDegrees(o.latitude),c=e.Cartesian3.fromDegrees(r,l,this.firstHeight||0);this.previewPos=c;const d=i.scene.globe.getHeight(new e.Cartographic(o.longitude,o.latitude,0))||0,u=e.Cartesian3.fromDegrees(r,l,d);this.previewGroundPos=u;const m=this.positions[this.positions.length-1],g=e.Cartographic.fromCartesian(m),p=e.Cartographic.fromCartesian(c),w=new e.EllipsoidGeodesic(g,p).surfaceDistance,y=new e.Cartesian3((m.x+c.x)/2,(m.y+c.y)/2,(m.z+c.z)/2),v=e.Cartographic.fromCartesian(y),C=this.previewLabelId||"measure_horizontal_preview";this.previewLabelId=C,this.htmlLabelPool.add({text:`${w.toFixed(2)} m`},{id:C,lon:e.Math.toDegrees(v.longitude),lat:e.Math.toDegrees(v.latitude),height:v.height||this.firstHeight||0,theme:"measure-horizontal-seg",show:!0});const b=((P=(M=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:P.call(M,.9))||e.Color.RED;this.previewGroundEntity||(this.previewGroundEntity=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewPos||!this.previewGroundPos?[]:[this.previewGroundPos,this.previewPos],!1),width:t.width||3,material:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}})),this.previewEntity||(this.previewEntity=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewPos||!this.positions.length?[]:[this.positions[this.positions.length-1],this.previewPos],!1),width:t.width||3,material:t.lineColor||t.color||e.Color.YELLOW,depthFailMaterial:new e.PolylineDashMaterialProperty({color:((E=(L=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:E.call(L,.9))||e.Color.RED,dashLength:12,dashPattern:255})}}))},e.ScreenSpaceEventType.MOUSE_MOVE)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){this.stop(),this.segmentEntities.forEach(t=>this.viewer.entities.remove(t)),this.segmentEntities=[],this.groundLineEntities.forEach(t=>this.viewer.entities.remove(t)),this.groundLineEntities=[],this.tempPoints.forEach(t=>this.viewer.entities.remove(t)),this.tempPoints=[],this.totalLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.totalLabelId]),this.totalLabelId=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewGroundEntity&&(this.viewer.entities.remove(this.previewGroundEntity),this.previewGroundEntity=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.segmentLabelIds.length&&this.htmlLabelPool&&this.htmlLabelPool.removeByIds(this.segmentLabelIds.slice()),this.segmentLabelIds=[],this.positions=[],this.hoverPos=null,this.labelEntity=null,this.firstHeight=null,this.previewPos=null,this.previewGroundPos=null}rehydrate(t,e){var p,f;const i=this.Cesium,n=this.viewer,s=t.options||{},o=s.lineColor||s.color||i.Color.YELLOW,r=((f=(p=s.dashLineColor||s.lineColor||s.color||i.Color.RED).withAlpha)==null?void 0:f.call(p,.9))||i.Color.RED,l=s.width||3,c=(t.positions||[]).map(w=>new i.Cartesian3(w[0],w[1],w[2]));if(!c.length)return;if(!this.htmlLabelPool){const w=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,n,w),this.htmlLabelPool.registerTheme("measure-horizontal-total",{createElement:(y,v)=>{var C;y.innerHTML=String(((C=v==null?void 0:v.data)==null?void 0:C.text)||""),y.style.background="rgba(0,0,0,0.6)",y.style.color="#fff",y.style.font="14px sans-serif",y.style.padding="4px 6px",y.style.borderRadius="4px",y.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-horizontal-seg",{createElement:(y,v)=>{var C;y.innerHTML=String(((C=v==null?void 0:v.data)==null?void 0:C.text)||""),y.style.background="rgba(0,0,0,0.6)",y.style.color="#fff",y.style.font="14px sans-serif",y.style.padding="4px 6px",y.style.borderRadius="4px",y.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}for(const w of c){const y=n.entities.add({position:w,point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(y);const v=i.Cartographic.fromCartesian(w),C=i.Math.toDegrees(v.longitude),b=i.Math.toDegrees(v.latitude),M=n.scene.globe.getHeight(new i.Cartographic(v.longitude,v.latitude,0))||0,P=i.Cartesian3.fromDegrees(C,b,M),L=n.entities.add({polyline:{positions:[P,w],width:l,material:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}});this.groundLineEntities.push(L)}for(let w=1;w<c.length;w++){const y=c[w-1],v=c[w],C=n.entities.add({polyline:{positions:[y,v],width:l,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}});this.segmentEntities.push(C);const b=i.Cartographic.fromCartesian(y),M=i.Cartographic.fromCartesian(v),L=new i.EllipsoidGeodesic(b,M).surfaceDistance,E=new i.Cartesian3((y.x+v.x)/2,(y.y+v.y)/2,(y.z+v.z)/2),I=i.Cartographic.fromCartesian(E),A=t.id+`_seg_${w-1}`;this.segmentLabelIds.push(A),this.htmlLabelPool.add({text:`${L.toFixed(2)} m`},{id:A,lon:i.Math.toDegrees(I.longitude),lat:i.Math.toDegrees(I.latitude),height:I.height||0,theme:"measure-horizontal-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})}let d=0;for(let w=1;w<c.length;w++){const y=i.Cartographic.fromCartesian(c[w-1]),v=i.Cartographic.fromCartesian(c[w]),C=new i.EllipsoidGeodesic(y,v);d+=C.surfaceDistance}const u=c[c.length-1],m=i.Cartographic.fromCartesian(u),g=t.id+"_total";this.totalLabelId=g,this.htmlLabelPool.add({text:`${d.toFixed(2)} m`},{id:g,lon:i.Math.toDegrees(m.longitude),lat:i.Math.toDegrees(m.latitude),height:m.height||0,theme:"measure-horizontal-total",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})}}class Ve{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"entity",null);h(this,"labelEntity",null);h(this,"positions",[]);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);h(this,"previewLabelId",null);h(this,"baseCarto",null);h(this,"baseUp",null);h(this,"tempPoints",[]);h(this,"previewPointEntity",null);h(this,"previewEntity",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const n=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,n),this.htmlLabelPool.registerTheme("measure-vertical",{createElement:(s,o)=>{var r;s.innerHTML=String(((r=o==null?void 0:o.data)==null?void 0:r.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var r,l,c,d,u;const s=i.camera.getPickRay(n.position);let o=s?i.scene.globe.pick(s,i.scene):null;if(o||(o=i.camera.pickEllipsoid(n.position,e.Ellipsoid.WGS84)),o||(o=i.scene.pickPosition(n.position)),!!o)if(this.positions.length===0){const m=e.Cartographic.fromCartesian(o);this.baseCarto=new e.Cartographic(m.longitude,m.latitude,0);const g=e.Ellipsoid.WGS84.cartographicToCartesian(this.baseCarto);this.baseUp=e.Ellipsoid.WGS84.geodeticSurfaceNormalCartographic(this.baseCarto),this.positions.push(g);const p=i.entities.add({position:g,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(p);const f=t.lineColor||t.color||e.Color.CYAN,w=((l=(r=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:l.call(r,.9))||e.Color.RED;this.previewEntity=i.entities.add({polyline:{positions:[g,g],width:t.width||3,material:f,depthFailMaterial:new e.PolylineDashMaterialProperty({color:w,dashLength:12,dashPattern:255})}})}else{if(!this.baseCarto||!this.baseUp)return;const m=this.positions[0],g=i.camera.getPickRay(n.position);if(!g)return;const p=g.origin,f=e.Cartesian3.normalize(g.direction,new e.Cartesian3),w=m,y=this.baseUp,v=e.Cartesian3.subtract(p,w,new e.Cartesian3),C=e.Cartesian3.dot(f,f),b=-e.Cartesian3.dot(f,y),M=e.Cartesian3.dot(y,y),P=-e.Cartesian3.dot(f,v),L=e.Cartesian3.dot(y,v),E=C*M-b*b;if(Math.abs(E)<1e-6)return;const I=(C*L-b*P)/E,A=e.Cartesian3.add(w,e.Cartesian3.multiplyByScalar(y,I,new e.Cartesian3),new e.Cartesian3);this.positions[1]=A,this.stop(),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewPointEntity&&(this.viewer.entities.remove(this.previewPointEntity),this.previewPointEntity=null);const x=t.lineColor||t.color||e.Color.CYAN,T=((d=(c=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:d.call(c,.9))||e.Color.RED;this.entity=i.entities.add({polyline:{positions:[m,A],width:t.width||3,material:x,depthFailMaterial:new e.PolylineDashMaterialProperty({color:T,dashLength:12,dashPattern:255})}});const $=i.entities.add({position:A,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push($);const D=this.baseCarto,k=e.Cartographic.fromCartesian(A),_=Math.abs((k.height||0)-(D.height||0)),O=new e.Cartesian3((this.positions[0].x+this.positions[1].x)/2,(this.positions[0].y+this.positions[1].y)/2,(this.positions[0].z+this.positions[1].z)/2),R=e.Cartographic.fromCartesian(O);this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null);const G=this.htmlLabelId||`measure_vertical_${Date.now()}`;this.htmlLabelId=G,this.htmlLabelPool.add({text:`${_.toFixed(2)} m`},{id:G,lon:e.Math.toDegrees(R.longitude),lat:e.Math.toDegrees(R.latitude),height:R.height||0,theme:"measure-vertical",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const B={entity:this.entity,label:this.labelEntity,positions:this.positions,vertical:_,clear:()=>this.clear()};(u=t.onComplete)==null||u.call(t,B)}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(n=>{var A,x;if(this.positions.length<1)return;if(!this.baseCarto||!this.baseUp){const T=e.Cartographic.fromCartesian(this.positions[0]);this.baseCarto=new e.Cartographic(T.longitude,T.latitude,T.height||0),this.baseUp=e.Ellipsoid.WGS84.geodeticSurfaceNormalCartographic(this.baseCarto)}const s=this.positions[0],o=i.camera.getPickRay(n.endPosition);if(!o)return;const r=o.origin,l=e.Cartesian3.normalize(o.direction,new e.Cartesian3),c=s,d=this.baseUp,u=e.Cartesian3.subtract(r,c,new e.Cartesian3),m=e.Cartesian3.dot(l,l),g=-e.Cartesian3.dot(l,d),p=e.Cartesian3.dot(d,d),f=-e.Cartesian3.dot(l,u),w=e.Cartesian3.dot(d,u),y=m*p-g*g;if(Math.abs(y)<1e-6)return;const v=(m*w-g*f)/y,C=e.Cartesian3.add(c,e.Cartesian3.multiplyByScalar(d,v,new e.Cartesian3),new e.Cartesian3);if(this.positions[1]=C,!this.previewEntity){const T=t.lineColor||t.color||e.Color.CYAN,$=((x=(A=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:x.call(A,.9))||e.Color.RED;this.previewEntity=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>this.positions.length<2?[]:[this.positions[0],this.positions[1]],!1),width:t.width||3,material:T,depthFailMaterial:new e.PolylineDashMaterialProperty({color:$,dashLength:12,dashPattern:255})}})}this.previewPointEntity?this.previewPointEntity.position=C:this.previewPointEntity=i.entities.add({position:C,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});const b=this.baseCarto,M=e.Cartographic.fromCartesian(C),P=Math.abs((M.height||0)-(b.height||0)),L=new e.Cartesian3((this.positions[0].x+C.x)/2,(this.positions[0].y+C.y)/2,(this.positions[0].z+C.z)/2),E=e.Cartographic.fromCartesian(L),I=this.previewLabelId||"measure_vertical_preview";this.previewLabelId=I,this.htmlLabelPool.add({text:`${P.toFixed(2)} m`},{id:I,lon:e.Math.toDegrees(E.longitude),lat:e.Math.toDegrees(E.latitude),height:E.height||0,theme:"measure-vertical",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})},e.ScreenSpaceEventType.MOUSE_MOVE)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){this.stop(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.labelEntity&&(this.viewer.entities.remove(this.labelEntity),this.labelEntity=null),this.tempPoints.forEach(t=>this.viewer.entities.remove(t)),this.tempPoints=[],this.previewPointEntity&&(this.viewer.entities.remove(this.previewPointEntity),this.previewPointEntity=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.htmlLabelPool&&this.htmlLabelId&&(this.htmlLabelPool.removeByIds([this.htmlLabelId]),this.htmlLabelId=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.positions=[]}rehydrate(t,e){var b,M;const i=this.Cesium,n=this.viewer,s=t.options||{},o=s.lineColor||s.color||i.Color.CYAN,r=((M=(b=s.dashLineColor||s.lineColor||s.color||i.Color.RED).withAlpha)==null?void 0:M.call(b,.9))||i.Color.RED,l=s.width||3,c=(t.positions||[]).map(P=>new i.Cartesian3(P[0],P[1],P[2]));if(c.length<2)return;if(!this.htmlLabelPool){const P=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,n,P),this.htmlLabelPool.registerTheme("measure-vertical",{createElement:(L,E)=>{var I;L.innerHTML=String(((I=E==null?void 0:E.data)==null?void 0:I.text)||""),L.style.background="rgba(0,0,0,0.6)",L.style.color="#fff",L.style.font="14px sans-serif",L.style.padding="4px 6px",L.style.borderRadius="4px",L.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}const d=c[0],u=c[1],m=n.entities.add({position:d,point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),g=n.entities.add({position:u,point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(m),this.tempPoints.push(g),this.entity=n.entities.add({polyline:{positions:[d,u],width:l,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}});const p=i.Cartographic.fromCartesian(d),f=i.Cartographic.fromCartesian(u),w=Math.abs((f.height||0)-(p.height||0)),y=new i.Cartesian3((d.x+u.x)/2,(d.y+u.y)/2,(d.z+u.z)/2),v=i.Cartographic.fromCartesian(y),C=t.id+"_label";this.htmlLabelId=C,this.htmlLabelPool.add({text:`${w.toFixed(2)} m`},{id:C,lon:i.Math.toDegrees(v.longitude),lat:i.Math.toDegrees(v.latitude),height:v.height||0,theme:"measure-vertical",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})}}class We{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"positions",[]);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);h(this,"segmentEntities",[]);h(this,"angleMarkerEntities",[]);h(this,"pointEntities",[]);h(this,"segmentLabelIds",[]);h(this,"angleLabelIds",[]);h(this,"previewLabelId",null);h(this,"previewSegmentEntities",[]);h(this,"previewAngleMarkerEntities",[]);h(this,"previewPointEntity",null);h(this,"previewLow",null);h(this,"previewHigh",null);h(this,"previewThird",null);h(this,"previewMarkerP1",null);h(this,"previewMarkerP2",null);h(this,"previewMarkerCorner",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const n=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,n),this.htmlLabelPool.registerTheme("measure-triangle",{createElement:(s,o)=>{var r;s.innerHTML=String(((r=o==null?void 0:o.data)==null?void 0:r.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-triangle-seg",{createElement:(s,o)=>{var r;s.innerHTML=String(((r=o==null?void 0:o.data)==null?void 0:r.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-triangle-angle",{createElement:(s,o)=>{var r;s.innerHTML=String(((r=o==null?void 0:o.data)==null?void 0:r.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var r,l,c;const s=i.scene.pickPosition(n.position);if(!s)return;this.positions.push(s);const o=i.entities.add({position:s,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});if(this.pointEntities.push(o),this.positions.length===2){this.stop(),this.previewSegmentEntities.forEach(J=>i.entities.remove(J)),this.previewSegmentEntities=[],this.previewAngleMarkerEntities.forEach(J=>i.entities.remove(J)),this.previewAngleMarkerEntities=[],this.previewPointEntity&&(i.entities.remove(this.previewPointEntity),this.previewPointEntity=null);const d=e.Cartographic.fromCartesian(this.positions[0]),u=e.Cartographic.fromCartesian(this.positions[1]),m=d.height||0,g=u.height||0,p=m<=g?this.positions[0]:this.positions[1],f=m>g?this.positions[0]:this.positions[1],w=e.Cartographic.fromCartesian(p);e.Cartographic.fromCartesian(f);const y=Math.max(m,g),v=e.Cartesian3.fromDegrees(e.Math.toDegrees(w.longitude),e.Math.toDegrees(w.latitude),y),C=t.lineColor||t.color||e.Color.YELLOW,b=((l=(r=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:l.call(r,.9))||e.Color.RED,M=i.entities.add({polyline:{positions:[p,v],width:t.width||3,material:C,depthFailMaterial:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}}),P=i.entities.add({polyline:{positions:[v,f],width:t.width||3,material:C,depthFailMaterial:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}}),L=i.entities.add({polyline:{positions:[p,f],width:t.width||3,material:C,depthFailMaterial:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}});this.segmentEntities.push(M,P,L);const E=e.Cartesian3.distance(p,v),I=e.Cartesian3.distance(v,f),A=e.Cartesian3.distance(p,f),x=new e.Cartesian3((p.x+v.x)/2,(p.y+v.y)/2,(p.z+v.z)/2),T=new e.Cartesian3((v.x+f.x)/2,(v.y+f.y)/2,(v.z+f.z)/2),$=new e.Cartesian3((p.x+f.x)/2,(p.y+f.y)/2,(p.z+f.z)/2),D=e.Cartographic.fromCartesian(x),k=e.Cartographic.fromCartesian(T),_=e.Cartographic.fromCartesian($),O="measure_triangle_seg_v",R="measure_triangle_seg_h",G="measure_triangle_seg_hyp";this.segmentLabelIds=[O,R,G],this.htmlLabelPool.add({text:`${E.toFixed(2)} m`},{id:O,lon:e.Math.toDegrees(D.longitude),lat:e.Math.toDegrees(D.latitude),height:D.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${I.toFixed(2)} m`},{id:R,lon:e.Math.toDegrees(k.longitude),lat:e.Math.toDegrees(k.latitude),height:k.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${A.toFixed(2)} m`},{id:G,lon:e.Math.toDegrees(_.longitude),lat:e.Math.toDegrees(_.latitude),height:_.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const B=e.Cartesian3.subtract(f,p,new e.Cartesian3),j=e.Cartesian3.subtract(v,p,new e.Cartesian3),X=e.Cartesian3.subtract(v,f,new e.Cartesian3),Q=e.Cartesian3.subtract(p,f,new e.Cartesian3),ae=e.Cartesian3.dot(B,j),we=Math.sqrt(e.Cartesian3.dot(B,B))*Math.sqrt(e.Cartesian3.dot(j,j)),ve=e.Cartesian3.dot(X,Q),Te=Math.sqrt(e.Cartesian3.dot(X,X))*Math.sqrt(e.Cartesian3.dot(Q,Q)),Y=Math.acos(Math.min(Math.max(ae/(we||1),-1),1)),ue=Math.acos(Math.min(Math.max(ve/(Te||1),-1),1)),oe=e.Cartographic.fromCartesian(p),W=e.Cartographic.fromCartesian(f),Z="measure_triangle_angle_a",le="measure_triangle_angle_b";this.angleLabelIds=[Z,le],this.htmlLabelPool.add({text:`${(Y*180/Math.PI).toFixed(2)}°`},{id:Z,lon:e.Math.toDegrees(oe.longitude),lat:e.Math.toDegrees(oe.latitude),height:oe.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${(ue*180/Math.PI).toFixed(2)}°`},{id:le,lon:e.Math.toDegrees(W.longitude),lat:e.Math.toDegrees(W.latitude),height:W.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const Ce=Math.max(.01,Math.min(.5,t.angleMarkerRatio??.2)),U=Math.min(E,I)*Ce;if(E>.001&&I>.001){const J=e.Cartesian3.normalize(e.Cartesian3.subtract(p,v,new e.Cartesian3),new e.Cartesian3),he=e.Cartesian3.normalize(e.Cartesian3.subtract(f,v,new e.Cartesian3),new e.Cartesian3),ee=new e.Cartesian3(v.x+J.x*U,v.y+J.y*U,v.z+J.z*U),F=new e.Cartesian3(v.x+he.x*U,v.y+he.y*U,v.z+he.z*U),q=new e.Cartesian3(v.x+J.x*U+he.x*U,v.y+J.y*U+he.y*U,v.z+J.z*U+he.z*U),ie=i.entities.add({polyline:{positions:[ee,q],width:t.width||3,material:C,depthFailMaterial:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}}),ke=i.entities.add({polyline:{positions:[F,q],width:t.width||3,material:C,depthFailMaterial:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}});this.angleMarkerEntities.push(ie,ke)}this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null);const K={entity:this.segmentEntities,positions:[p,f,v],lengths:{vertical:E,horizontal:I,hypotenuse:A},angles:{acuteA:Y,acuteB:ue},clear:()=>this.clear()};(c=t.onComplete)==null||c.call(t,K)}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(n=>{var ue,oe;if(this.positions.length!==1)return;const s=i.scene.pickPosition(n.endPosition);if(!s)return;const o=e.Cartographic.fromCartesian(this.positions[0]),r=e.Cartographic.fromCartesian(s),l=o.height||0,c=r.height||0,d=l<=c?this.positions[0]:s,u=l>c?this.positions[0]:s,m=e.Cartographic.fromCartesian(d),g=Math.max(l,c),p=e.Cartesian3.fromDegrees(this.Cesium.Math.toDegrees(m.longitude),this.Cesium.Math.toDegrees(m.latitude),g);this.previewLow=d,this.previewHigh=u,this.previewThird=p;const f=t.lineColor||t.color||e.Color.YELLOW,w=((oe=(ue=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:oe.call(ue,.9))||e.Color.RED;if(this.previewPointEntity?this.previewPointEntity.position=s:this.previewPointEntity=i.entities.add({position:s,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),!this.previewSegmentEntities.length){const W=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewLow||!this.previewThird?[]:[this.previewLow,this.previewThird],!1),width:t.width||3,material:f,depthFailMaterial:new e.PolylineDashMaterialProperty({color:w,dashLength:12,dashPattern:255})}}),Z=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewThird||!this.previewHigh?[]:[this.previewThird,this.previewHigh],!1),width:t.width||3,material:f,depthFailMaterial:new e.PolylineDashMaterialProperty({color:w,dashLength:12,dashPattern:255})}}),le=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewLow||!this.previewHigh?[]:[this.previewLow,this.previewHigh],!1),width:t.width||3,material:f,depthFailMaterial:new e.PolylineDashMaterialProperty({color:w,dashLength:12,dashPattern:255})}});this.previewSegmentEntities.push(W,Z,le)}const y=e.Cartesian3.distance(d,p),v=e.Cartesian3.distance(p,u),C=e.Cartesian3.distance(d,u),b=e.Cartesian3.subtract(u,d,new e.Cartesian3),M=e.Cartesian3.subtract(p,d,new e.Cartesian3),P=e.Cartesian3.subtract(p,u,new e.Cartesian3),L=e.Cartesian3.subtract(d,u,new e.Cartesian3),E=e.Cartesian3.dot(b,M),I=Math.sqrt(e.Cartesian3.dot(b,b))*Math.sqrt(e.Cartesian3.dot(M,M)),A=e.Cartesian3.dot(P,L),x=Math.sqrt(e.Cartesian3.dot(P,P))*Math.sqrt(e.Cartesian3.dot(L,L)),T=Math.acos(Math.min(Math.max(E/(I||1),-1),1)),$=Math.acos(Math.min(Math.max(A/(x||1),-1),1)),D=new e.Cartesian3((d.x+p.x)/2,(d.y+p.y)/2,(d.z+p.z)/2),k=new e.Cartesian3((p.x+u.x)/2,(p.y+u.y)/2,(p.z+u.z)/2),_=new e.Cartesian3((d.x+u.x)/2,(d.y+u.y)/2,(d.z+u.z)/2),O=e.Cartographic.fromCartesian(D),R=e.Cartographic.fromCartesian(k),G=e.Cartographic.fromCartesian(_),B=e.Cartographic.fromCartesian(d),j=e.Cartographic.fromCartesian(u),X="measure_triangle_seg_v",Q="measure_triangle_seg_h",ae="measure_triangle_seg_hyp",we="measure_triangle_angle_a",ve="measure_triangle_angle_b";this.segmentLabelIds.length===0&&(this.segmentLabelIds=[X,Q,ae]),this.angleLabelIds.length===0&&(this.angleLabelIds=[we,ve]),this.htmlLabelPool.add({text:`${y.toFixed(2)} m`},{id:X,lon:e.Math.toDegrees(O.longitude),lat:e.Math.toDegrees(O.latitude),height:O.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${v.toFixed(2)} m`},{id:Q,lon:e.Math.toDegrees(R.longitude),lat:e.Math.toDegrees(R.latitude),height:R.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${C.toFixed(2)} m`},{id:ae,lon:e.Math.toDegrees(G.longitude),lat:e.Math.toDegrees(G.latitude),height:G.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${(T*180/Math.PI).toFixed(2)}°`},{id:we,lon:e.Math.toDegrees(B.longitude),lat:e.Math.toDegrees(B.latitude),height:B.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${($*180/Math.PI).toFixed(2)}°`},{id:ve,lon:e.Math.toDegrees(j.longitude),lat:e.Math.toDegrees(j.latitude),height:j.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const Te=Math.max(.01,Math.min(.5,t.angleMarkerRatio??.2)),Y=Math.min(y,v)*Te;if(y>.001&&v>.001){const W=e.Cartesian3.normalize(e.Cartesian3.subtract(d,p,new e.Cartesian3),new e.Cartesian3),Z=e.Cartesian3.normalize(e.Cartesian3.subtract(u,p,new e.Cartesian3),new e.Cartesian3),le=new e.Cartesian3(p.x+W.x*Y,p.y+W.y*Y,p.z+W.z*Y),Ce=new e.Cartesian3(p.x+Z.x*Y,p.y+Z.y*Y,p.z+Z.z*Y),U=new e.Cartesian3(p.x+W.x*Y+Z.x*Y,p.y+W.y*Y+Z.y*Y,p.z+W.z*Y+Z.z*Y);if(this.previewMarkerP1=le,this.previewMarkerP2=Ce,this.previewMarkerCorner=U,!this.previewAngleMarkerEntities.length){const K=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewMarkerP1||!this.previewMarkerCorner?[]:[this.previewMarkerP1,this.previewMarkerCorner],!1),width:t.width||3,material:f,depthFailMaterial:new e.PolylineDashMaterialProperty({color:w,dashLength:12,dashPattern:255})}}),J=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewMarkerP2||!this.previewMarkerCorner?[]:[this.previewMarkerP2,this.previewMarkerCorner],!1),width:t.width||3,material:f,depthFailMaterial:new e.PolylineDashMaterialProperty({color:w,dashLength:12,dashPattern:255})}});this.previewAngleMarkerEntities.push(K,J)}}},e.ScreenSpaceEventType.MOUSE_MOVE)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){this.stop(),this.segmentEntities.forEach(t=>this.viewer.entities.remove(t)),this.segmentEntities=[],this.angleMarkerEntities.forEach(t=>this.viewer.entities.remove(t)),this.angleMarkerEntities=[],this.pointEntities.forEach(t=>this.viewer.entities.remove(t)),this.pointEntities=[],this.previewSegmentEntities.forEach(t=>this.viewer.entities.remove(t)),this.previewSegmentEntities=[],this.previewAngleMarkerEntities.forEach(t=>this.viewer.entities.remove(t)),this.previewAngleMarkerEntities=[],this.previewPointEntity&&(this.viewer.entities.remove(this.previewPointEntity),this.previewPointEntity=null),this.htmlLabelPool&&this.htmlLabelId&&(this.htmlLabelPool.removeByIds([this.htmlLabelId]),this.htmlLabelId=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.segmentLabelIds.length&&this.htmlLabelPool&&this.htmlLabelPool.removeByIds(this.segmentLabelIds.slice()),this.angleLabelIds.length&&this.htmlLabelPool&&this.htmlLabelPool.removeByIds(this.angleLabelIds.slice()),this.segmentLabelIds=[],this.angleLabelIds=[],this.positions=[]}rehydrate(t,e){var J,he;const i=this.Cesium,n=this.viewer,s=t.options||{},o=s.lineColor||s.color||i.Color.YELLOW,r=((he=(J=s.dashLineColor||s.lineColor||s.color||i.Color.RED).withAlpha)==null?void 0:he.call(J,.9))||i.Color.RED,l=s.width||3,c=(t.positions||[]).map(ee=>new i.Cartesian3(ee[0],ee[1],ee[2]));if(c.length<2)return;if(!this.htmlLabelPool){const ee=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,n,ee),this.htmlLabelPool.registerTheme("measure-triangle",{createElement:(F,q)=>{var ie;F.innerHTML=String(((ie=q==null?void 0:q.data)==null?void 0:ie.text)||""),F.style.background="rgba(0,0,0,0.6)",F.style.color="#fff",F.style.font="14px sans-serif",F.style.padding="4px 6px",F.style.borderRadius="4px",F.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-triangle-seg",{createElement:(F,q)=>{var ie;F.innerHTML=String(((ie=q==null?void 0:q.data)==null?void 0:ie.text)||""),F.style.background="rgba(0,0,0,0.6)",F.style.color="#fff",F.style.font="14px sans-serif",F.style.padding="4px 6px",F.style.borderRadius="4px",F.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-triangle-angle",{createElement:(F,q)=>{var ie;F.innerHTML=String(((ie=q==null?void 0:q.data)==null?void 0:ie.text)||""),F.style.background="rgba(0,0,0,0.6)",F.style.color="#fff",F.style.font="14px sans-serif",F.style.padding="4px 6px",F.style.borderRadius="4px",F.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}const d=i.Cartographic.fromCartesian(c[0]),u=i.Cartographic.fromCartesian(c[1]),m=d.height||0,g=u.height||0,p=m<=g?c[0]:c[1],f=m>g?c[0]:c[1],w=n.entities.add({position:p,point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),y=n.entities.add({position:f,point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.pointEntities.push(w,y);const v=i.Cartographic.fromCartesian(p),C=Math.max(m,g),b=i.Cartesian3.fromDegrees(i.Math.toDegrees(v.longitude),i.Math.toDegrees(v.latitude),C),M=n.entities.add({polyline:{positions:[p,b],width:l,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}}),P=n.entities.add({polyline:{positions:[b,f],width:l,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}}),L=n.entities.add({polyline:{positions:[p,f],width:l,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}});this.segmentEntities.push(M,P,L);const E=i.Cartesian3.distance(p,b),I=i.Cartesian3.distance(b,f),A=i.Cartesian3.distance(p,f),x=new i.Cartesian3((p.x+b.x)/2,(p.y+b.y)/2,(p.z+b.z)/2),T=new i.Cartesian3((b.x+f.x)/2,(b.y+f.y)/2,(b.z+f.z)/2),$=new i.Cartesian3((p.x+f.x)/2,(p.y+f.y)/2,(p.z+f.z)/2),D=i.Cartographic.fromCartesian(x),k=i.Cartographic.fromCartesian(T),_=i.Cartographic.fromCartesian($),O=t.id+"_tri_v",R=t.id+"_tri_h",G=t.id+"_tri_hyp";this.segmentLabelIds=[O,R,G],this.htmlLabelPool.add({text:`${E.toFixed(2)} m`},{id:O,lon:i.Math.toDegrees(D.longitude),lat:i.Math.toDegrees(D.latitude),height:D.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${I.toFixed(2)} m`},{id:R,lon:i.Math.toDegrees(k.longitude),lat:i.Math.toDegrees(k.latitude),height:k.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${A.toFixed(2)} m`},{id:G,lon:i.Math.toDegrees(_.longitude),lat:i.Math.toDegrees(_.latitude),height:_.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const B=i.Cartesian3.subtract(f,p,new i.Cartesian3),j=i.Cartesian3.subtract(b,p,new i.Cartesian3),X=i.Cartesian3.subtract(b,f,new i.Cartesian3),Q=i.Cartesian3.subtract(p,f,new i.Cartesian3),ae=i.Cartesian3.dot(B,j),we=Math.sqrt(i.Cartesian3.dot(B,B))*Math.sqrt(i.Cartesian3.dot(j,j)),ve=i.Cartesian3.dot(X,Q),Te=Math.sqrt(i.Cartesian3.dot(X,X))*Math.sqrt(i.Cartesian3.dot(Q,Q)),Y=Math.acos(Math.min(Math.max(ae/(we||1),-1),1)),ue=Math.acos(Math.min(Math.max(ve/(Te||1),-1),1)),oe=i.Cartographic.fromCartesian(p),W=i.Cartographic.fromCartesian(f),Z=s.labelText||{angle:"角度"},le=t.id+"_tri_angA",Ce=t.id+"_tri_angB";this.angleLabelIds=[le,Ce],this.htmlLabelPool.add({text:`${Z.angle}:${(Y*180/Math.PI).toFixed(2)}°`},{id:le,lon:i.Math.toDegrees(oe.longitude),lat:i.Math.toDegrees(oe.latitude),height:oe.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${Z.angle}:${(ue*180/Math.PI).toFixed(2)}°`},{id:Ce,lon:i.Math.toDegrees(W.longitude),lat:i.Math.toDegrees(W.latitude),height:W.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const U=Math.max(.01,Math.min(.5,s.angleMarkerRatio??.2)),K=Math.min(E,I)*U;if(E>.001&&I>.001){const ee=i.Cartesian3.normalize(i.Cartesian3.subtract(p,b,new i.Cartesian3),new i.Cartesian3),F=i.Cartesian3.normalize(i.Cartesian3.subtract(f,b,new i.Cartesian3),new i.Cartesian3),q=new i.Cartesian3(b.x+ee.x*K,b.y+ee.y*K,b.z+ee.z*K),ie=new i.Cartesian3(b.x+F.x*K,b.y+F.y*K,b.z+F.z*K),ke=new i.Cartesian3(b.x+ee.x*K+F.x*K,b.y+ee.y*K+F.y*K,b.z+ee.z*K+F.z*K),$n=n.entities.add({polyline:{positions:[q,ke],width:l,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}}),On=n.entities.add({polyline:{positions:[ie,ke],width:l,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}});this.angleMarkerEntities.push($n,On)}}}class Ue{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"entity",null);h(this,"labelEntity",null);h(this,"positions",[]);h(this,"tempPoints",[]);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);h(this,"previewEntity",null);h(this,"previewPos",null);h(this,"previewLabelId",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const n=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,n),this.htmlLabelPool.registerTheme("measure-space",{createElement:(s,o)=>{var r;s.innerHTML=String(((r=o==null?void 0:o.data)==null?void 0:r.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var r,l,c;const s=i.scene.pickPosition(n.position);if(!s)return;this.positions.push(s);const o=i.entities.add({position:s,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});if(this.tempPoints.push(o),this.positions.length===2){this.stop(),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null);const d=this.positions[0],u=this.positions[1],m=t.lineColor||t.color||e.Color.YELLOW,g=((l=(r=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:l.call(r,.9))||e.Color.RED;this.entity=i.entities.add({polyline:{positions:[d,u],width:t.width||3,material:m,depthFailMaterial:new e.PolylineDashMaterialProperty({color:g,dashLength:12,dashPattern:255})}});const p=e.Cartesian3.distance(d,u),f=u,w=e.Cartographic.fromCartesian(f),y=this.htmlLabelId||`measure_space_${Date.now()}`;this.htmlLabelId=y,this.htmlLabelPool.add({text:`${p.toFixed(2)} m`},{id:y,lon:e.Math.toDegrees(w.longitude),lat:e.Math.toDegrees(w.latitude),height:w.height||0,theme:"measure-space",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const v={entity:this.entity,label:this.labelEntity,positions:this.positions,distance:p,clear:()=>this.clear()};(c=t.onComplete)==null||c.call(t,v)}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(n=>{var g,p;if(this.positions.length!==1)return;const s=i.scene.pickPosition(n.endPosition);if(!s)return;this.previewPos=s;const o=this.positions[0],r=e.Cartesian3.distance(o,s),l=new e.Cartesian3((o.x+s.x)/2,(o.y+s.y)/2,(o.z+s.z)/2),c=e.Cartographic.fromCartesian(l),d=this.previewLabelId||"measure_space_preview";this.previewLabelId=d,this.htmlLabelPool.add({text:`${r.toFixed(2)} m`},{id:d,lon:e.Math.toDegrees(c.longitude),lat:e.Math.toDegrees(c.latitude),height:c.height||0,theme:"measure-space",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const u=t.lineColor||t.color||e.Color.YELLOW,m=((p=(g=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:p.call(g,.9))||e.Color.RED;this.previewEntity||(this.previewEntity=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewPos||!this.positions.length?[]:[this.positions[0],this.previewPos],!1),width:t.width||3,material:u,depthFailMaterial:new e.PolylineDashMaterialProperty({color:m,dashLength:12,dashPattern:255})}}))},e.ScreenSpaceEventType.MOUSE_MOVE)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){this.stop(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.labelEntity&&(this.viewer.entities.remove(this.labelEntity),this.labelEntity=null),this.htmlLabelPool&&this.htmlLabelId&&(this.htmlLabelPool.removeByIds([this.htmlLabelId]),this.htmlLabelId=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.tempPoints.forEach(t=>this.viewer.entities.remove(t)),this.tempPoints=[],this.positions=[]}rehydrate(t,e){var d,u;const i=this.Cesium,n=this.viewer,s=t.options||{},o=s.lineColor||s.color||i.Color.YELLOW,r=((u=(d=s.dashLineColor||s.lineColor||s.color||i.Color.RED).withAlpha)==null?void 0:u.call(d,.9))||i.Color.RED,l=s.width||3,c=(t.positions||[]).map(m=>new i.Cartesian3(m[0],m[1],m[2]));if(c.length){if(!this.htmlLabelPool){const m=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,n,m),this.htmlLabelPool.registerTheme("measure-space",{createElement:(g,p)=>{var f;g.innerHTML=String(((f=p==null?void 0:p.data)==null?void 0:f.text)||""),g.style.background="rgba(0,0,0,0.6)",g.style.color="#fff",g.style.font="14px sans-serif",g.style.padding="4px 6px",g.style.borderRadius="4px",g.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}if(c.length>=1){const m=n.entities.add({position:c[0],point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(m)}if(c.length>=2){const m=n.entities.add({position:c[1],point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(m),this.entity=n.entities.add({polyline:{positions:[c[0],c[1]],width:l,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}});const g=i.Cartesian3.distance(c[0],c[1]),p=i.Cartographic.fromCartesian(c[1]),f=t.id+"_label";this.htmlLabelId=f,this.htmlLabelPool.add({text:`${g.toFixed(2)} m`},{id:f,lon:i.Math.toDegrees(p.longitude),lat:i.Math.toDegrees(p.latitude),height:p.height||0,theme:"measure-space",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})}}}}class Ke{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"entity",null);h(this,"labelEntity",null);h(this,"positions",[]);h(this,"tempPoints",[]);h(this,"primitive",null);h(this,"previewEntity",null);h(this,"previewPos",null);h(this,"edgeEntities",[]);h(this,"pointEntities",[]);h(this,"previewEdgeEntity",null);h(this,"previewPointEntities",[]);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);h(this,"previewLabelId",null);h(this,"segmentLabelIds",[]);h(this,"angleLabelIds",[]);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const n=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,n),this.htmlLabelPool.registerTheme("measure-area",{createElement:(s,o)=>{var r;s.innerHTML=String(((r=o==null?void 0:o.data)==null?void 0:r.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-area-seg",{createElement:(s,o)=>{var r;s.innerHTML=String(((r=o==null?void 0:o.data)==null?void 0:r.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-area-angle",{createElement:(s,o)=>{var r;s.innerHTML=String(((r=o==null?void 0:o.data)==null?void 0:r.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var m,g;const s=i.scene.pickPosition(n.position);if(!s)return;this.positions.push(s);const o=i.entities.add({position:s,point:{pixelSize:8,color:t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(o),this.primitive&&(i.scene.primitives.remove(this.primitive),this.primitive=null);const r=new e.PolygonHierarchy(this.positions.slice()),l=new e.PolygonGeometry({polygonHierarchy:r,vertexFormat:e.MaterialAppearance.VERTEX_FORMAT,perPositionHeight:!0,arcType:e.ArcType.NONE}),c=new e.GeometryInstance({geometry:l}),d=t.color||e.Color.YELLOW.withAlpha(.4),u=t.color&&t.color.withAlpha?t.color.withAlpha(.25):e.Color.RED.withAlpha(.4);if(this.primitive=new e.Primitive({geometryInstances:c,appearance:new e.MaterialAppearance({material:e.Material.fromType("Color",{color:d}),translucent:!0,closed:!0}),depthFailAppearance:new e.MaterialAppearance({material:e.Material.fromType("Color",{color:u}),translucent:!0,closed:!0})}),i.scene.primitives.add(this.primitive),this.positions.length>=2){if(this.edgeEntities.length){for(const v of this.edgeEntities)try{i.entities.remove(v)}catch{}this.edgeEntities=[]}const p=t.lineColor||t.color||e.Color.YELLOW,f=((g=(m=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:g.call(m,.9))||e.Color.RED,w=this.positions.concat([this.positions[0]]),y=i.entities.add({polyline:{positions:w,width:t.width||2,material:p,clampToGround:!1,arcType:e.ArcType.NONE,depthFailMaterial:new e.PolylineDashMaterialProperty({color:f,dashLength:12,dashPattern:255})}});this.edgeEntities.push(y)}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(n=>{var p,f;if(this.positions.length===0)return;const s=i.scene.pickPosition(n.endPosition);if(!s)return;this.previewPos=s;const o=this.positions.concat([s]),r=new e.Cartesian3(o.reduce((w,y)=>w+y.x,0)/o.length,o.reduce((w,y)=>w+y.y,0)/o.length,o.reduce((w,y)=>w+y.z,0)/o.length),c=new e.EllipsoidTangentPlane(r,e.Ellipsoid.WGS84).projectPointsOntoPlane(o);let d=0;for(let w=0;w<c.length;w++){const y=(w+1)%c.length;d+=c[w].x*c[y].y-c[y].x*c[w].y}d=Math.abs(d)/2;const u=e.Cartographic.fromCartesian(r),m=this.previewLabelId||"measure_area_preview";this.previewLabelId=m;const g=t.labelText||{area:"面积"};if(this.htmlLabelPool.add({text:`${g.area}:${d.toFixed(2)} m²`},{id:m,lon:e.Math.toDegrees(u.longitude),lat:e.Math.toDegrees(u.latitude),height:u.height||0,theme:"measure-area",show:!0}),!this.previewEntity){const w=t.color||e.Color.YELLOW.withAlpha(.4);this.previewEntity=i.entities.add({polygon:{hierarchy:new e.CallbackProperty(()=>{if(!this.previewPos||!this.positions.length)return;const M=this.positions.concat([this.previewPos]);return new e.PolygonHierarchy(M)},!1),material:w,perPositionHeight:!0,arcType:e.ArcType.NONE}});const y=t.lineColor||t.color||e.Color.YELLOW,v=((f=(p=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:f.call(p,.9))||e.Color.RED;this.previewEdgeEntity=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewPos||!this.positions.length?[]:this.positions.concat([this.previewPos,this.positions[0]]),!1),width:t.width||2,material:y,clampToGround:!1,arcType:e.ArcType.NONE,depthFailMaterial:new e.PolylineDashMaterialProperty({color:v,dashLength:12,dashPattern:255})}});const C=t.pointColor||t.color||e.Color.YELLOW,b=i.entities.add({position:new e.CallbackProperty(()=>this.previewPos||this.positions[this.positions.length-1],!1),point:{pixelSize:8,color:C,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.previewPointEntities.push(b)}},e.ScreenSpaceEventType.MOUSE_MOVE),this.handler.setInputAction(()=>{var g;if(this.positions.length<3){this.stop();return}if(this.positions.length>=3){this.positions.pop();const p=this.tempPoints.pop();p&&this.viewer.entities.remove(p)}if(this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewEdgeEntity&&(this.viewer.entities.remove(this.previewEdgeEntity),this.previewEdgeEntity=null),this.previewPointEntities.length){for(const p of this.previewPointEntities)try{this.viewer.entities.remove(p)}catch{}this.previewPointEntities=[]}this.previewPos=null,this.stop();const n=new e.Cartesian3(this.positions.reduce((p,f)=>p+f.x,0)/this.positions.length,this.positions.reduce((p,f)=>p+f.y,0)/this.positions.length,this.positions.reduce((p,f)=>p+f.z,0)/this.positions.length),o=new e.EllipsoidTangentPlane(n,e.Ellipsoid.WGS84).projectPointsOntoPlane(this.positions);let r=0;for(let p=0;p<o.length;p++){const f=(p+1)%o.length;r+=o[p].x*o[f].y-o[f].x*o[p].y}r=Math.abs(r)/2;const l=e.Cartographic.fromCartesian(n),c=this.htmlLabelId||`measure_area_${Date.now()}`;this.htmlLabelId=c;const d=t.labelText||{area:"面积",side:"边长",angle:"角度"};this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.htmlLabelPool.add({text:`${d.area}:${r.toFixed(2)} m²`},{id:c,lon:e.Math.toDegrees(l.longitude),lat:e.Math.toDegrees(l.latitude),height:l.height||0,theme:"measure-area",show:!0}),this.labelEntity=this.htmlLabelId;for(let p=0;p<this.positions.length;p++){const f=(p+1)%this.positions.length,w=this.positions[p],y=this.positions[f],v=e.Cartographic.fromCartesian(w),C=e.Cartographic.fromCartesian(y),M=new e.EllipsoidGeodesic(v,C).surfaceDistance,P=new e.Cartesian3((w.x+y.x)/2,(w.y+y.y)/2,(w.z+y.z)/2),L=e.Cartographic.fromCartesian(P),E=`measure_area_seg_${Date.now()}_${p}`;this.segmentLabelIds.push(E),this.htmlLabelPool.add({text:`${d.side}:${M.toFixed(2)} m`},{id:E,lon:e.Math.toDegrees(L.longitude),lat:e.Math.toDegrees(L.latitude),height:L.height||0,theme:"measure-area-seg",show:!0})}const u=o;for(let p=0;p<u.length;p++){const f=u[(p-1+u.length)%u.length],w=u[p],y=u[(p+1)%u.length],v=f.x-w.x,C=f.y-w.y,b=y.x-w.x,M=y.y-w.y,P=Math.sqrt(v*v+C*C),L=Math.sqrt(b*b+M*M);if(!P||!L)continue;const E=v/P*(b/L)+C/P*(M/L),I=Math.acos(Math.min(1,Math.max(-1,E)))*(180/Math.PI),A=e.Cartographic.fromCartesian(this.positions[p]),x=`measure_area_angle_${Date.now()}_${p}`;this.angleLabelIds.push(x),this.htmlLabelPool.add({text:`${d.angle}:${I.toFixed(2)} °`},{id:x,lon:e.Math.toDegrees(A.longitude),lat:e.Math.toDegrees(A.latitude),height:A.height||0,theme:"measure-area-angle",show:!0})}const m={entity:this.primitive,label:this.labelEntity,positions:this.positions,area:r,clear:()=>this.clear()};(g=t.onComplete)==null||g.call(t,m)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){if(this.stop(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.primitive&&(this.viewer.scene.primitives.remove(this.primitive),this.primitive=null),this.edgeEntities.length){for(const t of this.edgeEntities)try{this.viewer.entities.remove(t)}catch{}this.edgeEntities=[]}if(this.pointEntities.length){for(const t of this.pointEntities)try{this.viewer.entities.remove(t)}catch{}this.pointEntities=[]}if(this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null,this.previewPos=null),this.previewEdgeEntity&&(this.viewer.entities.remove(this.previewEdgeEntity),this.previewEdgeEntity=null),this.previewPointEntities.length){for(const t of this.previewPointEntities)try{this.viewer.entities.remove(t)}catch{}this.previewPointEntities=[]}this.labelEntity&&(this.viewer.entities.remove(this.labelEntity),this.labelEntity=null),this.htmlLabelPool&&this.htmlLabelId&&(this.htmlLabelPool.removeByIds([this.htmlLabelId]),this.htmlLabelId=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.segmentLabelIds.length&&this.htmlLabelPool&&this.htmlLabelPool.removeByIds(this.segmentLabelIds.slice()),this.angleLabelIds.length&&this.htmlLabelPool&&this.htmlLabelPool.removeByIds(this.angleLabelIds.slice()),this.segmentLabelIds=[],this.angleLabelIds=[],this.tempPoints.forEach(t=>this.viewer.entities.remove(t)),this.tempPoints=[],this.positions=[]}rehydrate(t,e){const i=this.Cesium,n=this.viewer,s=t.options||{},o=(t.positions||[]).map(M=>new i.Cartesian3(M[0],M[1],M[2]));if(o.length<3)return;if(!this.htmlLabelPool){const M=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,n,M),this.htmlLabelPool.registerTheme("measure-area",{createElement:(P,L)=>{var E;P.innerHTML=String(((E=L==null?void 0:L.data)==null?void 0:E.text)||""),P.style.background="rgba(0,0,0,0.6)",P.style.color="#fff",P.style.font="14px sans-serif",P.style.padding="4px 6px",P.style.borderRadius="4px",P.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-area-seg",{createElement:(P,L)=>{var E;P.innerHTML=String(((E=L==null?void 0:L.data)==null?void 0:E.text)||""),P.style.background="rgba(0,0,0,0.6)",P.style.color="#fff",P.style.font="14px sans-serif",P.style.padding="4px 6px",P.style.borderRadius="4px",P.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-area-angle",{createElement:(P,L)=>{var E;P.innerHTML=String(((E=L==null?void 0:L.data)==null?void 0:E.text)||""),P.style.background="rgba(0,0,0,0.6)",P.style.color="#fff",P.style.font="14px sans-serif",P.style.padding="4px 6px",P.style.borderRadius="4px",P.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}for(const M of o){const P=n.entities.add({position:M,point:{pixelSize:8,color:s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(P)}const r=new i.Cartesian3(o.reduce((M,P)=>M+P.x,0)/o.length,o.reduce((M,P)=>M+P.y,0)/o.length,o.reduce((M,P)=>M+P.z,0)/o.length),c=new i.EllipsoidTangentPlane(r,i.Ellipsoid.WGS84).projectPointsOntoPlane(o);let d=0;for(let M=0;M<c.length;M++){const P=(M+1)%c.length;d+=c[M].x*c[P].y-c[P].x*c[M].y}d=Math.abs(d)/2;const u=i.Cartographic.fromCartesian(r),m=t.id+"_area";this.htmlLabelId=m;const g=s.labelText||{area:"面积",side:"边长",angle:"角度"};this.htmlLabelPool.add({text:`${g.area}:${d.toFixed(2)} m²`},{id:m,lon:i.Math.toDegrees(u.longitude),lat:i.Math.toDegrees(u.latitude),height:u.height||0,theme:"measure-area",show:!0});const p=new i.PolygonHierarchy(o),f=new i.PolygonGeometry({polygonHierarchy:p,vertexFormat:i.MaterialAppearance.VERTEX_FORMAT,perPositionHeight:!0}),w=new i.GeometryInstance({geometry:f}),y=s.color||i.Color.YELLOW.withAlpha(.4),v=s.color&&s.color.withAlpha?s.color.withAlpha(.25):i.Color.RED.withAlpha(.4),C=new i.Primitive({geometryInstances:w,appearance:new i.MaterialAppearance({material:i.Material.fromType("Color",{color:y}),translucent:!0,closed:!0}),depthFailAppearance:new i.MaterialAppearance({material:i.Material.fromType("Color",{color:v}),translucent:!0,closed:!0})});n.scene.primitives.add(C),this.primitive=C;for(let M=0;M<o.length;M++){const P=(M+1)%o.length,L=o[M],E=o[P],I=i.Cartographic.fromCartesian(L),A=i.Cartographic.fromCartesian(E),T=new i.EllipsoidGeodesic(I,A).surfaceDistance,$=new i.Cartesian3((L.x+E.x)/2,(L.y+E.y)/2,(L.z+E.z)/2),D=i.Cartographic.fromCartesian($),k=t.id+`_area_seg_${M}`;this.segmentLabelIds.push(k),this.htmlLabelPool.add({text:`${g.side}:${T.toFixed(2)} m`},{id:k,lon:i.Math.toDegrees(D.longitude),lat:i.Math.toDegrees(D.latitude),height:D.height||0,theme:"measure-area-seg",show:!0})}const b=c;for(let M=0;M<b.length;M++){const P=b[(M-1+b.length)%b.length],L=b[M],E=b[(M+1)%b.length],I=P.x-L.x,A=P.y-L.y,x=E.x-L.x,T=E.y-L.y,$=Math.sqrt(I*I+A*A),D=Math.sqrt(x*x+T*T);if(!$||!D)continue;const k=I/$*(x/D)+A/$*(T/D),_=Math.acos(Math.min(1,Math.max(-1,k)))*(180/Math.PI),O=i.Cartographic.fromCartesian(o[M]),R=t.id+`_area_angle_${M}`;this.angleLabelIds.push(R),this.htmlLabelPool.add({text:`${g.angle}:${_.toFixed(2)} °`},{id:R,lon:i.Math.toDegrees(O.longitude),lat:i.Math.toDegrees(O.latitude),height:O.height||0,theme:"measure-area-angle",show:!0})}}}class qe{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"entity",null);h(this,"positions",[]);h(this,"currentRadius",0);h(this,"labelEntity",null);h(this,"previewLabel",null);h(this,"ellipsePrimitive",null);h(this,"previewEntity",null);h(this,"isPrimitive",!1);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const n=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,n),this.htmlLabelPool.registerTheme("measure-circle",{createElement:(s,o)=>{var l;const r=((l=o==null?void 0:o.data)==null?void 0:l.text)||"";s.innerHTML=String(r),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var o;const s=i.scene.pickPosition(n.position);if(s&&(this.positions.push(s),this.positions.length===2)){this.stop();const r=this.positions[0],l=this.positions[1],c=e.Cartesian3.distance(r,l),d=Math.PI*c*c,u=2*Math.PI*c,m=t.labelText||{radius:"半径",area:"面积",circumference:"周长"},g=r;this.labelEntity?(this.labelEntity.position=g,this.labelEntity.label.text=`${m.radius}:${c.toFixed(2)} m
|
|
44
44
|
${m.area}:${d.toFixed(2)} m²
|
|
45
45
|
${m.circumference}:${u.toFixed(2)} m`):this.labelEntity=i.entities.add({position:g,label:{text:`${m.radius}:${c.toFixed(2)} m
|
|
46
46
|
${m.area}:${d.toFixed(2)} m²
|
|
47
|
-
${m.circumference}:${u.toFixed(2)} m`,font:"14px sans-serif",fillColor:e.Color.WHITE,outlineColor:e.Color.BLACK,outlineWidth:2,style:e.LabelStyle.FILL_AND_OUTLINE,verticalOrigin:e.VerticalOrigin.BOTTOM,pixelOffset:new e.Cartesian2(0,-10),disableDepthTestDistance:Number.POSITIVE_INFINITY,eyeOffset:new e.Cartesian3(0,0,-1e3),showBackground:!0,backgroundColor:e.Color.BLACK.withAlpha(.6),show:!1}}),this.previewEntity&&(i.entities.remove(this.previewEntity),this.previewEntity=null);const p=e.Cartographic.fromCartesian(
|
|
47
|
+
${m.circumference}:${u.toFixed(2)} m`,font:"14px sans-serif",fillColor:e.Color.WHITE,outlineColor:e.Color.BLACK,outlineWidth:2,style:e.LabelStyle.FILL_AND_OUTLINE,verticalOrigin:e.VerticalOrigin.BOTTOM,pixelOffset:new e.Cartesian2(0,-10),disableDepthTestDistance:Number.POSITIVE_INFINITY,eyeOffset:new e.Cartesian3(0,0,-1e3),showBackground:!0,backgroundColor:e.Color.BLACK.withAlpha(.6),show:!1}}),this.previewEntity&&(i.entities.remove(this.previewEntity),this.previewEntity=null);const p=e.Cartographic.fromCartesian(r),f=new e.EllipseGeometry({center:r,semiMajorAxis:c,semiMinorAxis:c,height:p.height||0,vertexFormat:e.MaterialAppearance.VERTEX_FORMAT}),w=new e.GeometryInstance({geometry:f}),y=t.color||e.Color.YELLOW.withAlpha(.5),v=t.color&&t.color.withAlpha?t.color.withAlpha(.25):e.Color.RED.withAlpha(.4);this.ellipsePrimitive&&(i.scene.primitives.remove(this.ellipsePrimitive),this.ellipsePrimitive=null),this.ellipsePrimitive=new e.Primitive({geometryInstances:w,appearance:new e.MaterialAppearance({material:e.Material.fromType("Color",{color:y}),translucent:!0,closed:!0}),depthFailAppearance:new e.MaterialAppearance({material:e.Material.fromType("Color",{color:v}),translucent:!0,closed:!0})}),i.scene.primitives.add(this.ellipsePrimitive),this.entity=this.ellipsePrimitive,this.isPrimitive=!0;const C=e.Cartographic.fromCartesian(r),b=e.Math.toDegrees(C.longitude),M=e.Math.toDegrees(C.latitude),P=C.height||0,L=this.htmlLabelId||`measure_circle_${Date.now()}`;this.htmlLabelId=L;const E=`${m.radius}:${c.toFixed(2)} m
|
|
48
48
|
${m.area}:${d.toFixed(2)} m²
|
|
49
|
-
${m.circumference}:${u.toFixed(2)} m`;this.htmlLabelPool.add({text:E},{id:L,lon:b,lat:M,height:P,theme:"measure-circle",show:!0});const I={entity:this.entity,label:this.labelEntity,positions:this.positions,radius:c,area:d,perimeter:u,clear:()=>this.clear()};(
|
|
49
|
+
${m.circumference}:${u.toFixed(2)} m`;this.htmlLabelPool.add({text:E},{id:L,lon:b,lat:M,height:P,theme:"measure-circle",show:!0});const I={entity:this.entity,label:this.labelEntity,positions:this.positions,radius:c,area:d,perimeter:u,clear:()=>this.clear()};(o=t.onComplete)==null||o.call(t,I)}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(n=>{if(this.positions.length!==1)return;const s=this.positions[0],o=i.camera.getPickRay(n.endPosition),r=i.scene.globe.pick(o,i.scene);if(!r)return;const l=e.Cartesian3.distance(s,r);this.currentRadius=l;const c=e.Cartographic.fromCartesian(s),d=Math.PI*l*l,u=2*Math.PI*l,m=t.labelText||{radius:"半径",area:"面积",circumference:"周长"},g=s;this.labelEntity?(this.labelEntity.position=g,this.labelEntity.label.text=`${m.radius}:${l.toFixed(2)} m
|
|
50
50
|
${m.area}:${d.toFixed(2)} m²
|
|
51
51
|
${m.circumference}:${u.toFixed(2)} m`):this.labelEntity=i.entities.add({position:g,label:{text:`${m.radius}:${l.toFixed(2)} m
|
|
52
52
|
${m.area}:${d.toFixed(2)} m²
|
|
53
|
-
${m.circumference}:${u.toFixed(2)} m`,font:"14px sans-serif",fillColor:e.Color.WHITE,outlineColor:e.Color.BLACK,outlineWidth:2,style:e.LabelStyle.FILL_AND_OUTLINE,verticalOrigin:e.VerticalOrigin.BOTTOM,pixelOffset:new e.Cartesian2(0,-10),disableDepthTestDistance:Number.POSITIVE_INFINITY,eyeOffset:new e.Cartesian3(0,0,-1e3),showBackground:!0,backgroundColor:e.Color.BLACK.withAlpha(.6),show:!1}});const p=e.Cartographic.fromCartesian(s),
|
|
53
|
+
${m.circumference}:${u.toFixed(2)} m`,font:"14px sans-serif",fillColor:e.Color.WHITE,outlineColor:e.Color.BLACK,outlineWidth:2,style:e.LabelStyle.FILL_AND_OUTLINE,verticalOrigin:e.VerticalOrigin.BOTTOM,pixelOffset:new e.Cartesian2(0,-10),disableDepthTestDistance:Number.POSITIVE_INFINITY,eyeOffset:new e.Cartesian3(0,0,-1e3),showBackground:!0,backgroundColor:e.Color.BLACK.withAlpha(.6),show:!1}});const p=e.Cartographic.fromCartesian(s),f=e.Math.toDegrees(p.longitude),w=e.Math.toDegrees(p.latitude),y=p.height||0,v=this.htmlLabelId||`measure_circle_${Date.now()}`;this.htmlLabelId=v;const C=`${m.radius}:${l.toFixed(2)} m
|
|
54
54
|
${m.area}:${d.toFixed(2)} m²
|
|
55
|
-
${m.circumference}:${u.toFixed(2)} m`;if(this.htmlLabelPool.add({text:C},{id:v,lon:
|
|
55
|
+
${m.circumference}:${u.toFixed(2)} m`;if(this.htmlLabelPool.add({text:C},{id:v,lon:f,lat:w,height:y,theme:"measure-circle",show:!0}),!this.previewEntity){const b=t.color||e.Color.YELLOW.withAlpha(.5);this.previewEntity=i.entities.add({position:s,ellipse:{semiMajorAxis:new e.CallbackProperty(()=>this.currentRadius,!1),semiMinorAxis:new e.CallbackProperty(()=>this.currentRadius,!1),height:c.height||0,material:b}})}},e.ScreenSpaceEventType.MOUSE_MOVE)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){this.stop(),this.entity&&(this.isPrimitive?this.viewer.scene.primitives.remove(this.entity):this.viewer.entities.remove(this.entity),this.entity=null,this.isPrimitive=!1),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.labelEntity&&(this.viewer.entities.remove(this.labelEntity),this.labelEntity=null),this.previewLabel&&(this.viewer.entities.remove(this.previewLabel),this.previewLabel=null),this.ellipsePrimitive&&(this.viewer.scene.primitives.remove(this.ellipsePrimitive),this.ellipsePrimitive=null),this.htmlLabelPool&&this.htmlLabelId&&(this.htmlLabelPool.removeByIds([this.htmlLabelId]),this.htmlLabelId=null),this.positions=[],this.currentRadius=0}rehydrate(t,e){const i=this.Cesium,n=this.viewer,s=t.options||{},o=(t.positions||[]).map(P=>new i.Cartesian3(P[0],P[1],P[2]));if(o.length<2)return;if(!this.htmlLabelPool){const P=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,n,P),this.htmlLabelPool.registerTheme("measure-circle",{createElement:(L,E)=>{var A;const I=((A=E==null?void 0:E.data)==null?void 0:A.text)||"";L.innerHTML=String(I),L.style.background="rgba(0,0,0,0.6)",L.style.color="#fff",L.style.font="14px sans-serif",L.style.padding="4px 6px",L.style.borderRadius="4px",L.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}const r=o[0],l=o[1],c=i.Cartesian3.distance(r,l),d=Math.PI*c*c,u=2*Math.PI*c,m=i.Cartographic.fromCartesian(r),g=new i.EllipseGeometry({center:r,semiMajorAxis:c,semiMinorAxis:c,height:m.height||0,vertexFormat:i.MaterialAppearance.VERTEX_FORMAT}),p=new i.GeometryInstance({geometry:g}),f=s.color||i.Color.YELLOW.withAlpha(.5),w=s.color&&s.color.withAlpha?s.color.withAlpha(.25):i.Color.RED.withAlpha(.4),y=new i.Primitive({geometryInstances:p,appearance:new i.MaterialAppearance({material:i.Material.fromType("Color",{color:f}),translucent:!0,closed:!0}),depthFailAppearance:new i.MaterialAppearance({material:i.Material.fromType("Color",{color:w}),translucent:!0,closed:!0})});n.scene.primitives.add(y),this.ellipsePrimitive=y,this.entity=y,this.isPrimitive=!0;const v=i.Cartographic.fromCartesian(r),C=t.id+"_circle";this.htmlLabelId=C;const b=s.labelText||{radius:"半径",area:"面积",circumference:"周长"},M=`${b.radius}:${c.toFixed(2)} m
|
|
56
56
|
${b.area}:${d.toFixed(2)} m²
|
|
57
|
-
${b.circumference}:${u.toFixed(2)} m`;this.htmlLabelPool.add({text:M},{id:C,lon:i.Math.toDegrees(v.longitude),lat:i.Math.toDegrees(v.latitude),height:v.height||0,theme:"measure-circle",show:!0})}}class Xe{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"entity",null);h(this,"labelEntity",null);h(this,"positions",[]);h(this,"tempPoints",[]);h(this,"segmentLabels",[]);h(this,"hoverPos",null);h(this,"previewPos",null);h(this,"previewLabel",null);h(this,"previewEntity",null);h(this,"htmlLabelPool",null);h(this,"totalLabelId",null);h(this,"segmentLabelIds",[]);h(this,"previewLabelId",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const o=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,o),this.htmlLabelPool.registerTheme("measure-polyline-total",{createElement:(s,r)=>{var n;s.innerHTML=String(((n=r==null?void 0:r.data)==null?void 0:n.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-polyline-seg",{createElement:(s,r)=>{var n;s.innerHTML=String(((n=r==null?void 0:r.data)==null?void 0:n.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(o=>{var n,l;const s=i.scene.pickPosition(o.position);if(!s)return;this.positions.push(s);const r=i.entities.add({position:s,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});if(this.tempPoints.push(r),this.entity?this.entity.polyline.positions=this.positions.slice():this.entity=i.entities.add({polyline:{positions:this.positions.slice(),width:t.width||3,material:t.lineColor||t.color||e.Color.YELLOW,depthFailMaterial:new e.PolylineDashMaterialProperty({color:((l=(n=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:l.call(n,.9))||e.Color.RED,dashLength:12,dashPattern:255})}}),this.positions.length>=2){const c=this.positions[this.positions.length-2],d=this.positions[this.positions.length-1],u=e.Cartographic.fromCartesian(c),m=e.Cartographic.fromCartesian(d),p=new e.EllipsoidGeodesic(u,m).surfaceDistance,y=new e.Cartesian3((c.x+d.x)/2,(c.y+d.y)/2,(c.z+d.z)/2),w=e.Cartographic.fromCartesian(y),f=`measure_polyline_seg_${this.segmentLabelIds.length}_${Date.now()}`;this.segmentLabelIds.push(f),this.htmlLabelPool.add({text:`${p.toFixed(2)} m`},{id:f,lon:e.Math.toDegrees(w.longitude),lat:e.Math.toDegrees(w.latitude),height:w.height||0,theme:"measure-polyline-seg",show:!0})}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(()=>{var c;if(this.positions.length<2){this.stop();return}if(this.stop(),this.previewLabelId&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.hoverPos&&(this.hoverPos=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.positions.length>=2&&this.tempPoints.length>=2){const d=this.tempPoints[this.tempPoints.length-1];this.viewer.entities.remove(d),this.tempPoints.pop()}if(this.segmentLabelIds.length>=1){const d=this.segmentLabelIds[this.segmentLabelIds.length-1];d&&(this.htmlLabelPool.removeByIds([d]),this.segmentLabelIds.pop())}this.positions.length>=2&&this.positions.pop();let o=0;for(let d=1;d<this.positions.length;d++){const u=this.positions[d-1],m=this.positions[d],g=e.Cartographic.fromCartesian(u),p=e.Cartographic.fromCartesian(m),w=new e.EllipsoidGeodesic(g,p).surfaceDistance;o+=w}const s=this.positions[this.positions.length-1];this.entity&&this.entity.polyline&&(this.entity.polyline.positions=this.positions);const r=e.Cartographic.fromCartesian(s),n=this.totalLabelId||`measure_polyline_total_${Date.now()}`;this.totalLabelId=n,this.htmlLabelPool.add({text:`${o.toFixed(2)} m`},{id:n,lon:e.Math.toDegrees(r.longitude),lat:e.Math.toDegrees(r.latitude),height:r.height||0,theme:"measure-polyline-total",show:!0}),this.labelEntity=this.totalLabelId;const l={entity:this.entity,label:this.labelEntity,segmentLabels:this.segmentLabelIds,positions:this.positions,distance:o,clear:()=>this.clear()};(c=t.onComplete)==null||c.call(t,l)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK),this.handler.setInputAction(o=>{var p,y;if(this.positions.length===0)return;const s=i.scene.pickPosition(o.endPosition);if(!s)return;this.hoverPos=s,this.previewPos=s;const r=this.positions[this.positions.length-1],n=e.Cartographic.fromCartesian(r),l=e.Cartographic.fromCartesian(s),d=new e.EllipsoidGeodesic(n,l).surfaceDistance,u=new e.Cartesian3((r.x+s.x)/2,(r.y+s.y)/2,(r.z+s.z)/2),m=e.Cartographic.fromCartesian(u),g=this.previewLabelId||"measure_polyline_preview";this.previewLabelId=g,this.htmlLabelPool.add({text:`${d.toFixed(2)} m`},{id:g,lon:e.Math.toDegrees(m.longitude),lat:e.Math.toDegrees(m.latitude),height:m.height||0,theme:"measure-polyline-seg",show:!0}),this.previewEntity||(this.previewEntity=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewPos||!this.positions.length?[]:[this.positions[this.positions.length-1],this.previewPos],!1),width:t.width||3,material:t.lineColor||t.color||e.Color.YELLOW,depthFailMaterial:new e.PolylineDashMaterialProperty({color:((y=(p=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:y.call(p,.9))||e.Color.RED,dashLength:12,dashPattern:255})}}))},e.ScreenSpaceEventType.MOUSE_MOVE)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){this.stop(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.totalLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.totalLabelId]),this.totalLabelId=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.hoverPos=null,this.segmentLabelIds.length&&this.htmlLabelPool&&this.htmlLabelPool.removeByIds(this.segmentLabelIds.slice()),this.segmentLabelIds=[],this.tempPoints.forEach(t=>this.viewer.entities.remove(t)),this.tempPoints=[],this.positions=[]}rehydrate(t,e){var p,y;const i=this.Cesium,o=this.viewer,s=t.options||{},r=s.lineColor||s.color||i.Color.YELLOW,n=((y=(p=s.dashLineColor||s.lineColor||s.color||i.Color.RED).withAlpha)==null?void 0:y.call(p,.9))||i.Color.RED,l=s.width||3,c=(t.positions||[]).map(w=>new i.Cartesian3(w[0],w[1],w[2]));if(c.length<2)return;if(!this.htmlLabelPool){const w=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,o,w),this.htmlLabelPool.registerTheme("measure-polyline-total",{createElement:(f,v)=>{var C;f.innerHTML=String(((C=v==null?void 0:v.data)==null?void 0:C.text)||""),f.style.background="rgba(0,0,0,0.6)",f.style.color="#fff",f.style.font="14px sans-serif",f.style.padding="4px 6px",f.style.borderRadius="4px",f.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-polyline-seg",{createElement:(f,v)=>{var C;f.innerHTML=String(((C=v==null?void 0:v.data)==null?void 0:C.text)||""),f.style.background="rgba(0,0,0,0.6)",f.style.color="#fff",f.style.font="14px sans-serif",f.style.padding="4px 6px",f.style.borderRadius="4px",f.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}for(const w of c){const f=o.entities.add({position:w,point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(f)}this.entity=o.entities.add({polyline:{positions:c,width:l,material:r,depthFailMaterial:new i.PolylineDashMaterialProperty({color:n,dashLength:12,dashPattern:255})}});let d=0;for(let w=1;w<c.length;w++){const f=i.Cartographic.fromCartesian(c[w-1]),v=i.Cartographic.fromCartesian(c[w]),C=new i.EllipsoidGeodesic(f,v);d+=C.surfaceDistance;const b=c[w-1],M=c[w],P=new i.Cartesian3((b.x+M.x)/2,(b.y+M.y)/2,(b.z+M.z)/2),L=i.Cartographic.fromCartesian(P),E=t.id+`_seg_${w-1}`;this.segmentLabelIds.push(E),this.htmlLabelPool.add({text:`${C.surfaceDistance.toFixed(2)} m`},{id:E,lon:i.Math.toDegrees(L.longitude),lat:i.Math.toDegrees(L.latitude),height:L.height||0,theme:"measure-polyline-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})}const u=c[c.length-1],m=i.Cartographic.fromCartesian(u),g=t.id+"_total";this.totalLabelId=g,this.htmlLabelPool.add({text:`${d.toFixed(2)} m`},{id:g,lon:i.Math.toDegrees(m.longitude),lat:i.Math.toDegrees(m.latitude),height:m.height||0,theme:"measure-polyline-total",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})}}class Je{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"labelEntity",null);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);h(this,"topPoint",null);h(this,"zeroPoint",null);h(this,"lineEntity",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const o=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,o),this.htmlLabelPool.registerTheme("measure-terrainHeight",{createElement:(s,r)=>{var n;s.innerHTML=String(((n=r==null?void 0:r.data)==null?void 0:n.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(o=>{var w;const s=i.scene.pickPosition(o.position);if(!s)return;const r=e.Cartographic.fromCartesian(s),n=i.scene.globe.getHeight(new e.Cartographic(r.longitude,r.latitude,0))||0,l=e.Math.toDegrees(r.longitude),c=e.Math.toDegrees(r.latitude),d=e.Cartesian3.fromDegrees(l,c,n);this.topPoint=i.entities.add({position:s,point:{pixelSize:8,color:t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),this.zeroPoint=i.entities.add({position:d,point:{pixelSize:8,color:e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),this.lineEntity=i.entities.add({polyline:{positions:[d,s],width:t.width||3,material:t.color||e.Color.YELLOW,depthFailMaterial:new e.PolylineDashMaterialProperty({color:e.Color.RED,dashLength:12,dashPattern:255})}});const u=t.labelText||{height:"高差"},m=(r.height||0)-n,g=`${u.height}:${m.toFixed(2)} m`,p=this.htmlLabelId||`measure_terrain_${Date.now()}`;this.htmlLabelId=p,this.htmlLabelPool.add({text:g},{id:p,lon:l,lat:c,height:r.height||0,theme:"measure-terrainHeight",show:!0}),this.labelEntity=this.htmlLabelId;const y={label:this.labelEntity,position:s,zeroPosition:d,line:this.lineEntity,terrainHeight:n,difference:m,clear:()=>this.clear()};(w=t.onComplete)==null||w.call(t,y),this.stop()},e.ScreenSpaceEventType.LEFT_CLICK)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){this.stop(),this.lineEntity&&(this.viewer.entities.remove(this.lineEntity),this.lineEntity=null),this.topPoint&&(this.viewer.entities.remove(this.topPoint),this.topPoint=null),this.zeroPoint&&(this.viewer.entities.remove(this.zeroPoint),this.zeroPoint=null),this.htmlLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.htmlLabelId]),this.htmlLabelId=null)}rehydrate(t,e){const i=this.Cesium,o=this.viewer,s=t.options||{},r=(t.positions||[]).map(w=>new i.Cartesian3(w[0],w[1],w[2]));if(r.length<1){const f=(t.data||{}).position;f&&(Array.isArray(f)&&f.length===3?r.push(new i.Cartesian3(f[0],f[1],f[2])):typeof f=="object"&&f&&"x"in f&&"y"in f&&"z"in f&&r.push(new i.Cartesian3(f.x,f.y,f.z)))}if(r.length<1)return;if(!this.htmlLabelPool){const w=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,o,w),this.htmlLabelPool.registerTheme("measure-terrainHeight",{createElement:(f,v)=>{var C;f.innerHTML=String(((C=v==null?void 0:v.data)==null?void 0:C.text)||""),f.style.background="rgba(0,0,0,0.6)",f.style.color="#fff",f.style.font="14px sans-serif",f.style.padding="4px 6px",f.style.borderRadius="4px",f.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}const n=r[0],l=i.Cartographic.fromCartesian(n),c=o.scene.globe.getHeight(new i.Cartographic(l.longitude,l.latitude,0))||0,d=i.Math.toDegrees(l.longitude),u=i.Math.toDegrees(l.latitude),m=i.Cartesian3.fromDegrees(d,u,c);this.topPoint=o.entities.add({position:n,point:{pixelSize:8,color:s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),this.zeroPoint=o.entities.add({position:m,point:{pixelSize:8,color:i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),this.lineEntity=o.entities.add({polyline:{positions:[m,n],width:s.width||3,material:s.color||i.Color.YELLOW,depthFailMaterial:new i.PolylineDashMaterialProperty({color:i.Color.RED,dashLength:12,dashPattern:255})}});const g=s.labelText||{height:"高差"},p=(l.height||0)-c,y=t.id+"_terrain";this.htmlLabelId=y,this.htmlLabelPool.add({text:`${g.height}:${p.toFixed(2)} m`},{id:y,lon:d,lat:u,height:l.height||0,theme:"measure-terrainHeight",show:!0})}}class Qe{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"entity",null);h(this,"labelEntity",null);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const o=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,o),this.htmlLabelPool.registerTheme("measure-coordinate",{createElement:(s,r)=>{var n;s.innerHTML=String(((n=r==null?void 0:r.data)==null?void 0:n.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(o=>{var g;const s=i.scene.pickPosition(o.position);if(!s)return;const r=e.Cartographic.fromCartesian(s),n=e.Math.toDegrees(r.longitude),l=e.Math.toDegrees(r.latitude),c=r.height||0;this.entity=i.entities.add({position:s,point:{pixelSize:10,color:t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});const d=this.htmlLabelId||`measure_coordinate_${Date.now()}`;this.htmlLabelId=d;const u=t.labelText||{lng:"经",lat:"纬",height:"高"};this.htmlLabelPool.add({text:`${u.lng}:${n.toFixed(6)}
|
|
57
|
+
${b.circumference}:${u.toFixed(2)} m`;this.htmlLabelPool.add({text:M},{id:C,lon:i.Math.toDegrees(v.longitude),lat:i.Math.toDegrees(v.latitude),height:v.height||0,theme:"measure-circle",show:!0})}}class Xe{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"entity",null);h(this,"labelEntity",null);h(this,"positions",[]);h(this,"tempPoints",[]);h(this,"segmentLabels",[]);h(this,"hoverPos",null);h(this,"previewPos",null);h(this,"previewLabel",null);h(this,"previewEntity",null);h(this,"htmlLabelPool",null);h(this,"totalLabelId",null);h(this,"segmentLabelIds",[]);h(this,"previewLabelId",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const n=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,n),this.htmlLabelPool.registerTheme("measure-polyline-total",{createElement:(s,o)=>{var r;s.innerHTML=String(((r=o==null?void 0:o.data)==null?void 0:r.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-polyline-seg",{createElement:(s,o)=>{var r;s.innerHTML=String(((r=o==null?void 0:o.data)==null?void 0:r.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var r,l;const s=i.scene.pickPosition(n.position);if(!s)return;this.positions.push(s);const o=i.entities.add({position:s,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});if(this.tempPoints.push(o),this.entity?this.entity.polyline.positions=this.positions.slice():this.entity=i.entities.add({polyline:{positions:this.positions.slice(),width:t.width||3,material:t.lineColor||t.color||e.Color.YELLOW,depthFailMaterial:new e.PolylineDashMaterialProperty({color:((l=(r=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:l.call(r,.9))||e.Color.RED,dashLength:12,dashPattern:255})}}),this.positions.length>=2){const c=this.positions[this.positions.length-2],d=this.positions[this.positions.length-1],u=e.Cartographic.fromCartesian(c),m=e.Cartographic.fromCartesian(d),p=new e.EllipsoidGeodesic(u,m).surfaceDistance,f=new e.Cartesian3((c.x+d.x)/2,(c.y+d.y)/2,(c.z+d.z)/2),w=e.Cartographic.fromCartesian(f),y=`measure_polyline_seg_${this.segmentLabelIds.length}_${Date.now()}`;this.segmentLabelIds.push(y),this.htmlLabelPool.add({text:`${p.toFixed(2)} m`},{id:y,lon:e.Math.toDegrees(w.longitude),lat:e.Math.toDegrees(w.latitude),height:w.height||0,theme:"measure-polyline-seg",show:!0})}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(()=>{var c;if(this.positions.length<2){this.stop();return}if(this.stop(),this.previewLabelId&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.hoverPos&&(this.hoverPos=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.positions.length>=2&&this.tempPoints.length>=2){const d=this.tempPoints[this.tempPoints.length-1];this.viewer.entities.remove(d),this.tempPoints.pop()}if(this.segmentLabelIds.length>=1){const d=this.segmentLabelIds[this.segmentLabelIds.length-1];d&&(this.htmlLabelPool.removeByIds([d]),this.segmentLabelIds.pop())}this.positions.length>=2&&this.positions.pop();let n=0;for(let d=1;d<this.positions.length;d++){const u=this.positions[d-1],m=this.positions[d],g=e.Cartographic.fromCartesian(u),p=e.Cartographic.fromCartesian(m),w=new e.EllipsoidGeodesic(g,p).surfaceDistance;n+=w}const s=this.positions[this.positions.length-1];this.entity&&this.entity.polyline&&(this.entity.polyline.positions=this.positions);const o=e.Cartographic.fromCartesian(s),r=this.totalLabelId||`measure_polyline_total_${Date.now()}`;this.totalLabelId=r,this.htmlLabelPool.add({text:`${n.toFixed(2)} m`},{id:r,lon:e.Math.toDegrees(o.longitude),lat:e.Math.toDegrees(o.latitude),height:o.height||0,theme:"measure-polyline-total",show:!0}),this.labelEntity=this.totalLabelId;const l={entity:this.entity,label:this.labelEntity,segmentLabels:this.segmentLabelIds,positions:this.positions,distance:n,clear:()=>this.clear()};(c=t.onComplete)==null||c.call(t,l)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK),this.handler.setInputAction(n=>{var p,f;if(this.positions.length===0)return;const s=i.scene.pickPosition(n.endPosition);if(!s)return;this.hoverPos=s,this.previewPos=s;const o=this.positions[this.positions.length-1],r=e.Cartographic.fromCartesian(o),l=e.Cartographic.fromCartesian(s),d=new e.EllipsoidGeodesic(r,l).surfaceDistance,u=new e.Cartesian3((o.x+s.x)/2,(o.y+s.y)/2,(o.z+s.z)/2),m=e.Cartographic.fromCartesian(u),g=this.previewLabelId||"measure_polyline_preview";this.previewLabelId=g,this.htmlLabelPool.add({text:`${d.toFixed(2)} m`},{id:g,lon:e.Math.toDegrees(m.longitude),lat:e.Math.toDegrees(m.latitude),height:m.height||0,theme:"measure-polyline-seg",show:!0}),this.previewEntity||(this.previewEntity=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.previewPos||!this.positions.length?[]:[this.positions[this.positions.length-1],this.previewPos],!1),width:t.width||3,material:t.lineColor||t.color||e.Color.YELLOW,depthFailMaterial:new e.PolylineDashMaterialProperty({color:((f=(p=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:f.call(p,.9))||e.Color.RED,dashLength:12,dashPattern:255})}}))},e.ScreenSpaceEventType.MOUSE_MOVE)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){this.stop(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.totalLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.totalLabelId]),this.totalLabelId=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.hoverPos=null,this.segmentLabelIds.length&&this.htmlLabelPool&&this.htmlLabelPool.removeByIds(this.segmentLabelIds.slice()),this.segmentLabelIds=[],this.tempPoints.forEach(t=>this.viewer.entities.remove(t)),this.tempPoints=[],this.positions=[]}rehydrate(t,e){var p,f;const i=this.Cesium,n=this.viewer,s=t.options||{},o=s.lineColor||s.color||i.Color.YELLOW,r=((f=(p=s.dashLineColor||s.lineColor||s.color||i.Color.RED).withAlpha)==null?void 0:f.call(p,.9))||i.Color.RED,l=s.width||3,c=(t.positions||[]).map(w=>new i.Cartesian3(w[0],w[1],w[2]));if(c.length<2)return;if(!this.htmlLabelPool){const w=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,n,w),this.htmlLabelPool.registerTheme("measure-polyline-total",{createElement:(y,v)=>{var C;y.innerHTML=String(((C=v==null?void 0:v.data)==null?void 0:C.text)||""),y.style.background="rgba(0,0,0,0.6)",y.style.color="#fff",y.style.font="14px sans-serif",y.style.padding="4px 6px",y.style.borderRadius="4px",y.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-polyline-seg",{createElement:(y,v)=>{var C;y.innerHTML=String(((C=v==null?void 0:v.data)==null?void 0:C.text)||""),y.style.background="rgba(0,0,0,0.6)",y.style.color="#fff",y.style.font="14px sans-serif",y.style.padding="4px 6px",y.style.borderRadius="4px",y.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}for(const w of c){const y=n.entities.add({position:w,point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(y)}this.entity=n.entities.add({polyline:{positions:c,width:l,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}});let d=0;for(let w=1;w<c.length;w++){const y=i.Cartographic.fromCartesian(c[w-1]),v=i.Cartographic.fromCartesian(c[w]),C=new i.EllipsoidGeodesic(y,v);d+=C.surfaceDistance;const b=c[w-1],M=c[w],P=new i.Cartesian3((b.x+M.x)/2,(b.y+M.y)/2,(b.z+M.z)/2),L=i.Cartographic.fromCartesian(P),E=t.id+`_seg_${w-1}`;this.segmentLabelIds.push(E),this.htmlLabelPool.add({text:`${C.surfaceDistance.toFixed(2)} m`},{id:E,lon:i.Math.toDegrees(L.longitude),lat:i.Math.toDegrees(L.latitude),height:L.height||0,theme:"measure-polyline-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})}const u=c[c.length-1],m=i.Cartographic.fromCartesian(u),g=t.id+"_total";this.totalLabelId=g,this.htmlLabelPool.add({text:`${d.toFixed(2)} m`},{id:g,lon:i.Math.toDegrees(m.longitude),lat:i.Math.toDegrees(m.latitude),height:m.height||0,theme:"measure-polyline-total",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})}}class Je{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"labelEntity",null);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);h(this,"topPoint",null);h(this,"zeroPoint",null);h(this,"lineEntity",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const n=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,n),this.htmlLabelPool.registerTheme("measure-terrainHeight",{createElement:(s,o)=>{var r;s.innerHTML=String(((r=o==null?void 0:o.data)==null?void 0:r.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var w;const s=i.scene.pickPosition(n.position);if(!s)return;const o=e.Cartographic.fromCartesian(s),r=i.scene.globe.getHeight(new e.Cartographic(o.longitude,o.latitude,0))||0,l=e.Math.toDegrees(o.longitude),c=e.Math.toDegrees(o.latitude),d=e.Cartesian3.fromDegrees(l,c,r);this.topPoint=i.entities.add({position:s,point:{pixelSize:8,color:t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),this.zeroPoint=i.entities.add({position:d,point:{pixelSize:8,color:e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),this.lineEntity=i.entities.add({polyline:{positions:[d,s],width:t.width||3,material:t.color||e.Color.YELLOW,depthFailMaterial:new e.PolylineDashMaterialProperty({color:e.Color.RED,dashLength:12,dashPattern:255})}});const u=t.labelText||{height:"高差"},m=(o.height||0)-r,g=`${u.height}:${m.toFixed(2)} m`,p=this.htmlLabelId||`measure_terrain_${Date.now()}`;this.htmlLabelId=p,this.htmlLabelPool.add({text:g},{id:p,lon:l,lat:c,height:o.height||0,theme:"measure-terrainHeight",show:!0}),this.labelEntity=this.htmlLabelId;const f={label:this.labelEntity,position:s,zeroPosition:d,line:this.lineEntity,terrainHeight:r,difference:m,clear:()=>this.clear()};(w=t.onComplete)==null||w.call(t,f),this.stop()},e.ScreenSpaceEventType.LEFT_CLICK)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){this.stop(),this.lineEntity&&(this.viewer.entities.remove(this.lineEntity),this.lineEntity=null),this.topPoint&&(this.viewer.entities.remove(this.topPoint),this.topPoint=null),this.zeroPoint&&(this.viewer.entities.remove(this.zeroPoint),this.zeroPoint=null),this.htmlLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.htmlLabelId]),this.htmlLabelId=null)}rehydrate(t,e){const i=this.Cesium,n=this.viewer,s=t.options||{},o=(t.positions||[]).map(w=>new i.Cartesian3(w[0],w[1],w[2]));if(o.length<1){const y=(t.data||{}).position;y&&(Array.isArray(y)&&y.length===3?o.push(new i.Cartesian3(y[0],y[1],y[2])):typeof y=="object"&&y&&"x"in y&&"y"in y&&"z"in y&&o.push(new i.Cartesian3(y.x,y.y,y.z)))}if(o.length<1)return;if(!this.htmlLabelPool){const w=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,n,w),this.htmlLabelPool.registerTheme("measure-terrainHeight",{createElement:(y,v)=>{var C;y.innerHTML=String(((C=v==null?void 0:v.data)==null?void 0:C.text)||""),y.style.background="rgba(0,0,0,0.6)",y.style.color="#fff",y.style.font="14px sans-serif",y.style.padding="4px 6px",y.style.borderRadius="4px",y.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}const r=o[0],l=i.Cartographic.fromCartesian(r),c=n.scene.globe.getHeight(new i.Cartographic(l.longitude,l.latitude,0))||0,d=i.Math.toDegrees(l.longitude),u=i.Math.toDegrees(l.latitude),m=i.Cartesian3.fromDegrees(d,u,c);this.topPoint=n.entities.add({position:r,point:{pixelSize:8,color:s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),this.zeroPoint=n.entities.add({position:m,point:{pixelSize:8,color:i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),this.lineEntity=n.entities.add({polyline:{positions:[m,r],width:s.width||3,material:s.color||i.Color.YELLOW,depthFailMaterial:new i.PolylineDashMaterialProperty({color:i.Color.RED,dashLength:12,dashPattern:255})}});const g=s.labelText||{height:"高差"},p=(l.height||0)-c,f=t.id+"_terrain";this.htmlLabelId=f,this.htmlLabelPool.add({text:`${g.height}:${p.toFixed(2)} m`},{id:f,lon:d,lat:u,height:l.height||0,theme:"measure-terrainHeight",show:!0})}}class Qe{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"entity",null);h(this,"labelEntity",null);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const n=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,n),this.htmlLabelPool.registerTheme("measure-coordinate",{createElement:(s,o)=>{var r;s.innerHTML=String(((r=o==null?void 0:o.data)==null?void 0:r.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var g;const s=i.scene.pickPosition(n.position);if(!s)return;const o=e.Cartographic.fromCartesian(s),r=e.Math.toDegrees(o.longitude),l=e.Math.toDegrees(o.latitude),c=o.height||0;this.entity=i.entities.add({position:s,point:{pixelSize:10,color:t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});const d=this.htmlLabelId||`measure_coordinate_${Date.now()}`;this.htmlLabelId=d;const u=t.labelText||{lng:"经",lat:"纬",height:"高"};this.htmlLabelPool.add({text:`${u.lng}:${r.toFixed(6)}
|
|
58
58
|
${u.lat}:${l.toFixed(6)}
|
|
59
|
-
${u.height}:${c.toFixed(2)} m`},{id:d,lon:
|
|
59
|
+
${u.height}:${c.toFixed(2)} m`},{id:d,lon:r,lat:l,height:c,theme:"measure-coordinate",show:!0}),this.labelEntity=this.htmlLabelId;const m={entity:this.entity,label:this.labelEntity,lnglat:{lng:r,lat:l,height:c},clear:()=>this.clear()};(g=t.onComplete)==null||g.call(t,m),this.stop()},e.ScreenSpaceEventType.LEFT_CLICK)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){this.stop(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.htmlLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.htmlLabelId]),this.htmlLabelId=null)}rehydrate(t,e){var p;const i=this.Cesium,n=this.viewer,s=t.options||{},o=(t.positions||[]).map(f=>new i.Cartesian3(f[0],f[1],f[2]));if(!o.length){const f=(p=t.data)==null?void 0:p.lnglat;if(f&&typeof f.lng=="number"&&typeof f.lat=="number"){const w=i.Cartesian3.fromDegrees(f.lng,f.lat,f.height||0);o.push(w)}}if(!o.length)return;if(!this.htmlLabelPool){const f=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,n,f),this.htmlLabelPool.registerTheme("measure-coordinate",{createElement:(w,y)=>{var v;w.innerHTML=String(((v=y==null?void 0:y.data)==null?void 0:v.text)||""),w.style.background="rgba(0,0,0,0.6)",w.style.color="#fff",w.style.font="14px sans-serif",w.style.padding="4px 6px",w.style.borderRadius="4px",w.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}const r=o[0],l=i.Cartographic.fromCartesian(r),c=i.Math.toDegrees(l.longitude),d=i.Math.toDegrees(l.latitude),u=l.height||0;this.entity=n.entities.add({position:r,point:{pixelSize:10,color:s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});const m=t.id+"_coord";this.htmlLabelId=m;const g=s.labelText||{lng:"经",lat:"纬",height:"高"};this.htmlLabelPool.add({text:`${g.lng}:${c.toFixed(6)}
|
|
60
60
|
${g.lat}:${d.toFixed(6)}
|
|
61
|
-
${g.height}:${u.toFixed(2)} m`},{id:m,lon:c,lat:d,height:u,theme:"measure-coordinate",show:!0})}}class Ze{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"startPoint",null);h(this,"endPoint",null);h(this,"secondPoint",null);h(this,"currentCorners",[]);h(this,"edgeEntities",[]);h(this,"pointEntities",[]);h(this,"previewEdgeEntity",null);h(this,"previewPointEntities",[]);h(this,"entity",null);h(this,"labelEntity",null);h(this,"primitive",null);h(this,"previewEntity",null);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);h(this,"segmentLabelIds",[]);h(this,"previewLabelId",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const
|
|
62
|
-
${
|
|
63
|
-
${
|
|
64
|
-
${
|
|
65
|
-
${
|
|
66
|
-
${
|
|
67
|
-
${
|
|
61
|
+
${g.height}:${u.toFixed(2)} m`},{id:m,lon:c,lat:d,height:u,theme:"measure-coordinate",show:!0})}}class Ze{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"startPoint",null);h(this,"endPoint",null);h(this,"secondPoint",null);h(this,"currentCorners",[]);h(this,"edgeEntities",[]);h(this,"pointEntities",[]);h(this,"previewEdgeEntity",null);h(this,"previewPointEntities",[]);h(this,"entity",null);h(this,"labelEntity",null);h(this,"primitive",null);h(this,"previewEntity",null);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);h(this,"segmentLabelIds",[]);h(this,"previewLabelId",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer;if(!this.htmlLabelPool){const n=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,n),this.htmlLabelPool.registerTheme("measure-rectangle",{createElement:(s,o)=>{var r;s.innerHTML=String(((r=o==null?void 0:o.data)==null?void 0:r.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-rectangle-seg",{createElement:(s,o)=>{var r;s.innerHTML=String(((r=o==null?void 0:o.data)==null?void 0:r.text)||""),s.style.background="rgba(0,0,0,0.6)",s.style.color="#fff",s.style.font="14px sans-serif",s.style.padding="4px 6px",s.style.borderRadius="4px",s.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var $,D,k;const s=i.scene.pickPosition(n.position);if(!s)return;if(!this.startPoint){this.startPoint=s;return}if(!this.secondPoint){this.secondPoint=s,this.endPoint=s;return}const o=s,r=this.computeRectangle(this.startPoint,this.secondPoint,o);if(!r){this.stop();return}this.stop();const{corners:l,center:c,width:d,height:u,area:m}=r;this.previewEntity&&(i.entities.remove(this.previewEntity),this.previewEntity=null),this.primitive&&(i.scene.primitives.remove(this.primitive),this.primitive=null),this.entity&&(i.entities.remove(this.entity),this.entity=null);const g=this.htmlLabelId||`measure_rectangle_${Date.now()}`;this.htmlLabelId=g;const p=e.Cartographic.fromCartesian(c),f=t.labelText||{width:"宽",heightLabel:"高",area:"面积",side:"边长"};this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.htmlLabelPool.add({text:`${f.width}:${d.toFixed(2)} m
|
|
62
|
+
${f.heightLabel}:${u.toFixed(2)} m
|
|
63
|
+
${f.area}:${m.toFixed(2)} m²`},{id:g,lon:e.Math.toDegrees(p.longitude),lat:e.Math.toDegrees(p.latitude),height:p.height||0,theme:"measure-rectangle",show:!0});const w=[[l[0],l[1]],[l[1],l[2]],[l[2],l[3]],[l[3],l[0]]];for(let _=0;_<w.length;_++){const[O,R]=w[_],G=_===0||_===2?d:u,B=new e.Cartesian3((O.x+R.x)/2,(O.y+R.y)/2,(O.z+R.z)/2),j=e.Cartographic.fromCartesian(B),X=`measure_rectangle_seg_${Date.now()}_${_}`;this.segmentLabelIds.push(X),this.htmlLabelPool.add({text:`${f.side}:${Number(G).toFixed(2)} m`},{id:X,lon:e.Math.toDegrees(j.longitude),lat:e.Math.toDegrees(j.latitude),height:j.height||0,theme:"measure-rectangle-seg",show:!0})}const y=this.buildSurfaceRectanglePositions(l),v=new e.PolygonHierarchy(y),C=new e.PolygonGeometry({polygonHierarchy:v,vertexFormat:e.MaterialAppearance.VERTEX_FORMAT,perPositionHeight:!0,arcType:e.ArcType.NONE}),b=new e.GeometryInstance({geometry:C}),M=t.color||e.Color.YELLOW.withAlpha(.4),P=t.color&&t.color.withAlpha?t.color.withAlpha(.25):e.Color.RED.withAlpha(.4);this.primitive=new e.Primitive({geometryInstances:b,appearance:new e.MaterialAppearance({material:e.Material.fromType("Color",{color:M}),translucent:!0,closed:!0}),depthFailAppearance:new e.MaterialAppearance({material:e.Material.fromType("Color",{color:P}),translucent:!0,closed:!0})}),i.scene.primitives.add(this.primitive);const L=t.lineColor||t.color||e.Color.YELLOW,E=((D=($=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:D.call($,.9))||e.Color.RED,I=[...y,y[0]],A=i.entities.add({polyline:{positions:I,width:t.width||2,material:L,clampToGround:!1,arcType:e.ArcType.NONE,depthFailMaterial:new e.PolylineDashMaterialProperty({color:E,dashLength:12,dashPattern:255})}});this.edgeEntities.push(A);const x=t.pointColor||t.color||e.Color.YELLOW;for(const _ of l){const O=i.entities.add({position:_,point:{pixelSize:8,color:x,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.pointEntities.push(O)}const T={entity:this.primitive,label:this.labelEntity,positions:[this.startPoint,this.secondPoint,o],width:d,height:u,area:m,clear:()=>this.clear()};(k=t.onComplete)==null||k.call(t,T)},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(n=>{var w,y;const s=i.scene.pickPosition(n.endPosition);if(!s)return;if(this.startPoint&&!this.secondPoint){if(this.endPoint=s,!this.previewEdgeEntity){const v=t.lineColor||t.color||e.Color.YELLOW,C=((y=(w=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:y.call(w,.9))||e.Color.RED;this.previewEdgeEntity=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.startPoint||!this.endPoint?[]:[this.startPoint,this.endPoint],!1),width:t.width||2,material:v,clampToGround:!1,arcType:e.ArcType.NONE,depthFailMaterial:new e.PolylineDashMaterialProperty({color:C,dashLength:12,dashPattern:255})}});const b=t.pointColor||t.color||e.Color.YELLOW,M=i.entities.add({position:this.startPoint,point:{pixelSize:8,color:b,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),P=i.entities.add({position:new e.CallbackProperty(()=>this.endPoint||this.startPoint,!1),point:{pixelSize:8,color:b,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.previewPointEntities.push(M,P)}return}if(!this.startPoint||!this.secondPoint)return;const o=this.computeRectangle(this.startPoint,this.secondPoint,s);if(!o)return;const{corners:r,center:l,width:c,height:d,area:u}=o,m=this.buildSurfaceRectanglePositions(r);this.currentCorners=m;const g=e.Cartographic.fromCartesian(l),p=this.previewLabelId||"measure_rectangle_preview";this.previewLabelId=p;const f=t.labelText||{width:"宽",heightLabel:"高",area:"面积"};if(this.htmlLabelPool.add({text:`${f.width}:${c.toFixed(2)} m
|
|
64
|
+
${f.heightLabel}:${d.toFixed(2)} m
|
|
65
|
+
${f.area}:${u.toFixed(2)} m²`},{id:p,lon:e.Math.toDegrees(g.longitude),lat:e.Math.toDegrees(g.latitude),height:g.height||0,theme:"measure-rectangle",show:!0}),!this.previewEntity){const v=t.color||e.Color.YELLOW.withAlpha(.4);this.previewEntity=i.entities.add({polygon:{hierarchy:new e.CallbackProperty(()=>{if(!(!this.startPoint||!this.secondPoint||!this.currentCorners.length))return new e.PolygonHierarchy(this.currentCorners)},!1),material:v,perPositionHeight:!0,arcType:e.ArcType.NONE}})}},e.ScreenSpaceEventType.MOUSE_MOVE)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){if(this.stop(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewEdgeEntity&&(this.viewer.entities.remove(this.previewEdgeEntity),this.previewEdgeEntity=null),this.previewPointEntities.length){for(const t of this.previewPointEntities)try{this.viewer.entities.remove(t)}catch{}this.previewPointEntities=[]}if(this.edgeEntities.length){for(const t of this.edgeEntities)try{this.viewer.entities.remove(t)}catch{}this.edgeEntities=[]}if(this.pointEntities.length){for(const t of this.pointEntities)try{this.viewer.entities.remove(t)}catch{}this.pointEntities=[]}this.primitive&&(this.viewer.scene.primitives.remove(this.primitive),this.primitive=null),this.htmlLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.htmlLabelId]),this.htmlLabelId=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.segmentLabelIds.length&&this.htmlLabelPool&&this.htmlLabelPool.removeByIds(this.segmentLabelIds.slice()),this.segmentLabelIds=[],this.startPoint=null,this.endPoint=null,this.secondPoint=null,this.currentCorners=[]}buildSurfaceRectanglePositions(t){return!t||!t.length?[]:t.slice()}rehydrate(t,e){const i=this.Cesium,n=this.viewer,s=t.options||{},o=(t.positions||[]).map(x=>new i.Cartesian3(x[0],x[1],x[2]));if(o.length<3)return;if(!this.htmlLabelPool){const x=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,n,x),this.htmlLabelPool.registerTheme("measure-rectangle",{createElement:(T,$)=>{var D;T.innerHTML=String(((D=$==null?void 0:$.data)==null?void 0:D.text)||""),T.style.background="rgba(0,0,0,0.6)",T.style.color="#fff",T.style.font="14px sans-serif",T.style.padding="4px 6px",T.style.borderRadius="4px",T.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-rectangle-seg",{createElement:(T,$)=>{var D;T.innerHTML=String(((D=$==null?void 0:$.data)==null?void 0:D.text)||""),T.style.background="rgba(0,0,0,0.6)",T.style.color="#fff",T.style.font="14px sans-serif",T.style.padding="4px 6px",T.style.borderRadius="4px",T.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}const r=this.computeRectangle(o[0],o[1],o[2]);if(!r)return;const l=r.corners,c=r.center,d=r.width,u=r.height,m=r.area,g=i.Cartographic.fromCartesian(c),p=t.id+"_rectangle",f=s.labelText||{width:"宽",heightLabel:"高",area:"面积",side:"边长"};this.htmlLabelId=p,this.htmlLabelPool.add({text:`${f.width}:${d.toFixed(2)} m
|
|
66
|
+
${f.heightLabel}:${u.toFixed(2)} m
|
|
67
|
+
${f.area}:${m.toFixed(2)} m²`},{id:p,lon:i.Math.toDegrees(g.longitude),lat:i.Math.toDegrees(g.latitude),height:g.height||0,theme:"measure-rectangle",show:!0});const w=[[l[0],l[1]],[l[1],l[2]],[l[2],l[3]],[l[3],l[0]]];for(let x=0;x<w.length;x++){const[T,$]=w[x],D=x===0||x===2?d:u,k=new i.Cartesian3((T.x+$.x)/2,(T.y+$.y)/2,(T.z+$.z)/2),_=i.Cartographic.fromCartesian(k),O=t.id+`_rectangle_seg_${x}`;this.segmentLabelIds.push(O),this.htmlLabelPool.add({text:`${f.side}:${Number(D).toFixed(2)} m`},{id:O,lon:i.Math.toDegrees(_.longitude),lat:i.Math.toDegrees(_.latitude),height:_.height||0,theme:"measure-rectangle-seg",show:!0})}const y=new i.PolygonHierarchy(l),v=new i.PolygonGeometry({polygonHierarchy:y,vertexFormat:i.MaterialAppearance.VERTEX_FORMAT,perPositionHeight:!0,arcType:i.ArcType.NONE}),C=new i.GeometryInstance({geometry:v}),b=s.color||i.Color.YELLOW.withAlpha(.4),M=s.color&&s.color.withAlpha?s.color.withAlpha(.25):i.Color.RED.withAlpha(.4),P=new i.Primitive({geometryInstances:C,appearance:new i.MaterialAppearance({material:i.Material.fromType("Color",{color:b}),translucent:!0,closed:!0}),depthFailAppearance:new i.MaterialAppearance({material:i.Material.fromType("Color",{color:M}),translucent:!0,closed:!0})});this.primitive=P,n.scene.primitives.add(this.primitive);const L=s.lineColor||b,E=[...l,l[0]],I=n.entities.add({polyline:{positions:E,width:s.width||2,material:L,clampToGround:!1,arcType:i.ArcType.NONE}});this.edgeEntities.push(I);const A=s.pointColor||b;for(const x of l){const T=n.entities.add({position:x,point:{pixelSize:8,color:A,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.pointEntities.push(T)}}computeRectangle(t,e,i){const n=this.Cesium,s=new n.EllipsoidTangentPlane(t,n.Ellipsoid.WGS84),o=s.projectPointsOntoPlane([t,e,i]);if(!o||o.length<3)return null;const r=o[0],l=o[1],c=o[2],d=l.x-r.x,u=l.y-r.y,m=Math.sqrt(d*d+u*u);if(!m)return null;const g=d/m,f=-(u/m),w=g,y=c.x-l.x,v=c.y-l.y,C=y*f+v*w;if(!C)return null;const b=new n.Cartesian2(l.x+f*C,l.y+w*C),M=new n.Cartesian2(r.x+f*C,r.y+w*C),P=s.projectPointsOntoEllipsoid([r,l,b,M]);if(!P||P.length<4)return null;const L=P,E=L[0],I=L[2],A=Math.abs(m),x=Math.abs(C),T=new n.Cartesian3((E.x+I.x)/2,(E.y+I.y)/2,(E.z+I.z)/2),D=new n.EllipsoidTangentPlane(T,n.Ellipsoid.WGS84).projectPointsOntoPlane(L);let k=0;for(let O=0;O<D.length;O++){const R=(O+1)%D.length;k+=D[O].x*D[R].y-D[R].x*D[O].y}const _=Math.abs(k)/2;return{corners:L,center:T,width:A,height:x,area:_}}}class et{constructor(t,e){h(this,"Cesium");h(this,"viewer");h(this,"handler",null);h(this,"entity",null);h(this,"positions",[]);h(this,"labelEntity",null);h(this,"currentPoints",[]);h(this,"primitive",null);h(this,"previewEntity",null);h(this,"edgeEntities",[]);h(this,"pointEntities",[]);h(this,"previewEdgeEntity",null);h(this,"previewPointEntities",[]);h(this,"htmlLabelPool",null);h(this,"htmlLabelId",null);h(this,"segmentLabelIds",[]);h(this,"previewLabelId",null);this.Cesium=t,this.viewer=e}start(t){this.clear();const e=this.Cesium,i=this.viewer,n=Math.max(t.sides||6,6);if(!this.htmlLabelPool){const s=t.overlayContainerId||"html-label-container";this.htmlLabelPool=new N(e,i,s),this.htmlLabelPool.registerTheme("measure-regular",{createElement:(o,r)=>{var l;o.innerHTML=String(((l=r==null?void 0:r.data)==null?void 0:l.text)||""),o.style.background="rgba(0,0,0,0.6)",o.style.color="#fff",o.style.font="14px sans-serif",o.style.padding="4px 6px",o.style.borderRadius="4px",o.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-regular-seg",{createElement:(o,r)=>{var l;o.innerHTML=String(((l=r==null?void 0:r.data)==null?void 0:l.text)||""),o.style.background="rgba(0,0,0,0.6)",o.style.color="#fff",o.style.font="14px sans-serif",o.style.padding="4px 6px",o.style.borderRadius="4px",o.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(s=>{var r,l,c;const o=i.scene.pickPosition(s.position);if(o&&(this.positions.push(o),this.positions.length===2)){this.stop();const d=this.positions[0],u=this.positions[1],m=e.Cartesian3.distance(d,u),g=this.buildRegularPolygonPoints(d,m,n);this.previewEntity&&(i.entities.remove(this.previewEntity),this.previewEntity=null),this.primitive&&(i.scene.primitives.remove(this.primitive),this.primitive=null);const p=new e.PolygonHierarchy(g),f=new e.PolygonGeometry({polygonHierarchy:p,vertexFormat:e.MaterialAppearance.VERTEX_FORMAT,perPositionHeight:!0,arcType:e.ArcType.NONE}),w=new e.GeometryInstance({geometry:f}),y=t.color||e.Color.YELLOW.withAlpha(.4),v=t.color&&t.color.withAlpha?t.color.withAlpha(.25):e.Color.RED.withAlpha(.4);this.primitive=new e.Primitive({geometryInstances:w,appearance:new e.MaterialAppearance({material:e.Material.fromType("Color",{color:y}),translucent:!0,closed:!0}),depthFailAppearance:new e.MaterialAppearance({material:e.Material.fromType("Color",{color:v}),translucent:!0,closed:!0})}),i.scene.primitives.add(this.primitive);const C=t.lineColor||y,b=((l=(r=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:l.call(r,.9))||e.Color.RED,M=g.slice(),P=i.entities.add({polyline:{positions:M,width:t.width||2,material:C,clampToGround:!1,arcType:e.ArcType.NONE,depthFailMaterial:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}});this.edgeEntities.push(P);const L=t.pointColor||y,E=g.slice(0,g.length-1);for(const k of E){const _=i.entities.add({position:k,point:{pixelSize:8,color:L,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.pointEntities.push(_)}const I=this.computeAreaByPlane(g),A=e.Cartographic.fromCartesian(d),x=this.htmlLabelId||`measure_regular_${Date.now()}`;this.htmlLabelId=x;const T=t.labelText||{sides:"边数",radius:"半径",circumference:"周长",area:"面积",side:"边长"};this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null);let $=0;for(let k=1;k<g.length;k++){const _=g[k-1],O=g[k],R=e.Cartographic.fromCartesian(_),G=e.Cartographic.fromCartesian(O),j=new e.EllipsoidGeodesic(R,G).surfaceDistance;$+=j;const X=new e.Cartesian3((_.x+O.x)/2,(_.y+O.y)/2,(_.z+O.z)/2),Q=e.Cartographic.fromCartesian(X),ae=`measure_regular_seg_${Date.now()}_${k-1}`;this.segmentLabelIds.push(ae),this.htmlLabelPool.add({text:`${T.side}:${j.toFixed(2)} m`},{id:ae,lon:e.Math.toDegrees(Q.longitude),lat:e.Math.toDegrees(Q.latitude),height:Q.height||0,theme:"measure-regular-seg",show:!0})}this.htmlLabelPool.add({text:`${T.sides}:${n}
|
|
68
68
|
${T.radius}:${m.toFixed(2)} m
|
|
69
|
-
${T.circumference}:${
|
|
70
|
-
${T.area}:${I.toFixed(2)} m²`},{id:x,lon:e.Math.toDegrees(
|
|
69
|
+
${T.circumference}:${$.toFixed(2)} m
|
|
70
|
+
${T.area}:${I.toFixed(2)} m²`},{id:x,lon:e.Math.toDegrees(A.longitude),lat:e.Math.toDegrees(A.latitude),height:A.height||0,theme:"measure-regular",show:!0});const D={entity:this.primitive,label:this.labelEntity,positions:g,radius:m,sides:n,perimeter:$,area:I,clear:()=>this.clear()};(c=t.onComplete)==null||c.call(t,D)}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(s=>{var f,w;if(this.positions.length!==1)return;const o=this.positions[0],r=i.camera.getPickRay(s.endPosition),l=i.scene.globe.pick(r,i.scene);if(!l)return;const c=e.Cartesian3.distance(o,l);if(this.currentPoints=this.buildRegularPolygonPoints(o,c,n),!this.previewEntity){const y=t.color||e.Color.YELLOW.withAlpha(.4);this.previewEntity=i.entities.add({polygon:{hierarchy:new e.CallbackProperty(()=>{if(!(!this.currentPoints||this.currentPoints.length===0))return new e.PolygonHierarchy(this.currentPoints)},!1),material:y,perPositionHeight:!0,arcType:e.ArcType.NONE}});const v=t.lineColor||t.color||e.Color.YELLOW,C=((w=(f=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:w.call(f,.9))||e.Color.RED;this.previewEdgeEntity=i.entities.add({polyline:{positions:new e.CallbackProperty(()=>!this.currentPoints||this.currentPoints.length===0?[]:this.currentPoints.slice(),!1),width:t.width||2,material:v,clampToGround:!1,arcType:e.ArcType.NONE,depthFailMaterial:new e.PolylineDashMaterialProperty({color:C,dashLength:12,dashPattern:255})}});const b=t.pointColor||t.color||e.Color.YELLOW,M=i.entities.add({position:o,point:{pixelSize:8,color:b,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),P=i.entities.add({position:new e.CallbackProperty(()=>l||o,!1),point:{pixelSize:8,color:b,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.previewPointEntities.push(M,P)}let d=0;for(let y=1;y<this.currentPoints.length;y++){const v=this.currentPoints[y-1],C=this.currentPoints[y],b=e.Cartographic.fromCartesian(v),M=e.Cartographic.fromCartesian(C),P=new e.EllipsoidGeodesic(b,M);d+=P.surfaceDistance}const u=this.computeAreaByPlane(this.currentPoints),m=e.Cartographic.fromCartesian(o),g=this.previewLabelId||"measure_regular_preview";this.previewLabelId=g;const p=t.labelText||{sides:"边数",radius:"半径",circumference:"周长",area:"面积"};this.htmlLabelPool.add({text:`${p.sides}:${n}
|
|
71
71
|
${p.radius}:${c.toFixed(2)} m
|
|
72
72
|
${p.circumference}:${d.toFixed(2)} m
|
|
73
|
-
${p.area}:${u.toFixed(2)} m²`},{id:g,lon:e.Math.toDegrees(m.longitude),lat:e.Math.toDegrees(m.latitude),height:m.height||0,theme:"measure-regular",show:!0})},e.ScreenSpaceEventType.MOUSE_MOVE)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){if(this.stop(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewEdgeEntity&&(this.viewer.entities.remove(this.previewEdgeEntity),this.previewEdgeEntity=null),this.previewPointEntities.length){for(const t of this.previewPointEntities)try{this.viewer.entities.remove(t)}catch{}this.previewPointEntities=[]}if(this.primitive&&(this.viewer.scene.primitives.remove(this.primitive),this.primitive=null),this.edgeEntities.length){for(const t of this.edgeEntities)try{this.viewer.entities.remove(t)}catch{}this.edgeEntities=[]}if(this.pointEntities.length){for(const t of this.pointEntities)try{this.viewer.entities.remove(t)}catch{}this.pointEntities=[]}this.labelEntity&&(this.viewer.entities.remove(this.labelEntity),this.labelEntity=null),this.htmlLabelPool&&this.htmlLabelId&&(this.htmlLabelPool.removeByIds([this.htmlLabelId]),this.htmlLabelId=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.segmentLabelIds.length&&this.htmlLabelPool&&this.htmlLabelPool.removeByIds(this.segmentLabelIds.slice()),this.segmentLabelIds=[],this.positions=[],this.currentPoints=[]}rehydrate(t,e){var P;const i=this.Cesium,
|
|
73
|
+
${p.area}:${u.toFixed(2)} m²`},{id:g,lon:e.Math.toDegrees(m.longitude),lat:e.Math.toDegrees(m.latitude),height:m.height||0,theme:"measure-regular",show:!0})},e.ScreenSpaceEventType.MOUSE_MOVE)}stop(){this.handler&&(this.handler.destroy(),this.handler=null)}clear(){if(this.stop(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewEdgeEntity&&(this.viewer.entities.remove(this.previewEdgeEntity),this.previewEdgeEntity=null),this.previewPointEntities.length){for(const t of this.previewPointEntities)try{this.viewer.entities.remove(t)}catch{}this.previewPointEntities=[]}if(this.primitive&&(this.viewer.scene.primitives.remove(this.primitive),this.primitive=null),this.edgeEntities.length){for(const t of this.edgeEntities)try{this.viewer.entities.remove(t)}catch{}this.edgeEntities=[]}if(this.pointEntities.length){for(const t of this.pointEntities)try{this.viewer.entities.remove(t)}catch{}this.pointEntities=[]}this.labelEntity&&(this.viewer.entities.remove(this.labelEntity),this.labelEntity=null),this.htmlLabelPool&&this.htmlLabelId&&(this.htmlLabelPool.removeByIds([this.htmlLabelId]),this.htmlLabelId=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.segmentLabelIds.length&&this.htmlLabelPool&&this.htmlLabelPool.removeByIds(this.segmentLabelIds.slice()),this.segmentLabelIds=[],this.positions=[],this.currentPoints=[]}rehydrate(t,e){var P;const i=this.Cesium,n=this.viewer,s=t.options||{},o=((P=t.data)==null?void 0:P.sides)||s.sides||3,r=(t.positions||[]).map(L=>new i.Cartesian3(L[0],L[1],L[2]));if(r.length<2)return;if(!this.htmlLabelPool){const L=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,n,L),this.htmlLabelPool.registerTheme("measure-regular",{createElement:(E,I)=>{var A;E.innerHTML=String(((A=I==null?void 0:I.data)==null?void 0:A.text)||""),E.style.background="rgba(0,0,0,0.6)",E.style.color="#fff",E.style.font="14px sans-serif",E.style.padding="4px 6px",E.style.borderRadius="4px",E.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-regular-seg",{createElement:(E,I)=>{var A;E.innerHTML=String(((A=I==null?void 0:I.data)==null?void 0:A.text)||""),E.style.background="rgba(0,0,0,0.6)",E.style.color="#fff",E.style.font="14px sans-serif",E.style.padding="4px 6px",E.style.borderRadius="4px",E.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}let l=[],c=r[0],d=0;if(r.length>=3){l=r.slice(),c=new i.Cartesian3(l.reduce((E,I)=>E+I.x,0)/l.length,l.reduce((E,I)=>E+I.y,0)/l.length,l.reduce((E,I)=>E+I.z,0)/l.length);const L=l[0];l[Math.floor(l.length/2)]||l[1],d=i.Cartesian3.distance(c,L)}else{const L=r[1];d=i.Cartesian3.distance(c,L),l=this.buildRegularPolygonPoints(c,d,Math.max(o,3))}const u=new i.PolygonHierarchy(l),m=new i.PolygonGeometry({polygonHierarchy:u,vertexFormat:i.MaterialAppearance.VERTEX_FORMAT,perPositionHeight:!0}),g=new i.GeometryInstance({geometry:m}),p=s.color||i.Color.YELLOW.withAlpha(.4),f=s.color&&s.color.withAlpha?s.color.withAlpha(.25):i.Color.RED.withAlpha(.4),w=new i.Primitive({geometryInstances:g,appearance:new i.MaterialAppearance({material:i.Material.fromType("Color",{color:p}),translucent:!0,closed:!0}),depthFailAppearance:new i.MaterialAppearance({material:i.Material.fromType("Color",{color:f}),translucent:!0,closed:!0})});n.scene.primitives.add(w),this.primitive=w;const y=this.computeAreaByPlane(l),v=i.Cartographic.fromCartesian(c),C=t.id+"_regular";this.htmlLabelId=C;const b=s.labelText||{sides:"边数",radius:"半径",circumference:"周长",area:"面积",side:"边长"};let M=0;for(let L=1;L<l.length;L++){const E=l[L-1],I=l[L],A=i.Cartographic.fromCartesian(E),x=i.Cartographic.fromCartesian(I),$=new i.EllipsoidGeodesic(A,x).surfaceDistance;M+=$;const D=new i.Cartesian3((E.x+I.x)/2,(E.y+I.y)/2,(E.z+I.z)/2),k=i.Cartographic.fromCartesian(D),_=t.id+`_regular_seg_${L-1}`;this.segmentLabelIds.push(_),this.htmlLabelPool.add({text:`${b.side}:${$.toFixed(2)} m`},{id:_,lon:i.Math.toDegrees(k.longitude),lat:i.Math.toDegrees(k.latitude),height:k.height||0,theme:"measure-regular-seg",show:!0})}this.htmlLabelPool.add({text:`${b.sides}:${Math.max(o,3)}
|
|
74
74
|
${b.radius}:${d.toFixed(2)} m
|
|
75
75
|
${b.circumference}:${M.toFixed(2)} m
|
|
76
|
-
${b.area}:${f.toFixed(2)} m²`},{id:C,lon:i.Math.toDegrees(v.longitude),lat:i.Math.toDegrees(v.latitude),height:v.height||0,theme:"measure-regular",show:!0})}buildRegularPolygonPoints(t,e,i){const o=this.Cesium,s=new o.EllipsoidTangentPlane(t,o.Ellipsoid.WGS84),r=2*Math.PI/i,n=[];for(let d=0;d<i;d++){const u=d*r,m=e*Math.cos(u),g=e*Math.sin(u);n.push(new o.Cartesian2(m,g))}const c=s.projectPointsOntoEllipsoid(n).slice();return c.push(c[0]),c}computeAreaByPlane(t){const e=this.Cesium,i=new e.Cartesian3(t.reduce((n,l)=>n+l.x,0)/t.length,t.reduce((n,l)=>n+l.y,0)/t.length,t.reduce((n,l)=>n+l.z,0)/t.length),s=new e.EllipsoidTangentPlane(i,e.Ellipsoid.WGS84).projectPointsOntoPlane(t);let r=0;for(let n=0;n<s.length;n++){const l=(n+1)%s.length;r+=s[n].x*s[l].y-s[l].x*s[n].y}return Math.abs(r)/2}}class _o{constructor({Cesium:t,viewer:e}){h(this,"Cesium");h(this,"viewer");h(this,"actives",[]);h(this,"measurements",[]);h(this,"htmlLabelPool",null);h(this,"recordHandlers",new Map);h(this,"specifiedClear",!1);h(this,"deleteLabelPool",null);h(this,"deleteLabelIds",new Map);this.Cesium=t,this.viewer=e,e.screenSpaceEventHandler.removeInputAction(t.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)}measure(t,e){let i=null;switch(t){case"horizontal":i=new Ye(this.Cesium,this.viewer);break;case"vertical":i=new Ve(this.Cesium,this.viewer);break;case"triangle":i=new We(this.Cesium,this.viewer);break;case"space":i=new Ue(this.Cesium,this.viewer);break;case"area":i=new Ke(this.Cesium,this.viewer);break;case"circle":i=new qe(this.Cesium,this.viewer);break;case"polyline":i=new Xe(this.Cesium,this.viewer);break;case"terrainHeight":i=new Je(this.Cesium,this.viewer);break;case"coordinate":i=new Qe(this.Cesium,this.viewer);break;case"rectangle":i=new Ze(this.Cesium,this.viewer);break;case"regularPolygon":i=new et(this.Cesium,this.viewer);break;default:throw new Error(`Unsupported measurement type: ${t}`)}if(!i)return;this.actives.push(i);const o=i,s={...e,onComplete:r=>{var c;const n={id:`m_${Date.now()}_${this.measurements.length}`,type:t,options:(()=>{const d={...e};return"onComplete"in d&&delete d.onComplete,d})(),positions:(()=>{if(Array.isArray(r==null?void 0:r.positions))return r.positions.map(d=>[d.x,d.y,d.z]);switch(t){case"terrainHeight":{const d=r==null?void 0:r.position;return d?[[d.x,d.y,d.z]]:void 0}case"coordinate":{const d=r==null?void 0:r.lnglat;if(d&&typeof d.lng=="number"&&typeof d.lat=="number"){const u=this.Cesium.Cartesian3.fromDegrees(d.lng,d.lat,d.height||0);return[[u.x,u.y,u.z]]}return}default:return}})(),data:this._serializeMetrics(t,r)};this.measurements.push(n),o&&this.recordHandlers.set(n.id,o),this.specifiedClear&&this._showDeleteLabels("html-label-container"),(c=e.onComplete)==null||c.call(e,r);const l=this.actives.indexOf(o);l>=0&&this.actives.splice(l,1)}};i.start(s)}clear(){const t=this.actives.pop();t&&t.clear(),this._removeAllDeleteLabels(),this.specifiedClear=!1}cancel(){const t=this.actives.pop();t&&t.stop()}disableDefaultSelection({disableLeftClick:t=!1,disableDoubleClick:e=!0}={}){var o,s;const i=(s=(o=this.viewer)==null?void 0:o.cesiumWidget)==null?void 0:s.screenSpaceEventHandler;i&&(e&&i.removeInputAction(this.Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK),t&&i.removeInputAction(this.Cesium.ScreenSpaceEventType.LEFT_CLICK))}clearAll(){for(;this.actives.length;){const t=this.actives.pop();try{t==null||t.clear()}catch{}}for(const[,t]of this.recordHandlers)try{t.clear()}catch{}this.recordHandlers.clear(),this.measurements=[],this._removeAllDeleteLabels(),this.specifiedClear=!1}getMeasurementsConfig(){return{measurements:this.measurements.map(t=>({...t,options:t.options?{...t.options}:t.options,positions:t.positions?t.positions.map(e=>[e[0],e[1],e[2]]):t.positions,data:t.data?{...t.data}:t.data}))}}setMeasurementsConfig(t){var e,i;if((e=t==null?void 0:t.measurements)!=null&&e.length){for(const o of t.measurements){let s=null;switch(o.type){case"horizontal":s=new Ye(this.Cesium,this.viewer);break;case"vertical":s=new Ve(this.Cesium,this.viewer);break;case"triangle":s=new We(this.Cesium,this.viewer);break;case"space":s=new Ue(this.Cesium,this.viewer);break;case"area":s=new Ke(this.Cesium,this.viewer);break;case"circle":s=new qe(this.Cesium,this.viewer);break;case"polyline":s=new Xe(this.Cesium,this.viewer);break;case"terrainHeight":s=new Je(this.Cesium,this.viewer);break;case"coordinate":s=new Qe(this.Cesium,this.viewer);break;case"rectangle":s=new Ze(this.Cesium,this.viewer);break;case"regularPolygon":s=new et(this.Cesium,this.viewer);break;default:s=null}(i=s==null?void 0:s.rehydrate)==null||i.call(s,o,void 0),s&&o.id&&this.recordHandlers.set(o.id,s),this.measurements.find(n=>n.id===o.id)||this.measurements.push(o)}this.specifiedClear&&this._showDeleteLabels("html-label-container")}}_serializeMetrics(t,e){switch(t){case"space":return{distance:e==null?void 0:e.distance};case"horizontal":return{distance:e==null?void 0:e.distance};case"vertical":return{vertical:e==null?void 0:e.vertical};case"polyline":return{distance:e==null?void 0:e.distance};case"area":return{area:e==null?void 0:e.area};case"circle":return{radius:e==null?void 0:e.radius,area:e==null?void 0:e.area,perimeter:e==null?void 0:e.perimeter};case"rectangle":return{width:e==null?void 0:e.width,height:e==null?void 0:e.height,area:e==null?void 0:e.area};case"regularPolygon":return{sides:e==null?void 0:e.sides,radius:e==null?void 0:e.radius,perimeter:e==null?void 0:e.perimeter,area:e==null?void 0:e.area};case"triangle":return{lengths:e==null?void 0:e.lengths,angles:e==null?void 0:e.angles};case"terrainHeight":return{terrainHeight:e==null?void 0:e.terrainHeight,difference:e==null?void 0:e.difference,position:e==null?void 0:e.position,zeroPosition:e==null?void 0:e.zeroPosition};case"coordinate":return{lnglat:e==null?void 0:e.lnglat};default:return{}}}_toCartesian(t){const e=this.Cesium;return new e.Cartesian3(t[0],t[1],t[2])}_removeRecordVisual(t){const e=this.viewer;this.Cesium;const i=e.entities.values;for(let r=i.length-1;r>=0;r--){const n=i[r];try{e.entities.remove(n)}catch{}}const o=e.scene.primitives,s=[];o._primitives&&o._primitives.forEach(r=>s.push(r));for(const r of s)try{e.scene.primitives.remove(r)}catch{}this.htmlLabelPool&&this.htmlLabelPool.removeAll()}toggleSpecifiedClear(t){if(this.specifiedClear)this._removeAllDeleteLabels(),this.specifiedClear=!1;else{if(this.specifiedClear=!0,!this.deleteLabelPool){const e=t||"html-label-container";this.deleteLabelPool=new N(this.Cesium,this.viewer,e),this.deleteLabelPool.registerTheme("measure-delete-label",{createElement:(i,o)=>{i.innerHTML="删除",i.style.background="rgba(255,0,0,0.7)",i.style.color="#fff",i.style.font="12px sans-serif",i.style.padding="2px 6px",i.style.borderRadius="4px",i.style.whiteSpace="nowrap"},options:{offset:{x:0,y:-10}}}),this.deleteLabelPool.eventBus.addListener(V.Click,{name:"measurement_delete_label_click",fn:i=>{var s;if(!i||i.theme!=="measure-delete-label")return;const o=(s=i==null?void 0:i.data)==null?void 0:s.recordId;o&&this.deleteMeasurement(o)}},!0)}this._showDeleteLabels(t||"html-label-container")}}deleteMeasurement(t){const e=this.recordHandlers.get(t);if(e)try{e.clear()}catch{}this.recordHandlers.delete(t),this.measurements=this.measurements.filter(o=>o.id!==t);const i=this.deleteLabelIds.get(t);i&&this.deleteLabelPool&&this.deleteLabelPool.removeByIds([i]),this.deleteLabelIds.delete(t)}_showDeleteLabels(t){if(!this.deleteLabelPool)return;const e=this.Cesium;for(const i of this.measurements){const o="m_del_"+i.id;if(this.deleteLabelIds.has(i.id))continue;const s=this._computeRecordCenter(i);if(!s)continue;const r=e.Cartographic.fromCartesian(s),n=e.Math.toDegrees(r.longitude),l=e.Math.toDegrees(r.latitude),c=r.height||0;this.deleteLabelPool.add({recordId:i.id},{id:o,lon:n,lat:l,height:c,theme:"measure-delete-label",show:!0,style:{zIndex:"1000"}}),this.deleteLabelIds.set(i.id,o)}}_removeAllDeleteLabels(){if(this.deleteLabelPool){const t=Array.from(this.deleteLabelIds.values());t.length&&this.deleteLabelPool.removeByIds(t)}this.deleteLabelIds.clear()}_computeRecordCenter(t){var o,s;const e=this.Cesium,i=(t.positions||[]).map(r=>this._toCartesian(r));if(i.length>0){const r=i.reduce((c,d)=>c+d.x,0)/i.length,n=i.reduce((c,d)=>c+d.y,0)/i.length,l=i.reduce((c,d)=>c+d.z,0)/i.length;return new e.Cartesian3(r,n,l)}if(t.type==="coordinate"&&((o=t.data)!=null&&o.lnglat)){const r=t.data.lnglat.lng,n=t.data.lnglat.lat,l=t.data.lnglat.height||0;return e.Cartesian3.fromDegrees(r,n,l)}if(t.type==="terrainHeight"&&((s=t.data)!=null&&s.position)){const r=t.data.position;return new e.Cartesian3(r.x,r.y,r.z)}return null}}class Do{constructor({Cesium:t,viewer:e}){h(this,"Cesium");h(this,"viewer");h(this,"options",null);h(this,"entity",null);h(this,"viewEntities",[]);h(this,"startTime",null);h(this,"stopTime",null);h(this,"isPaused",!1);h(this,"lastTime",null);h(this,"onTick",t=>{if(!this.options||!this.entity)return;const e=t.currentTime;if(this.Cesium.JulianDate.lessThan(e,this.startTime)||this.Cesium.JulianDate.greaterThan(e,this.stopTime)){!this.options.loop&&this.Cesium.JulianDate.greaterThan(e,this.stopTime)&&this.viewer.clock.shouldAnimate&&(this.viewer.clock.shouldAnimate=!1,this.options.onComplete&&this.options.onComplete());return}const i=this.entity.position.getValue(e),o=this.entity.orientation.getValue(e);if(i&&o){const s=this.Cesium.Matrix4.fromTranslationQuaternionRotationScale(i,o,new this.Cesium.Cartesian3(1,1,1),new this.Cesium.Matrix4),r=this.Cesium.Transforms.fixedFrameToHeadingPitchRoll(s,this.viewer.scene.globe.ellipsoid,this.Cesium.Transforms.eastNorthUpToFixedFrame,new this.Cesium.HeadingPitchRoll);this.viewer.camera.setView({destination:i,orientation:{heading:r.heading,pitch:r.pitch,roll:r.roll}}),this.options.onTick&&this.options.onTick(e,i,r)}});this.Cesium=t,this.viewer=e}get Viewer(){return this.viewer}get CesiumInstance(){return this.Cesium}start(t){this.clear(),this.options=t,!((t.waypoints||[]).length<2)&&(this._setupEntities(t),this.viewer.clock.startTime=this.startTime.clone(),this.viewer.clock.stopTime=this.stopTime.clone(),this.viewer.clock.currentTime=this.startTime.clone(),this.viewer.clock.clockRange=t.loop?this.Cesium.ClockRange.LOOP_STOP:this.Cesium.ClockRange.CLAMPED,this.viewer.clock.multiplier=1,this.viewer.clock.shouldAnimate=!0,this.viewer.clock.onTick.addEventListener(this.onTick))}preview(t){this.clear(),this.options=t,!((t.waypoints||[]).length<2)&&this._setupEntities(t)}_setupEntities(t){const e=t.waypoints||[],i=new this.Cesium.SampledPositionProperty,o=new this.Cesium.SampledProperty(this.Cesium.Quaternion),s=[];for(const u of e){let m;u.destination?u.destination.x!==void 0?m=new this.Cesium.Cartesian3(u.destination.x,u.destination.y,u.destination.z):m=u.destination:u.lon!==void 0&&u.lat!==void 0&&(m=this.Cesium.Cartesian3.fromDegrees(u.lon,u.lat,u.height??0));let g;u.orientation?g=new this.Cesium.HeadingPitchRoll(u.orientation.heading,u.orientation.pitch,u.orientation.roll):g=this.Cesium.HeadingPitchRoll.fromDegrees(u.heading??0,u.pitch??-30,u.roll??0);const p=this.Cesium.Transforms.headingPitchRollQuaternion(m,g);s.push({position:m,orientation:p})}const r=this.Cesium.JulianDate.now(),n=t.speed||100;let l=0;const c=[];for(let u=0;u<s.length;u++){if(u===0)c.push(r.clone());else{const g=this.Cesium.Cartesian3.distance(s[u-1].position,s[u].position)/Math.max(n,.1);l+=g,c.push(this.Cesium.JulianDate.addSeconds(r,l,new this.Cesium.JulianDate))}i.addSample(c[u],s[u].position),o.addSample(c[u],s[u].orientation)}this.startTime=c[0],this.stopTime=c[c.length-1];const d={availability:new this.Cesium.TimeIntervalCollection([new this.Cesium.TimeInterval({start:this.startTime,stop:this.stopTime})]),position:i,orientation:o};t.modelUrl?d.model={uri:t.modelUrl,scale:t.modelScale??1,minimumPixelSize:64,runAnimations:t.modelAnimate??!0}:d.point={pixelSize:1,color:this.Cesium.Color.TRANSPARENT},t.showPath&&this.viewEntities.push(this.viewer.entities.add({polyline:{positions:s.map(u=>u.position),width:3,material:this.Cesium.Color.GREEN}})),this.entity=this.viewer.entities.add(d),t.showStops&&s.forEach((u,m)=>{const g=this.Cesium.Cartographic.fromCartesian(u.position),p=this.Cesium.Cartesian3.fromRadians(g.longitude,g.latitude,0);this.viewEntities.push(this.viewer.entities.add({position:u.position,point:{pixelSize:8,color:this.Cesium.Color.YELLOW,outlineColor:this.Cesium.Color.BLACK,outlineWidth:1},label:{text:""+(m+1),font:"12px sans-serif",pixelOffset:new this.Cesium.Cartesian2(0,-15),fillColor:this.Cesium.Color.WHITE,outlineColor:this.Cesium.Color.BLACK,outlineWidth:2,style:this.Cesium.LabelStyle.FILL_AND_OUTLINE},polyline:{positions:[u.position,p],width:2,material:new this.Cesium.PolylineDashMaterialProperty({color:this.Cesium.Color.RED,dashLength:16})}}))})}stop(){this.viewer.clock.shouldAnimate=!1,this.viewer.clock.onTick.removeEventListener(this.onTick)}pause(){this.viewer.clock.shouldAnimate=!1,this.isPaused=!0}resume(){this.viewer.clock.shouldAnimate=!0,this.isPaused=!1}clear(){this.stop(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null);for(const t of this.viewEntities)this.viewer.entities.remove(t);this.viewEntities=[],this.options=null}captureCurrentView(){const t=this.viewer.camera.position.clone(),e=this.viewer.camera.heading,i=this.viewer.camera.pitch,o=this.viewer.camera.roll;return{destination:{x:t.x,y:t.y,z:t.z},orientation:{heading:e,pitch:i,roll:o}}}}class So{constructor({Cesium:t,viewer:e}){h(this,"Cesium");h(this,"viewer");h(this,"entity",null);h(this,"positionProperty",null);h(this,"startTime",null);h(this,"stopTime",null);h(this,"options",null);h(this,"cameraOffset",null);h(this,"onTick",t=>{if(!this.options||!this.positionProperty)return;const e=t.currentTime,i=this.positionProperty.getValue(e);if(this.options.followCamera&&this.options.initialView&&i){this.cameraOffset||(this.cameraOffset=this.Cesium.Cartesian3.subtract(this.options.initialView.destination,i,new this.Cesium.Cartesian3));const o=this.Cesium.Cartesian3.add(i,this.cameraOffset,new this.Cesium.Cartesian3);this.viewer.camera.setView({destination:o,orientation:this.options.initialView.orientation})}i&&this.options.onTick&&this.options.onTick(e,i),this.Cesium.JulianDate.greaterThanOrEquals(e,this.stopTime)&&(this.options.loop||(this.options.onComplete&&this.options.onComplete(),this.stop()))});this.Cesium=t,this.viewer=e}get Viewer(){return this.viewer}get CesiumInstance(){return this.Cesium}start(t){this.clear(),this.options=t;const e=this.normalizePositions(t.positions||[]);if(!e.length)return;const i=t.speed??30,o=this.buildTimes(e,i),s=new this.Cesium.SampledPositionProperty;for(let g=0;g<e.length;g++)s.addSample(o[g],e[g]);this.positionProperty=s;const r=new this.Cesium.VelocityOrientationProperty(s),n=t.showPath??!0,l=t.pathColor??this.Cesium.Color.YELLOW,c=t.pathWidth??3,d=t.pointColor??this.Cesium.Color.RED,u=t.pointPixelSize??8,m={availability:new this.Cesium.TimeIntervalCollection([new this.Cesium.TimeInterval({start:this.startTime,stop:this.stopTime})]),position:s,orientation:r,path:n?{material:l,width:c,leadTime:0}:void 0};t.modelUrl?m.model={uri:t.modelUrl,scale:t.modelScale??1,minimumPixelSize:64,runAnimations:t.modelAnimate??!0}:m.point={color:d,pixelSize:u},this.entity=this.viewer.entities.add(m),this.viewer.clock.startTime=this.startTime.clone(),this.viewer.clock.stopTime=this.stopTime.clone(),this.viewer.clock.currentTime=this.startTime.clone(),this.viewer.clock.clockRange=t.loop?this.Cesium.ClockRange.LOOP_STOP:this.Cesium.ClockRange.CLAMPED,this.viewer.clock.multiplier=1,this.viewer.clock.shouldAnimate=!0,t.initialView?(this.viewer.camera.setView({destination:t.initialView.destination,orientation:t.initialView.orientation}),this.cameraOffset=null):t.followCamera?this.viewer.trackedEntity=this.entity:t.lookAtOffset&&this.viewer.camera.lookAt(this.entity.position,t.lookAtOffset),this.viewer.clock.onTick.addEventListener(this.onTick)}stop(){this.viewer.clock.shouldAnimate=!1,this.viewer.clock.onTick.removeEventListener(this.onTick),this.viewer.trackedEntity===this.entity&&(this.viewer.trackedEntity=void 0)}clear(){this.stop(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.positionProperty=null,this.startTime=null,this.stopTime=null,this.options=null;try{this.viewer.camera.lookAtTransform(this.Cesium.Matrix4.IDENTITY)}catch{}}normalizePositions(t){const e=[];for(const i of t)if(Array.isArray(i)){const[o,s,r]=i;e.push(this.Cesium.Cartesian3.fromDegrees(o,s,r??0))}else(i==null?void 0:i.x)!==void 0&&(i==null?void 0:i.y)!==void 0&&(i==null?void 0:i.z)!==void 0&&e.push(i);return e}buildTimes(t,e){const i=[],o=this.Cesium.JulianDate.now();let s=0;for(let r=0;r<t.length;r++)if(r===0)i.push(o.clone());else{const n=this.Cesium.Cartesian3.distance(t[r-1],t[r]);s+=n/Math.max(e,.1),i.push(this.Cesium.JulianDate.addSeconds(o,s,new this.Cesium.JulianDate))}return this.startTime=i[0],this.stopTime=i[i.length-1],i}}D.AreaMeasure=Ke,D.BufferedHierarchicalAggregator=te,D.CameraRoamTool=Do,D.CircleMeasure=qe,D.CoordinateMeasure=Qe,D.DOM_EVENT_MAP=it,D.DrawTool=Wt,D.EditMode=zt,D.EntityLayerManager=Io,D.GLTFManage=vo,D.GLTFManageEventKey=Nt,D.HorizontalMeasure=Ye,D.HtmlOverlayLabelPool=N,D.MarkerEventBus=tt,D.MarkerEventKey=V,D.MaterialManager=Lo,D.MeasurementTool=_o,D.PathRoamTool=So,D.PolylineDistanceMeasure=Xe,D.PrimitiveManager=xo,D.RectangleMeasure=Ze,D.RegularPolygonMeasure=et,D.SpaceMeasure=Ue,D.TerrainHeightMeasure=Je,D.TooltipManager=xe,D.TriangleMeasure=We,D.VerticalMeasure=Ve,D.convertGeoJsonToEntityData=To,D.getDynamicImgMaterial=Co,D.getPolylineFlowMaterialProperty=Po,D.getWallMaterial=bo,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})}));
|
|
76
|
+
${b.area}:${y.toFixed(2)} m²`},{id:C,lon:i.Math.toDegrees(v.longitude),lat:i.Math.toDegrees(v.latitude),height:v.height||0,theme:"measure-regular",show:!0})}buildRegularPolygonPoints(t,e,i){const n=this.Cesium,s=new n.EllipsoidTangentPlane(t,n.Ellipsoid.WGS84),o=2*Math.PI/i,r=[];for(let d=0;d<i;d++){const u=d*o,m=e*Math.cos(u),g=e*Math.sin(u);r.push(new n.Cartesian2(m,g))}const c=s.projectPointsOntoEllipsoid(r).slice();return c.push(c[0]),c}computeAreaByPlane(t){const e=this.Cesium,i=new e.Cartesian3(t.reduce((r,l)=>r+l.x,0)/t.length,t.reduce((r,l)=>r+l.y,0)/t.length,t.reduce((r,l)=>r+l.z,0)/t.length),s=new e.EllipsoidTangentPlane(i,e.Ellipsoid.WGS84).projectPointsOntoPlane(t);let o=0;for(let r=0;r<s.length;r++){const l=(r+1)%s.length;o+=s[r].x*s[l].y-s[l].x*s[r].y}return Math.abs(o)/2}}class Dn{constructor({Cesium:t,viewer:e}){h(this,"Cesium");h(this,"viewer");h(this,"actives",[]);h(this,"measurements",[]);h(this,"htmlLabelPool",null);h(this,"recordHandlers",new Map);h(this,"specifiedClear",!1);h(this,"deleteLabelPool",null);h(this,"deleteLabelIds",new Map);this.Cesium=t,this.viewer=e,e.screenSpaceEventHandler.removeInputAction(t.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)}measure(t,e){let i=null;switch(t){case"horizontal":i=new Ye(this.Cesium,this.viewer);break;case"vertical":i=new Ve(this.Cesium,this.viewer);break;case"triangle":i=new We(this.Cesium,this.viewer);break;case"space":i=new Ue(this.Cesium,this.viewer);break;case"area":i=new Ke(this.Cesium,this.viewer);break;case"circle":i=new qe(this.Cesium,this.viewer);break;case"polyline":i=new Xe(this.Cesium,this.viewer);break;case"terrainHeight":i=new Je(this.Cesium,this.viewer);break;case"coordinate":i=new Qe(this.Cesium,this.viewer);break;case"rectangle":i=new Ze(this.Cesium,this.viewer);break;case"regularPolygon":i=new et(this.Cesium,this.viewer);break;default:throw new Error(`Unsupported measurement type: ${t}`)}if(!i)return;this.actives.push(i);const n=i,s={...e,onComplete:o=>{var c;const r={id:`m_${Date.now()}_${this.measurements.length}`,type:t,options:(()=>{const d={...e};return"onComplete"in d&&delete d.onComplete,d})(),positions:(()=>{if(Array.isArray(o==null?void 0:o.positions))return o.positions.map(d=>[d.x,d.y,d.z]);switch(t){case"terrainHeight":{const d=o==null?void 0:o.position;return d?[[d.x,d.y,d.z]]:void 0}case"coordinate":{const d=o==null?void 0:o.lnglat;if(d&&typeof d.lng=="number"&&typeof d.lat=="number"){const u=this.Cesium.Cartesian3.fromDegrees(d.lng,d.lat,d.height||0);return[[u.x,u.y,u.z]]}return}default:return}})(),data:this._serializeMetrics(t,o)};this.measurements.push(r),n&&this.recordHandlers.set(r.id,n),this.specifiedClear&&this._showDeleteLabels("html-label-container"),(c=e.onComplete)==null||c.call(e,o);const l=this.actives.indexOf(n);l>=0&&this.actives.splice(l,1)}};i.start(s)}clear(){const t=this.actives.pop();t&&t.clear(),this._removeAllDeleteLabels(),this.specifiedClear=!1}cancel(){const t=this.actives.pop();t&&t.stop()}disableDefaultSelection({disableLeftClick:t=!1,disableDoubleClick:e=!0}={}){var n,s;const i=(s=(n=this.viewer)==null?void 0:n.cesiumWidget)==null?void 0:s.screenSpaceEventHandler;i&&(e&&i.removeInputAction(this.Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK),t&&i.removeInputAction(this.Cesium.ScreenSpaceEventType.LEFT_CLICK))}clearAll(){for(;this.actives.length;){const t=this.actives.pop();try{t==null||t.clear()}catch{}}for(const[,t]of this.recordHandlers)try{t.clear()}catch{}this.recordHandlers.clear(),this.measurements=[],this._removeAllDeleteLabels(),this.specifiedClear=!1}getMeasurementsConfig(){return{measurements:this.measurements.map(t=>({...t,options:t.options?{...t.options}:t.options,positions:t.positions?t.positions.map(e=>[e[0],e[1],e[2]]):t.positions,data:t.data?{...t.data}:t.data}))}}setMeasurementsConfig(t){var e,i;if((e=t==null?void 0:t.measurements)!=null&&e.length){for(const n of t.measurements){let s=null;switch(n.type){case"horizontal":s=new Ye(this.Cesium,this.viewer);break;case"vertical":s=new Ve(this.Cesium,this.viewer);break;case"triangle":s=new We(this.Cesium,this.viewer);break;case"space":s=new Ue(this.Cesium,this.viewer);break;case"area":s=new Ke(this.Cesium,this.viewer);break;case"circle":s=new qe(this.Cesium,this.viewer);break;case"polyline":s=new Xe(this.Cesium,this.viewer);break;case"terrainHeight":s=new Je(this.Cesium,this.viewer);break;case"coordinate":s=new Qe(this.Cesium,this.viewer);break;case"rectangle":s=new Ze(this.Cesium,this.viewer);break;case"regularPolygon":s=new et(this.Cesium,this.viewer);break;default:s=null}(i=s==null?void 0:s.rehydrate)==null||i.call(s,n,void 0),s&&n.id&&this.recordHandlers.set(n.id,s),this.measurements.find(r=>r.id===n.id)||this.measurements.push(n)}this.specifiedClear&&this._showDeleteLabels("html-label-container")}}_serializeMetrics(t,e){switch(t){case"space":return{distance:e==null?void 0:e.distance};case"horizontal":return{distance:e==null?void 0:e.distance};case"vertical":return{vertical:e==null?void 0:e.vertical};case"polyline":return{distance:e==null?void 0:e.distance};case"area":return{area:e==null?void 0:e.area};case"circle":return{radius:e==null?void 0:e.radius,area:e==null?void 0:e.area,perimeter:e==null?void 0:e.perimeter};case"rectangle":return{width:e==null?void 0:e.width,height:e==null?void 0:e.height,area:e==null?void 0:e.area};case"regularPolygon":return{sides:e==null?void 0:e.sides,radius:e==null?void 0:e.radius,perimeter:e==null?void 0:e.perimeter,area:e==null?void 0:e.area};case"triangle":return{lengths:e==null?void 0:e.lengths,angles:e==null?void 0:e.angles};case"terrainHeight":return{terrainHeight:e==null?void 0:e.terrainHeight,difference:e==null?void 0:e.difference,position:e==null?void 0:e.position,zeroPosition:e==null?void 0:e.zeroPosition};case"coordinate":return{lnglat:e==null?void 0:e.lnglat};default:return{}}}_toCartesian(t){const e=this.Cesium;return new e.Cartesian3(t[0],t[1],t[2])}_removeRecordVisual(t){const e=this.viewer;this.Cesium;const i=e.entities.values;for(let o=i.length-1;o>=0;o--){const r=i[o];try{e.entities.remove(r)}catch{}}const n=e.scene.primitives,s=[];n._primitives&&n._primitives.forEach(o=>s.push(o));for(const o of s)try{e.scene.primitives.remove(o)}catch{}this.htmlLabelPool&&this.htmlLabelPool.removeAll()}toggleSpecifiedClear(t){if(this.specifiedClear)this._removeAllDeleteLabels(),this.specifiedClear=!1;else{if(this.specifiedClear=!0,!this.deleteLabelPool){const e=t||"html-label-container";this.deleteLabelPool=new N(this.Cesium,this.viewer,e),this.deleteLabelPool.registerTheme("measure-delete-label",{createElement:(i,n)=>{i.innerHTML="删除",i.style.background="rgba(255,0,0,0.7)",i.style.color="#fff",i.style.font="12px sans-serif",i.style.padding="2px 6px",i.style.borderRadius="4px",i.style.whiteSpace="nowrap"},options:{offset:{x:0,y:-10}}}),this.deleteLabelPool.eventBus.addListener(V.Click,{name:"measurement_delete_label_click",fn:i=>{var s;if(!i||i.theme!=="measure-delete-label")return;const n=(s=i==null?void 0:i.data)==null?void 0:s.recordId;n&&this.deleteMeasurement(n)}},!0)}this._showDeleteLabels(t||"html-label-container")}}deleteMeasurement(t){const e=this.recordHandlers.get(t);if(e)try{e.clear()}catch{}this.recordHandlers.delete(t),this.measurements=this.measurements.filter(n=>n.id!==t);const i=this.deleteLabelIds.get(t);i&&this.deleteLabelPool&&this.deleteLabelPool.removeByIds([i]),this.deleteLabelIds.delete(t)}_showDeleteLabels(t){if(!this.deleteLabelPool)return;const e=this.Cesium;for(const i of this.measurements){const n="m_del_"+i.id;if(this.deleteLabelIds.has(i.id))continue;const s=this._computeRecordCenter(i);if(!s)continue;const o=e.Cartographic.fromCartesian(s),r=e.Math.toDegrees(o.longitude),l=e.Math.toDegrees(o.latitude),c=o.height||0;this.deleteLabelPool.add({recordId:i.id},{id:n,lon:r,lat:l,height:c,theme:"measure-delete-label",show:!0,style:{zIndex:"1000"}}),this.deleteLabelIds.set(i.id,n)}}_removeAllDeleteLabels(){if(this.deleteLabelPool){const t=Array.from(this.deleteLabelIds.values());t.length&&this.deleteLabelPool.removeByIds(t)}this.deleteLabelIds.clear()}_computeRecordCenter(t){var n,s;const e=this.Cesium,i=(t.positions||[]).map(o=>this._toCartesian(o));if(i.length>0){const o=i.reduce((c,d)=>c+d.x,0)/i.length,r=i.reduce((c,d)=>c+d.y,0)/i.length,l=i.reduce((c,d)=>c+d.z,0)/i.length;return new e.Cartesian3(o,r,l)}if(t.type==="coordinate"&&((n=t.data)!=null&&n.lnglat)){const o=t.data.lnglat.lng,r=t.data.lnglat.lat,l=t.data.lnglat.height||0;return e.Cartesian3.fromDegrees(o,r,l)}if(t.type==="terrainHeight"&&((s=t.data)!=null&&s.position)){const o=t.data.position;return new e.Cartesian3(o.x,o.y,o.z)}return null}}class Sn{constructor({Cesium:t,viewer:e}){h(this,"Cesium");h(this,"viewer");h(this,"options",null);h(this,"entity",null);h(this,"viewEntities",[]);h(this,"startTime",null);h(this,"stopTime",null);h(this,"isPaused",!1);h(this,"lastTime",null);h(this,"onTick",t=>{if(!this.options||!this.entity)return;const e=t.currentTime;if(this.Cesium.JulianDate.lessThan(e,this.startTime)||this.Cesium.JulianDate.greaterThan(e,this.stopTime)){!this.options.loop&&this.Cesium.JulianDate.greaterThan(e,this.stopTime)&&this.viewer.clock.shouldAnimate&&(this.viewer.clock.shouldAnimate=!1,this.options.onComplete&&this.options.onComplete());return}const i=this.entity.position.getValue(e),n=this.entity.orientation.getValue(e);if(i&&n){const s=this.Cesium.Matrix4.fromTranslationQuaternionRotationScale(i,n,new this.Cesium.Cartesian3(1,1,1),new this.Cesium.Matrix4),o=this.Cesium.Transforms.fixedFrameToHeadingPitchRoll(s,this.viewer.scene.globe.ellipsoid,this.Cesium.Transforms.eastNorthUpToFixedFrame,new this.Cesium.HeadingPitchRoll);this.viewer.camera.setView({destination:i,orientation:{heading:o.heading,pitch:o.pitch,roll:o.roll}}),this.options.onTick&&this.options.onTick(e,i,o)}});this.Cesium=t,this.viewer=e}get Viewer(){return this.viewer}get CesiumInstance(){return this.Cesium}start(t){this.clear(),this.options=t,!((t.waypoints||[]).length<2)&&(this._setupEntities(t),this.viewer.clock.startTime=this.startTime.clone(),this.viewer.clock.stopTime=this.stopTime.clone(),this.viewer.clock.currentTime=this.startTime.clone(),this.viewer.clock.clockRange=t.loop?this.Cesium.ClockRange.LOOP_STOP:this.Cesium.ClockRange.CLAMPED,this.viewer.clock.multiplier=1,this.viewer.clock.shouldAnimate=!0,this.viewer.clock.onTick.addEventListener(this.onTick))}preview(t){this.clear(),this.options=t,!((t.waypoints||[]).length<2)&&this._setupEntities(t)}_setupEntities(t){const e=t.waypoints||[],i=new this.Cesium.SampledPositionProperty,n=new this.Cesium.SampledProperty(this.Cesium.Quaternion),s=[];for(const u of e){let m;u.destination?u.destination.x!==void 0?m=new this.Cesium.Cartesian3(u.destination.x,u.destination.y,u.destination.z):m=u.destination:u.lon!==void 0&&u.lat!==void 0&&(m=this.Cesium.Cartesian3.fromDegrees(u.lon,u.lat,u.height??0));let g;u.orientation?g=new this.Cesium.HeadingPitchRoll(u.orientation.heading,u.orientation.pitch,u.orientation.roll):g=this.Cesium.HeadingPitchRoll.fromDegrees(u.heading??0,u.pitch??-30,u.roll??0);const p=this.Cesium.Transforms.headingPitchRollQuaternion(m,g);s.push({position:m,orientation:p})}const o=this.Cesium.JulianDate.now(),r=t.speed||100;let l=0;const c=[];for(let u=0;u<s.length;u++){if(u===0)c.push(o.clone());else{const g=this.Cesium.Cartesian3.distance(s[u-1].position,s[u].position)/Math.max(r,.1);l+=g,c.push(this.Cesium.JulianDate.addSeconds(o,l,new this.Cesium.JulianDate))}i.addSample(c[u],s[u].position),n.addSample(c[u],s[u].orientation)}this.startTime=c[0],this.stopTime=c[c.length-1];const d={availability:new this.Cesium.TimeIntervalCollection([new this.Cesium.TimeInterval({start:this.startTime,stop:this.stopTime})]),position:i,orientation:n};t.modelUrl?d.model={uri:t.modelUrl,scale:t.modelScale??1,minimumPixelSize:64,runAnimations:t.modelAnimate??!0}:d.point={pixelSize:1,color:this.Cesium.Color.TRANSPARENT},t.showPath&&this.viewEntities.push(this.viewer.entities.add({polyline:{positions:s.map(u=>u.position),width:3,material:this.Cesium.Color.GREEN}})),this.entity=this.viewer.entities.add(d),t.showStops&&s.forEach((u,m)=>{const g=this.Cesium.Cartographic.fromCartesian(u.position),p=this.Cesium.Cartesian3.fromRadians(g.longitude,g.latitude,0);this.viewEntities.push(this.viewer.entities.add({position:u.position,point:{pixelSize:8,color:this.Cesium.Color.YELLOW,outlineColor:this.Cesium.Color.BLACK,outlineWidth:1},label:{text:""+(m+1),font:"12px sans-serif",pixelOffset:new this.Cesium.Cartesian2(0,-15),fillColor:this.Cesium.Color.WHITE,outlineColor:this.Cesium.Color.BLACK,outlineWidth:2,style:this.Cesium.LabelStyle.FILL_AND_OUTLINE},polyline:{positions:[u.position,p],width:2,material:new this.Cesium.PolylineDashMaterialProperty({color:this.Cesium.Color.RED,dashLength:16})}}))})}stop(){this.viewer.clock.shouldAnimate=!1,this.viewer.clock.onTick.removeEventListener(this.onTick)}pause(){this.viewer.clock.shouldAnimate=!1,this.isPaused=!0}resume(){this.viewer.clock.shouldAnimate=!0,this.isPaused=!1}clear(){this.stop(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null);for(const t of this.viewEntities)this.viewer.entities.remove(t);this.viewEntities=[],this.options=null}captureCurrentView(){const t=this.viewer.camera.position.clone(),e=this.viewer.camera.heading,i=this.viewer.camera.pitch,n=this.viewer.camera.roll;return{destination:{x:t.x,y:t.y,z:t.z},orientation:{heading:e,pitch:i,roll:n}}}}class An{constructor({Cesium:t,viewer:e}){h(this,"Cesium");h(this,"viewer");h(this,"entity",null);h(this,"positionProperty",null);h(this,"startTime",null);h(this,"stopTime",null);h(this,"options",null);h(this,"cameraOffset",null);h(this,"onTick",t=>{if(!this.options||!this.positionProperty)return;const e=t.currentTime,i=this.positionProperty.getValue(e);if(this.options.followCamera&&this.options.initialView&&i){this.cameraOffset||(this.cameraOffset=this.Cesium.Cartesian3.subtract(this.options.initialView.destination,i,new this.Cesium.Cartesian3));const n=this.Cesium.Cartesian3.add(i,this.cameraOffset,new this.Cesium.Cartesian3);this.viewer.camera.setView({destination:n,orientation:this.options.initialView.orientation})}i&&this.options.onTick&&this.options.onTick(e,i),this.Cesium.JulianDate.greaterThanOrEquals(e,this.stopTime)&&(this.options.loop||(this.options.onComplete&&this.options.onComplete(),this.stop()))});this.Cesium=t,this.viewer=e}get Viewer(){return this.viewer}get CesiumInstance(){return this.Cesium}start(t){this.clear(),this.options=t;const e=this.normalizePositions(t.positions||[]);if(!e.length)return;const i=t.speed??30,n=this.buildTimes(e,i),s=new this.Cesium.SampledPositionProperty;for(let g=0;g<e.length;g++)s.addSample(n[g],e[g]);this.positionProperty=s;const o=new this.Cesium.VelocityOrientationProperty(s),r=t.showPath??!0,l=t.pathColor??this.Cesium.Color.YELLOW,c=t.pathWidth??3,d=t.pointColor??this.Cesium.Color.RED,u=t.pointPixelSize??8,m={availability:new this.Cesium.TimeIntervalCollection([new this.Cesium.TimeInterval({start:this.startTime,stop:this.stopTime})]),position:s,orientation:o,path:r?{material:l,width:c,leadTime:0}:void 0};t.modelUrl?m.model={uri:t.modelUrl,scale:t.modelScale??1,minimumPixelSize:64,runAnimations:t.modelAnimate??!0}:m.point={color:d,pixelSize:u},this.entity=this.viewer.entities.add(m),this.viewer.clock.startTime=this.startTime.clone(),this.viewer.clock.stopTime=this.stopTime.clone(),this.viewer.clock.currentTime=this.startTime.clone(),this.viewer.clock.clockRange=t.loop?this.Cesium.ClockRange.LOOP_STOP:this.Cesium.ClockRange.CLAMPED,this.viewer.clock.multiplier=1,this.viewer.clock.shouldAnimate=!0,t.initialView?(this.viewer.camera.setView({destination:t.initialView.destination,orientation:t.initialView.orientation}),this.cameraOffset=null):t.followCamera?this.viewer.trackedEntity=this.entity:t.lookAtOffset&&this.viewer.camera.lookAt(this.entity.position,t.lookAtOffset),this.viewer.clock.onTick.addEventListener(this.onTick)}stop(){this.viewer.clock.shouldAnimate=!1,this.viewer.clock.onTick.removeEventListener(this.onTick),this.viewer.trackedEntity===this.entity&&(this.viewer.trackedEntity=void 0)}clear(){this.stop(),this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this.positionProperty=null,this.startTime=null,this.stopTime=null,this.options=null;try{this.viewer.camera.lookAtTransform(this.Cesium.Matrix4.IDENTITY)}catch{}}normalizePositions(t){const e=[];for(const i of t)if(Array.isArray(i)){const[n,s,o]=i;e.push(this.Cesium.Cartesian3.fromDegrees(n,s,o??0))}else(i==null?void 0:i.x)!==void 0&&(i==null?void 0:i.y)!==void 0&&(i==null?void 0:i.z)!==void 0&&e.push(i);return e}buildTimes(t,e){const i=[],n=this.Cesium.JulianDate.now();let s=0;for(let o=0;o<t.length;o++)if(o===0)i.push(n.clone());else{const r=this.Cesium.Cartesian3.distance(t[o-1],t[o]);s+=r/Math.max(e,.1),i.push(this.Cesium.JulianDate.addSeconds(n,s,new this.Cesium.JulianDate))}return this.startTime=i[0],this.stopTime=i[i.length-1],i}}S.AreaMeasure=Ke,S.BufferedHierarchicalAggregator=te,S.CameraRoamTool=Sn,S.CircleMeasure=qe,S.CoordinateMeasure=Qe,S.DOM_EVENT_MAP=it,S.DrawTool=Wt,S.EditMode=zt,S.EntityLayerManager=Tn,S.GLTFManage=Cn,S.GLTFManageEventKey=Nt,S.HorizontalMeasure=Ye,S.HtmlOverlayLabelPool=N,S.MarkerEventBus=tt,S.MarkerEventKey=V,S.MaterialManager=En,S.MeasurementTool=Dn,S.PathRoamTool=An,S.PolylineDistanceMeasure=Xe,S.PrimitiveManager=xn,S.RectangleMeasure=Ze,S.RegularPolygonMeasure=et,S.SpaceMeasure=Ue,S.TerrainHeightMeasure=Je,S.TooltipManager=_e,S.TriangleMeasure=We,S.VerticalMeasure=Ve,S.convertGeoJsonToEntityData=_n,S.getDynamicImgMaterial=bn,S.getPolylineFlowMaterialProperty=Ln,S.getWallMaterial=Pn,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})}));
|
|
77
77
|
//# sourceMappingURL=cesium-core.umd.js.map
|