leiting-bim 2.1.162 → 2.1.163

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.
@@ -1,4 +1,4 @@
1
- (function(A,te){typeof exports=="object"&&typeof module<"u"?te(exports):typeof define=="function"&&define.amd?define(["exports"],te):(A=typeof globalThis<"u"?globalThis:A||self,te(A.CesiumCore={}))})(this,(function(A){"use strict";var Ro=Object.defineProperty;var zo=(A,te,V)=>te in A?Ro(A,te,{enumerable:!0,configurable:!0,writable:!0,value:V}):A[te]=V;var l=(A,te,V)=>zo(A,typeof te!="symbol"?te+"":te,V);class te{constructor(t,e,i){l(this,"Cesium");l(this,"viewer");l(this,"labelPool");l(this,"threshold");l(this,"displayLimit");l(this,"maxLevel");l(this,"debugCurrentGrids");l(this,"levels");l(this,"points",[]);l(this,"gridLayers",new Map);l(this,"debugGrids",[]);l(this,"_updateFn");l(this,"clusterTheme");l(this,"pointTheme");l(this,"centralPointMode");l(this,"minGlobalPointCount");l(this,"groupByTheme");l(this,"tilingScheme");l(this,"terrainLevelOffset");l(this,"debugTileCoordLayer",null);l(this,"levelIndexByTileLevel",new Map);l(this,"_lastTileProvider",null);l(this,"_updateTimer",null);l(this,"_updateDelay",100);l(this,"_tilesRetryCount",0);l(this,"_tilesRetryMax",100);l(this,"_cameraDirty",!1);l(this,"_tileLoadListener",null);l(this,"_cameraChangedHandler",null);l(this,"defaultMinLevel",0);l(this,"defaultMaxLevel",28);l(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=h=>{h===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,h;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?(h=i.data)==null?void 0:h.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,h]of o.groups.entries()){const c=h.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 h of this.levels){const c=h.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 h=Math.abs(this.levels[r].level-t);h<o&&(o=h,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,h=r&&s.camera.computeViewRectangle(r),c=(d,u,m)=>{if(!n||!h)return!0;const g=this.tilingScheme.tileXYToRectangle(d,u,m);return!(!g||g.east<=h.west||g.west>=h.east||g.north<=h.south||g.south>=h.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,S=Math.floor(w/$),O=Math.floor(y/$),_=`${f}_${S}_${O}`;if(i.has(_))continue;i.add(_),e(p,S,O,m)}else{const S=1<<Math.min(-T,this.maxRefineLevels),O=w*S,_=y*S;for(let k=0;k<S;k++)for(let F=0;F<S;F++){const G=O+k,B=_+F;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),D=Math.floor((P- -90)/C),x=Math.floor((L- -90)/C);for(let T=E;T<=I;T++)for(let $=D;$<=x;$++){if(!c(T,$,f))continue;const S=`${f}_${T}_${$}`;i.has(S)||(i.add(S),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 h=`${e}_${i}`,c=r.get(h);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:h,cell:c,rect:d,west:u,south:m,east:g,north:p,centerLon:f,centerLat:w,viewTileLevel:n}}_processCellSkipPoints(t,e){var o,r,h,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=(h=(r=d.data)==null?void 0:r.billboard)==null?void 0:h[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:h,centerLat:c,viewTileLevel:d}=t,u=d;for(const[I,D]of r.groups){const x=D.filter(_=>{var k;return((k=_.data)==null?void 0:k.show)!==!1});if(x.length===0)continue;let T=h,$=c,S=((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,S=((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 F=((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:S,theme:F}),i++}}return i}_debugDrawCell(t){if(!this.debugCurrentGrids)return;const{levelIdx:e,west:i,south:n,east:s,north:o,lonIdx:r,latIdx:h}=t,c=this.levels[e].level;this._drawDebugGrid(i,n,s,o,`L:${c} X:${r} Y:${h}`)}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]),h=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(h)}_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 nt{constructor(){l(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 ot={[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){l(this,"viewer");l(this,"Cesium");l(this,"container");l(this,"labels",new Map);l(this,"activeIds",new Set);l(this,"occludedIds",new Set);l(this,"_updateFn");l(this,"_cameraChangedFn");l(this,"themes",{});l(this,"occlusionCheckLogs",[]);l(this,"occlusionLogEnabled",!1);l(this,"occlusionLogMax",1e4);l(this,"occlusionOptions",{enabled:!1,throttleMs:120,distanceEpsilon:1});l(this,"_occlusionTimer",null);l(this,"_lastOcclusionAt",0);l(this,"_occlusionChecking",!1);l(this,"_occlusionPending",!1);l(this,"eventBus");l(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 nt,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:h=!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||h)&&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(ot)){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||h){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=h?"block":"none",h&&this.activeIds.add(i),h?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 h=i.Cartesian3.fromDegrees(t,e,r);return this.toWindowCoordinates(h)}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),h=this.toWindowCoordinates(r);if(this.Cesium.defined(h)){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=`${h.x}px`,i.el.style.top=`${h.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,h=(u=this.viewer)==null?void 0:u.camera,c=this.Cesium;if(!r||!h||!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||!h.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(h.positionWC,e),f=c.Cartesian3.distance(h.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 ce{constructor(){l(this,"tooltipEl");l(this,"visible",!1);l(this,"offsetX",10);l(this,"offsetY",-20);l(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 Yt{constructor(t,e){l(this,"Cesium");l(this,"viewer");l(this,"handler",null);l(this,"entity",null);l(this,"tooltip",null);this.Cesium=t,this.viewer=e}startDrawing(t){const{Cesium:e,viewer:i}=this;this.tooltip=new ce,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),h=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:h,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 Vt{constructor(t,e){l(this,"Cesium");l(this,"viewer");l(this,"handler",null);l(this,"positions",[]);l(this,"entity",null);l(this,"tooltip",null);l(this,"tempPoints",[]);l(this,"options",null);l(this,"keydownHandler",null);this.Cesium=t,this.viewer=e}getPickPosition(t){var s,o,r,h;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=((h=(r=i.globe)==null?void 0:r.pick)==null?void 0:h.call(r,c,i))||null)}return n}syncEntity(){if(this.entity){if(this.positions.length===0){this.viewer.entities.remove(this.entity),this.entity=null;return}this.entity.polyline.positions=this.positions.slice()}}undoLastPoint(){if(this.positions.length===0)return;this.positions.pop();const t=this.tempPoints.pop();t&&this.viewer.entities.remove(t),this.syncEntity()}finishDrawing(t=!1){var s,o,r;const{Cesium:e}=this;if(t&&this.positions.length>0){this.positions.length=this.positions.length-1;const h=this.tempPoints.pop();h&&this.viewer.entities.remove(h)}if(this.syncEntity(),this.stopDrawing(),(s=this.tooltip)==null||s.hide(),this.tooltip=null,this.positions.length<2)return;const i=this.positions.map(h=>{const c=e.Cartographic.fromCartesian(h);return{lng:e.Math.toDegrees(c.longitude),lat:e.Math.toDegrees(c.latitude),height:c.height}}),n={entity:this.entity,positions:this.positions,lnglats:i,clear:()=>{this.clear()}};(r=(o=this.options)==null?void 0:o.onComplete)==null||r.call(o,n)}bindKeyboardEvents(){this.unbindKeyboardEvents(),this.keydownHandler=t=>{t.key==="Escape"&&(t.preventDefault(),this.finishDrawing(!1))},document.addEventListener("keydown",this.keydownHandler)}unbindKeyboardEvents(){this.keydownHandler&&(document.removeEventListener("keydown",this.keydownHandler),this.keydownHandler=null)}startDrawing(t){const{Cesium:e,viewer:i}=this;this.options=t,this.positions=[],this.tempPoints=[],this.entity=null,this.tooltip=new ce,this.tooltip.show("单击左键添加点,右键撤销,双击左键或 Esc 结束"),this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.bindKeyboardEvents(),this.handler.setInputAction(n=>{var r,h;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:((h=(r=t.color)==null?void 0:r.withAlpha)==null?void 0:h.call(r,.5))||e.Color.YELLOW.withAlpha(.5)}})},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(()=>{this.undoLastPoint()},e.ScreenSpaceEventType.RIGHT_CLICK),this.handler.setInputAction(()=>{this.finishDrawing(!0)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)}stopDrawing(){var t;this.unbindKeyboardEvents(),(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.options=null,this.stopDrawing()}}class Wt{constructor(t,e){l(this,"Cesium");l(this,"viewer");l(this,"handler",null);l(this,"startPoint",null);l(this,"endPoint",null);l(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),h=e.Cartographic.fromCartesian(this.endPoint),c=Math.min(r.longitude,h.longitude),d=Math.max(r.longitude,h.longitude),u=Math.min(r.latitude,h.latitude),m=Math.max(r.latitude,h.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),h=e.Cartographic.fromCartesian(this.endPoint),c={lng:e.Math.toDegrees(Math.min(r.longitude,h.longitude)),lat:e.Math.toDegrees(Math.min(r.latitude,h.latitude)),height:0},d={lng:e.Math.toDegrees(Math.max(r.longitude,h.longitude)),lat:e.Math.toDegrees(Math.max(r.latitude,h.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 Ut{constructor(t,e){l(this,"viewer");l(this,"Cesium");l(this,"handler",null);l(this,"entity",null);l(this,"positions",[]);l(this,"_isDrawing",!1);l(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,h=[],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);h.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:h,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 Kt{constructor(t,e){l(this,"Cesium");l(this,"viewer");l(this,"handler",null);l(this,"positions",[]);l(this,"lnglats",[]);l(this,"entity",null);l(this,"tooltip",null);l(this,"tempPoints",[]);l(this,"options",null);l(this,"keydownHandler",null);this.Cesium=t,this.viewer=e}isHelperPick(t){var e;return((e=t==null?void 0:t.id)==null?void 0:e._drawHelper)===!0}withHiddenHelpers(t){const e=[this.entity,...this.tempPoints].filter(Boolean),i=e.map(n=>n.show);e.forEach(n=>{n.show=!1});try{return t()}finally{e.forEach((n,s)=>{n.show=i[s]})}}getPickPosition(t){var r,h,c,d;const{viewer:e}=this,i=e==null?void 0:e.scene;if(!i||!t)return null;let n=null;const s=i.pick(t),o=this.isHelperPick(s);try{i.pickPositionSupported&&(n=o?this.withHiddenHelpers(()=>i.pickPosition(t)):i.pickPosition(t))}catch(u){console.warn("[PolygonDrawer] pickPosition failed:",u)}if(!n){const u=(h=(r=e.camera)==null?void 0:r.getPickRay)==null?void 0:h.call(r,t);u&&(n=((d=(c=i.globe)==null?void 0:c.pick)==null?void 0:d.call(c,u,i))||null)}return n}syncEntity(){this.entity&&this.positions.length===0&&(this.viewer.entities.remove(this.entity),this.entity=null)}undoLastPoint(){if(this.positions.length===0)return;this.positions.pop(),this.lnglats.pop();const t=this.tempPoints.pop();t&&this.viewer.entities.remove(t),this.syncEntity()}finishDrawing(t=!1){var i,n,s;if(t&&this.positions.length>0){this.positions.length=this.positions.length-1,this.lnglats.length=this.lnglats.length-1;const o=this.tempPoints.pop();o&&this.viewer.entities.remove(o)}if(this.syncEntity(),this.stopDrawing(),(i=this.tooltip)==null||i.hide(),this.tooltip=null,this.positions.length<3)return;const e={entity:this.entity,positions:this.positions,lnglats:this.lnglats.slice(),clear:()=>{this.clear()}};(s=(n=this.options)==null?void 0:n.onComplete)==null||s.call(n,e)}bindKeyboardEvents(){this.unbindKeyboardEvents(),this.keydownHandler=t=>{t.key==="Escape"&&(t.preventDefault(),this.finishDrawing(!1))},document.addEventListener("keydown",this.keydownHandler)}unbindKeyboardEvents(){this.keydownHandler&&(document.removeEventListener("keydown",this.keydownHandler),this.keydownHandler=null)}startDrawing(t){const{Cesium:e,viewer:i}=this;this.options=t,this.positions=[],this.lnglats=[],this.tempPoints=[],this.entity=null,this.tooltip=new ce,this.tooltip.show("单击左键添加点,右键撤销,双击左键或 Esc 结束"),this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.bindKeyboardEvents(),this.handler.setInputAction(n=>{const s=this.getPickPosition(n.position);if(!s)return;this.positions.push(s);const o=e.Cartographic.fromCartesian(s);this.lnglats.push({lng:e.Math.toDegrees(o.longitude),lat:e.Math.toDegrees(o.latitude),height:Number.isFinite(o.height)?o.height:0});const r=i.entities.add({position:s,point:{pixelSize:8,color:e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});r._drawHelper=!0,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)}}),this.entity._drawHelper=!0)},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(()=>{this.undoLastPoint()},e.ScreenSpaceEventType.RIGHT_CLICK),this.handler.setInputAction(()=>{this.finishDrawing(!0)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)}stopDrawing(){var t;this.unbindKeyboardEvents(),(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.lnglats=[],this.options=null,this.stopDrawing()}}class qt{constructor(t,e){l(this,"viewer");l(this,"Cesium");l(this,"activeDrawer",null);this.viewer=e,this.Cesium=t}draw(t,e){var i;switch(this.clear(),t){case"point":this.activeDrawer=new Yt(this.Cesium,this.viewer);break;case"line":this.activeDrawer=new Vt(this.Cesium,this.viewer);break;case"rectangle":this.activeDrawer=new Wt(this.Cesium,this.viewer);break;case"circle":this.activeDrawer=new Ut(this.Cesium,this.viewer);break;case"polygon":this.activeDrawer=new Kt(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 rt=typeof global=="object"&&global&&global.Object===Object&&global,Xt=typeof self=="object"&&self&&self.Object===Object&&self,se=rt||Xt||Function("return this")(),ge=se.Symbol,at=Object.prototype,Jt=at.hasOwnProperty,Zt=at.toString,Pe=ge?ge.toStringTag:void 0;function Qt(a){var t=Jt.call(a,Pe),e=a[Pe];try{a[Pe]=void 0;var i=!0}catch{}var n=Zt.call(a);return i&&(t?a[Pe]=e:delete a[Pe]),n}var ei=Object.prototype,ti=ei.toString;function ii(a){return ti.call(a)}var si="[object Null]",ni="[object Undefined]",lt=ge?ge.toStringTag:void 0;function Le(a){return a==null?a===void 0?ni:si:lt&&lt in Object(a)?Qt(a):ii(a)}function Ee(a){return a!=null&&typeof a=="object"}var Ae=Array.isArray;function $e(a){var t=typeof a;return a!=null&&(t=="object"||t=="function")}var oi="[object AsyncFunction]",ri="[object Function]",ai="[object GeneratorFunction]",li="[object Proxy]";function ht(a){if(!$e(a))return!1;var t=Le(a);return t==ri||t==ai||t==oi||t==li}var Be=se["__core-js_shared__"],ct=(function(){var a=/[^.]+$/.exec(Be&&Be.keys&&Be.keys.IE_PROTO||"");return a?"Symbol(src)_1."+a:""})();function hi(a){return!!ct&&ct in a}var ci=Function.prototype,di=ci.toString;function de(a){if(a!=null){try{return di.call(a)}catch{}try{return a+""}catch{}}return""}var pi=/[\\^$.*+?()[\]{}|]/g,ui=/^\[object .+?Constructor\]$/,mi=Function.prototype,gi=Object.prototype,fi=mi.toString,yi=gi.hasOwnProperty,wi=RegExp("^"+fi.call(yi).replace(pi,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function vi(a){if(!$e(a)||hi(a))return!1;var t=ht(a)?wi:ui;return t.test(de(a))}function Ci(a,t){return a==null?void 0:a[t]}function pe(a,t){var e=Ci(a,t);return vi(e)?e:void 0}var je=pe(se,"WeakMap"),dt=Object.create,bi=(function(){function a(){}return function(t){if(!$e(t))return{};if(dt)return dt(t);a.prototype=t;var e=new a;return a.prototype=void 0,e}})(),pt=(function(){try{var a=pe(Object,"defineProperty");return a({},"",{}),a}catch{}})();function Pi(a,t){for(var e=-1,i=a==null?0:a.length;++e<i&&t(a[e],e,a)!==!1;);return a}var Li=9007199254740991,Ei=/^(?:0|[1-9]\d*)$/;function Mi(a,t){var e=typeof a;return t=t??Li,!!t&&(e=="number"||e!="symbol"&&Ei.test(a))&&a>-1&&a%1==0&&a<t}function Ii(a,t,e){t=="__proto__"&&pt?pt(a,t,{configurable:!0,enumerable:!0,value:e,writable:!0}):a[t]=e}function ut(a,t){return a===t||a!==a&&t!==t}var Ti=Object.prototype,_i=Ti.hasOwnProperty;function xi(a,t,e){var i=a[t];(!(_i.call(a,t)&&ut(i,e))||e===void 0&&!(t in a))&&Ii(a,t,e)}var Di=9007199254740991;function mt(a){return typeof a=="number"&&a>-1&&a%1==0&&a<=Di}function Si(a){return a!=null&&mt(a.length)&&!ht(a)}var Ai=Object.prototype;function gt(a){var t=a&&a.constructor,e=typeof t=="function"&&t.prototype||Ai;return a===e}function $i(a,t){for(var e=-1,i=Array(a);++e<a;)i[e]=t(e);return i}var ki="[object Arguments]";function ft(a){return Ee(a)&&Le(a)==ki}var yt=Object.prototype,Oi=yt.hasOwnProperty,Hi=yt.propertyIsEnumerable,Fi=ft((function(){return arguments})())?ft:function(a){return Ee(a)&&Oi.call(a,"callee")&&!Hi.call(a,"callee")};function Ri(){return!1}var wt=typeof A=="object"&&A&&!A.nodeType&&A,vt=wt&&typeof module=="object"&&module&&!module.nodeType&&module,zi=vt&&vt.exports===wt,Ct=zi?se.Buffer:void 0,Ni=Ct?Ct.isBuffer:void 0,bt=Ni||Ri,Gi="[object Arguments]",Bi="[object Array]",ji="[object Boolean]",Yi="[object Date]",Vi="[object Error]",Wi="[object Function]",Ui="[object Map]",Ki="[object Number]",qi="[object Object]",Xi="[object RegExp]",Ji="[object Set]",Zi="[object String]",Qi="[object WeakMap]",es="[object ArrayBuffer]",ts="[object DataView]",is="[object Float32Array]",ss="[object Float64Array]",ns="[object Int8Array]",os="[object Int16Array]",rs="[object Int32Array]",as="[object Uint8Array]",ls="[object Uint8ClampedArray]",hs="[object Uint16Array]",cs="[object Uint32Array]",z={};z[is]=z[ss]=z[ns]=z[os]=z[rs]=z[as]=z[ls]=z[hs]=z[cs]=!0,z[Gi]=z[Bi]=z[es]=z[ji]=z[ts]=z[Yi]=z[Vi]=z[Wi]=z[Ui]=z[Ki]=z[qi]=z[Xi]=z[Ji]=z[Zi]=z[Qi]=!1;function ds(a){return Ee(a)&&mt(a.length)&&!!z[Le(a)]}function Ye(a){return function(t){return a(t)}}var Pt=typeof A=="object"&&A&&!A.nodeType&&A,Me=Pt&&typeof module=="object"&&module&&!module.nodeType&&module,ps=Me&&Me.exports===Pt,Ve=ps&&rt.process,fe=(function(){try{var a=Me&&Me.require&&Me.require("util").types;return a||Ve&&Ve.binding&&Ve.binding("util")}catch{}})(),Lt=fe&&fe.isTypedArray,us=Lt?Ye(Lt):ds,ms=Object.prototype,gs=ms.hasOwnProperty;function fs(a,t){var e=Ae(a),i=!e&&Fi(a),n=!e&&!i&&bt(a),s=!e&&!i&&!n&&us(a),o=e||i||n||s,r=o?$i(a.length,String):[],h=r.length;for(var c in a)gs.call(a,c)&&!(o&&(c=="length"||n&&(c=="offset"||c=="parent")||s&&(c=="buffer"||c=="byteLength"||c=="byteOffset")||Mi(c,h)))&&r.push(c);return r}function Et(a,t){return function(e){return a(t(e))}}var ys=Et(Object.keys,Object),ws=Object.prototype,vs=ws.hasOwnProperty;function Cs(a){if(!gt(a))return ys(a);var t=[];for(var e in Object(a))vs.call(a,e)&&e!="constructor"&&t.push(e);return t}function bs(a){return Si(a)?fs(a):Cs(a)}var Ie=pe(Object,"create");function Ps(){this.__data__=Ie?Ie(null):{},this.size=0}function Ls(a){var t=this.has(a)&&delete this.__data__[a];return this.size-=t?1:0,t}var Es="__lodash_hash_undefined__",Ms=Object.prototype,Is=Ms.hasOwnProperty;function Ts(a){var t=this.__data__;if(Ie){var e=t[a];return e===Es?void 0:e}return Is.call(t,a)?t[a]:void 0}var _s=Object.prototype,xs=_s.hasOwnProperty;function Ds(a){var t=this.__data__;return Ie?t[a]!==void 0:xs.call(t,a)}var Ss="__lodash_hash_undefined__";function As(a,t){var e=this.__data__;return this.size+=this.has(a)?0:1,e[a]=Ie&&t===void 0?Ss:t,this}function ue(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])}}ue.prototype.clear=Ps,ue.prototype.delete=Ls,ue.prototype.get=Ts,ue.prototype.has=Ds,ue.prototype.set=As;function $s(){this.__data__=[],this.size=0}function ke(a,t){for(var e=a.length;e--;)if(ut(a[e][0],t))return e;return-1}var ks=Array.prototype,Os=ks.splice;function Hs(a){var t=this.__data__,e=ke(t,a);if(e<0)return!1;var i=t.length-1;return e==i?t.pop():Os.call(t,e,1),--this.size,!0}function Fs(a){var t=this.__data__,e=ke(t,a);return e<0?void 0:t[e][1]}function Rs(a){return ke(this.__data__,a)>-1}function zs(a,t){var e=this.__data__,i=ke(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=$s,oe.prototype.delete=Hs,oe.prototype.get=Fs,oe.prototype.has=Rs,oe.prototype.set=zs;var Te=pe(se,"Map");function Ns(){this.size=0,this.__data__={hash:new ue,map:new(Te||oe),string:new ue}}function Gs(a){var t=typeof a;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?a!=="__proto__":a===null}function Oe(a,t){var e=a.__data__;return Gs(t)?e[typeof t=="string"?"string":"hash"]:e.map}function Bs(a){var t=Oe(this,a).delete(a);return this.size-=t?1:0,t}function js(a){return Oe(this,a).get(a)}function Ys(a){return Oe(this,a).has(a)}function Vs(a,t){var e=Oe(this,a),i=e.size;return e.set(a,t),this.size+=e.size==i?0:1,this}function ye(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])}}ye.prototype.clear=Ns,ye.prototype.delete=Bs,ye.prototype.get=js,ye.prototype.has=Ys,ye.prototype.set=Vs;function Ws(a,t){for(var e=-1,i=t.length,n=a.length;++e<i;)a[n+e]=t[e];return a}var Us=Et(Object.getPrototypeOf,Object);function Ks(){this.__data__=new oe,this.size=0}function qs(a){var t=this.__data__,e=t.delete(a);return this.size=t.size,e}function Xs(a){return this.__data__.get(a)}function Js(a){return this.__data__.has(a)}var Zs=200;function Qs(a,t){var e=this.__data__;if(e instanceof oe){var i=e.__data__;if(!Te||i.length<Zs-1)return i.push([a,t]),this.size=++e.size,this;e=this.__data__=new ye(i)}return e.set(a,t),this.size=e.size,this}function we(a){var t=this.__data__=new oe(a);this.size=t.size}we.prototype.clear=Ks,we.prototype.delete=qs,we.prototype.get=Xs,we.prototype.has=Js,we.prototype.set=Qs;var Mt=typeof A=="object"&&A&&!A.nodeType&&A,It=Mt&&typeof module=="object"&&module&&!module.nodeType&&module,en=It&&It.exports===Mt,Tt=en?se.Buffer:void 0;Tt&&Tt.allocUnsafe;function tn(a,t){return a.slice()}function sn(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 nn(){return[]}var on=Object.prototype,rn=on.propertyIsEnumerable,_t=Object.getOwnPropertySymbols,an=_t?function(a){return a==null?[]:(a=Object(a),sn(_t(a),function(t){return rn.call(a,t)}))}:nn;function ln(a,t,e){var i=t(a);return Ae(a)?i:Ws(i,e(a))}function hn(a){return ln(a,bs,an)}var We=pe(se,"DataView"),Ue=pe(se,"Promise"),Ke=pe(se,"Set"),xt="[object Map]",cn="[object Object]",Dt="[object Promise]",St="[object Set]",At="[object WeakMap]",$t="[object DataView]",dn=de(We),pn=de(Te),un=de(Ue),mn=de(Ke),gn=de(je),re=Le;(We&&re(new We(new ArrayBuffer(1)))!=$t||Te&&re(new Te)!=xt||Ue&&re(Ue.resolve())!=Dt||Ke&&re(new Ke)!=St||je&&re(new je)!=At)&&(re=function(a){var t=Le(a),e=t==cn?a.constructor:void 0,i=e?de(e):"";if(i)switch(i){case dn:return $t;case pn:return xt;case un:return Dt;case mn:return St;case gn:return At}return t});var fn=Object.prototype,yn=fn.hasOwnProperty;function wn(a){var t=a.length,e=new a.constructor(t);return t&&typeof a[0]=="string"&&yn.call(a,"index")&&(e.index=a.index,e.input=a.input),e}var kt=se.Uint8Array;function qe(a){var t=new a.constructor(a.byteLength);return new kt(t).set(new kt(a)),t}function vn(a,t){var e=qe(a.buffer);return new a.constructor(e,a.byteOffset,a.byteLength)}var Cn=/\w*$/;function bn(a){var t=new a.constructor(a.source,Cn.exec(a));return t.lastIndex=a.lastIndex,t}var Ot=ge?ge.prototype:void 0,Ht=Ot?Ot.valueOf:void 0;function Pn(a){return Ht?Object(Ht.call(a)):{}}function Ln(a,t){var e=qe(a.buffer);return new a.constructor(e,a.byteOffset,a.length)}var En="[object Boolean]",Mn="[object Date]",In="[object Map]",Tn="[object Number]",_n="[object RegExp]",xn="[object Set]",Dn="[object String]",Sn="[object Symbol]",An="[object ArrayBuffer]",$n="[object DataView]",kn="[object Float32Array]",On="[object Float64Array]",Hn="[object Int8Array]",Fn="[object Int16Array]",Rn="[object Int32Array]",zn="[object Uint8Array]",Nn="[object Uint8ClampedArray]",Gn="[object Uint16Array]",Bn="[object Uint32Array]";function jn(a,t,e){var i=a.constructor;switch(t){case An:return qe(a);case En:case Mn:return new i(+a);case $n:return vn(a);case kn:case On:case Hn:case Fn:case Rn:case zn:case Nn:case Gn:case Bn:return Ln(a);case In:return new i;case Tn:case Dn:return new i(a);case _n:return bn(a);case xn:return new i;case Sn:return Pn(a)}}function Yn(a){return typeof a.constructor=="function"&&!gt(a)?bi(Us(a)):{}}var Vn="[object Map]";function Wn(a){return Ee(a)&&re(a)==Vn}var Ft=fe&&fe.isMap,Un=Ft?Ye(Ft):Wn,Kn="[object Set]";function qn(a){return Ee(a)&&re(a)==Kn}var Rt=fe&&fe.isSet,Xn=Rt?Ye(Rt):qn,zt="[object Arguments]",Jn="[object Array]",Zn="[object Boolean]",Qn="[object Date]",eo="[object Error]",Nt="[object Function]",to="[object GeneratorFunction]",io="[object Map]",so="[object Number]",Gt="[object Object]",no="[object RegExp]",oo="[object Set]",ro="[object String]",ao="[object Symbol]",lo="[object WeakMap]",ho="[object ArrayBuffer]",co="[object DataView]",po="[object Float32Array]",uo="[object Float64Array]",mo="[object Int8Array]",go="[object Int16Array]",fo="[object Int32Array]",yo="[object Uint8Array]",wo="[object Uint8ClampedArray]",vo="[object Uint16Array]",Co="[object Uint32Array]",R={};R[zt]=R[Jn]=R[ho]=R[co]=R[Zn]=R[Qn]=R[po]=R[uo]=R[mo]=R[go]=R[fo]=R[io]=R[so]=R[Gt]=R[no]=R[oo]=R[ro]=R[ao]=R[yo]=R[wo]=R[vo]=R[Co]=!0,R[eo]=R[Nt]=R[lo]=!1;function He(a,t,e,i,n,s){var o;if(o!==void 0)return o;if(!$e(a))return a;var r=Ae(a);if(r)o=wn(a);else{var h=re(a),c=h==Nt||h==to;if(bt(a))return tn(a);if(h==Gt||h==zt||c&&!n)o=c?{}:Yn(a);else{if(!R[h])return n?a:{};o=jn(a,h)}}s||(s=new we);var d=s.get(a);if(d)return d;s.set(a,o),Xn(a)?a.forEach(function(g){o.add(He(g,t,e,g,a,s))}):Un(a)&&a.forEach(function(g,p){o.set(p,He(g,t,e,p,a,s))});var u=hn,m=r?void 0:u(a);return Pi(m||a,function(g,p){m&&(p=g,g=a[p]),xi(o,p,He(g,t,e,p,a,s))}),o}var bo=1,Po=4;function Fe(a){return He(a,bo|Po)}var Bt=(a=>(a.Rotate="rotate",a.Move="move",a.Scale="scale",a.MoveHeight="moveHeight",a.Empty="",a))(Bt||{}),jt=(a=>(a.Scale="addScale",a.Rotate="rotate",a.Translation="translation",a.Remove="removeById",a.Add="add",a))(jt||{});class Lo{constructor(t){l(this,"primitives",new Map);l(this,"eventListener",new Map);l(this,"Cesium");l(this,"viewer");l(this,"handler");l(this,"rotationRing");l(this,"translationSquare");l(this,"heightArrow");l(this,"editMode","");l(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),h=new n.HeadingPitchRoll(s,o,r),c=n.Transforms.headingPitchRollToFixedFrame(t.position,h,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,h=null,c=null;const d=()=>{s=null,o=null,r=null,c=null,h=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);h=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,h)-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 h=Math.sin(e.Math.toRadians(r)),c=Math.cos(e.Math.toRadians(r)),d=t.boundingSphere.radius*c,u=t.boundingSphere.radius*h;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,h=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:h,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;Ae(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 h=n.Matrix4.getTranslation(e,new n.Cartesian3),c=n.Cartographic.fromCartesian(h),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,h=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+h*.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,h=new n.HeadingPitchRoll(r,o.pitch,o.roll),c=n.Transforms.headingPitchRollToFixedFrame(n.Matrix4.getTranslation(t.modelMatrix,new n.Cartesian3),h,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 Eo(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`
1
+ (function(A,te){typeof exports=="object"&&typeof module<"u"?te(exports):typeof define=="function"&&define.amd?define(["exports"],te):(A=typeof globalThis<"u"?globalThis:A||self,te(A.CesiumCore={}))})(this,(function(A){"use strict";var Fo=Object.defineProperty;var zo=(A,te,V)=>te in A?Fo(A,te,{enumerable:!0,configurable:!0,writable:!0,value:V}):A[te]=V;var c=(A,te,V)=>zo(A,typeof te!="symbol"?te+"":te,V);class te{constructor(t,e,i){c(this,"Cesium");c(this,"viewer");c(this,"labelPool");c(this,"threshold");c(this,"displayLimit");c(this,"maxLevel");c(this,"debugCurrentGrids");c(this,"levels");c(this,"points",[]);c(this,"gridLayers",new Map);c(this,"debugGrids",[]);c(this,"_updateFn");c(this,"clusterTheme");c(this,"pointTheme");c(this,"centralPointMode");c(this,"minGlobalPointCount");c(this,"groupByTheme");c(this,"tilingScheme");c(this,"terrainLevelOffset");c(this,"debugTileCoordLayer",null);c(this,"levelIndexByTileLevel",new Map);c(this,"_lastTileProvider",null);c(this,"_updateTimer",null);c(this,"_updateDelay",100);c(this,"_tilesRetryCount",0);c(this,"_tilesRetryMax",100);c(this,"_cameraDirty",!1);c(this,"_tileLoadListener",null);c(this,"_cameraChangedHandler",null);c(this,"defaultMinLevel",0);c(this,"defaultMaxLevel",28);c(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=a=>{a===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,a;const e=this.points.findIndex(l=>l.id===t.id);if(e===-1)return;const i=this.points[e];for(const l of this.levels){const d=l.level,u=this.gridLayers.get(d);if(!u)continue;const p=this.Cesium.Cartographic.fromDegrees(i.lon,i.lat),g=this.tilingScheme.positionToTileXY(p,d,new this.Cesium.Cartesian2);if(!g)continue;const m=`${g.x}_${g.y}`,f=u.get(m);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?(a=i.data)==null?void 0:a.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,a]of o.groups.entries()){const l=a.filter(d=>!e.has(d.id));l.length===0?o.groups.delete(r):o.groups.set(r,l)}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 a of this.levels){const l=a.level,d=this.gridLayers.get(l);if(!d)continue;const u=this.Cesium.Cartographic.fromDegrees(t.lon,t.lat),p=this.tilingScheme.positionToTileXY(u,l,new this.Cesium.Cartesian2);if(!p)continue;const g=`${p.x}_${p.y}`;let m=d.get(g);if(m||(m={allPoints:[],groups:new Map,skipPoints:[]},d.set(g,m)),m.allPoints.push(t),(n=(i=(e=t.data)==null?void 0:e.billboard)==null?void 0:i[0])!=null&&n.skipAggregation)m.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;m.groups.has(f)||m.groups.set(f,[]),m.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 a=Math.abs(this.levels[r].level-t);a<o&&(o=a,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,a=r&&s.camera.computeViewRectangle(r),l=(d,u,p)=>{if(!n||!a)return!0;const g=this.tilingScheme.tileXYToRectangle(d,u,p);return!(!g||g.east<=a.west||g.west>=a.east||g.north<=a.south||g.south>=a.north)};for(const d of t){const u=d.rectangle,p=d._level??d.level;if(!u||typeof p!="number")continue;const g=this._getGridRefLevel(p),m=this._resolveLevelIndex(g);if(m===void 0)continue;const f=this.levels[m].level,w=d._x??d.x,y=d._y??d.y;if(typeof w=="number"&&typeof y=="number"){const I=p-f;if(I>=0){const k=1<<I,S=Math.floor(w/k),R=Math.floor(y/k),T=`${f}_${S}_${R}`;if(i.has(T))continue;i.add(T),e(m,S,R,p)}else{const S=1<<Math.min(-I,this.maxRefineLevels),R=w*S,T=y*S;for(let $=0;$<S;$++)for(let H=0;H<S;H++){const G=R+$,B=T+H;if(!l(G,B,f))continue;const Y=`${f}_${G}_${B}`;i.has(Y)||(i.add(Y),e(m,G,B,p))}}continue}const C=this.levels[m].size,b=this.Cesium.Math.toDegrees(u.west),P=this.Cesium.Math.toDegrees(u.east),E=this.Cesium.Math.toDegrees(u.south),L=this.Cesium.Math.toDegrees(u.north),M=Math.floor((b- -180)/C),x=Math.floor((P- -180)/C),_=Math.floor((E- -90)/C),D=Math.floor((L- -90)/C);for(let I=M;I<=x;I++)for(let k=_;k<=D;k++){if(!l(I,k,f))continue;const S=`${f}_${I}_${k}`;i.has(S)||(i.add(S),e(m,I,k,p))}}}_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 a=`${e}_${i}`,l=r.get(a);if(!l)return null;const d=this.tilingScheme.tileXYToRectangle(e,i,o),u=this.Cesium.Math.toDegrees(d.west),p=this.Cesium.Math.toDegrees(d.south),g=this.Cesium.Math.toDegrees(d.east),m=this.Cesium.Math.toDegrees(d.north),f=(u+g)/2,w=(p+m)/2;return{levelIdx:t,tileLevel:o,lonIdx:e,latIdx:i,key:a,cell:l,rect:d,west:u,south:p,east:g,north:m,centerLon:f,centerLat:w,viewTileLevel:n}}_processCellSkipPoints(t,e){var o,r,a,l;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:((l=(a=(r=d.data)==null?void 0:r.billboard)==null?void 0:a[0])==null?void 0:l.theme)||this.pointTheme,style:d.style}),e++)}return e}_processCellGroups(t,e,i){var p,g,m,f,w,y,v,C,b,P,E,L,M;const{levelIdx:n,lonIdx:s,latIdx:o,cell:r,centerLon:a,centerLat:l,viewTileLevel:d}=t,u=d;for(const[x,_]of r.groups){const D=_.filter(T=>{var $;return(($=T.data)==null?void 0:$.show)!==!1});if(D.length===0)continue;let I=a,k=l,S=((p=D[0])==null?void 0:p.height)||0;if(this.centralPointMode=="firstPoint"&&(I=((g=D[0])==null?void 0:g.lon)||0,k=((m=D[0])==null?void 0:m.lat)||0,S=((f=D[0])==null?void 0:f.height)||0),n===this.levels.length-1||D.length<e)for(const T of D){if(i>=this.displayLimit)break;this._isVisibleAtLevel(T,u)&&(this.labelPool.add(T.data,{id:`point-${T.id}`,lon:T.lon,lat:T.lat,height:T.height,theme:((v=(y=(w=T.data)==null?void 0:w.billboard)==null?void 0:y[0])==null?void 0:v.theme)||this.pointTheme,style:T.style}),i++)}else{if(i>=this.displayLimit)return i;const T=u==null?D:D.filter(B=>this._isVisibleAtLevel(B,u));if(!T.length)return i;const H=((E=(P=(b=(C=T[0])==null?void 0:C.data)==null?void 0:b.billboard)==null?void 0:P[0])==null?void 0:E.theme)||this.clusterTheme,G=this.groupByTheme?`cluster-${n}-${s}-${o}-${x}`:`cluster-${n}-${s}-${o}`;this.labelPool.add({id:G,billboard:((M=(L=T[0])==null?void 0:L.data)==null?void 0:M.billboard)||[],count:T.length,gridKey:`${s}_${o}`,points:T,aggregationGroup:x},{id:G,lon:I,lat:k,height:S,theme:H}),i++}}return i}_debugDrawCell(t){if(!this.debugCurrentGrids)return;const{levelIdx:e,west:i,south:n,east:s,north:o,lonIdx:r,latIdx:a}=t,l=this.levels[e].level;this._drawDebugGrid(i,n,s,o,`L:${l} X:${r} Y:${a}`)}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]),a=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(a)}_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=(h=>(h.Click="marker:click",h.DoubleClick="marker:dblclick",h.RightClick="marker:rightclick",h.MouseEnter="marker:mouseenter",h.MouseLeave="marker:mouseleave",h.MouseDown="marker:mousedown",h.MouseUp="marker:mouseup",h))(V||{});class nt{constructor(){c(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 ot={[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){c(this,"viewer");c(this,"Cesium");c(this,"container");c(this,"labels",new Map);c(this,"activeIds",new Set);c(this,"occludedIds",new Set);c(this,"_updateFn");c(this,"_cameraChangedFn");c(this,"themes",{});c(this,"occlusionCheckLogs",[]);c(this,"occlusionLogEnabled",!1);c(this,"occlusionLogMax",1e4);c(this,"occlusionOptions",{enabled:!1,throttleMs:120,distanceEpsilon:1});c(this,"_occlusionTimer",null);c(this,"_lastOcclusionAt",0);c(this,"_occlusionChecking",!1);c(this,"_occlusionPending",!1);c(this,"eventBus");c(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 nt,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:a=!0,notCreateElement:l=!1,style:d}=e,u=this.themes[r];if(!u){console.warn(`Theme "${r}" not registered`);return}let p=this.labels.get(i);if(p){p.theme=r,p.data=t,p.notCreateElement=l;try{p.unload=u.createElement(p.el,{id:i,theme:r,data:t},u),(!l||a)&&this.container.appendChild(p.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(ot)){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 m=null;if(!l||a){try{m=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)}p={id:i,el:g,theme:r,data:t,notCreateElement:l,unload:m},this.labels.set(i,p)}p.el.dataset.lon=String(n),p.el.dataset.lat=String(s),p.el.dataset.height=String(o),p.el.style.zIndex=(d==null?void 0:d.zIndex)||"1",p.el.style.display=a?"block":"none",a&&this.activeIds.add(i),a?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 a=i.Cartesian3.fromDegrees(t,e,r);return this.toWindowCoordinates(a)}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),a=this.toWindowCoordinates(r);if(this.Cesium.defined(a)){const d=((t=this.themes[i.theme].options)==null?void 0:t.offset)||{},u=d.x||0,p=d.y||0,g=this.occludedIds.has(e);i.el.style.left=`${a.x}px`,i.el.style.top=`${a.y}px`,i.el.style.transform=`translate(${u}px, ${p}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,a=(u=this.viewer)==null?void 0:u.camera,l=this.Cesium;if(!r||!a||!l)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 p=r.pickPosition(i);if(!p||!a.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,m=l.Cartesian3.distance(a.positionWC,e),f=l.Cartesian3.distance(a.positionWC,p),w=f+g<m;return this._pushOcclusionLog({timestamp:Date.now(),id:t,lon:n,lat:s,height:o,occluded:w,reason:"distance-compare",epsilon:g,labelDistance:m,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 ce{constructor(){c(this,"tooltipEl");c(this,"visible",!1);c(this,"offsetX",10);c(this,"offsetY",-20);c(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 jt{constructor(t,e){c(this,"Cesium");c(this,"viewer");c(this,"handler",null);c(this,"entity",null);c(this,"tooltip",null);this.Cesium=t,this.viewer=e}startDrawing(t){const{Cesium:e,viewer:i}=this;this.tooltip=new ce,this.tooltip.show("左键添加点"),this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var p,g;const s=i.scene.pickPosition(n.position);if(!s)return;const o=e.Cartographic.fromCartesian(s),r=e.Math.toDegrees(o.longitude),a=e.Math.toDegrees(o.latitude),l=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:a,height:l},clear:()=>{this.clear()}};(p=t.onComplete)==null||p.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 Vt{constructor(t,e){c(this,"Cesium");c(this,"viewer");c(this,"handler",null);c(this,"positions",[]);c(this,"entity",null);c(this,"tooltip",null);c(this,"tempPoints",[]);c(this,"options",null);c(this,"keydownHandler",null);this.Cesium=t,this.viewer=e}getPickPosition(t){var s,o,r,a;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(l){console.warn("[LineDrawer] pickPosition failed:",l)}if(!n){const l=(o=(s=e.camera)==null?void 0:s.getPickRay)==null?void 0:o.call(s,t);l&&(n=((a=(r=i.globe)==null?void 0:r.pick)==null?void 0:a.call(r,l,i))||null)}return n}syncEntity(){if(this.entity){if(this.positions.length===0){this.viewer.entities.remove(this.entity),this.entity=null;return}this.entity.polyline.positions=this.positions.slice()}}undoLastPoint(){if(this.positions.length===0)return;this.positions.pop();const t=this.tempPoints.pop();t&&this.viewer.entities.remove(t),this.syncEntity()}finishDrawing(t=!1){var s,o,r;const{Cesium:e}=this;if(t&&this.positions.length>0){this.positions.length=this.positions.length-1;const a=this.tempPoints.pop();a&&this.viewer.entities.remove(a)}if(this.syncEntity(),this.stopDrawing(),(s=this.tooltip)==null||s.hide(),this.tooltip=null,this.positions.length<2)return;const i=this.positions.map(a=>{const l=e.Cartographic.fromCartesian(a);return{lng:e.Math.toDegrees(l.longitude),lat:e.Math.toDegrees(l.latitude),height:l.height}}),n={entity:this.entity,positions:this.positions,lnglats:i,clear:()=>{this.clear()}};(r=(o=this.options)==null?void 0:o.onComplete)==null||r.call(o,n)}bindKeyboardEvents(){this.unbindKeyboardEvents(),this.keydownHandler=t=>{t.key==="Escape"&&(t.preventDefault(),this.finishDrawing(!1))},document.addEventListener("keydown",this.keydownHandler)}unbindKeyboardEvents(){this.keydownHandler&&(document.removeEventListener("keydown",this.keydownHandler),this.keydownHandler=null)}startDrawing(t){const{Cesium:e,viewer:i}=this;this.options=t,this.positions=[],this.tempPoints=[],this.entity=null,this.tooltip=new ce,this.tooltip.show("单击左键添加点,右键撤销,双击左键或 Esc 结束"),this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.bindKeyboardEvents(),this.handler.setInputAction(n=>{var r,a;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:((a=(r=t.color)==null?void 0:r.withAlpha)==null?void 0:a.call(r,.5))||e.Color.YELLOW.withAlpha(.5)}})},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(()=>{this.undoLastPoint()},e.ScreenSpaceEventType.RIGHT_CLICK),this.handler.setInputAction(()=>{this.finishDrawing(!0)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)}stopDrawing(){var t;this.unbindKeyboardEvents(),(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.options=null,this.stopDrawing()}}class Wt{constructor(t,e){c(this,"Cesium");c(this,"viewer");c(this,"handler",null);c(this,"startPoint",null);c(this,"endPoint",null);c(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),a=e.Cartographic.fromCartesian(this.endPoint),l=Math.min(r.longitude,a.longitude),d=Math.max(r.longitude,a.longitude),u=Math.min(r.latitude,a.latitude),p=Math.max(r.latitude,a.latitude);return new e.Rectangle(l,u,d,p)}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),a=e.Cartographic.fromCartesian(this.endPoint),l={lng:e.Math.toDegrees(Math.min(r.longitude,a.longitude)),lat:e.Math.toDegrees(Math.min(r.latitude,a.latitude)),height:0},d={lng:e.Math.toDegrees(Math.max(r.longitude,a.longitude)),lat:e.Math.toDegrees(Math.max(r.latitude,a.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:[l,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 Ut{constructor(t,e){c(this,"viewer");c(this,"Cesium");c(this,"handler",null);c(this,"entity",null);c(this,"positions",[]);c(this,"_isDrawing",!1);c(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,a=[],l=[];for(let p=0;p<360;p+=r){const g=this.Cesium.Math.toRadians(p),m=new this.Cesium.EllipsoidGeodesic;m.setEndPoints(s,new this.Cesium.Cartographic(s.longitude+1e-4*Math.cos(g),s.latitude+1e-4*Math.sin(g)));const f=m.interpolateUsingSurfaceDistance(n),w=this.Cesium.Ellipsoid.WGS84.cartographicToCartesian(f);a.push(w);const y=this.Cesium.Cartographic.fromCartesian(w);l.push({lng:this.Cesium.Math.toDegrees(y.longitude),lat:this.Cesium.Math.toDegrees(y.latitude),height:y.height})}l.push(l[0]);const d=this.positions.map(p=>{const g=this.Cesium.Cartographic.fromCartesian(p);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:a,circleLnglats:l,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 Kt{constructor(t,e){c(this,"Cesium");c(this,"viewer");c(this,"handler",null);c(this,"positions",[]);c(this,"lnglats",[]);c(this,"entity",null);c(this,"tooltip",null);c(this,"tempPoints",[]);c(this,"options",null);c(this,"keydownHandler",null);this.Cesium=t,this.viewer=e}isHelperPick(t){var e;return((e=t==null?void 0:t.id)==null?void 0:e._drawHelper)===!0}withHiddenHelpers(t){const e=[this.entity,...this.tempPoints].filter(Boolean),i=e.map(n=>n.show);e.forEach(n=>{n.show=!1});try{return t()}finally{e.forEach((n,s)=>{n.show=i[s]})}}getPickPosition(t){var r,a,l,d;const{viewer:e}=this,i=e==null?void 0:e.scene;if(!i||!t)return null;let n=null;const s=i.pick(t),o=this.isHelperPick(s);try{i.pickPositionSupported&&(n=o?this.withHiddenHelpers(()=>i.pickPosition(t)):i.pickPosition(t))}catch(u){console.warn("[PolygonDrawer] pickPosition failed:",u)}if(!n){const u=(a=(r=e.camera)==null?void 0:r.getPickRay)==null?void 0:a.call(r,t);u&&(n=((d=(l=i.globe)==null?void 0:l.pick)==null?void 0:d.call(l,u,i))||null)}return n}syncEntity(){this.entity&&this.positions.length===0&&(this.viewer.entities.remove(this.entity),this.entity=null)}undoLastPoint(){if(this.positions.length===0)return;this.positions.pop(),this.lnglats.pop();const t=this.tempPoints.pop();t&&this.viewer.entities.remove(t),this.syncEntity()}finishDrawing(t=!1){var i,n,s;if(t&&this.positions.length>0){this.positions.length=this.positions.length-1,this.lnglats.length=this.lnglats.length-1;const o=this.tempPoints.pop();o&&this.viewer.entities.remove(o)}if(this.syncEntity(),this.stopDrawing(),(i=this.tooltip)==null||i.hide(),this.tooltip=null,this.positions.length<3)return;const e={entity:this.entity,positions:this.positions,lnglats:this.lnglats.slice(),clear:()=>{this.clear()}};(s=(n=this.options)==null?void 0:n.onComplete)==null||s.call(n,e)}bindKeyboardEvents(){this.unbindKeyboardEvents(),this.keydownHandler=t=>{t.key==="Escape"&&(t.preventDefault(),this.finishDrawing(!1))},document.addEventListener("keydown",this.keydownHandler)}unbindKeyboardEvents(){this.keydownHandler&&(document.removeEventListener("keydown",this.keydownHandler),this.keydownHandler=null)}startDrawing(t){const{Cesium:e,viewer:i}=this;this.options=t,this.positions=[],this.lnglats=[],this.tempPoints=[],this.entity=null,this.tooltip=new ce,this.tooltip.show("单击左键添加点,右键撤销,双击左键或 Esc 结束"),this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.bindKeyboardEvents(),this.handler.setInputAction(n=>{const s=this.getPickPosition(n.position);if(!s)return;this.positions.push(s);const o=e.Cartographic.fromCartesian(s);this.lnglats.push({lng:e.Math.toDegrees(o.longitude),lat:e.Math.toDegrees(o.latitude),height:Number.isFinite(o.height)?o.height:0});const r=i.entities.add({position:s,point:{pixelSize:8,color:e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});r._drawHelper=!0,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)}}),this.entity._drawHelper=!0)},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(()=>{this.undoLastPoint()},e.ScreenSpaceEventType.RIGHT_CLICK),this.handler.setInputAction(()=>{this.finishDrawing(!0)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)}stopDrawing(){var t;this.unbindKeyboardEvents(),(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.lnglats=[],this.options=null,this.stopDrawing()}}class Xt{constructor(t,e){c(this,"viewer");c(this,"Cesium");c(this,"activeDrawer",null);this.viewer=e,this.Cesium=t}draw(t,e){var i;switch(this.clear(),t){case"point":this.activeDrawer=new jt(this.Cesium,this.viewer);break;case"line":this.activeDrawer=new Vt(this.Cesium,this.viewer);break;case"rectangle":this.activeDrawer=new Wt(this.Cesium,this.viewer);break;case"circle":this.activeDrawer=new Ut(this.Cesium,this.viewer);break;case"polygon":this.activeDrawer=new Kt(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 rt=typeof global=="object"&&global&&global.Object===Object&&global,qt=typeof self=="object"&&self&&self.Object===Object&&self,se=rt||qt||Function("return this")(),ge=se.Symbol,at=Object.prototype,Zt=at.hasOwnProperty,Jt=at.toString,Pe=ge?ge.toStringTag:void 0;function Qt(h){var t=Zt.call(h,Pe),e=h[Pe];try{h[Pe]=void 0;var i=!0}catch{}var n=Jt.call(h);return i&&(t?h[Pe]=e:delete h[Pe]),n}var ei=Object.prototype,ti=ei.toString;function ii(h){return ti.call(h)}var si="[object Null]",ni="[object Undefined]",lt=ge?ge.toStringTag:void 0;function Le(h){return h==null?h===void 0?ni:si:lt&&lt in Object(h)?Qt(h):ii(h)}function Ee(h){return h!=null&&typeof h=="object"}var Me=Array.isArray;function ke(h){var t=typeof h;return h!=null&&(t=="object"||t=="function")}var oi="[object AsyncFunction]",ri="[object Function]",ai="[object GeneratorFunction]",li="[object Proxy]";function ht(h){if(!ke(h))return!1;var t=Le(h);return t==ri||t==ai||t==oi||t==li}var Be=se["__core-js_shared__"],ct=(function(){var h=/[^.]+$/.exec(Be&&Be.keys&&Be.keys.IE_PROTO||"");return h?"Symbol(src)_1."+h:""})();function hi(h){return!!ct&&ct in h}var ci=Function.prototype,di=ci.toString;function de(h){if(h!=null){try{return di.call(h)}catch{}try{return h+""}catch{}}return""}var ui=/[\\^$.*+?()[\]{}|]/g,pi=/^\[object .+?Constructor\]$/,mi=Function.prototype,gi=Object.prototype,fi=mi.toString,yi=gi.hasOwnProperty,wi=RegExp("^"+fi.call(yi).replace(ui,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function vi(h){if(!ke(h)||hi(h))return!1;var t=ht(h)?wi:pi;return t.test(de(h))}function Ci(h,t){return h==null?void 0:h[t]}function ue(h,t){var e=Ci(h,t);return vi(e)?e:void 0}var Ye=ue(se,"WeakMap"),dt=Object.create,bi=(function(){function h(){}return function(t){if(!ke(t))return{};if(dt)return dt(t);h.prototype=t;var e=new h;return h.prototype=void 0,e}})(),ut=(function(){try{var h=ue(Object,"defineProperty");return h({},"",{}),h}catch{}})();function Pi(h,t){for(var e=-1,i=h==null?0:h.length;++e<i&&t(h[e],e,h)!==!1;);return h}var Li=9007199254740991,Ei=/^(?:0|[1-9]\d*)$/;function Mi(h,t){var e=typeof h;return t=t??Li,!!t&&(e=="number"||e!="symbol"&&Ei.test(h))&&h>-1&&h%1==0&&h<t}function xi(h,t,e){t=="__proto__"&&ut?ut(h,t,{configurable:!0,enumerable:!0,value:e,writable:!0}):h[t]=e}function pt(h,t){return h===t||h!==h&&t!==t}var Ii=Object.prototype,Ti=Ii.hasOwnProperty;function _i(h,t,e){var i=h[t];(!(Ti.call(h,t)&&pt(i,e))||e===void 0&&!(t in h))&&xi(h,t,e)}var Di=9007199254740991;function mt(h){return typeof h=="number"&&h>-1&&h%1==0&&h<=Di}function Si(h){return h!=null&&mt(h.length)&&!ht(h)}var Ai=Object.prototype;function gt(h){var t=h&&h.constructor,e=typeof t=="function"&&t.prototype||Ai;return h===e}function ki(h,t){for(var e=-1,i=Array(h);++e<h;)i[e]=t(e);return i}var $i="[object Arguments]";function ft(h){return Ee(h)&&Le(h)==$i}var yt=Object.prototype,Ri=yt.hasOwnProperty,Oi=yt.propertyIsEnumerable,Hi=ft((function(){return arguments})())?ft:function(h){return Ee(h)&&Ri.call(h,"callee")&&!Oi.call(h,"callee")};function Fi(){return!1}var wt=typeof A=="object"&&A&&!A.nodeType&&A,vt=wt&&typeof module=="object"&&module&&!module.nodeType&&module,zi=vt&&vt.exports===wt,Ct=zi?se.Buffer:void 0,Ni=Ct?Ct.isBuffer:void 0,bt=Ni||Fi,Gi="[object Arguments]",Bi="[object Array]",Yi="[object Boolean]",ji="[object Date]",Vi="[object Error]",Wi="[object Function]",Ui="[object Map]",Ki="[object Number]",Xi="[object Object]",qi="[object RegExp]",Zi="[object Set]",Ji="[object String]",Qi="[object WeakMap]",es="[object ArrayBuffer]",ts="[object DataView]",is="[object Float32Array]",ss="[object Float64Array]",ns="[object Int8Array]",os="[object Int16Array]",rs="[object Int32Array]",as="[object Uint8Array]",ls="[object Uint8ClampedArray]",hs="[object Uint16Array]",cs="[object Uint32Array]",z={};z[is]=z[ss]=z[ns]=z[os]=z[rs]=z[as]=z[ls]=z[hs]=z[cs]=!0,z[Gi]=z[Bi]=z[es]=z[Yi]=z[ts]=z[ji]=z[Vi]=z[Wi]=z[Ui]=z[Ki]=z[Xi]=z[qi]=z[Zi]=z[Ji]=z[Qi]=!1;function ds(h){return Ee(h)&&mt(h.length)&&!!z[Le(h)]}function je(h){return function(t){return h(t)}}var Pt=typeof A=="object"&&A&&!A.nodeType&&A,xe=Pt&&typeof module=="object"&&module&&!module.nodeType&&module,us=xe&&xe.exports===Pt,Ve=us&&rt.process,fe=(function(){try{var h=xe&&xe.require&&xe.require("util").types;return h||Ve&&Ve.binding&&Ve.binding("util")}catch{}})(),Lt=fe&&fe.isTypedArray,ps=Lt?je(Lt):ds,ms=Object.prototype,gs=ms.hasOwnProperty;function fs(h,t){var e=Me(h),i=!e&&Hi(h),n=!e&&!i&&bt(h),s=!e&&!i&&!n&&ps(h),o=e||i||n||s,r=o?ki(h.length,String):[],a=r.length;for(var l in h)gs.call(h,l)&&!(o&&(l=="length"||n&&(l=="offset"||l=="parent")||s&&(l=="buffer"||l=="byteLength"||l=="byteOffset")||Mi(l,a)))&&r.push(l);return r}function Et(h,t){return function(e){return h(t(e))}}var ys=Et(Object.keys,Object),ws=Object.prototype,vs=ws.hasOwnProperty;function Cs(h){if(!gt(h))return ys(h);var t=[];for(var e in Object(h))vs.call(h,e)&&e!="constructor"&&t.push(e);return t}function bs(h){return Si(h)?fs(h):Cs(h)}var Ie=ue(Object,"create");function Ps(){this.__data__=Ie?Ie(null):{},this.size=0}function Ls(h){var t=this.has(h)&&delete this.__data__[h];return this.size-=t?1:0,t}var Es="__lodash_hash_undefined__",Ms=Object.prototype,xs=Ms.hasOwnProperty;function Is(h){var t=this.__data__;if(Ie){var e=t[h];return e===Es?void 0:e}return xs.call(t,h)?t[h]:void 0}var Ts=Object.prototype,_s=Ts.hasOwnProperty;function Ds(h){var t=this.__data__;return Ie?t[h]!==void 0:_s.call(t,h)}var Ss="__lodash_hash_undefined__";function As(h,t){var e=this.__data__;return this.size+=this.has(h)?0:1,e[h]=Ie&&t===void 0?Ss:t,this}function pe(h){var t=-1,e=h==null?0:h.length;for(this.clear();++t<e;){var i=h[t];this.set(i[0],i[1])}}pe.prototype.clear=Ps,pe.prototype.delete=Ls,pe.prototype.get=Is,pe.prototype.has=Ds,pe.prototype.set=As;function ks(){this.__data__=[],this.size=0}function $e(h,t){for(var e=h.length;e--;)if(pt(h[e][0],t))return e;return-1}var $s=Array.prototype,Rs=$s.splice;function Os(h){var t=this.__data__,e=$e(t,h);if(e<0)return!1;var i=t.length-1;return e==i?t.pop():Rs.call(t,e,1),--this.size,!0}function Hs(h){var t=this.__data__,e=$e(t,h);return e<0?void 0:t[e][1]}function Fs(h){return $e(this.__data__,h)>-1}function zs(h,t){var e=this.__data__,i=$e(e,h);return i<0?(++this.size,e.push([h,t])):e[i][1]=t,this}function oe(h){var t=-1,e=h==null?0:h.length;for(this.clear();++t<e;){var i=h[t];this.set(i[0],i[1])}}oe.prototype.clear=ks,oe.prototype.delete=Os,oe.prototype.get=Hs,oe.prototype.has=Fs,oe.prototype.set=zs;var Te=ue(se,"Map");function Ns(){this.size=0,this.__data__={hash:new pe,map:new(Te||oe),string:new pe}}function Gs(h){var t=typeof h;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?h!=="__proto__":h===null}function Re(h,t){var e=h.__data__;return Gs(t)?e[typeof t=="string"?"string":"hash"]:e.map}function Bs(h){var t=Re(this,h).delete(h);return this.size-=t?1:0,t}function Ys(h){return Re(this,h).get(h)}function js(h){return Re(this,h).has(h)}function Vs(h,t){var e=Re(this,h),i=e.size;return e.set(h,t),this.size+=e.size==i?0:1,this}function ye(h){var t=-1,e=h==null?0:h.length;for(this.clear();++t<e;){var i=h[t];this.set(i[0],i[1])}}ye.prototype.clear=Ns,ye.prototype.delete=Bs,ye.prototype.get=Ys,ye.prototype.has=js,ye.prototype.set=Vs;function Ws(h,t){for(var e=-1,i=t.length,n=h.length;++e<i;)h[n+e]=t[e];return h}var Us=Et(Object.getPrototypeOf,Object);function Ks(){this.__data__=new oe,this.size=0}function Xs(h){var t=this.__data__,e=t.delete(h);return this.size=t.size,e}function qs(h){return this.__data__.get(h)}function Zs(h){return this.__data__.has(h)}var Js=200;function Qs(h,t){var e=this.__data__;if(e instanceof oe){var i=e.__data__;if(!Te||i.length<Js-1)return i.push([h,t]),this.size=++e.size,this;e=this.__data__=new ye(i)}return e.set(h,t),this.size=e.size,this}function we(h){var t=this.__data__=new oe(h);this.size=t.size}we.prototype.clear=Ks,we.prototype.delete=Xs,we.prototype.get=qs,we.prototype.has=Zs,we.prototype.set=Qs;var Mt=typeof A=="object"&&A&&!A.nodeType&&A,xt=Mt&&typeof module=="object"&&module&&!module.nodeType&&module,en=xt&&xt.exports===Mt,It=en?se.Buffer:void 0;It&&It.allocUnsafe;function tn(h,t){return h.slice()}function sn(h,t){for(var e=-1,i=h==null?0:h.length,n=0,s=[];++e<i;){var o=h[e];t(o,e,h)&&(s[n++]=o)}return s}function nn(){return[]}var on=Object.prototype,rn=on.propertyIsEnumerable,Tt=Object.getOwnPropertySymbols,an=Tt?function(h){return h==null?[]:(h=Object(h),sn(Tt(h),function(t){return rn.call(h,t)}))}:nn;function ln(h,t,e){var i=t(h);return Me(h)?i:Ws(i,e(h))}function hn(h){return ln(h,bs,an)}var We=ue(se,"DataView"),Ue=ue(se,"Promise"),Ke=ue(se,"Set"),_t="[object Map]",cn="[object Object]",Dt="[object Promise]",St="[object Set]",At="[object WeakMap]",kt="[object DataView]",dn=de(We),un=de(Te),pn=de(Ue),mn=de(Ke),gn=de(Ye),re=Le;(We&&re(new We(new ArrayBuffer(1)))!=kt||Te&&re(new Te)!=_t||Ue&&re(Ue.resolve())!=Dt||Ke&&re(new Ke)!=St||Ye&&re(new Ye)!=At)&&(re=function(h){var t=Le(h),e=t==cn?h.constructor:void 0,i=e?de(e):"";if(i)switch(i){case dn:return kt;case un:return _t;case pn:return Dt;case mn:return St;case gn:return At}return t});var fn=Object.prototype,yn=fn.hasOwnProperty;function wn(h){var t=h.length,e=new h.constructor(t);return t&&typeof h[0]=="string"&&yn.call(h,"index")&&(e.index=h.index,e.input=h.input),e}var $t=se.Uint8Array;function Xe(h){var t=new h.constructor(h.byteLength);return new $t(t).set(new $t(h)),t}function vn(h,t){var e=Xe(h.buffer);return new h.constructor(e,h.byteOffset,h.byteLength)}var Cn=/\w*$/;function bn(h){var t=new h.constructor(h.source,Cn.exec(h));return t.lastIndex=h.lastIndex,t}var Rt=ge?ge.prototype:void 0,Ot=Rt?Rt.valueOf:void 0;function Pn(h){return Ot?Object(Ot.call(h)):{}}function Ln(h,t){var e=Xe(h.buffer);return new h.constructor(e,h.byteOffset,h.length)}var En="[object Boolean]",Mn="[object Date]",xn="[object Map]",In="[object Number]",Tn="[object RegExp]",_n="[object Set]",Dn="[object String]",Sn="[object Symbol]",An="[object ArrayBuffer]",kn="[object DataView]",$n="[object Float32Array]",Rn="[object Float64Array]",On="[object Int8Array]",Hn="[object Int16Array]",Fn="[object Int32Array]",zn="[object Uint8Array]",Nn="[object Uint8ClampedArray]",Gn="[object Uint16Array]",Bn="[object Uint32Array]";function Yn(h,t,e){var i=h.constructor;switch(t){case An:return Xe(h);case En:case Mn:return new i(+h);case kn:return vn(h);case $n:case Rn:case On:case Hn:case Fn:case zn:case Nn:case Gn:case Bn:return Ln(h);case xn:return new i;case In:case Dn:return new i(h);case Tn:return bn(h);case _n:return new i;case Sn:return Pn(h)}}function jn(h){return typeof h.constructor=="function"&&!gt(h)?bi(Us(h)):{}}var Vn="[object Map]";function Wn(h){return Ee(h)&&re(h)==Vn}var Ht=fe&&fe.isMap,Un=Ht?je(Ht):Wn,Kn="[object Set]";function Xn(h){return Ee(h)&&re(h)==Kn}var Ft=fe&&fe.isSet,qn=Ft?je(Ft):Xn,zt="[object Arguments]",Zn="[object Array]",Jn="[object Boolean]",Qn="[object Date]",eo="[object Error]",Nt="[object Function]",to="[object GeneratorFunction]",io="[object Map]",so="[object Number]",Gt="[object Object]",no="[object RegExp]",oo="[object Set]",ro="[object String]",ao="[object Symbol]",lo="[object WeakMap]",ho="[object ArrayBuffer]",co="[object DataView]",uo="[object Float32Array]",po="[object Float64Array]",mo="[object Int8Array]",go="[object Int16Array]",fo="[object Int32Array]",yo="[object Uint8Array]",wo="[object Uint8ClampedArray]",vo="[object Uint16Array]",Co="[object Uint32Array]",F={};F[zt]=F[Zn]=F[ho]=F[co]=F[Jn]=F[Qn]=F[uo]=F[po]=F[mo]=F[go]=F[fo]=F[io]=F[so]=F[Gt]=F[no]=F[oo]=F[ro]=F[ao]=F[yo]=F[wo]=F[vo]=F[Co]=!0,F[eo]=F[Nt]=F[lo]=!1;function Oe(h,t,e,i,n,s){var o;if(o!==void 0)return o;if(!ke(h))return h;var r=Me(h);if(r)o=wn(h);else{var a=re(h),l=a==Nt||a==to;if(bt(h))return tn(h);if(a==Gt||a==zt||l&&!n)o=l?{}:jn(h);else{if(!F[a])return n?h:{};o=Yn(h,a)}}s||(s=new we);var d=s.get(h);if(d)return d;s.set(h,o),qn(h)?h.forEach(function(g){o.add(Oe(g,t,e,g,h,s))}):Un(h)&&h.forEach(function(g,m){o.set(m,Oe(g,t,e,m,h,s))});var u=hn,p=r?void 0:u(h);return Pi(p||h,function(g,m){p&&(m=g,g=h[m]),_i(o,m,Oe(g,t,e,m,h,s))}),o}var bo=1,Po=4;function He(h){return Oe(h,bo|Po)}var Bt=(h=>(h.Rotate="rotate",h.Move="move",h.Scale="scale",h.MoveHeight="moveHeight",h.Empty="",h))(Bt||{}),Yt=(h=>(h.Scale="addScale",h.Rotate="rotate",h.Translation="translation",h.Remove="removeById",h.Add="add",h))(Yt||{});class Lo{constructor(t){c(this,"primitives",new Map);c(this,"eventListener",new Map);c(this,"Cesium");c(this,"viewer");c(this,"handler");c(this,"rotationRing");c(this,"moveAxis");c(this,"translationSquare");c(this,"heightArrow");c(this,"scaleHandle");c(this,"scaleCenterProxy");c(this,"editMode","");c(this,"dragEndCallbackMap",new Map);c(this,"activeModelId","");c(this,"activeModelVisualState",new Map);c(this,"overlayContainer",null);c(this,"modeToolbarEl",null);c(this,"feedbackLabelEl",null);c(this,"overlayUpdateFn",null);c(this,"feedbackAnchor",null);c(this,"tooltipManager",null);c(this,"tooltipHideTimer",null);c(this,"scaleCenterHintVisible",!1);this.Cesium=t.Cesium,this.viewer=t.viewer,this.handler=new this.Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas),this.initOverlay(),typeof document<"u"&&(this.tooltipManager=new ce)}isSceneGadgetDebugEnabled(){var t;if(typeof window>"u")return!1;try{return window.__SCENE_GADGET_DEBUG__===!0||((t=window.localStorage)==null?void 0:t.getItem("sceneGadgetDebug"))==="1"}catch{return!1}}debugLog(t,e){this.isSceneGadgetDebugEnabled()&&console.log("[SceneGadget][GLTFManage]",t,e||{})}getPickDebugId(t){var i,n,s;if(!t)return null;const e=(t==null?void 0:t.id)||((i=t==null?void 0:t.primitive)==null?void 0:i.id)||null;return typeof e=="string"?e:e&&typeof(e==null?void 0:e.id)=="string"?e.id:e&&typeof(e==null?void 0:e.name)=="string"?e.name:(s=(n=t==null?void 0:t.primitive)==null?void 0:n.constructor)!=null&&s.name?`[primitive:${t.primitive.constructor.name}]`:String(e)}debugPickStack(t,e){var n;if(!this.isSceneGadgetDebugEnabled())return;const i=(n=this.viewer)==null?void 0:n.scene;if(!(!(i!=null&&i.drillPick)||!t))try{const s=i.drillPick(t,12)||[];this.debugLog("pick-stack",{mode:e,activeModelId:this.activeModelId,stack:s.map((o,r)=>({index:r,id:this.getPickDebugId(o)}))})}catch(s){this.debugLog("pick-stack:error",{mode:e,message:s instanceof Error?s.message:String(s)})}}showModeHint(t,e=2200){!this.tooltipManager||!t||(this.scaleCenterHintVisible=!0,this.tooltipManager.show(t),this.tooltipHideTimer&&clearTimeout(this.tooltipHideTimer),this.tooltipHideTimer=setTimeout(()=>{this.hideModeHint()},e))}showHoverModeHint(t){!this.tooltipManager||!t||(this.tooltipHideTimer&&(clearTimeout(this.tooltipHideTimer),this.tooltipHideTimer=null),this.tooltipManager.show(t),this.scaleCenterHintVisible=!0)}hideModeHint(){var t;this.tooltipHideTimer&&(clearTimeout(this.tooltipHideTimer),this.tooltipHideTimer=null),(t=this.tooltipManager)==null||t.hide(),this.scaleCenterHintVisible=!1}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)}async add(t,e=!0){var g,m,f,w,y;const i=this.viewer,n=this.Cesium,s=n.Math.toRadians(((g=t.headingPitchRoll)==null?void 0:g.heading)||0),o=n.Math.toRadians(((m=t.headingPitchRoll)==null?void 0:m.pitch)||0),r=n.Math.toRadians(((f=t.headingPitchRoll)==null?void 0:f.roll)||0),a=new n.HeadingPitchRoll(s,o,r);let l=t.position;if(Me(l)?l=n.Cartesian3.fromDegrees(l[0],l[1],l[2]||0):l&&typeof l=="object"&&typeof l.lng<"u"&&typeof l.lat<"u"&&(l=n.Cartesian3.fromDegrees(l.lng,l.lat,l.height||0)),!l)throw new Error("GLTFManage.add 缺少有效 position");const d=this.composeModelMatrix(l,a,t.scale),u={id:t.id,...t.model,modelMatrix:d};let p;if(typeof((w=n==null?void 0:n.Model)==null?void 0:w.fromGltf)=="function")p=i.scene.primitives.add(n.Model.fromGltf(u));else if(typeof((y=n==null?void 0:n.Model)==null?void 0:y.fromGltfAsync)=="function"){const v=await n.Model.fromGltfAsync(u);p=i.scene.primitives.add(v)}else throw new Error("Cesium.Model.fromGltf / fromGltfAsync 均不可用");p.scale=1,p.__sceneGadgetScale=this.getPrimitiveScale({modelMatrix:d}),this.initializePrimitiveRuntimeState(p),this.primitives.set(t.id,p),p.show=e,this.runEventListener("add",{info:t,gltf:p})}flyTo(t){const e=this.viewer;let i=this.primitives.get(t);const n=this.Cesium,s=this.getPrimitiveWorldBoundingSphere(i);s&&e.camera.flyToBoundingSphere(s,{duration:1.5,offset:new n.HeadingPitchRange(0,-.5,Math.max(s.radius*2.8,60))})}removeById(t){const e=this.viewer;let i=this.primitives.get(t);if(!i){console.error(`No model found with id: ${t}`);return}this.activeModelId===t&&this.deactivateEdit(),e.scene.primitives.remove(i),this.primitives.delete(t),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);if(i){const n=this.getPrimitiveScale(i),s={x:n.x+e,y:n.y+e,z:n.z+e};this.applyScaleToPrimitive(i,s),this.activeModelId===t.id?this.refreshActiveToolGeometry():this.updatedTool(i.modelMatrix),this.runEventListener("addScale",{id:t.id,scale:s})}}setScale(t,e=.1){let i=this.primitives.get(t);if(i){const n={x:e,y:e,z:e};this.applyScaleToPrimitive(i,n),this.activeModelId===t?this.refreshActiveToolGeometry():this.updatedTool(i.modelMatrix),this.runEventListener("addScale",{id:t,scale:n})}}setEditMode(t){this.editMode=t,this.updateToolbarState()}normalizeScaleVector(t){const e=this.Cesium;if(typeof t=="number"){const i=Number(t||1);return new e.Cartesian3(i,i,i)}return new e.Cartesian3(Number((t==null?void 0:t.x)??1),Number((t==null?void 0:t.y)??1),Number((t==null?void 0:t.z)??1))}getPrimitiveScale(t){const e=this.Cesium;if(!t)return{x:1,y:1,z:1};if(t.__sceneGadgetScale)return{x:Number(t.__sceneGadgetScale.x??1),y:Number(t.__sceneGadgetScale.y??1),z:Number(t.__sceneGadgetScale.z??1)};const i=e.Matrix4.getScale(t.modelMatrix,new e.Cartesian3);return{x:Number(i.x||1),y:Number(i.y||1),z:Number(i.z||1)}}initializePrimitiveRuntimeState(t){var i,n;if(!t)return;const e=()=>{const s=this.getPrimitiveRuntimeRadius(t);s>0&&(t.__sceneGadgetRuntimeRadiusReady=!0,this.cachePrimitiveUnitRadius(t,s))};if(e(),!t.__sceneGadgetRuntimeRadiusReady&&typeof((i=t==null?void 0:t.readyPromise)==null?void 0:i.then)=="function"){t.readyPromise.then(()=>{e()}).catch(()=>{});return}!t.__sceneGadgetRuntimeRadiusReady&&typeof((n=t==null?void 0:t.readyEvent)==null?void 0:n.addEventListener)=="function"&&t.readyEvent.addEventListener(()=>{e()})}getPrimitiveRuntimeRadius(t){var e;if(!t)return 0;try{const i=Number(((e=t==null?void 0:t.boundingSphere)==null?void 0:e.radius)||0);if(Number.isFinite(i)&&i>0)return i}catch{return 0}return 0}cachePrimitiveUnitRadius(t,e){if(!t)return 0;const i=Number(t.__sceneGadgetUnitRadius||0);if(Number.isFinite(i)&&i>0)return i;const n=Number(e||this.getPrimitiveRuntimeRadius(t)||0);if(!Number.isFinite(n)||n<=0)return 0;const s=this.getPrimitiveScale(t),o=Math.max(Math.abs(Number(s.x||1)),Math.abs(Number(s.y||1)),Math.abs(Number(s.z||1)),1),r=n/o;return t.__sceneGadgetUnitRadius=r,r}getPrimitiveFallbackRadius(t){if(!t)return 1;const e=this.getPrimitiveScale(t);return Math.max(Math.abs(Number(e.x||1)),Math.abs(Number(e.y||1)),Math.abs(Number(e.z||1)),1)}getPrimitiveEffectiveRadius(t){const e=this.cachePrimitiveUnitRadius(t);if(e>0){const i=this.getPrimitiveScale(t),n=Math.max(Math.abs(Number(i.x||1)),Math.abs(Number(i.y||1)),Math.abs(Number(i.z||1)),1);return Math.max(e*n,e,1)}return Math.max(this.getPrimitiveRuntimeRadius(t),this.getPrimitiveFallbackRadius(t),1)}getPrimitiveWorldBoundingSphere(t){const e=this.Cesium;if(!(t!=null&&t.modelMatrix))return null;const i=e.Matrix4.getTranslation(t.modelMatrix,new e.Cartesian3),n=this.getPrimitiveEffectiveRadius(t);return!Number.isFinite(n)||n<=0?null:new e.BoundingSphere(i,n)}extractModelBaseMatrix(t){const e=this.Cesium,i=e.Matrix4.getScale(t,new e.Cartesian3),n=new e.Cartesian3(Math.abs(i.x)<1e-6?1:1/i.x,Math.abs(i.y)<1e-6?1:1/i.y,Math.abs(i.z)<1e-6?1:1/i.z);return e.Matrix4.multiply(t,e.Matrix4.fromScale(n),new e.Matrix4)}composeModelMatrix(t,e,i){const n=this.Cesium,s=n.Transforms.headingPitchRollToFixedFrame(t,e,this.viewer.scene.globe.ellipsoid,n.Transforms.eastNorthUpToFixedFrame,new n.Matrix4);return n.Matrix4.multiply(s,n.Matrix4.fromScale(this.normalizeScaleVector(i)),new n.Matrix4)}applyScaleToPrimitive(t,e,i){const n=this.Cesium,s=this.getPrimitiveScale(t),o=this.getPrimitiveRuntimeRadius(t),r=this.getPrimitiveEffectiveRadius(t),a=this.cachePrimitiveUnitRadius(t,o),l=this.normalizeScaleVector(e),d=i||this.extractModelBaseMatrix(t.modelMatrix);t.__sceneGadgetScale={x:l.x,y:l.y,z:l.z},t.scale=1,t.modelMatrix=n.Matrix4.multiply(d,n.Matrix4.fromScale(l),new n.Matrix4);const u=this.getPrimitiveScale(t),p=this.getPrimitiveRuntimeRadius(t),g=this.getPrimitiveEffectiveRadius(t);return this.debugLog("applyScaleToPrimitive",{id:t==null?void 0:t.id,inputScale:e,unitRadius:a,beforeScale:s,afterScale:u,beforeRadius:o,afterRadius:p,beforeEffectiveRadius:r,afterEffectiveRadius:g}),t.modelMatrix}getGizmoModelMatrix(t){return this.extractModelBaseMatrix(t.modelMatrix)}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=this.extractModelBaseMatrix(t),s=e.Transforms.eastNorthUpToFixedFrame(e.Matrix4.getTranslation(n,new e.Cartesian3),i.scene.globe.ellipsoid,new e.Matrix4),o=e.Matrix4.multiply(e.Matrix4.inverse(s,new e.Matrix4),n,new e.Matrix4),r=e.Matrix4.getRotation(o,new e.Matrix3),a=e.Quaternion.fromRotationMatrix(r);return e.HeadingPitchRoll.fromQuaternion(a)}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,a=null,l="",d="",u=null,p=null,g=null,m=null;const f=()=>{s=null,o=null,r=null,a=null,l="",d="",u=null,p=null,g=null,m=null,this.hideFeedback(),this.unlockCamera()},w=C=>{const b=P=>(C.split(P)[1]||"").split("_");if(C.includes("moveAxis_")){const P=b("moveAxis_");return{modelId:P[0],mode:"move",axis:String(P[1]||"").toUpperCase()}}if(C.includes("translationPlane_")){const P=b("translationPlane_");return{modelId:P[0],mode:"move",axis:String(P[1]||"").toUpperCase()}}if(C.includes("rotationArc_")){const P=b("rotationArc_");return{modelId:P[0],mode:"rotate",axis:String(P[1]||"").toUpperCase()}}if(C.includes("rotationSector_")){const P=b("rotationSector_");return{modelId:P[0],mode:"rotate",axis:String(P[1]||"").toUpperCase()}}if(C.includes("scaleHandle_")){const P=b("scaleHandle_");return{modelId:P[0],mode:"scale",axis:String(P[1]||"").toUpperCase()}}if(C.includes("scaleAxis_")){const P=b("scaleAxis_");return{modelId:P[0],mode:"scale",axis:String(P[1]||"").toUpperCase()}}return C.includes("scaleCenter_")?{modelId:b("scaleCenter_")[0],mode:"scale",axis:"CENTER"}:C.includes("scaleCenterHit_")?{modelId:b("scaleCenterHit_")[0],mode:"scale",axis:"CENTER"}:null},y=C=>{if(this.editMode!=="scale"||!this.activeModelId||!C||!(n!=null&&n.drillPick))return!1;try{return(n.drillPick(C,12)||[]).some(P=>{const E=this.getPickDebugId(P);if(typeof E!="string")return!1;const L=w(E);return(L==null?void 0:L.mode)==="scale"&&(L==null?void 0:L.axis)==="CENTER"&&(L==null?void 0:L.modelId)===this.activeModelId})}catch{return!1}},v=(C,b,P,E)=>{if(s=this.primitives.get(C),s){l=P,d=E,o=e.Matrix4.clone(s.modelMatrix),a=this.normalizeScaleVector(this.getPrimitiveScale(s));const L=e.Matrix4.getTranslation(o,new e.Cartesian3);g=e.Cartesian3.clone(L),r=e.Cartesian2.clone(b.position||b.endPosition,new e.Cartesian2);const M=e.Transforms.eastNorthUpToFixedFrame(g);let x=new e.Cartesian3;P==="move"?E==="XY"?e.Matrix4.getColumn(M,2,x):E==="YZ"?e.Matrix4.getColumn(M,0,x):E==="ZX"?e.Matrix4.getColumn(M,1,x):x=e.Cartesian3.clone(i.scene.camera.direction):P==="rotate"?(E==="X"&&e.Matrix4.getColumn(M,0,x),E==="Y"&&e.Matrix4.getColumn(M,1,x),E==="Z"&&e.Matrix4.getColumn(M,2,x)):x=e.Cartesian3.clone(i.scene.camera.direction),e.Cartesian3.normalize(x,x),u=e.Plane.fromPointNormal(g,x);const _=i.camera.getPickRay(b.position||b.endPosition);p=_&&u?e.IntersectionTests.rayPlane(_,u):null,p&&(m=e.Cartesian3.subtract(p,g,new e.Cartesian3),e.Cartesian3.magnitudeSquared(m)>0&&e.Cartesian3.normalize(m,m)),this.lockCamera()}};this.handler.setInputAction(C=>{var M,x;if(!t())return;(this.editMode==="scale"||this.editMode==="move")&&this.debugPickStack(C.position,this.editMode);const P=n.pick(C.position),E=(P==null?void 0:P.id)||((M=P==null?void 0:P.primitive)==null?void 0:M.id);if(typeof E!="string"){this.editMode==="scale"&&this.debugLog("scale:leftDown:miss",{activeModelId:this.activeModelId,pickedPrimitiveId:(x=P==null?void 0:P.primitive)==null?void 0:x.id,pickedId:P==null?void 0:P.id});return}let L=w(E);this.editMode==="scale"&&this.debugLog("scale:leftDown:hit",{activeModelId:this.activeModelId,hitId:E,hitInfo:L}),L!=null&&L.modelId&&(this.setEditMode(L.mode),v(L.modelId,C,L.mode,L.axis),L.mode==="scale"&&L.axis==="CENTER"&&this.debugLog("scale:center:drag-start",{modelId:L.modelId,startMousePosition:C.position}))},e.ScreenSpaceEventType.LEFT_DOWN),this.handler.setInputAction(C=>{if(t()&&(l===""?y(C.endPosition)?this.showHoverModeHint("向上拖放大,向下拖缩小"):this.scaleCenterHintVisible&&this.hideModeHint():this.scaleCenterHintVisible&&this.hideModeHint(),l!=""&&s&&u&&g&&p)){const P=i.camera.getPickRay(C.endPosition),E=P?e.IntersectionTests.rayPlane(P,u):null;if(!E)return;l==="rotate"?this.rotateModel(s,o,d,g,m,E):l==="move"?this.moveModel(s,o,d,g,p,E):l==="scale"&&this.moveModelScale(s,o,d,g,r,p,a,C.endPosition,E)}},e.ScreenSpaceEventType.MOUSE_MOVE),this.handler.setInputAction(()=>{if(!t())return;let b=this.dragEndCallbackMap.get(s==null?void 0:s.id);if(b&&(l==="move"||l==="moveHeight")){let P=b.get("translation");P&&(this.runEventListener("translation",P),b.delete("translation"))}else if(b&&l==="rotate"){let P=b.get("rotate");P&&(this.runEventListener("rotate",P),b.delete("rotate"))}else if(b&&l==="scale"){let P=b.get("addScale");P&&(this.runEventListener("addScale",P),b.delete("addScale"))}f()},e.ScreenSpaceEventType.LEFT_UP),this.handler.setInputAction(()=>{f()},e.ScreenSpaceEventType.RIGHT_UP)}activateEditById(t,e){var s,o;const i=this.primitives.get(t);if(!i)return;const n=this.getPrimitiveRuntimeRadius(i);if(!Number.isFinite(n)||n<=0){typeof((s=i==null?void 0:i.readyPromise)==null?void 0:s.then)=="function"?i.readyPromise.then(()=>this.activateEditById(t,e)).catch(()=>{}):typeof((o=i==null?void 0:i.readyEvent)==null?void 0:o.addEventListener)=="function"&&i.readyEvent.addEventListener(()=>this.activateEditById(t,e));return}this.activeModelId&&this.activeModelId!==t&&this.deactivateEdit(!1),this.activeModelId=t,this.highlightModel(i,!0),this.showModeToolbar(t),this.switchEditMode(e||this.editMode||"move")}deactivateEdit(t=!0){this.removeTool(),this.clearActiveModelVisual(),this.hideModeToolbar(),this.hideFeedback(),this.hideModeHint(),this.activeModelId="",t&&this.setEditMode(""),this.unlockCamera()}switchEditMode(t){if(!t)return;const e=t==="moveHeight"?"move":t;this.setEditMode(e),this.refreshActiveToolGeometry(),this.updateOverlayPosition(),e!=="scale"&&this.hideModeHint()}refreshActiveToolGeometry(){const t=this.activeModelId?this.primitives.get(this.activeModelId):null;this.removeTool(),t&&(this.editMode==="move"?(this.createMoveAxis(t),this.createTranslationSquare(t)):this.editMode==="rotate"?this.createRotationRing(t):this.editMode==="scale"&&this.createScaleHandle(t))}highlightModel(t,e){if(!t)return;if(e){this.activeModelVisualState.has(t.id)||this.activeModelVisualState.set(t.id,{silhouetteColor:t.silhouetteColor,silhouetteSize:t.silhouetteSize}),t.silhouetteSize=0;return}const i=this.activeModelVisualState.get(t.id);i?(t.silhouetteColor=i.silhouetteColor,t.silhouetteSize=i.silhouetteSize,this.activeModelVisualState.delete(t.id)):t.silhouetteSize=0}clearActiveModelVisual(){if(!this.activeModelId)return;const t=this.primitives.get(this.activeModelId);if(t){this.highlightModel(t,!1);return}this.activeModelVisualState.delete(this.activeModelId)}initOverlay(){var r;if(typeof document>"u")return;const t=document.createElement("div");t.className="scene-gadget-gizmo-overlay",Object.assign(t.style,{position:"absolute",inset:"0",pointerEvents:"none",zIndex:"120"});const e=((r=this.viewer)==null?void 0:r.container)||document.body,i=window.getComputedStyle(e);e!==document.body&&i.position==="static"&&(e.style.position="relative");const n=document.createElement("div");Object.assign(n.style,{position:"absolute",display:"none",gap:"10px",flexDirection:"column",alignItems:"stretch",padding:"10px 8px",borderRadius:"14px",background:"rgba(7, 12, 20, 0.92)",border:"1px solid rgba(255,255,255,0.08)",boxShadow:"0 12px 28px rgba(0,0,0,0.28)",pointerEvents:"auto",transform:"translate(0, -50%)",backdropFilter:"blur(10px)"});const s=document.createElement("div");Object.assign(s.style,{position:"absolute",display:"none",padding:"4px 8px",borderRadius:"999px",background:"rgba(7, 13, 20, 0.92)",color:"#fff",fontSize:"12px",fontWeight:"600",lineHeight:"18px",pointerEvents:"none",transform:"translate(-50%, calc(-100% - 8px))",boxShadow:"0 8px 18px rgba(0,0,0,0.24)",whiteSpace:"nowrap"}),[{mode:"move",label:"移",title:"移动",color:"#53d7ff"},{mode:"rotate",label:"旋",title:"旋转",color:"#ff8a61"},{mode:"scale",label:"缩",title:"缩放",color:"#ffd76a"}].forEach(a=>{const l=document.createElement("button");l.type="button",l.dataset.mode=a.mode,l.title=a.title,l.innerText=a.label,Object.assign(l.style,{width:"42px",height:"42px",borderRadius:"10px",border:"1px solid rgba(255,255,255,0.08)",background:"rgba(255,255,255,0.05)",color:a.color,fontSize:"13px",fontWeight:"700",cursor:"pointer",pointerEvents:"auto"}),l.addEventListener("click",d=>{d.stopPropagation(),this.switchEditMode(a.mode)}),n.appendChild(l)}),t.appendChild(n),t.appendChild(s),e.appendChild(t),this.overlayContainer=t,this.modeToolbarEl=n,this.feedbackLabelEl=s,this.overlayUpdateFn=this.updateOverlayPosition.bind(this),this.viewer.scene.postRender.addEventListener(this.overlayUpdateFn)}showModeToolbar(t){this.modeToolbarEl&&(this.modeToolbarEl.style.display="flex",this.updateToolbarState(),this.updateOverlayPosition())}hideModeToolbar(){this.modeToolbarEl&&(this.modeToolbarEl.style.display="none")}updateToolbarState(){if(!this.modeToolbarEl)return;Array.from(this.modeToolbarEl.querySelectorAll("button")).forEach(e=>{const i=e.dataset.mode===this.editMode;Object.assign(e.style,i?{background:"rgba(255,255,255,0.14)",borderColor:"rgba(255,255,255,0.22)",boxShadow:"inset 0 0 0 1px rgba(255,255,255,0.05)"}:{background:"rgba(255,255,255,0.05)",borderColor:"rgba(255,255,255,0.08)",boxShadow:"none"})})}updateOverlayPosition(){var t,e;try{if(!this.activeModelId)return;const i=this.primitives.get(this.activeModelId);if(!i)return;const n=this.Cesium,s=this.getGizmoScreenBounds(i);if(!s){this.hideModeToolbar(),this.hideFeedback();return}const o=s.center,r=(e=(t=this.viewer)==null?void 0:t.scene)==null?void 0:e.canvas,a=Number((r==null?void 0:r.clientWidth)||(r==null?void 0:r.width)||0),l=Number((r==null?void 0:r.clientHeight)||(r==null?void 0:r.height)||0);if(this.modeToolbarEl&&this.modeToolbarEl.style.display!=="none"){const d=Number(this.modeToolbarEl.offsetWidth||58),u=Number(this.modeToolbarEl.offsetHeight||176),p=18;let g=s.maxX+p;g+d>a-12&&(g=s.minX-d-p),g=n.Math.clamp(g,12,Math.max(12,a-d-12));const m=(s.minY+s.maxY)/2,f=n.Math.clamp(m-u/2,12,Math.max(12,l-u-12));this.modeToolbarEl.style.left=`${g}px`,this.modeToolbarEl.style.top=`${f+u/2}px`}if(this.feedbackLabelEl&&this.feedbackLabelEl.style.display!=="none"){const d=this.feedbackAnchor||o,u=this.toWindowCoordinates(d);u&&(this.feedbackLabelEl.style.left=`${u.x}px`,this.feedbackLabelEl.style.top=`${u.y}px`)}}catch{this.hideModeToolbar(),this.hideFeedback()}}showFeedback(t,e){this.feedbackLabelEl&&(this.feedbackAnchor=e||null,this.feedbackLabelEl.innerText=t,this.feedbackLabelEl.style.display="block",this.updateOverlayPosition())}hideFeedback(){this.feedbackAnchor=null,this.feedbackLabelEl&&(this.feedbackLabelEl.style.display="none")}toWindowCoordinates(t){var s;const e=this.Cesium,i=(s=this.viewer)==null?void 0:s.scene,n=e==null?void 0:e.SceneTransforms;if(!(!i||!n||!t)){if(typeof n.wgs84ToWindowCoordinates=="function")return n.wgs84ToWindowCoordinates(i,t);if(typeof n.worldToWindowCoordinates=="function")return n.worldToWindowCoordinates(i,t)}}createUnitBoxGeometry(){const t=this.Cesium;return t.BoxGeometry.createGeometry(new t.BoxGeometry({maximum:new t.Cartesian3(.5,.5,.5),minimum:new t.Cartesian3(-.5,-.5,-.5)}))}getGizmoAppearance(){const t=this.Cesium;return new t.PerInstanceColorAppearance({translucent:!0,flat:!0,renderState:{depthTest:{enabled:!1},depthMask:!1,cull:{enabled:!1},blending:t.BlendingState.ALPHA_BLEND}})}getGizmoMetrics(t){const e=Math.max(this.getPrimitiveEffectiveRadius(t),8),i=Math.max(e*.08,2.2),n=Math.max(e*1.25,20),s=Math.max(e*.28,6),o=Math.max(e*.065,1.8),r=Math.max(e*.028,1.1),a=Math.max(i*2.2,e*.18),l=Math.max(e*.62,a+6),d=Math.max(e*.018,.8),u=Math.max(e*1.02,18),p=Math.max(e*.024,1.15),g=Math.max(e*1.06,18),m=Math.max(e*.075,2.4);return{centerRadius:i,axisLength:n,arrowLength:s,arrowRadius:o,axisThickness:r,planeStart:a,planeEnd:l,planeThickness:d,rotationRadius:u,rotationThickness:p,scaleOffset:g,scaleHandleRadius:m}}createSegmentInstance(t,e,i,n,s){const o=this.Cesium,r=o.Cartesian3.subtract(i,e,new o.Cartesian3),a=o.Cartesian3.magnitude(r);if(!Number.isFinite(a)||a<=0)return null;const l=o.Cartesian3.normalize(r,new o.Cartesian3),d=o.Cartesian3.midpoint(e,i,new o.Cartesian3),u=o.Cartesian3.UNIT_X,p=o.Cartesian3.cross(u,l,new o.Cartesian3),g=o.Cartesian3.magnitude(p),m=o.Math.clamp(o.Cartesian3.dot(u,l),-1,1);let f=o.Quaternion.clone(o.Quaternion.IDENTITY);return g>1e-6?(o.Cartesian3.normalize(p,p),f=o.Quaternion.fromAxisAngle(p,Math.acos(m))):m<0&&(f=o.Quaternion.fromAxisAngle(o.Cartesian3.UNIT_Z,Math.PI)),new o.GeometryInstance({id:t,geometry:this.createUnitBoxGeometry(),modelMatrix:o.Matrix4.fromTranslationQuaternionRotationScale(d,f,new o.Cartesian3(a,n,n)),attributes:{color:o.ColorGeometryInstanceAttribute.fromColor(s)}})}createCenterInstance(t,e,i){const n=this.Cesium;return new n.GeometryInstance({id:t,geometry:new n.EllipsoidGeometry({radii:new n.Cartesian3(e,e,e),vertexFormat:n.PerInstanceColorAppearance.VERTEX_FORMAT}),attributes:{color:n.ColorGeometryInstanceAttribute.fromColor(i)}})}createCenterBoxInstance(t,e,i){const n=this.Cesium;return new n.GeometryInstance({id:t,geometry:n.BoxGeometry.createGeometry(new n.BoxGeometry({maximum:new n.Cartesian3(e,e,e),minimum:new n.Cartesian3(-e,-e,-e)})),attributes:{color:n.ColorGeometryInstanceAttribute.fromColor(i)}})}getAxisVector(t,e){const i=this.Cesium;return e==="X"?i.Matrix4.getColumn(t,0,new i.Cartesian3):e==="Y"?i.Matrix4.getColumn(t,1,new i.Cartesian3):i.Matrix4.getColumn(t,2,new i.Cartesian3)}getRotationPlanePoint(t,e,i){const n=this.Cesium;return t==="xy"?new n.Cartesian3(e*Math.cos(i),e*Math.sin(i),0):t==="yz"?new n.Cartesian3(0,e*Math.cos(i),e*Math.sin(i)):new n.Cartesian3(e*Math.cos(i),0,e*Math.sin(i))}getGizmoLocalBounds(t){const e=this.Cesium,i=this.getGizmoMetrics(t);if(this.editMode==="rotate"){const n=[0,45,90].map(s=>e.Math.toRadians(s));return["xy","yz","xz"].flatMap(s=>n.map(o=>this.getRotationPlanePoint(s,i.rotationRadius,o)))}return this.editMode==="scale"?[new e.Cartesian3(i.scaleOffset,0,0),new e.Cartesian3(0,i.scaleOffset,0),new e.Cartesian3(0,0,i.scaleOffset),new e.Cartesian3(0,0,0)]:[new e.Cartesian3(i.axisLength+i.arrowLength,0,0),new e.Cartesian3(0,i.axisLength+i.arrowLength,0),new e.Cartesian3(0,0,i.axisLength+i.arrowLength),new e.Cartesian3(i.planeEnd,i.planeEnd,0),new e.Cartesian3(0,i.planeEnd,i.planeEnd),new e.Cartesian3(i.planeEnd,0,i.planeEnd)]}getGizmoScreenBounds(t){const e=this.Cesium,i=this.getGizmoModelMatrix(t),n=e.Matrix4.getTranslation(i,new e.Cartesian3),s=this.toWindowCoordinates(n);if(!s)return null;const o=this.getGizmoLocalBounds(t).map(r=>this.toWindowCoordinates(e.Matrix4.multiplyByPoint(i,r,new e.Cartesian3))).filter(Boolean);return o.length?o.reduce((r,a)=>({minX:Math.min(r.minX,a.x),maxX:Math.max(r.maxX,a.x),minY:Math.min(r.minY,a.y),maxY:Math.max(r.maxY,a.y),center:n}),{minX:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY,center:n}):{minX:s.x,maxX:s.x,minY:s.y,maxY:s.y,center:n}}writeDragEndPayload(t,e,i){let n=this.dragEndCallbackMap.get(t);n||(n=new Map,this.dragEndCallbackMap.set(t,n)),n.set(e,i)}applyTransformAroundCenter(t,e,i){const n=this.Cesium,s=n.Matrix4.fromTranslation(n.Cartesian3.negate(e,new n.Cartesian3)),o=n.Matrix4.fromTranslation(e),r=n.Matrix4.multiply(o,n.Matrix4.multiply(i,s,new n.Matrix4),new n.Matrix4);return n.Matrix4.multiply(r,t,new n.Matrix4)}createMoveAxis(t){const e=this.Cesium,i=this.viewer;this.moveAxis&&i.scene.primitives.remove(this.moveAxis);const n=this.getGizmoMetrics(t),s=[{axis:"X",start:new e.Cartesian3(n.centerRadius,0,0),end:new e.Cartesian3(n.axisLength,0,0),color:e.Color.RED.withAlpha(.98)},{axis:"Y",start:new e.Cartesian3(0,n.centerRadius,0),end:new e.Cartesian3(0,n.axisLength,0),color:e.Color.LIME.withAlpha(.98)},{axis:"Z",start:new e.Cartesian3(0,0,n.centerRadius),end:new e.Cartesian3(0,0,n.axisLength),color:e.Color.DODGERBLUE.withAlpha(.98)}].flatMap(o=>{const r=[],a=this.createSegmentInstance(`moveAxis_${t.id}_${o.axis}_line`,o.start,o.end,n.axisThickness,o.color);a&&r.push(a);const l=e.BoxGeometry.createGeometry(new e.BoxGeometry({maximum:new e.Cartesian3(n.scaleHandleRadius,n.scaleHandleRadius,n.scaleHandleRadius),minimum:new e.Cartesian3(-n.scaleHandleRadius,-n.scaleHandleRadius,-n.scaleHandleRadius)})),d=o.axis==="X"?[n.axisLength,0,0]:o.axis==="Y"?[0,n.axisLength,0]:[0,0,n.axisLength];return this.translate(l,d),r.push(new e.GeometryInstance({id:`moveAxis_${t.id}_${o.axis}_handle`,geometry:l,attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(o.color)}})),r});s.push(this.createCenterInstance(`moveCenter_${t.id}`,n.centerRadius,e.Color.WHITE)),this.moveAxis=new e.Primitive({geometryInstances:s,appearance:this.getGizmoAppearance(),modelMatrix:this.getGizmoModelMatrix(t),cull:!1,asynchronous:!1}),i.scene.primitives.add(this.moveAxis)}createRotationRing(t){const e=this.Cesium,i=this.viewer;this.rotationRing&&i.scene.primitives.remove(this.rotationRing);const n=this.getGizmoMetrics(t),s=10,o=4,r=Math.max(n.rotationRadius-n.rotationThickness*5,1),l=(n.rotationRadius+n.rotationThickness*5-r)/o,d=[{axis:"X",plane:"yz",color:e.Color.RED.withAlpha(.92)},{axis:"Y",plane:"xz",color:e.Color.LIME.withAlpha(.9)},{axis:"Z",plane:"xy",color:e.Color.YELLOW.withAlpha(.92)}].flatMap(u=>{const p=[];for(let g=0;g<90;g+=s){const m=e.Math.toRadians(g),f=e.Math.toRadians(g+s),w=this.getRotationPlanePoint(u.plane,n.rotationRadius,m),y=this.getRotationPlanePoint(u.plane,n.rotationRadius,f),v=this.createSegmentInstance(`rotationArc_${t.id}_${u.axis}_${g}`,w,y,n.rotationThickness,u.color);v&&p.push(v);for(let C=0;C<o;C+=1){const b=r+l*(C+.5),P=this.getRotationPlanePoint(u.plane,b,m),E=this.getRotationPlanePoint(u.plane,b,f),L=this.createSegmentInstance(`rotationSector_${t.id}_${u.axis}_${C}_${g}`,P,E,Math.max(l*.92,n.rotationThickness*1.4),u.color.withAlpha(.04));L&&p.push(L)}}return p});this.rotationRing=new e.Primitive({geometryInstances:d,appearance:this.getGizmoAppearance(),modelMatrix:this.getGizmoModelMatrix(t),cull:!1,asynchronous:!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 n=this.getGizmoMetrics(t),o=[{axis:"XY",color:e.Color.DODGERBLUE.withAlpha(.28),minimum:new e.Cartesian3(n.planeStart,n.planeStart,-n.planeThickness),maximum:new e.Cartesian3(n.planeEnd,n.planeEnd,n.planeThickness)},{axis:"YZ",color:e.Color.RED.withAlpha(.24),minimum:new e.Cartesian3(-n.planeThickness,n.planeStart,n.planeStart),maximum:new e.Cartesian3(n.planeThickness,n.planeEnd,n.planeEnd)},{axis:"ZX",color:e.Color.LIME.withAlpha(.24),minimum:new e.Cartesian3(n.planeStart,-n.planeThickness,n.planeStart),maximum:new e.Cartesian3(n.planeEnd,n.planeThickness,n.planeEnd)}].map(r=>new e.GeometryInstance({id:`translationPlane_${t.id}_${r.axis}`,geometry:new e.BoxGeometry({minimum:r.minimum,maximum:r.maximum}),attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(r.color)}}));this.translationSquare=new e.Primitive({geometryInstances:o,appearance:this.getGizmoAppearance(),cull:!1,modelMatrix:this.getGizmoModelMatrix(t),asynchronous:!1}),i.scene.primitives.add(this.translationSquare)}createHeightArrow(t){const e=this.Cesium,i=this.viewer,n=Math.max(this.getPrimitiveEffectiveRadius(t),8);this.heightArrow&&i.scene.primitives.remove(this.heightArrow);let s=e.Color.GREEN,o=Math.max(n*.03,1.5),r=2*o,a=Math.max(n*1.6,36),l=a*.1;const d=Math.max(n*.2,2),u=e.CylinderGeometry.createGeometry(new e.CylinderGeometry({length:a,topRadius:o,bottomRadius:o})),p=e.CylinderGeometry.createGeometry(new e.CylinderGeometry({length:l,topRadius:0,bottomRadius:r}));let g=a+d,m=(a+d)/2;this.translate(u,[0,0,m]),this.translate(p,[0,0,g]),this.heightArrow=new e.Primitive({modelMatrix:t.modelMatrix,geometryInstances:[new e.GeometryInstance({id:`heightArrow-line_${t.id}`,geometry:u,attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(s.withAlpha(.9))}}),new e.GeometryInstance({id:`heightArrow-arrow_${t.id}`,geometry:p,attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(s.withAlpha(.9))}})],appearance:new e.PerInstanceColorAppearance({translucent:!0,closed:!0}),cull:!1,asynchronous:!1}),i.scene.primitives.add(this.heightArrow)}createScaleHandle(t){const e=this.Cesium,i=this.viewer;this.scaleHandle&&i.scene.primitives.remove(this.scaleHandle),this.scaleCenterProxy&&i.scene.primitives.remove(this.scaleCenterProxy);const n=this.getGizmoMetrics(t),s=[{axis:"X",color:e.Color.RED.withAlpha(.96),end:new e.Cartesian3(n.scaleOffset,0,0)},{axis:"Y",color:e.Color.LIME.withAlpha(.96),end:new e.Cartesian3(0,n.scaleOffset,0)},{axis:"Z",color:e.Color.DODGERBLUE.withAlpha(.96),end:new e.Cartesian3(0,0,n.scaleOffset)}].flatMap(o=>{const r=[],a=this.createSegmentInstance(`scaleAxis_${t.id}_${o.axis}`,new e.Cartesian3(0,0,0),o.end,n.axisThickness,o.color);a&&r.push(a);const l=e.BoxGeometry.createGeometry(new e.BoxGeometry({maximum:new e.Cartesian3(n.scaleHandleRadius,n.scaleHandleRadius,n.scaleHandleRadius),minimum:new e.Cartesian3(-n.scaleHandleRadius,-n.scaleHandleRadius,-n.scaleHandleRadius)}));return this.translate(l,o.end),r.push(new e.GeometryInstance({id:`scaleHandle_${t.id}_${o.axis}`,geometry:l,attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(o.color)}})),r});s.push(this.createCenterInstance(`scaleCenter_${t.id}`,n.centerRadius*1.35,e.Color.WHITE)),this.scaleHandle=new e.Primitive({geometryInstances:s,appearance:this.getGizmoAppearance(),cull:!1,asynchronous:!1,modelMatrix:this.getGizmoModelMatrix(t)}),i.scene.primitives.add(this.scaleHandle),this.scaleCenterProxy=new e.Primitive({geometryInstances:[this.createCenterBoxInstance(`scaleCenterHit_${t.id}`,n.centerRadius*3.1,e.Color.WHITE.withAlpha(.02))],appearance:this.getGizmoAppearance(),cull:!1,asynchronous:!1,modelMatrix:this.getGizmoModelMatrix(t)}),i.scene.primitives.add(this.scaleCenterProxy)}translate(t,e){let i=this.Cesium;const n=new i.Cartesian3;Me(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.rotationRing=null),this.moveAxis&&(this.viewer.scene.primitives.remove(this.moveAxis),this.moveAxis=null),this.translationSquare&&(this.viewer.scene.primitives.remove(this.translationSquare),this.translationSquare=null),this.heightArrow&&(this.viewer.scene.primitives.remove(this.heightArrow),this.heightArrow=null),this.scaleHandle&&(this.viewer.scene.primitives.remove(this.scaleHandle),this.scaleHandle=null),this.scaleCenterProxy&&(this.viewer.scene.primitives.remove(this.scaleCenterProxy),this.scaleCenterProxy=null)}updatedTool(t){const e=this.extractModelBaseMatrix(t);this.rotationRing&&(this.rotationRing.modelMatrix=e),this.moveAxis&&(this.moveAxis.modelMatrix=e),this.translationSquare&&(this.translationSquare.modelMatrix=e),this.heightArrow&&(this.heightArrow.modelMatrix=e),this.scaleHandle&&(this.scaleHandle.modelMatrix=e),this.scaleCenterProxy&&(this.scaleCenterProxy.modelMatrix=e)}moveModel(t,e,i,n,s,o){const r=this.Cesium,a=r.Cartesian3.subtract(o,s,new r.Cartesian3),l=r.Transforms.eastNorthUpToFixedFrame(n);let d=a;if(!["XY","YZ","ZX"].includes(i)){const f=this.getAxisVector(l,i),w=r.Cartesian3.dot(a,f);d=r.Cartesian3.multiplyByScalar(f,w,new r.Cartesian3)}const u=r.Matrix4.multiply(r.Matrix4.fromTranslation(d),e,new r.Matrix4);t.modelMatrix=u,this.updatedTool(u);const p=r.Matrix4.getTranslation(u,new r.Cartesian3),g=r.Cartesian3.magnitude(d),m=["XY","YZ","ZX"].includes(i)?i:`${i}轴`;this.showFeedback(`${m} ${g.toFixed(2)} m`,p),this.writeDragEndPayload(t.id,"translation",{id:t.id,position:p})}moveModelHeight(t,e,i,n,s,o){const r=this.Cesium,a=this.projectVerticalPoint(i.endPosition,n,s);if(a&&o){const l=r.Cartographic.fromCartesian(a),d=new r.Cartographic(o.longitude,o.latitude,(l==null?void 0:l.height)||o.height||0),u=r.Cartographic.toCartesian(d),p=r.Matrix4.getRotation(e,new r.Matrix3),g=r.Matrix4.fromRotationTranslation(p,u);t.modelMatrix=g,this.updatedTool(g),this.showFeedback(`${(((l==null?void 0:l.height)||0)-(o.height||0)).toFixed(2)} m`,u);let m=new r.Cartesian3(g[12],g[13],g[14]),f=this.dragEndCallbackMap.get(t.id);f||(f=new Map,this.dragEndCallbackMap.set(t.id,f)),f.set("translation",{id:t.id,position:m})}}projectVerticalPoint(t,e,i){const n=this.Cesium,s=this.viewer;if(!t||!e||!i)return null;const o=s.camera.getPickRay(t);if(!o)return null;const r=o.origin,a=n.Cartesian3.normalize(o.direction,new n.Cartesian3),l=e,d=i,u=n.Cartesian3.subtract(r,l,new n.Cartesian3),p=n.Cartesian3.dot(a,a),g=-n.Cartesian3.dot(a,d),m=n.Cartesian3.dot(d,d),f=-n.Cartesian3.dot(a,u),w=n.Cartesian3.dot(d,u),y=p*m-g*g;if(Math.abs(y)<1e-6)return null;const v=(p*w-g*f)/y;return n.Cartesian3.add(l,n.Cartesian3.multiplyByScalar(d,v,new n.Cartesian3),new n.Cartesian3)}rotateModel(t,e,i,n,s,o){const r=this.Cesium;if(!s||!o||!n)return;const a=r.Cartesian3.subtract(o,n,new r.Cartesian3);if(r.Cartesian3.magnitudeSquared(a)<=1e-6)return;r.Cartesian3.normalize(a,a);const l=r.Transforms.eastNorthUpToFixedFrame(n),d=this.getAxisVector(l,i),u=r.Math.clamp(r.Cartesian3.dot(s,a),-1,1),p=Math.acos(u);if(!Number.isFinite(p)||p<=1e-6)return;const g=r.Cartesian3.cross(s,a,new r.Cartesian3),m=r.Cartesian3.dot(g,d)>=0?1:-1,f=p*m,w=r.Quaternion.fromAxisAngle(d,f),y=r.Matrix4.fromRotationTranslation(r.Matrix3.fromQuaternion(w)),v=this.applyTransformAroundCenter(e,n,y);t.modelMatrix=v,this.updatedTool(v);const C=r.Matrix4.getTranslation(v,new r.Cartesian3);this.showFeedback(`${i}轴 ${r.Math.toDegrees(f).toFixed(1)}°`,C);const b=this.getModelHeadingPitchRoll(this.extractModelBaseMatrix(v));this.writeDragEndPayload(t.id,"rotate",{id:t.id,headingPitchRoll:{heading:Number(r.Math.toDegrees(b.heading).toFixed(3)),pitch:Number(r.Math.toDegrees(b.pitch).toFixed(3)),roll:Number(r.Math.toDegrees(b.roll).toFixed(3))}})}moveModelScale(t,e,i,n,s,o,r,a,l){const d=this.Cesium;if(!r)return;const u=this.getGizmoMetrics(t),p=d.Transforms.eastNorthUpToFixedFrame(n),g=Math.max(u.scaleOffset*.7,8);let m=0;if(i==="CENTER"){if(!s||!a)return;const b=Number(s.y||0)-Number(a.y||0);m=Math.pow(2,b/180)-1}else{if(!o||!l)return;const b=d.Cartesian3.subtract(l,o,new d.Cartesian3),P=this.getAxisVector(p,i);m=d.Cartesian3.dot(b,P)/g}const f=Math.max(.05,1+m),w={x:r.x,y:r.y,z:r.z};if(i==="CENTER")w.x=Math.max(.05,r.x*f),w.y=Math.max(.05,r.y*f),w.z=Math.max(.05,r.z*f);else{const b=Math.max(.05,Number((r[i.toLowerCase()]*f).toFixed(4)));w[i.toLowerCase()]=b}const y=this.extractModelBaseMatrix(e);this.applyScaleToPrimitive(t,w,y),this.activeModelId===t.id?this.refreshActiveToolGeometry():this.updatedTool(t.modelMatrix);const v=d.Matrix4.getTranslation(t.modelMatrix,new d.Cartesian3),C=i==="CENTER"?`${Math.max(w.x,w.y,w.z).toFixed(2)}x`:`${i}轴 ${w[i.toLowerCase()].toFixed(2)}x`;this.debugLog("moveModelScale",{id:t==null?void 0:t.id,axis:i,startScale:{x:Number((r==null?void 0:r.x)||1),y:Number((r==null?void 0:r.y)||1),z:Number((r==null?void 0:r.z)||1)},nextScale:w,deltaFactor:m,factor:f,runtimeRadius:this.getPrimitiveRuntimeRadius(t)}),this.showFeedback(C,v),this.writeDragEndPayload(t.id,"addScale",{id:t.id,scale:w})}cleanup(){var t,e;this.deactivateEdit(),this.hideModeHint(),(t=this.tooltipManager)==null||t.destroy(),this.tooltipManager=null,this.overlayUpdateFn&&(this.viewer.scene.postRender.removeEventListener(this.overlayUpdateFn),this.overlayUpdateFn=null),(e=this.overlayContainer)==null||e.remove(),this.overlayContainer=null,this.modeToolbarEl=null,this.feedbackLabelEl=null,this.handler&&(this.handler.destroy(),this.handler=null)}}function Eo(h,t){const e=t.materialType||"DynamicImgMaterial"+Date.now()+Math.floor(Math.random()*1e3);function i(s){this._definitionChanged=new h.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:h.createPropertyDescriptor("color")}),i.prototype.getType=function(){return e},i.prototype.getValue=function(s,o){return h.defined(o)||(o={}),o.color=h.Property.getValueOrClonedDefault(this._color,s,h.Color.WHITE,o.color),o.image=t.image,o},i.prototype.equals=function(s){return this===s||s instanceof i&&h.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,7 +8,7 @@
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:n({count:t.count,freely:t.freely||"",direction:t.direction,duration:t.duration||100,isCustomColor:t.isCustomColor})},translucent(){return!0}}),new i(t)}function Mo(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)
11
+ }`};return h.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 Mo(h,t){const e=t.MaterialType||"wallType"+new Date().getTime()+parseInt(Math.random()*1e3+"");function i(s){this._definitionChanged=new h.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:h.createPropertyDescriptor("color")}),i.prototype.getType=function(){return e},i.prototype.getValue=function(s,o){return h.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&&h.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;
@@ -24,7 +24,7 @@
24
24
 
25
25
  return material;
26
26
  }
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 Io(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,h={};let c=t.materialType||"PolylineFlow"+Date.now()+Math.floor(Math.random()*1e3);function d(u){u=r(u,h),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;
27
+ `,o};return h.Material._materialCache.addMaterial(e,{fabric:{type:e,uniforms:{color:t.color||new h.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 xo(h,t){const e=h.Color,i=Object.defineProperties,n=h.Event,s=h.createPropertyDescriptor,o=h.Property,r=(u,p)=>u===void 0?p:u,a={};let l=t.materialType||"PolylineFlow"+Date.now()+Math.floor(Math.random()*1e3);function d(u){u=r(u,a),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 l},d.prototype.getValue=function(u,p){return p||(p={}),p.color=o.getValueOrClonedDefault(this._color,u,h.Color.WHITE,p.color),p.duration=this._duration,p},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")}),h.PolylineFlowMaterialProperty=d,h.Material._materialCache.addMaterial(l,{fabric:{type:l,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 To{constructor(){l(this,"categoryMap",new Map);l(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 s;if(e=e||"default",this.CategoryGet[e])return this.CategoryGet[e]({themeKey:t,materialMap:this.categoryMap,options:i||{}});const n=(s=this.categoryMap.get(e))==null?void 0:s.get(t);return typeof n=="function"&&n.__materialFactory===!0?n(i||{}):n}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 _o{constructor(t){l(this,"id");l(this,"entities",[]);l(this,"primitives",[]);l(this,"dataItem",{});l(this,"aggregator");l(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 xo{constructor(t,e,i,n,s,o){l(this,"id");l(this,"groupMap",new Map);l(this,"Cesium");l(this,"viewer");l(this,"materialManager");l(this,"aggregator");l(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:(h,c)=>{this.cardPool.showByIds([h.data.id])}}),new e.ScreenSpaceEventHandler(i.scene.canvas).setInputAction(()=>{this.cardPool.hideFilter(h=>!h.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){if(!t.positions||t.positions.length<1)return null;const i=this.materialManager.get({themeKey:t.theme,category:"wall",options:t}),n=(v,C=0)=>{const b=Number(v);return Number.isFinite(b)?b:C},s=t.positions.map(v=>n(v==null?void 0:v[2],0)),o=n(t.minHeight,0),r=n(t.maxHeight,0),h=v=>Array.isArray(v)&&v.length===t.positions.length&&v.every(C=>Math.abs(n(C,0))<1e-6),c=s.some(v=>Math.abs(v)>1e-6),m=(Array.isArray(t.minimumHeights)&&t.minimumHeights.length===t.positions.length&&!(h(t.minimumHeights)&&c)?t.minimumHeights.map(v=>n(v,0)):s).map(v=>v-o),f=(Array.isArray(t.maximumHeights)&&t.maximumHeights.length===t.positions.length&&!(h(t.maximumHeights)&&c)?t.maximumHeights.map(v=>n(v,0)):s).map(v=>v+r),w=t.positions.map(v=>this.Cesium.Cartesian3.fromDegrees(v[0],v[1],v[2]||0));let y={...t};return i&&(y.material=i),this.viewer.entities.add({wall:{...y,positions:w,minimumHeights:m,maximumHeights:f},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 h={...t};return i&&(h.material=i),this.viewer.entities.add({polygon:{...h,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(h=>{const c=this.createPolyline(h,s);c&&n.push(c)}),(t.wall||[]).forEach(h=>{const c=this.createWall(h,s);c&&n.push(c)}),(t.polygon||[]).forEach(h=>{const c=this.createPolygon(h,s);c&&n.push(c)});const o=this.createBillboardPoints(t);o.length&&e&&this.aggregator.appendPoints(o,!1),this.createCard(t);const r=new _o({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 Do{constructor(t,e,i,n,s){l(this,"Cesium");l(this,"viewer");l(this,"layerMap",new Map);l(this,"materialManager");l(this,"aggregator");l(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 xo(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 So(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 Ao{constructor(t){l(this,"Cesium");l(this,"viewer");l(this,"layerMap");l(this,"hideLayerMap");l(this,"entityLayerManager");l(this,"PrimitiveThemeMap");l(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=Fe(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,h,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=(h=t.properties)==null?void 0:h.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 h of t){const c=Math.floor(Math.abs(h)/n),d=h>=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 h=0;h<16;h++)r=r<<1|s[h];return{dashPattern:r,dashLength:e}}async processBatch(t){const e=new Map;t.forEach(i=>{let{layerId:n,dataList:s}=i;Fe(s).forEach(r=>{let h=this.createGeometryInstance(r);if(h){let c=this.carateThemePrimitive(r);c.ids.set(r.id,r),c.geometryInstances.set(r.id,h);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 h=Array.isArray(r[0])?r.flat():r,c=this.Cesium.Cartesian3.fromDegreesArrayHeights(h.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=Fe(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 h=o.get(r);if(!h){console.warn(`没有找到图元 ${r} 在图层 ${n} 中`);return}let c=this.PrimitiveThemeMap.get(h.theme);c&&(c.geometryInstances.delete(h.id),c.ids.delete(h.id),e.add(h))})}),Array.from(e.values()).forEach(i=>{this.updatePrimitive(i)})}addGeometryInstance(t){let e=Fe(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 h=this.getGeometryInstanceInfo(n,r);h&&e.set(h.theme,h)})}),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 h=this.getGeometryInstanceInfo(n,r);h&&e.set(h.theme,h)})}),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,h=r._positions||r._polygonHierarchy.positions;if(h&&h.length>0){let c=h[0].x,d=h[0].y,u=h[0].z,m=h[0].x,g=h[0].y,p=h[0].z;h.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} 的顶点信息`)}}const Re=class Re{constructor(t,e){l(this,"Cesium");l(this,"viewer");l(this,"handler",null);l(this,"positions",[]);l(this,"tempPoints",[]);l(this,"segmentEntities",[]);l(this,"segmentLabelIds",[]);l(this,"previewEntity",null);l(this,"previewGroundEntity",null);l(this,"hoverPos",null);l(this,"htmlLabelPool",null);l(this,"totalLabelId",null);l(this,"previewLabelId",null);l(this,"labelEntity",null);l(this,"firstHeight",null);l(this,"groundLineEntities",[]);l(this,"previewPos",null);l(this,"previewGroundPos",null);l(this,"tooltip",null);l(this,"moveFrameId",null);l(this,"pendingMove",null);l(this,"lastMoveKey",null);l(this,"keydownHandler",null);l(this,"contextMenuHandler",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.tooltip=new ce,this.tooltip.show(Re.TIP_TEXT),this._bindGlobalEvents(t,e,i),this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var p,f,w,y;const s=i.scene.pickPosition(n.position);if(!s)return;const o=e.Cartographic.fromCartesian(s),r=e.Math.toDegrees(o.longitude),h=e.Math.toDegrees(o.latitude);this.positions.length===0&&(this.firstHeight=o.height||0);const c=e.Cartesian3.fromDegrees(r,h,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=s,m=((f=(p=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:f.call(p,.9))||e.Color.RED,g=i.entities.add({polyline:{positions:[u,c],width:t.width||3,material:new e.PolylineDashMaterialProperty({color:m,dashLength:12,dashPattern:255})}});if(this.groundLineEntities.push(g),this.positions.length>=2){const v=this.positions[this.positions.length-2],C=this.positions[this.positions.length-1],b=e.Cartographic.fromCartesian(v),M=e.Cartographic.fromCartesian(C),P=i.entities.add({polyline:{positions:[v,C],width:t.width||3,material:t.lineColor||t.color||e.Color.YELLOW,depthFailMaterial:new e.PolylineDashMaterialProperty({color:((y=(w=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:y.call(w,.9))||e.Color.RED,dashLength:12,dashPattern:255})}});this.segmentEntities.push(P);const E=new e.EllipsoidGeodesic(b,M).surfaceDistance,I=new e.Cartesian3((v.x+C.x)/2,(v.y+C.y)/2,(v.z+C.z)/2),D=e.Cartographic.fromCartesian(I),x=`measure_horizontal_seg_${this.segmentLabelIds.length}_${Date.now()}`;this.segmentLabelIds.push(x),this.htmlLabelPool.add({text:`${E.toFixed(2)} m`},{id:x,lon:e.Math.toDegrees(D.longitude),lat:e.Math.toDegrees(D.latitude),height:D.height||this.firstHeight||0,theme:"measure-horizontal-seg",show:!0})}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(()=>{this._finishMeasurement(t,e)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK),this.handler.setInputAction(()=>{this._undoLastPoint()},e.ScreenSpaceEventType.RIGHT_CLICK),this.handler.setInputAction(n=>{var s,o;this.pendingMove={endPosition:{x:(s=n.endPosition)==null?void 0:s.x,y:(o=n.endPosition)==null?void 0:o.y}},this.moveFrameId==null&&(this.moveFrameId=window.requestAnimationFrame(()=>{this.moveFrameId=null;const r=this.pendingMove;if(this.pendingMove=null,!(r!=null&&r.endPosition))return;const h=`${r.endPosition.x}_${r.endPosition.y}`;h!==this.lastMoveKey&&(this.lastMoveKey=h,this._handlePreviewMove(r,t,e,i))}))},e.ScreenSpaceEventType.MOUSE_MOVE)}_handlePreviewMove(t,e,i,n){var C,b,M,P;if(this.positions.length===0)return;const s=n.scene.pickPosition(t.endPosition);if(!s)return;this.hoverPos=s;const o=i.Cartographic.fromCartesian(s),r=i.Math.toDegrees(o.longitude),h=i.Math.toDegrees(o.latitude),c=i.Cartesian3.fromDegrees(r,h,this.firstHeight||0);this.previewPos=c,this.previewGroundPos=s;const d=this.positions[this.positions.length-1],u=i.Cartographic.fromCartesian(d),m=i.Cartographic.fromCartesian(c),p=new i.EllipsoidGeodesic(u,m).surfaceDistance,f=new i.Cartesian3((d.x+c.x)/2,(d.y+c.y)/2,(d.z+c.z)/2),w=i.Cartographic.fromCartesian(f),y=this.previewLabelId||"measure_horizontal_preview";this.previewLabelId=y,this.htmlLabelPool.add({text:`${p.toFixed(2)} m`},{id:y,lon:i.Math.toDegrees(w.longitude),lat:i.Math.toDegrees(w.latitude),height:w.height||this.firstHeight||0,theme:"measure-horizontal-seg",show:!0});const v=((b=(C=e.dashLineColor||e.lineColor||e.color||i.Color.RED).withAlpha)==null?void 0:b.call(C,.9))||i.Color.RED;this.previewGroundEntity||(this.previewGroundEntity=n.entities.add({polyline:{positions:new i.CallbackProperty(()=>!this.previewPos||!this.previewGroundPos?[]:[this.previewGroundPos,this.previewPos],!1),width:e.width||3,material:new i.PolylineDashMaterialProperty({color:v,dashLength:12,dashPattern:255})}})),this.previewEntity||(this.previewEntity=n.entities.add({polyline:{positions:new i.CallbackProperty(()=>!this.previewPos||!this.positions.length?[]:[this.positions[this.positions.length-1],this.previewPos],!1),width:e.width||3,material:e.lineColor||e.color||i.Color.YELLOW,depthFailMaterial:new i.PolylineDashMaterialProperty({color:((P=(M=e.dashLineColor||e.lineColor||e.color||i.Color.RED).withAlpha)==null?void 0:P.call(M,.9))||i.Color.RED,dashLength:12,dashPattern:255})}}))}_clearPreviewState(){this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewGroundEntity&&(this.viewer.entities.remove(this.previewGroundEntity),this.previewGroundEntity=null),this.previewPos=null,this.previewGroundPos=null,this.hoverPos=null}_undoLastPoint(){if(!this.positions.length)return;this.positions.pop();const t=this.tempPoints.pop();t&&this.viewer.entities.remove(t);const e=this.groundLineEntities.pop();if(e&&this.viewer.entities.remove(e),this.segmentEntities.length>this.positions.length-1){const i=this.segmentEntities.pop();i&&this.viewer.entities.remove(i)}if(this.segmentLabelIds.length>this.positions.length-1&&this.htmlLabelPool){const i=this.segmentLabelIds.pop();i&&this.htmlLabelPool.removeByIds([i])}if(!this.positions.length){this.firstHeight=null,this._clearPreviewState();return}this.totalLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.totalLabelId]),this.totalLabelId=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null)}_finishMeasurement(t,e){var h;if(this.positions.length<2){this.clear();return}this.stop(),this._clearPreviewState();let i=0;for(let c=1;c<this.positions.length;c++){const d=this.positions[c-1],u=this.positions[c],m=e.Cartographic.fromCartesian(d),g=e.Cartographic.fromCartesian(u),p=new e.EllipsoidGeodesic(m,g);i+=p.surfaceDistance}const n=this.positions[this.positions.length-1],s=e.Cartographic.fromCartesian(n),o=this.totalLabelId||`measure_horizontal_total_${Date.now()}`;this.totalLabelId=o,this.htmlLabelPool.add({text:`${i.toFixed(2)} m`},{id:o,lon:e.Math.toDegrees(s.longitude),lat:e.Math.toDegrees(s.latitude),height:s.height||this.firstHeight||0,theme:"measure-horizontal-total",show:!0}),this.labelEntity=this.totalLabelId;const r={entity:this.segmentEntities,label:this.labelEntity,segmentLabels:this.segmentLabelIds,positions:this.positions,distance:i,clear:()=>this.clear()};(h=t.onComplete)==null||h.call(t,r)}_bindGlobalEvents(t,e,i){this.keydownHandler=n=>{n.key==="Escape"&&(n.preventDefault(),this._finishMeasurement(t,e))},window.addEventListener("keydown",this.keydownHandler),this.contextMenuHandler=n=>{n.preventDefault()},i.canvas.addEventListener("contextmenu",this.contextMenuHandler)}stop(){this.moveFrameId!=null&&(cancelAnimationFrame(this.moveFrameId),this.moveFrameId=null),this.pendingMove=null,this.lastMoveKey=null,this.keydownHandler&&(window.removeEventListener("keydown",this.keydownHandler),this.keydownHandler=null),this.contextMenuHandler&&(this.viewer.canvas.removeEventListener("contextmenu",this.contextMenuHandler),this.contextMenuHandler=null),this.handler&&(this.handler.destroy(),this.handler=null),this.tooltip&&(this.tooltip.destroy(),this.tooltip=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,h=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:h,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:h,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),D=t.id+`_seg_${w-1}`;this.segmentLabelIds.push(D),this.htmlLabelPool.add({text:`${L.toFixed(2)} m`},{id:D,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"}})}};l(Re,"TIP_TEXT","单击左键添加点,右键撤销,双击左键或Esc结束");let _e=Re;class Xe{constructor(t,e){l(this,"Cesium");l(this,"viewer");l(this,"handler",null);l(this,"entity",null);l(this,"labelEntity",null);l(this,"positions",[]);l(this,"htmlLabelPool",null);l(this,"htmlLabelId",null);l(this,"previewLabelId",null);l(this,"baseCarto",null);l(this,"baseUp",null);l(this,"tempPoints",[]);l(this,"previewPointEntity",null);l(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,h,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=((h=(r=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:h.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,D=e.Cartesian3.add(w,e.Cartesian3.multiplyByScalar(y,I,new e.Cartesian3),new e.Cartesian3);this.positions[1]=D,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,D],width:t.width||3,material:x,depthFailMaterial:new e.PolylineDashMaterialProperty({color:T,dashLength:12,dashPattern:255})}});const $=i.entities.add({position:D,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push($);const S=this.baseCarto,O=e.Cartographic.fromCartesian(D),_=Math.abs((O.height||0)-(S.height||0)),k=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),F=e.Cartographic.fromCartesian(k);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(F.longitude),lat:e.Math.toDegrees(F.latitude),height:F.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 D,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,h=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(h,h),g=-e.Cartesian3.dot(h,d),p=e.Cartesian3.dot(d,d),f=-e.Cartesian3.dot(h,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=(D=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:x.call(D,.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,h=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:h,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 Je{constructor(t,e){l(this,"Cesium");l(this,"viewer");l(this,"handler",null);l(this,"positions",[]);l(this,"htmlLabelPool",null);l(this,"htmlLabelId",null);l(this,"segmentEntities",[]);l(this,"angleMarkerEntities",[]);l(this,"pointEntities",[]);l(this,"segmentLabelIds",[]);l(this,"angleLabelIds",[]);l(this,"previewLabelId",null);l(this,"previewSegmentEntities",[]);l(this,"previewAngleMarkerEntities",[]);l(this,"previewPointEntity",null);l(this,"previewLow",null);l(this,"previewHigh",null);l(this,"previewThird",null);l(this,"previewMarkerP1",null);l(this,"previewMarkerP2",null);l(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,h,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=((h=(r=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:h.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),D=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),S=e.Cartographic.fromCartesian(x),O=e.Cartographic.fromCartesian(T),_=e.Cartographic.fromCartesian($),k="measure_triangle_seg_v",F="measure_triangle_seg_h",G="measure_triangle_seg_hyp";this.segmentLabelIds=[k,F,G],this.htmlLabelPool.add({text:`${E.toFixed(2)} m`},{id:k,lon:e.Math.toDegrees(S.longitude),lat:e.Math.toDegrees(S.latitude),height:S.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${I.toFixed(2)} m`},{id:F,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:`${D.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),Z=e.Cartesian3.subtract(p,f,new e.Cartesian3),ae=e.Cartesian3.dot(B,j),ve=Math.sqrt(e.Cartesian3.dot(B,B))*Math.sqrt(e.Cartesian3.dot(j,j)),Ce=e.Cartesian3.dot(X,Z),Se=Math.sqrt(e.Cartesian3.dot(X,X))*Math.sqrt(e.Cartesian3.dot(Z,Z)),Y=Math.acos(Math.min(Math.max(ae/(ve||1),-1),1)),me=Math.acos(Math.min(Math.max(Ce/(Se||1),-1),1)),ne=e.Cartographic.fromCartesian(p),W=e.Cartographic.fromCartesian(f),Q="measure_triangle_angle_a",le="measure_triangle_angle_b";this.angleLabelIds=[Q,le],this.htmlLabelPool.add({text:`${(Y*180/Math.PI).toFixed(2)}°`},{id:Q,lon:e.Math.toDegrees(ne.longitude),lat:e.Math.toDegrees(ne.latitude),height:ne.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${(me*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 be=Math.max(.01,Math.min(.5,t.angleMarkerRatio??.2)),U=Math.min(E,I)*be;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),H=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})}}),Ge=i.entities.add({polyline:{positions:[H,q],width:t.width||3,material:C,depthFailMaterial:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}});this.angleMarkerEntities.push(ie,Ge)}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:D},angles:{acuteA:Y,acuteB:me},clear:()=>this.clear()};(c=t.onComplete)==null||c.call(t,K)}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(n=>{var me,ne;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),h=o.height||0,c=r.height||0,d=h<=c?this.positions[0]:s,u=h>c?this.positions[0]:s,m=e.Cartographic.fromCartesian(d),g=Math.max(h,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=((ne=(me=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:ne.call(me,.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})}}),Q=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,Q,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)),D=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(D/(x||1),-1),1)),S=new e.Cartesian3((d.x+p.x)/2,(d.y+p.y)/2,(d.z+p.z)/2),O=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),k=e.Cartographic.fromCartesian(S),F=e.Cartographic.fromCartesian(O),G=e.Cartographic.fromCartesian(_),B=e.Cartographic.fromCartesian(d),j=e.Cartographic.fromCartesian(u),X="measure_triangle_seg_v",Z="measure_triangle_seg_h",ae="measure_triangle_seg_hyp",ve="measure_triangle_angle_a",Ce="measure_triangle_angle_b";this.segmentLabelIds.length===0&&(this.segmentLabelIds=[X,Z,ae]),this.angleLabelIds.length===0&&(this.angleLabelIds=[ve,Ce]),this.htmlLabelPool.add({text:`${y.toFixed(2)} m`},{id:X,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:`${v.toFixed(2)} m`},{id:Z,lon:e.Math.toDegrees(F.longitude),lat:e.Math.toDegrees(F.latitude),height:F.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:ve,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:Ce,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 Se=Math.max(.01,Math.min(.5,t.angleMarkerRatio??.2)),Y=Math.min(y,v)*Se;if(y>.001&&v>.001){const W=e.Cartesian3.normalize(e.Cartesian3.subtract(d,p,new e.Cartesian3),new e.Cartesian3),Q=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),be=new e.Cartesian3(p.x+Q.x*Y,p.y+Q.y*Y,p.z+Q.z*Y),U=new e.Cartesian3(p.x+W.x*Y+Q.x*Y,p.y+W.y*Y+Q.y*Y,p.z+W.z*Y+Q.z*Y);if(this.previewMarkerP1=le,this.previewMarkerP2=be,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,h=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:(H,q)=>{var ie;H.innerHTML=String(((ie=q==null?void 0:q.data)==null?void 0:ie.text)||""),H.style.background="rgba(0,0,0,0.6)",H.style.color="#fff",H.style.font="14px sans-serif",H.style.padding="4px 6px",H.style.borderRadius="4px",H.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-triangle-seg",{createElement:(H,q)=>{var ie;H.innerHTML=String(((ie=q==null?void 0:q.data)==null?void 0:ie.text)||""),H.style.background="rgba(0,0,0,0.6)",H.style.color="#fff",H.style.font="14px sans-serif",H.style.padding="4px 6px",H.style.borderRadius="4px",H.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-triangle-angle",{createElement:(H,q)=>{var ie;H.innerHTML=String(((ie=q==null?void 0:q.data)==null?void 0:ie.text)||""),H.style.background="rgba(0,0,0,0.6)",H.style.color="#fff",H.style.font="14px sans-serif",H.style.padding="4px 6px",H.style.borderRadius="4px",H.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:h,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}}),P=n.entities.add({polyline:{positions:[b,f],width:h,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}}),L=n.entities.add({polyline:{positions:[p,f],width:h,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),D=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),S=i.Cartographic.fromCartesian(x),O=i.Cartographic.fromCartesian(T),_=i.Cartographic.fromCartesian($),k=t.id+"_tri_v",F=t.id+"_tri_h",G=t.id+"_tri_hyp";this.segmentLabelIds=[k,F,G],this.htmlLabelPool.add({text:`${E.toFixed(2)} m`},{id:k,lon:i.Math.toDegrees(S.longitude),lat:i.Math.toDegrees(S.latitude),height:S.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${I.toFixed(2)} m`},{id:F,lon:i.Math.toDegrees(O.longitude),lat:i.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:`${D.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),Z=i.Cartesian3.subtract(p,f,new i.Cartesian3),ae=i.Cartesian3.dot(B,j),ve=Math.sqrt(i.Cartesian3.dot(B,B))*Math.sqrt(i.Cartesian3.dot(j,j)),Ce=i.Cartesian3.dot(X,Z),Se=Math.sqrt(i.Cartesian3.dot(X,X))*Math.sqrt(i.Cartesian3.dot(Z,Z)),Y=Math.acos(Math.min(Math.max(ae/(ve||1),-1),1)),me=Math.acos(Math.min(Math.max(Ce/(Se||1),-1),1)),ne=i.Cartographic.fromCartesian(p),W=i.Cartographic.fromCartesian(f),Q=s.labelText||{angle:"角度"},le=t.id+"_tri_angA",be=t.id+"_tri_angB";this.angleLabelIds=[le,be],this.htmlLabelPool.add({text:`${Q.angle}:${(Y*180/Math.PI).toFixed(2)}°`},{id:le,lon:i.Math.toDegrees(ne.longitude),lat:i.Math.toDegrees(ne.latitude),height:ne.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${Q.angle}:${(me*180/Math.PI).toFixed(2)}°`},{id:be,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),H=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+H.x*K,b.y+H.y*K,b.z+H.z*K),Ge=new i.Cartesian3(b.x+ee.x*K+H.x*K,b.y+ee.y*K+H.y*K,b.z+ee.z*K+H.z*K),Ho=n.entities.add({polyline:{positions:[q,Ge],width:h,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}}),Fo=n.entities.add({polyline:{positions:[ie,Ge],width:h,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}});this.angleMarkerEntities.push(Ho,Fo)}}}class Ze{constructor(t,e){l(this,"Cesium");l(this,"viewer");l(this,"handler",null);l(this,"entity",null);l(this,"labelEntity",null);l(this,"positions",[]);l(this,"tempPoints",[]);l(this,"htmlLabelPool",null);l(this,"htmlLabelId",null);l(this,"previewEntity",null);l(this,"previewPos",null);l(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,h,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=((h=(r=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:h.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),h=new e.Cartesian3((o.x+s.x)/2,(o.y+s.y)/2,(o.z+s.z)/2),c=e.Cartographic.fromCartesian(h),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,h=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:h,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"}})}}}}const ze=class ze{constructor(t,e){l(this,"Cesium");l(this,"viewer");l(this,"handler",null);l(this,"entity",null);l(this,"labelEntity",null);l(this,"positions",[]);l(this,"tempPoints",[]);l(this,"primitive",null);l(this,"previewEntity",null);l(this,"previewPos",null);l(this,"edgeEntities",[]);l(this,"pointEntities",[]);l(this,"previewEdgeEntity",null);l(this,"previewPointEntities",[]);l(this,"htmlLabelPool",null);l(this,"htmlLabelId",null);l(this,"previewLabelId",null);l(this,"segmentLabelIds",[]);l(this,"angleLabelIds",[]);l(this,"tooltip",null);l(this,"keydownHandler",null);l(this,"contextMenuHandler",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-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.tooltip=new ce,this.tooltip.show(ze.TIP_TEXT),this._bindGlobalEvents(t,e,i),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()),h=new e.PolygonGeometry({polygonHierarchy:r,vertexFormat:e.MaterialAppearance.VERTEX_FORMAT,perPositionHeight:!0,arcType:e.ArcType.NONE}),c=new e.GeometryInstance({geometry:h}),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(()=>{this._finishMeasurement(t,e,!0)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK),this.handler.setInputAction(()=>{this._undoLastPoint(t,e,i)},e.ScreenSpaceEventType.RIGHT_CLICK)}stop(){this.keydownHandler&&(window.removeEventListener("keydown",this.keydownHandler),this.keydownHandler=null),this.contextMenuHandler&&(this.viewer.canvas.removeEventListener("contextmenu",this.contextMenuHandler),this.contextMenuHandler=null),this.handler&&(this.handler.destroy(),this.handler=null),this.tooltip&&(this.tooltip.destroy(),this.tooltip=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=[]}_clearPreviewState(){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 t of this.previewPointEntities)try{this.viewer.entities.remove(t)}catch{}this.previewPointEntities=[]}this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.previewPos=null}_rebuildShape(t,e,i){var c,d;if(this.primitive&&(i.scene.primitives.remove(this.primitive),this.primitive=null),this.edgeEntities.length){for(const u of this.edgeEntities)try{i.entities.remove(u)}catch{}this.edgeEntities=[]}if(!this.positions.length)return;const n=new e.PolygonHierarchy(this.positions.slice()),s=new e.PolygonGeometry({polygonHierarchy:n,vertexFormat:e.MaterialAppearance.VERTEX_FORMAT,perPositionHeight:!0,arcType:e.ArcType.NONE}),o=new e.GeometryInstance({geometry:s}),r=t.color||e.Color.YELLOW.withAlpha(.4),h=t.color&&t.color.withAlpha?t.color.withAlpha(.25):e.Color.RED.withAlpha(.4);if(this.primitive=new e.Primitive({geometryInstances:o,appearance:new e.MaterialAppearance({material:e.Material.fromType("Color",{color:r}),translucent:!0,closed:!0}),depthFailAppearance:new e.MaterialAppearance({material:e.Material.fromType("Color",{color:h}),translucent:!0,closed:!0})}),i.scene.primitives.add(this.primitive),this.positions.length>=2){const u=t.lineColor||t.color||e.Color.YELLOW,m=((d=(c=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:d.call(c,.9))||e.Color.RED,g=this.positions.concat([this.positions[0]]),p=i.entities.add({polyline:{positions:g,width:t.width||2,material:u,clampToGround:!1,arcType:e.ArcType.NONE,depthFailMaterial:new e.PolylineDashMaterialProperty({color:m,dashLength:12,dashPattern:255})}});this.edgeEntities.push(p)}}_undoLastPoint(t,e,i){if(!this.positions.length)return;this.positions.pop();const n=this.tempPoints.pop();n&&i.entities.remove(n),this._clearPreviewState(),this._rebuildShape(t,e,i)}_finishMeasurement(t,e,i){var g;if(i&&this.positions.length>=3){this.positions.pop();const p=this.tempPoints.pop();p&&this.viewer.entities.remove(p)}if(this.positions.length<3){this.clear();return}this._clearPreviewState(),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 h=e.Cartographic.fromCartesian(n),c=this.htmlLabelId||`measure_area_${Date.now()}`;this.htmlLabelId=c;const d=t.labelText||{area:"面积",side:"边长",angle:"角度"};this.htmlLabelPool.add({text:`${d.area}:${r.toFixed(2)} m²`},{id:c,lon:e.Math.toDegrees(h.longitude),lat:e.Math.toDegrees(h.latitude),height:h.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),D=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(D.longitude),lat:e.Math.toDegrees(D.latitude),height:D.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)}_bindGlobalEvents(t,e,i){this.keydownHandler=n=>{n.key==="Escape"&&(n.preventDefault(),this._finishMeasurement(t,e,!1))},window.addEventListener("keydown",this.keydownHandler),this.contextMenuHandler=n=>{n.preventDefault()},i.canvas.addEventListener("contextmenu",this.contextMenuHandler)}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),D=i.Cartographic.fromCartesian(E),T=new i.EllipsoidGeodesic(I,D).surfaceDistance,$=new i.Cartesian3((L.x+E.x)/2,(L.y+E.y)/2,(L.z+E.z)/2),S=i.Cartographic.fromCartesian($),O=t.id+`_area_seg_${M}`;this.segmentLabelIds.push(O),this.htmlLabelPool.add({text:`${g.side}:${T.toFixed(2)} m`},{id:O,lon:i.Math.toDegrees(S.longitude),lat:i.Math.toDegrees(S.latitude),height:S.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,D=P.y-L.y,x=E.x-L.x,T=E.y-L.y,$=Math.sqrt(I*I+D*D),S=Math.sqrt(x*x+T*T);if(!$||!S)continue;const O=I/$*(x/S)+D/$*(T/S),_=Math.acos(Math.min(1,Math.max(-1,O)))*(180/Math.PI),k=i.Cartographic.fromCartesian(o[M]),F=t.id+`_area_angle_${M}`;this.angleLabelIds.push(F),this.htmlLabelPool.add({text:`${g.angle}:${_.toFixed(2)} °`},{id:F,lon:i.Math.toDegrees(k.longitude),lat:i.Math.toDegrees(k.latitude),height:k.height||0,theme:"measure-area-angle",show:!0})}}};l(ze,"TIP_TEXT","单击左键添加点,右键撤销,双击左键或Esc结束");let xe=ze;class Qe{constructor(t,e){l(this,"Cesium");l(this,"viewer");l(this,"handler",null);l(this,"entity",null);l(this,"positions",[]);l(this,"currentRadius",0);l(this,"labelEntity",null);l(this,"previewLabel",null);l(this,"ellipsePrimitive",null);l(this,"previewEntity",null);l(this,"isPrimitive",!1);l(this,"htmlLabelPool",null);l(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 h;const r=((h=o==null?void 0:o.data)==null?void 0:h.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],h=this.positions[1],c=e.Cartesian3.distance(r,h),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
- ${m.area}:${d.toFixed(2)} m²
45
- ${m.circumference}:${u.toFixed(2)} m`):this.labelEntity=i.entities.add({position:g,label:{text:`${m.radius}:${c.toFixed(2)} m
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(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
- ${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()};(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 h=e.Cartesian3.distance(s,r);this.currentRadius=h;const c=e.Cartographic.fromCartesian(s),d=Math.PI*h*h,u=2*Math.PI*h,m=t.labelText||{radius:"半径",area:"面积",circumference:"周长"},g=s;this.labelEntity?(this.labelEntity.position=g,this.labelEntity.label.text=`${m.radius}:${h.toFixed(2)} m
50
- ${m.area}:${d.toFixed(2)} m²
51
- ${m.circumference}:${u.toFixed(2)} m`):this.labelEntity=i.entities.add({position:g,label:{text:`${m.radius}:${h.toFixed(2)} m
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),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}:${h.toFixed(2)} m
54
- ${m.area}:${d.toFixed(2)} m²
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 D;const I=((D=E==null?void 0:E.data)==null?void 0:D.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],h=o[1],c=i.Cartesian3.distance(r,h),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
43
+ }`})()},translucent(){return!0}}),new d(t)}class Io{constructor(){c(this,"categoryMap",new Map);c(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 s;if(e=e||"default",this.CategoryGet[e])return this.CategoryGet[e]({themeKey:t,materialMap:this.categoryMap,options:i||{}});const n=(s=this.categoryMap.get(e))==null?void 0:s.get(t);return typeof n=="function"&&n.__materialFactory===!0?n(i||{}):n}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 To{constructor(t){c(this,"id");c(this,"entities",[]);c(this,"primitives",[]);c(this,"dataItem",{});c(this,"aggregator");c(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 _o{constructor(t,e,i,n,s,o){c(this,"id");c(this,"groupMap",new Map);c(this,"Cesium");c(this,"viewer");c(this,"materialManager");c(this,"aggregator");c(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:(a,l)=>{this.cardPool.showByIds([a.data.id])}}),new e.ScreenSpaceEventHandler(i.scene.canvas).setInputAction(()=>{this.cardPool.hideFilter(a=>!a.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){if(!t.positions||t.positions.length<1)return null;const i=this.materialManager.get({themeKey:t.theme,category:"wall",options:t}),n=(v,C=0)=>{const b=Number(v);return Number.isFinite(b)?b:C},s=t.positions.map(v=>n(v==null?void 0:v[2],0)),o=n(t.minHeight,0),r=n(t.maxHeight,0),a=v=>Array.isArray(v)&&v.length===t.positions.length&&v.every(C=>Math.abs(n(C,0))<1e-6),l=s.some(v=>Math.abs(v)>1e-6),p=(Array.isArray(t.minimumHeights)&&t.minimumHeights.length===t.positions.length&&!(a(t.minimumHeights)&&l)?t.minimumHeights.map(v=>n(v,0)):s).map(v=>v-o),f=(Array.isArray(t.maximumHeights)&&t.maximumHeights.length===t.positions.length&&!(a(t.maximumHeights)&&l)?t.maximumHeights.map(v=>n(v,0)):s).map(v=>v+r),w=t.positions.map(v=>this.Cesium.Cartesian3.fromDegrees(v[0],v[1],v[2]||0));let y={...t};return i&&(y.material=i),this.viewer.entities.add({wall:{...y,positions:w,minimumHeights:p,maximumHeights:f},show:(t.show??!0)&&e})}createPolygon(t,e){var l;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=((l=t.holes)==null?void 0:l.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 a={...t};return i&&(a.material=i),this.viewer.entities.add({polygon:{...a,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(a=>{const l=this.createPolyline(a,s);l&&n.push(l)}),(t.wall||[]).forEach(a=>{const l=this.createWall(a,s);l&&n.push(l)}),(t.polygon||[]).forEach(a=>{const l=this.createPolygon(a,s);l&&n.push(l)});const o=this.createBillboardPoints(t);o.length&&e&&this.aggregator.appendPoints(o,!1),this.createCard(t);const r=new To({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 Do{constructor(t,e,i,n,s){c(this,"Cesium");c(this,"viewer");c(this,"layerMap",new Map);c(this,"materialManager");c(this,"aggregator");c(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 _o(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 So(h){const t=[];return h.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 Ao{constructor(t){c(this,"Cesium");c(this,"viewer");c(this,"layerMap");c(this,"hideLayerMap");c(this,"entityLayerManager");c(this,"PrimitiveThemeMap");c(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=He(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,a,l,d,u,p,g,m,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=((l=(a=t.properties)==null?void 0:a.lineType)==null?void 0:l.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_${(p=t.properties)==null?void 0:p.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_${(m=t.properties)==null?void 0:m.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 a of t){const l=Math.floor(Math.abs(a)/n),d=a>=0?1:0;for(let u=0;u<l&&(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 a=0;a<16;a++)r=r<<1|s[a];return{dashPattern:r,dashLength:e}}async processBatch(t){const e=new Map;t.forEach(i=>{let{layerId:n,dataList:s}=i;He(s).forEach(r=>{let a=this.createGeometryInstance(r);if(a){let l=this.carateThemePrimitive(r);l.ids.set(r.id,r),l.geometryInstances.set(r.id,a);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 a=Array.isArray(r[0])?r.flat():r,l=this.Cesium.Cartesian3.fromDegreesArrayHeights(a.flat());return new this.Cesium.PolygonHierarchy(l)}))||[],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=He(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 a=o.get(r);if(!a){console.warn(`没有找到图元 ${r} 在图层 ${n} 中`);return}let l=this.PrimitiveThemeMap.get(a.theme);l&&(l.geometryInstances.delete(a.id),l.ids.delete(a.id),e.add(a))})}),Array.from(e.values()).forEach(i=>{this.updatePrimitive(i)})}addGeometryInstance(t){let e=He(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 a=this.getGeometryInstanceInfo(n,r);a&&e.set(a.theme,a)})}),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 a=this.getGeometryInstanceInfo(n,r);a&&e.set(a.theme,a)})}),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,a=r._positions||r._polygonHierarchy.positions;if(a&&a.length>0){let l=a[0].x,d=a[0].y,u=a[0].z,p=a[0].x,g=a[0].y,m=a[0].z;a.forEach(C=>{l=Math.min(l,C.x),d=Math.min(d,C.y),u=Math.min(u,C.z),p=Math.max(p,C.x),g=Math.max(g,C.y),m=Math.max(m,C.z)});const f=new this.Cesium.Cartesian3((l+p)/2,(d+g)/2,(u+m)/2),y=new this.Cesium.Cartesian3(p-l,g-d,m-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} 的顶点信息`)}}const Fe=class Fe{constructor(t,e){c(this,"Cesium");c(this,"viewer");c(this,"handler",null);c(this,"positions",[]);c(this,"tempPoints",[]);c(this,"segmentEntities",[]);c(this,"segmentLabelIds",[]);c(this,"previewEntity",null);c(this,"previewGroundEntity",null);c(this,"hoverPos",null);c(this,"htmlLabelPool",null);c(this,"totalLabelId",null);c(this,"previewLabelId",null);c(this,"labelEntity",null);c(this,"firstHeight",null);c(this,"groundLineEntities",[]);c(this,"previewPos",null);c(this,"previewGroundPos",null);c(this,"tooltip",null);c(this,"moveFrameId",null);c(this,"pendingMove",null);c(this,"lastMoveKey",null);c(this,"keydownHandler",null);c(this,"contextMenuHandler",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.tooltip=new ce,this.tooltip.show(Fe.TIP_TEXT),this._bindGlobalEvents(t,e,i),this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var m,f,w,y;const s=i.scene.pickPosition(n.position);if(!s)return;const o=e.Cartographic.fromCartesian(s),r=e.Math.toDegrees(o.longitude),a=e.Math.toDegrees(o.latitude);this.positions.length===0&&(this.firstHeight=o.height||0);const l=e.Cartesian3.fromDegrees(r,a,this.firstHeight||0);this.positions.push(l);const d=i.entities.add({position:l,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(d);const u=s,p=((f=(m=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:f.call(m,.9))||e.Color.RED,g=i.entities.add({polyline:{positions:[u,l],width:t.width||3,material:new e.PolylineDashMaterialProperty({color:p,dashLength:12,dashPattern:255})}});if(this.groundLineEntities.push(g),this.positions.length>=2){const v=this.positions[this.positions.length-2],C=this.positions[this.positions.length-1],b=e.Cartographic.fromCartesian(v),P=e.Cartographic.fromCartesian(C),E=i.entities.add({polyline:{positions:[v,C],width:t.width||3,material:t.lineColor||t.color||e.Color.YELLOW,depthFailMaterial:new e.PolylineDashMaterialProperty({color:((y=(w=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:y.call(w,.9))||e.Color.RED,dashLength:12,dashPattern:255})}});this.segmentEntities.push(E);const M=new e.EllipsoidGeodesic(b,P).surfaceDistance,x=new e.Cartesian3((v.x+C.x)/2,(v.y+C.y)/2,(v.z+C.z)/2),_=e.Cartographic.fromCartesian(x),D=`measure_horizontal_seg_${this.segmentLabelIds.length}_${Date.now()}`;this.segmentLabelIds.push(D),this.htmlLabelPool.add({text:`${M.toFixed(2)} m`},{id:D,lon:e.Math.toDegrees(_.longitude),lat:e.Math.toDegrees(_.latitude),height:_.height||this.firstHeight||0,theme:"measure-horizontal-seg",show:!0})}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(()=>{this._finishMeasurement(t,e)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK),this.handler.setInputAction(()=>{this._undoLastPoint()},e.ScreenSpaceEventType.RIGHT_CLICK),this.handler.setInputAction(n=>{var s,o;this.pendingMove={endPosition:{x:(s=n.endPosition)==null?void 0:s.x,y:(o=n.endPosition)==null?void 0:o.y}},this.moveFrameId==null&&(this.moveFrameId=window.requestAnimationFrame(()=>{this.moveFrameId=null;const r=this.pendingMove;if(this.pendingMove=null,!(r!=null&&r.endPosition))return;const a=`${r.endPosition.x}_${r.endPosition.y}`;a!==this.lastMoveKey&&(this.lastMoveKey=a,this._handlePreviewMove(r,t,e,i))}))},e.ScreenSpaceEventType.MOUSE_MOVE)}_handlePreviewMove(t,e,i,n){var C,b,P,E;if(this.positions.length===0)return;const s=n.scene.pickPosition(t.endPosition);if(!s)return;this.hoverPos=s;const o=i.Cartographic.fromCartesian(s),r=i.Math.toDegrees(o.longitude),a=i.Math.toDegrees(o.latitude),l=i.Cartesian3.fromDegrees(r,a,this.firstHeight||0);this.previewPos=l,this.previewGroundPos=s;const d=this.positions[this.positions.length-1],u=i.Cartographic.fromCartesian(d),p=i.Cartographic.fromCartesian(l),m=new i.EllipsoidGeodesic(u,p).surfaceDistance,f=new i.Cartesian3((d.x+l.x)/2,(d.y+l.y)/2,(d.z+l.z)/2),w=i.Cartographic.fromCartesian(f),y=this.previewLabelId||"measure_horizontal_preview";this.previewLabelId=y,this.htmlLabelPool.add({text:`${m.toFixed(2)} m`},{id:y,lon:i.Math.toDegrees(w.longitude),lat:i.Math.toDegrees(w.latitude),height:w.height||this.firstHeight||0,theme:"measure-horizontal-seg",show:!0});const v=((b=(C=e.dashLineColor||e.lineColor||e.color||i.Color.RED).withAlpha)==null?void 0:b.call(C,.9))||i.Color.RED;this.previewGroundEntity||(this.previewGroundEntity=n.entities.add({polyline:{positions:new i.CallbackProperty(()=>!this.previewPos||!this.previewGroundPos?[]:[this.previewGroundPos,this.previewPos],!1),width:e.width||3,material:new i.PolylineDashMaterialProperty({color:v,dashLength:12,dashPattern:255})}})),this.previewEntity||(this.previewEntity=n.entities.add({polyline:{positions:new i.CallbackProperty(()=>!this.previewPos||!this.positions.length?[]:[this.positions[this.positions.length-1],this.previewPos],!1),width:e.width||3,material:e.lineColor||e.color||i.Color.YELLOW,depthFailMaterial:new i.PolylineDashMaterialProperty({color:((E=(P=e.dashLineColor||e.lineColor||e.color||i.Color.RED).withAlpha)==null?void 0:E.call(P,.9))||i.Color.RED,dashLength:12,dashPattern:255})}}))}_clearPreviewState(){this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewGroundEntity&&(this.viewer.entities.remove(this.previewGroundEntity),this.previewGroundEntity=null),this.previewPos=null,this.previewGroundPos=null,this.hoverPos=null}_undoLastPoint(){if(!this.positions.length)return;this.positions.pop();const t=this.tempPoints.pop();t&&this.viewer.entities.remove(t);const e=this.groundLineEntities.pop();if(e&&this.viewer.entities.remove(e),this.segmentEntities.length>this.positions.length-1){const i=this.segmentEntities.pop();i&&this.viewer.entities.remove(i)}if(this.segmentLabelIds.length>this.positions.length-1&&this.htmlLabelPool){const i=this.segmentLabelIds.pop();i&&this.htmlLabelPool.removeByIds([i])}if(!this.positions.length){this.firstHeight=null,this._clearPreviewState();return}this.totalLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.totalLabelId]),this.totalLabelId=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null)}_finishMeasurement(t,e){var a;if(this.positions.length<2){this.clear();return}this.stop(),this._clearPreviewState();let i=0;for(let l=1;l<this.positions.length;l++){const d=this.positions[l-1],u=this.positions[l],p=e.Cartographic.fromCartesian(d),g=e.Cartographic.fromCartesian(u),m=new e.EllipsoidGeodesic(p,g);i+=m.surfaceDistance}const n=this.positions[this.positions.length-1],s=e.Cartographic.fromCartesian(n),o=this.totalLabelId||`measure_horizontal_total_${Date.now()}`;this.totalLabelId=o,this.htmlLabelPool.add({text:`${i.toFixed(2)} m`},{id:o,lon:e.Math.toDegrees(s.longitude),lat:e.Math.toDegrees(s.latitude),height:s.height||this.firstHeight||0,theme:"measure-horizontal-total",show:!0}),this.labelEntity=this.totalLabelId;const r={entity:this.segmentEntities,label:this.labelEntity,segmentLabels:this.segmentLabelIds,positions:this.positions,distance:i,clear:()=>this.clear()};(a=t.onComplete)==null||a.call(t,r)}_bindGlobalEvents(t,e,i){this.keydownHandler=n=>{n.key==="Escape"&&(n.preventDefault(),this._finishMeasurement(t,e))},window.addEventListener("keydown",this.keydownHandler),this.contextMenuHandler=n=>{n.preventDefault()},i.canvas.addEventListener("contextmenu",this.contextMenuHandler)}stop(){this.moveFrameId!=null&&(cancelAnimationFrame(this.moveFrameId),this.moveFrameId=null),this.pendingMove=null,this.lastMoveKey=null,this.keydownHandler&&(window.removeEventListener("keydown",this.keydownHandler),this.keydownHandler=null),this.contextMenuHandler&&(this.viewer.canvas.removeEventListener("contextmenu",this.contextMenuHandler),this.contextMenuHandler=null),this.handler&&(this.handler.destroy(),this.handler=null),this.tooltip&&(this.tooltip.destroy(),this.tooltip=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 m,f;const i=this.Cesium,n=this.viewer,s=t.options||{},o=s.lineColor||s.color||i.Color.YELLOW,r=((f=(m=s.dashLineColor||s.lineColor||s.color||i.Color.RED).withAlpha)==null?void 0:f.call(m,.9))||i.Color.RED,a=s.width||3,l=(t.positions||[]).map(w=>new i.Cartesian3(w[0],w[1],w[2]));if(!l.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 l){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),P=n.scene.globe.getHeight(new i.Cartographic(v.longitude,v.latitude,0))||0,E=i.Cartesian3.fromDegrees(C,b,P),L=n.entities.add({polyline:{positions:[E,w],width:a,material:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}});this.groundLineEntities.push(L)}for(let w=1;w<l.length;w++){const y=l[w-1],v=l[w],C=n.entities.add({polyline:{positions:[y,v],width:a,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}});this.segmentEntities.push(C);const b=i.Cartographic.fromCartesian(y),P=i.Cartographic.fromCartesian(v),L=new i.EllipsoidGeodesic(b,P).surfaceDistance,M=new i.Cartesian3((y.x+v.x)/2,(y.y+v.y)/2,(y.z+v.z)/2),x=i.Cartographic.fromCartesian(M),_=t.id+`_seg_${w-1}`;this.segmentLabelIds.push(_),this.htmlLabelPool.add({text:`${L.toFixed(2)} m`},{id:_,lon:i.Math.toDegrees(x.longitude),lat:i.Math.toDegrees(x.latitude),height:x.height||0,theme:"measure-horizontal-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})}let d=0;for(let w=1;w<l.length;w++){const y=i.Cartographic.fromCartesian(l[w-1]),v=i.Cartographic.fromCartesian(l[w]),C=new i.EllipsoidGeodesic(y,v);d+=C.surfaceDistance}const u=l[l.length-1],p=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(p.longitude),lat:i.Math.toDegrees(p.latitude),height:p.height||0,theme:"measure-horizontal-total",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})}};c(Fe,"TIP_TEXT","单击左键添加点,右键撤销,双击左键或Esc结束");let _e=Fe;class qe{constructor(t,e){c(this,"Cesium");c(this,"viewer");c(this,"handler",null);c(this,"entity",null);c(this,"labelEntity",null);c(this,"positions",[]);c(this,"htmlLabelPool",null);c(this,"htmlLabelId",null);c(this,"previewLabelId",null);c(this,"baseCarto",null);c(this,"baseUp",null);c(this,"tempPoints",[]);c(this,"previewPointEntity",null);c(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,a,l,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 p=e.Cartographic.fromCartesian(o);this.baseCarto=new e.Cartographic(p.longitude,p.latitude,0);const g=e.Ellipsoid.WGS84.cartographicToCartesian(this.baseCarto);this.baseUp=e.Ellipsoid.WGS84.geodeticSurfaceNormalCartographic(this.baseCarto),this.positions.push(g);const m=i.entities.add({position:g,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(m);const f=t.lineColor||t.color||e.Color.CYAN,w=((a=(r=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:a.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 p=this.positions[0],g=i.camera.getPickRay(n.position);if(!g)return;const m=g.origin,f=e.Cartesian3.normalize(g.direction,new e.Cartesian3),w=p,y=this.baseUp,v=e.Cartesian3.subtract(m,w,new e.Cartesian3),C=e.Cartesian3.dot(f,f),b=-e.Cartesian3.dot(f,y),P=e.Cartesian3.dot(y,y),E=-e.Cartesian3.dot(f,v),L=e.Cartesian3.dot(y,v),M=C*P-b*b;if(Math.abs(M)<1e-6)return;const x=(C*L-b*E)/M,_=e.Cartesian3.add(w,e.Cartesian3.multiplyByScalar(y,x,new e.Cartesian3),new e.Cartesian3);this.positions[1]=_,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 D=t.lineColor||t.color||e.Color.CYAN,I=((d=(l=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:d.call(l,.9))||e.Color.RED;this.entity=i.entities.add({polyline:{positions:[p,_],width:t.width||3,material:D,depthFailMaterial:new e.PolylineDashMaterialProperty({color:I,dashLength:12,dashPattern:255})}});const k=i.entities.add({position:_,point:{pixelSize:8,color:t.pointColor||t.color||e.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(k);const S=this.baseCarto,R=e.Cartographic.fromCartesian(_),T=Math.abs((R.height||0)-(S.height||0)),$=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),H=e.Cartographic.fromCartesian($);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:`${T.toFixed(2)} m`},{id:G,lon:e.Math.toDegrees(H.longitude),lat:e.Math.toDegrees(H.latitude),height:H.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:T,clear:()=>this.clear()};(u=t.onComplete)==null||u.call(t,B)}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(n=>{var _,D;if(this.positions.length<1)return;if(!this.baseCarto||!this.baseUp){const I=e.Cartographic.fromCartesian(this.positions[0]);this.baseCarto=new e.Cartographic(I.longitude,I.latitude,I.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,a=e.Cartesian3.normalize(o.direction,new e.Cartesian3),l=s,d=this.baseUp,u=e.Cartesian3.subtract(r,l,new e.Cartesian3),p=e.Cartesian3.dot(a,a),g=-e.Cartesian3.dot(a,d),m=e.Cartesian3.dot(d,d),f=-e.Cartesian3.dot(a,u),w=e.Cartesian3.dot(d,u),y=p*m-g*g;if(Math.abs(y)<1e-6)return;const v=(p*w-g*f)/y,C=e.Cartesian3.add(l,e.Cartesian3.multiplyByScalar(d,v,new e.Cartesian3),new e.Cartesian3);if(this.positions[1]=C,!this.previewEntity){const I=t.lineColor||t.color||e.Color.CYAN,k=((D=(_=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:D.call(_,.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:I,depthFailMaterial:new e.PolylineDashMaterialProperty({color:k,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,P=e.Cartographic.fromCartesian(C),E=Math.abs((P.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),M=e.Cartographic.fromCartesian(L),x=this.previewLabelId||"measure_vertical_preview";this.previewLabelId=x,this.htmlLabelPool.add({text:`${E.toFixed(2)} m`},{id:x,lon:e.Math.toDegrees(M.longitude),lat:e.Math.toDegrees(M.latitude),height:M.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,P;const i=this.Cesium,n=this.viewer,s=t.options||{},o=s.lineColor||s.color||i.Color.CYAN,r=((P=(b=s.dashLineColor||s.lineColor||s.color||i.Color.RED).withAlpha)==null?void 0:P.call(b,.9))||i.Color.RED,a=s.width||3,l=(t.positions||[]).map(E=>new i.Cartesian3(E[0],E[1],E[2]));if(l.length<2)return;if(!this.htmlLabelPool){const E=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,n,E),this.htmlLabelPool.registerTheme("measure-vertical",{createElement:(L,M)=>{var x;L.innerHTML=String(((x=M==null?void 0:M.data)==null?void 0:x.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=l[0],u=l[1],p=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(p),this.tempPoints.push(g),this.entity=n.entities.add({polyline:{positions:[d,u],width:a,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}});const m=i.Cartographic.fromCartesian(d),f=i.Cartographic.fromCartesian(u),w=Math.abs((f.height||0)-(m.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 Ze{constructor(t,e){c(this,"Cesium");c(this,"viewer");c(this,"handler",null);c(this,"positions",[]);c(this,"htmlLabelPool",null);c(this,"htmlLabelId",null);c(this,"segmentEntities",[]);c(this,"angleMarkerEntities",[]);c(this,"pointEntities",[]);c(this,"segmentLabelIds",[]);c(this,"angleLabelIds",[]);c(this,"previewLabelId",null);c(this,"previewSegmentEntities",[]);c(this,"previewAngleMarkerEntities",[]);c(this,"previewPointEntity",null);c(this,"previewLow",null);c(this,"previewHigh",null);c(this,"previewThird",null);c(this,"previewMarkerP1",null);c(this,"previewMarkerP2",null);c(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,a,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.pointEntities.push(o),this.positions.length===2){this.stop(),this.previewSegmentEntities.forEach(Z=>i.entities.remove(Z)),this.previewSegmentEntities=[],this.previewAngleMarkerEntities.forEach(Z=>i.entities.remove(Z)),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]),p=d.height||0,g=u.height||0,m=p<=g?this.positions[0]:this.positions[1],f=p>g?this.positions[0]:this.positions[1],w=e.Cartographic.fromCartesian(m);e.Cartographic.fromCartesian(f);const y=Math.max(p,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=((a=(r=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:a.call(r,.9))||e.Color.RED,P=i.entities.add({polyline:{positions:[m,v],width:t.width||3,material:C,depthFailMaterial:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}}),E=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:[m,f],width:t.width||3,material:C,depthFailMaterial:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}});this.segmentEntities.push(P,E,L);const M=e.Cartesian3.distance(m,v),x=e.Cartesian3.distance(v,f),_=e.Cartesian3.distance(m,f),D=new e.Cartesian3((m.x+v.x)/2,(m.y+v.y)/2,(m.z+v.z)/2),I=new e.Cartesian3((v.x+f.x)/2,(v.y+f.y)/2,(v.z+f.z)/2),k=new e.Cartesian3((m.x+f.x)/2,(m.y+f.y)/2,(m.z+f.z)/2),S=e.Cartographic.fromCartesian(D),R=e.Cartographic.fromCartesian(I),T=e.Cartographic.fromCartesian(k),$="measure_triangle_seg_v",H="measure_triangle_seg_h",G="measure_triangle_seg_hyp";this.segmentLabelIds=[$,H,G],this.htmlLabelPool.add({text:`${M.toFixed(2)} m`},{id:$,lon:e.Math.toDegrees(S.longitude),lat:e.Math.toDegrees(S.latitude),height:S.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${x.toFixed(2)} m`},{id:H,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:`${_.toFixed(2)} m`},{id:G,lon:e.Math.toDegrees(T.longitude),lat:e.Math.toDegrees(T.latitude),height:T.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const B=e.Cartesian3.subtract(f,m,new e.Cartesian3),Y=e.Cartesian3.subtract(v,m,new e.Cartesian3),q=e.Cartesian3.subtract(v,f,new e.Cartesian3),J=e.Cartesian3.subtract(m,f,new e.Cartesian3),ae=e.Cartesian3.dot(B,Y),ve=Math.sqrt(e.Cartesian3.dot(B,B))*Math.sqrt(e.Cartesian3.dot(Y,Y)),Ce=e.Cartesian3.dot(q,J),Ae=Math.sqrt(e.Cartesian3.dot(q,q))*Math.sqrt(e.Cartesian3.dot(J,J)),j=Math.acos(Math.min(Math.max(ae/(ve||1),-1),1)),me=Math.acos(Math.min(Math.max(Ce/(Ae||1),-1),1)),ne=e.Cartographic.fromCartesian(m),W=e.Cartographic.fromCartesian(f),Q="measure_triangle_angle_a",le="measure_triangle_angle_b";this.angleLabelIds=[Q,le],this.htmlLabelPool.add({text:`${(j*180/Math.PI).toFixed(2)}°`},{id:Q,lon:e.Math.toDegrees(ne.longitude),lat:e.Math.toDegrees(ne.latitude),height:ne.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${(me*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 be=Math.max(.01,Math.min(.5,t.angleMarkerRatio??.2)),U=Math.min(M,x)*be;if(M>.001&&x>.001){const Z=e.Cartesian3.normalize(e.Cartesian3.subtract(m,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+Z.x*U,v.y+Z.y*U,v.z+Z.z*U),O=new e.Cartesian3(v.x+he.x*U,v.y+he.y*U,v.z+he.z*U),X=new e.Cartesian3(v.x+Z.x*U+he.x*U,v.y+Z.y*U+he.y*U,v.z+Z.z*U+he.z*U),ie=i.entities.add({polyline:{positions:[ee,X],width:t.width||3,material:C,depthFailMaterial:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}}),Ge=i.entities.add({polyline:{positions:[O,X],width:t.width||3,material:C,depthFailMaterial:new e.PolylineDashMaterialProperty({color:b,dashLength:12,dashPattern:255})}});this.angleMarkerEntities.push(ie,Ge)}this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null);const K={entity:this.segmentEntities,positions:[m,f,v],lengths:{vertical:M,horizontal:x,hypotenuse:_},angles:{acuteA:j,acuteB:me},clear:()=>this.clear()};(l=t.onComplete)==null||l.call(t,K)}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(n=>{var me,ne;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),a=o.height||0,l=r.height||0,d=a<=l?this.positions[0]:s,u=a>l?this.positions[0]:s,p=e.Cartographic.fromCartesian(d),g=Math.max(a,l),m=e.Cartesian3.fromDegrees(this.Cesium.Math.toDegrees(p.longitude),this.Cesium.Math.toDegrees(p.latitude),g);this.previewLow=d,this.previewHigh=u,this.previewThird=m;const f=t.lineColor||t.color||e.Color.YELLOW,w=((ne=(me=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:ne.call(me,.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})}}),Q=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,Q,le)}const y=e.Cartesian3.distance(d,m),v=e.Cartesian3.distance(m,u),C=e.Cartesian3.distance(d,u),b=e.Cartesian3.subtract(u,d,new e.Cartesian3),P=e.Cartesian3.subtract(m,d,new e.Cartesian3),E=e.Cartesian3.subtract(m,u,new e.Cartesian3),L=e.Cartesian3.subtract(d,u,new e.Cartesian3),M=e.Cartesian3.dot(b,P),x=Math.sqrt(e.Cartesian3.dot(b,b))*Math.sqrt(e.Cartesian3.dot(P,P)),_=e.Cartesian3.dot(E,L),D=Math.sqrt(e.Cartesian3.dot(E,E))*Math.sqrt(e.Cartesian3.dot(L,L)),I=Math.acos(Math.min(Math.max(M/(x||1),-1),1)),k=Math.acos(Math.min(Math.max(_/(D||1),-1),1)),S=new e.Cartesian3((d.x+m.x)/2,(d.y+m.y)/2,(d.z+m.z)/2),R=new e.Cartesian3((m.x+u.x)/2,(m.y+u.y)/2,(m.z+u.z)/2),T=new e.Cartesian3((d.x+u.x)/2,(d.y+u.y)/2,(d.z+u.z)/2),$=e.Cartographic.fromCartesian(S),H=e.Cartographic.fromCartesian(R),G=e.Cartographic.fromCartesian(T),B=e.Cartographic.fromCartesian(d),Y=e.Cartographic.fromCartesian(u),q="measure_triangle_seg_v",J="measure_triangle_seg_h",ae="measure_triangle_seg_hyp",ve="measure_triangle_angle_a",Ce="measure_triangle_angle_b";this.segmentLabelIds.length===0&&(this.segmentLabelIds=[q,J,ae]),this.angleLabelIds.length===0&&(this.angleLabelIds=[ve,Ce]),this.htmlLabelPool.add({text:`${y.toFixed(2)} m`},{id:q,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:`${v.toFixed(2)} m`},{id:J,lon:e.Math.toDegrees(H.longitude),lat:e.Math.toDegrees(H.latitude),height:H.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:`${(I*180/Math.PI).toFixed(2)}°`},{id:ve,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:`${(k*180/Math.PI).toFixed(2)}°`},{id:Ce,lon:e.Math.toDegrees(Y.longitude),lat:e.Math.toDegrees(Y.latitude),height:Y.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const Ae=Math.max(.01,Math.min(.5,t.angleMarkerRatio??.2)),j=Math.min(y,v)*Ae;if(y>.001&&v>.001){const W=e.Cartesian3.normalize(e.Cartesian3.subtract(d,m,new e.Cartesian3),new e.Cartesian3),Q=e.Cartesian3.normalize(e.Cartesian3.subtract(u,m,new e.Cartesian3),new e.Cartesian3),le=new e.Cartesian3(m.x+W.x*j,m.y+W.y*j,m.z+W.z*j),be=new e.Cartesian3(m.x+Q.x*j,m.y+Q.y*j,m.z+Q.z*j),U=new e.Cartesian3(m.x+W.x*j+Q.x*j,m.y+W.y*j+Q.y*j,m.z+W.z*j+Q.z*j);if(this.previewMarkerP1=le,this.previewMarkerP2=be,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})}}),Z=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,Z)}}},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 Z,he;const i=this.Cesium,n=this.viewer,s=t.options||{},o=s.lineColor||s.color||i.Color.YELLOW,r=((he=(Z=s.dashLineColor||s.lineColor||s.color||i.Color.RED).withAlpha)==null?void 0:he.call(Z,.9))||i.Color.RED,a=s.width||3,l=(t.positions||[]).map(ee=>new i.Cartesian3(ee[0],ee[1],ee[2]));if(l.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:(O,X)=>{var ie;O.innerHTML=String(((ie=X==null?void 0:X.data)==null?void 0:ie.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-triangle-seg",{createElement:(O,X)=>{var ie;O.innerHTML=String(((ie=X==null?void 0:X.data)==null?void 0:ie.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-triangle-angle",{createElement:(O,X)=>{var ie;O.innerHTML=String(((ie=X==null?void 0:X.data)==null?void 0:ie.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}}})}const d=i.Cartographic.fromCartesian(l[0]),u=i.Cartographic.fromCartesian(l[1]),p=d.height||0,g=u.height||0,m=p<=g?l[0]:l[1],f=p>g?l[0]:l[1],w=n.entities.add({position:m,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(m),C=Math.max(p,g),b=i.Cartesian3.fromDegrees(i.Math.toDegrees(v.longitude),i.Math.toDegrees(v.latitude),C),P=n.entities.add({polyline:{positions:[m,b],width:a,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}}),E=n.entities.add({polyline:{positions:[b,f],width:a,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}}),L=n.entities.add({polyline:{positions:[m,f],width:a,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}});this.segmentEntities.push(P,E,L);const M=i.Cartesian3.distance(m,b),x=i.Cartesian3.distance(b,f),_=i.Cartesian3.distance(m,f),D=new i.Cartesian3((m.x+b.x)/2,(m.y+b.y)/2,(m.z+b.z)/2),I=new i.Cartesian3((b.x+f.x)/2,(b.y+f.y)/2,(b.z+f.z)/2),k=new i.Cartesian3((m.x+f.x)/2,(m.y+f.y)/2,(m.z+f.z)/2),S=i.Cartographic.fromCartesian(D),R=i.Cartographic.fromCartesian(I),T=i.Cartographic.fromCartesian(k),$=t.id+"_tri_v",H=t.id+"_tri_h",G=t.id+"_tri_hyp";this.segmentLabelIds=[$,H,G],this.htmlLabelPool.add({text:`${M.toFixed(2)} m`},{id:$,lon:i.Math.toDegrees(S.longitude),lat:i.Math.toDegrees(S.latitude),height:S.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${x.toFixed(2)} m`},{id:H,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:`${_.toFixed(2)} m`},{id:G,lon:i.Math.toDegrees(T.longitude),lat:i.Math.toDegrees(T.latitude),height:T.height||0,theme:"measure-triangle-seg",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const B=i.Cartesian3.subtract(f,m,new i.Cartesian3),Y=i.Cartesian3.subtract(b,m,new i.Cartesian3),q=i.Cartesian3.subtract(b,f,new i.Cartesian3),J=i.Cartesian3.subtract(m,f,new i.Cartesian3),ae=i.Cartesian3.dot(B,Y),ve=Math.sqrt(i.Cartesian3.dot(B,B))*Math.sqrt(i.Cartesian3.dot(Y,Y)),Ce=i.Cartesian3.dot(q,J),Ae=Math.sqrt(i.Cartesian3.dot(q,q))*Math.sqrt(i.Cartesian3.dot(J,J)),j=Math.acos(Math.min(Math.max(ae/(ve||1),-1),1)),me=Math.acos(Math.min(Math.max(Ce/(Ae||1),-1),1)),ne=i.Cartographic.fromCartesian(m),W=i.Cartographic.fromCartesian(f),Q=s.labelText||{angle:"角度"},le=t.id+"_tri_angA",be=t.id+"_tri_angB";this.angleLabelIds=[le,be],this.htmlLabelPool.add({text:`${Q.angle}:${(j*180/Math.PI).toFixed(2)}°`},{id:le,lon:i.Math.toDegrees(ne.longitude),lat:i.Math.toDegrees(ne.latitude),height:ne.height||0,theme:"measure-triangle-angle",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}}),this.htmlLabelPool.add({text:`${Q.angle}:${(me*180/Math.PI).toFixed(2)}°`},{id:be,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(M,x)*U;if(M>.001&&x>.001){const ee=i.Cartesian3.normalize(i.Cartesian3.subtract(m,b,new i.Cartesian3),new i.Cartesian3),O=i.Cartesian3.normalize(i.Cartesian3.subtract(f,b,new i.Cartesian3),new i.Cartesian3),X=new i.Cartesian3(b.x+ee.x*K,b.y+ee.y*K,b.z+ee.z*K),ie=new i.Cartesian3(b.x+O.x*K,b.y+O.y*K,b.z+O.z*K),Ge=new i.Cartesian3(b.x+ee.x*K+O.x*K,b.y+ee.y*K+O.y*K,b.z+ee.z*K+O.z*K),Oo=n.entities.add({polyline:{positions:[X,Ge],width:a,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}}),Ho=n.entities.add({polyline:{positions:[ie,Ge],width:a,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}});this.angleMarkerEntities.push(Oo,Ho)}}}class Je{constructor(t,e){c(this,"Cesium");c(this,"viewer");c(this,"handler",null);c(this,"entity",null);c(this,"labelEntity",null);c(this,"positions",[]);c(this,"tempPoints",[]);c(this,"htmlLabelPool",null);c(this,"htmlLabelId",null);c(this,"previewEntity",null);c(this,"previewPos",null);c(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,a,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.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],p=t.lineColor||t.color||e.Color.YELLOW,g=((a=(r=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:a.call(r,.9))||e.Color.RED;this.entity=i.entities.add({polyline:{positions:[d,u],width:t.width||3,material:p,depthFailMaterial:new e.PolylineDashMaterialProperty({color:g,dashLength:12,dashPattern:255})}});const m=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:`${m.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:m,clear:()=>this.clear()};(l=t.onComplete)==null||l.call(t,v)}},e.ScreenSpaceEventType.LEFT_CLICK),this.handler.setInputAction(n=>{var g,m;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),a=new e.Cartesian3((o.x+s.x)/2,(o.y+s.y)/2,(o.z+s.z)/2),l=e.Cartographic.fromCartesian(a),d=this.previewLabelId||"measure_space_preview";this.previewLabelId=d,this.htmlLabelPool.add({text:`${r.toFixed(2)} m`},{id:d,lon:e.Math.toDegrees(l.longitude),lat:e.Math.toDegrees(l.latitude),height:l.height||0,theme:"measure-space",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}});const u=t.lineColor||t.color||e.Color.YELLOW,p=((m=(g=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:m.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:p,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,a=s.width||3,l=(t.positions||[]).map(p=>new i.Cartesian3(p[0],p[1],p[2]));if(l.length){if(!this.htmlLabelPool){const p=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,n,p),this.htmlLabelPool.registerTheme("measure-space",{createElement:(g,m)=>{var f;g.innerHTML=String(((f=m==null?void 0:m.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(l.length>=1){const p=n.entities.add({position:l[0],point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(p)}if(l.length>=2){const p=n.entities.add({position:l[1],point:{pixelSize:8,color:s.pointColor||s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(p),this.entity=n.entities.add({polyline:{positions:[l[0],l[1]],width:a,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}});const g=i.Cartesian3.distance(l[0],l[1]),m=i.Cartographic.fromCartesian(l[1]),f=t.id+"_label";this.htmlLabelId=f,this.htmlLabelPool.add({text:`${g.toFixed(2)} m`},{id:f,lon:i.Math.toDegrees(m.longitude),lat:i.Math.toDegrees(m.latitude),height:m.height||0,theme:"measure-space",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})}}}}const ze=class ze{constructor(t,e){c(this,"Cesium");c(this,"viewer");c(this,"handler",null);c(this,"entity",null);c(this,"labelEntity",null);c(this,"positions",[]);c(this,"tempPoints",[]);c(this,"primitive",null);c(this,"previewEntity",null);c(this,"previewPos",null);c(this,"edgeEntities",[]);c(this,"pointEntities",[]);c(this,"previewEdgeEntity",null);c(this,"previewPointEntities",[]);c(this,"htmlLabelPool",null);c(this,"htmlLabelId",null);c(this,"previewLabelId",null);c(this,"segmentLabelIds",[]);c(this,"angleLabelIds",[]);c(this,"tooltip",null);c(this,"keydownHandler",null);c(this,"contextMenuHandler",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-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.tooltip=new ce,this.tooltip.show(ze.TIP_TEXT),this._bindGlobalEvents(t,e,i),this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var p,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()),a=new e.PolygonGeometry({polygonHierarchy:r,vertexFormat:e.MaterialAppearance.VERTEX_FORMAT,perPositionHeight:!0,arcType:e.ArcType.NONE}),l=new e.GeometryInstance({geometry:a}),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:l,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 m=t.lineColor||t.color||e.Color.YELLOW,f=((g=(p=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:g.call(p,.9))||e.Color.RED,w=this.positions.concat([this.positions[0]]),y=i.entities.add({polyline:{positions:w,width:t.width||2,material:m,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 m,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),l=new e.EllipsoidTangentPlane(r,e.Ellipsoid.WGS84).projectPointsOntoPlane(o);let d=0;for(let w=0;w<l.length;w++){const y=(w+1)%l.length;d+=l[w].x*l[y].y-l[y].x*l[w].y}d=Math.abs(d)/2;const u=e.Cartographic.fromCartesian(r),p=this.previewLabelId||"measure_area_preview";this.previewLabelId=p;const g=t.labelText||{area:"面积"};if(this.htmlLabelPool.add({text:`${g.area}:${d.toFixed(2)} m²`},{id:p,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 P=this.positions.concat([this.previewPos]);return new e.PolygonHierarchy(P)},!1),material:w,perPositionHeight:!0,arcType:e.ArcType.NONE}});const y=t.lineColor||t.color||e.Color.YELLOW,v=((f=(m=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:f.call(m,.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(()=>{this._finishMeasurement(t,e,!0)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK),this.handler.setInputAction(()=>{this._undoLastPoint(t,e,i)},e.ScreenSpaceEventType.RIGHT_CLICK)}stop(){this.keydownHandler&&(window.removeEventListener("keydown",this.keydownHandler),this.keydownHandler=null),this.contextMenuHandler&&(this.viewer.canvas.removeEventListener("contextmenu",this.contextMenuHandler),this.contextMenuHandler=null),this.handler&&(this.handler.destroy(),this.handler=null),this.tooltip&&(this.tooltip.destroy(),this.tooltip=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=[]}_clearPreviewState(){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 t of this.previewPointEntities)try{this.viewer.entities.remove(t)}catch{}this.previewPointEntities=[]}this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.previewPos=null}_rebuildShape(t,e,i){var l,d;if(this.primitive&&(i.scene.primitives.remove(this.primitive),this.primitive=null),this.edgeEntities.length){for(const u of this.edgeEntities)try{i.entities.remove(u)}catch{}this.edgeEntities=[]}if(!this.positions.length)return;const n=new e.PolygonHierarchy(this.positions.slice()),s=new e.PolygonGeometry({polygonHierarchy:n,vertexFormat:e.MaterialAppearance.VERTEX_FORMAT,perPositionHeight:!0,arcType:e.ArcType.NONE}),o=new e.GeometryInstance({geometry:s}),r=t.color||e.Color.YELLOW.withAlpha(.4),a=t.color&&t.color.withAlpha?t.color.withAlpha(.25):e.Color.RED.withAlpha(.4);if(this.primitive=new e.Primitive({geometryInstances:o,appearance:new e.MaterialAppearance({material:e.Material.fromType("Color",{color:r}),translucent:!0,closed:!0}),depthFailAppearance:new e.MaterialAppearance({material:e.Material.fromType("Color",{color:a}),translucent:!0,closed:!0})}),i.scene.primitives.add(this.primitive),this.positions.length>=2){const u=t.lineColor||t.color||e.Color.YELLOW,p=((d=(l=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:d.call(l,.9))||e.Color.RED,g=this.positions.concat([this.positions[0]]),m=i.entities.add({polyline:{positions:g,width:t.width||2,material:u,clampToGround:!1,arcType:e.ArcType.NONE,depthFailMaterial:new e.PolylineDashMaterialProperty({color:p,dashLength:12,dashPattern:255})}});this.edgeEntities.push(m)}}_undoLastPoint(t,e,i){if(!this.positions.length)return;this.positions.pop();const n=this.tempPoints.pop();n&&i.entities.remove(n),this._clearPreviewState(),this._rebuildShape(t,e,i)}_finishMeasurement(t,e,i){var g;if(i&&this.positions.length>=3){this.positions.pop();const m=this.tempPoints.pop();m&&this.viewer.entities.remove(m)}if(this.positions.length<3){this.clear();return}this._clearPreviewState(),this.stop();const n=new e.Cartesian3(this.positions.reduce((m,f)=>m+f.x,0)/this.positions.length,this.positions.reduce((m,f)=>m+f.y,0)/this.positions.length,this.positions.reduce((m,f)=>m+f.z,0)/this.positions.length),o=new e.EllipsoidTangentPlane(n,e.Ellipsoid.WGS84).projectPointsOntoPlane(this.positions);let r=0;for(let m=0;m<o.length;m++){const f=(m+1)%o.length;r+=o[m].x*o[f].y-o[f].x*o[m].y}r=Math.abs(r)/2;const a=e.Cartographic.fromCartesian(n),l=this.htmlLabelId||`measure_area_${Date.now()}`;this.htmlLabelId=l;const d=t.labelText||{area:"面积",side:"边长",angle:"角度"};this.htmlLabelPool.add({text:`${d.area}:${r.toFixed(2)} m²`},{id:l,lon:e.Math.toDegrees(a.longitude),lat:e.Math.toDegrees(a.latitude),height:a.height||0,theme:"measure-area",show:!0}),this.labelEntity=this.htmlLabelId;for(let m=0;m<this.positions.length;m++){const f=(m+1)%this.positions.length,w=this.positions[m],y=this.positions[f],v=e.Cartographic.fromCartesian(w),C=e.Cartographic.fromCartesian(y),P=new e.EllipsoidGeodesic(v,C).surfaceDistance,E=new e.Cartesian3((w.x+y.x)/2,(w.y+y.y)/2,(w.z+y.z)/2),L=e.Cartographic.fromCartesian(E),M=`measure_area_seg_${Date.now()}_${m}`;this.segmentLabelIds.push(M),this.htmlLabelPool.add({text:`${d.side}:${P.toFixed(2)} m`},{id:M,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 m=0;m<u.length;m++){const f=u[(m-1+u.length)%u.length],w=u[m],y=u[(m+1)%u.length],v=f.x-w.x,C=f.y-w.y,b=y.x-w.x,P=y.y-w.y,E=Math.sqrt(v*v+C*C),L=Math.sqrt(b*b+P*P);if(!E||!L)continue;const M=v/E*(b/L)+C/E*(P/L),x=Math.acos(Math.min(1,Math.max(-1,M)))*(180/Math.PI),_=e.Cartographic.fromCartesian(this.positions[m]),D=`measure_area_angle_${Date.now()}_${m}`;this.angleLabelIds.push(D),this.htmlLabelPool.add({text:`${d.angle}:${x.toFixed(2)} °`},{id:D,lon:e.Math.toDegrees(_.longitude),lat:e.Math.toDegrees(_.latitude),height:_.height||0,theme:"measure-area-angle",show:!0})}const p={entity:this.primitive,label:this.labelEntity,positions:this.positions,area:r,clear:()=>this.clear()};(g=t.onComplete)==null||g.call(t,p)}_bindGlobalEvents(t,e,i){this.keydownHandler=n=>{n.key==="Escape"&&(n.preventDefault(),this._finishMeasurement(t,e,!1))},window.addEventListener("keydown",this.keydownHandler),this.contextMenuHandler=n=>{n.preventDefault()},i.canvas.addEventListener("contextmenu",this.contextMenuHandler)}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<3)return;if(!this.htmlLabelPool){const P=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,n,P),this.htmlLabelPool.registerTheme("measure-area",{createElement:(E,L)=>{var M;E.innerHTML=String(((M=L==null?void 0:L.data)==null?void 0:M.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-area-seg",{createElement:(E,L)=>{var M;E.innerHTML=String(((M=L==null?void 0:L.data)==null?void 0:M.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-area-angle",{createElement:(E,L)=>{var M;E.innerHTML=String(((M=L==null?void 0:L.data)==null?void 0:M.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}}})}for(const P of o){const E=n.entities.add({position:P,point:{pixelSize:8,color:s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempPoints.push(E)}const r=new i.Cartesian3(o.reduce((P,E)=>P+E.x,0)/o.length,o.reduce((P,E)=>P+E.y,0)/o.length,o.reduce((P,E)=>P+E.z,0)/o.length),l=new i.EllipsoidTangentPlane(r,i.Ellipsoid.WGS84).projectPointsOntoPlane(o);let d=0;for(let P=0;P<l.length;P++){const E=(P+1)%l.length;d+=l[P].x*l[E].y-l[E].x*l[P].y}d=Math.abs(d)/2;const u=i.Cartographic.fromCartesian(r),p=t.id+"_area";this.htmlLabelId=p;const g=s.labelText||{area:"面积",side:"边长",angle:"角度"};this.htmlLabelPool.add({text:`${g.area}:${d.toFixed(2)} m²`},{id:p,lon:i.Math.toDegrees(u.longitude),lat:i.Math.toDegrees(u.latitude),height:u.height||0,theme:"measure-area",show:!0});const m=new i.PolygonHierarchy(o),f=new i.PolygonGeometry({polygonHierarchy:m,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 P=0;P<o.length;P++){const E=(P+1)%o.length,L=o[P],M=o[E],x=i.Cartographic.fromCartesian(L),_=i.Cartographic.fromCartesian(M),I=new i.EllipsoidGeodesic(x,_).surfaceDistance,k=new i.Cartesian3((L.x+M.x)/2,(L.y+M.y)/2,(L.z+M.z)/2),S=i.Cartographic.fromCartesian(k),R=t.id+`_area_seg_${P}`;this.segmentLabelIds.push(R),this.htmlLabelPool.add({text:`${g.side}:${I.toFixed(2)} m`},{id:R,lon:i.Math.toDegrees(S.longitude),lat:i.Math.toDegrees(S.latitude),height:S.height||0,theme:"measure-area-seg",show:!0})}const b=l;for(let P=0;P<b.length;P++){const E=b[(P-1+b.length)%b.length],L=b[P],M=b[(P+1)%b.length],x=E.x-L.x,_=E.y-L.y,D=M.x-L.x,I=M.y-L.y,k=Math.sqrt(x*x+_*_),S=Math.sqrt(D*D+I*I);if(!k||!S)continue;const R=x/k*(D/S)+_/k*(I/S),T=Math.acos(Math.min(1,Math.max(-1,R)))*(180/Math.PI),$=i.Cartographic.fromCartesian(o[P]),H=t.id+`_area_angle_${P}`;this.angleLabelIds.push(H),this.htmlLabelPool.add({text:`${g.angle}:${T.toFixed(2)} °`},{id:H,lon:i.Math.toDegrees($.longitude),lat:i.Math.toDegrees($.latitude),height:$.height||0,theme:"measure-area-angle",show:!0})}}};c(ze,"TIP_TEXT","单击左键添加点,右键撤销,双击左键或Esc结束");let De=ze;class Qe{constructor(t,e){c(this,"Cesium");c(this,"viewer");c(this,"handler",null);c(this,"entity",null);c(this,"positions",[]);c(this,"currentRadius",0);c(this,"labelEntity",null);c(this,"previewLabel",null);c(this,"ellipsePrimitive",null);c(this,"previewEntity",null);c(this,"isPrimitive",!1);c(this,"htmlLabelPool",null);c(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 a;const r=((a=o==null?void 0:o.data)==null?void 0:a.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],a=this.positions[1],l=e.Cartesian3.distance(r,a),d=Math.PI*l*l,u=2*Math.PI*l,p=t.labelText||{radius:"半径",area:"面积",circumference:"周长"},g=r;this.labelEntity?(this.labelEntity.position=g,this.labelEntity.label.text=`${p.radius}:${l.toFixed(2)} m
44
+ ${p.area}:${d.toFixed(2)} m²
45
+ ${p.circumference}:${u.toFixed(2)} m`):this.labelEntity=i.entities.add({position:g,label:{text:`${p.radius}:${l.toFixed(2)} m
46
+ ${p.area}:${d.toFixed(2)} m²
47
+ ${p.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 m=e.Cartographic.fromCartesian(r),f=new e.EllipseGeometry({center:r,semiMajorAxis:l,semiMinorAxis:l,height:m.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),P=e.Math.toDegrees(C.latitude),E=C.height||0,L=this.htmlLabelId||`measure_circle_${Date.now()}`;this.htmlLabelId=L;const M=`${p.radius}:${l.toFixed(2)} m
48
+ ${p.area}:${d.toFixed(2)} m²
49
+ ${p.circumference}:${u.toFixed(2)} m`;this.htmlLabelPool.add({text:M},{id:L,lon:b,lat:P,height:E,theme:"measure-circle",show:!0});const x={entity:this.entity,label:this.labelEntity,positions:this.positions,radius:l,area:d,perimeter:u,clear:()=>this.clear()};(o=t.onComplete)==null||o.call(t,x)}},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 a=e.Cartesian3.distance(s,r);this.currentRadius=a;const l=e.Cartographic.fromCartesian(s),d=Math.PI*a*a,u=2*Math.PI*a,p=t.labelText||{radius:"半径",area:"面积",circumference:"周长"},g=s;this.labelEntity?(this.labelEntity.position=g,this.labelEntity.label.text=`${p.radius}:${a.toFixed(2)} m
50
+ ${p.area}:${d.toFixed(2)} m²
51
+ ${p.circumference}:${u.toFixed(2)} m`):this.labelEntity=i.entities.add({position:g,label:{text:`${p.radius}:${a.toFixed(2)} m
52
+ ${p.area}:${d.toFixed(2)} m²
53
+ ${p.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 m=e.Cartographic.fromCartesian(s),f=e.Math.toDegrees(m.longitude),w=e.Math.toDegrees(m.latitude),y=m.height||0,v=this.htmlLabelId||`measure_circle_${Date.now()}`;this.htmlLabelId=v;const C=`${p.radius}:${a.toFixed(2)} m
54
+ ${p.area}:${d.toFixed(2)} m²
55
+ ${p.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:l.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(E=>new i.Cartesian3(E[0],E[1],E[2]));if(o.length<2)return;if(!this.htmlLabelPool){const E=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,n,E),this.htmlLabelPool.registerTheme("measure-circle",{createElement:(L,M)=>{var _;const x=((_=M==null?void 0:M.data)==null?void 0:_.text)||"";L.innerHTML=String(x),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],a=o[1],l=i.Cartesian3.distance(r,a),d=Math.PI*l*l,u=2*Math.PI*l,p=i.Cartographic.fromCartesian(r),g=new i.EllipseGeometry({center:r,semiMajorAxis:l,semiMinorAxis:l,height:p.height||0,vertexFormat:i.MaterialAppearance.VERTEX_FORMAT}),m=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:m,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:"周长"},P=`${b.radius}:${l.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})}}const Ne=class Ne{constructor(t,e){l(this,"Cesium");l(this,"viewer");l(this,"handler",null);l(this,"entity",null);l(this,"labelEntity",null);l(this,"positions",[]);l(this,"tempPoints",[]);l(this,"segmentLabels",[]);l(this,"hoverPos",null);l(this,"previewPos",null);l(this,"previewLabel",null);l(this,"previewEntity",null);l(this,"htmlLabelPool",null);l(this,"totalLabelId",null);l(this,"segmentLabelIds",[]);l(this,"previewLabelId",null);l(this,"tooltip",null);l(this,"keydownHandler",null);l(this,"contextMenuHandler",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.tooltip=new ce,this.tooltip.show(Ne.TIP_TEXT),this._bindGlobalEvents(t,e,i),this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var r,h;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:((h=(r=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:h.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(()=>{this._finishMeasurement(t,e,!0)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK),this.handler.setInputAction(()=>{this._undoLastPoint()},e.ScreenSpaceEventType.RIGHT_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),h=e.Cartographic.fromCartesian(s),d=new e.EllipsoidGeodesic(r,h).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.keydownHandler&&(window.removeEventListener("keydown",this.keydownHandler),this.keydownHandler=null),this.contextMenuHandler&&(this.viewer.canvas.removeEventListener("contextmenu",this.contextMenuHandler),this.contextMenuHandler=null),this.handler&&(this.handler.destroy(),this.handler=null),this.tooltip&&(this.tooltip.destroy(),this.tooltip=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=[]}_clearPreviewState(){this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.previewPos=null,this.hoverPos=null}_undoLastPoint(){var e;if(!this.positions.length)return;this.positions.pop();const t=this.tempPoints.pop();if(t&&this.viewer.entities.remove(t),this.segmentLabelIds.length>this.positions.length-1&&this.htmlLabelPool){const i=this.segmentLabelIds.pop();i&&this.htmlLabelPool.removeByIds([i])}(e=this.entity)!=null&&e.polyline&&(this.entity.polyline.positions=this.positions.slice()),this.positions.length?this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null):(this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this._clearPreviewState())}_finishMeasurement(t,e,i){var c;if(i){if(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()}if(this.positions.length<2){this.clear();return}this.stop(),this._clearPreviewState();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];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 h={entity:this.entity,label:this.labelEntity,segmentLabels:this.segmentLabelIds,positions:this.positions,distance:n,clear:()=>this.clear()};(c=t.onComplete)==null||c.call(t,h)}_bindGlobalEvents(t,e,i){this.keydownHandler=n=>{n.key==="Escape"&&(n.preventDefault(),this._finishMeasurement(t,e,!1))},window.addEventListener("keydown",this.keydownHandler),this.contextMenuHandler=n=>{n.preventDefault()},i.canvas.addEventListener("contextmenu",this.contextMenuHandler)}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,h=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:h,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"}})}};l(Ne,"TIP_TEXT","单击左键添加点,右键撤销,双击左键或Esc结束");let De=Ne;class et{constructor(t,e){l(this,"Cesium");l(this,"viewer");l(this,"handler",null);l(this,"labelEntity",null);l(this,"htmlLabelPool",null);l(this,"htmlLabelId",null);l(this,"topPoint",null);l(this,"zeroPoint",null);l(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,h=e.Math.toDegrees(o.longitude),c=e.Math.toDegrees(o.latitude),d=e.Cartesian3.fromDegrees(h,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:h,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],h=i.Cartographic.fromCartesian(r),c=n.scene.globe.getHeight(new i.Cartographic(h.longitude,h.latitude,0))||0,d=i.Math.toDegrees(h.longitude),u=i.Math.toDegrees(h.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=(h.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:h.height||0,theme:"measure-terrainHeight",show:!0})}}class tt{constructor(t,e){l(this,"Cesium");l(this,"viewer");l(this,"handler",null);l(this,"entity",null);l(this,"labelEntity",null);l(this,"htmlLabelPool",null);l(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),h=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
- ${u.lat}:${h.toFixed(6)}
59
- ${u.height}:${c.toFixed(2)} m`},{id:d,lon:r,lat:h,height:c,theme:"measure-coordinate",show:!0}),this.labelEntity=this.htmlLabelId;const m={entity:this.entity,label:this.labelEntity,lnglat:{lng:r,lat:h,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],h=i.Cartographic.fromCartesian(r),c=i.Math.toDegrees(h.longitude),d=i.Math.toDegrees(h.latitude),u=h.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)}
57
+ ${b.circumference}:${u.toFixed(2)} m`;this.htmlLabelPool.add({text:P},{id:C,lon:i.Math.toDegrees(v.longitude),lat:i.Math.toDegrees(v.latitude),height:v.height||0,theme:"measure-circle",show:!0})}}const Ne=class Ne{constructor(t,e){c(this,"Cesium");c(this,"viewer");c(this,"handler",null);c(this,"entity",null);c(this,"labelEntity",null);c(this,"positions",[]);c(this,"tempPoints",[]);c(this,"segmentLabels",[]);c(this,"hoverPos",null);c(this,"previewPos",null);c(this,"previewLabel",null);c(this,"previewEntity",null);c(this,"htmlLabelPool",null);c(this,"totalLabelId",null);c(this,"segmentLabelIds",[]);c(this,"previewLabelId",null);c(this,"tooltip",null);c(this,"keydownHandler",null);c(this,"contextMenuHandler",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.tooltip=new ce,this.tooltip.show(Ne.TIP_TEXT),this._bindGlobalEvents(t,e,i),this.handler=new e.ScreenSpaceEventHandler(i.canvas),this.handler.setInputAction(n=>{var r,a;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:((a=(r=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:a.call(r,.9))||e.Color.RED,dashLength:12,dashPattern:255})}}),this.positions.length>=2){const l=this.positions[this.positions.length-2],d=this.positions[this.positions.length-1],u=e.Cartographic.fromCartesian(l),p=e.Cartographic.fromCartesian(d),m=new e.EllipsoidGeodesic(u,p).surfaceDistance,f=new e.Cartesian3((l.x+d.x)/2,(l.y+d.y)/2,(l.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:`${m.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(()=>{this._finishMeasurement(t,e,!0)},e.ScreenSpaceEventType.LEFT_DOUBLE_CLICK),this.handler.setInputAction(()=>{this._undoLastPoint()},e.ScreenSpaceEventType.RIGHT_CLICK),this.handler.setInputAction(n=>{var m,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),a=e.Cartographic.fromCartesian(s),d=new e.EllipsoidGeodesic(r,a).surfaceDistance,u=new e.Cartesian3((o.x+s.x)/2,(o.y+s.y)/2,(o.z+s.z)/2),p=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(p.longitude),lat:e.Math.toDegrees(p.latitude),height:p.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=(m=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:f.call(m,.9))||e.Color.RED,dashLength:12,dashPattern:255})}}))},e.ScreenSpaceEventType.MOUSE_MOVE)}stop(){this.keydownHandler&&(window.removeEventListener("keydown",this.keydownHandler),this.keydownHandler=null),this.contextMenuHandler&&(this.viewer.canvas.removeEventListener("contextmenu",this.contextMenuHandler),this.contextMenuHandler=null),this.handler&&(this.handler.destroy(),this.handler=null),this.tooltip&&(this.tooltip.destroy(),this.tooltip=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=[]}_clearPreviewState(){this.previewEntity&&(this.viewer.entities.remove(this.previewEntity),this.previewEntity=null),this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null),this.previewPos=null,this.hoverPos=null}_undoLastPoint(){var e;if(!this.positions.length)return;this.positions.pop();const t=this.tempPoints.pop();if(t&&this.viewer.entities.remove(t),this.segmentLabelIds.length>this.positions.length-1&&this.htmlLabelPool){const i=this.segmentLabelIds.pop();i&&this.htmlLabelPool.removeByIds([i])}(e=this.entity)!=null&&e.polyline&&(this.entity.polyline.positions=this.positions.slice()),this.positions.length?this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null):(this.entity&&(this.viewer.entities.remove(this.entity),this.entity=null),this._clearPreviewState())}_finishMeasurement(t,e,i){var l;if(i){if(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()}if(this.positions.length<2){this.clear();return}this.stop(),this._clearPreviewState();let n=0;for(let d=1;d<this.positions.length;d++){const u=this.positions[d-1],p=this.positions[d],g=e.Cartographic.fromCartesian(u),m=e.Cartographic.fromCartesian(p),f=new e.EllipsoidGeodesic(g,m);n+=f.surfaceDistance}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 a={entity:this.entity,label:this.labelEntity,segmentLabels:this.segmentLabelIds,positions:this.positions,distance:n,clear:()=>this.clear()};(l=t.onComplete)==null||l.call(t,a)}_bindGlobalEvents(t,e,i){this.keydownHandler=n=>{n.key==="Escape"&&(n.preventDefault(),this._finishMeasurement(t,e,!1))},window.addEventListener("keydown",this.keydownHandler),this.contextMenuHandler=n=>{n.preventDefault()},i.canvas.addEventListener("contextmenu",this.contextMenuHandler)}rehydrate(t,e){var m,f;const i=this.Cesium,n=this.viewer,s=t.options||{},o=s.lineColor||s.color||i.Color.YELLOW,r=((f=(m=s.dashLineColor||s.lineColor||s.color||i.Color.RED).withAlpha)==null?void 0:f.call(m,.9))||i.Color.RED,a=s.width||3,l=(t.positions||[]).map(w=>new i.Cartesian3(w[0],w[1],w[2]));if(l.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 l){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:l,width:a,material:o,depthFailMaterial:new i.PolylineDashMaterialProperty({color:r,dashLength:12,dashPattern:255})}});let d=0;for(let w=1;w<l.length;w++){const y=i.Cartographic.fromCartesian(l[w-1]),v=i.Cartographic.fromCartesian(l[w]),C=new i.EllipsoidGeodesic(y,v);d+=C.surfaceDistance;const b=l[w-1],P=l[w],E=new i.Cartesian3((b.x+P.x)/2,(b.y+P.y)/2,(b.z+P.z)/2),L=i.Cartographic.fromCartesian(E),M=t.id+`_seg_${w-1}`;this.segmentLabelIds.push(M),this.htmlLabelPool.add({text:`${C.surfaceDistance.toFixed(2)} m`},{id:M,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=l[l.length-1],p=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(p.longitude),lat:i.Math.toDegrees(p.latitude),height:p.height||0,theme:"measure-polyline-total",show:!0,style:{pointerEvents:"none",userSelect:"none",cursor:"default"}})}};c(Ne,"TIP_TEXT","单击左键添加点,右键撤销,双击左键或Esc结束");let Se=Ne;class et{constructor(t,e){c(this,"Cesium");c(this,"viewer");c(this,"handler",null);c(this,"labelEntity",null);c(this,"htmlLabelPool",null);c(this,"htmlLabelId",null);c(this,"topPoint",null);c(this,"zeroPoint",null);c(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,a=e.Math.toDegrees(o.longitude),l=e.Math.toDegrees(o.latitude),d=e.Cartesian3.fromDegrees(a,l,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:"高差"},p=(o.height||0)-r,g=`${u.height}:${p.toFixed(2)} m`,m=this.htmlLabelId||`measure_terrain_${Date.now()}`;this.htmlLabelId=m,this.htmlLabelPool.add({text:g},{id:m,lon:a,lat:l,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:p,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],a=i.Cartographic.fromCartesian(r),l=n.scene.globe.getHeight(new i.Cartographic(a.longitude,a.latitude,0))||0,d=i.Math.toDegrees(a.longitude),u=i.Math.toDegrees(a.latitude),p=i.Cartesian3.fromDegrees(d,u,l);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:p,point:{pixelSize:8,color:i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),this.lineEntity=n.entities.add({polyline:{positions:[p,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:"高差"},m=(a.height||0)-l,f=t.id+"_terrain";this.htmlLabelId=f,this.htmlLabelPool.add({text:`${g.height}:${m.toFixed(2)} m`},{id:f,lon:d,lat:u,height:a.height||0,theme:"measure-terrainHeight",show:!0})}}class tt{constructor(t,e){c(this,"Cesium");c(this,"viewer");c(this,"handler",null);c(this,"entity",null);c(this,"labelEntity",null);c(this,"htmlLabelPool",null);c(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),a=e.Math.toDegrees(o.latitude),l=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
+ ${u.lat}:${a.toFixed(6)}
59
+ ${u.height}:${l.toFixed(2)} m`},{id:d,lon:r,lat:a,height:l,theme:"measure-coordinate",show:!0}),this.labelEntity=this.htmlLabelId;const p={entity:this.entity,label:this.labelEntity,lnglat:{lng:r,lat:a,height:l},clear:()=>this.clear()};(g=t.onComplete)==null||g.call(t,p),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 m;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=(m=t.data)==null?void 0:m.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],a=i.Cartographic.fromCartesian(r),l=i.Math.toDegrees(a.longitude),d=i.Math.toDegrees(a.latitude),u=a.height||0;this.entity=n.entities.add({position:r,point:{pixelSize:10,color:s.color||i.Color.YELLOW,disableDepthTestDistance:Number.POSITIVE_INFINITY}});const p=t.id+"_coord";this.htmlLabelId=p;const g=s.labelText||{lng:"经",lat:"纬",height:"高"};this.htmlLabelPool.add({text:`${g.lng}:${l.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 it{constructor(t,e){l(this,"Cesium");l(this,"viewer");l(this,"handler",null);l(this,"startPoint",null);l(this,"endPoint",null);l(this,"secondPoint",null);l(this,"currentCorners",[]);l(this,"edgeEntities",[]);l(this,"pointEntities",[]);l(this,"previewEdgeEntity",null);l(this,"previewPointEntities",[]);l(this,"entity",null);l(this,"labelEntity",null);l(this,"primitive",null);l(this,"previewEntity",null);l(this,"htmlLabelPool",null);l(this,"htmlLabelId",null);l(this,"segmentLabelIds",[]);l(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 $,S,O;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:h,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
61
+ ${g.height}:${u.toFixed(2)} m`},{id:p,lon:l,lat:d,height:u,theme:"measure-coordinate",show:!0})}}class it{constructor(t,e){c(this,"Cesium");c(this,"viewer");c(this,"handler",null);c(this,"startPoint",null);c(this,"endPoint",null);c(this,"secondPoint",null);c(this,"currentCorners",[]);c(this,"edgeEntities",[]);c(this,"pointEntities",[]);c(this,"previewEdgeEntity",null);c(this,"previewPointEntities",[]);c(this,"entity",null);c(this,"labelEntity",null);c(this,"primitive",null);c(this,"previewEntity",null);c(this,"htmlLabelPool",null);c(this,"htmlLabelId",null);c(this,"segmentLabelIds",[]);c(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 k,S,R;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:a,center:l,width:d,height:u,area:p}=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 m=e.Cartographic.fromCartesian(l),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
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=[[h[0],h[1]],[h[1],h[2]],[h[2],h[3]],[h[3],h[0]]];for(let _=0;_<w.length;_++){const[k,F]=w[_],G=_===0||_===2?d:u,B=new e.Cartesian3((k.x+F.x)/2,(k.y+F.y)/2,(k.z+F.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(h),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=((S=($=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:S.call($,.9))||e.Color.RED,I=[...y,y[0]],D=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(D);const x=t.pointColor||t.color||e.Color.YELLOW;for(const _ of h){const k=i.entities.add({position:_,point:{pixelSize:8,color:x,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.pointEntities.push(k)}const T={entity:this.primitive,label:this.labelEntity,positions:[this.startPoint,this.secondPoint,o],width:d,height:u,area:m,clear:()=>this.clear()};(O=t.onComplete)==null||O.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:h,width:c,height:d,area:u}=o,m=this.buildSurfaceRectanglePositions(r);this.currentCorners=m;const g=e.Cartographic.fromCartesian(h),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
63
+ ${f.area}:${p.toFixed(2)} m²`},{id:g,lon:e.Math.toDegrees(m.longitude),lat:e.Math.toDegrees(m.latitude),height:m.height||0,theme:"measure-rectangle",show:!0});const w=[[a[0],a[1]],[a[1],a[2]],[a[2],a[3]],[a[3],a[0]]];for(let T=0;T<w.length;T++){const[$,H]=w[T],G=T===0||T===2?d:u,B=new e.Cartesian3(($.x+H.x)/2,($.y+H.y)/2,($.z+H.z)/2),Y=e.Cartographic.fromCartesian(B),q=`measure_rectangle_seg_${Date.now()}_${T}`;this.segmentLabelIds.push(q),this.htmlLabelPool.add({text:`${f.side}:${Number(G).toFixed(2)} m`},{id:q,lon:e.Math.toDegrees(Y.longitude),lat:e.Math.toDegrees(Y.latitude),height:Y.height||0,theme:"measure-rectangle-seg",show:!0})}const y=this.buildSurfaceRectanglePositions(a),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}),P=t.color||e.Color.YELLOW.withAlpha(.4),E=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:P}),translucent:!0,closed:!0}),depthFailAppearance:new e.MaterialAppearance({material:e.Material.fromType("Color",{color:E}),translucent:!0,closed:!0})}),i.scene.primitives.add(this.primitive);const L=t.lineColor||t.color||e.Color.YELLOW,M=((S=(k=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:S.call(k,.9))||e.Color.RED,x=[...y,y[0]],_=i.entities.add({polyline:{positions:x,width:t.width||2,material:L,clampToGround:!1,arcType:e.ArcType.NONE,depthFailMaterial:new e.PolylineDashMaterialProperty({color:M,dashLength:12,dashPattern:255})}});this.edgeEntities.push(_);const D=t.pointColor||t.color||e.Color.YELLOW;for(const T of a){const $=i.entities.add({position:T,point:{pixelSize:8,color:D,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.pointEntities.push($)}const I={entity:this.primitive,label:this.labelEntity,positions:[this.startPoint,this.secondPoint,o],width:d,height:u,area:p,clear:()=>this.clear()};(R=t.onComplete)==null||R.call(t,I)},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,P=i.entities.add({position:this.startPoint,point:{pixelSize:8,color:b,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),E=i.entities.add({position:new e.CallbackProperty(()=>this.endPoint||this.startPoint,!1),point:{pixelSize:8,color:b,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.previewPointEntities.push(P,E)}return}if(!this.startPoint||!this.secondPoint)return;const o=this.computeRectangle(this.startPoint,this.secondPoint,s);if(!o)return;const{corners:r,center:a,width:l,height:d,area:u}=o,p=this.buildSurfaceRectanglePositions(r);this.currentCorners=p;const g=e.Cartographic.fromCartesian(a),m=this.previewLabelId||"measure_rectangle_preview";this.previewLabelId=m;const f=t.labelText||{width:"宽",heightLabel:"高",area:"面积"};if(this.htmlLabelPool.add({text:`${f.width}:${l.toFixed(2)} m
64
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 S;T.innerHTML=String(((S=$==null?void 0:$.data)==null?void 0:S.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 S;T.innerHTML=String(((S=$==null?void 0:$.data)==null?void 0:S.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 h=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
65
+ ${f.area}:${u.toFixed(2)} m²`},{id:m,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(D=>new i.Cartesian3(D[0],D[1],D[2]));if(o.length<3)return;if(!this.htmlLabelPool){const D=s.overlayContainerId||"html-label-container";this.htmlLabelPool=e||new N(i,n,D),this.htmlLabelPool.registerTheme("measure-rectangle",{createElement:(I,k)=>{var S;I.innerHTML=String(((S=k==null?void 0:k.data)==null?void 0:S.text)||""),I.style.background="rgba(0,0,0,0.6)",I.style.color="#fff",I.style.font="14px sans-serif",I.style.padding="4px 6px",I.style.borderRadius="4px",I.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-rectangle-seg",{createElement:(I,k)=>{var S;I.innerHTML=String(((S=k==null?void 0:k.data)==null?void 0:S.text)||""),I.style.background="rgba(0,0,0,0.6)",I.style.color="#fff",I.style.font="14px sans-serif",I.style.padding="4px 6px",I.style.borderRadius="4px",I.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}const r=this.computeRectangle(o[0],o[1],o[2]);if(!r)return;const a=r.corners,l=r.center,d=r.width,u=r.height,p=r.area,g=i.Cartographic.fromCartesian(l),m=t.id+"_rectangle",f=s.labelText||{width:"宽",heightLabel:"高",area:"面积",side:"边长"};this.htmlLabelId=m,this.htmlLabelPool.add({text:`${f.width}:${d.toFixed(2)} m
66
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=[[h[0],h[1]],[h[1],h[2]],[h[2],h[3]],[h[3],h[0]]];for(let x=0;x<w.length;x++){const[T,$]=w[x],S=x===0||x===2?d:u,O=new i.Cartesian3((T.x+$.x)/2,(T.y+$.y)/2,(T.z+$.z)/2),_=i.Cartographic.fromCartesian(O),k=t.id+`_rectangle_seg_${x}`;this.segmentLabelIds.push(k),this.htmlLabelPool.add({text:`${f.side}:${Number(S).toFixed(2)} m`},{id:k,lon:i.Math.toDegrees(_.longitude),lat:i.Math.toDegrees(_.latitude),height:_.height||0,theme:"measure-rectangle-seg",show:!0})}const y=new i.PolygonHierarchy(h),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=[...h,h[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 D=s.pointColor||b;for(const x of h){const T=n.entities.add({position:x,point:{pixelSize:8,color:D,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],h=o[1],c=o[2],d=h.x-r.x,u=h.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-h.x,v=c.y-h.y,C=y*f+v*w;if(!C)return null;const b=new n.Cartesian2(h.x+f*C,h.y+w*C),M=new n.Cartesian2(r.x+f*C,r.y+w*C),P=s.projectPointsOntoEllipsoid([r,h,b,M]);if(!P||P.length<4)return null;const L=P,E=L[0],I=L[2],D=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),S=new n.EllipsoidTangentPlane(T,n.Ellipsoid.WGS84).projectPointsOntoPlane(L);let O=0;for(let k=0;k<S.length;k++){const F=(k+1)%S.length;O+=S[k].x*S[F].y-S[F].x*S[k].y}const _=Math.abs(O)/2;return{corners:L,center:T,width:D,height:x,area:_}}}class st{constructor(t,e){l(this,"Cesium");l(this,"viewer");l(this,"handler",null);l(this,"entity",null);l(this,"positions",[]);l(this,"labelEntity",null);l(this,"currentPoints",[]);l(this,"primitive",null);l(this,"previewEntity",null);l(this,"edgeEntities",[]);l(this,"pointEntities",[]);l(this,"previewEdgeEntity",null);l(this,"previewPointEntities",[]);l(this,"htmlLabelPool",null);l(this,"htmlLabelId",null);l(this,"segmentLabelIds",[]);l(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 h;o.innerHTML=String(((h=r==null?void 0:r.data)==null?void 0:h.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 h;o.innerHTML=String(((h=r==null?void 0:r.data)==null?void 0:h.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,h,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=((h=(r=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:h.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 O of E){const _=i.entities.add({position:O,point:{pixelSize:8,color:L,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.pointEntities.push(_)}const I=this.computeAreaByPlane(g),D=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 O=1;O<g.length;O++){const _=g[O-1],k=g[O],F=e.Cartographic.fromCartesian(_),G=e.Cartographic.fromCartesian(k),j=new e.EllipsoidGeodesic(F,G).surfaceDistance;$+=j;const X=new e.Cartesian3((_.x+k.x)/2,(_.y+k.y)/2,(_.z+k.z)/2),Z=e.Cartographic.fromCartesian(X),ae=`measure_regular_seg_${Date.now()}_${O-1}`;this.segmentLabelIds.push(ae),this.htmlLabelPool.add({text:`${T.side}:${j.toFixed(2)} m`},{id:ae,lon:e.Math.toDegrees(Z.longitude),lat:e.Math.toDegrees(Z.latitude),height:Z.height||0,theme:"measure-regular-seg",show:!0})}this.htmlLabelPool.add({text:`${T.sides}:${n}
68
- ${T.radius}:${m.toFixed(2)} m
69
- ${T.circumference}:${$.toFixed(2)} m
70
- ${T.area}:${I.toFixed(2)} m²`},{id:x,lon:e.Math.toDegrees(D.longitude),lat:e.Math.toDegrees(D.latitude),height:D.height||0,theme:"measure-regular",show:!0});const S={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,S)}},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),h=i.scene.globe.pick(r,i.scene);if(!h)return;const c=e.Cartesian3.distance(o,h);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(()=>h||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
- ${p.radius}:${c.toFixed(2)} m
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,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 D;E.innerHTML=String(((D=I==null?void 0:I.data)==null?void 0:D.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 D;E.innerHTML=String(((D=I==null?void 0:I.data)==null?void 0:D.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 h=[],c=r[0],d=0;if(r.length>=3){h=r.slice(),c=new i.Cartesian3(h.reduce((E,I)=>E+I.x,0)/h.length,h.reduce((E,I)=>E+I.y,0)/h.length,h.reduce((E,I)=>E+I.z,0)/h.length);const L=h[0];h[Math.floor(h.length/2)]||h[1],d=i.Cartesian3.distance(c,L)}else{const L=r[1];d=i.Cartesian3.distance(c,L),h=this.buildRegularPolygonPoints(c,d,Math.max(o,3))}const u=new i.PolygonHierarchy(h),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(h),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<h.length;L++){const E=h[L-1],I=h[L],D=i.Cartographic.fromCartesian(E),x=i.Cartographic.fromCartesian(I),$=new i.EllipsoidGeodesic(D,x).surfaceDistance;M+=$;const S=new i.Cartesian3((E.x+I.x)/2,(E.y+I.y)/2,(E.z+I.z)/2),O=i.Cartographic.fromCartesian(S),_=t.id+`_regular_seg_${L-1}`;this.segmentLabelIds.push(_),this.htmlLabelPool.add({text:`${b.side}:${$.toFixed(2)} m`},{id:_,lon:i.Math.toDegrees(O.longitude),lat:i.Math.toDegrees(O.latitude),height:O.height||0,theme:"measure-regular-seg",show:!0})}this.htmlLabelPool.add({text:`${b.sides}:${Math.max(o,3)}
67
+ ${f.area}:${p.toFixed(2)} m²`},{id:m,lon:i.Math.toDegrees(g.longitude),lat:i.Math.toDegrees(g.latitude),height:g.height||0,theme:"measure-rectangle",show:!0});const w=[[a[0],a[1]],[a[1],a[2]],[a[2],a[3]],[a[3],a[0]]];for(let D=0;D<w.length;D++){const[I,k]=w[D],S=D===0||D===2?d:u,R=new i.Cartesian3((I.x+k.x)/2,(I.y+k.y)/2,(I.z+k.z)/2),T=i.Cartographic.fromCartesian(R),$=t.id+`_rectangle_seg_${D}`;this.segmentLabelIds.push($),this.htmlLabelPool.add({text:`${f.side}:${Number(S).toFixed(2)} m`},{id:$,lon:i.Math.toDegrees(T.longitude),lat:i.Math.toDegrees(T.latitude),height:T.height||0,theme:"measure-rectangle-seg",show:!0})}const y=new i.PolygonHierarchy(a),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),P=s.color&&s.color.withAlpha?s.color.withAlpha(.25):i.Color.RED.withAlpha(.4),E=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:P}),translucent:!0,closed:!0})});this.primitive=E,n.scene.primitives.add(this.primitive);const L=s.lineColor||b,M=[...a,a[0]],x=n.entities.add({polyline:{positions:M,width:s.width||2,material:L,clampToGround:!1,arcType:i.ArcType.NONE}});this.edgeEntities.push(x);const _=s.pointColor||b;for(const D of a){const I=n.entities.add({position:D,point:{pixelSize:8,color:_,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.pointEntities.push(I)}}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],a=o[1],l=o[2],d=a.x-r.x,u=a.y-r.y,p=Math.sqrt(d*d+u*u);if(!p)return null;const g=d/p,f=-(u/p),w=g,y=l.x-a.x,v=l.y-a.y,C=y*f+v*w;if(!C)return null;const b=new n.Cartesian2(a.x+f*C,a.y+w*C),P=new n.Cartesian2(r.x+f*C,r.y+w*C),E=s.projectPointsOntoEllipsoid([r,a,b,P]);if(!E||E.length<4)return null;const L=E,M=L[0],x=L[2],_=Math.abs(p),D=Math.abs(C),I=new n.Cartesian3((M.x+x.x)/2,(M.y+x.y)/2,(M.z+x.z)/2),S=new n.EllipsoidTangentPlane(I,n.Ellipsoid.WGS84).projectPointsOntoPlane(L);let R=0;for(let $=0;$<S.length;$++){const H=($+1)%S.length;R+=S[$].x*S[H].y-S[H].x*S[$].y}const T=Math.abs(R)/2;return{corners:L,center:I,width:_,height:D,area:T}}}class st{constructor(t,e){c(this,"Cesium");c(this,"viewer");c(this,"handler",null);c(this,"entity",null);c(this,"positions",[]);c(this,"labelEntity",null);c(this,"currentPoints",[]);c(this,"primitive",null);c(this,"previewEntity",null);c(this,"edgeEntities",[]);c(this,"pointEntities",[]);c(this,"previewEdgeEntity",null);c(this,"previewPointEntities",[]);c(this,"htmlLabelPool",null);c(this,"htmlLabelId",null);c(this,"segmentLabelIds",[]);c(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 a;o.innerHTML=String(((a=r==null?void 0:r.data)==null?void 0:a.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 a;o.innerHTML=String(((a=r==null?void 0:r.data)==null?void 0:a.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,a,l;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],p=e.Cartesian3.distance(d,u),g=this.buildRegularPolygonPoints(d,p,n);this.previewEntity&&(i.entities.remove(this.previewEntity),this.previewEntity=null),this.primitive&&(i.scene.primitives.remove(this.primitive),this.primitive=null);const m=new e.PolygonHierarchy(g),f=new e.PolygonGeometry({polygonHierarchy:m,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=((a=(r=t.dashLineColor||t.lineColor||t.color||e.Color.RED).withAlpha)==null?void 0:a.call(r,.9))||e.Color.RED,P=g.slice(),E=i.entities.add({polyline:{positions:P,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(E);const L=t.pointColor||y,M=g.slice(0,g.length-1);for(const R of M){const T=i.entities.add({position:R,point:{pixelSize:8,color:L,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.pointEntities.push(T)}const x=this.computeAreaByPlane(g),_=e.Cartographic.fromCartesian(d),D=this.htmlLabelId||`measure_regular_${Date.now()}`;this.htmlLabelId=D;const I=t.labelText||{sides:"边数",radius:"半径",circumference:"周长",area:"面积",side:"边长"};this.previewLabelId&&this.htmlLabelPool&&(this.htmlLabelPool.removeByIds([this.previewLabelId]),this.previewLabelId=null);let k=0;for(let R=1;R<g.length;R++){const T=g[R-1],$=g[R],H=e.Cartographic.fromCartesian(T),G=e.Cartographic.fromCartesian($),Y=new e.EllipsoidGeodesic(H,G).surfaceDistance;k+=Y;const q=new e.Cartesian3((T.x+$.x)/2,(T.y+$.y)/2,(T.z+$.z)/2),J=e.Cartographic.fromCartesian(q),ae=`measure_regular_seg_${Date.now()}_${R-1}`;this.segmentLabelIds.push(ae),this.htmlLabelPool.add({text:`${I.side}:${Y.toFixed(2)} m`},{id:ae,lon:e.Math.toDegrees(J.longitude),lat:e.Math.toDegrees(J.latitude),height:J.height||0,theme:"measure-regular-seg",show:!0})}this.htmlLabelPool.add({text:`${I.sides}:${n}
68
+ ${I.radius}:${p.toFixed(2)} m
69
+ ${I.circumference}:${k.toFixed(2)} m
70
+ ${I.area}:${x.toFixed(2)} m²`},{id:D,lon:e.Math.toDegrees(_.longitude),lat:e.Math.toDegrees(_.latitude),height:_.height||0,theme:"measure-regular",show:!0});const S={entity:this.primitive,label:this.labelEntity,positions:g,radius:p,sides:n,perimeter:k,area:x,clear:()=>this.clear()};(l=t.onComplete)==null||l.call(t,S)}},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),a=i.scene.globe.pick(r,i.scene);if(!a)return;const l=e.Cartesian3.distance(o,a);if(this.currentPoints=this.buildRegularPolygonPoints(o,l,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,P=i.entities.add({position:o,point:{pixelSize:8,color:b,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),E=i.entities.add({position:new e.CallbackProperty(()=>a||o,!1),point:{pixelSize:8,color:b,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.previewPointEntities.push(P,E)}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),P=e.Cartographic.fromCartesian(C),E=new e.EllipsoidGeodesic(b,P);d+=E.surfaceDistance}const u=this.computeAreaByPlane(this.currentPoints),p=e.Cartographic.fromCartesian(o),g=this.previewLabelId||"measure_regular_preview";this.previewLabelId=g;const m=t.labelText||{sides:"边数",radius:"半径",circumference:"周长",area:"面积"};this.htmlLabelPool.add({text:`${m.sides}:${n}
71
+ ${m.radius}:${l.toFixed(2)} m
72
+ ${m.circumference}:${d.toFixed(2)} m
73
+ ${m.area}:${u.toFixed(2)} m²`},{id:g,lon:e.Math.toDegrees(p.longitude),lat:e.Math.toDegrees(p.latitude),height:p.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 E;const i=this.Cesium,n=this.viewer,s=t.options||{},o=((E=t.data)==null?void 0:E.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:(M,x)=>{var _;M.innerHTML=String(((_=x==null?void 0:x.data)==null?void 0:_.text)||""),M.style.background="rgba(0,0,0,0.6)",M.style.color="#fff",M.style.font="14px sans-serif",M.style.padding="4px 6px",M.style.borderRadius="4px",M.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}}),this.htmlLabelPool.registerTheme("measure-regular-seg",{createElement:(M,x)=>{var _;M.innerHTML=String(((_=x==null?void 0:x.data)==null?void 0:_.text)||""),M.style.background="rgba(0,0,0,0.6)",M.style.color="#fff",M.style.font="14px sans-serif",M.style.padding="4px 6px",M.style.borderRadius="4px",M.style.whiteSpace="pre"},options:{offset:{x:0,y:-10}}})}let a=[],l=r[0],d=0;if(r.length>=3){a=r.slice(),l=new i.Cartesian3(a.reduce((M,x)=>M+x.x,0)/a.length,a.reduce((M,x)=>M+x.y,0)/a.length,a.reduce((M,x)=>M+x.z,0)/a.length);const L=a[0];a[Math.floor(a.length/2)]||a[1],d=i.Cartesian3.distance(l,L)}else{const L=r[1];d=i.Cartesian3.distance(l,L),a=this.buildRegularPolygonPoints(l,d,Math.max(o,3))}const u=new i.PolygonHierarchy(a),p=new i.PolygonGeometry({polygonHierarchy:u,vertexFormat:i.MaterialAppearance.VERTEX_FORMAT,perPositionHeight:!0}),g=new i.GeometryInstance({geometry:p}),m=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:m}),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(a),v=i.Cartographic.fromCartesian(l),C=t.id+"_regular";this.htmlLabelId=C;const b=s.labelText||{sides:"边数",radius:"半径",circumference:"周长",area:"面积",side:"边长"};let P=0;for(let L=1;L<a.length;L++){const M=a[L-1],x=a[L],_=i.Cartographic.fromCartesian(M),D=i.Cartographic.fromCartesian(x),k=new i.EllipsoidGeodesic(_,D).surfaceDistance;P+=k;const S=new i.Cartesian3((M.x+x.x)/2,(M.y+x.y)/2,(M.z+x.z)/2),R=i.Cartographic.fromCartesian(S),T=t.id+`_regular_seg_${L-1}`;this.segmentLabelIds.push(T),this.htmlLabelPool.add({text:`${b.side}:${k.toFixed(2)} m`},{id:T,lon:i.Math.toDegrees(R.longitude),lat:i.Math.toDegrees(R.latitude),height:R.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
- ${b.circumference}:${M.toFixed(2)} m
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,h)=>r+h.x,0)/t.length,t.reduce((r,h)=>r+h.y,0)/t.length,t.reduce((r,h)=>r+h.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 h=(r+1)%s.length;o+=s[r].x*s[h].y-s[h].x*s[r].y}return Math.abs(o)/2}}class $o{constructor({Cesium:t,viewer:e}){l(this,"Cesium");l(this,"viewer");l(this,"actives",[]);l(this,"measurements",[]);l(this,"htmlLabelPool",null);l(this,"recordHandlers",new Map);l(this,"specifiedClear",!1);l(this,"deleteLabelPool",null);l(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 _e(this.Cesium,this.viewer);break;case"vertical":i=new Xe(this.Cesium,this.viewer);break;case"triangle":i=new Je(this.Cesium,this.viewer);break;case"space":i=new Ze(this.Cesium,this.viewer);break;case"area":i=new xe(this.Cesium,this.viewer);break;case"circle":i=new Qe(this.Cesium,this.viewer);break;case"polyline":i=new De(this.Cesium,this.viewer);break;case"terrainHeight":i=new et(this.Cesium,this.viewer);break;case"coordinate":i=new tt(this.Cesium,this.viewer);break;case"rectangle":i=new it(this.Cesium,this.viewer);break;case"regularPolygon":i=new st(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 h=this.actives.indexOf(n);h>=0&&this.actives.splice(h,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 _e(this.Cesium,this.viewer);break;case"vertical":s=new Xe(this.Cesium,this.viewer);break;case"triangle":s=new Je(this.Cesium,this.viewer);break;case"space":s=new Ze(this.Cesium,this.viewer);break;case"area":s=new xe(this.Cesium,this.viewer);break;case"circle":s=new Qe(this.Cesium,this.viewer);break;case"polyline":s=new De(this.Cesium,this.viewer);break;case"terrainHeight":s=new et(this.Cesium,this.viewer);break;case"coordinate":s=new tt(this.Cesium,this.viewer);break;case"rectangle":s=new it(this.Cesium,this.viewer);break;case"regularPolygon":s=new st(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),h=e.Math.toDegrees(o.latitude),c=o.height||0;this.deleteLabelPool.add({recordId:i.id},{id:n,lon:r,lat:h,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,h=i.reduce((c,d)=>c+d.z,0)/i.length;return new e.Cartesian3(o,r,h)}if(t.type==="coordinate"&&((n=t.data)!=null&&n.lnglat)){const o=t.data.lnglat.lng,r=t.data.lnglat.lat,h=t.data.lnglat.height||0;return e.Cartesian3.fromDegrees(o,r,h)}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 ko{constructor({Cesium:t,viewer:e}){l(this,"Cesium");l(this,"viewer");l(this,"options",null);l(this,"entity",null);l(this,"viewEntities",[]);l(this,"startTime",null);l(this,"stopTime",null);l(this,"isPaused",!1);l(this,"lastTime",null);l(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 h=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);h+=g,c.push(this.Cesium.JulianDate.addSeconds(o,h,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 Oo{constructor({Cesium:t,viewer:e}){l(this,"Cesium");l(this,"viewer");l(this,"entity",null);l(this,"positionProperty",null);l(this,"startTime",null);l(this,"stopTime",null);l(this,"options",null);l(this,"cameraOffset",null);l(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,h=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:h,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}}A.AreaMeasure=xe,A.BufferedHierarchicalAggregator=te,A.CameraRoamTool=ko,A.CircleMeasure=Qe,A.CoordinateMeasure=tt,A.DOM_EVENT_MAP=ot,A.DrawTool=qt,A.EditMode=Bt,A.EntityLayerManager=Do,A.GLTFManage=Lo,A.GLTFManageEventKey=jt,A.HorizontalMeasure=_e,A.HtmlOverlayLabelPool=N,A.MarkerEventBus=nt,A.MarkerEventKey=V,A.MaterialManager=To,A.MeasurementTool=$o,A.PathRoamTool=Oo,A.PolylineDistanceMeasure=De,A.PrimitiveManager=Ao,A.RectangleMeasure=it,A.RegularPolygonMeasure=st,A.SpaceMeasure=Ze,A.TerrainHeightMeasure=et,A.TooltipManager=ce,A.TriangleMeasure=Je,A.VerticalMeasure=Xe,A.convertGeoJsonToEntityData=So,A.getDynamicImgMaterial=Eo,A.getPolylineFlowMaterialProperty=Io,A.getWallMaterial=Mo,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})}));
75
+ ${b.circumference}:${P.toFixed(2)} m
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,p=e*Math.cos(u),g=e*Math.sin(u);r.push(new n.Cartesian2(p,g))}const l=s.projectPointsOntoEllipsoid(r).slice();return l.push(l[0]),l}computeAreaByPlane(t){const e=this.Cesium,i=new e.Cartesian3(t.reduce((r,a)=>r+a.x,0)/t.length,t.reduce((r,a)=>r+a.y,0)/t.length,t.reduce((r,a)=>r+a.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 a=(r+1)%s.length;o+=s[r].x*s[a].y-s[a].x*s[r].y}return Math.abs(o)/2}}class ko{constructor({Cesium:t,viewer:e}){c(this,"Cesium");c(this,"viewer");c(this,"actives",[]);c(this,"measurements",[]);c(this,"htmlLabelPool",null);c(this,"recordHandlers",new Map);c(this,"specifiedClear",!1);c(this,"deleteLabelPool",null);c(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 _e(this.Cesium,this.viewer);break;case"vertical":i=new qe(this.Cesium,this.viewer);break;case"triangle":i=new Ze(this.Cesium,this.viewer);break;case"space":i=new Je(this.Cesium,this.viewer);break;case"area":i=new De(this.Cesium,this.viewer);break;case"circle":i=new Qe(this.Cesium,this.viewer);break;case"polyline":i=new Se(this.Cesium,this.viewer);break;case"terrainHeight":i=new et(this.Cesium,this.viewer);break;case"coordinate":i=new tt(this.Cesium,this.viewer);break;case"rectangle":i=new it(this.Cesium,this.viewer);break;case"regularPolygon":i=new st(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 l;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"),(l=e.onComplete)==null||l.call(e,o);const a=this.actives.indexOf(n);a>=0&&this.actives.splice(a,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 _e(this.Cesium,this.viewer);break;case"vertical":s=new qe(this.Cesium,this.viewer);break;case"triangle":s=new Ze(this.Cesium,this.viewer);break;case"space":s=new Je(this.Cesium,this.viewer);break;case"area":s=new De(this.Cesium,this.viewer);break;case"circle":s=new Qe(this.Cesium,this.viewer);break;case"polyline":s=new Se(this.Cesium,this.viewer);break;case"terrainHeight":s=new et(this.Cesium,this.viewer);break;case"coordinate":s=new tt(this.Cesium,this.viewer);break;case"rectangle":s=new it(this.Cesium,this.viewer);break;case"regularPolygon":s=new st(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),a=e.Math.toDegrees(o.latitude),l=o.height||0;this.deleteLabelPool.add({recordId:i.id},{id:n,lon:r,lat:a,height:l,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((l,d)=>l+d.x,0)/i.length,r=i.reduce((l,d)=>l+d.y,0)/i.length,a=i.reduce((l,d)=>l+d.z,0)/i.length;return new e.Cartesian3(o,r,a)}if(t.type==="coordinate"&&((n=t.data)!=null&&n.lnglat)){const o=t.data.lnglat.lng,r=t.data.lnglat.lat,a=t.data.lnglat.height||0;return e.Cartesian3.fromDegrees(o,r,a)}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 $o{constructor({Cesium:t,viewer:e}){c(this,"Cesium");c(this,"viewer");c(this,"options",null);c(this,"entity",null);c(this,"viewEntities",[]);c(this,"startTime",null);c(this,"stopTime",null);c(this,"isPaused",!1);c(this,"lastTime",null);c(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 p;u.destination?u.destination.x!==void 0?p=new this.Cesium.Cartesian3(u.destination.x,u.destination.y,u.destination.z):p=u.destination:u.lon!==void 0&&u.lat!==void 0&&(p=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 m=this.Cesium.Transforms.headingPitchRollQuaternion(p,g);s.push({position:p,orientation:m})}const o=this.Cesium.JulianDate.now(),r=t.speed||100;let a=0;const l=[];for(let u=0;u<s.length;u++){if(u===0)l.push(o.clone());else{const g=this.Cesium.Cartesian3.distance(s[u-1].position,s[u].position)/Math.max(r,.1);a+=g,l.push(this.Cesium.JulianDate.addSeconds(o,a,new this.Cesium.JulianDate))}i.addSample(l[u],s[u].position),n.addSample(l[u],s[u].orientation)}this.startTime=l[0],this.stopTime=l[l.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,p)=>{const g=this.Cesium.Cartographic.fromCartesian(u.position),m=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:""+(p+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,m],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 Ro{constructor({Cesium:t,viewer:e}){c(this,"Cesium");c(this,"viewer");c(this,"entity",null);c(this,"positionProperty",null);c(this,"startTime",null);c(this,"stopTime",null);c(this,"options",null);c(this,"cameraOffset",null);c(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,a=t.pathColor??this.Cesium.Color.YELLOW,l=t.pathWidth??3,d=t.pointColor??this.Cesium.Color.RED,u=t.pointPixelSize??8,p={availability:new this.Cesium.TimeIntervalCollection([new this.Cesium.TimeInterval({start:this.startTime,stop:this.stopTime})]),position:s,orientation:o,path:r?{material:a,width:l,leadTime:0}:void 0};t.modelUrl?p.model={uri:t.modelUrl,scale:t.modelScale??1,minimumPixelSize:64,runAnimations:t.modelAnimate??!0}:p.point={color:d,pixelSize:u},this.entity=this.viewer.entities.add(p),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}}A.AreaMeasure=De,A.BufferedHierarchicalAggregator=te,A.CameraRoamTool=$o,A.CircleMeasure=Qe,A.CoordinateMeasure=tt,A.DOM_EVENT_MAP=ot,A.DrawTool=Xt,A.EditMode=Bt,A.EntityLayerManager=Do,A.GLTFManage=Lo,A.GLTFManageEventKey=Yt,A.HorizontalMeasure=_e,A.HtmlOverlayLabelPool=N,A.MarkerEventBus=nt,A.MarkerEventKey=V,A.MaterialManager=Io,A.MeasurementTool=ko,A.PathRoamTool=Ro,A.PolylineDistanceMeasure=Se,A.PrimitiveManager=Ao,A.RectangleMeasure=it,A.RegularPolygonMeasure=st,A.SpaceMeasure=Je,A.TerrainHeightMeasure=et,A.TooltipManager=ce,A.TriangleMeasure=Ze,A.VerticalMeasure=qe,A.convertGeoJsonToEntityData=So,A.getDynamicImgMaterial=Eo,A.getPolylineFlowMaterialProperty=xo,A.getWallMaterial=Mo,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})}));
77
77
  //# sourceMappingURL=cesium-core.umd.js.map