@xingm/vmap-cesium-toolbar 0.0.2-alpha.6 → 0.0.2-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(x,T){typeof exports=="object"&&typeof module<"u"?T(exports,require("cesium")):typeof define=="function"&&define.amd?define(["exports","cesium"],T):(x=typeof globalThis<"u"?globalThis:x||self,T(x.VMapCesiumToolbar={},x.Cesium))})(this,(function(x,T){"use strict";function ue(u){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const t in u)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(u,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>u[t]})}}return e.default=u,Object.freeze(e)}const i=ue(T);class E{viewer;scene;entities;offsetHeight=0;originalDepthTestAgainstTerrain=null;originalRequestRenderMode=null;callbacks;tempPositions=[];tempEntities=[];tempLabelEntities=[];finishedPointEntities=[];drawOptions;resolveColor(e){try{return e?e instanceof i.Color?e:i.Color.fromCssColorString(String(e)):i.Color.YELLOW}catch{return i.Color.YELLOW}}applySelectedStyleToEntity(e){try{const n=e._drawOptions?.selected;if(!n)return;if(e._isSelected){this.restoreOriginalStyleForEntity(e),e._isSelected=!1;return}if(e._originalStyle||(e._originalStyle={},e.polyline&&(e._originalStyle.material=e.polyline.material,e._originalStyle.width=e.polyline.width),e.polygon&&(e._originalStyle.material=e.polygon.material,e._originalStyle.outlineColor=e.polygon.outlineColor,e._originalStyle.outlineWidth=e.polygon.outlineWidth),e.rectangle&&(e._originalStyle.material=e.rectangle.material,e._originalStyle.outlineColor=e.rectangle.outlineColor,e._originalStyle.outlineWidth=e.rectangle.outlineWidth),e.ellipse&&(e._originalStyle.material=e.ellipse.material,e._originalStyle.outlineColor=e.ellipse.outlineColor,e._originalStyle.outlineWidth=e.ellipse.outlineWidth)),e.polyline){const r=n.color?this.resolveColor(n.color):i.Color.YELLOW,o=n.width??(e.polyline.width||5)+2;e.polyline.material=new i.ColorMaterialProperty(r),e.polyline.width=new i.ConstantProperty(o)}if(e.polygon){const r=n.color?this.resolveColor(n.color):i.Color.YELLOW;e.polygon.material=new i.ColorMaterialProperty(r.withAlpha(.5)),e.polygon.outlineColor=new i.ConstantProperty(n.outlineColor?this.resolveColor(n.outlineColor):this.resolveColor("#ffffff")),e.polygon.outlineWidth=new i.ConstantProperty(n.outlineWidth??(e.polygon.outlineWidth||2))}if(e.rectangle){const r=n.color?this.resolveColor(n.color):i.Color.YELLOW;e.rectangle.material=new i.ColorMaterialProperty(r.withAlpha(.5)),e.rectangle.outlineColor=new i.ConstantProperty(n.outlineColor?this.resolveColor(n.outlineColor):this.resolveColor("#ffffff")),e.rectangle.outlineWidth=new i.ConstantProperty(n.outlineWidth??(e.rectangle.outlineWidth||2))}if(e.ellipse){const r=n.color?this.resolveColor(n.color):i.Color.YELLOW;e.ellipse.material=new i.ColorMaterialProperty(r.withAlpha(.5)),e.ellipse.outlineColor=new i.ConstantProperty(n.outlineColor?this.resolveColor(n.outlineColor):this.resolveColor("#ffffff")),e.ellipse.outlineWidth=new i.ConstantProperty(n.outlineWidth??(e.ellipse.outlineWidth||2))}e._isSelected=!0}catch(t){console.warn("applySelectedStyleToEntity failed",t)}}restoreOriginalStyleForEntity(e){try{const t=e._originalStyle;if(!t)return;e.polyline&&t.material&&(e.polyline.material=t.material,e.polyline.width=t.width??e.polyline.width),e.polygon&&t.material&&(e.polygon.material=t.material,e.polygon.outlineColor=t.outlineColor??e.polygon.outlineColor,e.polygon.outlineWidth=t.outlineWidth??e.polygon.outlineWidth),e.rectangle&&t.material&&(e.rectangle.material=t.material,e.rectangle.outlineColor=t.outlineColor??e.rectangle.outlineColor,e.rectangle.outlineWidth=t.outlineWidth??e.rectangle.outlineWidth),e.ellipse&&t.material&&(e.ellipse.material=t.material,e.ellipse.outlineColor=t.outlineColor??e.ellipse.outlineColor,e.ellipse.outlineWidth=t.outlineWidth??e.ellipse.outlineWidth),e._isSelected=!1}catch(t){console.warn("restoreOriginalStyleForEntity failed",t)}}constructor(e,t={}){this.viewer=e,this.scene=e.scene,this.entities=e.entities,this.callbacks=t,this.updateOffsetHeight()}updateOffsetHeight(){this.scene.mode===i.SceneMode.SCENE3D?this.offsetHeight=1:this.offsetHeight=0}pickGlobePosition(e){const t=this.viewer.camera.getPickRay(e);if(t&&this.scene.mode===i.SceneMode.SCENE3D&&this.scene.globe.tilesLoaded){const r=this.scene.globe.pick(t,this.scene);if(i.defined(r)&&Number.isFinite(r.x)&&Number.isFinite(r.y)&&Number.isFinite(r.z))return r}const n=this.viewer.camera.pickEllipsoid(e,this.scene.globe.ellipsoid);return n&&Number.isFinite(n.x)&&Number.isFinite(n.y)&&Number.isFinite(n.z)?n:null}enableContinuousRenderingIfNeeded(){try{this.scene.requestRenderMode!==void 0&&(this.originalRequestRenderMode===null&&(this.originalRequestRenderMode=!!this.scene.requestRenderMode),this.scene.requestRenderMode&&(this.scene.requestRenderMode=!1,typeof this.scene.requestRender=="function"&&this.scene.requestRender()))}catch(e){console.warn("enableContinuousRenderingIfNeeded failed",e)}}restoreRequestRenderModeIfNeeded(){try{this.originalRequestRenderMode!==null&&this.originalRequestRenderMode===!0&&(this.scene.requestRenderMode=!0,typeof this.scene.requestRender=="function"&&this.scene.requestRender())}catch(e){console.warn("restoreRequestRenderModeIfNeeded failed",e)}finally{this.originalRequestRenderMode=null}}addPoint(e){this.tempPositions.push(e.clone());const t=i.Cartographic.fromCartesian(e),n=i.Cartesian3.fromRadians(t.longitude,t.latitude,(t.height||0)+this.offsetHeight),r=this.entities.add({position:n,point:{pixelSize:8,color:i.Color.RED,outlineColor:i.Color.WHITE,outlineWidth:3,heightReference:i.HeightReference.NONE,scaleByDistance:new i.NearFarScalar(150,1,15e6,.5),disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempEntities.push(r)}createTotalLengthBillboardImage(e){const r="bold 16px 'Microsoft YaHei', 'PingFang SC', sans-serif",o=document.createElement("canvas"),s=o.getContext("2d");if(!s)return o.width=1,o.height=1,o;s.font=r;const a=s.measureText(e).width,c=20;return o.width=Math.ceil(a+24),o.height=Math.ceil(c+12),s.font=r,s.textBaseline="middle",s.textAlign="center",s.fillStyle="rgba(0, 0, 0, 0.8)",s.fillRect(0,0,o.width,o.height),s.fillStyle="#FFFFFF",s.fillText(e,o.width/2,o.height/2),o}createSegmentLengthBillboardImage(e){return this.createTotalLengthBillboardImage(e)}clearTempEntities(){this.tempEntities.forEach(e=>{e&&this.entities.remove(e)}),this.tempEntities=[],this.tempLabelEntities.forEach(e=>{e&&this.entities.remove(e)}),this.tempLabelEntities=[]}}function N(u){return!!u&&Number.isFinite(u.x)&&Number.isFinite(u.y)&&Number.isFinite(u.z)}function L(u){return!isFinite(u)||isNaN(u)?"0.00 m":u>=1e3?`${(u/1e3).toFixed(2)} km`:`${u.toFixed(2)} m`}function z(u){return!isFinite(u)||isNaN(u)?"0.00 m²":u>=1?`${u.toFixed(2)} km²`:`${(u*1e6).toFixed(2)} m²`}function F(u,e){const t=i.Cartographic.fromCartesian(u),n=i.Cartographic.fromCartesian(e),r=Math.min(t.longitude,n.longitude),o=Math.max(t.longitude,n.longitude),s=Math.min(t.latitude,n.latitude),l=Math.max(t.latitude,n.latitude);return new i.Rectangle(r,s,o,l)}function fe(u){const e=u.west,t=u.south,n=u.east,r=u.north,o=i.Cartesian3.distance(i.Cartesian3.fromRadians(e,t),i.Cartesian3.fromRadians(n,t)),s=i.Cartesian3.distance(i.Cartesian3.fromRadians(e,t),i.Cartesian3.fromRadians(e,r));return o*s/1e6}function W(u,e=i.Ellipsoid.WGS84){const t=u.filter(o=>N(o));if(t.length<3)return 0;let n=0;const r=t.length;for(let o=0;o<r;o++){const s=t[o],l=t[(o+1)%r];if(!N(s)||!N(l))return 0;const a=e.cartesianToCartographic(s),c=e.cartesianToCartographic(l);if(!a||!c||!Number.isFinite(a.longitude)||!Number.isFinite(a.latitude)||!Number.isFinite(c.longitude)||!Number.isFinite(c.latitude))return 0;n+=(c.longitude-a.longitude)*(2+Math.sin(a.latitude)+Math.sin(c.latitude))}return n=Math.abs(n*6378137*6378137/2),n/1e6}function ge(u){const e=u.filter(o=>N(o));if(e.length===0)return i.Cartesian3.ZERO;let t=0,n=0,r=0;for(let o=0;o<e.length;o++)t+=e[o].x,n+=e[o].y,r+=e[o].z;return new i.Cartesian3(t/e.length,n/e.length,r/e.length)}class S extends E{currentLineEntity=null;currentSegmentLabels=[];currentTotalLabel=null;currentLinePositions=[];isTotalLabelWarmedUp=!1;startDrawing(e){this.drawOptions=e,this.enableContinuousRenderingIfNeeded(),this.warmupTotalLengthLabel(),this.clearTempEntities(),this.tempPositions=[],this.currentLineEntity=null,this.currentSegmentLabels=[],this.currentTotalLabel=null,this.currentLinePositions=[],this.originalDepthTestAgainstTerrain===null&&(this.originalDepthTestAgainstTerrain=this.scene.globe.depthTestAgainstTerrain),this.scene.globe.depthTestAgainstTerrain=!1,this.callbacks.onDrawStart&&this.callbacks.onDrawStart()}updateDrawingEntity(e){const t=[...this.tempPositions];if(e&&t.push(e),t.length<2){this.clearLineEntity();return}const n=this.offsetHeight>0?t.map(s=>{const l=i.Cartographic.fromCartesian(s);return i.Cartesian3.fromRadians(l.longitude,l.latitude,(l.height||0)+this.offsetHeight)}):t,r=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):i.Color.YELLOW,o=this.drawOptions?.strokeWidth??5;this.currentLineEntity?(this.currentLineEntity.polyline.positions instanceof i.CallbackProperty?(this.currentLinePositions.length=0,this.currentLinePositions.push(...n)):(this.currentLinePositions=[...n],this.currentLineEntity.polyline.positions=new i.CallbackProperty(()=>this.currentLinePositions,!1)),this.currentLineEntity.polyline.material=new i.ColorMaterialProperty(r),this.currentLineEntity.polyline.width=new i.ConstantProperty(o)):(this.currentLinePositions=[...n],this.currentLineEntity=this.entities.add({polyline:{positions:new i.CallbackProperty(()=>this.currentLinePositions,!1),width:o,material:r,clampToGround:this.offsetHeight===0}}),this.tempEntities.push(this.currentLineEntity)),this.updateSegmentLabels(t),this.updateTotalLabel()}finishDrawing(){if(this.tempPositions.length<2)return this.restoreRequestRenderModeIfNeeded(),null;const e=this.tempPositions.filter(a=>N(a));if(e.length<2)return this.restoreRequestRenderModeIfNeeded(),null;const t=e.map(a=>{const c=i.Cartographic.fromCartesian(a);return i.Cartesian3.fromRadians(c.longitude,c.latitude,c.height||0)});let n=null,r=0;const o=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):i.Color.YELLOW,s=this.drawOptions?.strokeWidth??5;if(this.offsetHeight>0){const a=t.map(c=>{const d=i.Cartographic.fromCartesian(c);return i.Cartesian3.fromRadians(d.longitude,d.latitude,(d.height||0)+this.offsetHeight)});n=this.entities.add({name:"绘制的线",polyline:{positions:a,width:s,material:o,clampToGround:!1}}),n._groundPositions=t}else n=this.entities.add({name:"绘制的线",polyline:{positions:t,width:s,material:o,clampToGround:!0}}),n._groundPositions=t;n&&(n._drawOptions=this.drawOptions,n._drawType=this.getDrawType(),this.drawOptions?.onClick&&(n._onClick=this.drawOptions.onClick));for(let a=1;a<t.length;a++)r+=i.Cartesian3.distance(t[a-1],t[a]);this.tempLabelEntities.forEach(a=>{}),this.tempEntities.forEach(a=>{a&&this.entities.remove(a)}),this.tempEntities=[],this.tempPositions=[],this.currentLineEntity=null,this.currentSegmentLabels=[],this.currentTotalLabel=null,this.originalDepthTestAgainstTerrain!==null&&(this.scene.globe.depthTestAgainstTerrain=this.originalDepthTestAgainstTerrain,this.originalDepthTestAgainstTerrain=null);const l={entity:n,type:"line",positions:t,distance:r};return this.callbacks.onMeasureComplete&&this.callbacks.onMeasureComplete(l),this.restoreRequestRenderModeIfNeeded(),this.callbacks.onDrawEnd&&this.callbacks.onDrawEnd(n),l}getDrawType(){return"line"}clearLineEntity(){if(this.currentLineEntity){this.entities.remove(this.currentLineEntity);const e=this.tempEntities.indexOf(this.currentLineEntity);e>-1&&this.tempEntities.splice(e,1),this.currentLineEntity=null,this.currentLinePositions=[]}if(this.currentSegmentLabels.forEach(e=>{if(e){this.entities.remove(e);const t=this.tempLabelEntities.indexOf(e);t>-1&&this.tempLabelEntities.splice(t,1)}}),this.currentSegmentLabels=[],this.currentTotalLabel){this.entities.remove(this.currentTotalLabel);const e=this.tempLabelEntities.indexOf(this.currentTotalLabel);e>-1&&this.tempLabelEntities.splice(e,1),this.currentTotalLabel=null}}updateSegmentLabels(e){const t=e.length-1,n=this.currentSegmentLabels.length;if(n>t){for(let r=t;r<n;r++){const o=this.currentSegmentLabels[r];if(o){this.entities.remove(o);const s=this.tempLabelEntities.indexOf(o);s>-1&&this.tempLabelEntities.splice(s,1)}}this.currentSegmentLabels=this.currentSegmentLabels.slice(0,t)}for(let r=0;r<t;r++){const o=e[r],s=e[r+1],l=i.Cartesian3.distance(o,s);if(l>5){const a=i.Cartesian3.midpoint(o,s,new i.Cartesian3),c=i.Cartographic.fromCartesian(a),d=i.Cartesian3.fromRadians(c.longitude,c.latitude,c.height||0);let h=a;this.offsetHeight>0&&(h=i.Cartesian3.fromRadians(c.longitude,c.latitude,(c.height||0)+this.offsetHeight));const f=r%2===0?-25:25,m=L(l);if(r<this.currentSegmentLabels.length&&this.currentSegmentLabels[r].billboard){const p=this.currentSegmentLabels[r];if(p.position=new i.ConstantPositionProperty(h),p.billboard.pixelOffset=new i.ConstantProperty(new i.Cartesian2(0,f)),p._groundPosition=d,p._segmentText!==m){const g=this.createSegmentLengthBillboardImage(m);p.billboard.image=new i.ConstantProperty(g),p._segmentText=m}}else{const p=this.createSegmentLengthBillboardImage(m),w=this.entities.add({position:h,billboard:{image:p,pixelOffset:new i.ConstantProperty(new i.Cartesian2(0,f)),heightReference:new i.ConstantProperty(this.offsetHeight>0?i.HeightReference.RELATIVE_TO_GROUND:i.HeightReference.NONE),verticalOrigin:new i.ConstantProperty(i.VerticalOrigin.CENTER),horizontalOrigin:new i.ConstantProperty(i.HorizontalOrigin.CENTER),scale:new i.ConstantProperty(1),disableDepthTestDistance:new i.ConstantProperty(Number.POSITIVE_INFINITY)}});w._segmentText=m,w._groundPosition=d,this.currentSegmentLabels.push(w),this.tempLabelEntities.push(w)}}else if(r<this.currentSegmentLabels.length){const a=this.currentSegmentLabels[r];if(a){this.entities.remove(a);const c=this.tempLabelEntities.indexOf(a);c>-1&&this.tempLabelEntities.splice(c,1)}this.currentSegmentLabels.splice(r,1),r--}}}updateTotalLabel(){if(this.tempPositions.length>1){let e=0;for(let c=1;c<this.tempPositions.length;c++)e+=i.Cartesian3.distance(this.tempPositions[c-1],this.tempPositions[c]);const t=this.tempPositions[this.tempPositions.length-1],n=i.Cartographic.fromCartesian(t),r=i.Cartesian3.fromRadians(n.longitude,n.latitude,n.height||0);let o=r;this.offsetHeight>0&&(o=i.Cartesian3.fromRadians(n.longitude,n.latitude,(n.height||0)+this.offsetHeight));const l=`总长: ${L(e)}`,a=this.createTotalLengthBillboardImage(l);if(this.currentTotalLabel&&this.currentTotalLabel.billboard)this.currentTotalLabel.position=new i.ConstantPositionProperty(o),this.currentTotalLabel.billboard.image=new i.ConstantProperty(a),this.currentTotalLabel._groundPosition=r;else{const c=this.entities.add({position:o,billboard:{image:a,pixelOffset:new i.ConstantProperty(new i.Cartesian2(0,-35)),heightReference:new i.ConstantProperty(this.offsetHeight>0?i.HeightReference.RELATIVE_TO_GROUND:i.HeightReference.NONE),verticalOrigin:new i.ConstantProperty(i.VerticalOrigin.BOTTOM),horizontalOrigin:new i.ConstantProperty(i.HorizontalOrigin.CENTER),scale:new i.ConstantProperty(1),disableDepthTestDistance:new i.ConstantProperty(Number.POSITIVE_INFINITY)}});this.currentTotalLabel=c,this.currentTotalLabel._groundPosition=r,this.tempLabelEntities.push(c)}}else if(this.currentTotalLabel){this.entities.remove(this.currentTotalLabel);const e=this.tempLabelEntities.indexOf(this.currentTotalLabel);e>-1&&this.tempLabelEntities.splice(e,1),this.currentTotalLabel=null}}warmupTotalLengthLabel(){if(this.isTotalLabelWarmedUp)return;let e;try{e=this.viewer.camera.positionCartographic.clone()}catch{e=i.Cartographic.fromDegrees(120.2052342,30.2489634,this.offsetHeight)}const t=i.Cartesian3.fromRadians(e.longitude,e.latitude,(e.height||0)+this.offsetHeight),n=this.entities.add({position:t,label:{text:"总长: 0.00 m",font:"bold 16px 'Microsoft YaHei', 'PingFang SC', sans-serif",fillColor:i.Color.WHITE,outlineColor:i.Color.BLACK,outlineWidth:2,style:i.LabelStyle.FILL_AND_OUTLINE,pixelOffset:new i.Cartesian2(0,-35),heightReference:i.HeightReference.RELATIVE_TO_GROUND,scale:1,showBackground:!0,backgroundPadding:new i.Cartesian2(6,3),backgroundColor:i.Color.BLACK.withAlpha(.8),disableDepthTestDistance:Number.POSITIVE_INFINITY,verticalOrigin:i.VerticalOrigin.BOTTOM,horizontalOrigin:i.HorizontalOrigin.CENTER,show:!1}});this.isTotalLabelWarmedUp=!0,requestAnimationFrame(()=>{try{this.entities.remove(n)}catch{}})}}class X extends E{currentPolygonEntity=null;currentBorderEntity=null;startDrawing(e){this.drawOptions=e,this.enableContinuousRenderingIfNeeded(),this.clearTempEntities(),this.tempPositions=[],this.currentPolygonEntity=null,this.currentBorderEntity=null,this.originalDepthTestAgainstTerrain===null&&(this.originalDepthTestAgainstTerrain=this.scene.globe.depthTestAgainstTerrain),this.scene.globe.depthTestAgainstTerrain=!1,this.callbacks.onDrawStart&&this.callbacks.onDrawStart()}updateDrawingEntity(e){if(this.scene.mode===i.SceneMode.SCENE3D&&!this.scene.globe.tilesLoaded)return;const n=this.tempPositions.filter(o=>N(o)),r=e&&N(e)&&n.length>=2?[...n,e]:n;if(r.length>=3){const o=r.map(f=>i.Cartographic.fromCartesian(f)).filter(f=>f&&Number.isFinite(f.longitude)&&Number.isFinite(f.latitude));if(o.length<3){if(this.currentPolygonEntity){this.entities.remove(this.currentPolygonEntity);const f=this.tempEntities.indexOf(this.currentPolygonEntity);f>-1&&this.tempEntities.splice(f,1),this.currentPolygonEntity=null}if(this.currentBorderEntity){this.entities.remove(this.currentBorderEntity);const f=this.tempEntities.indexOf(this.currentBorderEntity);f>-1&&this.tempEntities.splice(f,1),this.currentBorderEntity=null}return}const s=o.map(f=>{const m=f.height||0,p=this.offsetHeight>0?this.offsetHeight:.1;return i.Cartesian3.fromRadians(f.longitude,f.latitude,m+p)}),l=i.HeightReference.NONE,a=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):i.Color.LIGHTGREEN,c=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):i.Color.DARKGREEN,d=this.drawOptions?.strokeWidth??this.drawOptions?.outlineWidth??2;this.currentPolygonEntity?(this.currentPolygonEntity.polygon.hierarchy=new i.ConstantProperty(new i.PolygonHierarchy(s)),this.currentPolygonEntity.polygon.heightReference=new i.ConstantProperty(l),this.currentPolygonEntity.polygon.material=new i.ColorMaterialProperty(a),this.currentPolygonEntity.polygon.outline=new i.ConstantProperty(!1)):(this.currentPolygonEntity=this.entities.add({polygon:{hierarchy:new i.ConstantProperty(new i.PolygonHierarchy(s)),material:new i.ColorMaterialProperty(a),outline:!1,heightReference:l}}),this.tempEntities.push(this.currentPolygonEntity));const h=s.slice();h.length>=2&&h.push(s[0]),this.currentBorderEntity&&this.currentBorderEntity.polyline?(this.currentBorderEntity.polyline.positions=new i.ConstantProperty(h),this.currentBorderEntity.polyline.width=new i.ConstantProperty(d),this.currentBorderEntity.polyline.material=new i.ColorMaterialProperty(c),this.currentBorderEntity.polyline.clampToGround=new i.ConstantProperty(!1)):(this.currentBorderEntity=this.entities.add({polyline:{positions:new i.ConstantProperty(h),width:d,material:new i.ColorMaterialProperty(c),clampToGround:!1}}),this.tempEntities.push(this.currentBorderEntity))}else{if(this.currentPolygonEntity){this.entities.remove(this.currentPolygonEntity);const o=this.tempEntities.indexOf(this.currentPolygonEntity);o>-1&&this.tempEntities.splice(o,1),this.currentPolygonEntity=null}if(this.currentBorderEntity){this.entities.remove(this.currentBorderEntity);const o=this.tempEntities.indexOf(this.currentBorderEntity);o>-1&&this.tempEntities.splice(o,1),this.currentBorderEntity=null}}}finishDrawing(){const e=this.tempPositions.filter(h=>N(h));if(e.length<3)return this.restoreRequestRenderModeIfNeeded(),null;const t=e.map(h=>i.Cartographic.fromCartesian(h)).filter(h=>h&&Number.isFinite(h.longitude)&&Number.isFinite(h.latitude));if(t.length<3)return this.restoreRequestRenderModeIfNeeded(),null;const n=t.map(h=>i.Cartesian3.fromRadians(h.longitude,h.latitude,h.height||0));let r=null,o=null;const s=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):i.Color.LIGHTGREEN,l=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):i.Color.DARKGREEN,a=this.drawOptions?.strokeWidth??this.drawOptions?.outlineWidth??2;if(this.offsetHeight>0){const h=n.map(m=>{const p=i.Cartographic.fromCartesian(m);return i.Cartesian3.fromRadians(p.longitude,p.latitude,(p.height||0)+this.offsetHeight)});r=this.entities.add({name:"绘制的多边形区域",polygon:{hierarchy:new i.PolygonHierarchy(h),material:new i.ColorMaterialProperty(s),outline:!1,heightReference:i.HeightReference.NONE}});const f=h.slice();f.length>=2&&f.push(h[0]),o=this.entities.add({polyline:{positions:f,width:a,material:new i.ColorMaterialProperty(l),clampToGround:!1}}),r._groundPositions=n,r&&(r._drawOptions=this.drawOptions,r._drawType=this.getDrawType(),this.drawOptions?.onClick&&(r._onClick=this.drawOptions.onClick))}else{r=this.entities.add({name:"绘制的多边形区域",polygon:{hierarchy:new i.PolygonHierarchy(n),material:new i.ColorMaterialProperty(s),outline:!1,heightReference:i.HeightReference.NONE}});const h=n.slice();h.length>=2&&h.push(n[0]),o=this.entities.add({polyline:{positions:h,width:a,material:new i.ColorMaterialProperty(l),clampToGround:!0}}),r._groundPositions=n,r&&(r._drawOptions=this.drawOptions,r._drawType=this.getDrawType(),this.drawOptions?.onClick&&(r._onClick=this.drawOptions.onClick),o&&(r._borderEntity=o))}const c=W(n,this.scene.globe.ellipsoid);if(c>0){const h=ge(n),f=i.Cartographic.fromCartesian(h),m=i.Cartesian3.fromRadians(f.longitude,f.latitude,f.height||0);let p=m;this.offsetHeight>0&&(p=i.Cartesian3.fromRadians(f.longitude,f.latitude,(f.height||0)+this.offsetHeight));const w=`面积: ${z(c)}`,g=this.createTotalLengthBillboardImage(w),b=this.entities.add({position:p,billboard:{image:g,pixelOffset:new i.ConstantProperty(new i.Cartesian2(0,-25)),heightReference:new i.ConstantProperty(this.offsetHeight>0?i.HeightReference.RELATIVE_TO_GROUND:i.HeightReference.NONE),verticalOrigin:new i.ConstantProperty(i.VerticalOrigin.BOTTOM),horizontalOrigin:new i.ConstantProperty(i.HorizontalOrigin.CENTER),scale:new i.ConstantProperty(1),disableDepthTestDistance:new i.ConstantProperty(Number.POSITIVE_INFINITY)}});b._groundPosition=m,this.tempLabelEntities.push(b)}this.tempEntities.forEach(h=>{h&&this.entities.remove(h)}),this.tempEntities=[],this.tempPositions=[],this.currentPolygonEntity=null,this.currentBorderEntity=null,this.originalDepthTestAgainstTerrain!==null&&(this.scene.globe.depthTestAgainstTerrain=this.originalDepthTestAgainstTerrain,this.originalDepthTestAgainstTerrain=null);const d={entity:r,type:"polygon",positions:n,areaKm2:W(n,this.scene.globe.ellipsoid)};return this.callbacks.onMeasureComplete&&this.callbacks.onMeasureComplete(d),this.restoreRequestRenderModeIfNeeded(),this.callbacks.onDrawEnd&&this.callbacks.onDrawEnd(r),d}getDrawType(){return"polygon"}}class B extends E{currentRectangleEntity=null;startDrawing(e){this.drawOptions=e,this.enableContinuousRenderingIfNeeded(),this.clearTempEntities(),this.tempPositions=[],this.currentRectangleEntity=null,this.originalDepthTestAgainstTerrain===null&&(this.originalDepthTestAgainstTerrain=this.scene.globe.depthTestAgainstTerrain),this.scene.globe.depthTestAgainstTerrain=!1,this.callbacks.onDrawStart&&this.callbacks.onDrawStart()}updateDrawingEntity(e){const t=[...this.tempPositions];if(e&&t.push(e),t.length<2){if(this.currentRectangleEntity){this.entities.remove(this.currentRectangleEntity);const a=this.tempEntities.indexOf(this.currentRectangleEntity);a>-1&&this.tempEntities.splice(a,1),this.currentRectangleEntity=null}return}const n=F(t[0],t[1]),r=i.HeightReference.NONE,o=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):i.Color.GREEN,s=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):i.Color.DARKGREEN,l=this.drawOptions?.strokeWidth??this.drawOptions?.outlineWidth??1;this.currentRectangleEntity?(this.currentRectangleEntity.rectangle.coordinates=new i.ConstantProperty(n),this.currentRectangleEntity.rectangle.heightReference=new i.ConstantProperty(r),this.currentRectangleEntity.rectangle.extrudedHeight=this.offsetHeight>0?new i.ConstantProperty(this.offsetHeight):void 0,this.currentRectangleEntity.rectangle.material=new i.ColorMaterialProperty(o.withAlpha(.5)),this.currentRectangleEntity.rectangle.outlineColor=new i.ConstantProperty(s),this.currentRectangleEntity.rectangle.outlineWidth=new i.ConstantProperty(l)):(this.currentRectangleEntity=this.entities.add({rectangle:{coordinates:n,material:o.withAlpha(.5),heightReference:r,extrudedHeight:this.offsetHeight>0?this.offsetHeight:void 0,outline:!0,outlineColor:s,outlineWidth:l}}),this.tempEntities.push(this.currentRectangleEntity))}finishDrawing(){if(this.tempPositions.length<2)return this.restoreRequestRenderModeIfNeeded(),null;const e=this.tempPositions.filter(h=>N(h));if(e.length<2)return this.restoreRequestRenderModeIfNeeded(),null;const t=e.map(h=>{const f=i.Cartographic.fromCartesian(h);return i.Cartesian3.fromRadians(f.longitude,f.latitude,f.height||0)}),n=F(t[0],t[1]);let r=null;const o=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):i.Color.GREEN,s=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):i.Color.DARKGREEN,l=this.drawOptions?.strokeWidth??this.drawOptions?.outlineWidth??1;this.offsetHeight>0?(r=this.entities.add({name:"绘制的矩形",rectangle:{coordinates:n,material:o.withAlpha(.5),heightReference:i.HeightReference.NONE,extrudedHeight:this.offsetHeight,outline:!0,outlineColor:s,outlineWidth:l}}),r._groundRectangle=n):(r=this.entities.add({name:"绘制的矩形",rectangle:{coordinates:n,material:o.withAlpha(.5),heightReference:i.HeightReference.NONE,outline:!0,outlineColor:s,outlineWidth:l}}),r._groundRectangle=n),r&&(r._drawOptions=this.drawOptions,r._drawType=this.getDrawType(),this.drawOptions?.onClick&&(r._onClick=this.drawOptions.onClick));const a=fe(n);if(a>0){const h=i.Rectangle.center(n),f=i.Cartesian3.fromRadians(h.longitude,h.latitude,0);let m=f;this.offsetHeight>0&&(m=i.Cartesian3.fromRadians(h.longitude,h.latitude,this.offsetHeight));const p=`面积: ${z(a)}`,w=this.createTotalLengthBillboardImage(p),g=this.entities.add({position:m,billboard:{image:w,pixelOffset:new i.ConstantProperty(new i.Cartesian2(0,-25)),heightReference:new i.ConstantProperty(this.offsetHeight>0?i.HeightReference.RELATIVE_TO_GROUND:i.HeightReference.NONE),verticalOrigin:new i.ConstantProperty(i.VerticalOrigin.BOTTOM),horizontalOrigin:new i.ConstantProperty(i.HorizontalOrigin.CENTER),scale:new i.ConstantProperty(1),disableDepthTestDistance:new i.ConstantProperty(Number.POSITIVE_INFINITY)}});g._groundPosition=f,this.tempLabelEntities.push(g)}this.tempEntities.forEach(h=>{h&&this.entities.remove(h)}),this.tempEntities=[],this.tempPositions=[],this.currentRectangleEntity=null,this.originalDepthTestAgainstTerrain!==null&&(this.scene.globe.depthTestAgainstTerrain=this.originalDepthTestAgainstTerrain,this.originalDepthTestAgainstTerrain=null);const c=i.Rectangle.subsample(n,this.scene.globe.ellipsoid),d={entity:r,type:"rectangle",positions:c,areaKm2:a};return this.callbacks.onMeasureComplete&&this.callbacks.onMeasureComplete(d),this.restoreRequestRenderModeIfNeeded(),this.callbacks.onDrawEnd&&this.callbacks.onDrawEnd(r),d}getDrawType(){return"rectangle"}}class U extends E{currentCircleEntity=null;currentBorderEntity=null;centerPosition=null;startDrawing(e){this.drawOptions=e,this.enableContinuousRenderingIfNeeded(),this.clearTempEntities(),this.tempPositions=[],this.currentCircleEntity=null,this.currentBorderEntity=null,this.centerPosition=null,this.originalDepthTestAgainstTerrain===null&&(this.originalDepthTestAgainstTerrain=this.scene.globe.depthTestAgainstTerrain),this.scene.globe.depthTestAgainstTerrain=!1,this.callbacks.onDrawStart&&this.callbacks.onDrawStart()}updateDrawingEntity(e){if(this.tempPositions.length===0){if(this.currentCircleEntity){this.entities.remove(this.currentCircleEntity);const h=this.tempEntities.indexOf(this.currentCircleEntity);h>-1&&this.tempEntities.splice(h,1),this.currentCircleEntity=null}return}if(!e)return;const t=this.tempPositions[0],n=i.Cartesian3.distance(t,e);if(n<1)return;const r=i.Cartographic.fromCartesian(t),o=i.Cartesian3.fromRadians(r.longitude,r.latitude,r.height||0);let s=o;this.offsetHeight>0&&(s=i.Cartesian3.fromRadians(r.longitude,r.latitude,(r.height||0)+this.offsetHeight));const l=n/this.scene.globe.ellipsoid.maximumRadius;new i.Rectangle(r.longitude-l,r.latitude-l,r.longitude+l,r.latitude+l);const a=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):i.Color.BLUE,c=this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):i.Color.BLUE,d=this.drawOptions?.outlineWidth??2;if(this.currentCircleEntity?(this.currentCircleEntity.ellipse.semiMajorAxis=new i.ConstantProperty(n),this.currentCircleEntity.ellipse.semiMinorAxis=new i.ConstantProperty(n),this.currentCircleEntity.position=new i.ConstantPositionProperty(s),this.currentCircleEntity.ellipse.material=new i.ColorMaterialProperty(a.withAlpha(.3)),this.currentCircleEntity.ellipse.outline=new i.ConstantProperty(d<=1),this.currentCircleEntity.ellipse.outlineColor=new i.ConstantProperty(c),this.currentCircleEntity.ellipse.outlineWidth=new i.ConstantProperty(d<=1?d:1)):(this.currentCircleEntity=this.entities.add({position:s,ellipse:{semiMajorAxis:n,semiMinorAxis:n,material:a.withAlpha(.3),outline:d<=1,outlineColor:c,outlineWidth:d<=1?d:1,heightReference:i.HeightReference.NONE}}),this.tempEntities.push(this.currentCircleEntity)),d>1){const h=i.Cartographic.fromCartesian(s),f=h.height||0,m=.1,p=n,w=this.generateCirclePositions(h,p,f+m),g=[...w,w[0]];this.currentBorderEntity&&this.currentBorderEntity.polyline?(this.currentBorderEntity.polyline.positions=new i.ConstantProperty(g),this.currentBorderEntity.polyline.material=new i.ColorMaterialProperty(c),this.currentBorderEntity.polyline.width=new i.ConstantProperty(d),this.currentBorderEntity.polyline.clampToGround=new i.ConstantProperty(!1)):(this.currentBorderEntity=this.entities.add({polyline:{positions:g,material:new i.ColorMaterialProperty(c),width:d,clampToGround:!1}}),this.tempEntities.push(this.currentBorderEntity))}else if(this.currentBorderEntity){this.entities.remove(this.currentBorderEntity);const h=this.tempEntities.indexOf(this.currentBorderEntity);h>-1&&this.tempEntities.splice(h,1),this.currentBorderEntity=null}this.centerPosition=o}finishDrawing(){if(this.tempPositions.length<1)return this.restoreRequestRenderModeIfNeeded(),null;const e=this.tempPositions[0],t=i.Cartographic.fromCartesian(e),n=i.Cartesian3.fromRadians(t.longitude,t.latitude,t.height||0);let r=0;if(this.tempPositions.length>=2)r=i.Cartesian3.distance(e,this.tempPositions[1]);else if(this.currentCircleEntity){const w=this.currentCircleEntity.ellipse;if(w){const g=w.semiMajorAxis?.getValue(i.JulianDate.now());r=typeof g=="number"?g:0}}if(r<1)return this.restoreRequestRenderModeIfNeeded(),null;let o=null,s=n;this.offsetHeight>0&&(s=i.Cartesian3.fromRadians(t.longitude,t.latitude,(t.height||0)+this.offsetHeight));const l=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):i.Color.BLUE,a=this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):i.Color.BLUE,c=this.drawOptions?.outlineWidth??2;if(c>1){o=this.entities.add({name:"绘制的圆",position:s,ellipse:{semiMajorAxis:r,semiMinorAxis:r,material:l.withAlpha(.3),outline:!1,heightReference:i.HeightReference.NONE}});const w=i.Cartographic.fromCartesian(s),g=w.height||0,b=.1,y=r,G=this.generateCirclePositions(w,y,g+b),C=[...G,G[0]],v=this.entities.add({name:"绘制的圆-边框",polyline:{positions:C,material:new i.ColorMaterialProperty(a),width:c,clampToGround:!(this.offsetHeight>0)}});o._borderEntity=v}else o=this.entities.add({name:"绘制的圆",position:s,ellipse:{semiMajorAxis:r,semiMinorAxis:r,material:l.withAlpha(.3),outline:!0,outlineColor:a,outlineWidth:c,heightReference:i.HeightReference.NONE}});o._groundPosition=n,o._radius=r,o&&(o._drawOptions=this.drawOptions,o._drawType=this.getDrawType(),this.drawOptions?.onClick&&(o._onClick=this.drawOptions.onClick));const d=Math.PI*r*r/1e6;if(d>0){const w=`面积: ${z(d)}`,g=this.createTotalLengthBillboardImage(w),b=this.entities.add({position:s,billboard:{image:g,pixelOffset:new i.ConstantProperty(new i.Cartesian2(0,-25)),heightReference:new i.ConstantProperty(this.offsetHeight>0?i.HeightReference.RELATIVE_TO_GROUND:i.HeightReference.NONE),verticalOrigin:new i.ConstantProperty(i.VerticalOrigin.BOTTOM),horizontalOrigin:new i.ConstantProperty(i.HorizontalOrigin.CENTER),scale:new i.ConstantProperty(1),disableDepthTestDistance:new i.ConstantProperty(Number.POSITIVE_INFINITY)}});b._groundPosition=n,this.tempLabelEntities.push(b)}this.tempEntities.forEach((w,g)=>{w&&this.entities.remove(w)}),this.tempEntities=[],this.tempPositions=[],this.currentCircleEntity=null,this.currentBorderEntity=null,this.centerPosition=null,this.originalDepthTestAgainstTerrain!==null&&(this.scene.globe.depthTestAgainstTerrain=this.originalDepthTestAgainstTerrain,this.originalDepthTestAgainstTerrain=null);const h=r/this.scene.globe.ellipsoid.maximumRadius,f=new i.Rectangle(t.longitude-h,t.latitude-h,t.longitude+h,t.latitude+h),m=i.Rectangle.subsample(f,this.scene.globe.ellipsoid),p={entity:o,type:"circle",positions:m,areaKm2:d};return this.callbacks.onMeasureComplete&&this.callbacks.onMeasureComplete(p),this.restoreRequestRenderModeIfNeeded(),this.callbacks.onDrawEnd&&this.callbacks.onDrawEnd(o),p}getDrawType(){return"circle"}generateCirclePositions(e,t,n,r=128){const s=e.latitude,l=e.longitude,a=t/6378137,c=[];for(let d=0;d<r;d++){const h=d/r*i.Math.TWO_PI,f=Math.sin(s),m=Math.cos(s),p=Math.sin(a),w=Math.cos(a),g=Math.sin(h),b=Math.cos(h),y=Math.asin(f*w+m*p*b),G=l+Math.atan2(g*p*m,w-f*Math.sin(y));c.push(i.Cartesian3.fromRadians(G,y,n))}return c}}class j{viewer;scene;entities;frustumPrimitives=[];drawMode=null;isDrawing=!1;tempPositions=[];tempEntities=[];tempLabelEntities=[];finishedEntities=[];finishedLabelEntities=[];finishedPointEntities=[];publicEntities=[];_doubleClickPending=!1;drawLine;drawPolygon;drawRectangle;drawCircle;currentDrawer=null;screenSpaceEventHandler=null;entityClickHandler=null;onDrawStartCallback=null;onDrawEndCallback=null;onEntityRemovedCallback=null;onMeasureCompleteCallback=null;offsetHeight=2;originalDepthTestAgainstTerrain=null;constructor(e){if(!e||!(e instanceof i.Viewer))throw new Error("Invalid Cesium Viewer instance provided.");this.viewer=e,this.scene=e.scene,this.entities=e.entities,this.updateOffsetHeight(),this.scene.globe.depthTestAgainstTerrain=!0;const t={onDrawStart:()=>{this.onDrawStartCallback&&this.onDrawStartCallback()},onDrawEnd:n=>{this.onDrawEndCallback&&this.onDrawEndCallback(n)},onEntityRemoved:n=>{this.onEntityRemovedCallback&&this.onEntityRemovedCallback(n)},onMeasureComplete:n=>{this.onMeasureCompleteCallback&&this.onMeasureCompleteCallback(n)}};this.drawLine=new S(e,t),this.drawPolygon=new X(e,t),this.drawRectangle=new B(e,t),this.drawCircle=new U(e,t);try{this.entityClickHandler=new i.ScreenSpaceEventHandler(this.scene.canvas),this.entityClickHandler.setInputAction(n=>{if(this.isDrawing)return;const r=this.scene.pick(n.position),o=r&&r.id;if(!o)return;const s=o._onClick;try{if(s){const a=o._groundPositions||o._groundPosition||void 0;s(o,o._drawType,a)}}catch(a){console.warn("entity onClick handler error",a)}const l=o._drawOptions;if(l?.selected)try{const a=l.selected;if(o._isSelected){const c=o._originalStyle;c&&(o.polyline&&c.material&&(o.polyline.material=c.material,o.polyline.width=c.width??o.polyline.width),o.polygon&&c.material&&(o.polygon.material=c.material,o.polygon.outlineColor=c.outlineColor??o.polygon.outlineColor,o.polygon.outlineWidth=c.outlineWidth??o.polygon.outlineWidth),o.rectangle&&c.material&&(o.rectangle.material=c.material,o.rectangle.outlineColor=c.outlineColor??o.rectangle.outlineColor,o.rectangle.outlineWidth=c.outlineWidth??o.rectangle.outlineWidth),o.ellipse&&c.material&&(o.ellipse.material=c.material,o.ellipse.outlineColor=c.outlineColor??o.ellipse.outlineColor,o.ellipse.outlineWidth=c.outlineWidth??o.ellipse.outlineWidth)),o._isSelected=!1}else{if(o._originalStyle={},o.polyline){o._originalStyle.material=o.polyline.material,o._originalStyle.width=o.polyline.width;const c=a?.color?i.Color.fromCssColorString(String(a.color)):i.Color.YELLOW;o.polyline.material=new i.ColorMaterialProperty(c),o.polyline.width=new i.ConstantProperty(a?.width??(o.polyline.width||5)+2)}if(o.polygon){o._originalStyle.material=o.polygon.material,o._originalStyle.outlineColor=o.polygon.outlineColor,o._originalStyle.outlineWidth=o.polygon.outlineWidth;const c=a?.color?i.Color.fromCssColorString(String(a.color)):i.Color.YELLOW;o.polygon.material=new i.ColorMaterialProperty(c.withAlpha(.5)),o.polygon.outlineColor=new i.ConstantProperty(a?.outlineColor?i.Color.fromCssColorString(String(a.outlineColor)):o.polygon.outlineColor),o.polygon.outlineWidth=new i.ConstantProperty(a?.outlineWidth??(o.polygon.outlineWidth||2))}if(o.rectangle){o._originalStyle.material=o.rectangle.material,o._originalStyle.outlineColor=o.rectangle.outlineColor,o._originalStyle.outlineWidth=o.rectangle.outlineWidth;const c=a?.color?i.Color.fromCssColorString(String(a.color)):i.Color.YELLOW;o.rectangle.material=new i.ColorMaterialProperty(c.withAlpha(.5)),o.rectangle.outlineColor=new i.ConstantProperty(a?.outlineColor?i.Color.fromCssColorString(String(a.outlineColor)):o.rectangle.outlineColor),o.rectangle.outlineWidth=new i.ConstantProperty(a?.outlineWidth??(o.rectangle.outlineWidth||2))}if(o.ellipse){o._originalStyle.material=o.ellipse.material,o._originalStyle.outlineColor=o.ellipse.outlineColor,o._originalStyle.outlineWidth=o.ellipse.outlineWidth;const c=a?.color?i.Color.fromCssColorString(String(a.color)):i.Color.YELLOW;o.ellipse.material=new i.ColorMaterialProperty(c.withAlpha(.5)),o.ellipse.outlineColor=new i.ConstantProperty(a?.outlineColor?i.Color.fromCssColorString(String(a.outlineColor)):o.ellipse.outlineColor),o.ellipse.outlineWidth=new i.ConstantProperty(a?.outlineWidth??(o.ellipse.outlineWidth||2))}o._isSelected=!0}}catch(a){console.warn("toggle selected style failed",a)}},i.ScreenSpaceEventType.LEFT_CLICK)}catch(n){console.warn("entity click handler init failed",n)}}handleSceneModeChanged(){const e=this.offsetHeight;this.updateOffsetHeight(),e!==this.offsetHeight&&this.updateFinishedEntitiesForModeChange()}updateOffsetHeight(){this.scene.mode===i.SceneMode.SCENE3D?this.offsetHeight=1:this.offsetHeight=0}startDrawingLine(e){this.startDrawing("line",e)}startDrawingPolygon(e){this.startDrawing("polygon",e)}startDrawingRectangle(e){this.startDrawing("rectangle",e)}startDrawingCircle(e){this.startDrawing("circle",e)}startDrawing(e,t){switch(this.endDrawingInternal(!1),this.drawMode=e,this.isDrawing=!0,this.tempPositions=[],this.tempEntities=[],this._doubleClickPending=!1,e){case"line":this.currentDrawer=this.drawLine;break;case"polygon":this.currentDrawer=this.drawPolygon;break;case"rectangle":this.currentDrawer=this.drawRectangle;break;case"circle":this.currentDrawer=this.drawCircle;break}this.currentDrawer&&this.currentDrawer.startDrawing(t),this.activateDrawingHandlers()}activateDrawingHandlers(){this.deactivateDrawingHandlers(),this.screenSpaceEventHandler=new i.ScreenSpaceEventHandler(this.scene.canvas),this.screenSpaceEventHandler.setInputAction(t=>{if(!this.isDrawing)return;if(this._doubleClickPending){this._doubleClickPending=!1;return}const n=this.pickGlobePosition(t.position);n&&this.addPoint(n)},i.ScreenSpaceEventType.LEFT_CLICK),this.screenSpaceEventHandler.setInputAction(()=>{!this.isDrawing||this.tempPositions.length===0||this.removeLastPoint()},i.ScreenSpaceEventType.RIGHT_CLICK),this.screenSpaceEventHandler.setInputAction(t=>{if(!this.isDrawing||this.tempPositions.length===0)return;const n=this.pickGlobePosition(t.endPosition);n&&this.updatePreview(n)},i.ScreenSpaceEventType.MOUSE_MOVE);const e=this.viewer.cesiumWidget.screenSpaceEventHandler.getInputAction(i.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);this.viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(i.ScreenSpaceEventType.LEFT_DOUBLE_CLICK),this.screenSpaceEventHandler.setInputAction(t=>{this.isDrawing&&(this._doubleClickPending=!0,this.finishDrawing(),e&&this.viewer.cesiumWidget.screenSpaceEventHandler.setInputAction(e,i.ScreenSpaceEventType.LEFT_DOUBLE_CLICK))},i.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)}pickGlobePosition(e){const t=this.viewer.camera.getPickRay(e);if(t&&this.scene.mode===i.SceneMode.SCENE3D&&this.scene.globe.tilesLoaded){const r=this.scene.globe.pick(t,this.scene);if(i.defined(r)&&Number.isFinite(r.x)&&Number.isFinite(r.y)&&Number.isFinite(r.z))return r}const n=this.viewer.camera.pickEllipsoid(e,this.scene.globe.ellipsoid);return n&&Number.isFinite(n.x)&&Number.isFinite(n.y)&&Number.isFinite(n.z)?n:null}addPoint(e){this.drawMode==="polygon"&&this.scene.mode===i.SceneMode.SCENE3D&&!this.scene.globe.tilesLoaded||this.currentDrawer&&(this.currentDrawer.addPoint(e),this.tempPositions=this.currentDrawer.tempPositions,this.tempEntities=this.currentDrawer.tempEntities,this.updateDrawingEntity())}removeLastPoint(){this.tempPositions.length>0&&(this.tempPositions.pop(),this.tempEntities.forEach(e=>{e&&this.entities.remove(e)}),this.tempEntities=[],this.tempLabelEntities.forEach(e=>{e&&this.entities.remove(e)}),this.tempLabelEntities=[],this.currentDrawer&&(this.currentDrawer.tempPositions=[...this.tempPositions],this.currentDrawer.tempEntities=[],this.currentDrawer.tempLabelEntities=[]),this.recreateRemainingEntities())}recreateRemainingEntities(){this.tempPositions.forEach(e=>{if(this.currentDrawer)this.currentDrawer.addPoint(e);else{const t=i.Cartographic.fromCartesian(e),n=i.Cartesian3.fromRadians(t.longitude,t.latitude,(t.height||0)+this.offsetHeight),r=this.entities.add({position:n,point:{pixelSize:8,color:i.Color.RED,outlineColor:i.Color.WHITE,outlineWidth:3,heightReference:i.HeightReference.NONE,scaleByDistance:new i.NearFarScalar(150,1,15e6,.5)}});this.tempEntities.push(r)}}),this.currentDrawer&&(this.tempPositions=this.currentDrawer.tempPositions,this.tempEntities=this.currentDrawer.tempEntities),this.updateDrawingEntity()}updatePreview(e){this.updateDrawingEntity(e)}updateDrawingEntity(e){if(!this.currentDrawer){console.warn("updateDrawingEntity called but currentDrawer is null. This should not happen.");return}this.currentDrawer.updateDrawingEntity(e),this.tempPositions=this.currentDrawer.tempPositions,this.tempEntities=this.currentDrawer.tempEntities,this.tempLabelEntities=this.currentDrawer.tempLabelEntities}finishDrawing(){if(!this.currentDrawer){console.warn("finishDrawing called but currentDrawer is null. This should not happen."),this.endDrawingInternal(!0);return}const e=this.currentDrawer.finishDrawing();try{this.currentDrawer.restoreRequestRenderModeIfNeeded&&this.currentDrawer.restoreRequestRenderModeIfNeeded()}catch{}e&&e.entity&&this.finishedEntities.push(e.entity),this.tempPositions=this.currentDrawer.tempPositions,this.tempEntities=this.currentDrawer.tempEntities,this.tempLabelEntities=this.currentDrawer.tempLabelEntities,this.finishedPointEntities=this.currentDrawer.finishedPointEntities,this.tempLabelEntities.forEach(t=>{this.finishedLabelEntities.push(t)}),this.tempLabelEntities=[],this.drawMode=null,this.isDrawing=!1,this.currentDrawer=null,this.deactivateDrawingHandlers()}endDrawingInternal(e){if(this.currentDrawer&&(this.currentDrawer.clearTempEntities(),this.tempPositions=this.currentDrawer.tempPositions,this.tempEntities=this.currentDrawer.tempEntities,this.tempLabelEntities=this.currentDrawer.tempLabelEntities),this.tempEntities.forEach(t=>{this.entities.remove(t)}),this.tempEntities=[],this.tempPositions=[],this.tempLabelEntities.forEach(t=>{this.entities.remove(t)}),this.tempLabelEntities=[],e){this.drawMode=null,this.isDrawing=!1,this.currentDrawer=null,this.deactivateDrawingHandlers(),this.originalDepthTestAgainstTerrain!==null&&(this.scene.globe.depthTestAgainstTerrain=this.originalDepthTestAgainstTerrain,this.originalDepthTestAgainstTerrain=null);try{this.currentDrawer&&this.currentDrawer.restoreRequestRenderModeIfNeeded&&this.currentDrawer.restoreRequestRenderModeIfNeeded()}catch{}}}endDrawing(){this.isDrawing?this.finishDrawing():this.endDrawingInternal(!0)}deactivateDrawingHandlers(){this.screenSpaceEventHandler&&(this.screenSpaceEventHandler.destroy(),this.screenSpaceEventHandler=null)}clearAll(){this.endDrawing(),this.clearAllPoints(),this.finishedEntities.forEach(e=>{this.entities.remove(e)}),this.finishedEntities=[],this.finishedLabelEntities.forEach(e=>{e&&this.entities.remove(e)}),this.finishedLabelEntities=[],this.publicEntities.forEach(e=>{e&&this.entities.remove(e)}),this.publicEntities=[],this.tempEntities.forEach(e=>{e&&this.entities.remove(e)}),this.tempEntities=[],this.tempLabelEntities.forEach(e=>{e&&e.label&&this.entities.remove(e)}),this.tempLabelEntities=[],this.tempPositions=[]}clearAllEntities(){this.endDrawing(),this.entities.removeAll(),this.finishedEntities=[],this.finishedLabelEntities=[],this.finishedPointEntities=[],this.publicEntities=[],this.tempEntities=[],this.tempLabelEntities=[],this.tempPositions=[]}clearAllPoints(){this.finishedPointEntities.forEach(t=>{t&&this.entities.remove(t)}),this.finishedPointEntities=[],this.tempEntities.forEach(t=>{t&&t.point&&this.entities.remove(t)});const e=this.entities.values;for(let t=e.length-1;t>=0;t--){const n=e[t];n&&n.point&&this.entities.remove(n)}}removeEntity(e){const t=this.finishedEntities.indexOf(e);t>-1&&(this.entities.remove(e),this.finishedEntities.splice(t,1),this.onEntityRemovedCallback&&this.onEntityRemovedCallback(e))}getFinishedEntities(){return[...this.finishedEntities]}createTotalLengthBillboardImage(e){const r="bold 16px 'Microsoft YaHei', 'PingFang SC', sans-serif",o=document.createElement("canvas"),s=o.getContext("2d");if(!s)return o.width=1,o.height=1,o;s.font=r;const a=s.measureText(e).width,c=20;return o.width=Math.ceil(a+24),o.height=Math.ceil(c+12),s.font=r,s.textBaseline="middle",s.textAlign="center",s.fillStyle="rgba(0, 0, 0, 0.8)",s.fillRect(0,0,o.width,o.height),s.fillStyle="#FFFFFF",s.fillText(e,o.width/2,o.height/2),o}createSegmentLengthBillboardImage(e){return this.createTotalLengthBillboardImage(e)}onMeasureComplete(e){this.onMeasureCompleteCallback=e}onDrawStart(e){this.onDrawStartCallback=e}onDrawEnd(e){this.onDrawEndCallback=e}onEntityRemoved(e){this.onEntityRemovedCallback=e}updateFinishedEntitiesForModeChange(){const e=this.offsetHeight>0;this.finishedEntities.forEach(t=>{if(t)if(t.polyline){const n=t._groundPositions;if(n&&n.length>0){const r=n.filter(o=>o&&Number.isFinite(o.x)&&Number.isFinite(o.y)&&Number.isFinite(o.z));if(r.length===0)return;if(e){const o=r.map(s=>{const l=i.Cartographic.fromCartesian(s);return i.Cartesian3.fromRadians(l.longitude,l.latitude,(l.height||0)+this.offsetHeight)});t.polyline.positions=new i.ConstantProperty(o),t.polyline.clampToGround=new i.ConstantProperty(!1)}else t.polyline.positions=new i.ConstantProperty(r),t.polyline.clampToGround=new i.ConstantProperty(!0)}}else if(t.polygon){const n=t._groundPositions;if(n&&n.length>0){const r=n.filter(o=>o&&Number.isFinite(o.x)&&Number.isFinite(o.y)&&Number.isFinite(o.z));if(r.length===0)return;if(e){const o=r.map(s=>{const l=i.Cartographic.fromCartesian(s);return i.Cartesian3.fromRadians(l.longitude,l.latitude,(l.height||0)+this.offsetHeight)});t.polygon.hierarchy=new i.ConstantProperty(new i.PolygonHierarchy(o)),t.polygon.heightReference=new i.ConstantProperty(i.HeightReference.NONE)}else t.polygon.hierarchy=new i.ConstantProperty(new i.PolygonHierarchy(r)),t.polygon.heightReference=new i.ConstantProperty(i.HeightReference.CLAMP_TO_GROUND)}}else t.rectangle&&t._groundRectangle&&(e?(t.rectangle.heightReference=new i.ConstantProperty(i.HeightReference.NONE),t.rectangle.extrudedHeight=new i.ConstantProperty(this.offsetHeight)):(t.rectangle.heightReference=new i.ConstantProperty(i.HeightReference.CLAMP_TO_GROUND),t.rectangle.extrudedHeight=void 0))}),this.finishedLabelEntities.forEach(t=>{if(!t)return;const n=t._groundPosition;if(n){if(t.label)if(e){const r=i.Cartographic.fromCartesian(n),o=i.Cartesian3.fromRadians(r.longitude,r.latitude,(r.height||0)+this.offsetHeight);t.position=new i.ConstantPositionProperty(o),t.label.heightReference=new i.ConstantProperty(i.HeightReference.RELATIVE_TO_GROUND)}else t.position=new i.ConstantPositionProperty(n),t.label.heightReference=new i.ConstantProperty(i.HeightReference.CLAMP_TO_GROUND);else if(t.billboard)if(e){const r=i.Cartographic.fromCartesian(n),o=i.Cartesian3.fromRadians(r.longitude,r.latitude,(r.height||0)+this.offsetHeight);t.position=new i.ConstantPositionProperty(o),t.billboard.heightReference=new i.ConstantProperty(i.HeightReference.RELATIVE_TO_GROUND)}else t.position=new i.ConstantPositionProperty(n),t.billboard.heightReference=new i.ConstantProperty(i.HeightReference.NONE)}}),this.finishedPointEntities.forEach(t=>{if(!t||!t.point)return;const n=t.position?.getValue(i.JulianDate.now());if(n){const r=i.Cartographic.fromCartesian(n),o=t._groundPosition;if(o)if(e){const s=i.Cartographic.fromCartesian(o),l=i.Cartesian3.fromRadians(s.longitude,s.latitude,(s.height||0)+this.offsetHeight);t.position=new i.ConstantPositionProperty(l),t.point.heightReference=new i.ConstantProperty(i.HeightReference.RELATIVE_TO_GROUND)}else t.position=new i.ConstantPositionProperty(o),t.point.heightReference=new i.ConstantProperty(i.HeightReference.CLAMP_TO_GROUND);else if(e){const s=i.Cartesian3.fromRadians(r.longitude,r.latitude,Math.max(0,(r.height||0)-this.offsetHeight)+this.offsetHeight);t.position=new i.ConstantPositionProperty(s),t.point.heightReference=new i.ConstantProperty(i.HeightReference.RELATIVE_TO_GROUND)}else{const s=i.Cartesian3.fromRadians(r.longitude,r.latitude,Math.max(0,(r.height||0)-this.offsetHeight));t.position=new i.ConstantPositionProperty(s),t.point.heightReference=new i.ConstantProperty(i.HeightReference.CLAMP_TO_GROUND)}}})}destroy(){if(this.deactivateDrawingHandlers(),this.entityClickHandler){try{this.entityClickHandler.destroy()}catch{}this.entityClickHandler=null}}}window.DrawHelper=j;function Z(){const e="57962be20a8da51ffd5d652bbc86325a,ef905e1aad18c1f8899ff8adb0453064,4b0c90d0a7ad9d80226e59a6a537507f".split(","),t=Math.floor(Math.random()*e.length);return e[t]}function me(u){const t=2*Math.PI*6378137,n=Math.max(10,Math.min(t,Math.abs(u))),r=Math.log2(t/(n*2))+1;return Math.max(1,Math.min(18,Math.round(r)))}function Q(u){const e=Math.max(1,Math.min(18,Math.round(u)));return 2*Math.PI*6378137/(2*Math.pow(2,e-1))}class q{viewer;initialCenter;getMapTypes;getCurrentMapTypeId;getToken;zoomCallback;onSceneModeChanged;constructor(e,t={}){this.viewer=e,this.initialCenter=t.initialCenter,this.getMapTypes=t.getMapTypes,this.getCurrentMapTypeId=t.getCurrentMapTypeId,this.getToken=t.getToken,this.zoomCallback=t.zoomCallback,this.onSceneModeChanged=t.onSceneModeChanged}setupCameraZoomLimitListener(){this.viewer.camera.changed.addEventListener(()=>{const t=this.getCurrentZoomLevel();let n=Math.max(1,Math.min(18,t)),r=18;const o=this.getMapTypes?this.getMapTypes():void 0,s=this.getCurrentMapTypeId?this.getCurrentMapTypeId():void 0;if(o&&s){const l=o.find(a=>a.id===s);if(l){const a=this.getToken?this.getToken():"";r=l.provider(a)[0]?.maximumLevel||18,n>r&&(n=r)}}(n===1||t>=r)&&this.setZoomLevel(n)})}getCurrentZoomLevel(){const e=this.viewer.camera.positionCartographic.height;return me(e)}setZoomLevel(e){try{const t=Math.max(1,Math.min(18,e)),n=Q(t);if(!isFinite(n)||isNaN(n)||n<=0){console.warn(`无效的目标高度: ${n},使用默认层级 ${t}`);return}let r;try{r=this.viewer.camera.positionCartographic.clone(),(!isFinite(r.longitude)||!isFinite(r.latitude))&&(r=i.Cartographic.fromDegrees(120.2052342,30.2489634))}catch(o){console.warn("获取当前相机位置失败,使用默认位置",o),r=i.Cartographic.fromDegrees(120.2052342,30.2489634)}this.viewer.camera.setView({destination:i.Cartesian3.fromRadians(r.longitude,r.latitude,n),orientation:{heading:this.viewer.camera.heading,pitch:this.viewer.camera.pitch,roll:this.viewer.camera.roll}})}catch(t){console.error("设置地图层级失败:",t);try{const n=Q(10),r=i.Cartographic.fromDegrees(120.2052342,30.2489634);this.viewer.camera.setView({destination:i.Cartesian3.fromRadians(r.longitude,r.latitude,n)})}catch(n){console.error("恢复地图层级失败:",n)}}}zoomIn(){const e=this.getCurrentZoomLevel(),t=this.viewer.camera.positionCartographic.height;let n=18;const r=this.getMapTypes?this.getMapTypes():void 0,o=this.getCurrentMapTypeId?this.getCurrentMapTypeId():void 0;if(r&&o){const a=r.find(c=>c.id===o);if(a){const c=this.getToken?this.getToken():"";if(n=a.provider(c)[0]?.maximumLevel||18,e>=n)return}}const s=e+1;this.setZoomLevel(s);const l=this.viewer.camera.positionCartographic.height;this.zoomCallback?.onZoomIn&&this.zoomCallback.onZoomIn(t,l,e)}zoomOut(){const e=this.getCurrentZoomLevel(),t=this.viewer.camera.positionCartographic.height;if(e<=1)return;const n=e-1;this.setZoomLevel(n);const r=this.viewer.camera.positionCartographic.height;this.zoomCallback?.onZoomOut&&this.zoomCallback.onZoomOut(t,r,e)}toggle2D3D(e){const t=this.viewer.scene,n=t.camera,o=t.mode===i.SceneMode.SCENE3D?i.SceneMode.SCENE2D:i.SceneMode.SCENE3D;e.innerHTML=o===i.SceneMode.SCENE3D?"3D":"2D";const s=t.canvas,l=new i.Cartesian2(s.clientWidth/2,s.clientHeight/2);let a=null;const c=n.getPickRay(l);if(c){const p=t.globe.pick(c,t);i.defined(p)&&(a=i.Cartographic.fromCartesian(p))}const d=n.positionCartographic.height,h=n.heading,f=n.pitch,m=n.roll;if(t.mode=o,this.onSceneModeChanged&&this.onSceneModeChanged(),a){const p=a.longitude,w=a.latitude;o===i.SceneMode.SCENE2D?n.setView({destination:i.Cartesian3.fromRadians(p,w,d),orientation:{heading:0,pitch:-Math.PI/2,roll:0}}):n.setView({destination:i.Cartesian3.fromRadians(p,w,d),orientation:{heading:h,pitch:f,roll:m}})}}resetLocation(){if(!this.initialCenter){console.warn("未设置初始中心点,无法执行复位操作");return}this.viewer.camera.flyTo({destination:i.Cartesian3.fromDegrees(this.initialCenter.longitude,this.initialCenter.latitude,this.initialCenter.height),duration:1})}setInitialCenter(e){this.initialCenter=e}getInitialCenter(){return this.initialCenter}toggleFullscreen(){this.isFullscreen()?this.exitFullscreen():this.enterFullscreen()}isFullscreen(){return!!(document.fullscreenElement||document.webkitFullscreenElement||document.msFullscreenElement)}enterFullscreen(){const e=this.viewer.container;e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullscreen?e.webkitRequestFullscreen():e.msRequestFullscreen&&e.msRequestFullscreen()}exitFullscreen(){document.exitFullscreen?document.exitFullscreen():document.webkitExitFullscreen?document.webkitExitFullscreen():document.msExitFullscreen&&document.msExitFullscreen()}}class we{viewer;drawHelper;measurementCallback;currentMode="none";constructor(e,t,n){this.viewer=e,this.drawHelper=t,this.measurementCallback=n}getMeasureMode(){return this.currentMode}setupDrawHelperCallbacks(){this.drawHelper.onMeasureComplete(e=>{this.measurementCallback&&(e.type==="line"&&this.measurementCallback.onDistanceComplete&&typeof e.distance=="number"?this.measurementCallback.onDistanceComplete(e.positions,e.distance):e.type==="polygon"&&this.measurementCallback.onAreaComplete&&typeof e.areaKm2=="number"&&this.measurementCallback.onAreaComplete(e.positions,e.areaKm2))}),this.drawHelper.onDrawStart(()=>{console.log("开始绘制"),this.measurementCallback?.onMeasurementStart&&this.measurementCallback.onMeasurementStart()}),this.drawHelper.onDrawEnd(e=>{e&&console.log("绘制完成",e),this.currentMode="none"}),this.drawHelper.onEntityRemoved(e=>{console.log("实体被移除",e)})}startAreaMeasurement(){this.currentMode="area",setTimeout(()=>{this.drawHelper.startDrawingPolygon()},50)}startDistanceMeasurement(){this.currentMode="distance",setTimeout(()=>{this.drawHelper.startDrawingLine()},50)}clearMeasurements(){this.currentMode="none",this.drawHelper.clearAll(),this.measurementCallback?.onClear&&this.measurementCallback.onClear()}}const pe=Z(),be="73.5577,18.1597,135.0882,53.5609",Ce={},xe=(u,e,t=pe)=>{const n={start:0,count:10,queryType:7,keyWord:u,mapBound:be,level:e?.defaultZoomLevel||15};return`http://api.tianditu.gov.cn/v2/search?postStr=${JSON.stringify(n)}&type=query&tk=${t}`};class J{viewer;toolbarElement;searchCallback;searchContainer=null;constructor(e,t,n){this.viewer=e,this.toolbarElement=t,this.searchCallback=n}setSearchCallback(e){this.searchCallback=e}toggleSearch(e){if(this.toolbarElement.querySelector(".search-container"))return;const n=e.offsetTop,r=document.createElement("div");r.className="search-container",r.style.cssText=`
1
+ (function(x,T){typeof exports=="object"&&typeof module<"u"?T(exports,require("cesium")):typeof define=="function"&&define.amd?define(["exports","cesium"],T):(x=typeof globalThis<"u"?globalThis:x||self,T(x.VMapCesiumToolbar={},x.Cesium))})(this,(function(x,T){"use strict";function ue(u){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const t in u)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(u,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>u[t]})}}return e.default=u,Object.freeze(e)}const i=ue(T);class E{viewer;scene;entities;offsetHeight=0;originalDepthTestAgainstTerrain=null;originalRequestRenderMode=null;callbacks;tempPositions=[];tempEntities=[];tempLabelEntities=[];finishedPointEntities=[];drawOptions;resolveColor(e){try{return e?e instanceof i.Color?e:i.Color.fromCssColorString(String(e)):i.Color.YELLOW}catch{return i.Color.YELLOW}}applySelectedStyleToEntity(e){try{const n=e._drawOptions?.selected;if(!n)return;if(e._isSelected){this.restoreOriginalStyleForEntity(e),e._isSelected=!1;return}if(e._originalStyle||(e._originalStyle={},e.polyline&&(e._originalStyle.material=e.polyline.material,e._originalStyle.width=e.polyline.width),e.polygon&&(e._originalStyle.material=e.polygon.material,e._originalStyle.outlineColor=e.polygon.outlineColor,e._originalStyle.outlineWidth=e.polygon.outlineWidth),e.rectangle&&(e._originalStyle.material=e.rectangle.material,e._originalStyle.outlineColor=e.rectangle.outlineColor,e._originalStyle.outlineWidth=e.rectangle.outlineWidth),e.ellipse&&(e._originalStyle.material=e.ellipse.material,e._originalStyle.outlineColor=e.ellipse.outlineColor,e._originalStyle.outlineWidth=e.ellipse.outlineWidth)),e.polyline){const r=n.color?this.resolveColor(n.color):i.Color.YELLOW,o=n.width??(e.polyline.width||5)+2;e.polyline.material=new i.ColorMaterialProperty(r),e.polyline.width=new i.ConstantProperty(o)}if(e.polygon){const r=n.color?this.resolveColor(n.color):i.Color.YELLOW;e.polygon.material=new i.ColorMaterialProperty(r.withAlpha(.5)),e.polygon.outlineColor=new i.ConstantProperty(n.outlineColor?this.resolveColor(n.outlineColor):this.resolveColor("#ffffff")),e.polygon.outlineWidth=new i.ConstantProperty(n.outlineWidth??(e.polygon.outlineWidth||2))}if(e.rectangle){const r=n.color?this.resolveColor(n.color):i.Color.YELLOW;e.rectangle.material=new i.ColorMaterialProperty(r.withAlpha(.5)),e.rectangle.outlineColor=new i.ConstantProperty(n.outlineColor?this.resolveColor(n.outlineColor):this.resolveColor("#ffffff")),e.rectangle.outlineWidth=new i.ConstantProperty(n.outlineWidth??(e.rectangle.outlineWidth||2))}if(e.ellipse){const r=n.color?this.resolveColor(n.color):i.Color.YELLOW;e.ellipse.material=new i.ColorMaterialProperty(r.withAlpha(.5)),e.ellipse.outlineColor=new i.ConstantProperty(n.outlineColor?this.resolveColor(n.outlineColor):this.resolveColor("#ffffff")),e.ellipse.outlineWidth=new i.ConstantProperty(n.outlineWidth??(e.ellipse.outlineWidth||2))}e._isSelected=!0}catch(t){console.warn("applySelectedStyleToEntity failed",t)}}restoreOriginalStyleForEntity(e){try{const t=e._originalStyle;if(!t)return;e.polyline&&t.material&&(e.polyline.material=t.material,e.polyline.width=t.width??e.polyline.width),e.polygon&&t.material&&(e.polygon.material=t.material,e.polygon.outlineColor=t.outlineColor??e.polygon.outlineColor,e.polygon.outlineWidth=t.outlineWidth??e.polygon.outlineWidth),e.rectangle&&t.material&&(e.rectangle.material=t.material,e.rectangle.outlineColor=t.outlineColor??e.rectangle.outlineColor,e.rectangle.outlineWidth=t.outlineWidth??e.rectangle.outlineWidth),e.ellipse&&t.material&&(e.ellipse.material=t.material,e.ellipse.outlineColor=t.outlineColor??e.ellipse.outlineColor,e.ellipse.outlineWidth=t.outlineWidth??e.ellipse.outlineWidth),e._isSelected=!1}catch(t){console.warn("restoreOriginalStyleForEntity failed",t)}}constructor(e,t={}){this.viewer=e,this.scene=e.scene,this.entities=e.entities,this.callbacks=t,this.updateOffsetHeight()}updateOffsetHeight(){this.scene.mode===i.SceneMode.SCENE3D?this.offsetHeight=1:this.offsetHeight=0}pickGlobePosition(e){const t=this.viewer.camera.getPickRay(e);if(t&&this.scene.mode===i.SceneMode.SCENE3D&&this.scene.globe.tilesLoaded){const r=this.scene.globe.pick(t,this.scene);if(i.defined(r)&&Number.isFinite(r.x)&&Number.isFinite(r.y)&&Number.isFinite(r.z))return r}const n=this.viewer.camera.pickEllipsoid(e,this.scene.globe.ellipsoid);return n&&Number.isFinite(n.x)&&Number.isFinite(n.y)&&Number.isFinite(n.z)?n:null}enableContinuousRenderingIfNeeded(){try{this.scene.requestRenderMode!==void 0&&(this.originalRequestRenderMode===null&&(this.originalRequestRenderMode=!!this.scene.requestRenderMode),this.scene.requestRenderMode&&(this.scene.requestRenderMode=!1,typeof this.scene.requestRender=="function"&&this.scene.requestRender()))}catch(e){console.warn("enableContinuousRenderingIfNeeded failed",e)}}restoreRequestRenderModeIfNeeded(){try{this.originalRequestRenderMode!==null&&this.originalRequestRenderMode===!0&&(this.scene.requestRenderMode=!0,typeof this.scene.requestRender=="function"&&this.scene.requestRender())}catch(e){console.warn("restoreRequestRenderModeIfNeeded failed",e)}finally{this.originalRequestRenderMode=null}}addPoint(e){this.tempPositions.push(e.clone());const t=i.Cartographic.fromCartesian(e),n=i.Cartesian3.fromRadians(t.longitude,t.latitude,(t.height||0)+this.offsetHeight),r=this.entities.add({position:n,point:{pixelSize:8,color:i.Color.RED,outlineColor:i.Color.WHITE,outlineWidth:3,heightReference:i.HeightReference.NONE,scaleByDistance:new i.NearFarScalar(150,1,15e6,.5),disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.tempEntities.push(r)}createTotalLengthBillboardImage(e){const r="bold 16px 'Microsoft YaHei', 'PingFang SC', sans-serif",o=document.createElement("canvas"),s=o.getContext("2d");if(!s)return o.width=1,o.height=1,o;s.font=r;const a=s.measureText(e).width,c=20;return o.width=Math.ceil(a+24),o.height=Math.ceil(c+12),s.font=r,s.textBaseline="middle",s.textAlign="center",s.fillStyle="rgba(0, 0, 0, 0.8)",s.fillRect(0,0,o.width,o.height),s.fillStyle="#FFFFFF",s.fillText(e,o.width/2,o.height/2),o}createSegmentLengthBillboardImage(e){return this.createTotalLengthBillboardImage(e)}clearTempEntities(){this.tempEntities.forEach(e=>{e&&this.entities.remove(e)}),this.tempEntities=[],this.tempLabelEntities.forEach(e=>{e&&this.entities.remove(e)}),this.tempLabelEntities=[]}}function N(u){return!!u&&Number.isFinite(u.x)&&Number.isFinite(u.y)&&Number.isFinite(u.z)}function L(u){return!isFinite(u)||isNaN(u)?"0.00 m":u>=1e3?`${(u/1e3).toFixed(2)} km`:`${u.toFixed(2)} m`}function z(u){return!isFinite(u)||isNaN(u)?"0.00 m²":u>=1?`${u.toFixed(2)} km²`:`${(u*1e6).toFixed(2)} m²`}function F(u,e){const t=i.Cartographic.fromCartesian(u),n=i.Cartographic.fromCartesian(e),r=Math.min(t.longitude,n.longitude),o=Math.max(t.longitude,n.longitude),s=Math.min(t.latitude,n.latitude),l=Math.max(t.latitude,n.latitude);return new i.Rectangle(r,s,o,l)}function fe(u){const e=u.west,t=u.south,n=u.east,r=u.north,o=i.Cartesian3.distance(i.Cartesian3.fromRadians(e,t),i.Cartesian3.fromRadians(n,t)),s=i.Cartesian3.distance(i.Cartesian3.fromRadians(e,t),i.Cartesian3.fromRadians(e,r));return o*s/1e6}function W(u,e=i.Ellipsoid.WGS84){const t=u.filter(o=>N(o));if(t.length<3)return 0;let n=0;const r=t.length;for(let o=0;o<r;o++){const s=t[o],l=t[(o+1)%r];if(!N(s)||!N(l))return 0;const a=e.cartesianToCartographic(s),c=e.cartesianToCartographic(l);if(!a||!c||!Number.isFinite(a.longitude)||!Number.isFinite(a.latitude)||!Number.isFinite(c.longitude)||!Number.isFinite(c.latitude))return 0;n+=(c.longitude-a.longitude)*(2+Math.sin(a.latitude)+Math.sin(c.latitude))}return n=Math.abs(n*6378137*6378137/2),n/1e6}function ge(u){const e=u.filter(o=>N(o));if(e.length===0)return i.Cartesian3.ZERO;let t=0,n=0,r=0;for(let o=0;o<e.length;o++)t+=e[o].x,n+=e[o].y,r+=e[o].z;return new i.Cartesian3(t/e.length,n/e.length,r/e.length)}class S extends E{currentLineEntity=null;currentSegmentLabels=[];currentTotalLabel=null;currentLinePositions=[];isTotalLabelWarmedUp=!1;startDrawing(e){this.drawOptions=e,this.enableContinuousRenderingIfNeeded(),this.warmupTotalLengthLabel(),this.clearTempEntities(),this.tempPositions=[],this.currentLineEntity=null,this.currentSegmentLabels=[],this.currentTotalLabel=null,this.currentLinePositions=[],this.originalDepthTestAgainstTerrain===null&&(this.originalDepthTestAgainstTerrain=this.scene.globe.depthTestAgainstTerrain),this.scene.globe.depthTestAgainstTerrain=!1,this.callbacks.onDrawStart&&this.callbacks.onDrawStart()}updateDrawingEntity(e){const t=[...this.tempPositions];if(e&&t.push(e),t.length<2){this.clearLineEntity();return}const n=this.offsetHeight>0?t.map(s=>{const l=i.Cartographic.fromCartesian(s);return i.Cartesian3.fromRadians(l.longitude,l.latitude,(l.height||0)+this.offsetHeight)}):t,r=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):i.Color.YELLOW,o=this.drawOptions?.strokeWidth??5;this.currentLineEntity?(this.currentLineEntity.polyline.positions instanceof i.CallbackProperty?(this.currentLinePositions.length=0,this.currentLinePositions.push(...n)):(this.currentLinePositions=[...n],this.currentLineEntity.polyline.positions=new i.CallbackProperty(()=>this.currentLinePositions,!1)),this.currentLineEntity.polyline.material=new i.ColorMaterialProperty(r),this.currentLineEntity.polyline.width=new i.ConstantProperty(o)):(this.currentLinePositions=[...n],this.currentLineEntity=this.entities.add({polyline:{positions:new i.CallbackProperty(()=>this.currentLinePositions,!1),width:o,material:r,clampToGround:this.offsetHeight===0}}),this.tempEntities.push(this.currentLineEntity)),this.updateSegmentLabels(t),this.updateTotalLabel()}finishDrawing(){if(this.tempPositions.length<2)return this.restoreRequestRenderModeIfNeeded(),null;const e=this.tempPositions.filter(a=>N(a));if(e.length<2)return this.restoreRequestRenderModeIfNeeded(),null;const t=e.map(a=>{const c=i.Cartographic.fromCartesian(a);return i.Cartesian3.fromRadians(c.longitude,c.latitude,c.height||0)});let n=null,r=0;const o=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):i.Color.YELLOW,s=this.drawOptions?.strokeWidth??5;if(this.offsetHeight>0){const a=t.map(c=>{const d=i.Cartographic.fromCartesian(c);return i.Cartesian3.fromRadians(d.longitude,d.latitude,(d.height||0)+this.offsetHeight)});n=this.entities.add({name:"绘制的线",polyline:{positions:a,width:s,material:o,clampToGround:!1}}),n._groundPositions=t}else n=this.entities.add({name:"绘制的线",polyline:{positions:t,width:s,material:o,clampToGround:!0}}),n._groundPositions=t;n&&(n._drawOptions=this.drawOptions,n._drawType=this.getDrawType(),this.drawOptions?.onClick&&(n._onClick=this.drawOptions.onClick));for(let a=1;a<t.length;a++)r+=i.Cartesian3.distance(t[a-1],t[a]);this.tempLabelEntities.forEach(a=>{}),this.tempEntities.forEach(a=>{a&&this.entities.remove(a)}),this.tempEntities=[],this.tempPositions=[],this.currentLineEntity=null,this.currentSegmentLabels=[],this.currentTotalLabel=null,this.originalDepthTestAgainstTerrain!==null&&(this.scene.globe.depthTestAgainstTerrain=this.originalDepthTestAgainstTerrain,this.originalDepthTestAgainstTerrain=null);const l={entity:n,type:"line",positions:t,distance:r};return this.callbacks.onMeasureComplete&&this.callbacks.onMeasureComplete(l),this.restoreRequestRenderModeIfNeeded(),this.callbacks.onDrawEnd&&this.callbacks.onDrawEnd(n),l}getDrawType(){return"line"}clearLineEntity(){if(this.currentLineEntity){this.entities.remove(this.currentLineEntity);const e=this.tempEntities.indexOf(this.currentLineEntity);e>-1&&this.tempEntities.splice(e,1),this.currentLineEntity=null,this.currentLinePositions=[]}if(this.currentSegmentLabels.forEach(e=>{if(e){this.entities.remove(e);const t=this.tempLabelEntities.indexOf(e);t>-1&&this.tempLabelEntities.splice(t,1)}}),this.currentSegmentLabels=[],this.currentTotalLabel){this.entities.remove(this.currentTotalLabel);const e=this.tempLabelEntities.indexOf(this.currentTotalLabel);e>-1&&this.tempLabelEntities.splice(e,1),this.currentTotalLabel=null}}updateSegmentLabels(e){const t=e.length-1,n=this.currentSegmentLabels.length;if(n>t){for(let r=t;r<n;r++){const o=this.currentSegmentLabels[r];if(o){this.entities.remove(o);const s=this.tempLabelEntities.indexOf(o);s>-1&&this.tempLabelEntities.splice(s,1)}}this.currentSegmentLabels=this.currentSegmentLabels.slice(0,t)}for(let r=0;r<t;r++){const o=e[r],s=e[r+1],l=i.Cartesian3.distance(o,s);if(l>5){const a=i.Cartesian3.midpoint(o,s,new i.Cartesian3),c=i.Cartographic.fromCartesian(a),d=i.Cartesian3.fromRadians(c.longitude,c.latitude,c.height||0);let h=a;this.offsetHeight>0&&(h=i.Cartesian3.fromRadians(c.longitude,c.latitude,(c.height||0)+this.offsetHeight));const f=r%2===0?-25:25,m=L(l);if(r<this.currentSegmentLabels.length&&this.currentSegmentLabels[r].billboard){const p=this.currentSegmentLabels[r];if(p.position=new i.ConstantPositionProperty(h),p.billboard.pixelOffset=new i.ConstantProperty(new i.Cartesian2(0,f)),p._groundPosition=d,p._segmentText!==m){const g=this.createSegmentLengthBillboardImage(m);p.billboard.image=new i.ConstantProperty(g),p._segmentText=m}}else{const p=this.createSegmentLengthBillboardImage(m),w=this.entities.add({position:h,billboard:{image:p,pixelOffset:new i.ConstantProperty(new i.Cartesian2(0,f)),heightReference:new i.ConstantProperty(this.offsetHeight>0?i.HeightReference.RELATIVE_TO_GROUND:i.HeightReference.NONE),verticalOrigin:new i.ConstantProperty(i.VerticalOrigin.CENTER),horizontalOrigin:new i.ConstantProperty(i.HorizontalOrigin.CENTER),scale:new i.ConstantProperty(1),disableDepthTestDistance:new i.ConstantProperty(Number.POSITIVE_INFINITY)}});w._segmentText=m,w._groundPosition=d,this.currentSegmentLabels.push(w),this.tempLabelEntities.push(w)}}else if(r<this.currentSegmentLabels.length){const a=this.currentSegmentLabels[r];if(a){this.entities.remove(a);const c=this.tempLabelEntities.indexOf(a);c>-1&&this.tempLabelEntities.splice(c,1)}this.currentSegmentLabels.splice(r,1),r--}}}updateTotalLabel(){if(this.tempPositions.length>1){let e=0;for(let c=1;c<this.tempPositions.length;c++)e+=i.Cartesian3.distance(this.tempPositions[c-1],this.tempPositions[c]);const t=this.tempPositions[this.tempPositions.length-1],n=i.Cartographic.fromCartesian(t),r=i.Cartesian3.fromRadians(n.longitude,n.latitude,n.height||0);let o=r;this.offsetHeight>0&&(o=i.Cartesian3.fromRadians(n.longitude,n.latitude,(n.height||0)+this.offsetHeight));const l=`总长: ${L(e)}`,a=this.createTotalLengthBillboardImage(l);if(this.currentTotalLabel&&this.currentTotalLabel.billboard)this.currentTotalLabel.position=new i.ConstantPositionProperty(o),this.currentTotalLabel.billboard.image=new i.ConstantProperty(a),this.currentTotalLabel._groundPosition=r;else{const c=this.entities.add({position:o,billboard:{image:a,pixelOffset:new i.ConstantProperty(new i.Cartesian2(0,-35)),heightReference:new i.ConstantProperty(this.offsetHeight>0?i.HeightReference.RELATIVE_TO_GROUND:i.HeightReference.NONE),verticalOrigin:new i.ConstantProperty(i.VerticalOrigin.BOTTOM),horizontalOrigin:new i.ConstantProperty(i.HorizontalOrigin.CENTER),scale:new i.ConstantProperty(1),disableDepthTestDistance:new i.ConstantProperty(Number.POSITIVE_INFINITY)}});this.currentTotalLabel=c,this.currentTotalLabel._groundPosition=r,this.tempLabelEntities.push(c)}}else if(this.currentTotalLabel){this.entities.remove(this.currentTotalLabel);const e=this.tempLabelEntities.indexOf(this.currentTotalLabel);e>-1&&this.tempLabelEntities.splice(e,1),this.currentTotalLabel=null}}warmupTotalLengthLabel(){if(this.isTotalLabelWarmedUp)return;let e;try{e=this.viewer.camera.positionCartographic.clone()}catch{e=i.Cartographic.fromDegrees(120.2052342,30.2489634,this.offsetHeight)}const t=i.Cartesian3.fromRadians(e.longitude,e.latitude,(e.height||0)+this.offsetHeight),n=this.entities.add({position:t,label:{text:"总长: 0.00 m",font:"bold 16px 'Microsoft YaHei', 'PingFang SC', sans-serif",fillColor:i.Color.WHITE,outlineColor:i.Color.BLACK,outlineWidth:2,style:i.LabelStyle.FILL_AND_OUTLINE,pixelOffset:new i.Cartesian2(0,-35),heightReference:i.HeightReference.RELATIVE_TO_GROUND,scale:1,showBackground:!0,backgroundPadding:new i.Cartesian2(6,3),backgroundColor:i.Color.BLACK.withAlpha(.8),disableDepthTestDistance:Number.POSITIVE_INFINITY,verticalOrigin:i.VerticalOrigin.BOTTOM,horizontalOrigin:i.HorizontalOrigin.CENTER,show:!1}});this.isTotalLabelWarmedUp=!0,requestAnimationFrame(()=>{try{this.entities.remove(n)}catch{}})}}class X extends E{currentPolygonEntity=null;currentBorderEntity=null;startDrawing(e){this.drawOptions=e,this.enableContinuousRenderingIfNeeded(),this.clearTempEntities(),this.tempPositions=[],this.currentPolygonEntity=null,this.currentBorderEntity=null,this.originalDepthTestAgainstTerrain===null&&(this.originalDepthTestAgainstTerrain=this.scene.globe.depthTestAgainstTerrain),this.scene.globe.depthTestAgainstTerrain=!1,this.callbacks.onDrawStart&&this.callbacks.onDrawStart()}updateDrawingEntity(e){if(this.scene.mode===i.SceneMode.SCENE3D&&!this.scene.globe.tilesLoaded)return;const n=this.tempPositions.filter(o=>N(o)),r=e&&N(e)&&n.length>=2?[...n,e]:n;if(r.length>=3){const o=r.map(f=>i.Cartographic.fromCartesian(f)).filter(f=>f&&Number.isFinite(f.longitude)&&Number.isFinite(f.latitude));if(o.length<3){if(this.currentPolygonEntity){this.entities.remove(this.currentPolygonEntity);const f=this.tempEntities.indexOf(this.currentPolygonEntity);f>-1&&this.tempEntities.splice(f,1),this.currentPolygonEntity=null}if(this.currentBorderEntity){this.entities.remove(this.currentBorderEntity);const f=this.tempEntities.indexOf(this.currentBorderEntity);f>-1&&this.tempEntities.splice(f,1),this.currentBorderEntity=null}return}const s=o.map(f=>{const m=f.height||0,p=this.offsetHeight>0?this.offsetHeight:.1;return i.Cartesian3.fromRadians(f.longitude,f.latitude,m+p)}),l=i.HeightReference.NONE,a=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):i.Color.LIGHTGREEN,c=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):i.Color.DARKGREEN,d=this.drawOptions?.strokeWidth??this.drawOptions?.outlineWidth??2;this.currentPolygonEntity?(this.currentPolygonEntity.polygon.hierarchy=new i.ConstantProperty(new i.PolygonHierarchy(s)),this.currentPolygonEntity.polygon.heightReference=new i.ConstantProperty(l),this.currentPolygonEntity.polygon.material=new i.ColorMaterialProperty(a),this.currentPolygonEntity.polygon.outline=new i.ConstantProperty(!1)):(this.currentPolygonEntity=this.entities.add({polygon:{hierarchy:new i.ConstantProperty(new i.PolygonHierarchy(s)),material:new i.ColorMaterialProperty(a),outline:!1,heightReference:l}}),this.tempEntities.push(this.currentPolygonEntity));const h=s.slice();h.length>=2&&h.push(s[0]),this.currentBorderEntity&&this.currentBorderEntity.polyline?(this.currentBorderEntity.polyline.positions=new i.ConstantProperty(h),this.currentBorderEntity.polyline.width=new i.ConstantProperty(d),this.currentBorderEntity.polyline.material=new i.ColorMaterialProperty(c),this.currentBorderEntity.polyline.clampToGround=new i.ConstantProperty(!1)):(this.currentBorderEntity=this.entities.add({polyline:{positions:new i.ConstantProperty(h),width:d,material:new i.ColorMaterialProperty(c),clampToGround:!1}}),this.tempEntities.push(this.currentBorderEntity))}else{if(this.currentPolygonEntity){this.entities.remove(this.currentPolygonEntity);const o=this.tempEntities.indexOf(this.currentPolygonEntity);o>-1&&this.tempEntities.splice(o,1),this.currentPolygonEntity=null}if(this.currentBorderEntity){this.entities.remove(this.currentBorderEntity);const o=this.tempEntities.indexOf(this.currentBorderEntity);o>-1&&this.tempEntities.splice(o,1),this.currentBorderEntity=null}}}finishDrawing(){const e=this.tempPositions.filter(h=>N(h));if(e.length<3)return this.restoreRequestRenderModeIfNeeded(),null;const t=e.map(h=>i.Cartographic.fromCartesian(h)).filter(h=>h&&Number.isFinite(h.longitude)&&Number.isFinite(h.latitude));if(t.length<3)return this.restoreRequestRenderModeIfNeeded(),null;const n=t.map(h=>i.Cartesian3.fromRadians(h.longitude,h.latitude,h.height||0));let r=null,o=null;const s=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):i.Color.LIGHTGREEN,l=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):i.Color.DARKGREEN,a=this.drawOptions?.strokeWidth??this.drawOptions?.outlineWidth??2;if(this.offsetHeight>0){const h=n.map(m=>{const p=i.Cartographic.fromCartesian(m);return i.Cartesian3.fromRadians(p.longitude,p.latitude,(p.height||0)+this.offsetHeight)});r=this.entities.add({name:"绘制的多边形区域",polygon:{hierarchy:new i.PolygonHierarchy(h),material:new i.ColorMaterialProperty(s),outline:!1,heightReference:i.HeightReference.NONE}});const f=h.slice();f.length>=2&&f.push(h[0]),o=this.entities.add({polyline:{positions:f,width:a,material:new i.ColorMaterialProperty(l),clampToGround:!1}}),r._groundPositions=n,r&&(r._drawOptions=this.drawOptions,r._drawType=this.getDrawType(),this.drawOptions?.onClick&&(r._onClick=this.drawOptions.onClick),o&&(r._borderEntity=o))}else{r=this.entities.add({name:"绘制的多边形区域",polygon:{hierarchy:new i.PolygonHierarchy(n),material:new i.ColorMaterialProperty(s),outline:!1,heightReference:i.HeightReference.NONE}});const h=n.slice();h.length>=2&&h.push(n[0]),o=this.entities.add({polyline:{positions:h,width:a,material:new i.ColorMaterialProperty(l),clampToGround:!0}}),r._groundPositions=n,r&&(r._drawOptions=this.drawOptions,r._drawType=this.getDrawType(),this.drawOptions?.onClick&&(r._onClick=this.drawOptions.onClick),o&&(r._borderEntity=o))}const c=W(n,this.scene.globe.ellipsoid);if(c>0){const h=ge(n),f=i.Cartographic.fromCartesian(h),m=i.Cartesian3.fromRadians(f.longitude,f.latitude,f.height||0);let p=m;this.offsetHeight>0&&(p=i.Cartesian3.fromRadians(f.longitude,f.latitude,(f.height||0)+this.offsetHeight));const w=`面积: ${z(c)}`,g=this.createTotalLengthBillboardImage(w),b=this.entities.add({position:p,billboard:{image:g,pixelOffset:new i.ConstantProperty(new i.Cartesian2(0,-25)),heightReference:new i.ConstantProperty(this.offsetHeight>0?i.HeightReference.RELATIVE_TO_GROUND:i.HeightReference.NONE),verticalOrigin:new i.ConstantProperty(i.VerticalOrigin.BOTTOM),horizontalOrigin:new i.ConstantProperty(i.HorizontalOrigin.CENTER),scale:new i.ConstantProperty(1),disableDepthTestDistance:new i.ConstantProperty(Number.POSITIVE_INFINITY)}});b._groundPosition=m,this.tempLabelEntities.push(b)}this.tempEntities.forEach(h=>{h&&this.entities.remove(h)}),this.tempEntities=[],this.tempPositions=[],this.currentPolygonEntity=null,this.currentBorderEntity=null,this.originalDepthTestAgainstTerrain!==null&&(this.scene.globe.depthTestAgainstTerrain=this.originalDepthTestAgainstTerrain,this.originalDepthTestAgainstTerrain=null);const d={entity:r,type:"polygon",positions:n,areaKm2:W(n,this.scene.globe.ellipsoid)};return this.callbacks.onMeasureComplete&&this.callbacks.onMeasureComplete(d),this.restoreRequestRenderModeIfNeeded(),this.callbacks.onDrawEnd&&this.callbacks.onDrawEnd(r),d}getDrawType(){return"polygon"}}class B extends E{currentRectangleEntity=null;startDrawing(e){this.drawOptions=e,this.enableContinuousRenderingIfNeeded(),this.clearTempEntities(),this.tempPositions=[],this.currentRectangleEntity=null,this.originalDepthTestAgainstTerrain===null&&(this.originalDepthTestAgainstTerrain=this.scene.globe.depthTestAgainstTerrain),this.scene.globe.depthTestAgainstTerrain=!1,this.callbacks.onDrawStart&&this.callbacks.onDrawStart()}updateDrawingEntity(e){const t=[...this.tempPositions];if(e&&t.push(e),t.length<2){if(this.currentRectangleEntity){this.entities.remove(this.currentRectangleEntity);const a=this.tempEntities.indexOf(this.currentRectangleEntity);a>-1&&this.tempEntities.splice(a,1),this.currentRectangleEntity=null}return}const n=F(t[0],t[1]),r=i.HeightReference.NONE,o=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):i.Color.GREEN,s=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):i.Color.DARKGREEN,l=this.drawOptions?.strokeWidth??this.drawOptions?.outlineWidth??1;this.currentRectangleEntity?(this.currentRectangleEntity.rectangle.coordinates=new i.ConstantProperty(n),this.currentRectangleEntity.rectangle.heightReference=new i.ConstantProperty(r),this.currentRectangleEntity.rectangle.extrudedHeight=this.offsetHeight>0?new i.ConstantProperty(this.offsetHeight):void 0,this.currentRectangleEntity.rectangle.material=new i.ColorMaterialProperty(o.withAlpha(.5)),this.currentRectangleEntity.rectangle.outlineColor=new i.ConstantProperty(s),this.currentRectangleEntity.rectangle.outlineWidth=new i.ConstantProperty(l)):(this.currentRectangleEntity=this.entities.add({rectangle:{coordinates:n,material:o.withAlpha(.5),heightReference:r,extrudedHeight:this.offsetHeight>0?this.offsetHeight:void 0,outline:!0,outlineColor:s,outlineWidth:l}}),this.tempEntities.push(this.currentRectangleEntity))}finishDrawing(){if(this.tempPositions.length<2)return this.restoreRequestRenderModeIfNeeded(),null;const e=this.tempPositions.filter(h=>N(h));if(e.length<2)return this.restoreRequestRenderModeIfNeeded(),null;const t=e.map(h=>{const f=i.Cartographic.fromCartesian(h);return i.Cartesian3.fromRadians(f.longitude,f.latitude,f.height||0)}),n=F(t[0],t[1]);let r=null;const o=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):i.Color.GREEN,s=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):i.Color.DARKGREEN,l=this.drawOptions?.strokeWidth??this.drawOptions?.outlineWidth??1;this.offsetHeight>0?(r=this.entities.add({name:"绘制的矩形",rectangle:{coordinates:n,material:o.withAlpha(.5),heightReference:i.HeightReference.NONE,extrudedHeight:this.offsetHeight,outline:!0,outlineColor:s,outlineWidth:l}}),r._groundRectangle=n):(r=this.entities.add({name:"绘制的矩形",rectangle:{coordinates:n,material:o.withAlpha(.5),heightReference:i.HeightReference.NONE,outline:!0,outlineColor:s,outlineWidth:l}}),r._groundRectangle=n),r&&(r._drawOptions=this.drawOptions,r._drawType=this.getDrawType(),this.drawOptions?.onClick&&(r._onClick=this.drawOptions.onClick));const a=fe(n);if(a>0){const h=i.Rectangle.center(n),f=i.Cartesian3.fromRadians(h.longitude,h.latitude,0);let m=f;this.offsetHeight>0&&(m=i.Cartesian3.fromRadians(h.longitude,h.latitude,this.offsetHeight));const p=`面积: ${z(a)}`,w=this.createTotalLengthBillboardImage(p),g=this.entities.add({position:m,billboard:{image:w,pixelOffset:new i.ConstantProperty(new i.Cartesian2(0,-25)),heightReference:new i.ConstantProperty(this.offsetHeight>0?i.HeightReference.RELATIVE_TO_GROUND:i.HeightReference.NONE),verticalOrigin:new i.ConstantProperty(i.VerticalOrigin.BOTTOM),horizontalOrigin:new i.ConstantProperty(i.HorizontalOrigin.CENTER),scale:new i.ConstantProperty(1),disableDepthTestDistance:new i.ConstantProperty(Number.POSITIVE_INFINITY)}});g._groundPosition=f,this.tempLabelEntities.push(g)}this.tempEntities.forEach(h=>{h&&this.entities.remove(h)}),this.tempEntities=[],this.tempPositions=[],this.currentRectangleEntity=null,this.originalDepthTestAgainstTerrain!==null&&(this.scene.globe.depthTestAgainstTerrain=this.originalDepthTestAgainstTerrain,this.originalDepthTestAgainstTerrain=null);const c=i.Rectangle.subsample(n,this.scene.globe.ellipsoid),d={entity:r,type:"rectangle",positions:c,areaKm2:a};return this.callbacks.onMeasureComplete&&this.callbacks.onMeasureComplete(d),this.restoreRequestRenderModeIfNeeded(),this.callbacks.onDrawEnd&&this.callbacks.onDrawEnd(r),d}getDrawType(){return"rectangle"}}class U extends E{currentCircleEntity=null;currentBorderEntity=null;centerPosition=null;startDrawing(e){this.drawOptions=e,this.enableContinuousRenderingIfNeeded(),this.clearTempEntities(),this.tempPositions=[],this.currentCircleEntity=null,this.currentBorderEntity=null,this.centerPosition=null,this.originalDepthTestAgainstTerrain===null&&(this.originalDepthTestAgainstTerrain=this.scene.globe.depthTestAgainstTerrain),this.scene.globe.depthTestAgainstTerrain=!1,this.callbacks.onDrawStart&&this.callbacks.onDrawStart()}updateDrawingEntity(e){if(this.tempPositions.length===0){if(this.currentCircleEntity){this.entities.remove(this.currentCircleEntity);const h=this.tempEntities.indexOf(this.currentCircleEntity);h>-1&&this.tempEntities.splice(h,1),this.currentCircleEntity=null}return}if(!e)return;const t=this.tempPositions[0],n=i.Cartesian3.distance(t,e);if(n<1)return;const r=i.Cartographic.fromCartesian(t),o=i.Cartesian3.fromRadians(r.longitude,r.latitude,r.height||0);let s=o;this.offsetHeight>0&&(s=i.Cartesian3.fromRadians(r.longitude,r.latitude,(r.height||0)+this.offsetHeight));const l=n/this.scene.globe.ellipsoid.maximumRadius;new i.Rectangle(r.longitude-l,r.latitude-l,r.longitude+l,r.latitude+l);const a=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):i.Color.BLUE,c=this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):i.Color.BLUE,d=this.drawOptions?.outlineWidth??2;if(this.currentCircleEntity?(this.currentCircleEntity.ellipse.semiMajorAxis=new i.ConstantProperty(n),this.currentCircleEntity.ellipse.semiMinorAxis=new i.ConstantProperty(n),this.currentCircleEntity.position=new i.ConstantPositionProperty(s),this.currentCircleEntity.ellipse.material=new i.ColorMaterialProperty(a.withAlpha(.3)),this.currentCircleEntity.ellipse.outline=new i.ConstantProperty(d<=1),this.currentCircleEntity.ellipse.outlineColor=new i.ConstantProperty(c),this.currentCircleEntity.ellipse.outlineWidth=new i.ConstantProperty(d<=1?d:1)):(this.currentCircleEntity=this.entities.add({position:s,ellipse:{semiMajorAxis:n,semiMinorAxis:n,material:a.withAlpha(.3),outline:d<=1,outlineColor:c,outlineWidth:d<=1?d:1,heightReference:i.HeightReference.NONE}}),this.tempEntities.push(this.currentCircleEntity)),d>1){const h=i.Cartographic.fromCartesian(s),f=h.height||0,m=.1,p=n,w=this.generateCirclePositions(h,p,f+m),g=[...w,w[0]];this.currentBorderEntity&&this.currentBorderEntity.polyline?(this.currentBorderEntity.polyline.positions=new i.ConstantProperty(g),this.currentBorderEntity.polyline.material=new i.ColorMaterialProperty(c),this.currentBorderEntity.polyline.width=new i.ConstantProperty(d),this.currentBorderEntity.polyline.clampToGround=new i.ConstantProperty(!1)):(this.currentBorderEntity=this.entities.add({polyline:{positions:g,material:new i.ColorMaterialProperty(c),width:d,clampToGround:!1}}),this.tempEntities.push(this.currentBorderEntity))}else if(this.currentBorderEntity){this.entities.remove(this.currentBorderEntity);const h=this.tempEntities.indexOf(this.currentBorderEntity);h>-1&&this.tempEntities.splice(h,1),this.currentBorderEntity=null}this.centerPosition=o}finishDrawing(){if(this.tempPositions.length<1)return this.restoreRequestRenderModeIfNeeded(),null;const e=this.tempPositions[0],t=i.Cartographic.fromCartesian(e),n=i.Cartesian3.fromRadians(t.longitude,t.latitude,t.height||0);let r=0;if(this.tempPositions.length>=2)r=i.Cartesian3.distance(e,this.tempPositions[1]);else if(this.currentCircleEntity){const w=this.currentCircleEntity.ellipse;if(w){const g=w.semiMajorAxis?.getValue(i.JulianDate.now());r=typeof g=="number"?g:0}}if(r<1)return this.restoreRequestRenderModeIfNeeded(),null;let o=null,s=n;this.offsetHeight>0&&(s=i.Cartesian3.fromRadians(t.longitude,t.latitude,(t.height||0)+this.offsetHeight));const l=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):i.Color.BLUE,a=this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):i.Color.BLUE,c=this.drawOptions?.outlineWidth??2;if(c>1){o=this.entities.add({name:"绘制的圆",position:s,ellipse:{semiMajorAxis:r,semiMinorAxis:r,material:l.withAlpha(.3),outline:!1,heightReference:i.HeightReference.NONE}});const w=i.Cartographic.fromCartesian(s),g=w.height||0,b=.1,y=r,G=this.generateCirclePositions(w,y,g+b),C=[...G,G[0]],v=this.entities.add({name:"绘制的圆-边框",polyline:{positions:C,material:new i.ColorMaterialProperty(a),width:c,clampToGround:!(this.offsetHeight>0)}});o._borderEntity=v}else o=this.entities.add({name:"绘制的圆",position:s,ellipse:{semiMajorAxis:r,semiMinorAxis:r,material:l.withAlpha(.3),outline:!0,outlineColor:a,outlineWidth:c,heightReference:i.HeightReference.NONE}});o._groundPosition=n,o._radius=r,o&&(o._drawOptions=this.drawOptions,o._drawType=this.getDrawType(),this.drawOptions?.onClick&&(o._onClick=this.drawOptions.onClick));const d=Math.PI*r*r/1e6;if(d>0){const w=`面积: ${z(d)}`,g=this.createTotalLengthBillboardImage(w),b=this.entities.add({position:s,billboard:{image:g,pixelOffset:new i.ConstantProperty(new i.Cartesian2(0,-25)),heightReference:new i.ConstantProperty(this.offsetHeight>0?i.HeightReference.RELATIVE_TO_GROUND:i.HeightReference.NONE),verticalOrigin:new i.ConstantProperty(i.VerticalOrigin.BOTTOM),horizontalOrigin:new i.ConstantProperty(i.HorizontalOrigin.CENTER),scale:new i.ConstantProperty(1),disableDepthTestDistance:new i.ConstantProperty(Number.POSITIVE_INFINITY)}});b._groundPosition=n,this.tempLabelEntities.push(b)}this.tempEntities.forEach((w,g)=>{w&&this.entities.remove(w)}),this.tempEntities=[],this.tempPositions=[],this.currentCircleEntity=null,this.currentBorderEntity=null,this.centerPosition=null,this.originalDepthTestAgainstTerrain!==null&&(this.scene.globe.depthTestAgainstTerrain=this.originalDepthTestAgainstTerrain,this.originalDepthTestAgainstTerrain=null);const h=r/this.scene.globe.ellipsoid.maximumRadius,f=new i.Rectangle(t.longitude-h,t.latitude-h,t.longitude+h,t.latitude+h),m=i.Rectangle.subsample(f,this.scene.globe.ellipsoid),p={entity:o,type:"circle",positions:m,areaKm2:d};return this.callbacks.onMeasureComplete&&this.callbacks.onMeasureComplete(p),this.restoreRequestRenderModeIfNeeded(),this.callbacks.onDrawEnd&&this.callbacks.onDrawEnd(o),p}getDrawType(){return"circle"}generateCirclePositions(e,t,n,r=128){const s=e.latitude,l=e.longitude,a=t/6378137,c=[];for(let d=0;d<r;d++){const h=d/r*i.Math.TWO_PI,f=Math.sin(s),m=Math.cos(s),p=Math.sin(a),w=Math.cos(a),g=Math.sin(h),b=Math.cos(h),y=Math.asin(f*w+m*p*b),G=l+Math.atan2(g*p*m,w-f*Math.sin(y));c.push(i.Cartesian3.fromRadians(G,y,n))}return c}}class j{viewer;scene;entities;frustumPrimitives=[];drawMode=null;isDrawing=!1;tempPositions=[];tempEntities=[];tempLabelEntities=[];finishedEntities=[];finishedLabelEntities=[];finishedPointEntities=[];publicEntities=[];_doubleClickPending=!1;drawLine;drawPolygon;drawRectangle;drawCircle;currentDrawer=null;screenSpaceEventHandler=null;entityClickHandler=null;onDrawStartCallback=null;onDrawEndCallback=null;onEntityRemovedCallback=null;onMeasureCompleteCallback=null;offsetHeight=2;originalDepthTestAgainstTerrain=null;constructor(e){if(!e||!(e instanceof i.Viewer))throw new Error("Invalid Cesium Viewer instance provided.");this.viewer=e,this.scene=e.scene,this.entities=e.entities,this.updateOffsetHeight(),this.scene.globe.depthTestAgainstTerrain=!0;const t={onDrawStart:()=>{this.onDrawStartCallback&&this.onDrawStartCallback()},onDrawEnd:n=>{this.onDrawEndCallback&&this.onDrawEndCallback(n)},onEntityRemoved:n=>{this.onEntityRemovedCallback&&this.onEntityRemovedCallback(n)},onMeasureComplete:n=>{this.onMeasureCompleteCallback&&this.onMeasureCompleteCallback(n)}};this.drawLine=new S(e,t),this.drawPolygon=new X(e,t),this.drawRectangle=new B(e,t),this.drawCircle=new U(e,t);try{this.entityClickHandler=new i.ScreenSpaceEventHandler(this.scene.canvas),this.entityClickHandler.setInputAction(n=>{if(this.isDrawing)return;const r=this.scene.pick(n.position),o=r&&r.id;if(!o)return;const s=o._onClick;try{if(s){const a=o._groundPositions||o._groundPosition||void 0;s(o,o._drawType,a)}}catch(a){console.warn("entity onClick handler error",a)}const l=o._drawOptions;if(l?.selected)try{const a=l.selected;if(o._isSelected){const c=o._originalStyle;c&&(o.polyline&&c.material&&(o.polyline.material=c.material,o.polyline.width=c.width??o.polyline.width),o.polygon&&c.material&&(o.polygon.material=c.material,o.polygon.outlineColor=c.outlineColor??o.polygon.outlineColor,o.polygon.outlineWidth=c.outlineWidth??o.polygon.outlineWidth),o.rectangle&&c.material&&(o.rectangle.material=c.material,o.rectangle.outlineColor=c.outlineColor??o.rectangle.outlineColor,o.rectangle.outlineWidth=c.outlineWidth??o.rectangle.outlineWidth),o.ellipse&&c.material&&(o.ellipse.material=c.material,o.ellipse.outlineColor=c.outlineColor??o.ellipse.outlineColor,o.ellipse.outlineWidth=c.outlineWidth??o.ellipse.outlineWidth)),o._isSelected=!1}else{if(o._originalStyle={},o.polyline){o._originalStyle.material=o.polyline.material,o._originalStyle.width=o.polyline.width;const c=a?.color?i.Color.fromCssColorString(String(a.color)):i.Color.YELLOW;o.polyline.material=new i.ColorMaterialProperty(c),o.polyline.width=new i.ConstantProperty(a?.width??(o.polyline.width||5)+2)}if(o.polygon){o._originalStyle.material=o.polygon.material,o._originalStyle.outlineColor=o.polygon.outlineColor,o._originalStyle.outlineWidth=o.polygon.outlineWidth;const c=a?.color?i.Color.fromCssColorString(String(a.color)):i.Color.YELLOW;o.polygon.material=new i.ColorMaterialProperty(c.withAlpha(.5)),o.polygon.outlineColor=new i.ConstantProperty(a?.outlineColor?i.Color.fromCssColorString(String(a.outlineColor)):o.polygon.outlineColor),o.polygon.outlineWidth=new i.ConstantProperty(a?.outlineWidth??(o.polygon.outlineWidth||2))}if(o.rectangle){o._originalStyle.material=o.rectangle.material,o._originalStyle.outlineColor=o.rectangle.outlineColor,o._originalStyle.outlineWidth=o.rectangle.outlineWidth;const c=a?.color?i.Color.fromCssColorString(String(a.color)):i.Color.YELLOW;o.rectangle.material=new i.ColorMaterialProperty(c.withAlpha(.5)),o.rectangle.outlineColor=new i.ConstantProperty(a?.outlineColor?i.Color.fromCssColorString(String(a.outlineColor)):o.rectangle.outlineColor),o.rectangle.outlineWidth=new i.ConstantProperty(a?.outlineWidth??(o.rectangle.outlineWidth||2))}if(o.ellipse){o._originalStyle.material=o.ellipse.material,o._originalStyle.outlineColor=o.ellipse.outlineColor,o._originalStyle.outlineWidth=o.ellipse.outlineWidth;const c=a?.color?i.Color.fromCssColorString(String(a.color)):i.Color.YELLOW;o.ellipse.material=new i.ColorMaterialProperty(c.withAlpha(.5)),o.ellipse.outlineColor=new i.ConstantProperty(a?.outlineColor?i.Color.fromCssColorString(String(a.outlineColor)):o.ellipse.outlineColor),o.ellipse.outlineWidth=new i.ConstantProperty(a?.outlineWidth??(o.ellipse.outlineWidth||2))}o._isSelected=!0}}catch(a){console.warn("toggle selected style failed",a)}},i.ScreenSpaceEventType.LEFT_CLICK)}catch(n){console.warn("entity click handler init failed",n)}}handleSceneModeChanged(){const e=this.offsetHeight;this.updateOffsetHeight(),e!==this.offsetHeight&&this.updateFinishedEntitiesForModeChange()}updateOffsetHeight(){this.scene.mode===i.SceneMode.SCENE3D?this.offsetHeight=1:this.offsetHeight=0}startDrawingLine(e){this.startDrawing("line",e)}startDrawingPolygon(e){this.startDrawing("polygon",e)}startDrawingRectangle(e){this.startDrawing("rectangle",e)}startDrawingCircle(e){this.startDrawing("circle",e)}startDrawing(e,t){switch(this.endDrawingInternal(!1),this.drawMode=e,this.isDrawing=!0,this.tempPositions=[],this.tempEntities=[],this._doubleClickPending=!1,e){case"line":this.currentDrawer=this.drawLine;break;case"polygon":this.currentDrawer=this.drawPolygon;break;case"rectangle":this.currentDrawer=this.drawRectangle;break;case"circle":this.currentDrawer=this.drawCircle;break}this.currentDrawer&&this.currentDrawer.startDrawing(t),this.activateDrawingHandlers()}activateDrawingHandlers(){this.deactivateDrawingHandlers(),this.screenSpaceEventHandler=new i.ScreenSpaceEventHandler(this.scene.canvas),this.screenSpaceEventHandler.setInputAction(t=>{if(!this.isDrawing)return;if(this._doubleClickPending){this._doubleClickPending=!1;return}const n=this.pickGlobePosition(t.position);n&&this.addPoint(n)},i.ScreenSpaceEventType.LEFT_CLICK),this.screenSpaceEventHandler.setInputAction(()=>{!this.isDrawing||this.tempPositions.length===0||this.removeLastPoint()},i.ScreenSpaceEventType.RIGHT_CLICK),this.screenSpaceEventHandler.setInputAction(t=>{if(!this.isDrawing||this.tempPositions.length===0)return;const n=this.pickGlobePosition(t.endPosition);n&&this.updatePreview(n)},i.ScreenSpaceEventType.MOUSE_MOVE);const e=this.viewer.cesiumWidget.screenSpaceEventHandler.getInputAction(i.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);this.viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(i.ScreenSpaceEventType.LEFT_DOUBLE_CLICK),this.screenSpaceEventHandler.setInputAction(t=>{this.isDrawing&&(this._doubleClickPending=!0,this.finishDrawing(),e&&this.viewer.cesiumWidget.screenSpaceEventHandler.setInputAction(e,i.ScreenSpaceEventType.LEFT_DOUBLE_CLICK))},i.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)}pickGlobePosition(e){const t=this.viewer.camera.getPickRay(e);if(t&&this.scene.mode===i.SceneMode.SCENE3D&&this.scene.globe.tilesLoaded){const r=this.scene.globe.pick(t,this.scene);if(i.defined(r)&&Number.isFinite(r.x)&&Number.isFinite(r.y)&&Number.isFinite(r.z))return r}const n=this.viewer.camera.pickEllipsoid(e,this.scene.globe.ellipsoid);return n&&Number.isFinite(n.x)&&Number.isFinite(n.y)&&Number.isFinite(n.z)?n:null}addPoint(e){this.drawMode==="polygon"&&this.scene.mode===i.SceneMode.SCENE3D&&!this.scene.globe.tilesLoaded||this.currentDrawer&&(this.currentDrawer.addPoint(e),this.tempPositions=this.currentDrawer.tempPositions,this.tempEntities=this.currentDrawer.tempEntities,this.updateDrawingEntity())}removeLastPoint(){this.tempPositions.length>0&&(this.tempPositions.pop(),this.tempEntities.forEach(e=>{e&&this.entities.remove(e)}),this.tempEntities=[],this.tempLabelEntities.forEach(e=>{e&&this.entities.remove(e)}),this.tempLabelEntities=[],this.currentDrawer&&(this.currentDrawer.tempPositions=[...this.tempPositions],this.currentDrawer.tempEntities=[],this.currentDrawer.tempLabelEntities=[]),this.recreateRemainingEntities())}recreateRemainingEntities(){this.tempPositions.forEach(e=>{if(this.currentDrawer)this.currentDrawer.addPoint(e);else{const t=i.Cartographic.fromCartesian(e),n=i.Cartesian3.fromRadians(t.longitude,t.latitude,(t.height||0)+this.offsetHeight),r=this.entities.add({position:n,point:{pixelSize:8,color:i.Color.RED,outlineColor:i.Color.WHITE,outlineWidth:3,heightReference:i.HeightReference.NONE,scaleByDistance:new i.NearFarScalar(150,1,15e6,.5)}});this.tempEntities.push(r)}}),this.currentDrawer&&(this.tempPositions=this.currentDrawer.tempPositions,this.tempEntities=this.currentDrawer.tempEntities),this.updateDrawingEntity()}updatePreview(e){this.updateDrawingEntity(e)}updateDrawingEntity(e){if(!this.currentDrawer){console.warn("updateDrawingEntity called but currentDrawer is null. This should not happen.");return}this.currentDrawer.updateDrawingEntity(e),this.tempPositions=this.currentDrawer.tempPositions,this.tempEntities=this.currentDrawer.tempEntities,this.tempLabelEntities=this.currentDrawer.tempLabelEntities}finishDrawing(){if(!this.currentDrawer){console.warn("finishDrawing called but currentDrawer is null. This should not happen."),this.endDrawingInternal(!0);return}const e=this.currentDrawer.finishDrawing();try{this.currentDrawer.restoreRequestRenderModeIfNeeded&&this.currentDrawer.restoreRequestRenderModeIfNeeded()}catch{}e&&e.entity&&this.finishedEntities.push(e.entity),this.tempPositions=this.currentDrawer.tempPositions,this.tempEntities=this.currentDrawer.tempEntities,this.tempLabelEntities=this.currentDrawer.tempLabelEntities,this.finishedPointEntities=this.currentDrawer.finishedPointEntities,this.tempLabelEntities.forEach(t=>{this.finishedLabelEntities.push(t)}),this.tempLabelEntities=[],this.drawMode=null,this.isDrawing=!1,this.currentDrawer=null,this.deactivateDrawingHandlers()}endDrawingInternal(e){if(this.currentDrawer&&(this.currentDrawer.clearTempEntities(),this.tempPositions=this.currentDrawer.tempPositions,this.tempEntities=this.currentDrawer.tempEntities,this.tempLabelEntities=this.currentDrawer.tempLabelEntities),this.tempEntities.forEach(t=>{this.entities.remove(t)}),this.tempEntities=[],this.tempPositions=[],this.tempLabelEntities.forEach(t=>{this.entities.remove(t)}),this.tempLabelEntities=[],e){this.drawMode=null,this.isDrawing=!1,this.currentDrawer=null,this.deactivateDrawingHandlers(),this.originalDepthTestAgainstTerrain!==null&&(this.scene.globe.depthTestAgainstTerrain=this.originalDepthTestAgainstTerrain,this.originalDepthTestAgainstTerrain=null);try{this.currentDrawer&&this.currentDrawer.restoreRequestRenderModeIfNeeded&&this.currentDrawer.restoreRequestRenderModeIfNeeded()}catch{}}}endDrawing(){this.isDrawing?this.finishDrawing():this.endDrawingInternal(!0)}deactivateDrawingHandlers(){this.screenSpaceEventHandler&&(this.screenSpaceEventHandler.destroy(),this.screenSpaceEventHandler=null)}clearAll(){this.endDrawing(),this.clearAllPoints(),this.finishedEntities.forEach(e=>{this.entities.remove(e)}),this.finishedEntities=[],this.finishedLabelEntities.forEach(e=>{e&&this.entities.remove(e)}),this.finishedLabelEntities=[],this.publicEntities.forEach(e=>{e&&this.entities.remove(e)}),this.publicEntities=[],this.tempEntities.forEach(e=>{e&&this.entities.remove(e)}),this.tempEntities=[],this.tempLabelEntities.forEach(e=>{e&&e.label&&this.entities.remove(e)}),this.tempLabelEntities=[],this.tempPositions=[]}clearAllEntities(){this.endDrawing(),this.entities.removeAll(),this.finishedEntities=[],this.finishedLabelEntities=[],this.finishedPointEntities=[],this.publicEntities=[],this.tempEntities=[],this.tempLabelEntities=[],this.tempPositions=[]}clearAllPoints(){this.finishedPointEntities.forEach(t=>{t&&this.entities.remove(t)}),this.finishedPointEntities=[],this.tempEntities.forEach(t=>{t&&t.point&&this.entities.remove(t)});const e=this.entities.values;for(let t=e.length-1;t>=0;t--){const n=e[t];n&&n.point&&this.entities.remove(n)}}removeEntity(e){const t=this.finishedEntities.indexOf(e);t>-1&&(this.entities.remove(e),this.finishedEntities.splice(t,1),this.onEntityRemovedCallback&&this.onEntityRemovedCallback(e))}getFinishedEntities(){return[...this.finishedEntities]}createTotalLengthBillboardImage(e){const r="bold 16px 'Microsoft YaHei', 'PingFang SC', sans-serif",o=document.createElement("canvas"),s=o.getContext("2d");if(!s)return o.width=1,o.height=1,o;s.font=r;const a=s.measureText(e).width,c=20;return o.width=Math.ceil(a+24),o.height=Math.ceil(c+12),s.font=r,s.textBaseline="middle",s.textAlign="center",s.fillStyle="rgba(0, 0, 0, 0.8)",s.fillRect(0,0,o.width,o.height),s.fillStyle="#FFFFFF",s.fillText(e,o.width/2,o.height/2),o}createSegmentLengthBillboardImage(e){return this.createTotalLengthBillboardImage(e)}onMeasureComplete(e){this.onMeasureCompleteCallback=e}onDrawStart(e){this.onDrawStartCallback=e}onDrawEnd(e){this.onDrawEndCallback=e}onEntityRemoved(e){this.onEntityRemovedCallback=e}updateFinishedEntitiesForModeChange(){const e=this.offsetHeight>0;this.finishedEntities.forEach(t=>{if(t)if(t.polyline){const n=t._groundPositions;if(n&&n.length>0){const r=n.filter(o=>o&&Number.isFinite(o.x)&&Number.isFinite(o.y)&&Number.isFinite(o.z));if(r.length===0)return;if(e){const o=r.map(s=>{const l=i.Cartographic.fromCartesian(s);return i.Cartesian3.fromRadians(l.longitude,l.latitude,(l.height||0)+this.offsetHeight)});t.polyline.positions=new i.ConstantProperty(o),t.polyline.clampToGround=new i.ConstantProperty(!1)}else t.polyline.positions=new i.ConstantProperty(r),t.polyline.clampToGround=new i.ConstantProperty(!0)}}else if(t.polygon){const n=t._groundPositions;if(n&&n.length>0){const r=n.filter(o=>o&&Number.isFinite(o.x)&&Number.isFinite(o.y)&&Number.isFinite(o.z));if(r.length===0)return;if(e){const o=r.map(s=>{const l=i.Cartographic.fromCartesian(s);return i.Cartesian3.fromRadians(l.longitude,l.latitude,(l.height||0)+this.offsetHeight)});t.polygon.hierarchy=new i.ConstantProperty(new i.PolygonHierarchy(o)),t.polygon.heightReference=new i.ConstantProperty(i.HeightReference.NONE)}else t.polygon.hierarchy=new i.ConstantProperty(new i.PolygonHierarchy(r)),t.polygon.heightReference=new i.ConstantProperty(i.HeightReference.CLAMP_TO_GROUND)}}else t.rectangle&&t._groundRectangle&&(e?(t.rectangle.heightReference=new i.ConstantProperty(i.HeightReference.NONE),t.rectangle.extrudedHeight=new i.ConstantProperty(this.offsetHeight)):(t.rectangle.heightReference=new i.ConstantProperty(i.HeightReference.CLAMP_TO_GROUND),t.rectangle.extrudedHeight=void 0))}),this.finishedLabelEntities.forEach(t=>{if(!t)return;const n=t._groundPosition;if(n){if(t.label)if(e){const r=i.Cartographic.fromCartesian(n),o=i.Cartesian3.fromRadians(r.longitude,r.latitude,(r.height||0)+this.offsetHeight);t.position=new i.ConstantPositionProperty(o),t.label.heightReference=new i.ConstantProperty(i.HeightReference.RELATIVE_TO_GROUND)}else t.position=new i.ConstantPositionProperty(n),t.label.heightReference=new i.ConstantProperty(i.HeightReference.CLAMP_TO_GROUND);else if(t.billboard)if(e){const r=i.Cartographic.fromCartesian(n),o=i.Cartesian3.fromRadians(r.longitude,r.latitude,(r.height||0)+this.offsetHeight);t.position=new i.ConstantPositionProperty(o),t.billboard.heightReference=new i.ConstantProperty(i.HeightReference.RELATIVE_TO_GROUND)}else t.position=new i.ConstantPositionProperty(n),t.billboard.heightReference=new i.ConstantProperty(i.HeightReference.NONE)}}),this.finishedPointEntities.forEach(t=>{if(!t||!t.point)return;const n=t.position?.getValue(i.JulianDate.now());if(n){const r=i.Cartographic.fromCartesian(n),o=t._groundPosition;if(o)if(e){const s=i.Cartographic.fromCartesian(o),l=i.Cartesian3.fromRadians(s.longitude,s.latitude,(s.height||0)+this.offsetHeight);t.position=new i.ConstantPositionProperty(l),t.point.heightReference=new i.ConstantProperty(i.HeightReference.RELATIVE_TO_GROUND)}else t.position=new i.ConstantPositionProperty(o),t.point.heightReference=new i.ConstantProperty(i.HeightReference.CLAMP_TO_GROUND);else if(e){const s=i.Cartesian3.fromRadians(r.longitude,r.latitude,Math.max(0,(r.height||0)-this.offsetHeight)+this.offsetHeight);t.position=new i.ConstantPositionProperty(s),t.point.heightReference=new i.ConstantProperty(i.HeightReference.RELATIVE_TO_GROUND)}else{const s=i.Cartesian3.fromRadians(r.longitude,r.latitude,Math.max(0,(r.height||0)-this.offsetHeight));t.position=new i.ConstantPositionProperty(s),t.point.heightReference=new i.ConstantProperty(i.HeightReference.CLAMP_TO_GROUND)}}})}destroy(){if(this.deactivateDrawingHandlers(),this.entityClickHandler){try{this.entityClickHandler.destroy()}catch{}this.entityClickHandler=null}}}window.DrawHelper=j;function Z(){const e="57962be20a8da51ffd5d652bbc86325a,ef905e1aad18c1f8899ff8adb0453064,4b0c90d0a7ad9d80226e59a6a537507f".split(","),t=Math.floor(Math.random()*e.length);return e[t]}function me(u){const t=2*Math.PI*6378137,n=Math.max(10,Math.min(t,Math.abs(u))),r=Math.log2(t/(n*2))+1;return Math.max(1,Math.min(18,Math.round(r)))}function Q(u){const e=Math.max(1,Math.min(18,Math.round(u)));return 2*Math.PI*6378137/(2*Math.pow(2,e-1))}class q{viewer;initialCenter;getMapTypes;getCurrentMapTypeId;getToken;zoomCallback;onSceneModeChanged;constructor(e,t={}){this.viewer=e,this.initialCenter=t.initialCenter,this.getMapTypes=t.getMapTypes,this.getCurrentMapTypeId=t.getCurrentMapTypeId,this.getToken=t.getToken,this.zoomCallback=t.zoomCallback,this.onSceneModeChanged=t.onSceneModeChanged}setupCameraZoomLimitListener(){this.viewer.camera.changed.addEventListener(()=>{const t=this.getCurrentZoomLevel();let n=Math.max(1,Math.min(18,t)),r=18;const o=this.getMapTypes?this.getMapTypes():void 0,s=this.getCurrentMapTypeId?this.getCurrentMapTypeId():void 0;if(o&&s){const l=o.find(a=>a.id===s);if(l){const a=this.getToken?this.getToken():"";r=l.provider(a)[0]?.maximumLevel||18,n>r&&(n=r)}}(n===1||t>=r)&&this.setZoomLevel(n)})}getCurrentZoomLevel(){const e=this.viewer.camera.positionCartographic.height;return me(e)}setZoomLevel(e){try{const t=Math.max(1,Math.min(18,e)),n=Q(t);if(!isFinite(n)||isNaN(n)||n<=0){console.warn(`无效的目标高度: ${n},使用默认层级 ${t}`);return}let r;try{r=this.viewer.camera.positionCartographic.clone(),(!isFinite(r.longitude)||!isFinite(r.latitude))&&(r=i.Cartographic.fromDegrees(120.2052342,30.2489634))}catch(o){console.warn("获取当前相机位置失败,使用默认位置",o),r=i.Cartographic.fromDegrees(120.2052342,30.2489634)}this.viewer.camera.setView({destination:i.Cartesian3.fromRadians(r.longitude,r.latitude,n),orientation:{heading:this.viewer.camera.heading,pitch:this.viewer.camera.pitch,roll:this.viewer.camera.roll}})}catch(t){console.error("设置地图层级失败:",t);try{const n=Q(10),r=i.Cartographic.fromDegrees(120.2052342,30.2489634);this.viewer.camera.setView({destination:i.Cartesian3.fromRadians(r.longitude,r.latitude,n)})}catch(n){console.error("恢复地图层级失败:",n)}}}zoomIn(){const e=this.getCurrentZoomLevel(),t=this.viewer.camera.positionCartographic.height;let n=18;const r=this.getMapTypes?this.getMapTypes():void 0,o=this.getCurrentMapTypeId?this.getCurrentMapTypeId():void 0;if(r&&o){const a=r.find(c=>c.id===o);if(a){const c=this.getToken?this.getToken():"";if(n=a.provider(c)[0]?.maximumLevel||18,e>=n)return}}const s=e+1;this.setZoomLevel(s);const l=this.viewer.camera.positionCartographic.height;this.zoomCallback?.onZoomIn&&this.zoomCallback.onZoomIn(t,l,e)}zoomOut(){const e=this.getCurrentZoomLevel(),t=this.viewer.camera.positionCartographic.height;if(e<=1)return;const n=e-1;this.setZoomLevel(n);const r=this.viewer.camera.positionCartographic.height;this.zoomCallback?.onZoomOut&&this.zoomCallback.onZoomOut(t,r,e)}toggle2D3D(e){const t=this.viewer.scene,n=t.camera,o=t.mode===i.SceneMode.SCENE3D?i.SceneMode.SCENE2D:i.SceneMode.SCENE3D;e.innerHTML=o===i.SceneMode.SCENE3D?"3D":"2D";const s=t.canvas,l=new i.Cartesian2(s.clientWidth/2,s.clientHeight/2);let a=null;const c=n.getPickRay(l);if(c){const p=t.globe.pick(c,t);i.defined(p)&&(a=i.Cartographic.fromCartesian(p))}const d=n.positionCartographic.height,h=n.heading,f=n.pitch,m=n.roll;if(t.mode=o,this.onSceneModeChanged&&this.onSceneModeChanged(),a){const p=a.longitude,w=a.latitude;o===i.SceneMode.SCENE2D?n.setView({destination:i.Cartesian3.fromRadians(p,w,d),orientation:{heading:0,pitch:-Math.PI/2,roll:0}}):n.setView({destination:i.Cartesian3.fromRadians(p,w,d),orientation:{heading:h,pitch:f,roll:m}})}}resetLocation(){if(!this.initialCenter){console.warn("未设置初始中心点,无法执行复位操作");return}this.viewer.camera.flyTo({destination:i.Cartesian3.fromDegrees(this.initialCenter.longitude,this.initialCenter.latitude,this.initialCenter.height),duration:1})}setInitialCenter(e){this.initialCenter=e}getInitialCenter(){return this.initialCenter}toggleFullscreen(){this.isFullscreen()?this.exitFullscreen():this.enterFullscreen()}isFullscreen(){return!!(document.fullscreenElement||document.webkitFullscreenElement||document.msFullscreenElement)}enterFullscreen(){const e=this.viewer.container;e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullscreen?e.webkitRequestFullscreen():e.msRequestFullscreen&&e.msRequestFullscreen()}exitFullscreen(){document.exitFullscreen?document.exitFullscreen():document.webkitExitFullscreen?document.webkitExitFullscreen():document.msExitFullscreen&&document.msExitFullscreen()}}class we{viewer;drawHelper;measurementCallback;currentMode="none";constructor(e,t,n){this.viewer=e,this.drawHelper=t,this.measurementCallback=n}getMeasureMode(){return this.currentMode}setupDrawHelperCallbacks(){this.drawHelper.onMeasureComplete(e=>{this.measurementCallback&&(e.type==="line"&&this.measurementCallback.onDistanceComplete&&typeof e.distance=="number"?this.measurementCallback.onDistanceComplete(e.positions,e.distance):e.type==="polygon"&&this.measurementCallback.onAreaComplete&&typeof e.areaKm2=="number"&&this.measurementCallback.onAreaComplete(e.positions,e.areaKm2))}),this.drawHelper.onDrawStart(()=>{console.log("开始绘制"),this.measurementCallback?.onMeasurementStart&&this.measurementCallback.onMeasurementStart()}),this.drawHelper.onDrawEnd(e=>{e&&console.log("绘制完成",e),this.currentMode="none"}),this.drawHelper.onEntityRemoved(e=>{console.log("实体被移除",e)})}startAreaMeasurement(){this.currentMode="area",setTimeout(()=>{this.drawHelper.startDrawingPolygon()},50)}startDistanceMeasurement(){this.currentMode="distance",setTimeout(()=>{this.drawHelper.startDrawingLine()},50)}clearMeasurements(){this.currentMode="none",this.drawHelper.clearAll(),this.measurementCallback?.onClear&&this.measurementCallback.onClear()}}const pe=Z(),be="73.5577,18.1597,135.0882,53.5609",Ce={},xe=(u,e,t=pe)=>{const n={start:0,count:10,queryType:7,keyWord:u,mapBound:be,level:e?.defaultZoomLevel||15};return`http://api.tianditu.gov.cn/v2/search?postStr=${JSON.stringify(n)}&type=query&tk=${t}`};class J{viewer;toolbarElement;searchCallback;searchContainer=null;constructor(e,t,n){this.viewer=e,this.toolbarElement=t,this.searchCallback=n}setSearchCallback(e){this.searchCallback=e}toggleSearch(e){if(this.toolbarElement.querySelector(".search-container"))return;const n=e.offsetTop,r=document.createElement("div");r.className="search-container",r.style.cssText=`
2
2
  position: absolute;
3
3
  right: 100%;
4
4
  top: ${n}px;