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