@xingm/vmap-cesium-toolbar 0.0.2-alpha.14 → 0.0.2-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +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/package.json +1 -1
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -197,7 +197,7 @@
|
|
|
197
197
|
position: absolute; top: 4px; right: 4px;
|
|
198
198
|
background: none; border: none; font-size: 16px; cursor: pointer;
|
|
199
199
|
padding: 0; line-height: 1; color: #999;
|
|
200
|
-
`,s.addEventListener("click",a=>{a.stopPropagation(),this.hide(t),e.onClose?.(t)}),i.appendChild(s)}return i}bringToFront(e){const t=e[I];t&&(this.currentTopZIndex+=1,t.zIndex=this.currentTopZIndex,t.domElement.style.zIndex=String(t.zIndex))}add(e){const t=this.mergeOptions(e),i=t.id??`infowindow_${Date.now()}_${Math.random().toString(36).slice(2,10)}`,n=this.convertPosition(t.position),o=this.viewer.entities.add({id:i,show:t.show!==!1,position:new r.ConstantPositionProperty(n)}),s=this.createDomElement(t,o);this.container.appendChild(s);const a=t.updateInterval??this.defaultUpdateInterval??0;let l=0;const c=()=>{const m=typeof performance<"u"?performance.now():Date.now();if(this.isCameraMoving)l=m;else{if(a>0&&m-l<a)return;l=m}this.updateDomPosition(o)},h=this.viewer.scene.postRender.addEventListener(c),u={domElement:s,options:{...t},cameraListener:c,postRenderListener:h,zIndex:++this.currentTopZIndex,lastUpdate:l,arrowEl:s.querySelector(".cesium-info-window-arrow")};return s.style.zIndex=String(u.zIndex),o[I]=u,this.entityMap.set(i,u),this.updateDomPosition(o),o}updatePosition(e,t){const i=this.convertPosition(t);e.position&&r.defined(e.position)&&e.position.setValue(i),this.updateDomPosition(e)}updateContent(e,t){const i=e[I];if(!i)return;const n=i.domElement.querySelector(".cesium-info-window-content");n&&(n.innerHTML="",typeof t=="string"?n.innerHTML=t:n.appendChild(t))}setVisible(e,t){const i=e[I];i&&(e.show=t,t?this.updateDomPosition(e):i.domElement.style.display="none")}show(e){this.setVisible(e,!0)}hide(e){this.setVisible(e,!1)}remove(e){const t=e.id,i=this.entityMap.get(t);i&&(i.postRenderListener(),this.container.contains(i.domElement)&&this.container.removeChild(i.domElement),this.viewer.entities.remove(e),this.entityMap.delete(t),delete e[I])}destroy(){this.cameraMoveStartListener&&(this.cameraMoveStartListener(),this.cameraMoveStartListener=void 0),this.cameraMoveEndListener&&(this.cameraMoveEndListener(),this.cameraMoveEndListener=void 0);const e=this.viewer.entities.values.slice();for(const t of e)t[I]&&this.remove(t);this.entityMap.clear()}}class we{viewer;entities;constructor(e){this.viewer=e,this.entities=e.entities}convertPosition(e){if(e instanceof r.Cartesian3){if(Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.z))return e;throw new Error("Invalid position: Cartesian3 has NaN/Infinity components")}if(Array.isArray(e)&&(e.length===2||e.length===3)){const t=Number(e[0]),i=Number(e[1]),n=e.length===3?Number(e[2]):void 0;if(!Number.isFinite(t)||!Number.isFinite(i)||n!==void 0&&!Number.isFinite(n))throw new Error("Invalid position: lon/lat/height must be finite numbers");const o=e.length===3?r.Cartesian3.fromDegrees(t,i,n):r.Cartesian3.fromDegrees(t,i);if(!Number.isFinite(o.x)||!Number.isFinite(o.y)||!Number.isFinite(o.z))throw new Error("Invalid position: converted Cartesian3 has NaN/Infinity components");return o}throw new Error("Invalid position format")}resolveColor(e){if(e instanceof r.Color)return e;try{return r.Color.fromCssColorString(e)}catch{return r.Color.WHITE}}resolveMaterial(e){return e?typeof e=="string"?new r.ColorMaterialProperty(this.resolveColor(e)):e instanceof r.Color?new r.ColorMaterialProperty(e):e:new r.ColorMaterialProperty(r.Color.YELLOW)}add(e){const t=e.positions.map(a=>this.convertPosition(a)),i=e.id||`polyline_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,n=this.resolveMaterial(e.material),o=this.entities.add({id:i,polyline:{positions:t,width:e.width??2,material:n,clampToGround:e.clampToGround??!1}});if(e.onClick){const a=o;a._onClick=e.onClick}const s=o;return s._clickHighlight=e.clickHighlight??!1,s._hoverHighlight=e.hoverHighlight??!1,s._highlightEntities=[o],o}updatePositions(e,t){const i=t.map(n=>this.convertPosition(n));e.polyline&&(e.polyline.positions=new r.ConstantProperty(i))}updateStyle(e,t){e.polyline&&(t.width!==void 0&&(e.polyline.width=new r.ConstantProperty(t.width)),t.material!==void 0&&(e.polyline.material=this.resolveMaterial(t.material)))}remove(e){const t=typeof e=="string"?this.entities.getById(e):e;return t?(t._onClick=void 0,this.entities.remove(t)):!1}}class Se{viewer;collection;fillPrimitive=null;borderPrimitive=null;records=new Map;rebuildScheduled=!1;colorApplyScheduled=!1;pendingColorApplyIds=new Set;constructor(e){this.viewer=e,this.collection=new r.PrimitiveCollection,this.viewer.scene.primitives.add(this.collection)}destroy(){try{this.fillPrimitive&&this.collection.remove(this.fillPrimitive),this.borderPrimitive&&this.collection.remove(this.borderPrimitive)}catch{}this.fillPrimitive=null,this.borderPrimitive=null;try{this.viewer.scene.primitives.remove(this.collection)}catch{}this.records.clear()}upsertGeometry(e){this.records.set(e.polygonId,{polygonId:e.polygonId,parts:e.parts,fillPositions:e.fillPositions,borderPositions:e.borderPositions,borderWidth:Math.max(1,Number(e.borderWidth)||1),fillColor:e.fillColor,borderColor:e.borderColor,visible:e.visible}),this.scheduleRebuild()}remove(e){this.records.has(e)&&(this.records.delete(e),this.pendingColorApplyIds.delete(e),this.scheduleRebuild())}setVisible(e,t){const i=this.records.get(e);i&&(i.visible=t,this.applyCurrentColors(e))}setColors(e,t,i){const n=this.records.get(e);n&&(n.borderColor=t,n.fillColor=i,this.applyCurrentColors(e))}scheduleApplyColors(e){if(this.pendingColorApplyIds.add(e),this.colorApplyScheduled)return;this.colorApplyScheduled=!0;const t=globalThis.requestAnimationFrame,i=()=>{this.colorApplyScheduled=!1;const n=Array.from(this.pendingColorApplyIds);this.pendingColorApplyIds.clear();for(const o of n)this.applyCurrentColors(o)};if(typeof t=="function"){t(i);return}setTimeout(i,0)}setBorderWidth(e,t){const i=this.records.get(e);i&&(i.borderWidth=Math.max(1,Number(t)||1),this.scheduleRebuild())}scheduleRebuild(){if(this.rebuildScheduled)return;this.rebuildScheduled=!0;const e=globalThis.requestAnimationFrame;if(typeof e=="function"){e(()=>{this.rebuildScheduled=!1,this.rebuild()});return}setTimeout(()=>{this.rebuildScheduled=!1,this.rebuild()},0)}rebuild(){if(this.fillPrimitive){try{this.collection.remove(this.fillPrimitive)}catch{}this.fillPrimitive=null}if(this.borderPrimitive){try{this.collection.remove(this.borderPrimitive)}catch{}this.borderPrimitive=null}const e=[],t=[];for(const i of this.records.values()){const n=i.visible?i.fillColor.alpha:0,o=i.visible?i.borderColor.alpha:0,s=new r.Color(i.fillColor.red,i.fillColor.green,i.fillColor.blue,n),a=new r.Color(i.borderColor.red,i.borderColor.green,i.borderColor.blue,o),l=new r.PolygonGeometry({polygonHierarchy:new r.PolygonHierarchy(i.fillPositions),vertexFormat:r.PerInstanceColorAppearance.VERTEX_FORMAT});e.push(new r.GeometryInstance({geometry:l,id:i.parts.fill,attributes:{color:r.ColorGeometryInstanceAttribute.fromColor(s)}}));const c=new r.GroundPolylineGeometry({positions:i.borderPositions,width:i.borderWidth});t.push(new r.GeometryInstance({geometry:c,id:i.parts.border,attributes:{color:r.ColorGeometryInstanceAttribute.fromColor(a)}}))}e.length>0&&(this.fillPrimitive=new r.GroundPrimitive({geometryInstances:e,appearance:new r.PerInstanceColorAppearance({translucent:!0,flat:!0}),asynchronous:!0}),this.collection.add(this.fillPrimitive)),t.length>0&&(this.borderPrimitive=new r.GroundPolylinePrimitive({geometryInstances:t,appearance:new r.PolylineColorAppearance({translucent:!0})}),this.collection.add(this.borderPrimitive));for(const i of this.records.values())this.applyCurrentColors(i.polygonId);try{this.viewer.scene.requestRender?.()}catch{}}applyCurrentColors(e){const t=this.records.get(e);if(!t)return;const i=t.visible?t.fillColor.alpha:0,n=t.visible?t.borderColor.alpha:0,o=new r.Color(t.fillColor.red,t.fillColor.green,t.fillColor.blue,i),s=new r.Color(t.borderColor.red,t.borderColor.green,t.borderColor.blue,n);let a=!1;try{if(this.fillPrimitive)if(this.fillPrimitive.ready){const l=this.fillPrimitive.getGeometryInstanceAttributes(t.parts.fill);l&&l.color&&(l.color=r.ColorGeometryInstanceAttribute.toValue(o))}else a=!0}catch{}try{if(this.borderPrimitive)if(this.borderPrimitive.ready){const l=this.borderPrimitive.getGeometryInstanceAttributes(t.parts.border);l&&l.color&&(l.color=r.ColorGeometryInstanceAttribute.toValue(s))}else a=!0}catch{}a&&this.scheduleApplyColors(e);try{this.viewer.scene.requestRender?.()}catch{}}}class ve{viewer;entities;primitiveBatch=null;constructor(e){this.viewer=e,this.entities=e.entities}getPrimitiveBatch(){return this.primitiveBatch||(this.primitiveBatch=new Se(this.viewer)),this.primitiveBatch}resolveMaterialColor(e){return e?typeof e=="string"?this.resolveColor(e):e instanceof r.Color?e:null:r.Color.BLUE.withAlpha(.5)}canUsePrimitive(e){return!(!((e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0)>0)||!(e.clampToGround??!0)||e.extrudedHeight!==void 0||this.resolveMaterialColor(e.material??r.Color.ORANGE.withAlpha(.5))===null||e.outlineColor!==void 0&&this.resolveColor(e.outlineColor)===null)}addPrimitivePolygon(e){const t=e.positions.map(x=>this.convertPosition(x)),i=e.id||`polygon_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,n=e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0,o=e.clampToGround??!0;if(!(n>0)||!o||e.extrudedHeight!==void 0)return console.warn("[vmap-cesium-tool] Polygon renderMode=primitive is not supported for the given options; falling back to Entity."),this.add({...e,renderMode:"entity"});const s=this.resolveMaterialColor(e.material??r.Color.ORANGE.withAlpha(.5));if(!s)return console.warn("[vmap-cesium-tool] Polygon renderMode=primitive requires solid color material; falling back to Entity."),this.add({...e,renderMode:"entity"});const a=e.outlineColor?this.resolveColor(e.outlineColor):r.Color.ORANGE,l=Math.max(1,Number(n)||1),c=new r.Entity({id:i}),h=new r.Entity({id:`${i}__border`}),u=c,m=h;u._overlayType="polygon-primitive",m._overlayType="polygon-primitive",e.onClick&&(u._onClick=e.onClick,m._onClick=e.onClick);const f=[c,h],p=e.clickHighlight??!1,g=e.hoverHighlight??!1;u._clickHighlight=p,m._clickHighlight=p,u._hoverHighlight=g,m._hoverHighlight=g,u._highlightEntities=f,m._highlightEntities=f,u._borderEntity=h,u._isThickOutline=!0,u._outlineWidth=l,u._clampToGround=!0,u._baseHeight=0,u._primitiveFillBaseColor=s,u._primitiveBorderBaseColor=a,m._primitiveFillBaseColor=s,m._primitiveBorderBaseColor=a;const y=this.elevatePositions(t,0),w=y,v=w.slice();return v.length>=2&&v.push(w[0]),this.getPrimitiveBatch().upsertGeometry({polygonId:i,parts:{fill:c,border:h},fillPositions:y,borderPositions:v,borderWidth:l,fillColor:s,borderColor:a,visible:!0}),c}convertPosition(e){if(e instanceof r.Cartesian3){if(Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.z))return e;throw new Error("Invalid position: Cartesian3 has NaN/Infinity components")}if(Array.isArray(e)&&(e.length===2||e.length===3)){const t=Number(e[0]),i=Number(e[1]),n=e.length===3?Number(e[2]):void 0;if(!Number.isFinite(t)||!Number.isFinite(i)||n!==void 0&&!Number.isFinite(n))throw new Error("Invalid position: lon/lat/height must be finite numbers");const o=e.length===3?r.Cartesian3.fromDegrees(t,i,n):r.Cartesian3.fromDegrees(t,i);if(!Number.isFinite(o.x)||!Number.isFinite(o.y)||!Number.isFinite(o.z))throw new Error("Invalid position: converted Cartesian3 has NaN/Infinity components");return o}throw new Error("Invalid position format")}resolveColor(e){if(e instanceof r.Color)return e;try{return r.Color.fromCssColorString(e)}catch{return r.Color.WHITE}}resolveMaterial(e){return e?typeof e=="string"?new r.ColorMaterialProperty(this.resolveColor(e)):e instanceof r.Color?new r.ColorMaterialProperty(e):e:new r.ColorMaterialProperty(r.Color.BLUE.withAlpha(.5))}polygonArea2D(e){let t=0;for(let i=0,n=e.length;i<n;i++){const o=e[i],s=e[(i+1)%n];t+=o.x*s.y-s.x*o.y}return t*.5}offsetPolygon2DInward(e,t){const i=e.length;if(i<3)return e.slice();const o=this.polygonArea2D(e)>0,s=[];for(let c=0;c<i;c++){const h=e[c],u=e[(c+1)%i],m=u.x-h.x,f=u.y-h.y,p=Math.hypot(m,f)||1,g=m/p,y=f/p,w=o?-y:y,v=o?g:-g;s.push(new r.Cartesian2(-w,-v))}const a=[];for(let c=0;c<i;c++){const h=e[c],u=s[c];a.push(u.x*h.x+u.y*h.y+t)}const l=[];for(let c=0;c<i;c++){const h=(c-1+i)%i,u=s[h],m=a[h],f=s[c],p=a[c],g=u.x*f.y-f.x*u.y;if(Math.abs(g)<1e-8){const y=e[c];l.push(new r.Cartesian2(y.x+f.x*t,y.y+f.y*t))}else{const y=(m*f.y-p*u.y)/g,w=(u.x*p-f.x*m)/g;l.push(new r.Cartesian2(y,w))}}return l}computeInnerOffsetPositions(e,t,i){const n=r.EllipsoidTangentPlane.fromPoints(e),o=n.projectPointsOntoPlane(e),s=this.offsetPolygon2DInward(o,t);return n.projectPointsOntoEllipsoid(s).map(l=>{const c=r.Cartographic.fromCartesian(l);return r.Cartesian3.fromRadians(c.longitude,c.latitude,i)})}elevatePositions(e,t){return e.map(i=>{const n=r.Cartographic.fromCartesian(i);return r.Cartesian3.fromRadians(n.longitude,n.latitude,t)})}add(e){const t=e.renderMode??"auto";if((t==="primitive"||t==="auto")&&this.canUsePrimitive(e))return this.addPrimitivePolygon(e);const i=e.positions.map(m=>this.convertPosition(m)),n=e.id||`polygon_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,o=this.resolveMaterial(e.material),s=e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0;if(s&&s>0){const m=e.clampToGround??!0,f=m?0:r.Cartographic.fromCartesian(i[0])?.height??0,p=m?r.HeightReference.CLAMP_TO_GROUND:e.heightReference??r.HeightReference.NONE,g=this.elevatePositions(i,0),y=this.entities.add({id:n,polygon:{hierarchy:g,material:this.resolveMaterial(e.material??r.Color.ORANGE.withAlpha(.5)),outline:!1,heightReference:p,...m?{}:{height:f},extrudedHeight:e.extrudedHeight}}),w=this.elevatePositions(i,f),v=w.slice();v.length>=2&&v.push(w[0]);const x=this.entities.add({polyline:{positions:v,width:s,material:new r.ColorMaterialProperty(this.resolveColor(e.outlineColor??r.Color.ORANGE)),clampToGround:m,...m?{zIndex:1}:{}}});if(e.onClick){const R=y,D=x;R._onClick=e.onClick,D._onClick=e.onClick}const C=y,b=x,P=[y,x],N=e.clickHighlight??!1,T=e.hoverHighlight??!1;return C._clickHighlight=N,b._clickHighlight=N,C._hoverHighlight=T,b._hoverHighlight=T,C._highlightEntities=P,b._highlightEntities=P,C._borderEntity=x,C._isThickOutline=!0,C._outlineWidth=s,C._clampToGround=m,C._baseHeight=f,y}const a=e.clampToGround??!0,l=e.heightReference??(a?r.HeightReference.CLAMP_TO_GROUND:r.HeightReference.NONE),c=a?this.elevatePositions(i,0):i,h=this.entities.add({id:n,polygon:{hierarchy:c,material:o,outline:e.outline??!0,outlineColor:e.outlineColor?this.resolveColor(e.outlineColor):r.Color.BLACK,outlineWidth:e.outlineWidth??1,heightReference:l,extrudedHeight:e.extrudedHeight}});if(e.onClick){const m=h;m._onClick=e.onClick}const u=h;return u._clickHighlight=e.clickHighlight??!1,u._hoverHighlight=e.hoverHighlight??!1,u._highlightEntities=[h],h._clampToGround=a,h}updatePositions(e,t){const i=t.map(a=>this.convertPosition(a)),n=e;if(n._overlayType==="polygon-primitive"){const a=n._borderEntity;if(!a)return;const l=String(e.id),c=this.elevatePositions(i,0),h=c,u=h.slice();u.length>=2&&u.push(h[0]);const m=n._primitiveFillBaseColor??r.Color.ORANGE.withAlpha(.5),f=n._primitiveBorderBaseColor??r.Color.ORANGE,p=Math.max(1,Number(n._outlineWidth??2)||2);this.getPrimitiveBatch().upsertGeometry({polygonId:l,parts:{fill:e,border:a},fillPositions:c,borderPositions:u,borderWidth:p,fillColor:m,borderColor:f,visible:e.show!==!1});return}const o=n._borderEntity,s=n._isThickOutline;if(e.polygon&&o&&s){const a=n._clampToGround??!0,l=a?0:r.Cartographic.fromCartesian(i[0])?.height??0;n._baseHeight=l;const c=this.elevatePositions(i,0);e.polygon.hierarchy=new r.ConstantProperty(new r.PolygonHierarchy(c)),a||(e.polygon.height=new r.ConstantProperty(l));const h=this.elevatePositions(i,l),u=h.slice();u.length>=2&&u.push(h[0]),o.polyline&&(o.polyline.positions=new r.ConstantProperty(u),o.polyline.clampToGround=new r.ConstantProperty(a))}else if(e.polygon){const a=n._clampToGround??!1,l=a?this.elevatePositions(i,0):i;e.polygon.hierarchy=new r.ConstantProperty(new r.PolygonHierarchy(l)),a&&(e.polygon.heightReference=new r.ConstantProperty(r.HeightReference.CLAMP_TO_GROUND))}}updateStyle(e,t){const i=e;if(i._overlayType==="polygon-primitive"){const s=String(e.id);if(t.material!==void 0){const c=this.resolveMaterialColor(t.material);if(c){i._primitiveFillBaseColor=c;const h=i._borderEntity;h&&(h._primitiveFillBaseColor=c)}}if(t.outlineColor!==void 0){const c=this.resolveColor(t.outlineColor);i._primitiveBorderBaseColor=c;const h=i._borderEntity;h&&(h._primitiveBorderBaseColor=c)}if(t.outlineWidth!==void 0){const c=Math.max(1,Number(t.outlineWidth)||1);i._outlineWidth=c,this.getPrimitiveBatch().setBorderWidth(s,c)}const a=i._primitiveFillBaseColor??r.Color.ORANGE.withAlpha(.5),l=i._primitiveBorderBaseColor??r.Color.ORANGE;this.getPrimitiveBatch().setColors(s,l,a);return}const n=i._borderEntity;i._isThickOutline&&e.polygon&&n?(t.material!==void 0&&(e.polygon.material=this.resolveMaterial(t.material)),t.outlineColor!==void 0&&n.polyline&&(n.polyline.material=new r.ColorMaterialProperty(this.resolveColor(t.outlineColor))),t.outlineWidth!==void 0&&n.polyline&&(n.polyline.width=new r.ConstantProperty(Math.max(0,t.outlineWidth)),i._outlineWidth=t.outlineWidth)):e.polygon&&(t.material!==void 0&&(e.polygon.material=this.resolveMaterial(t.material)),t.outline!==void 0&&(e.polygon.outline=new r.ConstantProperty(t.outline)),t.outlineColor!==void 0&&(e.polygon.outlineColor=new r.ConstantProperty(this.resolveColor(t.outlineColor))),t.outlineWidth!==void 0&&(e.polygon.outlineWidth=new r.ConstantProperty(t.outlineWidth)))}remove(e){const t=typeof e=="string"?this.entities.getById(e):e,i=typeof e!="string"?e:t,n=i;if(n&&n._overlayType==="polygon-primitive"){const a=String(i.id);try{this.getPrimitiveBatch().remove(a)}catch{}const l=n._borderEntity;return l&&(l._onClick=void 0,n._borderEntity=void 0),n._onClick=void 0,!0}if(!t)return!1;const o=t,s=o._borderEntity;return s&&(s._onClick=void 0,this.entities.remove(s)),o._onClick=void 0,this.entities.remove(t)}setPrimitiveVisible(e,t){if(e._overlayType!=="polygon-primitive")return;const n=String(e.id);this.getPrimitiveBatch().setVisible(n,t)}applyPrimitiveHighlight(e,t,i){if(e._overlayType!=="polygon-primitive")return;const n=e._highlightEntities&&e._highlightEntities.length>0?e._highlightEntities[0]:e,o=String(n.id);n._primitiveBorderBaseColor||(n._primitiveBorderBaseColor=r.Color.ORANGE),n._primitiveFillBaseColor||(n._primitiveFillBaseColor=r.Color.ORANGE.withAlpha(.5));const s=t.withAlpha(1),a=t.withAlpha(i);this.getPrimitiveBatch().setColors(o,s,a),e._isHighlighted=!0}restorePrimitiveHighlight(e){if(e._overlayType!=="polygon-primitive")return;const t=e._highlightEntities&&e._highlightEntities.length>0?e._highlightEntities[0]:e,i=String(t.id);t._primitiveBorderBaseColor&&t._primitiveFillBaseColor&&this.getPrimitiveBatch().setColors(i,t._primitiveBorderBaseColor,t._primitiveFillBaseColor),e._isHighlighted=!1}}class Be{viewer;collection;ringPrimitive=null;fillPrimitive=null;records=new Map;rebuildScheduled=!1;colorApplyScheduled=!1;pendingColorApplyIds=new Set;constructor(e){this.viewer=e,this.collection=new r.PrimitiveCollection,this.viewer.scene.primitives.add(this.collection)}destroy(){try{this.ringPrimitive&&this.collection.remove(this.ringPrimitive),this.fillPrimitive&&this.collection.remove(this.fillPrimitive),this.ringPrimitive=null,this.fillPrimitive=null}catch{}try{this.viewer.scene.primitives.remove(this.collection)}catch{}this.records.clear()}upsertGeometry(e){this.records.set(e.rectangleId,{rectangleId:e.rectangleId,parts:e.parts,outerPositions:e.outerPositions,innerPositions:e.innerPositions,ringColor:e.ringColor,fillColor:e.fillColor,visible:e.visible}),this.scheduleRebuild()}remove(e){this.records.has(e)&&(this.records.delete(e),this.pendingColorApplyIds.delete(e),this.scheduleRebuild())}setVisible(e,t){const i=this.records.get(e);i&&(i.visible=t,this.applyCurrentColors(e))}setColors(e,t,i){const n=this.records.get(e);n&&(n.ringColor=t,n.fillColor=i,this.applyCurrentColors(e))}scheduleApplyColors(e){if(this.pendingColorApplyIds.add(e),this.colorApplyScheduled)return;this.colorApplyScheduled=!0;const t=globalThis.requestAnimationFrame,i=()=>{this.colorApplyScheduled=!1;const n=Array.from(this.pendingColorApplyIds);this.pendingColorApplyIds.clear();for(const o of n)this.applyCurrentColors(o)};if(typeof t=="function"){t(i);return}setTimeout(i,0)}scheduleRebuild(){if(this.rebuildScheduled)return;this.rebuildScheduled=!0;const e=globalThis.requestAnimationFrame;if(typeof e=="function"){e(()=>{this.rebuildScheduled=!1,this.rebuild()});return}setTimeout(()=>{this.rebuildScheduled=!1,this.rebuild()},0)}rebuild(){if(this.ringPrimitive){try{this.collection.remove(this.ringPrimitive)}catch{}this.ringPrimitive=null}if(this.fillPrimitive){try{this.collection.remove(this.fillPrimitive)}catch{}this.fillPrimitive=null}const e=[],t=[];for(const i of this.records.values()){const n=i.visible?i.ringColor.alpha:0,o=i.visible?i.fillColor.alpha:0,s=new r.Color(i.ringColor.red,i.ringColor.green,i.ringColor.blue,n),a=new r.Color(i.fillColor.red,i.fillColor.green,i.fillColor.blue,o),l=new r.PolygonGeometry({polygonHierarchy:new r.PolygonHierarchy(i.outerPositions,[new r.PolygonHierarchy(i.innerPositions)]),vertexFormat:r.PerInstanceColorAppearance.VERTEX_FORMAT});e.push(new r.GeometryInstance({geometry:l,id:i.parts.outer,attributes:{color:r.ColorGeometryInstanceAttribute.fromColor(s)}}));const c=new r.PolygonGeometry({polygonHierarchy:new r.PolygonHierarchy(i.innerPositions),vertexFormat:r.PerInstanceColorAppearance.VERTEX_FORMAT});t.push(new r.GeometryInstance({geometry:c,id:i.parts.inner,attributes:{color:r.ColorGeometryInstanceAttribute.fromColor(a)}}))}e.length>0&&(this.ringPrimitive=new r.GroundPrimitive({geometryInstances:e,appearance:new r.PerInstanceColorAppearance({translucent:!0,flat:!0}),asynchronous:!0}),this.collection.add(this.ringPrimitive)),t.length>0&&(this.fillPrimitive=new r.GroundPrimitive({geometryInstances:t,appearance:new r.PerInstanceColorAppearance({translucent:!0,flat:!0}),asynchronous:!0}),this.collection.add(this.fillPrimitive));for(const i of this.records.values())this.applyCurrentColors(i.rectangleId);try{this.viewer.scene.requestRender?.()}catch{}}applyCurrentColors(e){const t=this.records.get(e);if(!t)return;const i=t.visible?t.ringColor.alpha:0,n=t.visible?t.fillColor.alpha:0,o=new r.Color(t.ringColor.red,t.ringColor.green,t.ringColor.blue,i),s=new r.Color(t.fillColor.red,t.fillColor.green,t.fillColor.blue,n);let a=!1;try{if(this.ringPrimitive)if(this.ringPrimitive.ready){const l=this.ringPrimitive.getGeometryInstanceAttributes(t.parts.outer);l&&l.color&&(l.color=r.ColorGeometryInstanceAttribute.toValue(o))}else a=!0}catch{}try{if(this.fillPrimitive)if(this.fillPrimitive.ready){const l=this.fillPrimitive.getGeometryInstanceAttributes(t.parts.inner);l&&l.color&&(l.color=r.ColorGeometryInstanceAttribute.toValue(s))}else a=!0}catch{}a&&this.scheduleApplyColors(e);try{this.viewer.scene.requestRender?.()}catch{}}}class be{viewer;entities;primitiveBatch=null;constructor(e){this.viewer=e,this.entities=e.entities}getPrimitiveBatch(){return this.primitiveBatch||(this.primitiveBatch=new Be(this.viewer)),this.primitiveBatch}resolveMaterialColor(e){return e?typeof e=="string"?this.resolveColor(e):e instanceof r.Color?e:null:r.Color.BLUE.withAlpha(.5)}canUsePrimitive(e){return!(!((e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0)>0)||!(e.clampToGround??!0)||e.extrudedHeight!==void 0||this.resolveMaterialColor(e.material)===null||e.outlineColor!==void 0&&!(this.resolveColor(e.outlineColor)instanceof r.Color))}addPrimitiveRectangle(e){const t=e.id||`rectangle_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,i=e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0,n=e.clampToGround??!0;if(!(i>0)||!n||e.extrudedHeight!==void 0)return console.warn("[vmap-cesium-tool] Rectangle renderMode=primitive is not supported for the given options; falling back to Entity."),this.add({...e,renderMode:"entity"});const o=this.resolveMaterialColor(e.material);if(!o)return console.warn("[vmap-cesium-tool] Rectangle renderMode=primitive requires solid color material; falling back to Entity."),this.add({...e,renderMode:"entity"});const s=e.outlineColor?this.resolveColor(e.outlineColor):r.Color.BLACK,a=new r.Entity({id:t}),l=new r.Entity({id:`${t}__fill`}),c=a,h=l;c._overlayType="rectangle-primitive",h._overlayType="rectangle-primitive";const u=[a,l],m=e.clickHighlight??!1,f=e.hoverHighlight??!1;c._clickHighlight=m,h._clickHighlight=m,c._hoverHighlight=f,h._hoverHighlight=f,c._highlightEntities=u,h._highlightEntities=u,c._innerEntity=l,c._isRing=!0,c._ringThickness=i,c._outerRectangle=e.coordinates,c._clampToGround=!0,c._baseHeight=0,c._primitiveRingBaseColor=s,c._primitiveFillBaseColor=o,h._primitiveRingBaseColor=s,h._primitiveFillBaseColor=o,e.onClick&&(c._onClick=e.onClick,h._onClick=e.onClick);const p=this.rectangleToPositions(e.coordinates,0),g=this.shrinkRectangle(e.coordinates,i),y=this.rectangleToPositions(g,0);return this.getPrimitiveBatch().upsertGeometry({rectangleId:t,parts:{outer:a,inner:l},outerPositions:p,innerPositions:y,ringColor:s,fillColor:o,visible:!0}),a}resolveColor(e){if(e instanceof r.Color)return e;try{return r.Color.fromCssColorString(e)}catch{return r.Color.WHITE}}resolveMaterial(e){return e?typeof e=="string"?new r.ColorMaterialProperty(this.resolveColor(e)):e instanceof r.Color?new r.ColorMaterialProperty(e):e:new r.ColorMaterialProperty(r.Color.BLUE.withAlpha(.5))}rectangleToPositions(e,t){const i=e.west,n=e.south,o=e.east,s=e.north;return[r.Cartesian3.fromRadians(i,n,t),r.Cartesian3.fromRadians(o,n,t),r.Cartesian3.fromRadians(o,s,t),r.Cartesian3.fromRadians(i,s,t)]}shrinkRectangle(e,t){const n=(e.north+e.south)/2,o=t/6378137,s=t/(6378137*Math.cos(n)),a=(e.east-e.west)/2*.999,l=(e.north-e.south)/2*.999,c=Math.min(s,a),h=Math.min(o,l);return new r.Rectangle(e.west+c,e.south+h,e.east-c,e.north-h)}add(e){const t=e.id||`rectangle_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,i=this.resolveMaterial(e.material),n=e.renderMode??"auto";if(n==="primitive"||n==="auto"&&this.canUsePrimitive(e))return this.addPrimitiveRectangle({...e,id:t,renderMode:"primitive"});const o=e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0;if(o&&o>0){const h=e.clampToGround??!0,u=h?0:e.height??0,m=h?r.HeightReference.CLAMP_TO_GROUND:e.heightReference??r.HeightReference.NONE,f=e.heightEpsilon??(h?0:.1),p=u+f,g=this.rectangleToPositions(e.coordinates,0),y=this.shrinkRectangle(e.coordinates,o),w=this.rectangleToPositions(y,0),v=this.entities.add({id:t,polygon:{hierarchy:new r.PolygonHierarchy(g,[new r.PolygonHierarchy(w)]),material:new r.ColorMaterialProperty(e.outlineColor?this.resolveColor(e.outlineColor):r.Color.BLACK),outline:!1,heightReference:m,...h?{}:{height:p}}}),x=this.entities.add({id:`${t}__fill`,rectangle:{coordinates:y,material:i,outline:!1,heightReference:m,...h?{}:{height:p},extrudedHeight:e.extrudedHeight}});if(e.onClick){const R=v,D=x;R._onClick=e.onClick,D._onClick=e.onClick}const C=v,b=x,P=[v,x],N=e.clickHighlight??!1,T=e.hoverHighlight??!1;return C._clickHighlight=N,b._clickHighlight=N,C._hoverHighlight=T,b._hoverHighlight=T,C._highlightEntities=P,b._highlightEntities=P,C._innerEntity=x,C._isRing=!0,C._ringThickness=o,C._outerRectangle=e.coordinates,C._clampToGround=h,C._baseHeight=u,C._ringHeightEpsilon=f,v}const s=e.clampToGround??!0,a=e.heightReference??(s?r.HeightReference.CLAMP_TO_GROUND:r.HeightReference.NONE),l=this.entities.add({id:t,rectangle:{coordinates:e.coordinates,material:i,outline:e.outline??!0,outlineColor:e.outlineColor?this.resolveColor(e.outlineColor):r.Color.BLACK,outlineWidth:e.outlineWidth??1,heightReference:a,...!s&&e.height!==void 0?{height:e.height}:{},extrudedHeight:e.extrudedHeight}});if(e.onClick){const h=l;h._onClick=e.onClick}const c=l;return c._clickHighlight=e.clickHighlight??!1,c._hoverHighlight=e.hoverHighlight??!1,c._highlightEntities=[l],l._clampToGround=s,l}updateCoordinates(e,t){const i=e;if(i._overlayType==="rectangle-primitive"){const s=e,a=String(s.id),l=s._innerEntity;if(!l)return;const c=s._ringThickness??0,h=this.rectangleToPositions(t,0),u=this.shrinkRectangle(t,c),m=this.rectangleToPositions(u,0),f=s._primitiveRingBaseColor??r.Color.BLACK,p=s._primitiveFillBaseColor??r.Color.BLUE.withAlpha(.5);this.getPrimitiveBatch().upsertGeometry({rectangleId:a,parts:{outer:e,inner:l},outerPositions:h,innerPositions:m,ringColor:f,fillColor:p,visible:e.show!==!1}),s._outerRectangle=t;return}const n=i._innerEntity,o=i._ringThickness;if(e.polygon&&n&&o){const s=i._clampToGround??!0,a=s?0:i._baseHeight??0,l=i._ringHeightEpsilon??(s?0:.1),c=a+l,h=this.rectangleToPositions(t,0),u=this.shrinkRectangle(t,o),m=this.rectangleToPositions(u,0);e.polygon.hierarchy=new r.ConstantProperty(new r.PolygonHierarchy(h,[new r.PolygonHierarchy(m)])),n.rectangle.coordinates=new r.ConstantProperty(u),n.rectangle&&(s?n.rectangle.height=void 0:n.rectangle.height=new r.ConstantProperty(c)),!s&&e.polygon&&(e.polygon.height=new r.ConstantProperty(c)),i._outerRectangle=t}else e.rectangle&&(e.rectangle.coordinates=new r.ConstantProperty(t))}updateStyle(e,t){const i=e;if(i._overlayType==="rectangle-primitive"){const s=e,a=String(s.id),l=s._innerEntity;if(!l)return;if(t.outlineColor!==void 0&&(s._primitiveRingBaseColor=this.resolveColor(t.outlineColor),l._primitiveRingBaseColor=s._primitiveRingBaseColor),t.material!==void 0){const c=this.resolveMaterialColor(t.material);c&&(s._primitiveFillBaseColor=c,l._primitiveFillBaseColor=c)}if(t.outlineWidth!==void 0){s._ringThickness=Math.max(0,Number(t.outlineWidth)||0);const c=s._outerRectangle;c&&this.updateCoordinates(e,c)}s._primitiveRingBaseColor&&s._primitiveFillBaseColor&&this.getPrimitiveBatch().setColors(a,s._primitiveRingBaseColor,s._primitiveFillBaseColor);return}const n=i._innerEntity;if(i._isRing&&e.polygon&&n){if(t.outlineColor!==void 0&&(e.polygon.material=new r.ColorMaterialProperty(this.resolveColor(t.outlineColor))),t.material!==void 0&&(n.rectangle.material=this.resolveMaterial(t.material)),t.outlineWidth!==void 0){const s=Math.max(0,t.outlineWidth);i._ringThickness=s;const a=i._outerRectangle??void 0;if(a){const l=i._clampToGround??!0,c=l?0:i._baseHeight??0,h=i._ringHeightEpsilon??(l?0:.1),u=c+h,m=this.rectangleToPositions(a,0),f=this.shrinkRectangle(a,s),p=this.rectangleToPositions(f,0);e.polygon.hierarchy=new r.ConstantProperty(new r.PolygonHierarchy(m,[new r.PolygonHierarchy(p)])),n.rectangle.coordinates=new r.ConstantProperty(f),n.rectangle&&(l?n.rectangle.height=void 0:n.rectangle.height=new r.ConstantProperty(u)),!l&&e.polygon&&(e.polygon.height=new r.ConstantProperty(u))}}}else e.rectangle&&(t.material!==void 0&&(e.rectangle.material=this.resolveMaterial(t.material)),t.outline!==void 0&&(e.rectangle.outline=new r.ConstantProperty(t.outline)),t.outlineColor!==void 0&&(e.rectangle.outlineColor=new r.ConstantProperty(this.resolveColor(t.outlineColor))),t.outlineWidth!==void 0&&(e.rectangle.outlineWidth=new r.ConstantProperty(t.outlineWidth)))}remove(e){const t=typeof e=="string"?this.entities.getById(e):e,i=typeof e!="string"?e:t,n=i;if(n&&n._overlayType==="rectangle-primitive"){const a=String(i.id);try{this.getPrimitiveBatch().remove(a)}catch{}const l=n._innerEntity;return l&&(l._onClick=void 0,n._innerEntity=void 0),n._onClick=void 0,!0}if(!t)return!1;const o=t,s=o._innerEntity;return s&&(s._onClick=void 0,this.entities.remove(s)),o._onClick=void 0,this.entities.remove(t)}setPrimitiveVisible(e,t){if(e._overlayType!=="rectangle-primitive")return;const n=String(e.id);this.getPrimitiveBatch().setVisible(n,t)}applyPrimitiveHighlight(e,t,i){if(e._overlayType!=="rectangle-primitive")return;const n=e._highlightEntities&&e._highlightEntities.length>0?e._highlightEntities[0]:e,o=String(n.id);n._primitiveRingBaseColor||(n._primitiveRingBaseColor=r.Color.BLACK),n._primitiveFillBaseColor||(n._primitiveFillBaseColor=r.Color.BLUE.withAlpha(.5));const s=t.withAlpha(1),a=t.withAlpha(i);this.getPrimitiveBatch().setColors(o,s,a),e._isHighlighted=!0}restorePrimitiveHighlight(e){if(e._overlayType!=="rectangle-primitive")return;const t=e._highlightEntities&&e._highlightEntities.length>0?e._highlightEntities[0]:e,i=String(t.id);t._primitiveRingBaseColor&&t._primitiveFillBaseColor&&this.getPrimitiveBatch().setColors(i,t._primitiveRingBaseColor,t._primitiveFillBaseColor),e._isHighlighted=!1}}class Xe{viewer;collection;ringPrimitive=null;fillPrimitive=null;records=new Map;rebuildScheduled=!1;colorApplyScheduled=!1;pendingColorApplyIds=new Set;constructor(e){this.viewer=e,this.collection=new r.PrimitiveCollection,this.viewer.scene.primitives.add(this.collection)}destroy(){try{this.ringPrimitive&&this.collection.remove(this.ringPrimitive),this.fillPrimitive&&this.collection.remove(this.fillPrimitive),this.ringPrimitive=null,this.fillPrimitive=null}catch{}try{this.viewer.scene.primitives.remove(this.collection)}catch{}this.records.clear()}has(e){return this.records.has(e)}upsertGeometry(e){this.records.set(e.circleId,{circleId:e.circleId,parts:e.parts,ringPositions:e.ringPositions,fillPositions:e.fillPositions,ringColor:e.ringColor,fillColor:e.fillColor,visible:e.visible}),this.scheduleRebuild()}remove(e){this.records.has(e)&&(this.records.delete(e),this.pendingColorApplyIds.delete(e),this.scheduleRebuild())}setVisible(e,t){const i=this.records.get(e);i&&(i.visible=t,this.applyCurrentColors(e))}setColors(e,t,i){const n=this.records.get(e);n&&(n.ringColor=t,n.fillColor=i,this.applyCurrentColors(e))}scheduleApplyColors(e){if(this.pendingColorApplyIds.add(e),this.colorApplyScheduled)return;this.colorApplyScheduled=!0;const t=globalThis.requestAnimationFrame,i=()=>{this.colorApplyScheduled=!1;const n=Array.from(this.pendingColorApplyIds);this.pendingColorApplyIds.clear();for(const o of n)this.applyCurrentColors(o)};if(typeof t=="function"){t(i);return}setTimeout(i,0)}scheduleRebuild(){if(this.rebuildScheduled)return;this.rebuildScheduled=!0;const e=globalThis.requestAnimationFrame;if(typeof e=="function"){e(()=>{this.rebuildScheduled=!1,this.rebuild()});return}setTimeout(()=>{this.rebuildScheduled=!1,this.rebuild()},0)}rebuild(){if(this.ringPrimitive){try{this.collection.remove(this.ringPrimitive)}catch{}this.ringPrimitive=null}if(this.fillPrimitive){try{this.collection.remove(this.fillPrimitive)}catch{}this.fillPrimitive=null}const e=[],t=[];for(const i of this.records.values()){const n=i.visible?i.ringColor.alpha:0,o=i.visible?i.fillColor.alpha:0,s=new r.Color(i.ringColor.red,i.ringColor.green,i.ringColor.blue,n),a=new r.Color(i.fillColor.red,i.fillColor.green,i.fillColor.blue,o),l=new r.PolygonGeometry({polygonHierarchy:new r.PolygonHierarchy(i.ringPositions,[new r.PolygonHierarchy(i.fillPositions)]),vertexFormat:r.PerInstanceColorAppearance.VERTEX_FORMAT});e.push(new r.GeometryInstance({geometry:l,id:i.parts.outer,attributes:{color:r.ColorGeometryInstanceAttribute.fromColor(s)}}));const c=new r.PolygonGeometry({polygonHierarchy:new r.PolygonHierarchy(i.fillPositions),vertexFormat:r.PerInstanceColorAppearance.VERTEX_FORMAT});t.push(new r.GeometryInstance({geometry:c,id:i.parts.inner,attributes:{color:r.ColorGeometryInstanceAttribute.fromColor(a)}}))}e.length>0&&(this.ringPrimitive=new r.GroundPrimitive({geometryInstances:e,appearance:new r.PerInstanceColorAppearance({translucent:!0,flat:!0}),asynchronous:!0}),this.collection.add(this.ringPrimitive)),t.length>0&&(this.fillPrimitive=new r.GroundPrimitive({geometryInstances:t,appearance:new r.PerInstanceColorAppearance({translucent:!0,flat:!0}),asynchronous:!0}),this.collection.add(this.fillPrimitive));for(const i of this.records.values())this.applyCurrentColors(i.circleId);try{this.viewer.scene.requestRender?.()}catch{}}applyCurrentColors(e){const t=this.records.get(e);if(!t)return;const i=t.visible?t.ringColor.alpha:0,n=t.visible?t.fillColor.alpha:0,o=new r.Color(t.ringColor.red,t.ringColor.green,t.ringColor.blue,i),s=new r.Color(t.fillColor.red,t.fillColor.green,t.fillColor.blue,n);let a=!1;try{if(this.ringPrimitive)if(this.ringPrimitive.ready){const l=this.ringPrimitive.getGeometryInstanceAttributes(t.parts.outer);l&&l.color&&(l.color=r.ColorGeometryInstanceAttribute.toValue(o))}else a=!0}catch{}try{if(this.fillPrimitive)if(this.fillPrimitive.ready){const l=this.fillPrimitive.getGeometryInstanceAttributes(t.parts.inner);l&&l.color&&(l.color=r.ColorGeometryInstanceAttribute.toValue(s))}else a=!0}catch{}a&&this.scheduleApplyColors(e);try{this.viewer.scene.requestRender?.()}catch{}}}class z{viewer;entities;primitiveBatch=null;static bearingTableCache=new Map;constructor(e){this.viewer=e,this.entities=e.entities}getPrimitiveBatch(){return this.primitiveBatch||(this.primitiveBatch=new Xe(this.viewer)),this.primitiveBatch}resolveMaterialColor(e){return e?typeof e=="string"?this.resolveColor(e):e instanceof r.Color?e:null:r.Color.BLUE.withAlpha(.5)}canUsePrimitive(e){return!(!((e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0)>0)||!(e.clampToGround??!0)||e.extrudedHeight!==void 0||this.resolveMaterialColor(e.material)===null)}addPrimitiveCircle(e){const t=e.id||`circle_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,i=e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0,n=e.clampToGround??!0,o=this.resolveMaterialColor(e.material);if(!(i>0)||!n||!o)return console.warn("[vmap-cesium-tool] Circle renderMode=primitive is not supported for the given options; falling back to Entity."),this.add({...e,renderMode:"entity"});const s=this.convertPosition(e.position),a=r.Cartographic.fromCartesian(s),l=new r.Cartographic(a.longitude,a.latitude,0),c=e.radius,h=Math.max(16,Math.floor(e.segments??this.getDefaultSegmentsForRadius(c))),u=Math.max(0,e.radius-i),m=this.generateCirclePositions(l,c,0,h),f=this.generateCirclePositions(l,u,0,h),p=e.outlineColor?this.resolveColor(e.outlineColor):r.Color.BLACK,g=new r.Entity({id:t}),y=new r.Entity({id:`${t}__fill`}),w=g,v=y;w._overlayType="circle-primitive",v._overlayType="circle-primitive";const x=[g,y],C=e.clickHighlight??!1,b=e.hoverHighlight??!1;return w._clickHighlight=C,v._clickHighlight=C,w._hoverHighlight=b,v._hoverHighlight=b,w._highlightEntities=x,v._highlightEntities=x,w._innerEntity=y,e.onClick&&(w._onClick=e.onClick,v._onClick=e.onClick),w._clampToGround=!0,w._baseHeight=0,w._centerCartographic=new r.Cartographic(a.longitude,a.latitude,0),w._isRing=!0,w._ringThickness=i,w._outerRadius=c,w._innerRadius=u,w._ringSegments=h,w._fillMaterial=o,w._primitiveRingBaseColor=p,w._primitiveFillBaseColor=o,v._primitiveRingBaseColor=p,v._primitiveFillBaseColor=o,this.getPrimitiveBatch().upsertGeometry({circleId:t,parts:{outer:g,inner:y},ringPositions:m,fillPositions:f,ringColor:p,fillColor:o,visible:!0}),g}convertPosition(e){if(e instanceof r.Cartesian3){if(Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.z))return e;throw new Error("Invalid position: Cartesian3 has NaN/Infinity components")}if(Array.isArray(e)&&(e.length===2||e.length===3)){const t=Number(e[0]),i=Number(e[1]),n=e.length===3?Number(e[2]):void 0;if(!Number.isFinite(t)||!Number.isFinite(i)||n!==void 0&&!Number.isFinite(n))throw new Error("Invalid position: lon/lat/height must be finite numbers");const o=e.length===3?r.Cartesian3.fromDegrees(t,i,n):r.Cartesian3.fromDegrees(t,i);if(!Number.isFinite(o.x)||!Number.isFinite(o.y)||!Number.isFinite(o.z))throw new Error("Invalid position: converted Cartesian3 has NaN/Infinity components");return o}throw new Error("Invalid position format")}resolveColor(e){if(e instanceof r.Color)return e;try{return r.Color.fromCssColorString(e)}catch{return r.Color.WHITE}}resolveMaterial(e){return e?typeof e=="string"?this.resolveColor(e):(e instanceof r.Color,e):r.Color.BLUE.withAlpha(.5)}add(e){const t=e.renderMode??"auto";if((t==="primitive"||t==="auto")&&this.canUsePrimitive(e))return this.addPrimitiveCircle(e);const i=this.convertPosition(e.position),n=e.id||`circle_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,o=this.resolveMaterial(e.material),s=e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0;if(s>0){const a=e.clampToGround??!0,l=r.Cartographic.fromCartesian(i),c=a?0:l?.height??0,h=a?r.HeightReference.CLAMP_TO_GROUND:e.heightReference??r.HeightReference.NONE,u=e.heightEpsilon??(a?0:.01),m=c+u,f=new r.Cartographic(l.longitude,l.latitude,0),p=r.Cartesian3.fromRadians(l.longitude,l.latitude,0),g=e.radius,y=Math.max(16,Math.floor(e.segments??this.getDefaultSegmentsForRadius(g))),w=Math.max(0,e.radius-s),v=this.generateCirclePositions(f,g,0,y),x=this.generateCirclePositions(f,w,0,y),C=this.entities.add({id:n,polygon:{hierarchy:new r.PolygonHierarchy(v,[new r.PolygonHierarchy(x)]),material:new r.ColorMaterialProperty(e.outlineColor?this.resolveColor(e.outlineColor):r.Color.BLACK),outline:!1,heightReference:h,...a?{}:{height:m}}}),b=this.entities.add({id:`${n}__fill`,position:p,polygon:{hierarchy:x,material:o instanceof r.Color?new r.ColorMaterialProperty(o):o,outline:!1,heightReference:h,...a?{}:{height:m},extrudedHeight:e.extrudedHeight}});if(e.onClick){const M=C,A=b;M._onClick=e.onClick,A._onClick=e.onClick}const P=C,N=b,T=[C,b],R=e.clickHighlight??!1,D=e.hoverHighlight??!1;return P._clickHighlight=R,N._clickHighlight=R,P._hoverHighlight=D,N._hoverHighlight=D,P._highlightEntities=T,N._highlightEntities=T,P._innerEntity=b,P._isRing=!0,P._ringThickness=s,P._fillMaterial=o,P._ringHeightEpsilon=u,P._centerCartographic=new r.Cartographic(l.longitude,l.latitude,c),P._outerRadius=g,P._innerRadius=w,P._ringSegments=y,P._clampToGround=a,P._baseHeight=c,C}else{const a=e.clampToGround??!0,l=e.heightReference??(a?r.HeightReference.CLAMP_TO_GROUND:r.HeightReference.NONE),c=r.Cartographic.fromCartesian(i),h=r.Cartesian3.fromRadians(c.longitude,c.latitude,0),u=a?0:c.height??0,m=this.entities.add({id:n,position:h,ellipse:{semiMajorAxis:e.radius,semiMinorAxis:e.radius,material:o,outline:e.outline??!0,outlineColor:e.outlineColor?this.resolveColor(e.outlineColor):r.Color.BLACK,outlineWidth:e.outlineWidth??1,heightReference:l,height:u,extrudedHeight:e.extrudedHeight}});if(e.onClick){const p=m;p._onClick=e.onClick}const f=m;return f._clickHighlight=e.clickHighlight??!1,f._hoverHighlight=e.hoverHighlight??!1,f._highlightEntities=[m],m._clampToGround=a,m._baseHeight=u,m}}generateCirclePositions(e,t,i,n=128){const s=e.latitude,a=e.longitude,l=t/6378137,c=[],h=Math.max(3,Math.floor(n)),u=this.getBearingTable(h),m=Math.sin(s),f=Math.cos(s),p=Math.sin(l),g=Math.cos(l);for(let y=0;y<h;y++){const w=u.sin[y],v=u.cos[y],x=Math.asin(m*g+f*p*v),C=a+Math.atan2(w*p*f,g-m*Math.sin(x));c.push(r.Cartesian3.fromRadians(C,x,i))}return c}getBearingTable(e){const t=Math.max(3,Math.floor(e)),i=z.bearingTableCache.get(t);if(i)return i;const n=new Float64Array(t),o=new Float64Array(t);for(let a=0;a<t;a++){const l=a/t*r.Math.TWO_PI;n[a]=Math.sin(l),o[a]=Math.cos(l)}const s={sin:n,cos:o};return z.bearingTableCache.set(t,s),s}getDefaultSegmentsForRadius(e){const t=Math.max(0,Number(e));return Number.isFinite(t)?t<=200?48:t<=1e3?64:t<=5e3?96:128:96}updatePosition(e,t){const i=this.convertPosition(t),n=e;if(n._overlayType==="circle-primitive"){const u=e,m=String(u.id),f=u._ringThickness??0,p=u._outerRadius??0,g=u._ringSegments??this.getDefaultSegmentsForRadius(p),y=Math.max(0,p-f),w=r.Cartographic.fromCartesian(i),v=new r.Cartographic(w.longitude,w.latitude,0);u._centerCartographic=new r.Cartographic(w.longitude,w.latitude,0);const x=this.generateCirclePositions(v,p,0,g),C=this.generateCirclePositions(v,y,0,g),b=u._innerEntity;if(!b)return;const P=u._primitiveRingBaseColor??r.Color.BLACK,N=u._primitiveFillBaseColor??this.resolveMaterialColor(u._fillMaterial)??r.Color.BLUE.withAlpha(.5);this.getPrimitiveBatch().upsertGeometry({circleId:m,parts:{outer:e,inner:b},ringPositions:x,fillPositions:C,ringColor:P,fillColor:N,visible:e.show!==!1});return}let o;try{o=r.Cartographic.fromCartesian(i)}catch{o=void 0}if(!o){e.position=new r.ConstantPositionProperty(i);const u=n._innerEntity;u&&(u.position=new r.ConstantPositionProperty(i));return}const s=n._clampToGround??!1,a=s?0:o.height??0,l=n._ringHeightEpsilon??0,c=a+l;n._baseHeight=a;const h=r.Cartesian3.fromRadians(o.longitude,o.latitude,0);if(n._isRing&&e.polygon){n._centerCartographic=new r.Cartographic(o.longitude,o.latitude,a);const u=n._outerRadius,m=n._innerRadius,f=n._ringSegments??256;if(u!==void 0&&m!==void 0){const g=new r.Cartographic(o.longitude,o.latitude,0),y=this.generateCirclePositions(g,u,0,f),w=this.generateCirclePositions(g,m,0,f);e.polygon.hierarchy=new r.ConstantProperty(new r.PolygonHierarchy(y,[new r.PolygonHierarchy(w)]));const v=n._innerEntity;v&&v.polygon&&(v.polygon.hierarchy=new r.ConstantProperty(new r.PolygonHierarchy(w)))}e.polygon.heightReference=new r.ConstantProperty(s?r.HeightReference.CLAMP_TO_GROUND:r.HeightReference.NONE),s?e.polygon.height=void 0:e.polygon.height=new r.ConstantProperty(c);const p=n._innerEntity;p&&(p.position=new r.ConstantPositionProperty(h),p.polygon&&(p.polygon.heightReference=new r.ConstantProperty(s?r.HeightReference.CLAMP_TO_GROUND:r.HeightReference.NONE),s?p.polygon.height=void 0:p.polygon.height=new r.ConstantProperty(c)));return}e.position=new r.ConstantPositionProperty(h),n._baseHeight=s?0:a,e.ellipse&&(e.ellipse.heightReference=new r.ConstantProperty(s?r.HeightReference.CLAMP_TO_GROUND:r.HeightReference.NONE),e.ellipse.height=new r.ConstantProperty(s?0:a))}updateRadius(e,t){const i=e,n=i._ringThickness;if(i._overlayType==="circle-primitive"){const o=e,s=String(o.id),a=o._innerEntity;if(!a)return;const l=o._ringThickness??0,c=o._centerCartographic?new r.Cartographic(o._centerCartographic.longitude,o._centerCartographic.latitude,0):void 0;if(!c)return;const h=o._ringSegments??this.getDefaultSegmentsForRadius(t);o._outerRadius=t,o._innerRadius=Math.max(0,t-l);const u=this.generateCirclePositions(c,o._outerRadius,0,h),m=this.generateCirclePositions(c,o._innerRadius,0,h),f=o._primitiveRingBaseColor,p=o._primitiveFillBaseColor;this.getPrimitiveBatch().upsertGeometry({circleId:s,parts:{outer:e,inner:a},ringPositions:u,fillPositions:m,ringColor:f??r.Color.BLACK,fillColor:p??this.resolveMaterialColor(o._fillMaterial)??r.Color.BLUE.withAlpha(.5),visible:e.show!==!1});return}if(i._isRing&&e.polygon&&n!==void 0){const o=i._centerCartographic;if(!o)return;const s=i._clampToGround??!1,a=i._baseHeight??0,l=i._ringHeightEpsilon??0,c=a+l,h=i._ringSegments??256;i._outerRadius=t,i._innerRadius=Math.max(0,t-n);const u=new r.Cartographic(o.longitude,o.latitude,0),m=this.generateCirclePositions(u,i._outerRadius,0,h),f=this.generateCirclePositions(u,i._innerRadius,0,h);e.polygon.hierarchy=new r.ConstantProperty(new r.PolygonHierarchy(m,[new r.PolygonHierarchy(f)])),e.polygon.heightReference=new r.ConstantProperty(s?r.HeightReference.CLAMP_TO_GROUND:r.HeightReference.NONE),s||(e.polygon.height=new r.ConstantProperty(c));const p=i._innerEntity;p&&p.polygon&&(p.polygon.hierarchy=new r.ConstantProperty(new r.PolygonHierarchy(f)),p.polygon.heightReference=new r.ConstantProperty(s?r.HeightReference.CLAMP_TO_GROUND:r.HeightReference.NONE),s||(p.polygon.height=new r.ConstantProperty(c)));return}e.ellipse&&(e.ellipse.semiMajorAxis=new r.ConstantProperty(t),e.ellipse.semiMinorAxis=new r.ConstantProperty(t))}updateStyle(e,t){const i=e;if(i._overlayType==="circle-primitive"){const n=e,o=String(n.id),s=n._innerEntity;if(!s)return;if(t.outlineColor!==void 0&&(n._primitiveRingBaseColor=this.resolveColor(t.outlineColor),s._primitiveRingBaseColor=n._primitiveRingBaseColor),t.material!==void 0){const a=this.resolveMaterialColor(t.material);a&&(n._primitiveFillBaseColor=a,s._primitiveFillBaseColor=a,n._fillMaterial=a)}if(t.outlineWidth!==void 0){const a=Math.max(0,t.outlineWidth);n._ringThickness=a}n._primitiveRingBaseColor&&n._primitiveFillBaseColor&&this.getPrimitiveBatch().setColors(o,n._primitiveRingBaseColor,n._primitiveFillBaseColor);return}if(i._isRing&&e.polygon){const n=i._innerEntity;if(t.outlineColor!==void 0&&(e.polygon.material=new r.ColorMaterialProperty(this.resolveColor(t.outlineColor))),t.material!==void 0&&n&&n.polygon){const o=this.resolveMaterial(t.material);n.polygon.material=o instanceof r.Color?new r.ColorMaterialProperty(o):o,i._fillMaterial=t.material}if(t.outlineWidth!==void 0){const o=Math.max(0,t.outlineWidth);i._ringThickness=o;const s=i._outerRadius;s!==void 0&&this.updateRadius(e,s)}return}if(e.ellipse){if(t.material!==void 0){const n=this.resolveMaterial(t.material);e.ellipse.material=n instanceof r.Color?new r.ColorMaterialProperty(n):n}t.outline!==void 0&&(e.ellipse.outline=new r.ConstantProperty(t.outline)),t.outlineColor!==void 0&&(e.ellipse.outlineColor=new r.ConstantProperty(this.resolveColor(t.outlineColor))),t.outlineWidth!==void 0&&(e.ellipse.outlineWidth=new r.ConstantProperty(t.outlineWidth))}}remove(e){const t=typeof e=="string"?this.entities.getById(e):e,i=typeof e!="string"?e:t,n=i;if(n&&n._overlayType==="circle-primitive"){const a=String(i.id);try{this.getPrimitiveBatch().remove(a)}catch{}const l=n._innerEntity;return l&&(l._onClick=void 0,n._innerEntity=void 0),n._onClick=void 0,!0}if(!t)return!1;const o=t,s=o._innerEntity;return s&&(s._onClick=void 0,this.entities.remove(s)),o._onClick=void 0,this.entities.remove(t)}setPrimitiveVisible(e,t){if(e._overlayType!=="circle-primitive")return;const n=String(e.id);this.getPrimitiveBatch().setVisible(n,t)}applyPrimitiveHighlight(e,t,i){if(e._overlayType!=="circle-primitive")return;const n=e._highlightEntities&&e._highlightEntities.length>0?e._highlightEntities[0]:e,o=String(n.id);n._primitiveRingBaseColor||(n._primitiveRingBaseColor=r.Color.BLACK),n._primitiveFillBaseColor||(n._primitiveFillBaseColor=this.resolveMaterialColor(n._fillMaterial)??r.Color.BLUE.withAlpha(.5));const s=t.withAlpha(1),a=t.withAlpha(i);this.getPrimitiveBatch().setColors(o,s,a),e._isHighlighted=!0}restorePrimitiveHighlight(e){if(e._overlayType!=="circle-primitive")return;const t=e._highlightEntities&&e._highlightEntities.length>0?e._highlightEntities[0]:e,i=String(t.id);t._primitiveRingBaseColor&&t._primitiveFillBaseColor&&this.getPrimitiveBatch().setColors(i,t._primitiveRingBaseColor,t._primitiveFillBaseColor),e._isHighlighted=!1}}class Ce{viewer;entities;constructor(e){this.viewer=e,this.entities=e.entities}convertPosition(e){if(e instanceof r.Cartesian3){if(Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.z))return e;throw new Error("Invalid position: Cartesian3 has NaN/Infinity components")}if(Array.isArray(e)&&(e.length===2||e.length===3)){const t=Number(e[0]),i=Number(e[1]),n=e.length===3?Number(e[2]):void 0;if(!Number.isFinite(t)||!Number.isFinite(i)||n!==void 0&&!Number.isFinite(n))throw new Error("Invalid position: lon/lat/height must be finite numbers");const o=e.length===3?r.Cartesian3.fromDegrees(t,i,n):r.Cartesian3.fromDegrees(t,i);if(!Number.isFinite(o.x)||!Number.isFinite(o.y)||!Number.isFinite(o.z))throw new Error("Invalid position: converted Cartesian3 has NaN/Infinity components");return o}throw new Error("Invalid position format")}resolveColor(e){if(e instanceof r.Color)return e;try{return r.Color.fromCssColorString(e)}catch{return r.Color.WHITE}}resolveLineMaterial(e){const t=e.lineStyle??"solid",i=e.lineColor?this.resolveColor(e.lineColor):r.Color.WHITE;if(t==="dashed"){const n=e.lineMaterialMode??"stripe",o=e.gapColor!==void 0?this.resolveColor(e.gapColor):r.Color.TRANSPARENT;if(n==="dash"){const a=e.dashLength??16,l={color:i,dashLength:a,gapColor:o};return e.dashPattern!==void 0&&(l.dashPattern=e.dashPattern),new r.PolylineDashMaterialProperty(l)}const s=e.stripeRepeat??32;return new r.StripeMaterialProperty({orientation:r.StripeOrientation.VERTICAL,evenColor:i,oddColor:o,repeat:s})}return new r.ColorMaterialProperty(i)}resolveGlowMaterial(e,t){const i=e?this.resolveColor(e):r.Color.CYAN,n=r.Math.clamp(t??.25,0,1);return new r.PolylineGlowMaterialProperty({color:i,glowPower:n})}getInnerWidth(e){return Math.max(1,Math.round(e-2))}addInnerEntity(e){return this.entities.add({id:`${e.outerId}__inner`,polyline:{positions:e.ringPositions,width:e.innerWidth,material:e.lineMaterial,clampToGround:e.clampToGround,zIndex:1}})}removeInnerEntity(e){const t=e;if(!t._innerEntity)return;const i=t._innerEntity;i._onClick=void 0,this.entities.remove(t._innerEntity),t._innerEntity=void 0}rebuildRingPositions(e,t,i){const n=t._centerCartographic,o=t._outerRadius;if(!n||o===void 0)return;const s=i?.segments??t._ringSegments??128,a=e.polyline?.clampToGround?.getValue?.(r.JulianDate.now?.())??e.polyline?.clampToGround,l=typeof a=="boolean"?a:!0,h=i?.clampToGround??l?0:n.height??0;return this.generateCirclePositions(n,o,h,s)}generateCirclePositions(e,t,i,n=128){const s=e.latitude,a=e.longitude,l=t/6378137,c=[];for(let h=0;h<n;h++){const u=h/n*r.Math.TWO_PI,m=Math.sin(s),f=Math.cos(s),p=Math.sin(l),g=Math.cos(l),y=Math.sin(u),w=Math.cos(u),v=Math.asin(m*g+f*p*w),x=a+Math.atan2(y*p*f,g-m*Math.sin(v));c.push(r.Cartesian3.fromRadians(x,v,i))}return c.length>0&&c.push(c[0]),c}add(e){const t=e.id||`ring_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,i=e.glowWidth??e.width??8,n=e.segments??128,o=e.clampToGround??!0,s=e.showInnerLine??!0,a=this.convertPosition(e.position),l=r.Cartographic.fromCartesian(a),c=o?0:l.height??0,h=this.generateCirclePositions(l,e.radius,c,n),u=this.resolveGlowMaterial(e.color,e.glowPower),m=this.resolveLineMaterial({lineColor:e.lineColor,lineStyle:e.lineStyle,lineMaterialMode:e.lineMaterialMode,stripeRepeat:e.stripeRepeat,dashLength:e.dashLength,dashPattern:e.dashPattern,gapColor:e.gapColor}),f=e.lineWidth??this.getInnerWidth(i),p=this.entities.add({id:t,polyline:{positions:h,width:i,material:u,clampToGround:o,zIndex:0}}),g=s?this.addInnerEntity({outerId:t,ringPositions:h,innerWidth:f,lineMaterial:m,clampToGround:o}):void 0,y=p;if(y._overlayType="ring",y._centerCartographic=l,y._outerRadius=e.radius,y._ringSegments=n,y._ringGlowPower=r.Math.clamp(e.glowPower??.25,0,1),y._ringLineColor=e.lineColor??r.Color.WHITE,y._ringLineStyle=e.lineStyle??"solid",y._ringLineMaterialMode=e.lineMaterialMode??"stripe",y._ringStripeRepeat=e.stripeRepeat,y._ringDashLength=e.dashLength,y._ringDashPattern=e.dashPattern,y._ringGapColor=e.gapColor,y._ringShowInnerLine=s,y._innerEntity=g,e.onClick&&(y._onClick=e.onClick,g)){const C=g;C._onClick=()=>e.onClick?.(p)}const w=e.clickHighlight??!1,v=e.hoverHighlight??!1,x=g?[p,g]:[p];if(y._clickHighlight=w,y._hoverHighlight=v,y._highlightEntities=x,g){const C=g;C._clickHighlight=w,C._hoverHighlight=v,C._highlightEntities=x}return p}updatePosition(e,t){if(!e.polyline)return;const i=e,n=i._ringSegments??128,o=i._outerRadius??0,s=this.convertPosition(t),a=r.Cartographic.fromCartesian(s),l=e.polyline.clampToGround?.getValue?.(r.JulianDate.now?.())??e.polyline.clampToGround,h=(typeof l=="boolean"?l:!0)?0:a.height??0,u=this.generateCirclePositions(a,o,h,n);e.polyline.positions=new r.ConstantProperty(u),i._innerEntity?.polyline&&(i._innerEntity.polyline.positions=new r.ConstantProperty(u)),i._centerCartographic=a}updateRadius(e,t){if(!e.polyline)return;const i=e,n=i._ringSegments??128,o=i._centerCartographic;if(!o)return;const s=e.polyline.clampToGround?.getValue?.(r.JulianDate.now?.())??e.polyline.clampToGround,l=(typeof s=="boolean"?s:!0)?0:o.height??0,c=this.generateCirclePositions(o,t,l,n);e.polyline.positions=new r.ConstantProperty(c),i._innerEntity?.polyline&&(i._innerEntity.polyline.positions=new r.ConstantProperty(c)),i._outerRadius=t}updateStyle(e,t){if(!e.polyline)return;const i=e;if(t.showInnerLine!==void 0){if(i._ringShowInnerLine=t.showInnerLine,!t.showInnerLine)this.removeInnerEntity(e);else if(!i._innerEntity){const u=this.rebuildRingPositions(e,i,{clampToGround:t.clampToGround,segments:t.segments});if(u){const m=t.clampToGround??e.polyline?.clampToGround?.getValue?.(r.JulianDate.now?.())??e.polyline?.clampToGround,f=typeof m=="boolean"?m:!0,p=e.polyline.width?.getValue?.(r.JulianDate.now?.())??e.polyline.width??t.glowWidth??t.width??8,g=typeof p=="number"?p:t.glowWidth??t.width??8,y=t.lineWidth??this.getInnerWidth(g),w=this.resolveLineMaterial({lineColor:t.lineColor??i._ringLineColor,lineStyle:t.lineStyle??i._ringLineStyle,lineMaterialMode:t.lineMaterialMode??i._ringLineMaterialMode,stripeRepeat:t.stripeRepeat??i._ringStripeRepeat,dashLength:t.dashLength??i._ringDashLength,dashPattern:t.dashPattern??i._ringDashPattern,gapColor:t.gapColor??i._ringGapColor}),v=this.addInnerEntity({outerId:String(e.id),ringPositions:u,innerWidth:y,lineMaterial:w,clampToGround:f});if(i._innerEntity=v,i._onClick){const x=v;x._onClick=()=>i._onClick?.(e)}}}}const n=t.glowWidth??t.width;if(n!==void 0){if(e.polyline.width=new r.ConstantProperty(n),i._innerEntity?.polyline){const u=t.lineWidth??this.getInnerWidth(n);i._innerEntity.polyline.width=new r.ConstantProperty(u)}}else t.lineWidth!==void 0&&i._innerEntity?.polyline&&(i._innerEntity.polyline.width=new r.ConstantProperty(t.lineWidth));if(t.color!==void 0||t.glowPower!==void 0){const u=t.glowPower??i._ringGlowPower??.25;e.polyline.material=this.resolveGlowMaterial(t.color??r.Color.CYAN,u),i._ringGlowPower=r.Math.clamp(u,0,1)}if((t.lineColor!==void 0||t.lineStyle!==void 0||t.lineMaterialMode!==void 0||t.stripeRepeat!==void 0||t.dashLength!==void 0||t.dashPattern!==void 0||t.gapColor!==void 0)&&i._innerEntity?.polyline){const u=t.lineColor??i._ringLineColor,m=t.lineStyle??i._ringLineStyle,f=t.lineMaterialMode??i._ringLineMaterialMode,p=t.stripeRepeat??i._ringStripeRepeat,g=t.dashLength??i._ringDashLength,y=t.dashPattern??i._ringDashPattern,w=t.gapColor??i._ringGapColor;i._innerEntity.polyline.material=this.resolveLineMaterial({lineColor:u,lineStyle:m,lineMaterialMode:f,stripeRepeat:p,dashLength:g,dashPattern:y,gapColor:w}),i._ringLineColor=u,i._ringLineStyle=m,i._ringLineMaterialMode=f,i._ringStripeRepeat=p,i._ringDashLength=g,i._ringDashPattern=y,i._ringGapColor=w}const s=i._centerCartographic,a=i._outerRadius,l=t.segments??i._ringSegments,c=t.segments!==void 0&&t.segments!==i._ringSegments,h=t.clampToGround!==void 0;if(t.clampToGround!==void 0&&(e.polyline.clampToGround=new r.ConstantProperty(t.clampToGround),i._innerEntity?.polyline&&(i._innerEntity.polyline.clampToGround=new r.ConstantProperty(t.clampToGround))),(c||h)&&s&&a!==void 0){const m=t.clampToGround??!0?0:s.height??0,f=this.generateCirclePositions(s,a,m,l??128);e.polyline.positions=new r.ConstantProperty(f),i._innerEntity?.polyline&&(i._innerEntity.polyline.positions=new r.ConstantProperty(f)),i._ringSegments=l??128}}setVisible(e,t){e.show=t;const i=e;i._innerEntity&&(i._innerEntity.show=t)}remove(e){const t=typeof e=="string"?this.entities.getById(e):e;if(!t)return!1;const i=t;if(i._onClick=void 0,i._innerEntity){const n=i._innerEntity;n._onClick=void 0,this.entities.remove(i._innerEntity),i._innerEntity=void 0}return this.entities.remove(t)}}class k{viewer;entities;overlayMap=new Map;infoWindowContainer=null;lastHoverTargets=null;hoverPickRAF=null;hoverPickPos=null;static DEFAULT_HIGHLIGHT_COLOR=r.Color.YELLOW;static DEFAULT_HIGHLIGHT_FILL_ALPHA=.35;marker;label;icon;svg;infoWindow;polyline;polygon;rectangle;circle;ring;constructor(e){this.viewer=e,this.entities=e.entities,this.enableTranslucentPicking(),this.initInfoWindowContainer(),this.setupEntityClickHandler(),this.setupEntityHoverHandler(),this.marker=new ge(e),this.label=new fe(e),this.icon=new me(e),this.svg=new pe(e),this.infoWindow=new ye(e,this.infoWindowContainer),this.polyline=new we(e),this.polygon=new ve(e),this.rectangle=new be(e),this.circle=new z(e),this.ring=new Ce(e)}enableTranslucentPicking(){try{const e=this.viewer.scene;e&&"pickTranslucentDepth"in e&&(e.pickTranslucentDepth=!0)}catch{}}pickCartographic(e){try{const t=this.viewer.scene;let i=null;if(t.pickPositionSupported)try{const n=t.pickPosition(e);n&&Number.isFinite(n.x)&&(i=n)}catch{}return i||(i=this.viewer.camera.pickEllipsoid(e,t.globe.ellipsoid)),i?r.Cartographic.fromCartesian(i):null}catch{return null}}findHoverableRectangleByCartographic(e){for(const t of this.overlayMap.values()){const i=t;if(i._drawType!==void 0||i.show===!1||!!!(i._hoverHighlight||i._highlightEntities&&i._highlightEntities.some(s=>s._hoverHighlight)))continue;let o=null;if(i.rectangle&&i.rectangle.coordinates!==void 0&&(o=this.getPropertyValue(i.rectangle.coordinates,null)),!o&&i._innerEntity&&i._innerEntity.rectangle&&i._innerEntity.rectangle.coordinates!==void 0&&(o=this.getPropertyValue(i._innerEntity.rectangle.coordinates,null)),o&&r.Rectangle.contains(o,e))return i}return null}isPointInPolygon2D(e,t){let i=!1;for(let n=0,o=t.length-1;n<t.length;o=n++){const s=t[n].x,a=t[n].y,l=t[o].x,c=t[o].y;a>e.y!=c>e.y&&e.x<(l-s)*(e.y-a)/(c-a+1e-12)+s&&(i=!i)}return i}resolvePolygonPositions(e){if(e.polygon&&e.polygon.hierarchy!==void 0){const t=this.getPropertyValue(e.polygon.hierarchy,null);if(t&&Array.isArray(t.positions))return t.positions}return null}findHoverablePolygonByCartographic(e){for(const t of this.overlayMap.values()){const i=t;if(i._drawType!==void 0||i.show===!1||!!!(i._hoverHighlight||i._highlightEntities&&i._highlightEntities.some(c=>c._hoverHighlight)))continue;const o=this.resolvePolygonPositions(i)||(i._innerEntity?this.resolvePolygonPositions(i._innerEntity):null);if(!o||o.length<3)continue;const s=r.EllipsoidTangentPlane.fromPoints(o,this.viewer.scene.globe.ellipsoid),a=s.projectPointOntoPlane(r.Cartesian3.fromRadians(e.longitude,e.latitude,0));if(!a)continue;const l=s.projectPointsOntoPlane(o);if(!(!l||l.length<3)&&this.isPointInPolygon2D(a,l))return i}return null}findHoverableCircleByCartographic(e){for(const t of this.overlayMap.values()){const i=t;if(!(i._drawType!==void 0||i.show===!1||!(i._hoverHighlight||i._highlightEntities&&i._highlightEntities.some(o=>o._hoverHighlight)))){if(i._isRing&&i._outerRadius&&i._centerCartographic){const o=i._centerCartographic;if(r.Cartesian3.distance(r.Cartesian3.fromRadians(o.longitude,o.latitude,0),r.Cartesian3.fromRadians(e.longitude,e.latitude,0))<=i._outerRadius)return i}if(i.ellipse&&i.position){const o=this.getNumberProperty(i.ellipse.semiMajorAxis,0),s=this.getNumberProperty(i.ellipse.semiMinorAxis,0),a=Math.max(0,Math.min(o,s));if(a>0){const l=this.getPropertyValue(i.position,null);if(l){const c=r.Cartographic.fromCartesian(l);if(r.Cartesian3.distance(r.Cartesian3.fromRadians(c.longitude,c.latitude,0),r.Cartesian3.fromRadians(e.longitude,e.latitude,0))<=a)return i}}}}}return null}initInfoWindowContainer(){const e=this.viewer.container;this.infoWindowContainer=document.createElement("div"),this.infoWindowContainer.id="cesium-info-window-container",this.infoWindowContainer.style.position="absolute",this.infoWindowContainer.style.left="0",this.infoWindowContainer.style.top="0",this.infoWindowContainer.style.width="100%",this.infoWindowContainer.style.height="100%",this.infoWindowContainer.style.pointerEvents="none",this.infoWindowContainer.style.zIndex="1000",e.appendChild(this.infoWindowContainer)}setupEntityClickHandler(){this.viewer.cesiumWidget.screenSpaceEventHandler.setInputAction(e=>{const t=this.viewer;if(t.__vmapDrawHelperIsDrawing)return;const i=Number(t.__vmapDrawHelperBlockPickUntil)||0;if(Date.now()<i)return;const n=e.position;if(!n||!Number.isFinite(n.x)||!Number.isFinite(n.y))return;const o=this.viewer.scene.pick(e.position);if(o&&r.defined(o.id)&&o.id instanceof r.Entity){const s=o.id;if(s.show===!1||s._drawType!==void 0)return;s._clickHighlight&&this.toggleOverlayHighlight(s);const a=s._onClick;a&&a(s)}},r.ScreenSpaceEventType.LEFT_CLICK)}setupEntityHoverHandler(){const e=this.viewer.scene?.canvas,t=()=>{this.lastHoverTargets&&this.lastHoverTargets.length>0&&this.setOverlayHighlightReason(this.lastHoverTargets,"hover",!1),this.lastHoverTargets=null};e&&e.addEventListener("mouseleave",()=>{t()}),this.viewer.cesiumWidget.screenSpaceEventHandler.setInputAction(i=>{const n=this.viewer;if(n.__vmapDrawHelperIsDrawing){t();return}const o=Number(n.__vmapDrawHelperBlockPickUntil)||0;if(Date.now()<o){t();return}const s=i.endPosition;if(!s||!Number.isFinite(s.x)||!Number.isFinite(s.y)){t();return}this.hoverPickPos=i.endPosition,this.hoverPickRAF===null&&(this.hoverPickRAF=window.requestAnimationFrame(()=>{this.hoverPickRAF=null;const a=this.hoverPickPos;if(!a){t();return}const l=this.viewer.scene.pick(a);let c=null;const h=f=>{let p=null;if(f instanceof r.Entity?p=f:f&&f.id instanceof r.Entity?p=f.id:f&&f.entity instanceof r.Entity&&(p=f.entity),!p)return null;const g=p;if(g._drawType!==void 0||g.show===!1)return null;if(g._hoverHighlight)return g;const y=g._highlightEntities;if(y&&y.length>0){const w=y.find(v=>!!v._hoverHighlight);if(w&&w.show!==!1&&w._drawType===void 0)return w}return null};if(l&&(r.defined(l.id)&&(c=h(l.id)),!c&&r.defined(l.primitive)&&(c=h(l.primitive))),!c)try{const f=this.viewer.scene.drillPick(a);if(Array.isArray(f))for(const p of f){const g=h(p?.id)||h(p?.primitive);if(g){c=g;break}}}catch{}if(!c){const f=this.pickCartographic(a);f&&(c=this.findHoverableRectangleByCartographic(f)||this.findHoverableCircleByCartographic(f)||this.findHoverablePolygonByCartographic(f))}if(!c){t();return}if(c.show===!1){t();return}const u=c._highlightEntities&&c._highlightEntities.length>0?c._highlightEntities:[c];this.lastHoverTargets&&this.lastHoverTargets.length===u.length&&this.lastHoverTargets.every((f,p)=>f===u[p])||(t(),this.lastHoverTargets=u,this.setOverlayHighlightReason(u,"hover",!0))}))},r.ScreenSpaceEventType.MOUSE_MOVE)}getPropertyValue(e,t){try{return e&&typeof e.getValue=="function"?e.getValue(r.JulianDate.now()):e!==void 0?e:t}catch{return t}}getNumberProperty(e,t){const i=this.getPropertyValue(e,t),n=typeof i=="number"?i:Number(i);return Number.isFinite(n)?n:t}resolveHighlightOptions(e){const t=typeof e=="object"&&e?e.fillAlpha:void 0,i=typeof t=="number"?r.Math.clamp(t,0,1):k.DEFAULT_HIGHLIGHT_FILL_ALPHA,n=typeof e=="object"&&e?e.color:void 0;return{color:(a=>{try{return a?a instanceof r.Color?a:r.Color.fromCssColorString(String(a)):k.DEFAULT_HIGHLIGHT_COLOR}catch{return k.DEFAULT_HIGHLIGHT_COLOR}})(n),fillAlpha:i}}getActiveHighlightOptions(e){const t=e._highlightState,i=t?.click?e._clickHighlight:t?.hover?e._hoverHighlight:void 0;return this.resolveHighlightOptions(i)}setOverlayHighlightReason(e,t,i){for(const n of e){const o=n;o._highlightState||(o._highlightState={}),o._highlightState[t]=i,!!(o._highlightState.click||o._highlightState.hover)?this.applyOverlayHighlightStyle(o):this.restoreOverlayHighlightStyle(o)}}applyOverlayHighlightStyle(e){if(e._highlightOriginalStyle||(e._highlightOriginalStyle={}),e._overlayType==="circle-primitive"){const{color:n,fillAlpha:o}=this.getActiveHighlightOptions(e);this.circle.applyPrimitiveHighlight(e,n,o);return}if(e._overlayType==="polygon-primitive"){const{color:n,fillAlpha:o}=this.getActiveHighlightOptions(e);this.polygon.applyPrimitiveHighlight(e,n,o);return}if(e._overlayType==="rectangle-primitive"){const{color:n,fillAlpha:o}=this.getActiveHighlightOptions(e);this.rectangle.applyPrimitiveHighlight(e,n,o);return}const{color:t,fillAlpha:i}=this.getActiveHighlightOptions(e);if(e.point){const n=e.point;e._highlightOriginalStyle.point||(e._highlightOriginalStyle.point={pixelSize:n.pixelSize,color:n.color,outlineColor:n.outlineColor,outlineWidth:n.outlineWidth});const o=this.getNumberProperty(n.pixelSize,10),s=this.getNumberProperty(n.outlineWidth,2);n.pixelSize=new r.ConstantProperty(o+3),n.color=new r.ConstantProperty(t.withAlpha(.9)),n.outlineColor=new r.ConstantProperty(t),n.outlineWidth=new r.ConstantProperty(Math.max(3,s+1))}if(e.label){const n=e.label;e._highlightOriginalStyle.label||(e._highlightOriginalStyle.label={fillColor:n.fillColor,outlineColor:n.outlineColor,outlineWidth:n.outlineWidth,scale:n.scale});const o=this.getNumberProperty(n.scale,1),s=this.getNumberProperty(n.outlineWidth,2);n.fillColor=new r.ConstantProperty(t),n.outlineColor=new r.ConstantProperty(r.Color.BLACK),n.outlineWidth=new r.ConstantProperty(Math.max(2,s)),n.scale=new r.ConstantProperty(o*1.08)}if(e.billboard){const n=e.billboard;e._highlightOriginalStyle.billboard||(e._highlightOriginalStyle.billboard={scale:n.scale,color:n.color});const o=this.getNumberProperty(n.scale,1);n.scale=new r.ConstantProperty(o*1.08),n.color=new r.ConstantProperty(t)}if(e.polyline){const n=e.polyline;e._highlightOriginalStyle.polyline||(e._highlightOriginalStyle.polyline={width:n.width,material:n.material});const o=this.getNumberProperty(n.width,2);if(n.width=new r.ConstantProperty(o+2),n.material instanceof r.ColorMaterialProperty)n.material=new r.ColorMaterialProperty(t);else if(n.material instanceof r.PolylineGlowMaterialProperty){const s=n.material.glowPower;n.material=new r.PolylineGlowMaterialProperty({color:t,glowPower:typeof s=="number"?s:.25})}}if(e.polygon){const n=e.polygon;e._highlightOriginalStyle.polygon||(e._highlightOriginalStyle.polygon={outline:n.outline,outlineColor:n.outlineColor,outlineWidth:n.outlineWidth,material:n.material});const o=this.getNumberProperty(n.outlineWidth,1);n.outline=new r.ConstantProperty(!0),n.outlineColor=new r.ConstantProperty(t),n.outlineWidth=new r.ConstantProperty(Math.max(2,o+2)),n.material=new r.ColorMaterialProperty(t.withAlpha(i))}if(e.rectangle){const n=e.rectangle;e._highlightOriginalStyle.rectangle||(e._highlightOriginalStyle.rectangle={outline:n.outline,outlineColor:n.outlineColor,outlineWidth:n.outlineWidth,material:n.material});const o=this.getNumberProperty(n.outlineWidth,1);n.outline=new r.ConstantProperty(!0),n.outlineColor=new r.ConstantProperty(t),n.outlineWidth=new r.ConstantProperty(Math.max(2,o+2)),n.material=new r.ColorMaterialProperty(t.withAlpha(i))}if(e.ellipse){const n=e.ellipse;e._highlightOriginalStyle.ellipse||(e._highlightOriginalStyle.ellipse={outline:n.outline,outlineColor:n.outlineColor,outlineWidth:n.outlineWidth,material:n.material});const o=this.getNumberProperty(n.outlineWidth,1);n.outline=new r.ConstantProperty(!0),n.outlineColor=new r.ConstantProperty(t),n.outlineWidth=new r.ConstantProperty(Math.max(2,o+2)),n.material=new r.ColorMaterialProperty(t.withAlpha(i))}e._isHighlighted=!0}restoreOverlayHighlightStyle(e){if(e._overlayType==="circle-primitive"){this.circle.restorePrimitiveHighlight(e);return}if(e._overlayType==="polygon-primitive"){this.polygon.restorePrimitiveHighlight(e);return}if(e._overlayType==="rectangle-primitive"){this.rectangle.restorePrimitiveHighlight(e);return}if(!e._isHighlighted)return;const t=e._highlightOriginalStyle;if(!t){e._isHighlighted=!1;return}if(e.point&&t.point){const i=e.point;i.pixelSize=t.point.pixelSize,i.color=t.point.color,i.outlineColor=t.point.outlineColor,i.outlineWidth=t.point.outlineWidth}if(e.label&&t.label){const i=e.label;i.fillColor=t.label.fillColor,i.outlineColor=t.label.outlineColor,i.outlineWidth=t.label.outlineWidth,i.scale=t.label.scale}if(e.billboard&&t.billboard){const i=e.billboard;i.scale=t.billboard.scale,i.color=t.billboard.color}if(e.polyline&&t.polyline){const i=e.polyline;i.width=t.polyline.width,i.material=t.polyline.material}if(e.polygon&&t.polygon){const i=e.polygon;i.outline=t.polygon.outline,i.outlineColor=t.polygon.outlineColor,i.outlineWidth=t.polygon.outlineWidth,i.material=t.polygon.material}if(e.rectangle&&t.rectangle){const i=e.rectangle;i.outline=t.rectangle.outline,i.outlineColor=t.rectangle.outlineColor,i.outlineWidth=t.rectangle.outlineWidth,i.material=t.rectangle.material}if(e.ellipse&&t.ellipse){const i=e.ellipse;i.outline=t.ellipse.outline,i.outlineColor=t.ellipse.outlineColor,i.outlineWidth=t.ellipse.outlineWidth,i.material=t.ellipse.material}e._isHighlighted=!1}generateId(e){return`${e}_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}toggleOverlayHighlight(e,t="click"){const i=e._highlightEntities&&e._highlightEntities.length>0?e._highlightEntities:[e],n=!i.some(o=>!!o._highlightState?.[t]);this.setOverlayHighlightReason(i,t,n)}setOverlayHighlight(e,t,i="click"){const n=typeof e=="string"?this.overlayMap.get(e):e;if(!n)return!1;const o=n._highlightEntities&&n._highlightEntities.length>0?n._highlightEntities:[n];return this.setOverlayHighlightReason(o,i,t),!0}addMarker(e){const t=e.id||this.generateId("marker"),i=this.marker.add({...e,id:t});return this.overlayMap.set(t,i),i}addLabel(e){const t=e.id||this.generateId("label"),i=this.label.add({...e,id:t});return this.overlayMap.set(t,i),i}addIcon(e){const t=e.id||this.generateId("icon"),i=this.icon.add({...e,id:t});return this.overlayMap.set(t,i),i}addSvg(e){const t=e.id||this.generateId("svg"),i=this.svg.add({...e,id:t});return this.overlayMap.set(t,i),i}addInfoWindow(e){const t=e.id||this.generateId("infowindow"),i=this.infoWindow.add({...e,id:t});return this.overlayMap.set(t,i),i}addPolyline(e){const t=e.id||this.generateId("polyline"),i=this.polyline.add({...e,id:t});return this.overlayMap.set(t,i),i}addPolygon(e){const t=e.id||this.generateId("polygon"),i=this.polygon.add({...e,id:t});return this.overlayMap.set(t,i),i}addRectangle(e){const t=e.id||this.generateId("rectangle"),i=this.rectangle.add({...e,id:t});return this.overlayMap.set(t,i),i}addCircle(e){const t=e.id||this.generateId("circle"),i=this.circle.add({...e,id:t});return this.overlayMap.set(t,i),i}addRing(e){const t=e.id||this.generateId("ring"),i=this.ring.add({...e,id:t});return this.overlayMap.set(t,i),i}getOverlay(e){return this.overlayMap.get(e)}removeOverlay(e){const t=this.overlayMap.get(e);if(t){const i=t;if(i._infoWindow&&this.infoWindow.remove(t),i._overlayType==="circle-primitive"){try{this.circle.remove(t)}catch{}return this.overlayMap.delete(e),!0}if(i._overlayType==="polygon-primitive"){try{this.polygon.remove(t)}catch{}return this.overlayMap.delete(e),!0}if(i._overlayType==="rectangle-primitive"){try{this.rectangle.remove(t)}catch{}return this.overlayMap.delete(e),!0}return i._innerEntity&&(this.entities.remove(i._innerEntity),i._innerEntity=void 0),i._borderEntity&&(this.entities.remove(i._borderEntity),i._borderEntity=void 0),this.entities.remove(t),this.overlayMap.delete(e),!0}return!1}removeAllOverlays(){Array.from(this.overlayMap.keys()).forEach(t=>this.removeOverlay(t))}updateOverlayPosition(e,t){const i=this.overlayMap.get(e);if(!i)return!1;const n=i;return n._overlayType==="circle-primitive"?(this.circle.updatePosition(i,t),!0):(i.point&&!n._infoWindow?this.marker.updatePosition(i,t):i.label?this.label.updatePosition(i,t):i.billboard?this.icon.updatePosition(i,t):i.polyline?n._overlayType==="ring"?this.ring.updatePosition(i,t):console.warn("Polyline position update requires multiple positions"):i.polygon?console.warn("Polygon position update requires multiple positions"):i.ellipse&&this.circle.updatePosition(i,t),n._infoWindow&&this.infoWindow.updatePosition(i,t),!0)}setOverlayVisible(e,t){const i=this.overlayMap.get(e);if(i){i.show=t;const n=i;return n._overlayType==="circle-primitive"?(this.circle.setPrimitiveVisible(i,t),n._innerEntity&&(n._innerEntity.show=t),!0):n._overlayType==="polygon-primitive"?(this.polygon.setPrimitiveVisible(i,t),n._borderEntity&&(n._borderEntity.show=t),!0):n._overlayType==="rectangle-primitive"?(this.rectangle.setPrimitiveVisible(i,t),n._innerEntity&&(n._innerEntity.show=t),!0):(n._innerEntity&&(n._innerEntity.show=t),n._borderEntity&&(n._borderEntity.show=t),n._infoWindow&&this.infoWindow.setVisible(i,t),!0)}return!1}getAllOverlayIds(){return Array.from(this.overlayMap.keys())}getAllOverlays(){return Array.from(this.overlayMap.values())}destroy(){this.removeAllOverlays(),this.infoWindowContainer&&this.infoWindowContainer.parentNode&&this.infoWindowContainer.parentNode.removeChild(this.infoWindowContainer),this.overlayMap.clear()}}class Ue{viewer;imageryLayer=null;rectangle=null;canvas;ctx;options;data=[];gradientLUT;autoUpdateEnabled=!1;autoUpdateOptions={enabled:!0,viewPaddingRatio:.15,cellSizeMeters:1e3,cellSizeMetersByHeight:e=>e>2e6?2e4:e>1e6?12e3:e>5e5?8e3:e>2e5?4e3:e>1e5?2e3:e>5e4?1e3:e>2e4?600:300};removeMoveEndListener=null;aggregateWorker=null;workerReady=!1;pendingUpdate=!1;lastUpdateKey="";constructor(e,t={}){this.viewer=e;const i=t.width??512,n=t.height??512,o=document.createElement("canvas");o.width=i,o.height=n;const s=o.getContext("2d");if(!s)throw new Error("Failed to get 2D context for heatmap canvas.");this.canvas=o,this.ctx=s,this.options={width:i,height:n,radius:t.radius??30,minValue:t.minValue??0,maxValue:t.maxValue??1,opacity:t.opacity??1,gradient:t.gradient??{0:"#0000ff",.4:"#00ffff",.7:"#ffff00",1:"#ff0000"}},this.gradientLUT=new Uint8ClampedArray(256*4),this.buildGradientLUT()}setData(e){if(this.data=e.slice(),this.data.length===0){this.clearLayer();return}let t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;for(const a of this.data)!Number.isFinite(a.lon)||!Number.isFinite(a.lat)||(a.lon<t&&(t=a.lon),a.lon>n&&(n=a.lon),a.lat<i&&(i=a.lat),a.lat>o&&(o=a.lat));if(!Number.isFinite(t)||!Number.isFinite(i)||!Number.isFinite(n)||!Number.isFinite(o)){this.clearLayer();return}const s=.001;t-=s,n+=s,i-=s,o+=s,this.rectangle=r.Rectangle.fromDegrees(t,i,n,o),this.autoUpdateEnabled?(this.ensureWorker(),this.pushDataToWorker(),this.requestAutoUpdate()):this.renderHeatmap(this.data,this.rectangle,{persistMinMax:!0})}setGradient(e){this.options.gradient=e,this.buildGradientLUT(),this.data.length>0&&(this.autoUpdateEnabled?this.requestAutoUpdate():this.rectangle&&this.renderHeatmap(this.data,this.rectangle,{persistMinMax:!0}))}setOpacity(e){this.options.opacity=Math.min(1,Math.max(0,e)),this.imageryLayer&&(this.imageryLayer.alpha=this.options.opacity)}setVisible(e){this.imageryLayer&&(this.imageryLayer.show=e)}destroy(){if(this.stopAutoUpdate(),this.aggregateWorker){try{this.aggregateWorker.terminate()}catch{}this.aggregateWorker=null,this.workerReady=!1}this.clearLayer()}setAutoUpdate(e={}){const t=e.enabled??!0;this.autoUpdateOptions={...this.autoUpdateOptions,...e,enabled:t,viewPaddingRatio:e.viewPaddingRatio??this.autoUpdateOptions.viewPaddingRatio,cellSizeMeters:e.cellSizeMeters??this.autoUpdateOptions.cellSizeMeters,cellSizeMetersByHeight:e.cellSizeMetersByHeight??this.autoUpdateOptions.cellSizeMetersByHeight},t?this.startAutoUpdateInternal():(this.stopAutoUpdate(),this.data.length>0&&this.rectangle&&this.renderHeatmap(this.data,this.rectangle,{persistMinMax:!0}))}stopAutoUpdate(){if(this.autoUpdateEnabled=!1,this.removeMoveEndListener){try{this.removeMoveEndListener()}catch{}this.removeMoveEndListener=null}this.pendingUpdate=!1,this.lastUpdateKey=""}clearLayer(){if(this.imageryLayer){try{this.viewer.imageryLayers.remove(this.imageryLayer,!0)}catch{}this.imageryLayer=null}}startAutoUpdateInternal(){if(this.autoUpdateEnabled)return;this.autoUpdateEnabled=!0,this.ensureWorker(),this.pushDataToWorker();const e=()=>{this.requestAutoUpdate()},t=this.viewer.camera.moveEnd?.addEventListener?.(e);this.removeMoveEndListener=typeof t=="function"?t:null,this.requestAutoUpdate()}requestAutoUpdate(){if(!this.autoUpdateEnabled)return;if(!this.workerReady){this.pendingUpdate=!0;return}const e=this.getPaddedViewRectangleDegrees(this.autoUpdateOptions.viewPaddingRatio);if(!e)return;const t=this.viewer.camera.positionCartographic?.height??0,i=this.autoUpdateOptions.cellSizeMetersByHeight?this.autoUpdateOptions.cellSizeMetersByHeight(t):this.autoUpdateOptions.cellSizeMeters,n=`${e.west.toFixed(4)},${e.south.toFixed(4)},${e.east.toFixed(4)},${e.north.toFixed(4)}|${Math.round(t)}|${Math.round(i)}`;n!==this.lastUpdateKey&&(this.lastUpdateKey=n,this.aggregateWorker?.postMessage({type:"aggregate",bbox:e,cellMeters:i}))}getPaddedViewRectangleDegrees(e){const t=this.viewer.camera.computeViewRectangle(this.viewer.scene.globe.ellipsoid);if(!t)return null;const i=r.Math.toDegrees(t.west),n=r.Math.toDegrees(t.east),o=r.Math.toDegrees(t.south),s=r.Math.toDegrees(t.north);if(i>n)return null;const a=(n-i)*e,l=(s-o)*e;return{west:i-a,east:n+a,south:o-l,north:s+l}}ensureWorker(){if(this.aggregateWorker)return;const e=`
|
|
200
|
+
`,s.addEventListener("click",a=>{a.stopPropagation(),this.hide(t),e.onClose?.(t)}),i.appendChild(s)}return i}bringToFront(e){const t=e[I];t&&(this.currentTopZIndex+=1,t.zIndex=this.currentTopZIndex,t.domElement.style.zIndex=String(t.zIndex))}add(e){const t=this.mergeOptions(e),i=t.id??`infowindow_${Date.now()}_${Math.random().toString(36).slice(2,10)}`,n=this.convertPosition(t.position),o=this.viewer.entities.add({id:i,show:t.show!==!1,position:new r.ConstantPositionProperty(n)}),s=this.createDomElement(t,o);this.container.appendChild(s);const a=t.updateInterval??this.defaultUpdateInterval??0;let l=0;const c=()=>{const m=typeof performance<"u"?performance.now():Date.now();if(this.isCameraMoving)l=m;else{if(a>0&&m-l<a)return;l=m}this.updateDomPosition(o)},h=this.viewer.scene.postRender.addEventListener(c),u={domElement:s,options:{...t},cameraListener:c,postRenderListener:h,zIndex:++this.currentTopZIndex,lastUpdate:l,arrowEl:s.querySelector(".cesium-info-window-arrow")};return s.style.zIndex=String(u.zIndex),o[I]=u,this.entityMap.set(i,u),this.updateDomPosition(o),o}updatePosition(e,t){const i=this.convertPosition(t);e.position&&r.defined(e.position)&&e.position.setValue(i),this.updateDomPosition(e)}updateContent(e,t){const i=e[I];if(!i)return;const n=i.domElement.querySelector(".cesium-info-window-content");n&&(n.innerHTML="",typeof t=="string"?n.innerHTML=t:n.appendChild(t))}setVisible(e,t){const i=e[I];i&&(e.show=t,t?this.updateDomPosition(e):i.domElement.style.display="none")}show(e){this.setVisible(e,!0)}hide(e){this.setVisible(e,!1)}remove(e){const t=e.id,i=this.entityMap.get(t);i&&(i.postRenderListener(),this.container.contains(i.domElement)&&this.container.removeChild(i.domElement),this.viewer.entities.remove(e),this.entityMap.delete(t),delete e[I])}destroy(){this.cameraMoveStartListener&&(this.cameraMoveStartListener(),this.cameraMoveStartListener=void 0),this.cameraMoveEndListener&&(this.cameraMoveEndListener(),this.cameraMoveEndListener=void 0);const e=this.viewer.entities.values.slice();for(const t of e)t[I]&&this.remove(t);this.entityMap.clear()}}class we{viewer;entities;constructor(e){this.viewer=e,this.entities=e.entities}convertPosition(e){if(e instanceof r.Cartesian3){if(Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.z))return e;throw new Error("Invalid position: Cartesian3 has NaN/Infinity components")}if(Array.isArray(e)&&(e.length===2||e.length===3)){const t=Number(e[0]),i=Number(e[1]),n=e.length===3?Number(e[2]):void 0;if(!Number.isFinite(t)||!Number.isFinite(i)||n!==void 0&&!Number.isFinite(n))throw new Error("Invalid position: lon/lat/height must be finite numbers");const o=e.length===3?r.Cartesian3.fromDegrees(t,i,n):r.Cartesian3.fromDegrees(t,i);if(!Number.isFinite(o.x)||!Number.isFinite(o.y)||!Number.isFinite(o.z))throw new Error("Invalid position: converted Cartesian3 has NaN/Infinity components");return o}throw new Error("Invalid position format")}resolveColor(e){if(e instanceof r.Color)return e;try{return r.Color.fromCssColorString(e)}catch{return r.Color.WHITE}}resolveMaterial(e){return e?typeof e=="string"?new r.ColorMaterialProperty(this.resolveColor(e)):e instanceof r.Color?new r.ColorMaterialProperty(e):e:new r.ColorMaterialProperty(r.Color.YELLOW)}add(e){const t=e.positions.map(a=>this.convertPosition(a)),i=e.id||`polyline_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,n=this.resolveMaterial(e.material),o=this.entities.add({id:i,polyline:{positions:t,width:e.width??2,material:n,clampToGround:e.clampToGround??!1}});if(e.onClick){const a=o;a._onClick=e.onClick}const s=o;return s._clickHighlight=e.clickHighlight??!1,s._hoverHighlight=e.hoverHighlight??!1,s._highlightEntities=[o],o}updatePositions(e,t){const i=t.map(n=>this.convertPosition(n));e.polyline&&(e.polyline.positions=new r.ConstantProperty(i))}updateStyle(e,t){e.polyline&&(t.width!==void 0&&(e.polyline.width=new r.ConstantProperty(t.width)),t.material!==void 0&&(e.polyline.material=this.resolveMaterial(t.material)))}remove(e){const t=typeof e=="string"?this.entities.getById(e):e;return t?(t._onClick=void 0,this.entities.remove(t)):!1}}class Se{viewer;collection;fillPrimitive=null;borderPrimitive=null;records=new Map;rebuildScheduled=!1;colorApplyScheduled=!1;pendingColorApplyIds=new Set;constructor(e){this.viewer=e,this.collection=new r.PrimitiveCollection,this.viewer.scene.primitives.add(this.collection)}destroy(){try{this.fillPrimitive&&this.collection.remove(this.fillPrimitive),this.borderPrimitive&&this.collection.remove(this.borderPrimitive)}catch{}this.fillPrimitive=null,this.borderPrimitive=null;try{this.viewer.scene.primitives.remove(this.collection)}catch{}this.records.clear()}upsertGeometry(e){this.records.set(e.polygonId,{polygonId:e.polygonId,parts:e.parts,fillPositions:e.fillPositions,borderPositions:e.borderPositions,borderWidth:Math.max(1,Number(e.borderWidth)||1),fillColor:e.fillColor,borderColor:e.borderColor,visible:e.visible}),this.scheduleRebuild()}remove(e){this.records.has(e)&&(this.records.delete(e),this.pendingColorApplyIds.delete(e),this.scheduleRebuild())}setVisible(e,t){const i=this.records.get(e);i&&(i.visible=t,this.applyCurrentColors(e))}setColors(e,t,i){const n=this.records.get(e);n&&(n.borderColor=t,n.fillColor=i,this.applyCurrentColors(e))}scheduleApplyColors(e){if(this.pendingColorApplyIds.add(e),this.colorApplyScheduled)return;this.colorApplyScheduled=!0;const t=globalThis.requestAnimationFrame,i=()=>{this.colorApplyScheduled=!1;const n=Array.from(this.pendingColorApplyIds);this.pendingColorApplyIds.clear();for(const o of n)this.applyCurrentColors(o)};if(typeof t=="function"){t(i);return}setTimeout(i,0)}setBorderWidth(e,t){const i=this.records.get(e);i&&(i.borderWidth=Math.max(1,Number(t)||1),this.scheduleRebuild())}scheduleRebuild(){if(this.rebuildScheduled)return;this.rebuildScheduled=!0;const e=globalThis.requestAnimationFrame;if(typeof e=="function"){e(()=>{this.rebuildScheduled=!1,this.rebuild()});return}setTimeout(()=>{this.rebuildScheduled=!1,this.rebuild()},0)}rebuild(){if(this.fillPrimitive){try{this.collection.remove(this.fillPrimitive)}catch{}this.fillPrimitive=null}if(this.borderPrimitive){try{this.collection.remove(this.borderPrimitive)}catch{}this.borderPrimitive=null}const e=[],t=[];for(const i of this.records.values()){const n=i.visible?i.fillColor.alpha:0,o=i.visible?i.borderColor.alpha:0,s=new r.Color(i.fillColor.red,i.fillColor.green,i.fillColor.blue,n),a=new r.Color(i.borderColor.red,i.borderColor.green,i.borderColor.blue,o),l=new r.PolygonGeometry({polygonHierarchy:new r.PolygonHierarchy(i.fillPositions),vertexFormat:r.PerInstanceColorAppearance.VERTEX_FORMAT});e.push(new r.GeometryInstance({geometry:l,id:i.parts.fill,attributes:{color:r.ColorGeometryInstanceAttribute.fromColor(s)}}));const c=new r.GroundPolylineGeometry({positions:i.borderPositions,width:i.borderWidth});t.push(new r.GeometryInstance({geometry:c,id:i.parts.border,attributes:{color:r.ColorGeometryInstanceAttribute.fromColor(a)}}))}e.length>0&&(this.fillPrimitive=new r.GroundPrimitive({geometryInstances:e,appearance:new r.PerInstanceColorAppearance({translucent:!0,flat:!0}),asynchronous:!0}),this.collection.add(this.fillPrimitive)),t.length>0&&(this.borderPrimitive=new r.GroundPolylinePrimitive({geometryInstances:t,appearance:new r.PolylineColorAppearance({translucent:!0})}),this.collection.add(this.borderPrimitive));for(const i of this.records.values())this.applyCurrentColors(i.polygonId);try{this.viewer.scene.requestRender?.()}catch{}}applyCurrentColors(e){const t=this.records.get(e);if(!t)return;const i=t.visible?t.fillColor.alpha:0,n=t.visible?t.borderColor.alpha:0,o=new r.Color(t.fillColor.red,t.fillColor.green,t.fillColor.blue,i),s=new r.Color(t.borderColor.red,t.borderColor.green,t.borderColor.blue,n);let a=!1;try{if(this.fillPrimitive)if(this.fillPrimitive.ready){const l=this.fillPrimitive.getGeometryInstanceAttributes(t.parts.fill);l&&l.color&&(l.color=r.ColorGeometryInstanceAttribute.toValue(o))}else a=!0}catch{}try{if(this.borderPrimitive)if(this.borderPrimitive.ready){const l=this.borderPrimitive.getGeometryInstanceAttributes(t.parts.border);l&&l.color&&(l.color=r.ColorGeometryInstanceAttribute.toValue(s))}else a=!0}catch{}a&&this.scheduleApplyColors(e);try{this.viewer.scene.requestRender?.()}catch{}}}class ve{viewer;entities;primitiveBatch=null;constructor(e){this.viewer=e,this.entities=e.entities}getPrimitiveBatch(){return this.primitiveBatch||(this.primitiveBatch=new Se(this.viewer)),this.primitiveBatch}resolveMaterialColor(e){return e?typeof e=="string"?this.resolveColor(e):e instanceof r.Color?e:null:r.Color.BLUE.withAlpha(.5)}canUsePrimitive(e){return!(!((e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0)>0)||!(e.clampToGround??!0)||e.extrudedHeight!==void 0||this.resolveMaterialColor(e.material??r.Color.ORANGE.withAlpha(.5))===null||e.outlineColor!==void 0&&this.resolveColor(e.outlineColor)===null)}addPrimitivePolygon(e){const t=e.positions.map(x=>this.convertPosition(x)),i=e.id||`polygon_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,n=e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0,o=e.clampToGround??!0;if(!(n>0)||!o||e.extrudedHeight!==void 0)return console.warn("[vmap-cesium-tool] Polygon renderMode=primitive is not supported for the given options; falling back to Entity."),this.add({...e,renderMode:"entity"});const s=this.resolveMaterialColor(e.material??r.Color.ORANGE.withAlpha(.5));if(!s)return console.warn("[vmap-cesium-tool] Polygon renderMode=primitive requires solid color material; falling back to Entity."),this.add({...e,renderMode:"entity"});const a=e.outlineColor?this.resolveColor(e.outlineColor):r.Color.ORANGE,l=Math.max(1,Number(n)||1),c=new r.Entity({id:i}),h=new r.Entity({id:`${i}__border`}),u=c,m=h;u._overlayType="polygon-primitive",m._overlayType="polygon-primitive",e.onClick&&(u._onClick=e.onClick,m._onClick=e.onClick);const f=[c,h],p=e.clickHighlight??!1,g=e.hoverHighlight??!1;u._clickHighlight=p,m._clickHighlight=p,u._hoverHighlight=g,m._hoverHighlight=g,u._highlightEntities=f,m._highlightEntities=f,u._borderEntity=h,u._isThickOutline=!0,u._outlineWidth=l,u._clampToGround=!0,u._baseHeight=0,u._primitiveFillBaseColor=s,u._primitiveBorderBaseColor=a,m._primitiveFillBaseColor=s,m._primitiveBorderBaseColor=a;const y=this.elevatePositions(t,0),w=y,v=w.slice();return v.length>=2&&v.push(w[0]),this.getPrimitiveBatch().upsertGeometry({polygonId:i,parts:{fill:c,border:h},fillPositions:y,borderPositions:v,borderWidth:l,fillColor:s,borderColor:a,visible:!0}),c}convertPosition(e){if(e instanceof r.Cartesian3){if(Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.z))return e;throw new Error("Invalid position: Cartesian3 has NaN/Infinity components")}if(Array.isArray(e)&&(e.length===2||e.length===3)){const t=Number(e[0]),i=Number(e[1]),n=e.length===3?Number(e[2]):void 0;if(!Number.isFinite(t)||!Number.isFinite(i)||n!==void 0&&!Number.isFinite(n))throw new Error("Invalid position: lon/lat/height must be finite numbers");const o=e.length===3?r.Cartesian3.fromDegrees(t,i,n):r.Cartesian3.fromDegrees(t,i);if(!Number.isFinite(o.x)||!Number.isFinite(o.y)||!Number.isFinite(o.z))throw new Error("Invalid position: converted Cartesian3 has NaN/Infinity components");return o}throw new Error("Invalid position format")}resolveColor(e){if(e instanceof r.Color)return e;try{return r.Color.fromCssColorString(e)}catch{return r.Color.WHITE}}resolveMaterial(e){return e?typeof e=="string"?new r.ColorMaterialProperty(this.resolveColor(e)):e instanceof r.Color?new r.ColorMaterialProperty(e):e:new r.ColorMaterialProperty(r.Color.BLUE.withAlpha(.5))}polygonArea2D(e){let t=0;for(let i=0,n=e.length;i<n;i++){const o=e[i],s=e[(i+1)%n];t+=o.x*s.y-s.x*o.y}return t*.5}offsetPolygon2DInward(e,t){const i=e.length;if(i<3)return e.slice();const o=this.polygonArea2D(e)>0,s=[];for(let c=0;c<i;c++){const h=e[c],u=e[(c+1)%i],m=u.x-h.x,f=u.y-h.y,p=Math.hypot(m,f)||1,g=m/p,y=f/p,w=o?-y:y,v=o?g:-g;s.push(new r.Cartesian2(-w,-v))}const a=[];for(let c=0;c<i;c++){const h=e[c],u=s[c];a.push(u.x*h.x+u.y*h.y+t)}const l=[];for(let c=0;c<i;c++){const h=(c-1+i)%i,u=s[h],m=a[h],f=s[c],p=a[c],g=u.x*f.y-f.x*u.y;if(Math.abs(g)<1e-8){const y=e[c];l.push(new r.Cartesian2(y.x+f.x*t,y.y+f.y*t))}else{const y=(m*f.y-p*u.y)/g,w=(u.x*p-f.x*m)/g;l.push(new r.Cartesian2(y,w))}}return l}computeInnerOffsetPositions(e,t,i){const n=r.EllipsoidTangentPlane.fromPoints(e),o=n.projectPointsOntoPlane(e),s=this.offsetPolygon2DInward(o,t);return n.projectPointsOntoEllipsoid(s).map(l=>{const c=r.Cartographic.fromCartesian(l);return r.Cartesian3.fromRadians(c.longitude,c.latitude,i)})}elevatePositions(e,t){return e.map(i=>{const n=r.Cartographic.fromCartesian(i);return r.Cartesian3.fromRadians(n.longitude,n.latitude,t)})}add(e){const t=e.renderMode??"auto";if((t==="primitive"||t==="auto")&&this.canUsePrimitive(e))return this.addPrimitivePolygon(e);const i=e.positions.map(m=>this.convertPosition(m)),n=e.id||`polygon_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,o=this.resolveMaterial(e.material),s=e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0;if(s&&s>0){const m=e.clampToGround??!0,f=m?0:r.Cartographic.fromCartesian(i[0])?.height??0,p=m?r.HeightReference.CLAMP_TO_GROUND:e.heightReference??r.HeightReference.NONE,g=this.elevatePositions(i,0),y=this.entities.add({id:n,polygon:{hierarchy:g,material:this.resolveMaterial(e.material??r.Color.ORANGE.withAlpha(.5)),outline:!1,heightReference:p,...m?{}:{height:f},extrudedHeight:e.extrudedHeight}}),w=this.elevatePositions(i,f),v=w.slice();v.length>=2&&v.push(w[0]);const x=this.entities.add({polyline:{positions:v,width:s,material:new r.ColorMaterialProperty(this.resolveColor(e.outlineColor??r.Color.ORANGE)),clampToGround:m,...m?{zIndex:1}:{}}});if(e.onClick){const R=y,D=x;R._onClick=e.onClick,D._onClick=e.onClick}const C=y,b=x,P=[y,x],N=e.clickHighlight??!1,T=e.hoverHighlight??!1;return C._clickHighlight=N,b._clickHighlight=N,C._hoverHighlight=T,b._hoverHighlight=T,C._highlightEntities=P,b._highlightEntities=P,C._borderEntity=x,C._isThickOutline=!0,C._outlineWidth=s,C._clampToGround=m,C._baseHeight=f,y}const a=e.clampToGround??!0,l=e.heightReference??(a?r.HeightReference.CLAMP_TO_GROUND:r.HeightReference.NONE),c=a?this.elevatePositions(i,0):i,h=this.entities.add({id:n,polygon:{hierarchy:c,material:o,outline:e.outline??!0,outlineColor:e.outlineColor?this.resolveColor(e.outlineColor):r.Color.BLACK,outlineWidth:e.outlineWidth??1,heightReference:l,extrudedHeight:e.extrudedHeight}});if(e.onClick){const m=h;m._onClick=e.onClick}const u=h;return u._clickHighlight=e.clickHighlight??!1,u._hoverHighlight=e.hoverHighlight??!1,u._highlightEntities=[h],h._clampToGround=a,h}updatePositions(e,t){const i=t.map(a=>this.convertPosition(a)),n=e;if(n._overlayType==="polygon-primitive"){const a=n._borderEntity;if(!a)return;const l=String(e.id),c=this.elevatePositions(i,0),h=c,u=h.slice();u.length>=2&&u.push(h[0]);const m=n._primitiveFillBaseColor??r.Color.ORANGE.withAlpha(.5),f=n._primitiveBorderBaseColor??r.Color.ORANGE,p=Math.max(1,Number(n._outlineWidth??2)||2);this.getPrimitiveBatch().upsertGeometry({polygonId:l,parts:{fill:e,border:a},fillPositions:c,borderPositions:u,borderWidth:p,fillColor:m,borderColor:f,visible:e.show!==!1});return}const o=n._borderEntity,s=n._isThickOutline;if(e.polygon&&o&&s){const a=n._clampToGround??!0,l=a?0:r.Cartographic.fromCartesian(i[0])?.height??0;n._baseHeight=l;const c=this.elevatePositions(i,0);e.polygon.hierarchy=new r.ConstantProperty(new r.PolygonHierarchy(c)),a||(e.polygon.height=new r.ConstantProperty(l));const h=this.elevatePositions(i,l),u=h.slice();u.length>=2&&u.push(h[0]),o.polyline&&(o.polyline.positions=new r.ConstantProperty(u),o.polyline.clampToGround=new r.ConstantProperty(a))}else if(e.polygon){const a=n._clampToGround??!1,l=a?this.elevatePositions(i,0):i;e.polygon.hierarchy=new r.ConstantProperty(new r.PolygonHierarchy(l)),a&&(e.polygon.heightReference=new r.ConstantProperty(r.HeightReference.CLAMP_TO_GROUND))}}updateStyle(e,t){const i=e;if(i._overlayType==="polygon-primitive"){const s=String(e.id);if(t.material!==void 0){const c=this.resolveMaterialColor(t.material);if(c){i._primitiveFillBaseColor=c;const h=i._borderEntity;h&&(h._primitiveFillBaseColor=c)}}if(t.outlineColor!==void 0){const c=this.resolveColor(t.outlineColor);i._primitiveBorderBaseColor=c;const h=i._borderEntity;h&&(h._primitiveBorderBaseColor=c)}if(t.outlineWidth!==void 0){const c=Math.max(1,Number(t.outlineWidth)||1);i._outlineWidth=c,this.getPrimitiveBatch().setBorderWidth(s,c)}const a=i._primitiveFillBaseColor??r.Color.ORANGE.withAlpha(.5),l=i._primitiveBorderBaseColor??r.Color.ORANGE;this.getPrimitiveBatch().setColors(s,l,a);return}const n=i._borderEntity;i._isThickOutline&&e.polygon&&n?(t.material!==void 0&&(e.polygon.material=this.resolveMaterial(t.material)),t.outlineColor!==void 0&&n.polyline&&(n.polyline.material=new r.ColorMaterialProperty(this.resolveColor(t.outlineColor))),t.outlineWidth!==void 0&&n.polyline&&(n.polyline.width=new r.ConstantProperty(Math.max(0,t.outlineWidth)),i._outlineWidth=t.outlineWidth)):e.polygon&&(t.material!==void 0&&(e.polygon.material=this.resolveMaterial(t.material)),t.outline!==void 0&&(e.polygon.outline=new r.ConstantProperty(t.outline)),t.outlineColor!==void 0&&(e.polygon.outlineColor=new r.ConstantProperty(this.resolveColor(t.outlineColor))),t.outlineWidth!==void 0&&(e.polygon.outlineWidth=new r.ConstantProperty(t.outlineWidth)))}remove(e){const t=typeof e=="string"?this.entities.getById(e):e,i=typeof e!="string"?e:t,n=i;if(n&&n._overlayType==="polygon-primitive"){const a=String(i.id);try{this.getPrimitiveBatch().remove(a)}catch{}const l=n._borderEntity;return l&&(l._onClick=void 0,n._borderEntity=void 0),n._onClick=void 0,!0}if(!t)return!1;const o=t,s=o._borderEntity;return s&&(s._onClick=void 0,this.entities.remove(s)),o._onClick=void 0,this.entities.remove(t)}setPrimitiveVisible(e,t){if(e._overlayType!=="polygon-primitive")return;const n=String(e.id);this.getPrimitiveBatch().setVisible(n,t)}applyPrimitiveHighlight(e,t,i){if(e._overlayType!=="polygon-primitive")return;const n=e._highlightEntities&&e._highlightEntities.length>0?e._highlightEntities[0]:e,o=String(n.id);n._primitiveBorderBaseColor||(n._primitiveBorderBaseColor=r.Color.ORANGE),n._primitiveFillBaseColor||(n._primitiveFillBaseColor=r.Color.ORANGE.withAlpha(.5));const s=t.withAlpha(1),a=t.withAlpha(i);this.getPrimitiveBatch().setColors(o,s,a),e._isHighlighted=!0}restorePrimitiveHighlight(e){if(e._overlayType!=="polygon-primitive")return;const t=e._highlightEntities&&e._highlightEntities.length>0?e._highlightEntities[0]:e,i=String(t.id);t._primitiveBorderBaseColor&&t._primitiveFillBaseColor&&this.getPrimitiveBatch().setColors(i,t._primitiveBorderBaseColor,t._primitiveFillBaseColor),e._isHighlighted=!1}}class Be{viewer;collection;ringPrimitive=null;fillPrimitive=null;records=new Map;rebuildScheduled=!1;colorApplyScheduled=!1;pendingColorApplyIds=new Set;constructor(e){this.viewer=e,this.collection=new r.PrimitiveCollection,this.viewer.scene.primitives.add(this.collection)}destroy(){try{this.ringPrimitive&&this.collection.remove(this.ringPrimitive),this.fillPrimitive&&this.collection.remove(this.fillPrimitive),this.ringPrimitive=null,this.fillPrimitive=null}catch{}try{this.viewer.scene.primitives.remove(this.collection)}catch{}this.records.clear()}upsertGeometry(e){this.records.set(e.rectangleId,{rectangleId:e.rectangleId,parts:e.parts,outerPositions:e.outerPositions,innerPositions:e.innerPositions,ringColor:e.ringColor,fillColor:e.fillColor,visible:e.visible}),this.scheduleRebuild()}remove(e){this.records.has(e)&&(this.records.delete(e),this.pendingColorApplyIds.delete(e),this.scheduleRebuild())}setVisible(e,t){const i=this.records.get(e);i&&(i.visible=t,this.applyCurrentColors(e))}setColors(e,t,i){const n=this.records.get(e);n&&(n.ringColor=t,n.fillColor=i,this.applyCurrentColors(e))}scheduleApplyColors(e){if(this.pendingColorApplyIds.add(e),this.colorApplyScheduled)return;this.colorApplyScheduled=!0;const t=globalThis.requestAnimationFrame,i=()=>{this.colorApplyScheduled=!1;const n=Array.from(this.pendingColorApplyIds);this.pendingColorApplyIds.clear();for(const o of n)this.applyCurrentColors(o)};if(typeof t=="function"){t(i);return}setTimeout(i,0)}scheduleRebuild(){if(this.rebuildScheduled)return;this.rebuildScheduled=!0;const e=globalThis.requestAnimationFrame;if(typeof e=="function"){e(()=>{this.rebuildScheduled=!1,this.rebuild()});return}setTimeout(()=>{this.rebuildScheduled=!1,this.rebuild()},0)}rebuild(){if(this.ringPrimitive){try{this.collection.remove(this.ringPrimitive)}catch{}this.ringPrimitive=null}if(this.fillPrimitive){try{this.collection.remove(this.fillPrimitive)}catch{}this.fillPrimitive=null}const e=[],t=[];for(const i of this.records.values()){const n=i.visible?i.ringColor.alpha:0,o=i.visible?i.fillColor.alpha:0,s=new r.Color(i.ringColor.red,i.ringColor.green,i.ringColor.blue,n),a=new r.Color(i.fillColor.red,i.fillColor.green,i.fillColor.blue,o),l=new r.PolygonGeometry({polygonHierarchy:new r.PolygonHierarchy(i.outerPositions,[new r.PolygonHierarchy(i.innerPositions)]),vertexFormat:r.PerInstanceColorAppearance.VERTEX_FORMAT});e.push(new r.GeometryInstance({geometry:l,id:i.parts.outer,attributes:{color:r.ColorGeometryInstanceAttribute.fromColor(s)}}));const c=new r.PolygonGeometry({polygonHierarchy:new r.PolygonHierarchy(i.innerPositions),vertexFormat:r.PerInstanceColorAppearance.VERTEX_FORMAT});t.push(new r.GeometryInstance({geometry:c,id:i.parts.inner,attributes:{color:r.ColorGeometryInstanceAttribute.fromColor(a)}}))}e.length>0&&(this.ringPrimitive=new r.GroundPrimitive({geometryInstances:e,appearance:new r.PerInstanceColorAppearance({translucent:!0,flat:!0}),asynchronous:!0}),this.collection.add(this.ringPrimitive)),t.length>0&&(this.fillPrimitive=new r.GroundPrimitive({geometryInstances:t,appearance:new r.PerInstanceColorAppearance({translucent:!0,flat:!0}),asynchronous:!0}),this.collection.add(this.fillPrimitive));for(const i of this.records.values())this.applyCurrentColors(i.rectangleId);try{this.viewer.scene.requestRender?.()}catch{}}applyCurrentColors(e){const t=this.records.get(e);if(!t)return;const i=t.visible?t.ringColor.alpha:0,n=t.visible?t.fillColor.alpha:0,o=new r.Color(t.ringColor.red,t.ringColor.green,t.ringColor.blue,i),s=new r.Color(t.fillColor.red,t.fillColor.green,t.fillColor.blue,n);let a=!1;try{if(this.ringPrimitive)if(this.ringPrimitive.ready){const l=this.ringPrimitive.getGeometryInstanceAttributes(t.parts.outer);l&&l.color&&(l.color=r.ColorGeometryInstanceAttribute.toValue(o))}else a=!0}catch{}try{if(this.fillPrimitive)if(this.fillPrimitive.ready){const l=this.fillPrimitive.getGeometryInstanceAttributes(t.parts.inner);l&&l.color&&(l.color=r.ColorGeometryInstanceAttribute.toValue(s))}else a=!0}catch{}a&&this.scheduleApplyColors(e);try{this.viewer.scene.requestRender?.()}catch{}}}class be{viewer;entities;primitiveBatch=null;constructor(e){this.viewer=e,this.entities=e.entities}getPrimitiveBatch(){return this.primitiveBatch||(this.primitiveBatch=new Be(this.viewer)),this.primitiveBatch}resolveMaterialColor(e){return e?typeof e=="string"?this.resolveColor(e):e instanceof r.Color?e:null:r.Color.BLUE.withAlpha(.5)}canUsePrimitive(e){return!(!((e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0)>0)||!(e.clampToGround??!0)||e.extrudedHeight!==void 0||this.resolveMaterialColor(e.material)===null||e.outlineColor!==void 0&&!(this.resolveColor(e.outlineColor)instanceof r.Color))}addPrimitiveRectangle(e){const t=e.id||`rectangle_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,i=e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0,n=e.clampToGround??!0;if(!(i>0)||!n||e.extrudedHeight!==void 0)return console.warn("[vmap-cesium-tool] Rectangle renderMode=primitive is not supported for the given options; falling back to Entity."),this.add({...e,renderMode:"entity"});const o=this.resolveMaterialColor(e.material);if(!o)return console.warn("[vmap-cesium-tool] Rectangle renderMode=primitive requires solid color material; falling back to Entity."),this.add({...e,renderMode:"entity"});const s=e.outlineColor?this.resolveColor(e.outlineColor):r.Color.BLACK,a=new r.Entity({id:t}),l=new r.Entity({id:`${t}__fill`}),c=a,h=l;c._overlayType="rectangle-primitive",h._overlayType="rectangle-primitive";const u=[a,l],m=e.clickHighlight??!1,f=e.hoverHighlight??!1;c._clickHighlight=m,h._clickHighlight=m,c._hoverHighlight=f,h._hoverHighlight=f,c._highlightEntities=u,h._highlightEntities=u,c._innerEntity=l,c._isRing=!0,c._ringThickness=i,c._outerRectangle=e.coordinates,c._clampToGround=!0,c._baseHeight=0,c._primitiveRingBaseColor=s,c._primitiveFillBaseColor=o,h._primitiveRingBaseColor=s,h._primitiveFillBaseColor=o,e.onClick&&(c._onClick=e.onClick,h._onClick=e.onClick);const p=this.rectangleToPositions(e.coordinates,0),g=this.shrinkRectangle(e.coordinates,i),y=this.rectangleToPositions(g,0);return this.getPrimitiveBatch().upsertGeometry({rectangleId:t,parts:{outer:a,inner:l},outerPositions:p,innerPositions:y,ringColor:s,fillColor:o,visible:!0}),a}resolveColor(e){if(e instanceof r.Color)return e;try{return r.Color.fromCssColorString(e)}catch{return r.Color.WHITE}}resolveMaterial(e){return e?typeof e=="string"?new r.ColorMaterialProperty(this.resolveColor(e)):e instanceof r.Color?new r.ColorMaterialProperty(e):e:new r.ColorMaterialProperty(r.Color.BLUE.withAlpha(.5))}rectangleToPositions(e,t){const i=e.west,n=e.south,o=e.east,s=e.north;return[r.Cartesian3.fromRadians(i,n,t),r.Cartesian3.fromRadians(o,n,t),r.Cartesian3.fromRadians(o,s,t),r.Cartesian3.fromRadians(i,s,t)]}shrinkRectangle(e,t){const n=(e.north+e.south)/2,o=t/6378137,s=t/(6378137*Math.cos(n)),a=(e.east-e.west)/2*.999,l=(e.north-e.south)/2*.999,c=Math.min(s,a),h=Math.min(o,l);return new r.Rectangle(e.west+c,e.south+h,e.east-c,e.north-h)}add(e){const t=e.id||`rectangle_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,i=this.resolveMaterial(e.material),n=e.renderMode??"auto";if(n==="primitive"||n==="auto"&&this.canUsePrimitive(e))return this.addPrimitiveRectangle({...e,id:t,renderMode:"primitive"});const o=e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0;if(o&&o>0){const h=e.clampToGround??!0,u=h?0:e.height??0,m=h?r.HeightReference.CLAMP_TO_GROUND:e.heightReference??r.HeightReference.NONE,f=e.heightEpsilon??(h?0:.1),p=u+f,g=this.rectangleToPositions(e.coordinates,0),y=this.shrinkRectangle(e.coordinates,o),w=this.rectangleToPositions(y,0),v=this.entities.add({id:t,polygon:{hierarchy:new r.PolygonHierarchy(g,[new r.PolygonHierarchy(w)]),material:new r.ColorMaterialProperty(e.outlineColor?this.resolveColor(e.outlineColor):r.Color.BLACK),outline:!1,heightReference:m,...h?{}:{height:p}}}),x=this.entities.add({id:`${t}__fill`,rectangle:{coordinates:y,material:i,outline:!1,heightReference:m,...h?{}:{height:p},extrudedHeight:e.extrudedHeight}});if(e.onClick){const R=v,D=x;R._onClick=e.onClick,D._onClick=e.onClick}const C=v,b=x,P=[v,x],N=e.clickHighlight??!1,T=e.hoverHighlight??!1;return C._clickHighlight=N,b._clickHighlight=N,C._hoverHighlight=T,b._hoverHighlight=T,C._highlightEntities=P,b._highlightEntities=P,C._innerEntity=x,C._isRing=!0,C._ringThickness=o,C._outerRectangle=e.coordinates,C._clampToGround=h,C._baseHeight=u,C._ringHeightEpsilon=f,v}const s=e.clampToGround??!0,a=e.heightReference??(s?r.HeightReference.CLAMP_TO_GROUND:r.HeightReference.NONE),l=this.entities.add({id:t,rectangle:{coordinates:e.coordinates,material:i,outline:e.outline??!0,outlineColor:e.outlineColor?this.resolveColor(e.outlineColor):r.Color.BLACK,outlineWidth:e.outlineWidth??1,heightReference:a,...!s&&e.height!==void 0?{height:e.height}:{},extrudedHeight:e.extrudedHeight}});if(e.onClick){const h=l;h._onClick=e.onClick}const c=l;return c._clickHighlight=e.clickHighlight??!1,c._hoverHighlight=e.hoverHighlight??!1,c._highlightEntities=[l],l._clampToGround=s,l}updateCoordinates(e,t){const i=e;if(i._overlayType==="rectangle-primitive"){const s=e,a=String(s.id),l=s._innerEntity;if(!l)return;const c=s._ringThickness??0,h=this.rectangleToPositions(t,0),u=this.shrinkRectangle(t,c),m=this.rectangleToPositions(u,0),f=s._primitiveRingBaseColor??r.Color.BLACK,p=s._primitiveFillBaseColor??r.Color.BLUE.withAlpha(.5);this.getPrimitiveBatch().upsertGeometry({rectangleId:a,parts:{outer:e,inner:l},outerPositions:h,innerPositions:m,ringColor:f,fillColor:p,visible:e.show!==!1}),s._outerRectangle=t;return}const n=i._innerEntity,o=i._ringThickness;if(e.polygon&&n&&o){const s=i._clampToGround??!0,a=s?0:i._baseHeight??0,l=i._ringHeightEpsilon??(s?0:.1),c=a+l,h=this.rectangleToPositions(t,0),u=this.shrinkRectangle(t,o),m=this.rectangleToPositions(u,0);e.polygon.hierarchy=new r.ConstantProperty(new r.PolygonHierarchy(h,[new r.PolygonHierarchy(m)])),n.rectangle.coordinates=new r.ConstantProperty(u),n.rectangle&&(s?n.rectangle.height=void 0:n.rectangle.height=new r.ConstantProperty(c)),!s&&e.polygon&&(e.polygon.height=new r.ConstantProperty(c)),i._outerRectangle=t}else e.rectangle&&(e.rectangle.coordinates=new r.ConstantProperty(t))}updateStyle(e,t){const i=e;if(i._overlayType==="rectangle-primitive"){const s=e,a=String(s.id),l=s._innerEntity;if(!l)return;if(t.outlineColor!==void 0&&(s._primitiveRingBaseColor=this.resolveColor(t.outlineColor),l._primitiveRingBaseColor=s._primitiveRingBaseColor),t.material!==void 0){const c=this.resolveMaterialColor(t.material);c&&(s._primitiveFillBaseColor=c,l._primitiveFillBaseColor=c)}if(t.outlineWidth!==void 0){s._ringThickness=Math.max(0,Number(t.outlineWidth)||0);const c=s._outerRectangle;c&&this.updateCoordinates(e,c)}s._primitiveRingBaseColor&&s._primitiveFillBaseColor&&this.getPrimitiveBatch().setColors(a,s._primitiveRingBaseColor,s._primitiveFillBaseColor);return}const n=i._innerEntity;if(i._isRing&&e.polygon&&n){if(t.outlineColor!==void 0&&(e.polygon.material=new r.ColorMaterialProperty(this.resolveColor(t.outlineColor))),t.material!==void 0&&(n.rectangle.material=this.resolveMaterial(t.material)),t.outlineWidth!==void 0){const s=Math.max(0,t.outlineWidth);i._ringThickness=s;const a=i._outerRectangle??void 0;if(a){const l=i._clampToGround??!0,c=l?0:i._baseHeight??0,h=i._ringHeightEpsilon??(l?0:.1),u=c+h,m=this.rectangleToPositions(a,0),f=this.shrinkRectangle(a,s),p=this.rectangleToPositions(f,0);e.polygon.hierarchy=new r.ConstantProperty(new r.PolygonHierarchy(m,[new r.PolygonHierarchy(p)])),n.rectangle.coordinates=new r.ConstantProperty(f),n.rectangle&&(l?n.rectangle.height=void 0:n.rectangle.height=new r.ConstantProperty(u)),!l&&e.polygon&&(e.polygon.height=new r.ConstantProperty(u))}}}else e.rectangle&&(t.material!==void 0&&(e.rectangle.material=this.resolveMaterial(t.material)),t.outline!==void 0&&(e.rectangle.outline=new r.ConstantProperty(t.outline)),t.outlineColor!==void 0&&(e.rectangle.outlineColor=new r.ConstantProperty(this.resolveColor(t.outlineColor))),t.outlineWidth!==void 0&&(e.rectangle.outlineWidth=new r.ConstantProperty(t.outlineWidth)))}remove(e){const t=typeof e=="string"?this.entities.getById(e):e,i=typeof e!="string"?e:t,n=i;if(n&&n._overlayType==="rectangle-primitive"){const a=String(i.id);try{this.getPrimitiveBatch().remove(a)}catch{}const l=n._innerEntity;return l&&(l._onClick=void 0,n._innerEntity=void 0),n._onClick=void 0,!0}if(!t)return!1;const o=t,s=o._innerEntity;return s&&(s._onClick=void 0,this.entities.remove(s)),o._onClick=void 0,this.entities.remove(t)}setPrimitiveVisible(e,t){if(e._overlayType!=="rectangle-primitive")return;const n=String(e.id);this.getPrimitiveBatch().setVisible(n,t)}applyPrimitiveHighlight(e,t,i){if(e._overlayType!=="rectangle-primitive")return;const n=e._highlightEntities&&e._highlightEntities.length>0?e._highlightEntities[0]:e,o=String(n.id);n._primitiveRingBaseColor||(n._primitiveRingBaseColor=r.Color.BLACK),n._primitiveFillBaseColor||(n._primitiveFillBaseColor=r.Color.BLUE.withAlpha(.5));const s=t.withAlpha(1),a=t.withAlpha(i);this.getPrimitiveBatch().setColors(o,s,a),e._isHighlighted=!0}restorePrimitiveHighlight(e){if(e._overlayType!=="rectangle-primitive")return;const t=e._highlightEntities&&e._highlightEntities.length>0?e._highlightEntities[0]:e,i=String(t.id);t._primitiveRingBaseColor&&t._primitiveFillBaseColor&&this.getPrimitiveBatch().setColors(i,t._primitiveRingBaseColor,t._primitiveFillBaseColor),e._isHighlighted=!1}}class Xe{viewer;collection;ringPrimitive=null;fillPrimitive=null;records=new Map;rebuildScheduled=!1;colorApplyScheduled=!1;pendingColorApplyIds=new Set;constructor(e){this.viewer=e,this.collection=new r.PrimitiveCollection,this.viewer.scene.primitives.add(this.collection)}destroy(){try{this.ringPrimitive&&this.collection.remove(this.ringPrimitive),this.fillPrimitive&&this.collection.remove(this.fillPrimitive),this.ringPrimitive=null,this.fillPrimitive=null}catch{}try{this.viewer.scene.primitives.remove(this.collection)}catch{}this.records.clear()}has(e){return this.records.has(e)}upsertGeometry(e){this.records.set(e.circleId,{circleId:e.circleId,parts:e.parts,ringPositions:e.ringPositions,fillPositions:e.fillPositions,ringColor:e.ringColor,fillColor:e.fillColor,visible:e.visible}),this.scheduleRebuild()}remove(e){this.records.has(e)&&(this.records.delete(e),this.pendingColorApplyIds.delete(e),this.scheduleRebuild())}setVisible(e,t){const i=this.records.get(e);i&&(i.visible=t,this.applyCurrentColors(e))}setColors(e,t,i){const n=this.records.get(e);n&&(n.ringColor=t,n.fillColor=i,this.applyCurrentColors(e))}scheduleApplyColors(e){if(this.pendingColorApplyIds.add(e),this.colorApplyScheduled)return;this.colorApplyScheduled=!0;const t=globalThis.requestAnimationFrame,i=()=>{this.colorApplyScheduled=!1;const n=Array.from(this.pendingColorApplyIds);this.pendingColorApplyIds.clear();for(const o of n)this.applyCurrentColors(o)};if(typeof t=="function"){t(i);return}setTimeout(i,0)}scheduleRebuild(){if(this.rebuildScheduled)return;this.rebuildScheduled=!0;const e=globalThis.requestAnimationFrame;if(typeof e=="function"){e(()=>{this.rebuildScheduled=!1,this.rebuild()});return}setTimeout(()=>{this.rebuildScheduled=!1,this.rebuild()},0)}rebuild(){if(this.ringPrimitive){try{this.collection.remove(this.ringPrimitive)}catch{}this.ringPrimitive=null}if(this.fillPrimitive){try{this.collection.remove(this.fillPrimitive)}catch{}this.fillPrimitive=null}const e=[],t=[];for(const i of this.records.values()){const n=i.visible?i.ringColor.alpha:0,o=i.visible?i.fillColor.alpha:0,s=new r.Color(i.ringColor.red,i.ringColor.green,i.ringColor.blue,n),a=new r.Color(i.fillColor.red,i.fillColor.green,i.fillColor.blue,o),l=new r.PolygonGeometry({polygonHierarchy:new r.PolygonHierarchy(i.ringPositions,[new r.PolygonHierarchy(i.fillPositions)]),vertexFormat:r.PerInstanceColorAppearance.VERTEX_FORMAT});e.push(new r.GeometryInstance({geometry:l,id:i.parts.outer,attributes:{color:r.ColorGeometryInstanceAttribute.fromColor(s)}}));const c=new r.PolygonGeometry({polygonHierarchy:new r.PolygonHierarchy(i.fillPositions),vertexFormat:r.PerInstanceColorAppearance.VERTEX_FORMAT});t.push(new r.GeometryInstance({geometry:c,id:i.parts.inner,attributes:{color:r.ColorGeometryInstanceAttribute.fromColor(a)}}))}e.length>0&&(this.ringPrimitive=new r.GroundPrimitive({geometryInstances:e,appearance:new r.PerInstanceColorAppearance({translucent:!0,flat:!0}),asynchronous:!0}),this.collection.add(this.ringPrimitive)),t.length>0&&(this.fillPrimitive=new r.GroundPrimitive({geometryInstances:t,appearance:new r.PerInstanceColorAppearance({translucent:!0,flat:!0}),asynchronous:!0}),this.collection.add(this.fillPrimitive));for(const i of this.records.values())this.applyCurrentColors(i.circleId);try{this.viewer.scene.requestRender?.()}catch{}}applyCurrentColors(e){const t=this.records.get(e);if(!t)return;const i=t.visible?t.ringColor.alpha:0,n=t.visible?t.fillColor.alpha:0,o=new r.Color(t.ringColor.red,t.ringColor.green,t.ringColor.blue,i),s=new r.Color(t.fillColor.red,t.fillColor.green,t.fillColor.blue,n);let a=!1;try{if(this.ringPrimitive)if(this.ringPrimitive.ready){const l=this.ringPrimitive.getGeometryInstanceAttributes(t.parts.outer);l&&l.color&&(l.color=r.ColorGeometryInstanceAttribute.toValue(o))}else a=!0}catch{}try{if(this.fillPrimitive)if(this.fillPrimitive.ready){const l=this.fillPrimitive.getGeometryInstanceAttributes(t.parts.inner);l&&l.color&&(l.color=r.ColorGeometryInstanceAttribute.toValue(s))}else a=!0}catch{}a&&this.scheduleApplyColors(e);try{this.viewer.scene.requestRender?.()}catch{}}}class z{viewer;entities;primitiveBatch=null;static bearingTableCache=new Map;constructor(e){this.viewer=e,this.entities=e.entities}getPrimitiveBatch(){return this.primitiveBatch||(this.primitiveBatch=new Xe(this.viewer)),this.primitiveBatch}resolveMaterialColor(e){return e?typeof e=="string"?this.resolveColor(e):e instanceof r.Color?e:null:r.Color.BLUE.withAlpha(.5)}canUsePrimitive(e){return!(!((e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0)>0)||!(e.clampToGround??!0)||e.extrudedHeight!==void 0||this.resolveMaterialColor(e.material)===null)}addPrimitiveCircle(e){const t=e.id||`circle_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,i=e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0,n=e.clampToGround??!0,o=this.resolveMaterialColor(e.material);if(!(i>0)||!n||!o)return console.warn("[vmap-cesium-tool] Circle renderMode=primitive is not supported for the given options; falling back to Entity."),this.add({...e,renderMode:"entity"});const s=this.convertPosition(e.position),a=r.Cartographic.fromCartesian(s),l=new r.Cartographic(a.longitude,a.latitude,0),c=e.radius,h=Math.max(16,Math.floor(e.segments??this.getDefaultSegmentsForRadius(c))),u=Math.max(0,e.radius-i),m=this.generateCirclePositions(l,c,0,h),f=this.generateCirclePositions(l,u,0,h),p=e.outlineColor?this.resolveColor(e.outlineColor):r.Color.BLACK,g=new r.Entity({id:t}),y=new r.Entity({id:`${t}__fill`}),w=g,v=y;w._overlayType="circle-primitive",v._overlayType="circle-primitive";const x=[g,y],C=e.clickHighlight??!1,b=e.hoverHighlight??!1;return w._clickHighlight=C,v._clickHighlight=C,w._hoverHighlight=b,v._hoverHighlight=b,w._highlightEntities=x,v._highlightEntities=x,w._innerEntity=y,e.onClick&&(w._onClick=e.onClick,v._onClick=e.onClick),w._clampToGround=!0,w._baseHeight=0,w._centerCartographic=new r.Cartographic(a.longitude,a.latitude,0),w._isRing=!0,w._ringThickness=i,w._outerRadius=c,w._innerRadius=u,w._ringSegments=h,w._fillMaterial=o,w._primitiveRingBaseColor=p,w._primitiveFillBaseColor=o,v._primitiveRingBaseColor=p,v._primitiveFillBaseColor=o,this.getPrimitiveBatch().upsertGeometry({circleId:t,parts:{outer:g,inner:y},ringPositions:m,fillPositions:f,ringColor:p,fillColor:o,visible:!0}),g}convertPosition(e){if(e instanceof r.Cartesian3){if(Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.z))return e;throw new Error("Invalid position: Cartesian3 has NaN/Infinity components")}if(Array.isArray(e)&&(e.length===2||e.length===3)){const t=Number(e[0]),i=Number(e[1]),n=e.length===3?Number(e[2]):void 0;if(!Number.isFinite(t)||!Number.isFinite(i)||n!==void 0&&!Number.isFinite(n))throw new Error("Invalid position: lon/lat/height must be finite numbers");const o=e.length===3?r.Cartesian3.fromDegrees(t,i,n):r.Cartesian3.fromDegrees(t,i);if(!Number.isFinite(o.x)||!Number.isFinite(o.y)||!Number.isFinite(o.z))throw new Error("Invalid position: converted Cartesian3 has NaN/Infinity components");return o}throw new Error("Invalid position format")}resolveColor(e){if(e instanceof r.Color)return e;try{return r.Color.fromCssColorString(e)}catch{return r.Color.WHITE}}resolveMaterial(e){return e?typeof e=="string"?this.resolveColor(e):(e instanceof r.Color,e):r.Color.BLUE.withAlpha(.5)}add(e){const t=e.renderMode??"auto";if((t==="primitive"||t==="auto")&&this.canUsePrimitive(e))return this.addPrimitiveCircle(e);const i=this.convertPosition(e.position),n=e.id||`circle_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,o=this.resolveMaterial(e.material),s=e.outlineWidth&&e.outlineWidth>1?e.outlineWidth:0;if(s>0){const a=e.clampToGround??!0,l=r.Cartographic.fromCartesian(i),c=a?0:l?.height??0,h=a?r.HeightReference.CLAMP_TO_GROUND:e.heightReference??r.HeightReference.NONE,u=e.heightEpsilon??(a?0:.01),m=c+u,f=new r.Cartographic(l.longitude,l.latitude,0),p=r.Cartesian3.fromRadians(l.longitude,l.latitude,0),g=e.radius,y=Math.max(16,Math.floor(e.segments??this.getDefaultSegmentsForRadius(g))),w=Math.max(0,e.radius-s),v=this.generateCirclePositions(f,g,0,y),x=this.generateCirclePositions(f,w,0,y),C=this.entities.add({id:n,polygon:{hierarchy:new r.PolygonHierarchy(v,[new r.PolygonHierarchy(x)]),material:new r.ColorMaterialProperty(e.outlineColor?this.resolveColor(e.outlineColor):r.Color.BLACK),outline:!1,heightReference:h,...a?{}:{height:m}}}),b=this.entities.add({id:`${n}__fill`,position:p,polygon:{hierarchy:x,material:o instanceof r.Color?new r.ColorMaterialProperty(o):o,outline:!1,heightReference:h,...a?{}:{height:m},extrudedHeight:e.extrudedHeight}});if(e.onClick){const M=C,A=b;M._onClick=e.onClick,A._onClick=e.onClick}const P=C,N=b,T=[C,b],R=e.clickHighlight??!1,D=e.hoverHighlight??!1;return P._clickHighlight=R,N._clickHighlight=R,P._hoverHighlight=D,N._hoverHighlight=D,P._highlightEntities=T,N._highlightEntities=T,P._innerEntity=b,P._isRing=!0,P._ringThickness=s,P._fillMaterial=o,P._ringHeightEpsilon=u,P._centerCartographic=new r.Cartographic(l.longitude,l.latitude,c),P._outerRadius=g,P._innerRadius=w,P._ringSegments=y,P._clampToGround=a,P._baseHeight=c,C}else{const a=e.clampToGround??!0,l=e.heightReference??(a?r.HeightReference.CLAMP_TO_GROUND:r.HeightReference.NONE),c=r.Cartographic.fromCartesian(i),h=r.Cartesian3.fromRadians(c.longitude,c.latitude,0),u=a?0:c.height??0,m=this.entities.add({id:n,position:h,ellipse:{semiMajorAxis:e.radius,semiMinorAxis:e.radius,material:o,outline:e.outline??!0,outlineColor:e.outlineColor?this.resolveColor(e.outlineColor):r.Color.BLACK,outlineWidth:e.outlineWidth??1,heightReference:l,height:u,extrudedHeight:e.extrudedHeight}});if(e.onClick){const p=m;p._onClick=e.onClick}const f=m;return f._clickHighlight=e.clickHighlight??!1,f._hoverHighlight=e.hoverHighlight??!1,f._highlightEntities=[m],m._clampToGround=a,m._baseHeight=u,m}}generateCirclePositions(e,t,i,n=128){const s=e.latitude,a=e.longitude,l=t/6378137,c=[],h=Math.max(3,Math.floor(n)),u=this.getBearingTable(h),m=Math.sin(s),f=Math.cos(s),p=Math.sin(l),g=Math.cos(l);for(let y=0;y<h;y++){const w=u.sin[y],v=u.cos[y],x=Math.asin(m*g+f*p*v),C=a+Math.atan2(w*p*f,g-m*Math.sin(x));c.push(r.Cartesian3.fromRadians(C,x,i))}return c}getBearingTable(e){const t=Math.max(3,Math.floor(e)),i=z.bearingTableCache.get(t);if(i)return i;const n=new Float64Array(t),o=new Float64Array(t);for(let a=0;a<t;a++){const l=a/t*r.Math.TWO_PI;n[a]=Math.sin(l),o[a]=Math.cos(l)}const s={sin:n,cos:o};return z.bearingTableCache.set(t,s),s}getDefaultSegmentsForRadius(e){const t=Math.max(0,Number(e));return Number.isFinite(t)?t<=200?48:t<=1e3?64:t<=5e3?96:128:96}updatePosition(e,t){const i=this.convertPosition(t),n=e;if(n._overlayType==="circle-primitive"){const u=e,m=String(u.id),f=u._ringThickness??0,p=u._outerRadius??0,g=u._ringSegments??this.getDefaultSegmentsForRadius(p),y=Math.max(0,p-f),w=r.Cartographic.fromCartesian(i),v=new r.Cartographic(w.longitude,w.latitude,0);u._centerCartographic=new r.Cartographic(w.longitude,w.latitude,0);const x=this.generateCirclePositions(v,p,0,g),C=this.generateCirclePositions(v,y,0,g),b=u._innerEntity;if(!b)return;const P=u._primitiveRingBaseColor??r.Color.BLACK,N=u._primitiveFillBaseColor??this.resolveMaterialColor(u._fillMaterial)??r.Color.BLUE.withAlpha(.5);this.getPrimitiveBatch().upsertGeometry({circleId:m,parts:{outer:e,inner:b},ringPositions:x,fillPositions:C,ringColor:P,fillColor:N,visible:e.show!==!1});return}let o;try{o=r.Cartographic.fromCartesian(i)}catch{o=void 0}if(!o){e.position=new r.ConstantPositionProperty(i);const u=n._innerEntity;u&&(u.position=new r.ConstantPositionProperty(i));return}const s=n._clampToGround??!1,a=s?0:o.height??0,l=n._ringHeightEpsilon??0,c=a+l;n._baseHeight=a;const h=r.Cartesian3.fromRadians(o.longitude,o.latitude,0);if(n._isRing&&e.polygon){n._centerCartographic=new r.Cartographic(o.longitude,o.latitude,a);const u=n._outerRadius,m=n._innerRadius,f=n._ringSegments??256;if(u!==void 0&&m!==void 0){const g=new r.Cartographic(o.longitude,o.latitude,0),y=this.generateCirclePositions(g,u,0,f),w=this.generateCirclePositions(g,m,0,f);e.polygon.hierarchy=new r.ConstantProperty(new r.PolygonHierarchy(y,[new r.PolygonHierarchy(w)]));const v=n._innerEntity;v&&v.polygon&&(v.polygon.hierarchy=new r.ConstantProperty(new r.PolygonHierarchy(w)))}e.polygon.heightReference=new r.ConstantProperty(s?r.HeightReference.CLAMP_TO_GROUND:r.HeightReference.NONE),s?e.polygon.height=void 0:e.polygon.height=new r.ConstantProperty(c);const p=n._innerEntity;p&&(p.position=new r.ConstantPositionProperty(h),p.polygon&&(p.polygon.heightReference=new r.ConstantProperty(s?r.HeightReference.CLAMP_TO_GROUND:r.HeightReference.NONE),s?p.polygon.height=void 0:p.polygon.height=new r.ConstantProperty(c)));return}e.position=new r.ConstantPositionProperty(h),n._baseHeight=s?0:a,e.ellipse&&(e.ellipse.heightReference=new r.ConstantProperty(s?r.HeightReference.CLAMP_TO_GROUND:r.HeightReference.NONE),e.ellipse.height=new r.ConstantProperty(s?0:a))}updateRadius(e,t){const i=e,n=i._ringThickness;if(i._overlayType==="circle-primitive"){const o=e,s=String(o.id),a=o._innerEntity;if(!a)return;const l=o._ringThickness??0,c=o._centerCartographic?new r.Cartographic(o._centerCartographic.longitude,o._centerCartographic.latitude,0):void 0;if(!c)return;const h=o._ringSegments??this.getDefaultSegmentsForRadius(t);o._outerRadius=t,o._innerRadius=Math.max(0,t-l);const u=this.generateCirclePositions(c,o._outerRadius,0,h),m=this.generateCirclePositions(c,o._innerRadius,0,h),f=o._primitiveRingBaseColor,p=o._primitiveFillBaseColor;this.getPrimitiveBatch().upsertGeometry({circleId:s,parts:{outer:e,inner:a},ringPositions:u,fillPositions:m,ringColor:f??r.Color.BLACK,fillColor:p??this.resolveMaterialColor(o._fillMaterial)??r.Color.BLUE.withAlpha(.5),visible:e.show!==!1});return}if(i._isRing&&e.polygon&&n!==void 0){const o=i._centerCartographic;if(!o)return;const s=i._clampToGround??!1,a=i._baseHeight??0,l=i._ringHeightEpsilon??0,c=a+l,h=i._ringSegments??256;i._outerRadius=t,i._innerRadius=Math.max(0,t-n);const u=new r.Cartographic(o.longitude,o.latitude,0),m=this.generateCirclePositions(u,i._outerRadius,0,h),f=this.generateCirclePositions(u,i._innerRadius,0,h);e.polygon.hierarchy=new r.ConstantProperty(new r.PolygonHierarchy(m,[new r.PolygonHierarchy(f)])),e.polygon.heightReference=new r.ConstantProperty(s?r.HeightReference.CLAMP_TO_GROUND:r.HeightReference.NONE),s||(e.polygon.height=new r.ConstantProperty(c));const p=i._innerEntity;p&&p.polygon&&(p.polygon.hierarchy=new r.ConstantProperty(new r.PolygonHierarchy(f)),p.polygon.heightReference=new r.ConstantProperty(s?r.HeightReference.CLAMP_TO_GROUND:r.HeightReference.NONE),s||(p.polygon.height=new r.ConstantProperty(c)));return}e.ellipse&&(e.ellipse.semiMajorAxis=new r.ConstantProperty(t),e.ellipse.semiMinorAxis=new r.ConstantProperty(t))}updateStyle(e,t){const i=e;if(i._overlayType==="circle-primitive"){const n=e,o=String(n.id),s=n._innerEntity;if(!s)return;if(t.outlineColor!==void 0&&(n._primitiveRingBaseColor=this.resolveColor(t.outlineColor),s._primitiveRingBaseColor=n._primitiveRingBaseColor),t.material!==void 0){const a=this.resolveMaterialColor(t.material);a&&(n._primitiveFillBaseColor=a,s._primitiveFillBaseColor=a,n._fillMaterial=a)}if(t.outlineWidth!==void 0){const a=Math.max(0,t.outlineWidth);n._ringThickness=a}n._primitiveRingBaseColor&&n._primitiveFillBaseColor&&this.getPrimitiveBatch().setColors(o,n._primitiveRingBaseColor,n._primitiveFillBaseColor);return}if(i._isRing&&e.polygon){const n=i._innerEntity;if(t.outlineColor!==void 0&&(e.polygon.material=new r.ColorMaterialProperty(this.resolveColor(t.outlineColor))),t.material!==void 0&&n&&n.polygon){const o=this.resolveMaterial(t.material);n.polygon.material=o instanceof r.Color?new r.ColorMaterialProperty(o):o,i._fillMaterial=t.material}if(t.outlineWidth!==void 0){const o=Math.max(0,t.outlineWidth);i._ringThickness=o;const s=i._outerRadius;s!==void 0&&this.updateRadius(e,s)}return}if(e.ellipse){if(t.material!==void 0){const n=this.resolveMaterial(t.material);e.ellipse.material=n instanceof r.Color?new r.ColorMaterialProperty(n):n}t.outline!==void 0&&(e.ellipse.outline=new r.ConstantProperty(t.outline)),t.outlineColor!==void 0&&(e.ellipse.outlineColor=new r.ConstantProperty(this.resolveColor(t.outlineColor))),t.outlineWidth!==void 0&&(e.ellipse.outlineWidth=new r.ConstantProperty(t.outlineWidth))}}remove(e){const t=typeof e=="string"?this.entities.getById(e):e,i=typeof e!="string"?e:t,n=i;if(n&&n._overlayType==="circle-primitive"){const a=String(i.id);try{this.getPrimitiveBatch().remove(a)}catch{}const l=n._innerEntity;return l&&(l._onClick=void 0,n._innerEntity=void 0),n._onClick=void 0,!0}if(!t)return!1;const o=t,s=o._innerEntity;return s&&(s._onClick=void 0,this.entities.remove(s)),o._onClick=void 0,this.entities.remove(t)}setPrimitiveVisible(e,t){if(e._overlayType!=="circle-primitive")return;const n=String(e.id);this.getPrimitiveBatch().setVisible(n,t)}applyPrimitiveHighlight(e,t,i){if(e._overlayType!=="circle-primitive")return;const n=e._highlightEntities&&e._highlightEntities.length>0?e._highlightEntities[0]:e,o=String(n.id);n._primitiveRingBaseColor||(n._primitiveRingBaseColor=r.Color.BLACK),n._primitiveFillBaseColor||(n._primitiveFillBaseColor=this.resolveMaterialColor(n._fillMaterial)??r.Color.BLUE.withAlpha(.5));const s=t.withAlpha(1),a=t.withAlpha(i);this.getPrimitiveBatch().setColors(o,s,a),e._isHighlighted=!0}restorePrimitiveHighlight(e){if(e._overlayType!=="circle-primitive")return;const t=e._highlightEntities&&e._highlightEntities.length>0?e._highlightEntities[0]:e,i=String(t.id);t._primitiveRingBaseColor&&t._primitiveFillBaseColor&&this.getPrimitiveBatch().setColors(i,t._primitiveRingBaseColor,t._primitiveFillBaseColor),e._isHighlighted=!1}}class Ce{viewer;entities;constructor(e){this.viewer=e,this.entities=e.entities}convertPosition(e){if(e instanceof r.Cartesian3){if(Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.z))return e;throw new Error("Invalid position: Cartesian3 has NaN/Infinity components")}if(Array.isArray(e)&&(e.length===2||e.length===3)){const t=Number(e[0]),i=Number(e[1]),n=e.length===3?Number(e[2]):void 0;if(!Number.isFinite(t)||!Number.isFinite(i)||n!==void 0&&!Number.isFinite(n))throw new Error("Invalid position: lon/lat/height must be finite numbers");const o=e.length===3?r.Cartesian3.fromDegrees(t,i,n):r.Cartesian3.fromDegrees(t,i);if(!Number.isFinite(o.x)||!Number.isFinite(o.y)||!Number.isFinite(o.z))throw new Error("Invalid position: converted Cartesian3 has NaN/Infinity components");return o}throw new Error("Invalid position format")}resolveColor(e){if(e instanceof r.Color)return e;try{return r.Color.fromCssColorString(e)}catch{return r.Color.WHITE}}resolveLineMaterial(e){const t=e.lineStyle??"solid",i=e.lineColor?this.resolveColor(e.lineColor):r.Color.WHITE;if(t==="dashed"){const n=e.lineMaterialMode??"stripe",o=e.gapColor!==void 0?this.resolveColor(e.gapColor):r.Color.TRANSPARENT;if(n==="dash"){const a=e.dashLength??16,l={color:i,dashLength:a,gapColor:o};return e.dashPattern!==void 0&&(l.dashPattern=e.dashPattern),new r.PolylineDashMaterialProperty(l)}const s=e.stripeRepeat??32;return new r.StripeMaterialProperty({orientation:r.StripeOrientation.VERTICAL,evenColor:i,oddColor:o,repeat:s})}return new r.ColorMaterialProperty(i)}resolveGlowMaterial(e,t){const i=e?this.resolveColor(e):r.Color.CYAN,n=r.Math.clamp(t??.25,0,1);return new r.PolylineGlowMaterialProperty({color:i,glowPower:n})}getInnerWidth(e){return Math.max(1,Math.round(e-2))}addInnerEntity(e){return this.entities.add({id:`${e.outerId}__inner`,polyline:{positions:e.ringPositions,width:e.innerWidth,material:e.lineMaterial,clampToGround:e.clampToGround,zIndex:1}})}removeInnerEntity(e){const t=e;if(!t._innerEntity)return;const i=t._innerEntity;i._onClick=void 0,this.entities.remove(t._innerEntity),t._innerEntity=void 0}rebuildRingPositions(e,t,i){const n=t._centerCartographic,o=t._outerRadius;if(!n||o===void 0)return;const s=i?.segments??t._ringSegments??128,a=e.polyline?.clampToGround?.getValue?.(r.JulianDate.now?.())??e.polyline?.clampToGround,l=typeof a=="boolean"?a:!0,h=i?.clampToGround??l?0:n.height??0;return this.generateCirclePositions(n,o,h,s)}generateCirclePositions(e,t,i,n=128){const s=e.latitude,a=e.longitude,l=t/6378137,c=[];for(let h=0;h<n;h++){const u=h/n*r.Math.TWO_PI,m=Math.sin(s),f=Math.cos(s),p=Math.sin(l),g=Math.cos(l),y=Math.sin(u),w=Math.cos(u),v=Math.asin(m*g+f*p*w),x=a+Math.atan2(y*p*f,g-m*Math.sin(v));c.push(r.Cartesian3.fromRadians(x,v,i))}return c.length>0&&c.push(c[0]),c}add(e){const t=e.id||`ring_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,i=e.glowWidth??e.width??8,n=e.segments??128,o=e.clampToGround??!0,s=e.showInnerLine??!0,a=this.convertPosition(e.position),l=r.Cartographic.fromCartesian(a),c=o?0:l.height??0,h=this.generateCirclePositions(l,e.radius,c,n),u=this.resolveGlowMaterial(e.color,e.glowPower),m=this.resolveLineMaterial({lineColor:e.lineColor,lineStyle:e.lineStyle,lineMaterialMode:e.lineMaterialMode,stripeRepeat:e.stripeRepeat,dashLength:e.dashLength,dashPattern:e.dashPattern,gapColor:e.gapColor}),f=e.lineWidth??this.getInnerWidth(i),p=this.entities.add({id:t,polyline:{positions:h,width:i,material:u,clampToGround:o,zIndex:0}}),g=s?this.addInnerEntity({outerId:t,ringPositions:h,innerWidth:f,lineMaterial:m,clampToGround:o}):void 0,y=p;if(y._overlayType="ring",y._centerCartographic=l,y._outerRadius=e.radius,y._ringSegments=n,y._ringGlowPower=r.Math.clamp(e.glowPower??.25,0,1),y._ringLineColor=e.lineColor??r.Color.WHITE,y._ringLineStyle=e.lineStyle??"solid",y._ringLineMaterialMode=e.lineMaterialMode??"stripe",y._ringStripeRepeat=e.stripeRepeat,y._ringDashLength=e.dashLength,y._ringDashPattern=e.dashPattern,y._ringGapColor=e.gapColor,y._ringShowInnerLine=s,y._innerEntity=g,e.onClick&&(y._onClick=e.onClick,g)){const C=g;C._onClick=()=>e.onClick?.(p)}const w=e.clickHighlight??!1,v=e.hoverHighlight??!1,x=g?[p,g]:[p];if(y._clickHighlight=w,y._hoverHighlight=v,y._highlightEntities=x,g){const C=g;C._clickHighlight=w,C._hoverHighlight=v,C._highlightEntities=x}return p}updatePosition(e,t){if(!e.polyline)return;const i=e,n=i._ringSegments??128,o=i._outerRadius??0,s=this.convertPosition(t),a=r.Cartographic.fromCartesian(s),l=e.polyline.clampToGround?.getValue?.(r.JulianDate.now?.())??e.polyline.clampToGround,h=(typeof l=="boolean"?l:!0)?0:a.height??0,u=this.generateCirclePositions(a,o,h,n);e.polyline.positions=new r.ConstantProperty(u),i._innerEntity?.polyline&&(i._innerEntity.polyline.positions=new r.ConstantProperty(u)),i._centerCartographic=a}updateRadius(e,t){if(!e.polyline)return;const i=e,n=i._ringSegments??128,o=i._centerCartographic;if(!o)return;const s=e.polyline.clampToGround?.getValue?.(r.JulianDate.now?.())??e.polyline.clampToGround,l=(typeof s=="boolean"?s:!0)?0:o.height??0,c=this.generateCirclePositions(o,t,l,n);e.polyline.positions=new r.ConstantProperty(c),i._innerEntity?.polyline&&(i._innerEntity.polyline.positions=new r.ConstantProperty(c)),i._outerRadius=t}updateStyle(e,t){if(!e.polyline)return;const i=e;if(t.showInnerLine!==void 0){if(i._ringShowInnerLine=t.showInnerLine,!t.showInnerLine)this.removeInnerEntity(e);else if(!i._innerEntity){const u=this.rebuildRingPositions(e,i,{clampToGround:t.clampToGround,segments:t.segments});if(u){const m=t.clampToGround??e.polyline?.clampToGround?.getValue?.(r.JulianDate.now?.())??e.polyline?.clampToGround,f=typeof m=="boolean"?m:!0,p=e.polyline.width?.getValue?.(r.JulianDate.now?.())??e.polyline.width??t.glowWidth??t.width??8,g=typeof p=="number"?p:t.glowWidth??t.width??8,y=t.lineWidth??this.getInnerWidth(g),w=this.resolveLineMaterial({lineColor:t.lineColor??i._ringLineColor,lineStyle:t.lineStyle??i._ringLineStyle,lineMaterialMode:t.lineMaterialMode??i._ringLineMaterialMode,stripeRepeat:t.stripeRepeat??i._ringStripeRepeat,dashLength:t.dashLength??i._ringDashLength,dashPattern:t.dashPattern??i._ringDashPattern,gapColor:t.gapColor??i._ringGapColor}),v=this.addInnerEntity({outerId:String(e.id),ringPositions:u,innerWidth:y,lineMaterial:w,clampToGround:f});if(i._innerEntity=v,i._onClick){const x=v;x._onClick=()=>i._onClick?.(e)}}}}const n=t.glowWidth??t.width;if(n!==void 0){if(e.polyline.width=new r.ConstantProperty(n),i._innerEntity?.polyline){const u=t.lineWidth??this.getInnerWidth(n);i._innerEntity.polyline.width=new r.ConstantProperty(u)}}else t.lineWidth!==void 0&&i._innerEntity?.polyline&&(i._innerEntity.polyline.width=new r.ConstantProperty(t.lineWidth));if(t.color!==void 0||t.glowPower!==void 0){const u=t.glowPower??i._ringGlowPower??.25;e.polyline.material=this.resolveGlowMaterial(t.color??r.Color.CYAN,u),i._ringGlowPower=r.Math.clamp(u,0,1)}if((t.lineColor!==void 0||t.lineStyle!==void 0||t.lineMaterialMode!==void 0||t.stripeRepeat!==void 0||t.dashLength!==void 0||t.dashPattern!==void 0||t.gapColor!==void 0)&&i._innerEntity?.polyline){const u=t.lineColor??i._ringLineColor,m=t.lineStyle??i._ringLineStyle,f=t.lineMaterialMode??i._ringLineMaterialMode,p=t.stripeRepeat??i._ringStripeRepeat,g=t.dashLength??i._ringDashLength,y=t.dashPattern??i._ringDashPattern,w=t.gapColor??i._ringGapColor;i._innerEntity.polyline.material=this.resolveLineMaterial({lineColor:u,lineStyle:m,lineMaterialMode:f,stripeRepeat:p,dashLength:g,dashPattern:y,gapColor:w}),i._ringLineColor=u,i._ringLineStyle=m,i._ringLineMaterialMode=f,i._ringStripeRepeat=p,i._ringDashLength=g,i._ringDashPattern=y,i._ringGapColor=w}const s=i._centerCartographic,a=i._outerRadius,l=t.segments??i._ringSegments,c=t.segments!==void 0&&t.segments!==i._ringSegments,h=t.clampToGround!==void 0;if(t.clampToGround!==void 0&&(e.polyline.clampToGround=new r.ConstantProperty(t.clampToGround),i._innerEntity?.polyline&&(i._innerEntity.polyline.clampToGround=new r.ConstantProperty(t.clampToGround))),(c||h)&&s&&a!==void 0){const m=t.clampToGround??!0?0:s.height??0,f=this.generateCirclePositions(s,a,m,l??128);e.polyline.positions=new r.ConstantProperty(f),i._innerEntity?.polyline&&(i._innerEntity.polyline.positions=new r.ConstantProperty(f)),i._ringSegments=l??128}}setVisible(e,t){e.show=t;const i=e;i._innerEntity&&(i._innerEntity.show=t)}remove(e){const t=typeof e=="string"?this.entities.getById(e):e;if(!t)return!1;const i=t;if(i._onClick=void 0,i._innerEntity){const n=i._innerEntity;n._onClick=void 0,this.entities.remove(i._innerEntity),i._innerEntity=void 0}return this.entities.remove(t)}}class k{viewer;entities;overlayMap=new Map;infoWindowContainer=null;lastHoverTargets=null;hoverPickRAF=null;hoverPickPos=null;static DEFAULT_HIGHLIGHT_COLOR=r.Color.YELLOW;static DEFAULT_HIGHLIGHT_FILL_ALPHA=.35;marker;label;icon;svg;infoWindow;polyline;polygon;rectangle;circle;ring;constructor(e){this.viewer=e,this.entities=e.entities,this.initInfoWindowContainer(),this.setupEntityClickHandler(),this.setupEntityHoverHandler(),this.marker=new ge(e),this.label=new fe(e),this.icon=new me(e),this.svg=new pe(e),this.infoWindow=new ye(e,this.infoWindowContainer),this.polyline=new we(e),this.polygon=new ve(e),this.rectangle=new be(e),this.circle=new z(e),this.ring=new Ce(e)}enableTranslucentPicking(){try{const e=this.viewer.scene;e&&"pickTranslucentDepth"in e&&(e.pickTranslucentDepth=!0)}catch{}}pickCartographic(e){try{const t=this.viewer.scene;let i=null;if(t.pickPositionSupported)try{const n=t.pickPosition(e);n&&Number.isFinite(n.x)&&(i=n)}catch{}return i||(i=this.viewer.camera.pickEllipsoid(e,t.globe.ellipsoid)),i?r.Cartographic.fromCartesian(i):null}catch{return null}}findHoverableRectangleByCartographic(e){for(const t of this.overlayMap.values()){const i=t;if(i._drawType!==void 0||i.show===!1||!!!(i._hoverHighlight||i._highlightEntities&&i._highlightEntities.some(s=>s._hoverHighlight)))continue;let o=null;if(i.rectangle&&i.rectangle.coordinates!==void 0&&(o=this.getPropertyValue(i.rectangle.coordinates,null)),!o&&i._innerEntity&&i._innerEntity.rectangle&&i._innerEntity.rectangle.coordinates!==void 0&&(o=this.getPropertyValue(i._innerEntity.rectangle.coordinates,null)),o&&r.Rectangle.contains(o,e))return i}return null}isPointInPolygon2D(e,t){let i=!1;for(let n=0,o=t.length-1;n<t.length;o=n++){const s=t[n].x,a=t[n].y,l=t[o].x,c=t[o].y;a>e.y!=c>e.y&&e.x<(l-s)*(e.y-a)/(c-a+1e-12)+s&&(i=!i)}return i}resolvePolygonPositions(e){if(e.polygon&&e.polygon.hierarchy!==void 0){const t=this.getPropertyValue(e.polygon.hierarchy,null);if(t&&Array.isArray(t.positions))return t.positions}return null}findHoverablePolygonByCartographic(e){for(const t of this.overlayMap.values()){const i=t;if(i._drawType!==void 0||i.show===!1||!!!(i._hoverHighlight||i._highlightEntities&&i._highlightEntities.some(c=>c._hoverHighlight)))continue;const o=this.resolvePolygonPositions(i)||(i._innerEntity?this.resolvePolygonPositions(i._innerEntity):null);if(!o||o.length<3)continue;const s=r.EllipsoidTangentPlane.fromPoints(o,this.viewer.scene.globe.ellipsoid),a=s.projectPointOntoPlane(r.Cartesian3.fromRadians(e.longitude,e.latitude,0));if(!a)continue;const l=s.projectPointsOntoPlane(o);if(!(!l||l.length<3)&&this.isPointInPolygon2D(a,l))return i}return null}findHoverableCircleByCartographic(e){for(const t of this.overlayMap.values()){const i=t;if(!(i._drawType!==void 0||i.show===!1||!(i._hoverHighlight||i._highlightEntities&&i._highlightEntities.some(o=>o._hoverHighlight)))){if(i._isRing&&i._outerRadius&&i._centerCartographic){const o=i._centerCartographic;if(r.Cartesian3.distance(r.Cartesian3.fromRadians(o.longitude,o.latitude,0),r.Cartesian3.fromRadians(e.longitude,e.latitude,0))<=i._outerRadius)return i}if(i.ellipse&&i.position){const o=this.getNumberProperty(i.ellipse.semiMajorAxis,0),s=this.getNumberProperty(i.ellipse.semiMinorAxis,0),a=Math.max(0,Math.min(o,s));if(a>0){const l=this.getPropertyValue(i.position,null);if(l){const c=r.Cartographic.fromCartesian(l);if(r.Cartesian3.distance(r.Cartesian3.fromRadians(c.longitude,c.latitude,0),r.Cartesian3.fromRadians(e.longitude,e.latitude,0))<=a)return i}}}}}return null}initInfoWindowContainer(){const e=this.viewer.container;this.infoWindowContainer=document.createElement("div"),this.infoWindowContainer.id="cesium-info-window-container",this.infoWindowContainer.style.position="absolute",this.infoWindowContainer.style.left="0",this.infoWindowContainer.style.top="0",this.infoWindowContainer.style.width="100%",this.infoWindowContainer.style.height="100%",this.infoWindowContainer.style.pointerEvents="none",this.infoWindowContainer.style.zIndex="1000",e.appendChild(this.infoWindowContainer)}setupEntityClickHandler(){this.viewer.cesiumWidget.screenSpaceEventHandler.setInputAction(e=>{const t=this.viewer;if(t.__vmapDrawHelperIsDrawing)return;const i=Number(t.__vmapDrawHelperBlockPickUntil)||0;if(Date.now()<i)return;const n=e.position;if(!n||!Number.isFinite(n.x)||!Number.isFinite(n.y))return;const o=this.viewer.scene.pick(e.position);if(o&&r.defined(o.id)&&o.id instanceof r.Entity){const s=o.id;if(s.show===!1||s._drawType!==void 0)return;s._clickHighlight&&this.toggleOverlayHighlight(s);const a=s._onClick;a&&a(s)}},r.ScreenSpaceEventType.LEFT_CLICK)}setupEntityHoverHandler(){const e=this.viewer.scene?.canvas,t=()=>{this.lastHoverTargets&&this.lastHoverTargets.length>0&&this.setOverlayHighlightReason(this.lastHoverTargets,"hover",!1),this.lastHoverTargets=null};e&&e.addEventListener("mouseleave",()=>{t()}),this.viewer.cesiumWidget.screenSpaceEventHandler.setInputAction(i=>{const n=this.viewer;if(n.__vmapDrawHelperIsDrawing){t();return}const o=Number(n.__vmapDrawHelperBlockPickUntil)||0;if(Date.now()<o){t();return}const s=i.endPosition;if(!s||!Number.isFinite(s.x)||!Number.isFinite(s.y)){t();return}this.hoverPickPos=i.endPosition,this.hoverPickRAF===null&&(this.hoverPickRAF=window.requestAnimationFrame(()=>{this.hoverPickRAF=null;const a=this.hoverPickPos;if(!a){t();return}const l=this.viewer.scene.pick(a);let c=null;const h=f=>{let p=null;if(f instanceof r.Entity?p=f:f&&f.id instanceof r.Entity?p=f.id:f&&f.entity instanceof r.Entity&&(p=f.entity),!p)return null;const g=p;if(g._drawType!==void 0||g.show===!1)return null;if(g._hoverHighlight)return g;const y=g._highlightEntities;if(y&&y.length>0){const w=y.find(v=>!!v._hoverHighlight);if(w&&w.show!==!1&&w._drawType===void 0)return w}return null};if(l&&(r.defined(l.id)&&(c=h(l.id)),!c&&r.defined(l.primitive)&&(c=h(l.primitive))),!c)try{const f=this.viewer.scene.drillPick(a);if(Array.isArray(f))for(const p of f){const g=h(p?.id)||h(p?.primitive);if(g){c=g;break}}}catch{}if(!c){const f=this.pickCartographic(a);f&&(c=this.findHoverableRectangleByCartographic(f)||this.findHoverableCircleByCartographic(f)||this.findHoverablePolygonByCartographic(f))}if(!c){t();return}if(c.show===!1){t();return}const u=c._highlightEntities&&c._highlightEntities.length>0?c._highlightEntities:[c];this.lastHoverTargets&&this.lastHoverTargets.length===u.length&&this.lastHoverTargets.every((f,p)=>f===u[p])||(t(),this.lastHoverTargets=u,this.setOverlayHighlightReason(u,"hover",!0))}))},r.ScreenSpaceEventType.MOUSE_MOVE)}getPropertyValue(e,t){try{return e&&typeof e.getValue=="function"?e.getValue(r.JulianDate.now()):e!==void 0?e:t}catch{return t}}getNumberProperty(e,t){const i=this.getPropertyValue(e,t),n=typeof i=="number"?i:Number(i);return Number.isFinite(n)?n:t}resolveHighlightOptions(e){const t=typeof e=="object"&&e?e.fillAlpha:void 0,i=typeof t=="number"?r.Math.clamp(t,0,1):k.DEFAULT_HIGHLIGHT_FILL_ALPHA,n=typeof e=="object"&&e?e.color:void 0;return{color:(a=>{try{return a?a instanceof r.Color?a:r.Color.fromCssColorString(String(a)):k.DEFAULT_HIGHLIGHT_COLOR}catch{return k.DEFAULT_HIGHLIGHT_COLOR}})(n),fillAlpha:i}}getActiveHighlightOptions(e){const t=e._highlightState,i=t?.click?e._clickHighlight:t?.hover?e._hoverHighlight:void 0;return this.resolveHighlightOptions(i)}setOverlayHighlightReason(e,t,i){for(const n of e){const o=n;o._highlightState||(o._highlightState={}),o._highlightState[t]=i,!!(o._highlightState.click||o._highlightState.hover)?this.applyOverlayHighlightStyle(o):this.restoreOverlayHighlightStyle(o)}}applyOverlayHighlightStyle(e){if(e._highlightOriginalStyle||(e._highlightOriginalStyle={}),e._overlayType==="circle-primitive"){const{color:n,fillAlpha:o}=this.getActiveHighlightOptions(e);this.circle.applyPrimitiveHighlight(e,n,o);return}if(e._overlayType==="polygon-primitive"){const{color:n,fillAlpha:o}=this.getActiveHighlightOptions(e);this.polygon.applyPrimitiveHighlight(e,n,o);return}if(e._overlayType==="rectangle-primitive"){const{color:n,fillAlpha:o}=this.getActiveHighlightOptions(e);this.rectangle.applyPrimitiveHighlight(e,n,o);return}const{color:t,fillAlpha:i}=this.getActiveHighlightOptions(e);if(e.point){const n=e.point;e._highlightOriginalStyle.point||(e._highlightOriginalStyle.point={pixelSize:n.pixelSize,color:n.color,outlineColor:n.outlineColor,outlineWidth:n.outlineWidth});const o=this.getNumberProperty(n.pixelSize,10),s=this.getNumberProperty(n.outlineWidth,2);n.pixelSize=new r.ConstantProperty(o+3),n.color=new r.ConstantProperty(t.withAlpha(.9)),n.outlineColor=new r.ConstantProperty(t),n.outlineWidth=new r.ConstantProperty(Math.max(3,s+1))}if(e.label){const n=e.label;e._highlightOriginalStyle.label||(e._highlightOriginalStyle.label={fillColor:n.fillColor,outlineColor:n.outlineColor,outlineWidth:n.outlineWidth,scale:n.scale});const o=this.getNumberProperty(n.scale,1),s=this.getNumberProperty(n.outlineWidth,2);n.fillColor=new r.ConstantProperty(t),n.outlineColor=new r.ConstantProperty(r.Color.BLACK),n.outlineWidth=new r.ConstantProperty(Math.max(2,s)),n.scale=new r.ConstantProperty(o*1.08)}if(e.billboard){const n=e.billboard;e._highlightOriginalStyle.billboard||(e._highlightOriginalStyle.billboard={scale:n.scale,color:n.color});const o=this.getNumberProperty(n.scale,1);n.scale=new r.ConstantProperty(o*1.08),n.color=new r.ConstantProperty(t)}if(e.polyline){const n=e.polyline;e._highlightOriginalStyle.polyline||(e._highlightOriginalStyle.polyline={width:n.width,material:n.material});const o=this.getNumberProperty(n.width,2);if(n.width=new r.ConstantProperty(o+2),n.material instanceof r.ColorMaterialProperty)n.material=new r.ColorMaterialProperty(t);else if(n.material instanceof r.PolylineGlowMaterialProperty){const s=n.material.glowPower;n.material=new r.PolylineGlowMaterialProperty({color:t,glowPower:typeof s=="number"?s:.25})}}if(e.polygon){const n=e.polygon;e._highlightOriginalStyle.polygon||(e._highlightOriginalStyle.polygon={outline:n.outline,outlineColor:n.outlineColor,outlineWidth:n.outlineWidth,material:n.material});const o=this.getNumberProperty(n.outlineWidth,1);n.outline=new r.ConstantProperty(!0),n.outlineColor=new r.ConstantProperty(t),n.outlineWidth=new r.ConstantProperty(Math.max(2,o+2)),n.material=new r.ColorMaterialProperty(t.withAlpha(i))}if(e.rectangle){const n=e.rectangle;e._highlightOriginalStyle.rectangle||(e._highlightOriginalStyle.rectangle={outline:n.outline,outlineColor:n.outlineColor,outlineWidth:n.outlineWidth,material:n.material});const o=this.getNumberProperty(n.outlineWidth,1);n.outline=new r.ConstantProperty(!0),n.outlineColor=new r.ConstantProperty(t),n.outlineWidth=new r.ConstantProperty(Math.max(2,o+2)),n.material=new r.ColorMaterialProperty(t.withAlpha(i))}if(e.ellipse){const n=e.ellipse;e._highlightOriginalStyle.ellipse||(e._highlightOriginalStyle.ellipse={outline:n.outline,outlineColor:n.outlineColor,outlineWidth:n.outlineWidth,material:n.material});const o=this.getNumberProperty(n.outlineWidth,1);n.outline=new r.ConstantProperty(!0),n.outlineColor=new r.ConstantProperty(t),n.outlineWidth=new r.ConstantProperty(Math.max(2,o+2)),n.material=new r.ColorMaterialProperty(t.withAlpha(i))}e._isHighlighted=!0}restoreOverlayHighlightStyle(e){if(e._overlayType==="circle-primitive"){this.circle.restorePrimitiveHighlight(e);return}if(e._overlayType==="polygon-primitive"){this.polygon.restorePrimitiveHighlight(e);return}if(e._overlayType==="rectangle-primitive"){this.rectangle.restorePrimitiveHighlight(e);return}if(!e._isHighlighted)return;const t=e._highlightOriginalStyle;if(!t){e._isHighlighted=!1;return}if(e.point&&t.point){const i=e.point;i.pixelSize=t.point.pixelSize,i.color=t.point.color,i.outlineColor=t.point.outlineColor,i.outlineWidth=t.point.outlineWidth}if(e.label&&t.label){const i=e.label;i.fillColor=t.label.fillColor,i.outlineColor=t.label.outlineColor,i.outlineWidth=t.label.outlineWidth,i.scale=t.label.scale}if(e.billboard&&t.billboard){const i=e.billboard;i.scale=t.billboard.scale,i.color=t.billboard.color}if(e.polyline&&t.polyline){const i=e.polyline;i.width=t.polyline.width,i.material=t.polyline.material}if(e.polygon&&t.polygon){const i=e.polygon;i.outline=t.polygon.outline,i.outlineColor=t.polygon.outlineColor,i.outlineWidth=t.polygon.outlineWidth,i.material=t.polygon.material}if(e.rectangle&&t.rectangle){const i=e.rectangle;i.outline=t.rectangle.outline,i.outlineColor=t.rectangle.outlineColor,i.outlineWidth=t.rectangle.outlineWidth,i.material=t.rectangle.material}if(e.ellipse&&t.ellipse){const i=e.ellipse;i.outline=t.ellipse.outline,i.outlineColor=t.ellipse.outlineColor,i.outlineWidth=t.ellipse.outlineWidth,i.material=t.ellipse.material}e._isHighlighted=!1}generateId(e){return`${e}_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}toggleOverlayHighlight(e,t="click"){const i=e._highlightEntities&&e._highlightEntities.length>0?e._highlightEntities:[e],n=!i.some(o=>!!o._highlightState?.[t]);this.setOverlayHighlightReason(i,t,n)}setOverlayHighlight(e,t,i="click"){const n=typeof e=="string"?this.overlayMap.get(e):e;if(!n)return!1;const o=n._highlightEntities&&n._highlightEntities.length>0?n._highlightEntities:[n];return this.setOverlayHighlightReason(o,i,t),!0}addMarker(e){const t=e.id||this.generateId("marker"),i=this.marker.add({...e,id:t});return this.overlayMap.set(t,i),i}addLabel(e){const t=e.id||this.generateId("label"),i=this.label.add({...e,id:t});return this.overlayMap.set(t,i),i}addIcon(e){const t=e.id||this.generateId("icon"),i=this.icon.add({...e,id:t});return this.overlayMap.set(t,i),i}addSvg(e){const t=e.id||this.generateId("svg"),i=this.svg.add({...e,id:t});return this.overlayMap.set(t,i),i}addInfoWindow(e){const t=e.id||this.generateId("infowindow"),i=this.infoWindow.add({...e,id:t});return this.overlayMap.set(t,i),i}addPolyline(e){const t=e.id||this.generateId("polyline"),i=this.polyline.add({...e,id:t});return this.overlayMap.set(t,i),i}addPolygon(e){const t=e.id||this.generateId("polygon"),i=this.polygon.add({...e,id:t});return this.overlayMap.set(t,i),i}addRectangle(e){const t=e.id||this.generateId("rectangle"),i=this.rectangle.add({...e,id:t});return this.overlayMap.set(t,i),i}addCircle(e){const t=e.id||this.generateId("circle"),i=this.circle.add({...e,id:t});return this.overlayMap.set(t,i),i}addRing(e){const t=e.id||this.generateId("ring"),i=this.ring.add({...e,id:t});return this.overlayMap.set(t,i),i}getOverlay(e){return this.overlayMap.get(e)}removeOverlay(e){const t=this.overlayMap.get(e);if(t){const i=t;if(i._infoWindow&&this.infoWindow.remove(t),i._overlayType==="circle-primitive"){try{this.circle.remove(t)}catch{}return this.overlayMap.delete(e),!0}if(i._overlayType==="polygon-primitive"){try{this.polygon.remove(t)}catch{}return this.overlayMap.delete(e),!0}if(i._overlayType==="rectangle-primitive"){try{this.rectangle.remove(t)}catch{}return this.overlayMap.delete(e),!0}return i._innerEntity&&(this.entities.remove(i._innerEntity),i._innerEntity=void 0),i._borderEntity&&(this.entities.remove(i._borderEntity),i._borderEntity=void 0),this.entities.remove(t),this.overlayMap.delete(e),!0}return!1}removeAllOverlays(){Array.from(this.overlayMap.keys()).forEach(t=>this.removeOverlay(t))}updateOverlayPosition(e,t){const i=this.overlayMap.get(e);if(!i)return!1;const n=i;return n._overlayType==="circle-primitive"?(this.circle.updatePosition(i,t),!0):(i.point&&!n._infoWindow?this.marker.updatePosition(i,t):i.label?this.label.updatePosition(i,t):i.billboard?this.icon.updatePosition(i,t):i.polyline?n._overlayType==="ring"?this.ring.updatePosition(i,t):console.warn("Polyline position update requires multiple positions"):i.polygon?console.warn("Polygon position update requires multiple positions"):i.ellipse&&this.circle.updatePosition(i,t),n._infoWindow&&this.infoWindow.updatePosition(i,t),!0)}setOverlayVisible(e,t){const i=this.overlayMap.get(e);if(i){i.show=t;const n=i;return n._overlayType==="circle-primitive"?(this.circle.setPrimitiveVisible(i,t),n._innerEntity&&(n._innerEntity.show=t),!0):n._overlayType==="polygon-primitive"?(this.polygon.setPrimitiveVisible(i,t),n._borderEntity&&(n._borderEntity.show=t),!0):n._overlayType==="rectangle-primitive"?(this.rectangle.setPrimitiveVisible(i,t),n._innerEntity&&(n._innerEntity.show=t),!0):(n._innerEntity&&(n._innerEntity.show=t),n._borderEntity&&(n._borderEntity.show=t),n._infoWindow&&this.infoWindow.setVisible(i,t),!0)}return!1}getAllOverlayIds(){return Array.from(this.overlayMap.keys())}getAllOverlays(){return Array.from(this.overlayMap.values())}destroy(){this.removeAllOverlays(),this.infoWindowContainer&&this.infoWindowContainer.parentNode&&this.infoWindowContainer.parentNode.removeChild(this.infoWindowContainer),this.overlayMap.clear()}}class Ue{viewer;imageryLayer=null;rectangle=null;canvas;ctx;options;data=[];gradientLUT;autoUpdateEnabled=!1;autoUpdateOptions={enabled:!0,viewPaddingRatio:.15,cellSizeMeters:1e3,cellSizeMetersByHeight:e=>e>2e6?2e4:e>1e6?12e3:e>5e5?8e3:e>2e5?4e3:e>1e5?2e3:e>5e4?1e3:e>2e4?600:300};removeMoveEndListener=null;aggregateWorker=null;workerReady=!1;pendingUpdate=!1;lastUpdateKey="";constructor(e,t={}){this.viewer=e;const i=t.width??512,n=t.height??512,o=document.createElement("canvas");o.width=i,o.height=n;const s=o.getContext("2d");if(!s)throw new Error("Failed to get 2D context for heatmap canvas.");this.canvas=o,this.ctx=s,this.options={width:i,height:n,radius:t.radius??30,minValue:t.minValue??0,maxValue:t.maxValue??1,opacity:t.opacity??1,gradient:t.gradient??{0:"#0000ff",.4:"#00ffff",.7:"#ffff00",1:"#ff0000"}},this.gradientLUT=new Uint8ClampedArray(256*4),this.buildGradientLUT()}setData(e){if(this.data=e.slice(),this.data.length===0){this.clearLayer();return}let t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;for(const a of this.data)!Number.isFinite(a.lon)||!Number.isFinite(a.lat)||(a.lon<t&&(t=a.lon),a.lon>n&&(n=a.lon),a.lat<i&&(i=a.lat),a.lat>o&&(o=a.lat));if(!Number.isFinite(t)||!Number.isFinite(i)||!Number.isFinite(n)||!Number.isFinite(o)){this.clearLayer();return}const s=.001;t-=s,n+=s,i-=s,o+=s,this.rectangle=r.Rectangle.fromDegrees(t,i,n,o),this.autoUpdateEnabled?(this.ensureWorker(),this.pushDataToWorker(),this.requestAutoUpdate()):this.renderHeatmap(this.data,this.rectangle,{persistMinMax:!0})}setGradient(e){this.options.gradient=e,this.buildGradientLUT(),this.data.length>0&&(this.autoUpdateEnabled?this.requestAutoUpdate():this.rectangle&&this.renderHeatmap(this.data,this.rectangle,{persistMinMax:!0}))}setOpacity(e){this.options.opacity=Math.min(1,Math.max(0,e)),this.imageryLayer&&(this.imageryLayer.alpha=this.options.opacity)}setVisible(e){this.imageryLayer&&(this.imageryLayer.show=e)}destroy(){if(this.stopAutoUpdate(),this.aggregateWorker){try{this.aggregateWorker.terminate()}catch{}this.aggregateWorker=null,this.workerReady=!1}this.clearLayer()}setAutoUpdate(e={}){const t=e.enabled??!0;this.autoUpdateOptions={...this.autoUpdateOptions,...e,enabled:t,viewPaddingRatio:e.viewPaddingRatio??this.autoUpdateOptions.viewPaddingRatio,cellSizeMeters:e.cellSizeMeters??this.autoUpdateOptions.cellSizeMeters,cellSizeMetersByHeight:e.cellSizeMetersByHeight??this.autoUpdateOptions.cellSizeMetersByHeight},t?this.startAutoUpdateInternal():(this.stopAutoUpdate(),this.data.length>0&&this.rectangle&&this.renderHeatmap(this.data,this.rectangle,{persistMinMax:!0}))}stopAutoUpdate(){if(this.autoUpdateEnabled=!1,this.removeMoveEndListener){try{this.removeMoveEndListener()}catch{}this.removeMoveEndListener=null}this.pendingUpdate=!1,this.lastUpdateKey=""}clearLayer(){if(this.imageryLayer){try{this.viewer.imageryLayers.remove(this.imageryLayer,!0)}catch{}this.imageryLayer=null}}startAutoUpdateInternal(){if(this.autoUpdateEnabled)return;this.autoUpdateEnabled=!0,this.ensureWorker(),this.pushDataToWorker();const e=()=>{this.requestAutoUpdate()},t=this.viewer.camera.moveEnd?.addEventListener?.(e);this.removeMoveEndListener=typeof t=="function"?t:null,this.requestAutoUpdate()}requestAutoUpdate(){if(!this.autoUpdateEnabled)return;if(!this.workerReady){this.pendingUpdate=!0;return}const e=this.getPaddedViewRectangleDegrees(this.autoUpdateOptions.viewPaddingRatio);if(!e)return;const t=this.viewer.camera.positionCartographic?.height??0,i=this.autoUpdateOptions.cellSizeMetersByHeight?this.autoUpdateOptions.cellSizeMetersByHeight(t):this.autoUpdateOptions.cellSizeMeters,n=`${e.west.toFixed(4)},${e.south.toFixed(4)},${e.east.toFixed(4)},${e.north.toFixed(4)}|${Math.round(t)}|${Math.round(i)}`;n!==this.lastUpdateKey&&(this.lastUpdateKey=n,this.aggregateWorker?.postMessage({type:"aggregate",bbox:e,cellMeters:i}))}getPaddedViewRectangleDegrees(e){const t=this.viewer.camera.computeViewRectangle(this.viewer.scene.globe.ellipsoid);if(!t)return null;const i=r.Math.toDegrees(t.west),n=r.Math.toDegrees(t.east),o=r.Math.toDegrees(t.south),s=r.Math.toDegrees(t.north);if(i>n)return null;const a=(n-i)*e,l=(s-o)*e;return{west:i-a,east:n+a,south:o-l,north:s+l}}ensureWorker(){if(this.aggregateWorker)return;const e=`
|
|
201
201
|
let lons = null;
|
|
202
202
|
let lats = null;
|
|
203
203
|
let values = null;
|