@xingm/vmap-cesium-toolbar 0.0.2-alpha.10 → 0.0.2-alpha.11
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.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(v,E){typeof exports=="object"&&typeof module<"u"?E(exports,require("cesium")):typeof define=="function"&&define.amd?define(["exports","cesium"],E):(v=typeof globalThis<"u"?globalThis:v||self,E(v.VMapCesiumToolbar={},v.Cesium))})(this,(function(v,E){"use strict";function ge(c){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(c){for(const t in c)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(c,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>c[t]})}}return e.default=c,Object.freeze(e)}const n=ge(E);class Y{viewer;scene;entities;offsetHeight=0;originalDepthTestAgainstTerrain=null;originalRequestRenderMode=null;callbacks;tempPositions=[];tempEntities=[];tempLabelEntities=[];finishedPointEntities=[];drawOptions;getTempPositions(){return this.tempPositions}getTempEntities(){return this.tempEntities}getTempLabelEntities(){return this.tempLabelEntities}getFinishedPointEntities(){return this.finishedPointEntities}setTempPositions(e){this.tempPositions=e}setTempEntities(e){this.tempEntities=e}setTempLabelEntities(e){this.tempLabelEntities=e}addPointForHelper(e){this.addPoint(e)}clearTempEntitiesForHelper(){this.clearTempEntities()}clearTempPointEntitiesForHelper(){const e=[];this.tempEntities.forEach(t=>{t&&t.point?this.entities.remove(t):t&&e.push(t)}),this.tempEntities=e}removeLastPointAndRedraw(){if(this.tempPositions.length===0)return;const e=this.tempPositions.slice(0,this.tempPositions.length-1);this.clearTempEntities(),this.tempPositions=[],e.forEach(t=>{this.addPoint(t)}),this.updateDrawingEntity()}resolveColor(e){try{return e?e instanceof n.Color?e:n.Color.fromCssColorString(String(e)):n.Color.YELLOW}catch{return n.Color.YELLOW}}applySelectedStyleToEntity(e){j(e)}restoreOriginalStyleForEntity(e){const t=e;t._isSelected&&j(t)}constructor(e,t={}){this.viewer=e,this.scene=e.scene,this.entities=e.entities,this.callbacks=t,this.updateOffsetHeight()}updateOffsetHeight(){this.scene.mode===n.SceneMode.SCENE3D?this.offsetHeight=1:this.offsetHeight=0}pickGlobePosition(e){const t=this.viewer.camera.getPickRay(e);if(t&&this.scene.mode===n.SceneMode.SCENE3D&&this.scene.globe.tilesLoaded){const r=this.scene.globe.pick(t,this.scene);if(n.defined(r)&&Number.isFinite(r.x)&&Number.isFinite(r.y)&&Number.isFinite(r.z))return r}const i=this.viewer.camera.pickEllipsoid(e,this.scene.globe.ellipsoid);return i&&Number.isFinite(i.x)&&Number.isFinite(i.y)&&Number.isFinite(i.z)?i: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=n.Cartographic.fromCartesian(e),i=n.Cartesian3.fromRadians(t.longitude,t.latitude,(t.height||0)+this.offsetHeight),r=this.entities.add({position:i,point:{pixelSize:8,color:n.Color.RED,outlineColor:n.Color.WHITE,outlineWidth:3,heightReference:n.HeightReference.NONE,scaleByDistance:new n.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 l=s.measureText(e).width,h=20;return o.width=Math.ceil(l+24),o.height=Math.ceil(h+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 j(c){try{const t=c._drawOptions?.selected;if(!t)return;if(c._isSelected){const r=c._originalStyle;if(!r){c._isSelected=!1;return}c.polyline&&r.material&&(c.polyline.material=r.material,c.polyline.width=r.width??c.polyline.width),c.polygon&&r.material&&(c.polygon.material=r.material,c.polygon.outlineColor=r.outlineColor??c.polygon.outlineColor,c.polygon.outlineWidth=r.outlineWidth??c.polygon.outlineWidth),c.rectangle&&r.material&&(c.rectangle.material=r.material,c.rectangle.outlineColor=r.outlineColor??c.rectangle.outlineColor,c.rectangle.outlineWidth=r.outlineWidth??c.rectangle.outlineWidth),c.ellipse&&r.material&&(c.ellipse.material=r.material,c.ellipse.outlineColor=r.outlineColor??c.ellipse.outlineColor,c.ellipse.outlineWidth=r.outlineWidth??c.ellipse.outlineWidth),c._isSelected=!1;return}c._originalStyle||(c._originalStyle={},c.polyline&&(c._originalStyle.material=c.polyline.material,c._originalStyle.width=c.polyline.width),c.polygon&&(c._originalStyle.material=c.polygon.material,c._originalStyle.outlineColor=c.polygon.outlineColor,c._originalStyle.outlineWidth=c.polygon.outlineWidth),c.rectangle&&(c._originalStyle.material=c.rectangle.material,c._originalStyle.outlineColor=c.rectangle.outlineColor,c._originalStyle.outlineWidth=c.rectangle.outlineWidth),c.ellipse&&(c._originalStyle.material=c.ellipse.material,c._originalStyle.outlineColor=c.ellipse.outlineColor,c._originalStyle.outlineWidth=c.ellipse.outlineWidth));const i=r=>{try{return r?r instanceof n.Color?r:n.Color.fromCssColorString(String(r)):n.Color.YELLOW}catch{return n.Color.YELLOW}};if(c.polyline){const r=t.color?i(t.color):n.Color.YELLOW,o=t.width??(c.polyline.width||5)+2;c.polyline.material=new n.ColorMaterialProperty(r),c.polyline.width=new n.ConstantProperty(o)}if(c.polygon){const r=t.color?i(t.color):n.Color.YELLOW;c.polygon.material=new n.ColorMaterialProperty(r.withAlpha(.5)),c.polygon.outlineColor=new n.ConstantProperty(t.outlineColor?i(t.outlineColor):i("#ffffff")),c.polygon.outlineWidth=new n.ConstantProperty(t.outlineWidth??(c.polygon.outlineWidth||2))}if(c.rectangle){const r=t.color?i(t.color):n.Color.YELLOW;c.rectangle.material=new n.ColorMaterialProperty(r.withAlpha(.5)),c.rectangle.outlineColor=new n.ConstantProperty(t.outlineColor?i(t.outlineColor):i("#ffffff")),c.rectangle.outlineWidth=new n.ConstantProperty(t.outlineWidth??(c.rectangle.outlineWidth||2))}if(c.ellipse){const r=t.color?i(t.color):n.Color.YELLOW;c.ellipse.material=new n.ColorMaterialProperty(r.withAlpha(.5)),c.ellipse.outlineColor=new n.ConstantProperty(t.outlineColor?i(t.outlineColor):i("#ffffff")),c.ellipse.outlineWidth=new n.ConstantProperty(t.outlineWidth??(c.ellipse.outlineWidth||2))}c._isSelected=!0}catch(e){console.warn("toggleSelectedStyle failed",e)}}function P(c){return!!c&&Number.isFinite(c.x)&&Number.isFinite(c.y)&&Number.isFinite(c.z)}function I(c){return!isFinite(c)||isNaN(c)?"0.00 m":c>=1e3?`${(c/1e3).toFixed(2)} km`:`${c.toFixed(2)} m`}function R(c){return!isFinite(c)||isNaN(c)?"0.00 m²":c>=1?`${c.toFixed(2)} km²`:`${(c*1e6).toFixed(2)} m²`}function F(c,e){const t=n.Cartographic.fromCartesian(c),i=n.Cartographic.fromCartesian(e),r=Math.min(t.longitude,i.longitude),o=Math.max(t.longitude,i.longitude),s=Math.min(t.latitude,i.latitude),a=Math.max(t.latitude,i.latitude);return new n.Rectangle(r,s,o,a)}function me(c){const e=c.west,t=c.south,i=c.east,r=c.north,o=n.Cartesian3.distance(n.Cartesian3.fromRadians(e,t),n.Cartesian3.fromRadians(i,t)),s=n.Cartesian3.distance(n.Cartesian3.fromRadians(e,t),n.Cartesian3.fromRadians(e,r));return o*s/1e6}function z(c,e=n.Ellipsoid.WGS84){const t=c.filter(o=>P(o));if(t.length<3)return 0;let i=0;const r=t.length;for(let o=0;o<r;o++){const s=t[o],a=t[(o+1)%r];if(!P(s)||!P(a))return 0;const l=e.cartesianToCartographic(s),h=e.cartesianToCartographic(a);if(!l||!h||!Number.isFinite(l.longitude)||!Number.isFinite(l.latitude)||!Number.isFinite(h.longitude)||!Number.isFinite(h.latitude))return 0;i+=(h.longitude-l.longitude)*(2+Math.sin(l.latitude)+Math.sin(h.latitude))}return i=Math.abs(i*6378137*6378137/2),i/1e6}function pe(c){const e=c.filter(o=>P(o));if(e.length===0)return n.Cartesian3.ZERO;let t=0,i=0,r=0;for(let o=0;o<e.length;o++)t+=e[o].x,i+=e[o].y,r+=e[o].z;return new n.Cartesian3(t/e.length,i/e.length,r/e.length)}class X extends Y{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 i=this.offsetHeight>0?t.map(s=>{const a=n.Cartographic.fromCartesian(s);return n.Cartesian3.fromRadians(a.longitude,a.latitude,(a.height||0)+this.offsetHeight)}):t,r=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):n.Color.YELLOW,o=this.drawOptions?.strokeWidth??5;this.currentLineEntity&&this.tempEntities.indexOf(this.currentLineEntity)===-1&&(this.currentLineEntity=null,this.currentLinePositions=[]),this.currentLineEntity?(this.currentLineEntity.polyline.positions instanceof n.CallbackProperty?(this.currentLinePositions.length=0,this.currentLinePositions.push(...i)):(this.currentLinePositions=[...i],this.currentLineEntity.polyline.positions=new n.CallbackProperty(()=>this.currentLinePositions,!1)),this.currentLineEntity.polyline.material=new n.ColorMaterialProperty(r),this.currentLineEntity.polyline.width=new n.ConstantProperty(o)):(this.currentLinePositions=[...i],this.currentLineEntity=this.entities.add({polyline:{positions:new n.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(l=>P(l));if(e.length<2)return this.restoreRequestRenderModeIfNeeded(),null;const t=e.map(l=>{const h=n.Cartographic.fromCartesian(l);return n.Cartesian3.fromRadians(h.longitude,h.latitude,h.height||0)});let i=null,r=0;const o=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):n.Color.YELLOW,s=this.drawOptions?.strokeWidth??5;if(this.offsetHeight>0){const l=t.map(h=>{const d=n.Cartographic.fromCartesian(h);return n.Cartesian3.fromRadians(d.longitude,d.latitude,(d.height||0)+this.offsetHeight)});i=this.entities.add({name:"绘制的线",polyline:{positions:l,width:s,material:o,clampToGround:!1}}),i._groundPositions=t}else i=this.entities.add({name:"绘制的线",polyline:{positions:t,width:s,material:o,clampToGround:!0}}),i._groundPositions=t;i&&(i._drawOptions=this.drawOptions,i._drawType=this.getDrawType(),this.drawOptions?.onClick&&(i._onClick=this.drawOptions.onClick));for(let l=1;l<t.length;l++)r+=n.Cartesian3.distance(t[l-1],t[l]);this.tempLabelEntities.forEach(l=>{}),this.tempEntities.forEach(l=>{l&&this.entities.remove(l)}),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 a={entity:i,type:"line",positions:t,distance:r};return this.callbacks.onMeasureComplete&&this.callbacks.onMeasureComplete(a),this.restoreRequestRenderModeIfNeeded(),this.callbacks.onDrawEnd&&this.callbacks.onDrawEnd(i,a),a}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,i=this.currentSegmentLabels.length;if(i>t){for(let r=t;r<i;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],a=n.Cartesian3.distance(o,s);if(a>5){const l=n.Cartesian3.midpoint(o,s,new n.Cartesian3),h=n.Cartographic.fromCartesian(l),d=n.Cartesian3.fromRadians(h.longitude,h.latitude,h.height||0);let u=l;this.offsetHeight>0&&(u=n.Cartesian3.fromRadians(h.longitude,h.latitude,(h.height||0)+this.offsetHeight));const m=r%2===0?-25:25,w=I(a);if(r<this.currentSegmentLabels.length&&this.currentSegmentLabels[r].billboard){const g=this.currentSegmentLabels[r];if(g.position=new n.ConstantPositionProperty(u),g.billboard.pixelOffset=new n.ConstantProperty(new n.Cartesian2(0,m)),g._groundPosition=d,g._segmentText!==w){const f=this.createSegmentLengthBillboardImage(w);g.billboard.image=new n.ConstantProperty(f),g._segmentText=w}}else{const g=this.createSegmentLengthBillboardImage(w),p=this.entities.add({position:u,billboard:{image:g,pixelOffset:new n.ConstantProperty(new n.Cartesian2(0,m)),heightReference:new n.ConstantProperty(this.offsetHeight>0?n.HeightReference.RELATIVE_TO_GROUND:n.HeightReference.NONE),verticalOrigin:new n.ConstantProperty(n.VerticalOrigin.CENTER),horizontalOrigin:new n.ConstantProperty(n.HorizontalOrigin.CENTER),scale:new n.ConstantProperty(1),disableDepthTestDistance:new n.ConstantProperty(Number.POSITIVE_INFINITY)}});p._segmentText=w,p._groundPosition=d,this.currentSegmentLabels.push(p),this.tempLabelEntities.push(p)}}else if(r<this.currentSegmentLabels.length){const l=this.currentSegmentLabels[r];if(l){this.entities.remove(l);const h=this.tempLabelEntities.indexOf(l);h>-1&&this.tempLabelEntities.splice(h,1)}this.currentSegmentLabels.splice(r,1),r--}}}updateTotalLabel(){if(this.tempPositions.length>1){let e=0;for(let h=1;h<this.tempPositions.length;h++)e+=n.Cartesian3.distance(this.tempPositions[h-1],this.tempPositions[h]);const t=this.tempPositions[this.tempPositions.length-1],i=n.Cartographic.fromCartesian(t),r=n.Cartesian3.fromRadians(i.longitude,i.latitude,i.height||0);let o=r;this.offsetHeight>0&&(o=n.Cartesian3.fromRadians(i.longitude,i.latitude,(i.height||0)+this.offsetHeight));const a=`总长: ${I(e)}`,l=this.createTotalLengthBillboardImage(a);if(this.currentTotalLabel&&this.currentTotalLabel.billboard)this.currentTotalLabel.position=new n.ConstantPositionProperty(o),this.currentTotalLabel.billboard.image=new n.ConstantProperty(l),this.currentTotalLabel._groundPosition=r;else{const h=this.entities.add({position:o,billboard:{image:l,pixelOffset:new n.ConstantProperty(new n.Cartesian2(0,-35)),heightReference:new n.ConstantProperty(this.offsetHeight>0?n.HeightReference.RELATIVE_TO_GROUND:n.HeightReference.NONE),verticalOrigin:new n.ConstantProperty(n.VerticalOrigin.BOTTOM),horizontalOrigin:new n.ConstantProperty(n.HorizontalOrigin.CENTER),scale:new n.ConstantProperty(1),disableDepthTestDistance:new n.ConstantProperty(Number.POSITIVE_INFINITY)}});this.currentTotalLabel=h,this.currentTotalLabel._groundPosition=r,this.tempLabelEntities.push(h)}}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=n.Cartographic.fromDegrees(120.2052342,30.2489634,this.offsetHeight)}const t=n.Cartesian3.fromRadians(e.longitude,e.latitude,(e.height||0)+this.offsetHeight),i=this.entities.add({position:t,label:{text:"总长: 0.00 m",font:"bold 16px 'Microsoft YaHei', 'PingFang SC', sans-serif",fillColor:n.Color.WHITE,outlineColor:n.Color.BLACK,outlineWidth:2,style:n.LabelStyle.FILL_AND_OUTLINE,pixelOffset:new n.Cartesian2(0,-35),heightReference:n.HeightReference.RELATIVE_TO_GROUND,scale:1,showBackground:!0,backgroundPadding:new n.Cartesian2(6,3),backgroundColor:n.Color.BLACK.withAlpha(.8),disableDepthTestDistance:Number.POSITIVE_INFINITY,verticalOrigin:n.VerticalOrigin.BOTTOM,horizontalOrigin:n.HorizontalOrigin.CENTER,show:!1}});this.isTotalLabelWarmedUp=!0,requestAnimationFrame(()=>{try{this.entities.remove(i)}catch{}})}}class B extends Y{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===n.SceneMode.SCENE3D&&!this.scene.globe.tilesLoaded)return;const i=this.tempPositions.filter(o=>P(o)),r=e&&P(e)&&i.length>=2?[...i,e]:i;if(r.length>=3){const o=r.map(g=>n.Cartographic.fromCartesian(g)).filter(g=>g&&Number.isFinite(g.longitude)&&Number.isFinite(g.latitude));if(o.length<3){if(this.currentPolygonEntity){this.entities.remove(this.currentPolygonEntity);const g=this.tempEntities.indexOf(this.currentPolygonEntity);g>-1&&this.tempEntities.splice(g,1),this.currentPolygonEntity=null}if(this.currentBorderEntity){this.entities.remove(this.currentBorderEntity);const g=this.tempEntities.indexOf(this.currentBorderEntity);g>-1&&this.tempEntities.splice(g,1),this.currentBorderEntity=null}return}const s=o.map(g=>{const p=g.height||0,f=this.offsetHeight>0?this.offsetHeight:.1;return n.Cartesian3.fromRadians(g.longitude,g.latitude,p+f)}),a=n.HeightReference.NONE,l=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):n.Color.LIGHTGREEN.withAlpha(.3),h=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):n.Color.LIGHTGREEN,d=this.drawOptions?.strokeWidth??this.drawOptions?.outlineWidth??2,u=this.tempEntities.filter(g=>!!g?.polygon),m=this.tempEntities.filter(g=>{const p=g;return!!p?.polyline&&!p?.point&&!p?.polygon});(u.length>1||m.length>1)&&([...u,...m].forEach(g=>{this.entities.remove(g)}),this.tempEntities=this.tempEntities.filter(g=>{const p=g;return p?.point?!0:!(p?.polygon||p?.polyline&&!p?.polygon)}),this.currentPolygonEntity=null,this.currentBorderEntity=null),this.currentPolygonEntity&&this.tempEntities.indexOf(this.currentPolygonEntity)===-1&&(this.currentPolygonEntity=null),this.currentBorderEntity&&this.tempEntities.indexOf(this.currentBorderEntity)===-1&&(this.currentBorderEntity=null),this.currentPolygonEntity?(this.currentPolygonEntity.polygon.hierarchy=new n.ConstantProperty(new n.PolygonHierarchy(s)),this.currentPolygonEntity.polygon.heightReference=new n.ConstantProperty(a),this.currentPolygonEntity.polygon.material=new n.ColorMaterialProperty(l),this.currentPolygonEntity.polygon.outline=new n.ConstantProperty(!1)):(this.currentPolygonEntity=this.entities.add({polygon:{hierarchy:new n.ConstantProperty(new n.PolygonHierarchy(s)),material:new n.ColorMaterialProperty(l),outline:!1,heightReference:a}}),this.tempEntities.push(this.currentPolygonEntity));const w=s.slice();w.length>=2&&w.push(s[0]),this.currentBorderEntity&&this.currentBorderEntity.polyline?(this.currentBorderEntity.polyline.positions=new n.ConstantProperty(w),this.currentBorderEntity.polyline.width=new n.ConstantProperty(d),this.currentBorderEntity.polyline.material=new n.ColorMaterialProperty(h),this.currentBorderEntity.polyline.clampToGround=new n.ConstantProperty(!1)):(this.currentBorderEntity=this.entities.add({polyline:{positions:new n.ConstantProperty(w),width:d,material:new n.ColorMaterialProperty(h),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(u=>P(u));if(e.length<3)return this.restoreRequestRenderModeIfNeeded(),null;const t=e.map(u=>n.Cartographic.fromCartesian(u)).filter(u=>u&&Number.isFinite(u.longitude)&&Number.isFinite(u.latitude));if(t.length<3)return this.restoreRequestRenderModeIfNeeded(),null;const i=t.map(u=>n.Cartesian3.fromRadians(u.longitude,u.latitude,u.height||0));let r=null,o=null;const s=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):n.Color.LIGHTGREEN.withAlpha(.3),a=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):n.Color.LIGHTGREEN,l=this.drawOptions?.strokeWidth??this.drawOptions?.outlineWidth??2;if(this.offsetHeight>0){const u=i.map(w=>{const g=n.Cartographic.fromCartesian(w);return n.Cartesian3.fromRadians(g.longitude,g.latitude,(g.height||0)+this.offsetHeight)});r=this.entities.add({name:"绘制的多边形区域",polygon:{hierarchy:new n.PolygonHierarchy(u),material:new n.ColorMaterialProperty(s),outline:!1,heightReference:n.HeightReference.NONE}});const m=u.slice();m.length>=2&&m.push(u[0]),o=this.entities.add({polyline:{positions:m,width:l,material:new n.ColorMaterialProperty(a),clampToGround:!1}}),r._groundPositions=i,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 n.PolygonHierarchy(i),material:new n.ColorMaterialProperty(s),outline:!1,heightReference:n.HeightReference.NONE}});const u=i.slice();u.length>=2&&u.push(i[0]),o=this.entities.add({polyline:{positions:u,width:l,material:new n.ColorMaterialProperty(a),clampToGround:!0}}),r._groundPositions=i,r&&(r._drawOptions=this.drawOptions,r._drawType=this.getDrawType(),this.drawOptions?.onClick&&(r._onClick=this.drawOptions.onClick),o&&(r._borderEntity=o))}const h=z(i,this.scene.globe.ellipsoid);if(h>0){const u=pe(i),m=n.Cartographic.fromCartesian(u),w=n.Cartesian3.fromRadians(m.longitude,m.latitude,m.height||0);let g=w;this.offsetHeight>0&&(g=n.Cartesian3.fromRadians(m.longitude,m.latitude,(m.height||0)+this.offsetHeight));const p=`面积: ${R(h)}`,f=this.createTotalLengthBillboardImage(p),b=this.entities.add({position:g,billboard:{image:f,pixelOffset:new n.ConstantProperty(new n.Cartesian2(0,-25)),heightReference:new n.ConstantProperty(this.offsetHeight>0?n.HeightReference.RELATIVE_TO_GROUND:n.HeightReference.NONE),verticalOrigin:new n.ConstantProperty(n.VerticalOrigin.BOTTOM),horizontalOrigin:new n.ConstantProperty(n.HorizontalOrigin.CENTER),scale:new n.ConstantProperty(1),disableDepthTestDistance:new n.ConstantProperty(Number.POSITIVE_INFINITY)}});b._groundPosition=w,this.tempLabelEntities.push(b)}this.tempEntities.forEach(u=>{u&&this.entities.remove(u)}),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:i,areaKm2:z(i,this.scene.globe.ellipsoid)};return this.callbacks.onMeasureComplete&&this.callbacks.onMeasureComplete(d),this.restoreRequestRenderModeIfNeeded(),this.callbacks.onDrawEnd&&this.callbacks.onDrawEnd(r,d),d}clear(){if(this.currentPolygonEntity){this.entities.remove(this.currentPolygonEntity);const e=this.tempEntities.indexOf(this.currentPolygonEntity);e>-1&&this.tempEntities.splice(e,1),this.currentPolygonEntity=null}if(this.currentBorderEntity){this.entities.remove(this.currentBorderEntity);const e=this.tempEntities.indexOf(this.currentBorderEntity);e>-1&&this.tempEntities.splice(e,1),this.currentBorderEntity=null}}getDrawType(){return"polygon"}}class U extends Y{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 l=this.tempEntities.indexOf(this.currentRectangleEntity);l>-1&&this.tempEntities.splice(l,1),this.currentRectangleEntity=null}return}const i=F(t[0],t[1]),r=n.HeightReference.NONE,o=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):n.Color.GREEN,s=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):n.Color.DARKGREEN,a=this.drawOptions?.strokeWidth??this.drawOptions?.outlineWidth??1;this.currentRectangleEntity&&!this.entities.contains(this.currentRectangleEntity)&&(this.currentRectangleEntity=null),this.currentRectangleEntity?(this.currentRectangleEntity.rectangle.coordinates=new n.ConstantProperty(i),this.currentRectangleEntity.rectangle.heightReference=new n.ConstantProperty(r),this.currentRectangleEntity.rectangle.extrudedHeight=this.offsetHeight>0?new n.ConstantProperty(this.offsetHeight):void 0,this.currentRectangleEntity.rectangle.material=new n.ColorMaterialProperty(o.withAlpha(.5)),this.currentRectangleEntity.rectangle.outlineColor=new n.ConstantProperty(s),this.currentRectangleEntity.rectangle.outlineWidth=new n.ConstantProperty(a)):(this.currentRectangleEntity=this.entities.add({rectangle:{coordinates:i,material:o.withAlpha(.5),heightReference:r,extrudedHeight:this.offsetHeight>0?this.offsetHeight:void 0,outline:!0,outlineColor:s,outlineWidth:a}}),this.tempEntities.push(this.currentRectangleEntity))}finishDrawing(){if(this.tempPositions.length<2)return this.restoreRequestRenderModeIfNeeded(),null;const e=this.tempPositions.filter(m=>P(m));if(e.length<2)return this.restoreRequestRenderModeIfNeeded(),null;const t=e.map(m=>{const w=n.Cartographic.fromCartesian(m);return n.Cartesian3.fromRadians(w.longitude,w.latitude,w.height||0)}),i=F(t[0],t[1]);let r=null;const o=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):n.Color.GREEN,s=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):n.Color.DARKGREEN,a=this.drawOptions?.strokeWidth??this.drawOptions?.outlineWidth??1;this.offsetHeight>0?(r=this.entities.add({name:"绘制的矩形",rectangle:{coordinates:i,material:o.withAlpha(.5),heightReference:n.HeightReference.NONE,extrudedHeight:this.offsetHeight,outline:!0,outlineColor:s,outlineWidth:a}}),r._groundRectangle=i):(r=this.entities.add({name:"绘制的矩形",rectangle:{coordinates:i,material:o.withAlpha(.5),heightReference:n.HeightReference.NONE,outline:!0,outlineColor:s,outlineWidth:a}}),r._groundRectangle=i),r&&(r._drawOptions=this.drawOptions,r._drawType=this.getDrawType(),this.drawOptions?.onClick&&(r._onClick=this.drawOptions.onClick));const l=me(i);if(l>0){const m=n.Rectangle.center(i),w=n.Cartesian3.fromRadians(m.longitude,m.latitude,0);let g=w;this.offsetHeight>0&&(g=n.Cartesian3.fromRadians(m.longitude,m.latitude,this.offsetHeight));const p=`面积: ${R(l)}`,f=this.createTotalLengthBillboardImage(p),b=this.entities.add({position:g,billboard:{image:f,pixelOffset:new n.ConstantProperty(new n.Cartesian2(0,-25)),heightReference:new n.ConstantProperty(this.offsetHeight>0?n.HeightReference.RELATIVE_TO_GROUND:n.HeightReference.NONE),verticalOrigin:new n.ConstantProperty(n.VerticalOrigin.BOTTOM),horizontalOrigin:new n.ConstantProperty(n.HorizontalOrigin.CENTER),scale:new n.ConstantProperty(1),disableDepthTestDistance:new n.ConstantProperty(Number.POSITIVE_INFINITY)}});b._groundPosition=w,this.tempLabelEntities.push(b)}this.tempEntities.forEach(m=>{m&&this.entities.remove(m)}),this.tempEntities=[],this.tempPositions=[],this.currentRectangleEntity=null,this.originalDepthTestAgainstTerrain!==null&&(this.scene.globe.depthTestAgainstTerrain=this.originalDepthTestAgainstTerrain,this.originalDepthTestAgainstTerrain=null);const h=n.Rectangle.subsample(i,this.scene.globe.ellipsoid),d=(()=>{if(h.length>1){const m=h[0],w=h[h.length-1];if(n.Cartesian3.equalsEpsilon(m,w,n.Math.EPSILON9))return h.slice(0,h.length-1)}return h})(),u={entity:r,type:"rectangle",positions:d,areaKm2:l};return this.callbacks.onMeasureComplete&&this.callbacks.onMeasureComplete(u),this.restoreRequestRenderModeIfNeeded(),this.callbacks.onDrawEnd&&this.callbacks.onDrawEnd(r,u),u}getDrawType(){return"rectangle"}}class Z extends Y{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 u=this.tempEntities.indexOf(this.currentCircleEntity);u>-1&&this.tempEntities.splice(u,1),this.currentCircleEntity=null}return}if(!e)return;const t=this.tempPositions[0],i=n.Cartesian3.distance(t,e);if(i<1)return;const r=n.Cartographic.fromCartesian(t),o=n.Cartesian3.fromRadians(r.longitude,r.latitude,r.height||0);let s=o;this.offsetHeight>0&&(s=n.Cartesian3.fromRadians(r.longitude,r.latitude,(r.height||0)+this.offsetHeight));const a=i/this.scene.globe.ellipsoid.maximumRadius;new n.Rectangle(r.longitude-a,r.latitude-a,r.longitude+a,r.latitude+a);const l=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):n.Color.BLUE,h=this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):n.Color.BLUE,d=this.drawOptions?.outlineWidth??2;if(this.currentCircleEntity&&!this.entities.contains(this.currentCircleEntity)&&(this.currentCircleEntity=null),this.currentBorderEntity&&!this.entities.contains(this.currentBorderEntity)&&(this.currentBorderEntity=null),this.currentCircleEntity?(this.currentCircleEntity.ellipse.semiMajorAxis=new n.ConstantProperty(i),this.currentCircleEntity.ellipse.semiMinorAxis=new n.ConstantProperty(i),this.currentCircleEntity.position=new n.ConstantPositionProperty(s),this.currentCircleEntity.ellipse.material=new n.ColorMaterialProperty(l.withAlpha(.3)),this.currentCircleEntity.ellipse.outline=new n.ConstantProperty(d<=1),this.currentCircleEntity.ellipse.outlineColor=new n.ConstantProperty(h),this.currentCircleEntity.ellipse.outlineWidth=new n.ConstantProperty(d<=1?d:1)):(this.currentCircleEntity=this.entities.add({position:s,ellipse:{semiMajorAxis:i,semiMinorAxis:i,material:l.withAlpha(.3),outline:d<=1,outlineColor:h,outlineWidth:d<=1?d:1,heightReference:n.HeightReference.NONE}}),this.tempEntities.push(this.currentCircleEntity)),d>1){const u=n.Cartographic.fromCartesian(s),m=u.height||0,w=.1,g=i,p=this.generateCirclePositions(u,g,m+w),f=[...p,p[0]];this.currentBorderEntity&&this.currentBorderEntity.polyline?(this.currentBorderEntity.polyline.positions=new n.ConstantProperty(f),this.currentBorderEntity.polyline.material=new n.ColorMaterialProperty(h),this.currentBorderEntity.polyline.width=new n.ConstantProperty(d),this.currentBorderEntity.polyline.clampToGround=new n.ConstantProperty(!1)):(this.currentBorderEntity=this.entities.add({polyline:{positions:f,material:new n.ColorMaterialProperty(h),width:d,clampToGround:!1}}),this.tempEntities.push(this.currentBorderEntity))}else if(this.currentBorderEntity){this.entities.remove(this.currentBorderEntity);const u=this.tempEntities.indexOf(this.currentBorderEntity);u>-1&&this.tempEntities.splice(u,1),this.currentBorderEntity=null}this.centerPosition=o}finishDrawing(){if(this.tempPositions.length<1)return this.restoreRequestRenderModeIfNeeded(),null;const e=this.tempPositions[0],t=n.Cartographic.fromCartesian(e),i=n.Cartesian3.fromRadians(t.longitude,t.latitude,t.height||0);let r=0;if(this.tempPositions.length>=2)r=n.Cartesian3.distance(e,this.tempPositions[1]);else if(this.currentCircleEntity){const f=this.currentCircleEntity.ellipse;if(f){const b=f.semiMajorAxis?.getValue(n.JulianDate.now());r=typeof b=="number"?b:0}}if(r<1)return this.restoreRequestRenderModeIfNeeded(),null;let o=null,s=i;this.offsetHeight>0&&(s=n.Cartesian3.fromRadians(t.longitude,t.latitude,(t.height||0)+this.offsetHeight));const a=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):n.Color.BLUE,l=this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):n.Color.BLUE,h=this.drawOptions?.outlineWidth??2;if(h>1){o=this.entities.add({name:"绘制的圆",position:s,ellipse:{semiMajorAxis:r,semiMinorAxis:r,material:a.withAlpha(.3),outline:!1,heightReference:n.HeightReference.NONE}});const f=n.Cartographic.fromCartesian(s),b=f.height||0,C=.1,G=r,y=this.generateCirclePositions(f,G,b+C),x=[...y,y[0]],D=this.entities.add({name:"绘制的圆-边框",polyline:{positions:x,material:new n.ColorMaterialProperty(l),width:h,clampToGround:!(this.offsetHeight>0)}});o._borderEntity=D}else o=this.entities.add({name:"绘制的圆",position:s,ellipse:{semiMajorAxis:r,semiMinorAxis:r,material:a.withAlpha(.3),outline:!0,outlineColor:l,outlineWidth:h,heightReference:n.HeightReference.NONE}});o._groundPosition=i,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 f=`面积: ${R(d)}`,b=this.createTotalLengthBillboardImage(f),C=this.entities.add({position:s,billboard:{image:b,pixelOffset:new n.ConstantProperty(new n.Cartesian2(0,-25)),heightReference:new n.ConstantProperty(this.offsetHeight>0?n.HeightReference.RELATIVE_TO_GROUND:n.HeightReference.NONE),verticalOrigin:new n.ConstantProperty(n.VerticalOrigin.BOTTOM),horizontalOrigin:new n.ConstantProperty(n.HorizontalOrigin.CENTER),scale:new n.ConstantProperty(1),disableDepthTestDistance:new n.ConstantProperty(Number.POSITIVE_INFINITY)}});C._groundPosition=i,this.tempLabelEntities.push(C)}this.tempEntities.forEach((f,b)=>{f&&this.entities.remove(f)}),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 u=r/this.scene.globe.ellipsoid.maximumRadius,m=new n.Rectangle(t.longitude-u,t.latitude-u,t.longitude+u,t.latitude+u),w=n.Rectangle.subsample(m,this.scene.globe.ellipsoid),g=(()=>{if(w.length>1){const f=w[0],b=w[w.length-1];if(n.Cartesian3.equalsEpsilon(f,b,n.Math.EPSILON9))return w.slice(0,w.length-1)}return w})(),p={entity:o,type:"circle",positions:g,areaKm2:d};return this.callbacks.onMeasureComplete&&this.callbacks.onMeasureComplete(p),this.restoreRequestRenderModeIfNeeded(),this.callbacks.onDrawEnd&&this.callbacks.onDrawEnd(o,p),p}getDrawType(){return"circle"}generateCirclePositions(e,t,i,r=128){const s=e.latitude,a=e.longitude,l=t/6378137,h=[];for(let d=0;d<r;d++){const u=d/r*n.Math.TWO_PI,m=Math.sin(s),w=Math.cos(s),g=Math.sin(l),p=Math.cos(l),f=Math.sin(u),b=Math.cos(u),C=Math.asin(m*p+w*g*b),G=a+Math.atan2(f*g*w,p-m*Math.sin(C));h.push(n.Cartesian3.fromRadians(G,C,i))}return h}}class M{viewer;scene;entities;drawMode=null;isDrawing=!1;tempPositions=[];tempEntities=[];tempLabelEntities=[];finishedEntities=[];finishedLabelEntities=[];finishedPointEntities=[];publicEntities=[];_doubleClickPending=!1;lastPreviewPosition=null;static activeDrawingHelper=null;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 n.Viewer))throw new Error("Invalid Cesium Viewer instance provided.");this.viewer=e,this.scene=e.scene,this.entities=e.entities,this.updateOffsetHeight();const t={onDrawStart:()=>{this.onDrawStartCallback&&this.onDrawStartCallback()},onDrawEnd:i=>{this.onDrawEndCallback&&this.onDrawEndCallback(i)},onEntityRemoved:i=>{this.onEntityRemovedCallback&&this.onEntityRemovedCallback(i)},onMeasureComplete:i=>{this.onMeasureCompleteCallback&&this.onMeasureCompleteCallback(i)}};this.drawLine=new X(e,t),this.drawPolygon=new B(e,t),this.drawRectangle=new U(e,t),this.drawCircle=new Z(e,t);try{this.entityClickHandler=new n.ScreenSpaceEventHandler(this.scene.canvas),this.entityClickHandler.setInputAction(i=>{if(this.isDrawing)return;const r=this.scene.pick(i.position),o=r&&r.id;if(!o)return;const s=o;if(!(s._drawType!==void 0))return;const l=s._onClick;try{if(l){const d=s._groundPositions||s._groundPosition||void 0,u=Array.isArray(d)?d:d?[d]:void 0;l(s,s._drawType,u)}}catch(d){console.warn("entity onClick handler error",d)}s._drawOptions?.selected&&j(s)},n.ScreenSpaceEventType.LEFT_CLICK)}catch(i){console.warn("entity click handler init failed",i)}}handleSceneModeChanged(){const e=this.offsetHeight;this.updateOffsetHeight(),e!==this.offsetHeight&&this.updateFinishedEntitiesForModeChange()}updateOffsetHeight(){this.scene.mode===n.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){const i=M.activeDrawingHelper;switch(i&&i!==this&&i.cancelDrawing(),this.endDrawingInternal(!1),this.drawMode=e,this.isDrawing=!0,this.lastPreviewPosition=null,M.activeDrawingHelper=this,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 n.ScreenSpaceEventHandler(this.scene.canvas),this.screenSpaceEventHandler.setInputAction(t=>{if(!this.isDrawing)return;if(this._doubleClickPending){this._doubleClickPending=!1;return}const i=this.pickGlobePosition(t.position);i&&this.addPoint(i)},n.ScreenSpaceEventType.LEFT_CLICK),this.screenSpaceEventHandler.setInputAction(()=>{!this.isDrawing||this.tempPositions.length===0||this.removeLastPoint()},n.ScreenSpaceEventType.RIGHT_CLICK),this.screenSpaceEventHandler.setInputAction(t=>{if(!this.isDrawing||this.tempPositions.length===0)return;const i=this.pickGlobePosition(t.endPosition);i&&this.updatePreview(i)},n.ScreenSpaceEventType.MOUSE_MOVE);const e=this.viewer.cesiumWidget.screenSpaceEventHandler.getInputAction(n.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);this.viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(n.ScreenSpaceEventType.LEFT_DOUBLE_CLICK),this.screenSpaceEventHandler.setInputAction(t=>{this.isDrawing&&(this._doubleClickPending=!0,this.finishDrawing(),e&&this.viewer.cesiumWidget.screenSpaceEventHandler.setInputAction(e,n.ScreenSpaceEventType.LEFT_DOUBLE_CLICK))},n.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)}pickGlobePosition(e){const t=this.viewer.camera.getPickRay(e);if(t&&this.scene.mode===n.SceneMode.SCENE3D&&this.scene.globe.tilesLoaded){const r=this.scene.globe.pick(t,this.scene);if(n.defined(r)&&Number.isFinite(r.x)&&Number.isFinite(r.y)&&Number.isFinite(r.z))return r}const i=this.viewer.camera.pickEllipsoid(e,this.scene.globe.ellipsoid);return i&&Number.isFinite(i.x)&&Number.isFinite(i.y)&&Number.isFinite(i.z)?i:null}addPoint(e){this.drawMode==="polygon"&&this.scene.mode===n.SceneMode.SCENE3D&&!this.scene.globe.tilesLoaded||this.currentDrawer&&(this.currentDrawer.addPointForHelper(e),this.tempPositions=this.currentDrawer.getTempPositions(),this.tempEntities=this.currentDrawer.getTempEntities(),this.updateDrawingEntity())}removeLastPoint(){if(!this.currentDrawer)return;const e=this.currentDrawer.getTempPositions();!e||e.length===0||(this.currentDrawer.removeLastPointAndRedraw(),this.tempPositions=this.currentDrawer.getTempPositions(),this.tempEntities=this.currentDrawer.getTempEntities(),this.tempLabelEntities=this.currentDrawer.getTempLabelEntities(),this.lastPreviewPosition&&this.isDrawing&&this.updateDrawingEntity(this.lastPreviewPosition))}updatePreview(e){this.lastPreviewPosition=e.clone(),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.getTempPositions(),this.tempEntities=this.currentDrawer.getTempEntities(),this.tempLabelEntities=this.currentDrawer.getTempLabelEntities()}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.getTempPositions(),this.tempEntities=this.currentDrawer.getTempEntities(),this.tempLabelEntities=this.currentDrawer.getTempLabelEntities(),this.finishedPointEntities=this.currentDrawer.getFinishedPointEntities(),this.tempLabelEntities.forEach(t=>{this.finishedLabelEntities.push(t)}),this.tempLabelEntities=[],this.drawMode=null,this.isDrawing=!1,this.lastPreviewPosition=null,this.currentDrawer=null,this.deactivateDrawingHandlers(),M.activeDrawingHelper===this&&(M.activeDrawingHelper=null)}endDrawingInternal(e){if(this.currentDrawer&&(this.currentDrawer.clearTempEntitiesForHelper(),this.tempPositions=this.currentDrawer.getTempPositions(),this.tempEntities=this.currentDrawer.getTempEntities(),this.tempLabelEntities=this.currentDrawer.getTempLabelEntities()),this.tempEntities=[],this.tempLabelEntities=[],this.tempPositions=[],e){this.drawMode=null,this.isDrawing=!1,this.lastPreviewPosition=null,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{}M.activeDrawingHelper===this&&(M.activeDrawingHelper=null)}}endDrawing(){this.isDrawing?this.finishDrawing():this.endDrawingInternal(!0)}cancelDrawing(){this.isDrawing&&this.endDrawingInternal(!0)}deactivateDrawingHandlers(){this.screenSpaceEventHandler&&(this.screenSpaceEventHandler.destroy(),this.screenSpaceEventHandler=null)}clearAll(){this.endDrawing(),this.clearAllPoints(),this.finishedEntities.forEach(e=>{if(!e)return;const t=e._borderEntity;t&&this.entities.remove(t),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=[],this.tempLabelEntities=[],this.tempPositions=[],this.drawPolygon&&this.drawPolygon.clear()}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.currentDrawer&&(this.currentDrawer.clearTempPointEntitiesForHelper(),this.tempEntities=this.currentDrawer.getTempEntities());const e=this.entities.values;for(let t=e.length-1;t>=0;t--){const i=e[t];i&&i.point&&this.entities.remove(i)}}removeEntity(e){const t=this.finishedEntities.indexOf(e);if(t>-1){const i=e._borderEntity;i&&this.entities.remove(i),this.entities.remove(e),this.finishedEntities.splice(t,1),this.onEntityRemovedCallback&&this.onEntityRemovedCallback(e)}}getFinishedEntities(){return[...this.finishedEntities]}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 i=t._groundPositions;if(i&&i.length>0){const r=i.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 a=n.Cartographic.fromCartesian(s);return n.Cartesian3.fromRadians(a.longitude,a.latitude,(a.height||0)+this.offsetHeight)});t.polyline.positions=new n.ConstantProperty(o),t.polyline.clampToGround=new n.ConstantProperty(!1)}else t.polyline.positions=new n.ConstantProperty(r),t.polyline.clampToGround=new n.ConstantProperty(!0)}}else if(t.polygon){const i=t._groundPositions;if(i&&i.length>0){const r=i.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 a=n.Cartographic.fromCartesian(s);return n.Cartesian3.fromRadians(a.longitude,a.latitude,(a.height||0)+this.offsetHeight)});t.polygon.hierarchy=new n.ConstantProperty(new n.PolygonHierarchy(o)),t.polygon.heightReference=new n.ConstantProperty(n.HeightReference.NONE)}else t.polygon.hierarchy=new n.ConstantProperty(new n.PolygonHierarchy(r)),t.polygon.heightReference=new n.ConstantProperty(n.HeightReference.CLAMP_TO_GROUND)}}else t.rectangle&&t._groundRectangle&&(e?(t.rectangle.heightReference=new n.ConstantProperty(n.HeightReference.NONE),t.rectangle.extrudedHeight=new n.ConstantProperty(this.offsetHeight)):(t.rectangle.heightReference=new n.ConstantProperty(n.HeightReference.CLAMP_TO_GROUND),t.rectangle.extrudedHeight=void 0))}),this.finishedLabelEntities.forEach(t=>{if(!t)return;const i=t._groundPosition;if(i){if(t.label)if(e){const r=n.Cartographic.fromCartesian(i),o=n.Cartesian3.fromRadians(r.longitude,r.latitude,(r.height||0)+this.offsetHeight);t.position=new n.ConstantPositionProperty(o),t.label.heightReference=new n.ConstantProperty(n.HeightReference.RELATIVE_TO_GROUND)}else t.position=new n.ConstantPositionProperty(i),t.label.heightReference=new n.ConstantProperty(n.HeightReference.CLAMP_TO_GROUND);else if(t.billboard)if(e){const r=n.Cartographic.fromCartesian(i),o=n.Cartesian3.fromRadians(r.longitude,r.latitude,(r.height||0)+this.offsetHeight);t.position=new n.ConstantPositionProperty(o),t.billboard.heightReference=new n.ConstantProperty(n.HeightReference.RELATIVE_TO_GROUND)}else t.position=new n.ConstantPositionProperty(i),t.billboard.heightReference=new n.ConstantProperty(n.HeightReference.NONE)}}),this.finishedPointEntities.forEach(t=>{if(!t||!t.point)return;const i=t.position?.getValue(n.JulianDate.now());if(i){const r=n.Cartographic.fromCartesian(i),o=t._groundPosition;if(o)if(e){const s=n.Cartographic.fromCartesian(o),a=n.Cartesian3.fromRadians(s.longitude,s.latitude,(s.height||0)+this.offsetHeight);t.position=new n.ConstantPositionProperty(a),t.point.heightReference=new n.ConstantProperty(n.HeightReference.RELATIVE_TO_GROUND)}else t.position=new n.ConstantPositionProperty(o),t.point.heightReference=new n.ConstantProperty(n.HeightReference.CLAMP_TO_GROUND);else if(e){const s=n.Cartesian3.fromRadians(r.longitude,r.latitude,Math.max(0,(r.height||0)-this.offsetHeight)+this.offsetHeight);t.position=new n.ConstantPositionProperty(s),t.point.heightReference=new n.ConstantProperty(n.HeightReference.RELATIVE_TO_GROUND)}else{const s=n.Cartesian3.fromRadians(r.longitude,r.latitude,Math.max(0,(r.height||0)-this.offsetHeight));t.position=new n.ConstantPositionProperty(s),t.point.heightReference=new n.ConstantProperty(n.HeightReference.CLAMP_TO_GROUND)}}})}destroy(){if(this.deactivateDrawingHandlers(),this.entityClickHandler){try{this.entityClickHandler.destroy()}catch{}this.entityClickHandler=null}}}window.DrawHelper=M;function Q(){const e="2cca1367384c44b8b0196b47108b2813,57962be20a8da51ffd5d652bbc86325a,ef905e1aad18c1f8899ff8adb0453064,4b0c90d0a7ad9d80226e59a6a537507f,ffe26eb6d4ed64558d651e2aa0f47233".split(","),t=Math.floor(Math.random()*e.length);return e[t]}function we(c){const t=2*Math.PI*6378137,i=Math.max(10,Math.min(t,Math.abs(c))),r=Math.log2(t/(i*2))+1;return Math.max(1,Math.min(18,Math.round(r)))}function q(c){const e=Math.max(1,Math.min(18,Math.round(c)));return 2*Math.PI*6378137/(2*Math.pow(2,e-1))}class J{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 i=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 a=o.find(l=>l.id===s);if(a){const l=this.getToken?this.getToken():"";r=a.provider(l)[0]?.maximumLevel||18,i>r&&(i=r)}}(i===1||t>=r)&&this.setZoomLevel(i)})}getCurrentZoomLevel(){const e=this.viewer.camera.positionCartographic.height;return we(e)}setZoomLevel(e){try{const t=Math.max(1,Math.min(18,e)),i=q(t);if(!isFinite(i)||isNaN(i)||i<=0){console.warn(`无效的目标高度: ${i},使用默认层级 ${t}`);return}let r;try{r=this.viewer.camera.positionCartographic.clone(),(!isFinite(r.longitude)||!isFinite(r.latitude))&&(r=n.Cartographic.fromDegrees(120.2052342,30.2489634))}catch(o){console.warn("获取当前相机位置失败,使用默认位置",o),r=n.Cartographic.fromDegrees(120.2052342,30.2489634)}this.viewer.camera.setView({destination:n.Cartesian3.fromRadians(r.longitude,r.latitude,i),orientation:{heading:this.viewer.camera.heading,pitch:this.viewer.camera.pitch,roll:this.viewer.camera.roll}})}catch(t){console.error("设置地图层级失败:",t);try{const i=q(10),r=n.Cartographic.fromDegrees(120.2052342,30.2489634);this.viewer.camera.setView({destination:n.Cartesian3.fromRadians(r.longitude,r.latitude,i)})}catch(i){console.error("恢复地图层级失败:",i)}}}zoomIn(){const e=this.getCurrentZoomLevel(),t=this.viewer.camera.positionCartographic.height;let i=18;const r=this.getMapTypes?this.getMapTypes():void 0,o=this.getCurrentMapTypeId?this.getCurrentMapTypeId():void 0;if(r&&o){const l=r.find(h=>h.id===o);if(l){const h=this.getToken?this.getToken():"";if(i=l.provider(h)[0]?.maximumLevel||18,e>=i)return}}const s=e+1;this.setZoomLevel(s);const a=this.viewer.camera.positionCartographic.height;this.zoomCallback?.onZoomIn&&this.zoomCallback.onZoomIn(t,a,e)}zoomOut(){const e=this.getCurrentZoomLevel(),t=this.viewer.camera.positionCartographic.height;if(e<=1)return;const i=e-1;this.setZoomLevel(i);const r=this.viewer.camera.positionCartographic.height;this.zoomCallback?.onZoomOut&&this.zoomCallback.onZoomOut(t,r,e)}toggle2D3D(e){const t=this.viewer.scene,i=t.camera,o=t.mode===n.SceneMode.SCENE3D?n.SceneMode.SCENE2D:n.SceneMode.SCENE3D;e.innerHTML=o===n.SceneMode.SCENE3D?"3D":"2D";const s=t.canvas,a=new n.Cartesian2(s.clientWidth/2,s.clientHeight/2);let l=null;const h=i.getPickRay(a);if(h){const g=t.globe.pick(h,t);n.defined(g)&&(l=n.Cartographic.fromCartesian(g))}const d=i.positionCartographic.height,u=i.heading,m=i.pitch,w=i.roll;if(t.mode=o,this.onSceneModeChanged&&this.onSceneModeChanged(),l){const g=l.longitude,p=l.latitude;o===n.SceneMode.SCENE2D?i.setView({destination:n.Cartesian3.fromRadians(g,p,d),orientation:{heading:0,pitch:-Math.PI/2,roll:0}}):i.setView({destination:n.Cartesian3.fromRadians(g,p,d),orientation:{heading:u,pitch:m,roll:w}})}}resetLocation(){if(!this.initialCenter){console.warn("未设置初始中心点,无法执行复位操作");return}this.viewer.camera.flyTo({destination:n.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 be{viewer;drawHelper;measurementCallback;currentMode="none";constructor(e,t,i){this.viewer=e,this.drawHelper=t,this.measurementCallback=i}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.drawHelper.cancelDrawing?.(),this.currentMode="area",setTimeout(()=>{this.drawHelper.startDrawingPolygon()},50)}startDistanceMeasurement(){this.drawHelper.cancelDrawing?.(),this.currentMode="distance",setTimeout(()=>{this.drawHelper.startDrawingLine()},50)}clearMeasurements(){this.currentMode="none",this.drawHelper.clearAll(),this.measurementCallback?.onClear&&this.measurementCallback.onClear()}}const ye=Q(),Ce="73.5577,18.1597,135.0882,53.5609",ve={},xe=(c,e,t=ye)=>{const i={start:0,count:10,queryType:7,keyWord:c,mapBound:Ce,level:e?.defaultZoomLevel||15};return`http://api.tianditu.gov.cn/v2/search?postStr=${JSON.stringify(i)}&type=query&tk=${t}`};class V{viewer;toolbarElement;searchCallback;searchContainer=null;constructor(e,t,i){this.viewer=e,this.toolbarElement=t,this.searchCallback=i}setSearchCallback(e){this.searchCallback=e}toggleSearch(e){if(this.toolbarElement.querySelector(".search-container"))return;const i=e.offsetTop,r=document.createElement("div");r.className="search-container",r.style.cssText=`
|
|
1
|
+
(function(v,E){typeof exports=="object"&&typeof module<"u"?E(exports,require("cesium")):typeof define=="function"&&define.amd?define(["exports","cesium"],E):(v=typeof globalThis<"u"?globalThis:v||self,E(v.VMapCesiumToolbar={},v.Cesium))})(this,(function(v,E){"use strict";function ge(c){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(c){for(const t in c)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(c,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>c[t]})}}return e.default=c,Object.freeze(e)}const n=ge(E);class Y{viewer;scene;entities;offsetHeight=0;originalDepthTestAgainstTerrain=null;originalRequestRenderMode=null;callbacks;tempPositions=[];tempEntities=[];tempLabelEntities=[];finishedPointEntities=[];drawOptions;getTempPositions(){return this.tempPositions}getTempEntities(){return this.tempEntities}getTempLabelEntities(){return this.tempLabelEntities}getFinishedPointEntities(){return this.finishedPointEntities}setTempPositions(e){this.tempPositions=e}setTempEntities(e){this.tempEntities=e}setTempLabelEntities(e){this.tempLabelEntities=e}addPointForHelper(e){this.addPoint(e)}clearTempEntitiesForHelper(){this.clearTempEntities()}clearTempPointEntitiesForHelper(){const e=[];this.tempEntities.forEach(t=>{t&&t.point?this.entities.remove(t):t&&e.push(t)}),this.tempEntities=e}removeLastPointAndRedraw(){if(this.tempPositions.length===0)return;const e=this.tempPositions.slice(0,this.tempPositions.length-1);this.clearTempEntities(),this.tempPositions=[],e.forEach(t=>{this.addPoint(t)}),this.updateDrawingEntity()}resolveColor(e){try{return e?e instanceof n.Color?e:n.Color.fromCssColorString(String(e)):n.Color.YELLOW}catch{return n.Color.YELLOW}}applySelectedStyleToEntity(e){j(e)}restoreOriginalStyleForEntity(e){const t=e;t._isSelected&&j(t)}constructor(e,t={}){this.viewer=e,this.scene=e.scene,this.entities=e.entities,this.callbacks=t,this.updateOffsetHeight()}updateOffsetHeight(){this.scene.mode===n.SceneMode.SCENE3D?this.offsetHeight=1:this.offsetHeight=0}pickGlobePosition(e){const t=this.viewer.camera.getPickRay(e);if(t&&this.scene.mode===n.SceneMode.SCENE3D&&this.scene.globe.tilesLoaded){const r=this.scene.globe.pick(t,this.scene);if(n.defined(r)&&Number.isFinite(r.x)&&Number.isFinite(r.y)&&Number.isFinite(r.z))return r}const i=this.viewer.camera.pickEllipsoid(e,this.scene.globe.ellipsoid);return i&&Number.isFinite(i.x)&&Number.isFinite(i.y)&&Number.isFinite(i.z)?i: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=n.Cartographic.fromCartesian(e),i=n.Cartesian3.fromRadians(t.longitude,t.latitude,(t.height||0)+this.offsetHeight),r=this.entities.add({position:i,point:{pixelSize:8,color:n.Color.RED,outlineColor:n.Color.WHITE,outlineWidth:3,heightReference:n.HeightReference.NONE,scaleByDistance:new n.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 l=s.measureText(e).width,h=20;return o.width=Math.ceil(l+24),o.height=Math.ceil(h+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 j(c){try{const t=c._drawOptions?.selected;if(!t)return;if(c._isSelected){const r=c._originalStyle;if(!r){c._isSelected=!1;return}c.polyline&&r.material&&(c.polyline.material=r.material,c.polyline.width=r.width??c.polyline.width),c.polygon&&r.material&&(c.polygon.material=r.material,c.polygon.outlineColor=r.outlineColor??c.polygon.outlineColor,c.polygon.outlineWidth=r.outlineWidth??c.polygon.outlineWidth),c.rectangle&&r.material&&(c.rectangle.material=r.material,c.rectangle.outlineColor=r.outlineColor??c.rectangle.outlineColor,c.rectangle.outlineWidth=r.outlineWidth??c.rectangle.outlineWidth),c.ellipse&&r.material&&(c.ellipse.material=r.material,c.ellipse.outlineColor=r.outlineColor??c.ellipse.outlineColor,c.ellipse.outlineWidth=r.outlineWidth??c.ellipse.outlineWidth),c._isSelected=!1;return}c._originalStyle||(c._originalStyle={},c.polyline&&(c._originalStyle.material=c.polyline.material,c._originalStyle.width=c.polyline.width),c.polygon&&(c._originalStyle.material=c.polygon.material,c._originalStyle.outlineColor=c.polygon.outlineColor,c._originalStyle.outlineWidth=c.polygon.outlineWidth),c.rectangle&&(c._originalStyle.material=c.rectangle.material,c._originalStyle.outlineColor=c.rectangle.outlineColor,c._originalStyle.outlineWidth=c.rectangle.outlineWidth),c.ellipse&&(c._originalStyle.material=c.ellipse.material,c._originalStyle.outlineColor=c.ellipse.outlineColor,c._originalStyle.outlineWidth=c.ellipse.outlineWidth));const i=r=>{try{return r?r instanceof n.Color?r:n.Color.fromCssColorString(String(r)):n.Color.YELLOW}catch{return n.Color.YELLOW}};if(c.polyline){const r=t.color?i(t.color):n.Color.YELLOW,o=t.width??(c.polyline.width||5)+2;c.polyline.material=new n.ColorMaterialProperty(r),c.polyline.width=new n.ConstantProperty(o)}if(c.polygon){const r=t.color?i(t.color):n.Color.YELLOW;c.polygon.material=new n.ColorMaterialProperty(r.withAlpha(.5)),c.polygon.outlineColor=new n.ConstantProperty(t.outlineColor?i(t.outlineColor):i("#ffffff")),c.polygon.outlineWidth=new n.ConstantProperty(t.outlineWidth??(c.polygon.outlineWidth||2))}if(c.rectangle){const r=t.color?i(t.color):n.Color.YELLOW;c.rectangle.material=new n.ColorMaterialProperty(r.withAlpha(.5)),c.rectangle.outlineColor=new n.ConstantProperty(t.outlineColor?i(t.outlineColor):i("#ffffff")),c.rectangle.outlineWidth=new n.ConstantProperty(t.outlineWidth??(c.rectangle.outlineWidth||2))}if(c.ellipse){const r=t.color?i(t.color):n.Color.YELLOW;c.ellipse.material=new n.ColorMaterialProperty(r.withAlpha(.5)),c.ellipse.outlineColor=new n.ConstantProperty(t.outlineColor?i(t.outlineColor):i("#ffffff")),c.ellipse.outlineWidth=new n.ConstantProperty(t.outlineWidth??(c.ellipse.outlineWidth||2))}c._isSelected=!0}catch(e){console.warn("toggleSelectedStyle failed",e)}}function P(c){return!!c&&Number.isFinite(c.x)&&Number.isFinite(c.y)&&Number.isFinite(c.z)}function I(c){return!isFinite(c)||isNaN(c)?"0.00 m":c>=1e3?`${(c/1e3).toFixed(2)} km`:`${c.toFixed(2)} m`}function R(c){return!isFinite(c)||isNaN(c)?"0.00 m²":c>=1?`${c.toFixed(2)} km²`:`${(c*1e6).toFixed(2)} m²`}function F(c,e){const t=n.Cartographic.fromCartesian(c),i=n.Cartographic.fromCartesian(e),r=Math.min(t.longitude,i.longitude),o=Math.max(t.longitude,i.longitude),s=Math.min(t.latitude,i.latitude),a=Math.max(t.latitude,i.latitude);return new n.Rectangle(r,s,o,a)}function me(c){const e=c.west,t=c.south,i=c.east,r=c.north,o=n.Cartesian3.distance(n.Cartesian3.fromRadians(e,t),n.Cartesian3.fromRadians(i,t)),s=n.Cartesian3.distance(n.Cartesian3.fromRadians(e,t),n.Cartesian3.fromRadians(e,r));return o*s/1e6}function z(c,e=n.Ellipsoid.WGS84){const t=c.filter(o=>P(o));if(t.length<3)return 0;let i=0;const r=t.length;for(let o=0;o<r;o++){const s=t[o],a=t[(o+1)%r];if(!P(s)||!P(a))return 0;const l=e.cartesianToCartographic(s),h=e.cartesianToCartographic(a);if(!l||!h||!Number.isFinite(l.longitude)||!Number.isFinite(l.latitude)||!Number.isFinite(h.longitude)||!Number.isFinite(h.latitude))return 0;i+=(h.longitude-l.longitude)*(2+Math.sin(l.latitude)+Math.sin(h.latitude))}return i=Math.abs(i*6378137*6378137/2),i/1e6}function pe(c){const e=c.filter(o=>P(o));if(e.length===0)return n.Cartesian3.ZERO;let t=0,i=0,r=0;for(let o=0;o<e.length;o++)t+=e[o].x,i+=e[o].y,r+=e[o].z;return new n.Cartesian3(t/e.length,i/e.length,r/e.length)}class X extends Y{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 i=this.offsetHeight>0?t.map(s=>{const a=n.Cartographic.fromCartesian(s);return n.Cartesian3.fromRadians(a.longitude,a.latitude,(a.height||0)+this.offsetHeight)}):t,r=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):n.Color.YELLOW,o=this.drawOptions?.strokeWidth??5;this.currentLineEntity&&this.tempEntities.indexOf(this.currentLineEntity)===-1&&(this.currentLineEntity=null,this.currentLinePositions=[]),this.currentLineEntity?(this.currentLineEntity.polyline.positions instanceof n.CallbackProperty?(this.currentLinePositions.length=0,this.currentLinePositions.push(...i)):(this.currentLinePositions=[...i],this.currentLineEntity.polyline.positions=new n.CallbackProperty(()=>this.currentLinePositions,!1)),this.currentLineEntity.polyline.material=new n.ColorMaterialProperty(r),this.currentLineEntity.polyline.width=new n.ConstantProperty(o)):(this.currentLinePositions=[...i],this.currentLineEntity=this.entities.add({polyline:{positions:new n.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(l=>P(l));if(e.length<2)return this.restoreRequestRenderModeIfNeeded(),null;const t=e.map(l=>{const h=n.Cartographic.fromCartesian(l);return n.Cartesian3.fromRadians(h.longitude,h.latitude,h.height||0)});let i=null,r=0;const o=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):n.Color.YELLOW,s=this.drawOptions?.strokeWidth??5;if(this.offsetHeight>0){const l=t.map(h=>{const d=n.Cartographic.fromCartesian(h);return n.Cartesian3.fromRadians(d.longitude,d.latitude,(d.height||0)+this.offsetHeight)});i=this.entities.add({name:"绘制的线",polyline:{positions:l,width:s,material:o,clampToGround:!1}}),i._groundPositions=t}else i=this.entities.add({name:"绘制的线",polyline:{positions:t,width:s,material:o,clampToGround:!0}}),i._groundPositions=t;i&&(i._drawOptions=this.drawOptions,i._drawType=this.getDrawType(),this.drawOptions?.onClick&&(i._onClick=this.drawOptions.onClick));for(let l=1;l<t.length;l++)r+=n.Cartesian3.distance(t[l-1],t[l]);this.tempLabelEntities.forEach(l=>{}),this.tempEntities.forEach(l=>{l&&this.entities.remove(l)}),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 a={entity:i,type:"line",positions:t,distance:r};return this.callbacks.onMeasureComplete&&this.callbacks.onMeasureComplete(a),this.restoreRequestRenderModeIfNeeded(),this.callbacks.onDrawEnd&&this.callbacks.onDrawEnd(i,a),a}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,i=this.currentSegmentLabels.length;if(i>t){for(let r=t;r<i;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],a=n.Cartesian3.distance(o,s);if(a>5){const l=n.Cartesian3.midpoint(o,s,new n.Cartesian3),h=n.Cartographic.fromCartesian(l),d=n.Cartesian3.fromRadians(h.longitude,h.latitude,h.height||0);let u=l;this.offsetHeight>0&&(u=n.Cartesian3.fromRadians(h.longitude,h.latitude,(h.height||0)+this.offsetHeight));const m=r%2===0?-25:25,w=I(a);if(r<this.currentSegmentLabels.length&&this.currentSegmentLabels[r].billboard){const g=this.currentSegmentLabels[r];if(g.position=new n.ConstantPositionProperty(u),g.billboard.pixelOffset=new n.ConstantProperty(new n.Cartesian2(0,m)),g._groundPosition=d,g._segmentText!==w){const f=this.createSegmentLengthBillboardImage(w);g.billboard.image=new n.ConstantProperty(f),g._segmentText=w}}else{const g=this.createSegmentLengthBillboardImage(w),p=this.entities.add({position:u,billboard:{image:g,pixelOffset:new n.ConstantProperty(new n.Cartesian2(0,m)),heightReference:new n.ConstantProperty(this.offsetHeight>0?n.HeightReference.RELATIVE_TO_GROUND:n.HeightReference.NONE),verticalOrigin:new n.ConstantProperty(n.VerticalOrigin.CENTER),horizontalOrigin:new n.ConstantProperty(n.HorizontalOrigin.CENTER),scale:new n.ConstantProperty(1),disableDepthTestDistance:new n.ConstantProperty(Number.POSITIVE_INFINITY)}});p._segmentText=w,p._groundPosition=d,this.currentSegmentLabels.push(p),this.tempLabelEntities.push(p)}}else if(r<this.currentSegmentLabels.length){const l=this.currentSegmentLabels[r];if(l){this.entities.remove(l);const h=this.tempLabelEntities.indexOf(l);h>-1&&this.tempLabelEntities.splice(h,1)}this.currentSegmentLabels.splice(r,1),r--}}}updateTotalLabel(){if(this.tempPositions.length>1){let e=0;for(let h=1;h<this.tempPositions.length;h++)e+=n.Cartesian3.distance(this.tempPositions[h-1],this.tempPositions[h]);const t=this.tempPositions[this.tempPositions.length-1],i=n.Cartographic.fromCartesian(t),r=n.Cartesian3.fromRadians(i.longitude,i.latitude,i.height||0);let o=r;this.offsetHeight>0&&(o=n.Cartesian3.fromRadians(i.longitude,i.latitude,(i.height||0)+this.offsetHeight));const a=`总长: ${I(e)}`,l=this.createTotalLengthBillboardImage(a);if(this.currentTotalLabel&&this.currentTotalLabel.billboard)this.currentTotalLabel.position=new n.ConstantPositionProperty(o),this.currentTotalLabel.billboard.image=new n.ConstantProperty(l),this.currentTotalLabel._groundPosition=r;else{const h=this.entities.add({position:o,billboard:{image:l,pixelOffset:new n.ConstantProperty(new n.Cartesian2(0,-35)),heightReference:new n.ConstantProperty(this.offsetHeight>0?n.HeightReference.RELATIVE_TO_GROUND:n.HeightReference.NONE),verticalOrigin:new n.ConstantProperty(n.VerticalOrigin.BOTTOM),horizontalOrigin:new n.ConstantProperty(n.HorizontalOrigin.CENTER),scale:new n.ConstantProperty(1),disableDepthTestDistance:new n.ConstantProperty(Number.POSITIVE_INFINITY)}});this.currentTotalLabel=h,this.currentTotalLabel._groundPosition=r,this.tempLabelEntities.push(h)}}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=n.Cartographic.fromDegrees(120.2052342,30.2489634,this.offsetHeight)}const t=n.Cartesian3.fromRadians(e.longitude,e.latitude,(e.height||0)+this.offsetHeight),i=this.entities.add({position:t,label:{text:"总长: 0.00 m",font:"bold 16px 'Microsoft YaHei', 'PingFang SC', sans-serif",fillColor:n.Color.WHITE,outlineColor:n.Color.BLACK,outlineWidth:2,style:n.LabelStyle.FILL_AND_OUTLINE,pixelOffset:new n.Cartesian2(0,-35),heightReference:n.HeightReference.RELATIVE_TO_GROUND,scale:1,showBackground:!0,backgroundPadding:new n.Cartesian2(6,3),backgroundColor:n.Color.BLACK.withAlpha(.8),disableDepthTestDistance:Number.POSITIVE_INFINITY,verticalOrigin:n.VerticalOrigin.BOTTOM,horizontalOrigin:n.HorizontalOrigin.CENTER,show:!1}});this.isTotalLabelWarmedUp=!0,requestAnimationFrame(()=>{try{this.entities.remove(i)}catch{}})}}class B extends Y{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===n.SceneMode.SCENE3D&&!this.scene.globe.tilesLoaded)return;const i=this.tempPositions.filter(o=>P(o)),r=e&&P(e)&&i.length>=2?[...i,e]:i;if(r.length>=3){const o=r.map(g=>n.Cartographic.fromCartesian(g)).filter(g=>g&&Number.isFinite(g.longitude)&&Number.isFinite(g.latitude));if(o.length<3){if(this.currentPolygonEntity){this.entities.remove(this.currentPolygonEntity);const g=this.tempEntities.indexOf(this.currentPolygonEntity);g>-1&&this.tempEntities.splice(g,1),this.currentPolygonEntity=null}if(this.currentBorderEntity){this.entities.remove(this.currentBorderEntity);const g=this.tempEntities.indexOf(this.currentBorderEntity);g>-1&&this.tempEntities.splice(g,1),this.currentBorderEntity=null}return}const s=o.map(g=>{const p=g.height||0,f=this.offsetHeight>0?this.offsetHeight:.1;return n.Cartesian3.fromRadians(g.longitude,g.latitude,p+f)}),a=n.HeightReference.NONE,l=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):n.Color.LIGHTGREEN.withAlpha(.3),h=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):n.Color.LIGHTGREEN,d=this.drawOptions?.strokeWidth??this.drawOptions?.outlineWidth??2,u=this.tempEntities.filter(g=>!!g?.polygon),m=this.tempEntities.filter(g=>{const p=g;return!!p?.polyline&&!p?.point&&!p?.polygon});(u.length>1||m.length>1)&&([...u,...m].forEach(g=>{this.entities.remove(g)}),this.tempEntities=this.tempEntities.filter(g=>{const p=g;return p?.point?!0:!(p?.polygon||p?.polyline&&!p?.polygon)}),this.currentPolygonEntity=null,this.currentBorderEntity=null),this.currentPolygonEntity&&this.tempEntities.indexOf(this.currentPolygonEntity)===-1&&(this.currentPolygonEntity=null),this.currentBorderEntity&&this.tempEntities.indexOf(this.currentBorderEntity)===-1&&(this.currentBorderEntity=null),this.currentPolygonEntity?(this.currentPolygonEntity.polygon.hierarchy=new n.ConstantProperty(new n.PolygonHierarchy(s)),this.currentPolygonEntity.polygon.heightReference=new n.ConstantProperty(a),this.currentPolygonEntity.polygon.material=new n.ColorMaterialProperty(l),this.currentPolygonEntity.polygon.outline=new n.ConstantProperty(!1)):(this.currentPolygonEntity=this.entities.add({polygon:{hierarchy:new n.ConstantProperty(new n.PolygonHierarchy(s)),material:new n.ColorMaterialProperty(l),outline:!1,heightReference:a}}),this.tempEntities.push(this.currentPolygonEntity));const w=s.slice();w.length>=2&&w.push(s[0]),this.currentBorderEntity&&this.currentBorderEntity.polyline?(this.currentBorderEntity.polyline.positions=new n.ConstantProperty(w),this.currentBorderEntity.polyline.width=new n.ConstantProperty(d),this.currentBorderEntity.polyline.material=new n.ColorMaterialProperty(h),this.currentBorderEntity.polyline.clampToGround=new n.ConstantProperty(!1)):(this.currentBorderEntity=this.entities.add({polyline:{positions:new n.ConstantProperty(w),width:d,material:new n.ColorMaterialProperty(h),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(u=>P(u));if(e.length<3)return this.restoreRequestRenderModeIfNeeded(),null;const t=e.map(u=>n.Cartographic.fromCartesian(u)).filter(u=>u&&Number.isFinite(u.longitude)&&Number.isFinite(u.latitude));if(t.length<3)return this.restoreRequestRenderModeIfNeeded(),null;const i=t.map(u=>n.Cartesian3.fromRadians(u.longitude,u.latitude,u.height||0));let r=null,o=null;const s=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):n.Color.LIGHTGREEN.withAlpha(.3),a=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):n.Color.LIGHTGREEN,l=this.drawOptions?.strokeWidth??this.drawOptions?.outlineWidth??2;if(this.offsetHeight>0){const u=i.map(w=>{const g=n.Cartographic.fromCartesian(w);return n.Cartesian3.fromRadians(g.longitude,g.latitude,(g.height||0)+this.offsetHeight)});r=this.entities.add({name:"绘制的多边形区域",polygon:{hierarchy:new n.PolygonHierarchy(u),material:new n.ColorMaterialProperty(s),outline:!1,heightReference:n.HeightReference.NONE}});const m=u.slice();m.length>=2&&m.push(u[0]),o=this.entities.add({polyline:{positions:m,width:l,material:new n.ColorMaterialProperty(a),clampToGround:!1}}),r._groundPositions=i,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 n.PolygonHierarchy(i),material:new n.ColorMaterialProperty(s),outline:!1,heightReference:n.HeightReference.NONE}});const u=i.slice();u.length>=2&&u.push(i[0]),o=this.entities.add({polyline:{positions:u,width:l,material:new n.ColorMaterialProperty(a),clampToGround:!0}}),r._groundPositions=i,r&&(r._drawOptions=this.drawOptions,r._drawType=this.getDrawType(),this.drawOptions?.onClick&&(r._onClick=this.drawOptions.onClick),o&&(r._borderEntity=o))}const h=z(i,this.scene.globe.ellipsoid);if(h>0){const u=pe(i),m=n.Cartographic.fromCartesian(u),w=n.Cartesian3.fromRadians(m.longitude,m.latitude,m.height||0);let g=w;this.offsetHeight>0&&(g=n.Cartesian3.fromRadians(m.longitude,m.latitude,(m.height||0)+this.offsetHeight));const p=`面积: ${R(h)}`,f=this.createTotalLengthBillboardImage(p),b=this.entities.add({position:g,billboard:{image:f,pixelOffset:new n.ConstantProperty(new n.Cartesian2(0,-25)),heightReference:new n.ConstantProperty(this.offsetHeight>0?n.HeightReference.RELATIVE_TO_GROUND:n.HeightReference.NONE),verticalOrigin:new n.ConstantProperty(n.VerticalOrigin.BOTTOM),horizontalOrigin:new n.ConstantProperty(n.HorizontalOrigin.CENTER),scale:new n.ConstantProperty(1),disableDepthTestDistance:new n.ConstantProperty(Number.POSITIVE_INFINITY)}});b._groundPosition=w,this.tempLabelEntities.push(b)}this.tempEntities.forEach(u=>{u&&this.entities.remove(u)}),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:i,areaKm2:z(i,this.scene.globe.ellipsoid)};return this.callbacks.onMeasureComplete&&this.callbacks.onMeasureComplete(d),this.restoreRequestRenderModeIfNeeded(),this.callbacks.onDrawEnd&&this.callbacks.onDrawEnd(r,d),d}clear(){if(this.currentPolygonEntity){this.entities.remove(this.currentPolygonEntity);const e=this.tempEntities.indexOf(this.currentPolygonEntity);e>-1&&this.tempEntities.splice(e,1),this.currentPolygonEntity=null}if(this.currentBorderEntity){this.entities.remove(this.currentBorderEntity);const e=this.tempEntities.indexOf(this.currentBorderEntity);e>-1&&this.tempEntities.splice(e,1),this.currentBorderEntity=null}}getDrawType(){return"polygon"}}class U extends Y{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 l=this.tempEntities.indexOf(this.currentRectangleEntity);l>-1&&this.tempEntities.splice(l,1),this.currentRectangleEntity=null}return}const i=F(t[0],t[1]),r=n.HeightReference.NONE,o=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):n.Color.GREEN,s=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):n.Color.DARKGREEN,a=this.drawOptions?.strokeWidth??this.drawOptions?.outlineWidth??1;this.currentRectangleEntity&&!this.entities.contains(this.currentRectangleEntity)&&(this.currentRectangleEntity=null),this.currentRectangleEntity?(this.currentRectangleEntity.rectangle.coordinates=new n.ConstantProperty(i),this.currentRectangleEntity.rectangle.heightReference=new n.ConstantProperty(r),this.currentRectangleEntity.rectangle.extrudedHeight=this.offsetHeight>0?new n.ConstantProperty(this.offsetHeight):void 0,this.currentRectangleEntity.rectangle.material=new n.ColorMaterialProperty(o.withAlpha(.5)),this.currentRectangleEntity.rectangle.outlineColor=new n.ConstantProperty(s),this.currentRectangleEntity.rectangle.outlineWidth=new n.ConstantProperty(a)):(this.currentRectangleEntity=this.entities.add({rectangle:{coordinates:i,material:o.withAlpha(.5),heightReference:r,extrudedHeight:this.offsetHeight>0?this.offsetHeight:void 0,outline:!0,outlineColor:s,outlineWidth:a}}),this.tempEntities.push(this.currentRectangleEntity))}finishDrawing(){if(this.tempPositions.length<2)return this.restoreRequestRenderModeIfNeeded(),null;const e=this.tempPositions.filter(m=>P(m));if(e.length<2)return this.restoreRequestRenderModeIfNeeded(),null;const t=e.map(m=>{const w=n.Cartographic.fromCartesian(m);return n.Cartesian3.fromRadians(w.longitude,w.latitude,w.height||0)}),i=F(t[0],t[1]);let r=null;const o=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):n.Color.GREEN,s=this.drawOptions?.strokeColor?this.resolveColor(this.drawOptions.strokeColor):this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):n.Color.DARKGREEN,a=this.drawOptions?.strokeWidth??this.drawOptions?.outlineWidth??1;this.offsetHeight>0?(r=this.entities.add({name:"绘制的矩形",rectangle:{coordinates:i,material:o.withAlpha(.5),heightReference:n.HeightReference.NONE,extrudedHeight:this.offsetHeight,outline:!0,outlineColor:s,outlineWidth:a}}),r._groundRectangle=i):(r=this.entities.add({name:"绘制的矩形",rectangle:{coordinates:i,material:o.withAlpha(.5),heightReference:n.HeightReference.NONE,outline:!0,outlineColor:s,outlineWidth:a}}),r._groundRectangle=i),r&&(r._drawOptions=this.drawOptions,r._drawType=this.getDrawType(),this.drawOptions?.onClick&&(r._onClick=this.drawOptions.onClick));const l=me(i);if(l>0){const m=n.Rectangle.center(i),w=n.Cartesian3.fromRadians(m.longitude,m.latitude,0);let g=w;this.offsetHeight>0&&(g=n.Cartesian3.fromRadians(m.longitude,m.latitude,this.offsetHeight));const p=`面积: ${R(l)}`,f=this.createTotalLengthBillboardImage(p),b=this.entities.add({position:g,billboard:{image:f,pixelOffset:new n.ConstantProperty(new n.Cartesian2(0,-25)),heightReference:new n.ConstantProperty(this.offsetHeight>0?n.HeightReference.RELATIVE_TO_GROUND:n.HeightReference.NONE),verticalOrigin:new n.ConstantProperty(n.VerticalOrigin.BOTTOM),horizontalOrigin:new n.ConstantProperty(n.HorizontalOrigin.CENTER),scale:new n.ConstantProperty(1),disableDepthTestDistance:new n.ConstantProperty(Number.POSITIVE_INFINITY)}});b._groundPosition=w,this.tempLabelEntities.push(b)}this.tempEntities.forEach(m=>{m&&this.entities.remove(m)}),this.tempEntities=[],this.tempPositions=[],this.currentRectangleEntity=null,this.originalDepthTestAgainstTerrain!==null&&(this.scene.globe.depthTestAgainstTerrain=this.originalDepthTestAgainstTerrain,this.originalDepthTestAgainstTerrain=null);const h=n.Rectangle.subsample(i,this.scene.globe.ellipsoid),d=(()=>{if(h.length>1){const m=h[0],w=h[h.length-1];if(n.Cartesian3.equalsEpsilon(m,w,n.Math.EPSILON9))return h.slice(0,h.length-1)}return h})(),u={entity:r,type:"rectangle",positions:d,areaKm2:l};return this.callbacks.onMeasureComplete&&this.callbacks.onMeasureComplete(u),this.restoreRequestRenderModeIfNeeded(),this.callbacks.onDrawEnd&&this.callbacks.onDrawEnd(r,u),u}getDrawType(){return"rectangle"}}class Z extends Y{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 u=this.tempEntities.indexOf(this.currentCircleEntity);u>-1&&this.tempEntities.splice(u,1),this.currentCircleEntity=null}return}if(!e)return;const t=this.tempPositions[0],i=n.Cartesian3.distance(t,e);if(i<1)return;const r=n.Cartographic.fromCartesian(t),o=n.Cartesian3.fromRadians(r.longitude,r.latitude,r.height||0);let s=o;this.offsetHeight>0&&(s=n.Cartesian3.fromRadians(r.longitude,r.latitude,(r.height||0)+this.offsetHeight));const a=i/this.scene.globe.ellipsoid.maximumRadius;new n.Rectangle(r.longitude-a,r.latitude-a,r.longitude+a,r.latitude+a);const l=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):n.Color.BLUE,h=this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):n.Color.BLUE,d=this.drawOptions?.outlineWidth??2;if(this.currentCircleEntity&&!this.entities.contains(this.currentCircleEntity)&&(this.currentCircleEntity=null),this.currentBorderEntity&&!this.entities.contains(this.currentBorderEntity)&&(this.currentBorderEntity=null),this.currentCircleEntity?(this.currentCircleEntity.ellipse.semiMajorAxis=new n.ConstantProperty(i),this.currentCircleEntity.ellipse.semiMinorAxis=new n.ConstantProperty(i),this.currentCircleEntity.position=new n.ConstantPositionProperty(s),this.currentCircleEntity.ellipse.material=new n.ColorMaterialProperty(l.withAlpha(.3)),this.currentCircleEntity.ellipse.outline=new n.ConstantProperty(d<=1),this.currentCircleEntity.ellipse.outlineColor=new n.ConstantProperty(h),this.currentCircleEntity.ellipse.outlineWidth=new n.ConstantProperty(d<=1?d:1)):(this.currentCircleEntity=this.entities.add({position:s,ellipse:{semiMajorAxis:i,semiMinorAxis:i,material:l.withAlpha(.3),outline:d<=1,outlineColor:h,outlineWidth:d<=1?d:1,heightReference:n.HeightReference.NONE}}),this.tempEntities.push(this.currentCircleEntity)),d>1){const u=n.Cartographic.fromCartesian(s),m=u.height||0,w=.1,g=i,p=this.generateCirclePositions(u,g,m+w),f=[...p,p[0]];this.currentBorderEntity&&this.currentBorderEntity.polyline?(this.currentBorderEntity.polyline.positions=new n.ConstantProperty(f),this.currentBorderEntity.polyline.material=new n.ColorMaterialProperty(h),this.currentBorderEntity.polyline.width=new n.ConstantProperty(d),this.currentBorderEntity.polyline.clampToGround=new n.ConstantProperty(!1)):(this.currentBorderEntity=this.entities.add({polyline:{positions:f,material:new n.ColorMaterialProperty(h),width:d,clampToGround:!1}}),this.tempEntities.push(this.currentBorderEntity))}else if(this.currentBorderEntity){this.entities.remove(this.currentBorderEntity);const u=this.tempEntities.indexOf(this.currentBorderEntity);u>-1&&this.tempEntities.splice(u,1),this.currentBorderEntity=null}this.centerPosition=o}finishDrawing(){if(this.tempPositions.length<1)return this.restoreRequestRenderModeIfNeeded(),null;const e=this.tempPositions[0],t=n.Cartographic.fromCartesian(e),i=n.Cartesian3.fromRadians(t.longitude,t.latitude,t.height||0);let r=0;if(this.tempPositions.length>=2)r=n.Cartesian3.distance(e,this.tempPositions[1]);else if(this.currentCircleEntity){const f=this.currentCircleEntity.ellipse;if(f){const b=f.semiMajorAxis?.getValue(n.JulianDate.now());r=typeof b=="number"?b:0}}if(r<1)return this.restoreRequestRenderModeIfNeeded(),null;let o=null,s=i;this.offsetHeight>0&&(s=n.Cartesian3.fromRadians(t.longitude,t.latitude,(t.height||0)+this.offsetHeight));const a=this.drawOptions?.fillColor?this.resolveColor(this.drawOptions.fillColor):n.Color.BLUE,l=this.drawOptions?.outlineColor?this.resolveColor(this.drawOptions.outlineColor):n.Color.BLUE,h=this.drawOptions?.outlineWidth??2;if(h>1){o=this.entities.add({name:"绘制的圆",position:s,ellipse:{semiMajorAxis:r,semiMinorAxis:r,material:a.withAlpha(.3),outline:!1,heightReference:n.HeightReference.NONE}});const f=n.Cartographic.fromCartesian(s),b=f.height||0,C=.1,G=r,y=this.generateCirclePositions(f,G,b+C),x=[...y,y[0]],D=this.entities.add({name:"绘制的圆-边框",polyline:{positions:x,material:new n.ColorMaterialProperty(l),width:h,clampToGround:!(this.offsetHeight>0)}});o._borderEntity=D}else o=this.entities.add({name:"绘制的圆",position:s,ellipse:{semiMajorAxis:r,semiMinorAxis:r,material:a.withAlpha(.3),outline:!0,outlineColor:l,outlineWidth:h,heightReference:n.HeightReference.NONE}});o._groundPosition=i,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 f=`面积: ${R(d)}`,b=this.createTotalLengthBillboardImage(f),C=this.entities.add({position:s,billboard:{image:b,pixelOffset:new n.ConstantProperty(new n.Cartesian2(0,-25)),heightReference:new n.ConstantProperty(this.offsetHeight>0?n.HeightReference.RELATIVE_TO_GROUND:n.HeightReference.NONE),verticalOrigin:new n.ConstantProperty(n.VerticalOrigin.BOTTOM),horizontalOrigin:new n.ConstantProperty(n.HorizontalOrigin.CENTER),scale:new n.ConstantProperty(1),disableDepthTestDistance:new n.ConstantProperty(Number.POSITIVE_INFINITY)}});C._groundPosition=i,this.tempLabelEntities.push(C)}this.tempEntities.forEach((f,b)=>{f&&this.entities.remove(f)}),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 u=r/this.scene.globe.ellipsoid.maximumRadius,m=new n.Rectangle(t.longitude-u,t.latitude-u,t.longitude+u,t.latitude+u),w=n.Rectangle.subsample(m,this.scene.globe.ellipsoid),g=(()=>{if(w.length>1){const f=w[0],b=w[w.length-1];if(n.Cartesian3.equalsEpsilon(f,b,n.Math.EPSILON9))return w.slice(0,w.length-1)}return w})(),p={entity:o,type:"circle",positions:g,areaKm2:d};return this.callbacks.onMeasureComplete&&this.callbacks.onMeasureComplete(p),this.restoreRequestRenderModeIfNeeded(),this.callbacks.onDrawEnd&&this.callbacks.onDrawEnd(o,p),p}getDrawType(){return"circle"}generateCirclePositions(e,t,i,r=128){const s=e.latitude,a=e.longitude,l=t/6378137,h=[];for(let d=0;d<r;d++){const u=d/r*n.Math.TWO_PI,m=Math.sin(s),w=Math.cos(s),g=Math.sin(l),p=Math.cos(l),f=Math.sin(u),b=Math.cos(u),C=Math.asin(m*p+w*g*b),G=a+Math.atan2(f*g*w,p-m*Math.sin(C));h.push(n.Cartesian3.fromRadians(G,C,i))}return h}}class M{viewer;scene;entities;drawMode=null;isDrawing=!1;tempPositions=[];tempEntities=[];tempLabelEntities=[];finishedEntities=[];finishedLabelEntities=[];finishedPointEntities=[];publicEntities=[];_doubleClickPending=!1;lastPreviewPosition=null;static activeDrawingHelper=null;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 n.Viewer))throw new Error("Invalid Cesium Viewer instance provided.");this.viewer=e,this.scene=e.scene,this.entities=e.entities,this.updateOffsetHeight();const t={onDrawStart:()=>{this.onDrawStartCallback&&this.onDrawStartCallback()},onDrawEnd:i=>{this.onDrawEndCallback&&this.onDrawEndCallback(i)},onEntityRemoved:i=>{this.onEntityRemovedCallback&&this.onEntityRemovedCallback(i)},onMeasureComplete:i=>{this.onMeasureCompleteCallback&&this.onMeasureCompleteCallback(i)}};this.drawLine=new X(e,t),this.drawPolygon=new B(e,t),this.drawRectangle=new U(e,t),this.drawCircle=new Z(e,t);try{this.entityClickHandler=new n.ScreenSpaceEventHandler(this.scene.canvas),this.entityClickHandler.setInputAction(i=>{if(this.isDrawing)return;const r=this.scene.pick(i.position),o=r&&r.id;if(!o)return;const s=o;if(!(s._drawType!==void 0))return;const l=s._onClick;try{if(l){const d=s._groundPositions||s._groundPosition||void 0,u=Array.isArray(d)?d:d?[d]:void 0;l(s,s._drawType,u)}}catch(d){console.warn("entity onClick handler error",d)}s._drawOptions?.selected&&j(s)},n.ScreenSpaceEventType.LEFT_CLICK)}catch(i){console.warn("entity click handler init failed",i)}}handleSceneModeChanged(){const e=this.offsetHeight;this.updateOffsetHeight(),e!==this.offsetHeight&&this.updateFinishedEntitiesForModeChange()}updateOffsetHeight(){this.scene.mode===n.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){const i=M.activeDrawingHelper;switch(i&&i!==this&&i.cancelDrawing(),this.endDrawingInternal(!1),this.drawMode=e,this.isDrawing=!0,this.lastPreviewPosition=null,M.activeDrawingHelper=this,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 n.ScreenSpaceEventHandler(this.scene.canvas),this.screenSpaceEventHandler.setInputAction(t=>{if(!this.isDrawing)return;if(this._doubleClickPending){this._doubleClickPending=!1;return}const i=this.pickGlobePosition(t.position);i&&this.addPoint(i)},n.ScreenSpaceEventType.LEFT_CLICK),this.screenSpaceEventHandler.setInputAction(()=>{!this.isDrawing||this.tempPositions.length===0||this.removeLastPoint()},n.ScreenSpaceEventType.RIGHT_CLICK),this.screenSpaceEventHandler.setInputAction(t=>{if(!this.isDrawing||this.tempPositions.length===0)return;const i=this.pickGlobePosition(t.endPosition);i&&this.updatePreview(i)},n.ScreenSpaceEventType.MOUSE_MOVE);const e=this.viewer.cesiumWidget.screenSpaceEventHandler.getInputAction(n.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);this.viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(n.ScreenSpaceEventType.LEFT_DOUBLE_CLICK),this.screenSpaceEventHandler.setInputAction(t=>{if(!this.isDrawing)return;if(!this.pickGlobePosition(t.position)){console.warn("Double-click event ignored: not on the map.");return}this._doubleClickPending=!0,this.finishDrawing(),e&&this.viewer.cesiumWidget.screenSpaceEventHandler.setInputAction(e,n.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)},n.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)}pickGlobePosition(e){const t=this.viewer.camera.getPickRay(e);if(t&&this.scene.mode===n.SceneMode.SCENE3D&&this.scene.globe.tilesLoaded){const r=this.scene.globe.pick(t,this.scene);if(n.defined(r)&&Number.isFinite(r.x)&&Number.isFinite(r.y)&&Number.isFinite(r.z))return r}const i=this.viewer.camera.pickEllipsoid(e,this.scene.globe.ellipsoid);return i&&Number.isFinite(i.x)&&Number.isFinite(i.y)&&Number.isFinite(i.z)?i:null}addPoint(e){this.drawMode==="polygon"&&this.scene.mode===n.SceneMode.SCENE3D&&!this.scene.globe.tilesLoaded||this.currentDrawer&&(this.currentDrawer.addPointForHelper(e),this.tempPositions=this.currentDrawer.getTempPositions(),this.tempEntities=this.currentDrawer.getTempEntities(),this.updateDrawingEntity())}removeLastPoint(){if(!this.currentDrawer)return;const e=this.currentDrawer.getTempPositions();!e||e.length===0||(this.currentDrawer.removeLastPointAndRedraw(),this.tempPositions=this.currentDrawer.getTempPositions(),this.tempEntities=this.currentDrawer.getTempEntities(),this.tempLabelEntities=this.currentDrawer.getTempLabelEntities(),this.lastPreviewPosition&&this.isDrawing&&this.updateDrawingEntity(this.lastPreviewPosition))}updatePreview(e){this.lastPreviewPosition=e.clone(),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.getTempPositions(),this.tempEntities=this.currentDrawer.getTempEntities(),this.tempLabelEntities=this.currentDrawer.getTempLabelEntities()}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.getTempPositions(),this.tempEntities=this.currentDrawer.getTempEntities(),this.tempLabelEntities=this.currentDrawer.getTempLabelEntities(),this.finishedPointEntities=this.currentDrawer.getFinishedPointEntities(),this.tempLabelEntities.forEach(t=>{this.finishedLabelEntities.push(t)}),this.tempLabelEntities=[],this.drawMode=null,this.isDrawing=!1,this.lastPreviewPosition=null,this.currentDrawer=null,this.deactivateDrawingHandlers(),M.activeDrawingHelper===this&&(M.activeDrawingHelper=null)}endDrawingInternal(e){if(this.currentDrawer&&(this.currentDrawer.clearTempEntitiesForHelper(),this.tempPositions=this.currentDrawer.getTempPositions(),this.tempEntities=this.currentDrawer.getTempEntities(),this.tempLabelEntities=this.currentDrawer.getTempLabelEntities()),this.tempEntities=[],this.tempLabelEntities=[],this.tempPositions=[],e){this.drawMode=null,this.isDrawing=!1,this.lastPreviewPosition=null,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{}M.activeDrawingHelper===this&&(M.activeDrawingHelper=null)}}endDrawing(){this.isDrawing?this.finishDrawing():this.endDrawingInternal(!0)}cancelDrawing(){this.isDrawing&&this.endDrawingInternal(!0)}deactivateDrawingHandlers(){this.screenSpaceEventHandler&&(this.screenSpaceEventHandler.destroy(),this.screenSpaceEventHandler=null)}clearAll(){this.endDrawing(),this.clearAllPoints(),this.finishedEntities.forEach(e=>{if(!e)return;const t=e._borderEntity;t&&this.entities.remove(t),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=[],this.tempLabelEntities=[],this.tempPositions=[],this.drawPolygon&&this.drawPolygon.clear()}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.currentDrawer&&(this.currentDrawer.clearTempPointEntitiesForHelper(),this.tempEntities=this.currentDrawer.getTempEntities());const e=this.entities.values;for(let t=e.length-1;t>=0;t--){const i=e[t];i&&i.point&&this.entities.remove(i)}}removeEntity(e){const t=this.finishedEntities.indexOf(e);if(t>-1){const i=e._borderEntity;i&&this.entities.remove(i),this.entities.remove(e),this.finishedEntities.splice(t,1),this.onEntityRemovedCallback&&this.onEntityRemovedCallback(e)}}getFinishedEntities(){return[...this.finishedEntities]}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 i=t._groundPositions;if(i&&i.length>0){const r=i.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 a=n.Cartographic.fromCartesian(s);return n.Cartesian3.fromRadians(a.longitude,a.latitude,(a.height||0)+this.offsetHeight)});t.polyline.positions=new n.ConstantProperty(o),t.polyline.clampToGround=new n.ConstantProperty(!1)}else t.polyline.positions=new n.ConstantProperty(r),t.polyline.clampToGround=new n.ConstantProperty(!0)}}else if(t.polygon){const i=t._groundPositions;if(i&&i.length>0){const r=i.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 a=n.Cartographic.fromCartesian(s);return n.Cartesian3.fromRadians(a.longitude,a.latitude,(a.height||0)+this.offsetHeight)});t.polygon.hierarchy=new n.ConstantProperty(new n.PolygonHierarchy(o)),t.polygon.heightReference=new n.ConstantProperty(n.HeightReference.NONE)}else t.polygon.hierarchy=new n.ConstantProperty(new n.PolygonHierarchy(r)),t.polygon.heightReference=new n.ConstantProperty(n.HeightReference.CLAMP_TO_GROUND)}}else t.rectangle&&t._groundRectangle&&(e?(t.rectangle.heightReference=new n.ConstantProperty(n.HeightReference.NONE),t.rectangle.extrudedHeight=new n.ConstantProperty(this.offsetHeight)):(t.rectangle.heightReference=new n.ConstantProperty(n.HeightReference.CLAMP_TO_GROUND),t.rectangle.extrudedHeight=void 0))}),this.finishedLabelEntities.forEach(t=>{if(!t)return;const i=t._groundPosition;if(i){if(t.label)if(e){const r=n.Cartographic.fromCartesian(i),o=n.Cartesian3.fromRadians(r.longitude,r.latitude,(r.height||0)+this.offsetHeight);t.position=new n.ConstantPositionProperty(o),t.label.heightReference=new n.ConstantProperty(n.HeightReference.RELATIVE_TO_GROUND)}else t.position=new n.ConstantPositionProperty(i),t.label.heightReference=new n.ConstantProperty(n.HeightReference.CLAMP_TO_GROUND);else if(t.billboard)if(e){const r=n.Cartographic.fromCartesian(i),o=n.Cartesian3.fromRadians(r.longitude,r.latitude,(r.height||0)+this.offsetHeight);t.position=new n.ConstantPositionProperty(o),t.billboard.heightReference=new n.ConstantProperty(n.HeightReference.RELATIVE_TO_GROUND)}else t.position=new n.ConstantPositionProperty(i),t.billboard.heightReference=new n.ConstantProperty(n.HeightReference.NONE)}}),this.finishedPointEntities.forEach(t=>{if(!t||!t.point)return;const i=t.position?.getValue(n.JulianDate.now());if(i){const r=n.Cartographic.fromCartesian(i),o=t._groundPosition;if(o)if(e){const s=n.Cartographic.fromCartesian(o),a=n.Cartesian3.fromRadians(s.longitude,s.latitude,(s.height||0)+this.offsetHeight);t.position=new n.ConstantPositionProperty(a),t.point.heightReference=new n.ConstantProperty(n.HeightReference.RELATIVE_TO_GROUND)}else t.position=new n.ConstantPositionProperty(o),t.point.heightReference=new n.ConstantProperty(n.HeightReference.CLAMP_TO_GROUND);else if(e){const s=n.Cartesian3.fromRadians(r.longitude,r.latitude,Math.max(0,(r.height||0)-this.offsetHeight)+this.offsetHeight);t.position=new n.ConstantPositionProperty(s),t.point.heightReference=new n.ConstantProperty(n.HeightReference.RELATIVE_TO_GROUND)}else{const s=n.Cartesian3.fromRadians(r.longitude,r.latitude,Math.max(0,(r.height||0)-this.offsetHeight));t.position=new n.ConstantPositionProperty(s),t.point.heightReference=new n.ConstantProperty(n.HeightReference.CLAMP_TO_GROUND)}}})}destroy(){if(this.deactivateDrawingHandlers(),this.entityClickHandler){try{this.entityClickHandler.destroy()}catch{}this.entityClickHandler=null}}}window.DrawHelper=M;function Q(){const e="2cca1367384c44b8b0196b47108b2813,57962be20a8da51ffd5d652bbc86325a,ef905e1aad18c1f8899ff8adb0453064,4b0c90d0a7ad9d80226e59a6a537507f,ffe26eb6d4ed64558d651e2aa0f47233".split(","),t=Math.floor(Math.random()*e.length);return e[t]}function we(c){const t=2*Math.PI*6378137,i=Math.max(10,Math.min(t,Math.abs(c))),r=Math.log2(t/(i*2))+1;return Math.max(1,Math.min(18,Math.round(r)))}function q(c){const e=Math.max(1,Math.min(18,Math.round(c)));return 2*Math.PI*6378137/(2*Math.pow(2,e-1))}class J{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 i=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 a=o.find(l=>l.id===s);if(a){const l=this.getToken?this.getToken():"";r=a.provider(l)[0]?.maximumLevel||18,i>r&&(i=r)}}(i===1||t>=r)&&this.setZoomLevel(i)})}getCurrentZoomLevel(){const e=this.viewer.camera.positionCartographic.height;return we(e)}setZoomLevel(e){try{const t=Math.max(1,Math.min(18,e)),i=q(t);if(!isFinite(i)||isNaN(i)||i<=0){console.warn(`无效的目标高度: ${i},使用默认层级 ${t}`);return}let r;try{r=this.viewer.camera.positionCartographic.clone(),(!isFinite(r.longitude)||!isFinite(r.latitude))&&(r=n.Cartographic.fromDegrees(120.2052342,30.2489634))}catch(o){console.warn("获取当前相机位置失败,使用默认位置",o),r=n.Cartographic.fromDegrees(120.2052342,30.2489634)}this.viewer.camera.setView({destination:n.Cartesian3.fromRadians(r.longitude,r.latitude,i),orientation:{heading:this.viewer.camera.heading,pitch:this.viewer.camera.pitch,roll:this.viewer.camera.roll}})}catch(t){console.error("设置地图层级失败:",t);try{const i=q(10),r=n.Cartographic.fromDegrees(120.2052342,30.2489634);this.viewer.camera.setView({destination:n.Cartesian3.fromRadians(r.longitude,r.latitude,i)})}catch(i){console.error("恢复地图层级失败:",i)}}}zoomIn(){const e=this.getCurrentZoomLevel(),t=this.viewer.camera.positionCartographic.height;let i=18;const r=this.getMapTypes?this.getMapTypes():void 0,o=this.getCurrentMapTypeId?this.getCurrentMapTypeId():void 0;if(r&&o){const l=r.find(h=>h.id===o);if(l){const h=this.getToken?this.getToken():"";if(i=l.provider(h)[0]?.maximumLevel||18,e>=i)return}}const s=e+1;this.setZoomLevel(s);const a=this.viewer.camera.positionCartographic.height;this.zoomCallback?.onZoomIn&&this.zoomCallback.onZoomIn(t,a,e)}zoomOut(){const e=this.getCurrentZoomLevel(),t=this.viewer.camera.positionCartographic.height;if(e<=1)return;const i=e-1;this.setZoomLevel(i);const r=this.viewer.camera.positionCartographic.height;this.zoomCallback?.onZoomOut&&this.zoomCallback.onZoomOut(t,r,e)}toggle2D3D(e){const t=this.viewer.scene,i=t.camera,o=t.mode===n.SceneMode.SCENE3D?n.SceneMode.SCENE2D:n.SceneMode.SCENE3D;e.innerHTML=o===n.SceneMode.SCENE3D?"3D":"2D";const s=t.canvas,a=new n.Cartesian2(s.clientWidth/2,s.clientHeight/2);let l=null;const h=i.getPickRay(a);if(h){const g=t.globe.pick(h,t);n.defined(g)&&(l=n.Cartographic.fromCartesian(g))}const d=i.positionCartographic.height,u=i.heading,m=i.pitch,w=i.roll;if(t.mode=o,this.onSceneModeChanged&&this.onSceneModeChanged(),l){const g=l.longitude,p=l.latitude;o===n.SceneMode.SCENE2D?i.setView({destination:n.Cartesian3.fromRadians(g,p,d),orientation:{heading:0,pitch:-Math.PI/2,roll:0}}):i.setView({destination:n.Cartesian3.fromRadians(g,p,d),orientation:{heading:u,pitch:m,roll:w}})}}resetLocation(){if(!this.initialCenter){console.warn("未设置初始中心点,无法执行复位操作");return}this.viewer.camera.flyTo({destination:n.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 be{viewer;drawHelper;measurementCallback;currentMode="none";constructor(e,t,i){this.viewer=e,this.drawHelper=t,this.measurementCallback=i}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.drawHelper.cancelDrawing?.(),this.currentMode="area",setTimeout(()=>{this.drawHelper.startDrawingPolygon()},50)}startDistanceMeasurement(){this.drawHelper.cancelDrawing?.(),this.currentMode="distance",setTimeout(()=>{this.drawHelper.startDrawingLine()},50)}clearMeasurements(){this.currentMode="none",this.drawHelper.clearAll(),this.measurementCallback?.onClear&&this.measurementCallback.onClear()}}const ye=Q(),Ce="73.5577,18.1597,135.0882,53.5609",ve={},xe=(c,e,t=ye)=>{const i={start:0,count:10,queryType:7,keyWord:c,mapBound:Ce,level:e?.defaultZoomLevel||15};return`http://api.tianditu.gov.cn/v2/search?postStr=${JSON.stringify(i)}&type=query&tk=${t}`};class V{viewer;toolbarElement;searchCallback;searchContainer=null;constructor(e,t,i){this.viewer=e,this.toolbarElement=t,this.searchCallback=i}setSearchCallback(e){this.searchCallback=e}toggleSearch(e){if(this.toolbarElement.querySelector(".search-container"))return;const i=e.offsetTop,r=document.createElement("div");r.className="search-container",r.style.cssText=`
|
|
2
2
|
position: absolute;
|
|
3
3
|
right: 100%;
|
|
4
4
|
top: ${i}px;
|