cesium-heatbox 1.2.1-alpha.2 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import*as e from"cesium";var t={d:(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const i=(l={BoundingSphere:()=>e.BoundingSphere,Cartesian2:()=>e.Cartesian2,Cartesian3:()=>e.Cartesian3,Cartographic:()=>e.Cartographic,Color:()=>e.Color,Ellipsoid:()=>e.Ellipsoid,Entity:()=>e.Entity,HeadingPitchRange:()=>e.HeadingPitchRange,JulianDate:()=>e.JulianDate,LabelStyle:()=>e.LabelStyle,Math:()=>e.Math,Rectangle:()=>e.Rectangle,ScreenSpaceEventHandler:()=>e.ScreenSpaceEventHandler,ScreenSpaceEventType:()=>e.ScreenSpaceEventType,defined:()=>e.defined},h={},t.d(h,l),h),n={voxelSize:20,opacity:.8,emptyOpacity:.03,showOutline:!0,showEmptyVoxels:!1,wireframeOnly:!1,heightBased:!1,outlineWidth:2,minColor:[0,32,255],maxColor:[255,64,0],maxRenderVoxels:5e4,batchMode:"auto",debug:!1,autoVoxelSize:!1,colorMap:"custom",diverging:!1,divergingPivot:0,highlightTopN:null,highlightStyle:{outlineWidth:4,boostOpacity:.2},voxelGap:0,outlineOpacity:1,outlineWidthResolver:null,outlineEmulation:"off",outlineInset:0,outlineInsetMode:"all",enableThickFrames:!1,outlineRenderMode:"standard",emulationScope:"off",adaptiveOutlines:!1,outlineWidthPreset:"medium",boxOpacityResolver:null,outlineOpacityResolver:null,adaptiveParams:{neighborhoodRadius:30,densityThreshold:3,cameraDistanceFactor:.8,overlapRiskFactor:.4,minOutlineWidth:1,maxOutlineWidth:5,outlineWidthRange:null,boxOpacityRange:null,outlineOpacityRange:null,adaptiveOpacityEnabled:!1,zScaleCompensation:!0,overlapDetection:!1},renderLimitStrategy:"density",minCoverageRatio:.2,coverageBinsXY:"auto",autoVoxelSizeMode:"basic",autoVoxelTargetFill:.6,renderBudgetMode:"manual",autoView:!1,fitViewOptions:{paddingPercent:.1,pitchDegrees:-30,headingDegrees:0,altitudeStrategy:"auto"},spatialId:{enabled:!1,mode:"tile-grid",provider:"ouranos-gex",zoom:25,zoomControl:"auto",zoomTolerancePct:10},aggregation:{enabled:!1,byProperty:null,keyResolver:null,showInDescription:!0,topN:10},classification:{enabled:!1,scheme:"linear",classes:5,thresholds:null,colorMap:null,domain:null,classificationTargets:{color:!0,opacity:!1,width:!1}}},a=5e4,o=1e3,r=40075016.68557849,s=(Math.PI,"対象エンティティがありません");var l,h;let c="undefined"!=typeof process&&process.env&&"true"===process.env.DEBUG?3:"undefined"!=typeof process&&process.env?1:3;const d={error(...e){c>=0&&console.error("[Heatbox ERROR]",...e)},warn(...e){c>=1&&console.warn("[Heatbox WARN]",...e)},info(...e){c>=2&&console.log("[Heatbox INFO]",...e)},debug(...e){c>=3&&console.log("[Heatbox DEBUG]",...e)},setLogLevel:e=>(e&&void 0!==e.debug&&("boolean"==typeof e.debug?c=e.debug?3:1:"object"==typeof e.debug&&null!==e.debug&&(c=3)),c)},u=(d.debug,d.warn,d.error,d.info,new Set);function p(e,t){u.has(e)||(u.add(e),d.warn(t))}const m={"mobile-fast":{maxRenderVoxels:5e3,outlineRenderMode:"emulation-only",adaptiveOutlines:!1,outlineWidthPreset:"thin",opacity:.7,renderLimitStrategy:"density",minCoverageRatio:.1,topNHighlight:10,description:"Mobile devices - prioritizes performance over visual quality"},"desktop-balanced":{maxRenderVoxels:15e3,outlineRenderMode:"standard",adaptiveOutlines:!0,outlineWidthPreset:"medium",opacity:.8,renderLimitStrategy:"hybrid",minCoverageRatio:.2,topNHighlight:20,adaptiveParams:{outlineWidthRange:[1,4],outlineOpacityRange:[.4,1],boxOpacityRange:[.2,.8]},description:"Desktop environments - balanced performance and quality"},"dense-data":{maxRenderVoxels:25e3,outlineRenderMode:"inset",adaptiveOutlines:!0,outlineWidthPreset:"thin",opacity:.6,renderLimitStrategy:"hybrid",minCoverageRatio:.3,topNHighlight:30,outlineInset:.5,highlightTopN:!0,highlightStyle:{boostOpacity:.3,boostOutlineWidth:1.5},description:"High-density datasets - optimized for cluttered environments"},"sparse-data":{maxRenderVoxels:8e3,outlineRenderMode:"standard",adaptiveOutlines:!1,outlineWidthPreset:"thick",opacity:.9,renderLimitStrategy:"coverage",minCoverageRatio:.8,topNHighlight:50,emptyOpacity:.05,showEmptyVoxels:!0,description:"Sparse datasets - emphasizes visibility and coverage"}};function g(){return Object.keys(m)}function f(e){return m[e]||null}function y(e,t={}){const i=f(e);if(!i)return t;const{description:n,...a}=i;return x(a,t)}function x(e,t){const i={...e};for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&(t[e]&&"object"==typeof t[e]&&!Array.isArray(t[e])?i[e]=x(i[e]||{},t[e]):i[e]=t[e]);return i}function v(e,t=!1){if(null==e)return t;if("boolean"==typeof e)return e;if("string"==typeof e){const i=e.trim().toLowerCase();return""===i?t:!!["true","1","yes","on"].includes(i)||!["false","0","no","off"].includes(i)&&Boolean(i)}return"number"==typeof e?Number.isFinite(e)?0!==e:t:Boolean(e)}function b(e){return!!Array.isArray(e)&&0!==e.length&&(e.length>5e3&&d.warn(`エンティティ数が推奨値(5000)を超えています: ${e.length}`),!0)}function M(e={}){let t=e;var i;e.profile&&"none"!==e.profile&&("string"==typeof(i=e.profile)&&Object.prototype.hasOwnProperty.call(m,i)?(d.debug(`Applying profile: ${e.profile}`),t=y(e.profile,e),delete t.profile):d.warn(`Invalid profile name: ${e.profile}. Available profiles: mobile-fast, desktop-balanced, dense-data, sparse-data`));const a={...t};if(a.batchMode&&a.debug&&d.warn("batchMode option is deprecated and will be removed in v1.0.0. It is currently ignored."),void 0!==a.voxelSize&&("number"!=typeof(r=a.voxelSize)||isNaN(r)||r<5||r>o))throw new Error(`ボクセルサイズが無効です: ${a.voxelSize}`);var r;if(void 0!==a.opacity&&(a.opacity=Math.max(0,Math.min(1,a.opacity))),void 0!==a.emptyOpacity&&(a.emptyOpacity=Math.max(0,Math.min(1,a.emptyOpacity))),a.minColor&&Array.isArray(a.minColor)&&3===a.minColor.length&&(a.minColor=a.minColor.map(e=>Math.max(0,Math.min(255,Math.floor(e))))),a.maxColor&&Array.isArray(a.maxColor)&&3===a.maxColor.length&&(a.maxColor=a.maxColor.map(e=>Math.max(0,Math.min(255,Math.floor(e))))),void 0!==a.colorMap&&(["custom","viridis","inferno"].includes(a.colorMap)||(d.warn(`Invalid colorMap: ${a.colorMap}. Using 'custom'.`),a.colorMap="custom")),void 0!==a.highlightTopN&&null!==a.highlightTopN&&("number"!=typeof a.highlightTopN||a.highlightTopN<=0)&&(d.warn(`Invalid highlightTopN: ${a.highlightTopN}. Must be a positive number.`),a.highlightTopN=null),void 0!==a.voxelGap&&(a.voxelGap=Math.max(0,Math.min(100,parseFloat(a.voxelGap)||0))),void 0!==a.outlineOpacity&&(a.outlineOpacity=Math.max(0,Math.min(1,parseFloat(a.outlineOpacity)||1))),void 0!==a.outlineWidth){const e=parseFloat(a.outlineWidth);a.outlineWidth=Number.isFinite(e)?Math.max(.5,Math.min(20,e)):n.outlineWidth}if(void 0!==a.wireframeOnly&&(a.wireframeOnly=v(a.wireframeOnly)),void 0!==a.heightBased&&(a.heightBased=v(a.heightBased)),void 0!==a.outlineWidthResolver&&null!==a.outlineWidthResolver&&(p("outlineWidthResolver","[Heatbox][DEPRECATION][v1.0.0] outlineWidthResolver is deprecated; prefer adaptiveOutlines with outlineWidthPreset and adaptiveParams."),"function"!=typeof a.outlineWidthResolver&&(d.warn("outlineWidthResolver must be a function. Ignoring."),a.outlineWidthResolver=null)),void 0!==a.outlineOpacityResolver&&null!==a.outlineOpacityResolver&&(p("outlineOpacityResolver","[Heatbox][DEPRECATION][v1.0.0] outlineOpacityResolver is deprecated; prefer adaptiveOutlines with adaptiveParams.outlineOpacityRange."),"function"!=typeof a.outlineOpacityResolver&&(d.warn("outlineOpacityResolver must be a function. Ignoring."),a.outlineOpacityResolver=null)),void 0!==a.boxOpacityResolver&&null!==a.boxOpacityResolver&&(p("boxOpacityResolver","[Heatbox][DEPRECATION][v1.0.0] boxOpacityResolver is deprecated; prefer adaptiveOutlines with adaptiveParams.boxOpacityRange."),"function"!=typeof a.boxOpacityResolver&&(d.warn("boxOpacityResolver must be a function. Ignoring."),a.boxOpacityResolver=null)),void 0!==a.outlineEmulation&&(void 0===a.outlineRenderMode||"standard"===a.outlineRenderMode)){p("outlineEmulation","[Heatbox][DEPRECATION][v1.0.0] outlineEmulation is deprecated; use outlineRenderMode and emulationScope instead.");const e=a.outlineEmulation;!1===e||"off"===e?(a.outlineRenderMode="standard",a.emulationScope="off"):!0===e||"all"===e?(a.outlineRenderMode="emulation-only",a.emulationScope="all"):"topn"===e?(a.outlineRenderMode="standard",a.emulationScope="topn"):"non-topn"===e?(a.outlineRenderMode="standard",a.emulationScope="non-topn"):(d.warn(`Invalid outlineEmulation: ${e}. Using 'standard' mode.`),a.outlineRenderMode="standard"),delete a.outlineEmulation}if(void 0!==a.outlineWidthPreset){const e=a.outlineWidthPreset,t={uniform:"medium","adaptive-density":"adaptive","topn-focus":"thick"};t[e]&&(p(`outlineWidthPreset.${e}`,`[Heatbox][DEPRECATION][v1.0.0] outlineWidthPreset "${e}" is deprecated; use "${t[e]}".`),a.outlineWidthPreset=t[e])}if(void 0!==a.outlineInset){const e=parseFloat(a.outlineInset);a.outlineInset=isNaN(e)||e<0?0:e}if(void 0!==a.outlineInsetMode){let e=a.outlineInsetMode;"off"===e&&(e="none"),["all","topn","none"].includes(e)?a.outlineInsetMode=e:(d.warn(`Invalid outlineInsetMode: ${a.outlineInsetMode}. Using 'all'.`),a.outlineInsetMode="all")}if(void 0!==a.outlineInset){const e=parseFloat(a.outlineInset);a.outlineInset=Math.max(0,Math.min(100,isNaN(e)?0:e))}if(void 0!==a.outlineInsetMode){let e=a.outlineInsetMode;"off"===e&&(e="none"),["all","topn","none"].includes(e)?a.outlineInsetMode=e:(d.warn(`Invalid outlineInsetMode: ${a.outlineInsetMode}. Using 'all'.`),a.outlineInsetMode="all")}if(void 0!==a.enableThickFrames&&(a.enableThickFrames=v(a.enableThickFrames)),void 0!==a.renderLimitStrategy&&(["density","coverage","hybrid"].includes(a.renderLimitStrategy)||(d.warn(`Invalid renderLimitStrategy: ${a.renderLimitStrategy}. Using 'density'.`),a.renderLimitStrategy="density")),void 0!==a.minCoverageRatio){const e=parseFloat(a.minCoverageRatio);a.minCoverageRatio=isNaN(e)?.2:Math.max(0,Math.min(1,e))}if(void 0!==a.coverageBinsXY){const e=a.coverageBinsXY;if("auto"!==e){const t=parseInt(e,10);!Number.isFinite(t)||t<=0?(d.warn(`Invalid coverageBinsXY: ${e}. Using 'auto'.`),a.coverageBinsXY="auto"):a.coverageBinsXY=t}}if(void 0!==a.autoVoxelSizeMode&&(["basic","occupancy"].includes(a.autoVoxelSizeMode)||(d.warn(`Invalid autoVoxelSizeMode: ${a.autoVoxelSizeMode}. Using 'basic'.`),a.autoVoxelSizeMode="basic")),void 0!==a.autoVoxelTargetFill){const e=parseFloat(a.autoVoxelTargetFill);a.autoVoxelTargetFill=isNaN(e)?.6:Math.max(0,Math.min(1,e))}if(void 0!==a.renderBudgetMode&&(["manual","auto"].includes(a.renderBudgetMode)||(d.warn(`Invalid renderBudgetMode: ${a.renderBudgetMode}. Using 'manual'.`),a.renderBudgetMode="manual")),void 0!==a.fitViewOptions){const e=a.fitViewOptions||{};void 0!==e.pitch&&void 0===e.pitchDegrees&&p("fitViewOptions.pitch","[Heatbox][DEPRECATION][v1.0.0] fitViewOptions.pitch is deprecated; use fitViewOptions.pitchDegrees."),void 0!==e.heading&&void 0===e.headingDegrees&&p("fitViewOptions.heading","[Heatbox][DEPRECATION][v1.0.0] fitViewOptions.heading is deprecated; use fitViewOptions.headingDegrees.");const t=parseFloat(e.paddingPercent),i=void 0!==e.pitchDegrees?parseFloat(e.pitchDegrees):parseFloat(e.pitch),n=void 0!==e.headingDegrees?parseFloat(e.headingDegrees):parseFloat(e.heading),o=e.altitudeStrategy;a.fitViewOptions={paddingPercent:Number.isFinite(t)?Math.max(0,Math.min(1,t)):.1,pitchDegrees:Number.isFinite(i)?Math.max(-90,Math.min(0,i)):-30,headingDegrees:Number.isFinite(n)?n:0,altitudeStrategy:"manual"===o?"manual":"auto"}}const s=a.adaptiveParams?{...a.adaptiveParams}:{};a.adaptiveParams={...n.adaptiveParams,...s};const l=a.adaptiveParams;if(void 0!==s.minOutlineWidth&&void 0!==s.maxOutlineWidth&&void 0===s.outlineWidthRange&&(l.outlineWidthRange=[Math.max(1,parseFloat(s.minOutlineWidth)||1),Math.max(1,parseFloat(s.maxOutlineWidth)||5)],d.debug("adaptiveParams: minOutlineWidth/maxOutlineWidth normalized to outlineWidthRange")),void 0!==l.outlineWidthRange&&Array.isArray(l.outlineWidthRange)){const[e,t]=l.outlineWidthRange;l.outlineWidthRange=[Math.max(1,parseFloat(e)||1),Math.max(1,parseFloat(t)||5)],l.outlineWidthRange[0]>l.outlineWidthRange[1]&&(l.outlineWidthRange=[l.outlineWidthRange[1],l.outlineWidthRange[0]],d.warn("adaptiveParams.outlineWidthRange: min > max detected, swapped values"))}if(void 0!==l.boxOpacityRange&&Array.isArray(l.boxOpacityRange)){const[e,t]=l.boxOpacityRange;l.boxOpacityRange=[Math.max(0,Math.min(1,parseFloat(e)||0)),Math.max(0,Math.min(1,parseFloat(t)||1))],l.boxOpacityRange[0]>l.boxOpacityRange[1]&&(l.boxOpacityRange=[l.boxOpacityRange[1],l.boxOpacityRange[0]],d.warn("adaptiveParams.boxOpacityRange: min > max detected, swapped values"))}if(void 0!==l.outlineOpacityRange&&Array.isArray(l.outlineOpacityRange)){const[e,t]=l.outlineOpacityRange;l.outlineOpacityRange=[Math.max(0,Math.min(1,parseFloat(e)||0)),Math.max(0,Math.min(1,parseFloat(t)||1))],l.outlineOpacityRange[0]>l.outlineOpacityRange[1]&&(l.outlineOpacityRange=[l.outlineOpacityRange[1],l.outlineOpacityRange[0]],d.warn("adaptiveParams.outlineOpacityRange: min > max detected, swapped values"))}if(void 0!==l.overlapDetection&&(l.overlapDetection=v(l.overlapDetection)),void 0!==l.zScaleCompensation&&(l.zScaleCompensation=v(l.zScaleCompensation)),void 0!==l.adaptiveOpacityEnabled&&(l.adaptiveOpacityEnabled=v(l.adaptiveOpacityEnabled)),void 0!==l.neighborhoodRadius){const e=parseFloat(l.neighborhoodRadius);l.neighborhoodRadius=Number.isFinite(e)&&e>0?e:30}if(void 0!==l.densityThreshold){const e=parseFloat(l.densityThreshold);l.densityThreshold=Number.isFinite(e)&&e>0?e:3}if(void 0!==l.cameraDistanceFactor){const e=parseFloat(l.cameraDistanceFactor);l.cameraDistanceFactor=Number.isFinite(e)&&e>0?e:.8}if(void 0!==l.overlapRiskFactor){const e=parseFloat(l.overlapRiskFactor);l.overlapRiskFactor=Number.isFinite(e)?Math.max(0,Math.min(1,e)):.4}if(a.adaptiveParams=l,a.performanceOverlay){const e={...a.performanceOverlay};if(e.enabled=v(e.enabled,!1),e.autoShow=v(e.autoShow,!1),e.autoUpdate=v(e.autoUpdate,!0),e.position=["top-left","top-right","bottom-left","bottom-right"].includes(e.position)?e.position:"top-right",void 0!==e.updateIntervalMs){const t=parseFloat(e.updateIntervalMs);e.updateIntervalMs=Number.isFinite(t)?Math.max(100,t):500}if(void 0!==e.fpsAveragingWindowMs){const t=parseFloat(e.fpsAveragingWindowMs);e.fpsAveragingWindowMs=Number.isFinite(t)?Math.max(200,t):1e3}a.performanceOverlay=e}if(void 0!==t.spatialId){const e="object"==typeof t.spatialId&&null!==t.spatialId?{...t.spatialId}:{};if(e.enabled=v(e.enabled,!1),void 0!==e.mode?"tile-grid"!==e.mode&&(d.warn(`Invalid spatialId.mode: ${e.mode}. Using 'tile-grid'.`),e.mode="tile-grid"):e.mode="tile-grid",void 0!==e.provider?"ouranos-gex"!==e.provider&&(d.warn(`Unknown spatialId.provider: ${e.provider}. Using 'ouranos-gex'.`),e.provider="ouranos-gex"):e.provider="ouranos-gex",void 0!==e.zoom)if("auto"===e.zoom)e.zoom="auto";else{const t=parseInt(e.zoom,10);Number.isNaN(t)||t<0||t>35?(d.warn(`Invalid spatialId.zoom: ${e.zoom}. Using 25.`),e.zoom=25):e.zoom=t}else e.zoom=25;if(void 0!==e.zoomControl?["auto","manual"].includes(e.zoomControl)||(d.warn(`Invalid spatialId.zoomControl: ${e.zoomControl}. Using 'auto'.`),e.zoomControl="auto"):e.zoomControl="auto",void 0!==e.zoomTolerancePct){const t=parseFloat(e.zoomTolerancePct);!Number.isFinite(t)||t<=0||t>100?(d.warn(`Invalid spatialId.zoomTolerancePct: ${e.zoomTolerancePct}. Using 10.`),e.zoomTolerancePct=10):e.zoomTolerancePct=t}else e.zoomTolerancePct=10;a.spatialId=e}else a.spatialId={...n.spatialId};return a.classification=function(e){const t={...n.classification,classificationTargets:{...n.classification.classificationTargets}};if(void 0===e)return{...t};if(null===e||!1===e)return{...t,enabled:!1};const i={...t};let a=e;const o=["color","opacity","width"];if("string"==typeof e&&(a={scheme:e,enabled:"none"!==e}),"object"==typeof a){if(void 0!==a.enabled?i.enabled=v(a.enabled,t.enabled):i.enabled=!0,void 0!==a.scheme&&(i.scheme=function(e){if(!e||"string"!=typeof e)return"linear";const t=e.trim().toLowerCase();return["linear","log","equal-interval","quantize","threshold","quantile","jenks"].includes(t)?t:(d.warn(`[classification] Unknown scheme '${e}', falling back to 'linear'.`),"linear")}(a.scheme)),void 0!==a.classes){const e=Number(a.classes);i.classes=Number.isInteger(e)?Math.max(2,Math.min(20,e)):t.classes}if(Array.isArray(a.thresholds)){const e=a.thresholds.map(e=>Number(e)).filter(e=>Number.isFinite(e)).sort((e,t)=>e-t);i.thresholds=e.length>0?e:null}else null===a.thresholds&&(i.thresholds=null);if(Array.isArray(a.colorMap)?i.colorMap=a.colorMap.slice():null===a.colorMap?i.colorMap=null:void 0!==a.colorMap&&(d.warn("[classification] colorMap should be an array of colors or stop objects. Ignoring provided value."),i.colorMap=null),Array.isArray(a.domain)&&2===a.domain.length){const[e,t]=a.domain.map(e=>Number(e));Number.isFinite(e)&&Number.isFinite(t)&&(i.domain=[e,t])}else null===a.domain&&(i.domain=null);const e={...t.classificationTargets},n=(i,n)=>{if(null!=i)if("object"!=typeof i||Array.isArray(i))d.warn(`[classification] ${n} should be an object with boolean flags. Ignoring provided value.`);else for(const n of o)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=v(i[n],t.classificationTargets[n]))};n(a.targets,"targets"),n(a.classificationTargets,"classificationTargets"),i.classificationTargets=e}else d.warn("[classification] Unsupported configuration type. Expected string or object."),i.enabled=!1;return i.enabled?"threshold"!==i.scheme||Array.isArray(i.thresholds)?i:(d.warn("[classification] threshold scheme requires a thresholds array. Disabling classification."),{...t,enabled:!1}):{...t,enabled:!1}}(a.classification),void 0!==a.aggregation?a.aggregation=function(e){const t={...n.aggregation};if(!e||"object"!=typeof e)return t;if(void 0!==e.enabled&&(t.enabled=v(e.enabled,!1)),void 0!==e.byProperty&&null!==e.byProperty&&("string"==typeof e.byProperty&&""!==e.byProperty.trim()?t.byProperty=e.byProperty.trim():(d.warn("[aggregation] byProperty must be a non-empty string, ignoring"),t.byProperty=null)),void 0!==e.keyResolver&&null!==e.keyResolver&&("function"==typeof e.keyResolver?t.keyResolver=e.keyResolver:(d.warn("[aggregation] keyResolver must be a function, ignoring"),t.keyResolver=null)),void 0!==e.showInDescription&&(t.showInDescription=v(e.showInDescription,!0)),void 0!==e.topN){const i=Number(e.topN);Number.isInteger(i)&&i>0&&i<=100?t.topN=i:(d.warn("[aggregation] topN must be a positive integer <= 100, using default (10)"),t.topN=n.aggregation.topN)}return!t.enabled||t.byProperty||t.keyResolver||d.warn('[aggregation] enabled=true but neither byProperty nor keyResolver is set. Will use default key "default".'),t}(a.aggregation):a.aggregation={...n.aggregation},a}function w(e,t){const i=_(e),n=i.x*i.y*Math.max(i.z,10),a=t/n;let r;return r=a>.001?Math.max(10,Math.min(20,20/Math.sqrt(1e3*a))):a>1e-4?Math.max(20,Math.min(50,50/Math.sqrt(1e4*a))):Math.max(50,Math.min(100,100/Math.sqrt(1e5*a))),r=Math.max(5,Math.min(o,r)),d.debug(`Basic voxel size estimated: ${r}m (density: ${a}, volume: ${n})`),Math.round(r)}function _(e){try{const t={minLat:Number.isFinite(e.minLat)?Math.max(-90,Math.min(90,e.minLat)):0,maxLat:Number.isFinite(e.maxLat)?Math.max(-90,Math.min(90,e.maxLat)):.1,minLon:Number.isFinite(e.minLon)?Math.max(-180,Math.min(180,e.minLon)):0,maxLon:Number.isFinite(e.maxLon)?Math.max(-180,Math.min(180,e.maxLon)):.1,minAlt:Number.isFinite(e.minAlt)?e.minAlt:0,maxAlt:Number.isFinite(e.maxAlt)?e.maxAlt:100};t.maxLat<=t.minLat&&(t.maxLat=t.minLat+.001),t.maxLon<=t.minLon&&(t.maxLon=t.minLon+.001),t.maxAlt<=t.minAlt&&(t.maxAlt=t.minAlt+1);const i=(t.minLat+t.maxLat)/2,n=Math.cos(Math.max(-Math.PI/2,Math.min(Math.PI/2,i*Math.PI/180))),a=111e3*Math.abs(t.maxLon-t.minLon)*Math.abs(n),o=111e3*Math.abs(t.maxLat-t.minLat),r=Math.abs(t.maxAlt-t.minAlt);return{x:Math.max(1,Math.min(1e6,a)),y:Math.max(1,Math.min(1e6,o)),z:Math.max(1,Math.min(1e4,r))}}catch(e){return d.warn("Data range calculation failed:",e),{x:1e3,y:1e3,z:100}}}const S={low:{min:4e3,max:8e3},mid:{min:8e3,max:15e3},high:{min:15e3,max:25e3}};class C{static calculateBounds(e){if(!Array.isArray(e)||0===e.length)throw new Error("エンティティが提供されていません");let t=1/0,n=-1/0,a=1/0,o=-1/0,r=1/0,s=-1/0,l=0;const h=i.JulianDate.now();if(e.forEach((e,c)=>{try{let c,d,u,p;if(e.position&&(c="function"==typeof e.position.getValue?e.position.getValue(h):e.position),!c)return;if("number"==typeof c?.x&&"number"==typeof c?.y&&Math.abs(c.x)<=360&&Math.abs(c.y)<=90)d=c.x,u=c.y,p="number"==typeof c.z?c.z:0;else{const e=i.Cartographic.fromCartesian(c);if(!e)return;d=i.Math.toDegrees(e.longitude),u=i.Math.toDegrees(e.latitude),p=e.height}t=Math.min(t,d),n=Math.max(n,d),a=Math.min(a,u),o=Math.max(o,u),r=Math.min(r,p),s=Math.max(s,p),l++}catch(e){d.warn(`エンティティ ${c} の処理に失敗:`,e)}}),0===l)throw new Error("有効な位置情報を持つエンティティが見つかりません");return d.debug("座標範囲計算完了:",{validCount:l,bounds:{minLon:t,maxLon:n,minLat:a,maxLat:o,minAlt:r,maxAlt:s}}),{minLon:t,maxLon:n,minLat:a,maxLat:o,minAlt:r,maxAlt:s,centerLon:(t+n)/2,centerLat:(a+o)/2,centerAlt:(r+s)/2}}static voxelIndexToCoordinate(e,t,i,n,a){const{minLon:o,maxLon:r,minLat:s,maxLat:l,minAlt:h,maxAlt:c}=n,{numVoxelsX:d,numVoxelsY:u,numVoxelsZ:p}=a;return{lon:o+(e+.5)/d*(r-o),lat:s+(t+.5)/u*(l-s),alt:h+(i+.5)/p*(c-h)}}static coordinateToCartesian3(e,t,n){return i.Cartesian3.fromDegrees(e,t,n)}}class z{static createGrid(e,t){const i=(e.minLat+e.maxLat)/2,n=111e3*(e.maxLon-e.minLon)*Math.cos(i*Math.PI/180),a=111e3*(e.maxLat-e.minLat),o=e.maxAlt-e.minAlt,r=Math.max(1,Math.ceil(n/t)),s=Math.max(1,Math.ceil(a/t)),l=Math.max(1,Math.ceil(o/t)),h=r>0?n/r:t,c=s>0?a/s:t,u=l>0?Math.max(o/l,1):Math.max(t,1),p=r*s*l;return d.debug("VoxelGrid created:",{numVoxelsX:r,numVoxelsY:s,numVoxelsZ:l,totalVoxels:p,voxelSizeMeters:t,cellSizeX:h,cellSizeY:c,cellSizeZ:u,lonRangeMeters:n,latRangeMeters:a,altRangeMeters:o}),{numVoxelsX:r,numVoxelsY:s,numVoxelsZ:l,totalVoxels:p,voxelSizeMeters:t,cellSizeX:h,cellSizeY:c,cellSizeZ:u,lonRangeMeters:n,latRangeMeters:a,altRangeMeters:o}}static getVoxelKey(e,t,i){return`${e},${t},${i}`}static parseVoxelKey(e){const[t,i,n]=e.split(",").map(Number);return{x:t,y:i,z:n}}static iterateAllVoxels(e,t){const{numVoxelsX:i,numVoxelsY:n,numVoxelsZ:a}=e;for(let e=0;e<i;e++)for(let i=0;i<n;i++)for(let n=0;n<a;n++)t(e,i,n,this.getVoxelKey(e,i,n))}}class R{static convert(e,t,i,n){e=R._normalizeLongitude(e),t=R._clampLatitude(t),n=Math.max(0,Math.min(35,Math.floor(n)));const a=Math.pow(2,n),o=Math.floor((e+180)/360*a),r=t*Math.PI/180,s=Math.floor((1-Math.log(Math.tan(r)+1/Math.cos(r))/Math.PI)/2*a),l=R._getAltitudePerBin(n,t),h=Math.floor(i/l);return{zfxy:{z:n,f:h,x:o,y:s},zfxyStr:`/${n}/${h}/${o}/${s}`,vertices:R._calculateVertices(e,t,i,n,o,s,h,l)}}static _normalizeLongitude(e){if(180===e)return-180;for(;e>180;)e-=360;for(;e<-180;)e+=360;return e}static _clampLatitude(e){const t=85.0511287798;return Math.max(-t,Math.min(t,e))}static _getAltitudePerBin(e,t){const i=r,n=Math.max(0,Math.min(35,Math.floor(e))),a=Number.isFinite(t)?t*Math.PI/180:0,o=i*Math.max(Math.cos(a),1e-5)/Math.pow(2,n)*1;return Math.min(5e3,Math.max(.5,o))}static _calculateVertices(e,t,i,n,a,o,r,s){const l=Math.pow(2,n),h=a/l*360-180,c=(a+1)/l*360-180,d=Math.atan(Math.sinh(Math.PI*(1-2*(o+1)/l))),u=Math.atan(Math.sinh(Math.PI*(1-2*o/l))),p=180*d/Math.PI,m=180*u/Math.PI,g=r*s,f=(r+1)*s;return[{lng:h,lat:p,alt:g},{lng:c,lat:p,alt:g},{lng:c,lat:m,alt:g},{lng:h,lat:m,alt:g},{lng:h,lat:p,alt:f},{lng:c,lat:p,alt:f},{lng:c,lat:m,alt:f},{lng:h,lat:m,alt:f}]}static validateZFXY(e){if(!e||"object"!=typeof e)return!1;const{z:t,f:i,x:n,y:a}=e;if(!(Number.isInteger(t)&&Number.isInteger(i)&&Number.isInteger(n)&&Number.isInteger(a)))return!1;if(t<0||t>35)return!1;const o=Math.pow(2,t);return!(n<0||n>=o||a<0||a>=o)}static parseZFXYStr(e){if("string"!=typeof e)return null;const t=e.split("/").filter(e=>e.length>0);if(4!==t.length)return null;const[i,n,a,o]=t.map(e=>parseInt(e,10));if(Number.isNaN(i)||Number.isNaN(n)||Number.isNaN(a)||Number.isNaN(o))return null;const r={z:i,f:n,x:a,y:o};return R.validateZFXY(r)?r:null}}class A{constructor(e={}){this.provider=e.provider||"ouranos-gex",this.Space=null,this.fallbackMode=!1,this.loaded=!1}async loadProvider(){if(this.loaded)return!this.fallbackMode;if("ouranos-gex"!==this.provider)return d.warn(`SpatialIdAdapter: Unknown provider '${this.provider}', using built-in fallback`),this.fallbackMode=!0,this.loaded=!0,!1;try{const e=await Promise.resolve().then(function(){var e=new Error("Cannot find module 'ouranos-gex-lib-for-javascript'");throw e.code="MODULE_NOT_FOUND",e});return this.Space=e.Space,this.fallbackMode=!1,this.loaded=!0,d.info("SpatialIdAdapter: ouranos-gex loaded successfully"),!0}catch(e){return d.warn("SpatialIdAdapter: ouranos-gex not available, using built-in fallback",e.message),this.fallbackMode=!0,this.loaded=!0,!1}}neighbors(e){const{z:t,f:i,x:n,y:a}=e,o=Math.pow(2,t),r=[];for(let e=-1;e<=1;e++)for(let s=-1;s<=1;s++){if(0===s&&0===e)continue;const l=a+e;if(l<0||l>=o)continue;const h=(n+s+o)%o;r.push({z:t,f:i,x:h,y:l})}return r}children(e){const{z:t,f:i,x:n,y:a}=e,o=t+1,r=2*n,s=2*a,l=Math.pow(2,o),h=[];for(let e=0;e<=1;e++)for(let t=0;t<=1;t++){const n=(r+t)%l,a=s+e;a<0||a>=l||h.push({z:o,f:i,x:n,y:a})}return h}parent(e){const{z:t,f:i,x:n,y:a}=e;return t<=0?null:{z:t-1,f:i,x:Math.floor(n/2),y:Math.floor(a/2)}}getVoxelBounds(e,t,i,n){if(!this.loaded)throw new Error("SpatialIdAdapter: loadProvider() must be called before getVoxelBounds()");if(!this.Space||this.fallbackMode){const a=R.convert(e,t,i,n);return a.vertices=A._normalizeVertices(a.vertices),a}try{const a=new this.Space({lng:e,lat:t,alt:i},n),o="function"==typeof a.vertices3d?a.vertices3d():[],r=A._normalizeVertices(o);return{zfxy:a.zfxy,zfxyStr:a.zfxyStr,vertices:r}}catch(a){return d.warn("SpatialIdAdapter: ouranos-gex error, falling back to built-in converter",a.message),R.convert(e,t,i,n)}}calculateOptimalZoom(e,t,i=10){let n=25,a=1/0,o=null,r=1/0;for(let s=15;s<=30;s++){const l=this._calculateCellSizeAtZoom(s,t),h=Math.abs(l-e)/e;h<a&&(n=s,a=h),h<=i/100&&h<r&&(o=s,r=h)}const s=null!==o?o:n,l=this._calculateCellSizeAtZoom(s,t),h=Math.abs(l-e)/e*100;return d.debug(`SpatialIdAdapter: Optimal zoom ${s} for target size ${e}m (cell size: ${l.toFixed(1)}m, error: ${h.toFixed(1)}%)${null===o?" [closest, exceeds tolerance]":""}`),s}static _normalizeVertices(e){return Array.isArray(e)?e.map((e,t)=>{if(Array.isArray(e)){const[t,i,n]=e;return{lng:A._toNumber(t),lat:A._toNumber(i),alt:A._toNumber(n)}}if(e&&"object"==typeof e){const t=e.lng??e.lon??e.longitude,i=e.lat??e.latitude,n=e.alt??e.altitude??e.height;return{lng:A._toNumber(t),lat:A._toNumber(i),alt:A._toNumber(n)}}return d.warn("SpatialIdAdapter: Unexpected vertex format from provider",{index:t,vertex:e}),{lng:0,lat:0,alt:0}}):[]}static _toNumber(e){const t=Number(e);return Number.isFinite(t)?t:0}_calculateCellSizeAtZoom(e,t){const i=r,n=t*Math.PI/180;return i*Math.cos(n)/Math.pow(2,e)}getStatus(){return{provider:this.provider,loaded:this.loaded,fallbackMode:this.fallbackMode}}}function O(e,t=i.JulianDate.now()){if(null==e)return e;try{if("function"==typeof e.getValue)return e.getValue(t);if("function"==typeof e.get)return e.get(t)}catch(e){return}return e}function N(e){if(0===e.length)throw new Error("mean requires at least one data point");return function(e){if(0===e.length)return 0;var t,i=e[0],n=0;if("number"!=typeof i)return Number.NaN;for(var a=1;a<e.length;a++){if("number"!=typeof e[a])return Number.NaN;t=i+e[a],Math.abs(i)>=Math.abs(e[a])?n+=i-t+e[a]:n+=e[a]-t+i,i=t}return i+n}(e)/e.length}function V(e){if(1===e.length)return 0;var t=function(e){if(0===e.length)throw new Error("variance requires at least one data point");return function(e,t){var i,n,a=N(e),o=0;if(2===t)for(n=0;n<e.length;n++)o+=(i=e[n]-a)*i;else for(n=0;n<e.length;n++)o+=Math.pow(e[n]-a,t);return o}(e,2)/e.length}(e);return Math.sqrt(t)}function I(e){if(0===e.length)throw new Error("min requires at least one data point");for(var t=e[0],i=1;i<e.length;i++)e[i]<t&&(t=e[i]);return t}function F(e){if(0===e.length)throw new Error("max requires at least one data point");for(var t=e[0],i=1;i<e.length;i++)e[i]>t&&(t=e[i]);return t}function L(e,t){for(var i=[],n=0;n<e;n++){for(var a=[],o=0;o<t;o++)a.push(0);i.push(a)}return i}function k(e,t,i,n){var a;if(e>0){var o=(i[t]-i[e-1])/(t-e+1);a=n[t]-n[e-1]-(t-e+1)*o*o}else a=n[t]-i[t]*i[t]/(t+1);return a<0?0:a}function D(e,t,i,n,a,o,r){if(!(e>t)){var s=Math.floor((e+t)/2);n[i][s]=n[i-1][s-1],a[i][s]=s;var l=i;e>i&&(l=Math.max(l,a[i][e-1]||0)),l=Math.max(l,a[i-1][s]||0);var h,c,d,u=s-1;t<n[0].length-1&&(u=Math.min(u,a[i][t+1]||0));for(var p=u;p>=l&&!((h=k(p,s,o,r))+n[i-1][l-1]>=n[i][s]);--p)(c=k(l,s,o,r)+n[i-1][l-1])<n[i][s]&&(n[i][s]=c,a[i][s]=l),l++,(d=h+n[i-1][p-1])<n[i][s]&&(n[i][s]=d,a[i][s]=p);D(e,s-1,i,n,a,o,r),D(s+1,t,i,n,a,o,r)}}var $=function(){this.totalCount=0,this.data={}};$.prototype.train=function(e,t){for(var i in this.data[t]||(this.data[t]={}),e){var n=e[i];void 0===this.data[t][i]&&(this.data[t][i]={}),void 0===this.data[t][i][n]&&(this.data[t][i][n]=0),this.data[t][i][n]++}this.totalCount++},$.prototype.score=function(e){var t,i={};for(var n in e){var a=e[n];for(t in this.data)i[t]={},this.data[t][n]?i[t][n+"_"+a]=(this.data[t][n][a]||0)/this.totalCount:i[t][n+"_"+a]=0}var o={};for(t in i)for(var r in o[t]=0,i[t])o[t]+=i[t][r];return o};var E=function(){this.weights=[],this.bias=0};E.prototype.predict=function(e){if(e.length!==this.weights.length)return null;for(var t=0,i=0;i<this.weights.length;i++)t+=this.weights[i]*e[i];return(t+=this.bias)>0?1:0},E.prototype.train=function(e,t){if(0!==t&&1!==t)return null;e.length!==this.weights.length&&(this.weights=e,this.bias=1);var i=this.predict(e);if("number"==typeof i&&i!==t){for(var n=t-i,a=0;a<this.weights.length;a++)this.weights[a]+=n*e[a];this.bias+=n}return this},Math.log(Math.sqrt(2*Math.PI)),Math.sqrt(2*Math.PI);var T=Math.sqrt(2*Math.PI);function P(e){for(var t=e,i=e,n=1;n<15;n++)t+=i*=e*e/(2*n+1);return Math.round(1e4*(.5+t/T*Math.exp(-e*e/2)))/1e4}for(var W=[],B=0;B<=3.09;B+=.01)W.push(P(B));let j={quantile:(e,t)=>Array.isArray(e)&&0!==e.length?function(e,t){var i=e.length*t;if(0===e.length)throw new Error("quantile requires at least one data point.");if(t<0||t>1)throw new Error("quantiles must be between 0 and 1");return 1===t?e[e.length-1]:0===t?e[0]:i%1!=0?e[Math.ceil(i)-1]:e.length%2==0?(e[i-1]+e[i])/2:e[i]}([...e].sort((e,t)=>e-t),t):NaN,ckmeans(e,t){if(!Array.isArray(e)||0===e.length||!t||t<2)return[];try{return function(e,t){if(t>e.length)throw new Error("cannot generate more classes than there are data values");var i=function(e){return e.slice().sort(function(e,t){return e-t})}(e),n=function(e){for(var t,i=0,n=0;n<e.length;n++)0!==n&&e[n]===t||(t=e[n],i++);return i}(i);if(1===n)return[i];var a=L(t,i.length),o=L(t,i.length);!function(e,t,i){for(var n=t[0].length,a=e[Math.floor(n/2)],o=[],r=[],s=0,l=void 0;s<n;++s)l=e[s]-a,0===s?(o.push(l),r.push(l*l)):(o.push(o[s-1]+l),r.push(r[s-1]+l*l)),t[0][s]=k(0,s,o,r),i[0][s]=0;for(var h=1;h<t.length;++h)D(h<t.length-1?h:n-1,n-1,h,t,i,o,r)}(i,a,o);for(var r=[],s=o[0].length-1,l=o.length-1;l>=0;l--){var h=o[l][s];r[l]=i.slice(h,s+1),l>0&&(s=h-1)}return r}(e,t)}catch(e){return[]}},jenksBreaks(e,t){if(!Array.isArray(e)||0===e.length||!t||t<2)return[];const i="function"==typeof this?.ckmeans?this.ckmeans(e,t):[],n=[];for(let e=0;e<i.length-1;e++){const t=i[e];Array.isArray(t)&&t.length>0&&n.push(t[t.length-1])}return n},summary:e=>Array.isArray(e)&&0!==e.length?{min:I(e),max:F(e),mean:N(e),stddev:V(e)}:{min:NaN,max:NaN,mean:NaN,stddev:NaN}};function H(){return j}function U(e){if(e instanceof i.Color)return e;if(Array.isArray(e)){const[t,n,a,o=1]=e;return new i.Color(t,n,a,o)}return"string"==typeof e?i.Color.fromCssColorString(e):i.Color.WHITE.clone()}function Y(e={}){const{scheme:t="linear",values:n=null,domain:a=null,breaks:o=null,classes:r=5,thresholds:s=null,colorMap:l=null}=e,h=Math.max(2,r||2);let c,d=0,u=1;if(Array.isArray(a)&&2===a.length)[d,u]=a;else if(Array.isArray(n)&&n.length>0){const e=H().summary(n);d=e.min,u=e.max}u===d&&(u=d+1);let p=[];switch(t){case"linear":{const e=u-d||1;c=t=>(t-d)/e,p=[d,u];break}case"log":{d<=0&&(d=1);const e=Math.log(d),t=Math.log(u>d?u:d+1)-e||1;c=i=>i<=0?0:(Math.log(i)-e)/t,p=[d,u];break}case"equal-interval":if(Array.isArray(o)&&o.length>=2)p=[...o];else{p=[];for(let e=0;e<=h;e++)p.push(d+e/h*(u-d))}c=e=>{for(let t=0;t<p.length-1;t++){const i=p[t],n=p[t+1];if(e<=n)return(t+(e-i)/(n-i||1))/h}return 1};break;case"quantize":if(Array.isArray(o)&&o.length>=2)p=[...o];else{p=[];for(let e=0;e<=h;e++)p.push(d+e/h*(u-d))}c=e=>{for(let t=0;t<p.length-1;t++)if(e<=p[t+1])return t/(h-1);return 1};break;case"threshold":if(Array.isArray(o)&&o.length>=2)p=[...o];else{if(!Array.isArray(s)||0===s.length)throw new Error("threshold scheme requires thresholds array");p=[d,...s,u]}c=e=>{for(let t=0;t<p.length-1;t++)if(e<=p[t+1])return t/(p.length-2);return 1};break;case"quantile":if(Array.isArray(o)&&o.length>=2)p=[...o];else{if(!Array.isArray(n)||0===n.length)throw new Error("quantile scheme requires values array");{const e=H();p=[d];const t=Math.max(2,h);for(let i=1;i<t;i++)p.push(e.quantile(n,i/t));p.push(u)}}c=e=>{for(let t=0;t<p.length-1;t++)if(e<=p[t+1])return p.length>2?t/(p.length-2):0;return 1};break;case"jenks":if(Array.isArray(o)&&o.length>=2)p=[...o];else{if(!Array.isArray(n)||0===n.length)throw new Error("jenks scheme requires values array");{const e=H().jenksBreaks(n,h);if(p=[d],Array.isArray(e))for(const t of e)Number.isFinite(t)&&t>d&&t<u&&p.push(t);p.push(u)}}c=e=>{for(let t=0;t<p.length-1;t++)if(e<=p[t+1])return p.length>2?t/(p.length-2):0;return 1};break;default:throw new Error(`unknown classification scheme: ${t}`)}const m=function(e){if(!Array.isArray(e)||0===e.length)return null;if(e.every(e=>e&&"object"==typeof e&&Object.prototype.hasOwnProperty.call(e,"position")))return e;const t=e.length>1?e.length-1:1;return e.map((i,n)=>({position:1===e.length?0:n/t,color:i}))}(l),g=m?e=>function(e,t){if(!Array.isArray(e)||0===e.length)return i.Color.WHITE.clone();if(1===e.length)return U(e[0].color).clone();const n=Math.max(0,Math.min(1,t)),a=[...e].sort((e,t)=>e.position-t.position);if(n<=a[0].position)return U(a[0].color).clone();if(n>=a[a.length-1].position)return U(a[a.length-1].color).clone();for(let e=0;e<a.length-1;e++){const t=a[e],o=a[e+1];if(n>=t.position&&n<=o.position){const e=o.position-t.position||1,a=(n-t.position)/e,r=U(t.color),s=U(o.color);return i.Color.lerp(r,s,a,new i.Color)}}return U(a[a.length-1].color).clone()}(m,Math.max(0,Math.min(1,e))):e=>i.Color.lerp(i.Color.BLUE||new i.Color(0,0,1,1),i.Color.RED||new i.Color(1,0,0,1),Math.max(0,Math.min(1,e)),new i.Color),f="threshold"===t?Math.max(1,p.length>1?p.length-1:h):Math.max(1,h);let y;return y="threshold"===t?e=>{for(let t=0;t<p.length-1;t++)if(e<=p[t+1])return t;return p.length-2}:e=>{const t=Math.max(0,Math.min(1,c(e)));return Math.min(h-1,Math.floor(t*h))},{scheme:t,domain:[d,u],breaks:p,classes:"threshold"===t&&p.length>1?p.length-1:h,normalize:c,getColorForClass:e=>{const t=Number.isFinite(e)?Math.max(0,Math.min(f-1,Math.round(e))):0;return g(1===f?0:t/(f-1))},getColor:e=>g(Math.max(0,Math.min(1,e))),classify:y}}class X{static async classifyEntitiesIntoVoxels(e,t,n,a={}){if(a.spatialId?.enabled)return await X._classifyBySpatialId(e,t,n,a);const o=new Map;let r=0,s=0;const l=a.aggregation||{},h=Boolean(l.enabled),c=i.JulianDate.now(),u="string"==typeof l.byProperty&&""!==l.byProperty.trim()?l.byProperty.trim():null,p="function"==typeof l.keyResolver?l.keyResolver:null;let m=null;if(h&&(p||u?m=(e,t)=>{let i;if(p){try{i=p(e)}catch(e){return d.warn(`[aggregation] keyResolver threw error for entity ${t}, using "unknown"`,e),"unknown"}i=O(i,c)}else if(u){let t;try{const i=e.properties?.getValue?.(c);i&&"object"==typeof i&&u in i&&(t=i[u])}catch(e){d.warn(`[aggregation] Failed to resolve PropertyBag for ${u}, fallback to direct property`,e)}if(void 0===t){const i=e.properties?.[u];t=O(i,c)}i=t}if(null==i||"number"==typeof i&&Number.isNaN(i))return"unknown";const n=String(i);return""===n.trim()?"unknown":n}:(d.warn('[aggregation] enabled but no byProperty or keyResolver specified, using "default" key'),m=()=>"default")),d.debug(`Processing ${e.length} entities for classification`),e.forEach((e,a)=>{try{let l,d,u,p;if(e.position&&(l="function"==typeof e.position.getValue?e.position.getValue(c):e.position),!l)return void s++;if("number"==typeof l?.x&&"number"==typeof l?.y&&Math.abs(l.x)<=360&&Math.abs(l.y)<=90)d=l.x,u=l.y,p="number"==typeof l.z?l.z:0;else if(i.Cartographic&&"function"==typeof i.Cartographic.fromCartesian){const e=i.Cartographic.fromCartesian(l);if(!e)return void s++;d=i.Math.toDegrees(e.longitude),u=i.Math.toDegrees(e.latitude),p=e.height}else{if("number"!=typeof l.x||"number"!=typeof l.y)return void s++;d=l.x,u=l.y,p="number"==typeof l.z?l.z:0}if(d<t.minLon-.001||d>t.maxLon+.001||u<t.minLat-.001||u>t.maxLat+.001||p<t.minAlt-1||p>t.maxAlt+1)return void s++;const{x:g,y:f,z:y}=X._normalizeGridIndices(d,u,p,t,n);if(g>=0&&g<n.numVoxelsX&&f>=0&&f<n.numVoxelsY&&y>=0&&y<n.numVoxelsZ){const t=z.getVoxelKey(g,f,y);if(!o.has(t)){const e={x:g,y:f,z:y,entities:[],count:0};h&&(e.layerStats=new Map),o.set(t,e)}const i=o.get(t);if(i.entities.push(e),i.count++,h&&m){const t=m(e,a)||"unknown",n=i.layerStats.get(t)||0;i.layerStats.set(t,n+1)}r++}else s++}catch(e){d.warn(`エンティティ ${a} の処理に失敗:`,e),s++}}),h){for(const e of o.values())if(e.layerStats&&e.layerStats.size>0){let t=0,i=null;for(const[n,a]of e.layerStats)a>t&&(t=a,i=n);e.layerTop=i}d.debug(`[aggregation] Calculated layerTop for ${o.size} voxels`)}return d.info(`${r}個のエンティティを${o.size}個のボクセルに分類(${s}個はスキップ)`),o}static calculateStatistics(e,t,i={}){if(i._externalStats){d.debug("Using external statistics:",i._externalStats);const n=Number.isFinite(i._externalStats.minCount)?i._externalStats.minCount:Number.isFinite(i._externalStats.min)?i._externalStats.min:0,a=Number.isFinite(i._externalStats.maxCount)?i._externalStats.maxCount:Number.isFinite(i._externalStats.max)?i._externalStats.max:n,o={...i._externalStats,min:n,max:a,minCount:n,maxCount:a,totalVoxels:t.totalVoxels,renderedVoxels:0,nonEmptyVoxels:e.size,emptyVoxels:Math.max(0,t.totalVoxels-e.size),totalEntities:0};let r=0;for(const t of e.values())r+=t.count;return o.totalEntities=r,o.averageCount=e.size>0?r/e.size:0,o.classification||(o.classification=X._buildClassificationStats([],i.classification,o.minCount,o.maxCount),o.domain&&(o.classification.domain=o.domain)),o}if(0===e.size){const e={totalVoxels:t.totalVoxels,renderedVoxels:0,nonEmptyVoxels:0,emptyVoxels:t.totalVoxels,totalEntities:0,minCount:0,maxCount:0,averageCount:0,autoAdjusted:!1,originalVoxelSize:null,finalVoxelSize:null,adjustmentReason:null};return e.classification=X._buildClassificationStats([],i.classification,0,0),e}const n=Array.from(e.values()).map(e=>e.count),a=n.reduce((e,t)=>e+t,0),o=Math.max(0,t.totalVoxels-e.size),r={totalVoxels:t.totalVoxels,renderedVoxels:0,nonEmptyVoxels:e.size,emptyVoxels:o,totalEntities:a,minCount:Math.min(...n),maxCount:Math.max(...n),averageCount:a/e.size,autoAdjusted:!1,originalVoxelSize:null,finalVoxelSize:null,adjustmentReason:null};return r.classification=X._buildClassificationStats(n,i.classification,r.minCount,r.maxCount),d.debug("統計情報計算完了:",r),r}static _normalizeGridIndices(e,t,i,n,a){const o=(e,t,i,n)=>{const a=Number.isFinite(i-t)?i-t:0,o=Number.isFinite(e)?e:t,r=(e=>{const t=Number.isFinite(e)?Math.floor(e):0;return t>0?t:1})(n);if(0===a)return 0;const s=(o-t)/a,l=Math.floor(s*r),h=r-1,c=Number.isFinite(l)?l:0;return Math.max(0,Math.min(h,c))};return{x:o(e,n.minLon,n.maxLon,a.numVoxelsX),y:o(t,n.minLat,n.maxLat,a.numVoxelsY),z:o(i,n.minAlt,n.maxAlt,a.numVoxelsZ)}}static getTopNVoxels(e,t){if(0===e.size||t<=0)return[];const i=Array.from(e.values()).sort((e,t)=>t.count-e.count);return i.slice(0,Math.min(t,i.length))}static async _classifyBySpatialId(e,t,n,a){d.debug(`Spatial ID mode enabled: ${a.spatialId.mode}`);const o=new A({provider:a.spatialId.provider||"ouranos-gex"});let r;await o.loadProvider();const s=(t.minLat+t.maxLat)/2;if("auto"===a.spatialId.zoomControl){const e=a.voxelSize||30,t=a.spatialId.zoomTolerancePct||10;r=o.calculateOptimalZoom(e,s,t),d.info(`Auto-selected zoom level ${r} for target size ${e}m (lat: ${s.toFixed(4)}°)`)}else{const e=a.spatialId.zoom;"number"==typeof e&&Number.isFinite(e)&&e>=0&&e<=35?r=Math.floor(e):(r=25,d.warn(`Invalid zoom value in manual mode (${e}), using default zoom level ${r}`)),d.info(`Using manual zoom level ${r}`)}a._resolvedZoom=r,a._spatialIdProvider=o.fallbackMode?null:a.spatialId.provider;const l=a.aggregation||{},h=Boolean(l.enabled),c=i.JulianDate.now(),u="string"==typeof l.byProperty&&""!==l.byProperty.trim()?l.byProperty.trim():null,p="function"==typeof l.keyResolver?l.keyResolver:null;let m=null;h&&(p||u?m=(e,t)=>{let i;if(p){try{i=p(e)}catch(e){return d.warn(`[aggregation] keyResolver threw error for entity ${t}, using "unknown"`,e),"unknown"}i=O(i,c)}else if(u){let t;try{const i=e.properties?.getValue?.(c);i&&"object"==typeof i&&u in i&&(t=i[u])}catch(e){d.warn(`[aggregation] Failed to resolve PropertyBag for ${u}, fallback to direct property`,e)}if(void 0===t){const i=e.properties?.[u];t=O(i,c)}i=t}if(null==i||"number"==typeof i&&Number.isNaN(i))return"unknown";const n=String(i);return""===n.trim()?"unknown":n}:(d.warn('[aggregation] enabled but no byProperty or keyResolver specified, using "default" key'),m=()=>"default"));const g=new Map;let f=0,y=0,x=0;for(const a of e){try{let e,s,l,d;if(a.position&&(e="function"==typeof a.position.getValue?a.position.getValue(c):a.position),!e){y++;continue}if("number"==typeof e?.x&&"number"==typeof e?.y&&Math.abs(e.x)<=360&&Math.abs(e.y)<=90)s=e.x,l=e.y,d="number"==typeof e.z?e.z:0;else if(i.Cartographic&&"function"==typeof i.Cartographic.fromCartesian){const t=i.Cartographic.fromCartesian(e);if(!t){y++;continue}s=i.Math.toDegrees(t.longitude),l=i.Math.toDegrees(t.latitude),d=t.height}else{if("number"!=typeof e.x||"number"!=typeof e.y){y++;continue}s=e.x,l=e.y,d="number"==typeof e.z?e.z:0}const{zfxy:u,zfxyStr:p,vertices:v}=o.getVoxelBounds(s,l,d,r);if(!g.has(p)){const e=v.reduce((e,t)=>e+t.lng,0)/8,i=v.reduce((e,t)=>e+t.lat,0)/8,a=v.reduce((e,t)=>e+t.alt,0)/8,{x:o,y:r,z:s}=X._normalizeGridIndices(e,i,a,t,n),l={key:p,x:o,y:r,z:s,bounds:v,spatialId:{...u,id:p},entities:[],count:0};h&&(l.layerStats=new Map),g.set(p,l)}const b=g.get(p);if(b.entities.push(a),b.count++,h&&m){const e=m(a,x)||"unknown",t=b.layerStats.get(e)||0;b.layerStats.set(e,t+1)}f++}catch(e){d.warn("Failed to process entity for spatial ID:",e),y++}x++}if(h){for(const e of g.values())if(e.layerStats&&e.layerStats.size>0){let t=0,i=null;for(const[n,a]of e.layerStats)a>t&&(t=a,i=n);e.layerTop=i}d.debug(`[aggregation] Calculated layerTop for ${g.size} voxels (Spatial ID mode)`)}return d.info(`Spatial ID: ${f} entities classified into ${g.size} voxels (${y} skipped)`),g}static _buildClassificationStats(e,t={},i,n){const a=t&&"object"==typeof t?t:{},o=Boolean(a.enabled),r=(a.scheme||"linear").toLowerCase(),s=Math.max(2,a.classes||5);let l=null;if(Array.isArray(a.domain)&&2===a.domain.length){const[e,t]=a.domain;Number.isFinite(e)&&Number.isFinite(t)&&(l=[e,t])}if(!l){const e=Number.isFinite(i)?i:0;l=[e,Number.isFinite(n)?n:e]}const h=[...Array.isArray(e)?e.filter(e=>Number.isFinite(e)):[]].sort((e,t)=>e-t),c={enabled:o,scheme:r,domain:l,classes:a.classes??s,thresholds:a.thresholds??null,sampleSize:h.length,quantiles:null,histogram:null,breaks:null,jenksBreaks:null,ckmeansClusters:null};if(0===h.length)return c;try{const e=H();c.quantiles=[e.quantile(h,.25),e.quantile(h,.5),e.quantile(h,.75),e.quantile(h,1)]}catch(e){d.warn("Failed to compute quantiles for classification statistics:",e),c.quantiles=null}c.histogram=X._createHistogramFromSorted(h);const u=Math.min(Math.max(2,s),h.length);if(o&&"jenks"===r&&h.length>=2&&u>=2)try{const e=H(),t=e.jenksBreaks(h,u);if(c.jenksBreaks=Array.isArray(t)&&t.length>0?t:null,"function"==typeof e.ckmeans){const t=e.ckmeans(h,u);c.ckmeansClusters=Array.isArray(t)&&t.length>0?t:null}}catch(e){d.warn("Failed to compute jenks statistics:",e),c.jenksBreaks=null,c.ckmeansClusters=null}if(o)try{const e=Y({scheme:r,classes:a.classes,thresholds:a.thresholds,colorMap:a.colorMap,domain:l,values:h});c.breaks=e.breaks||null}catch(e){d.warn("Failed to build classifier for statistics:",e),c.breaks=null}return c}static _createHistogramFromSorted(e,t=10){if(!Array.isArray(e)||0===e.length)return null;const i=e[0],n=e[e.length-1];if(!Number.isFinite(i)||!Number.isFinite(n))return null;if(i===n)return{bins:[{start:i,end:n}],counts:[e.length]};const a=Math.max(1,Math.min(t,e.length)),o=(n-i)/a||1,r=[],s=new Array(a).fill(0);for(let e=0;e<a;e++){const t=i+o*e,s=e===a-1?n:t+o;r.push({start:t,end:s})}for(const t of e){if(!Number.isFinite(t))continue;let e=Math.floor((t-i)/o);e<0?e=0:e>=a&&(e=a-1),s[e]++}return{bins:r,counts:s}}}const q=Object.freeze({viridis:Object.freeze([[68,1,84],[72,40,120],[62,74,137],[49,104,142],[38,130,142],[31,158,137],[53,183,121],[109,205,89],[180,222,44],[253,231,37]]),inferno:Object.freeze([[0,0,4],[31,12,72],[85,15,109],[136,34,106],[186,54,85],[227,89,51],[249,142,8],[252,187,17],[245,219,76],[252,255,164]]),diverging:Object.freeze([[0,0,255],[32,64,255],[64,128,255],[96,160,255],[128,192,255],[160,224,255],[192,240,255],[224,248,255],[255,255,255],[255,248,224],[255,240,192],[255,224,160],[255,192,128],[255,160,96],[255,128,64],[255,64,32],[255,0,0]])});class Z{static calculateColor(e,t=null,n={}){try{Number.isFinite(e)||(d.warn(`Invalid normalizedDensity: ${e}. Using 0.5 as fallback.`),e=.5);const{minColor:i=[0,0,255],maxColor:a=[255,0,0],colorMap:o,diverging:r=!1,divergingPivot:s=0}=n;if(r&&null!==t){const e="number"==typeof s?s:0;return Z.calculateDivergingColor(t,{divergingPivot:e})}return o&&"custom"!==o?Z.interpolateFromColorMap(e,o):Z.interpolateLinear(e,i,a)}catch(e){return d.warn(`Color calculation failed: ${e.message}. Falling back to gray.`),i.Color.GRAY}}static interpolateLinear(e,t,n){const a=Math.max(0,Math.min(1,e)),[o,r,s]=t,[l,h,c]=n,d=Math.round(o+(l-o)*a),u=Math.round(r+(h-r)*a),p=Math.round(s+(c-s)*a);return i.Color.fromBytes(d,u,p)}static interpolateFromColorMap(e,t){const n=q[t];if(!n)return d.warn(`Unknown color map: ${t}. Falling back to linear interpolation.`),Z.interpolateLinear(e,[0,0,255],[255,0,0]);const a=Math.max(0,Math.min(1,e))*(n.length-1),o=Math.floor(a),r=Math.min(o+1,n.length-1),s=a-o,[l,h,c]=n[o],[u,p,m]=n[r],g=Math.round(l+(u-l)*s),f=Math.round(h+(p-h)*s),y=Math.round(c+(m-c)*s);return i.Color.fromBytes(g,f,y)}static calculateDivergingColor(e,t={}){const{divergingPivot:i=0}=t,n=i;let a;return 0===n?e<0?(a=1/(1-e)*.5,a=Math.max(0,Math.min(.5,a))):e>0?(a=.5+e/(1+e)*.5,a=Math.max(.5,Math.min(1,a))):a=.5:e<=n?(a=e/n*.5,a=Math.max(0,Math.min(.5,a))):(a=.5+(e-n)/n*.5,a=Math.max(.5,Math.min(1,a))),Z.interpolateFromColorMap(a,"diverging")}static getAvailableColorMaps(){return Object.keys(q)}static isValidColorMap(e){return Object.hasOwn(q,e)}}class J{constructor(e={}){this.options={renderLimitStrategy:"density",highlightTopN:0,coverageBinsXY:"auto",minCoverageRatio:.2,...e},this._lastSelectionStats=null,d.debug(`VoxelSelector initialized with strategy: ${this.options.renderLimitStrategy}`)}selectVoxels(e,t,i={}){try{if(!Array.isArray(e)||0===e.length)return d.warn("VoxelSelector: Empty or invalid voxel array provided"),this._createEmptyResult();if(t<=0)return d.warn(`VoxelSelector: Invalid maxCount: ${t}`),this._createEmptyResult();if(e.length<=t)return this._createResult(e,this.options.renderLimitStrategy,e.length,0);const{grid:n}=i,a=this.options.renderLimitStrategy||"density",o=this._identifyTopNVoxels(e);let r;switch(a){case"coverage":r=this._selectByCoverageStrategy(e,t,n,o);break;case"hybrid":r=this._selectByHybridStrategy(e,t,n,o);break;default:r=this._selectByDensityStrategy(e,t,o)}return this._lastSelectionStats={strategy:r.strategy,clippedNonEmpty:r.clippedNonEmpty,coverageRatio:r.coverageRatio||null,selectedCount:r.selectedVoxels.length,totalCount:e.length},d.debug(`VoxelSelector: Applied ${r.strategy} strategy - selected ${r.selectedVoxels.length}/${e.length} voxels`),r}catch(i){return d.error(`VoxelSelector: Selection failed: ${i.message}. Falling back to density strategy.`),this._fallbackToDensitySelection(e,t)}}getLastSelectionStats(){return this._lastSelectionStats}_identifyTopNVoxels(e){const t=new Set;if(this.options.highlightTopN&&this.options.highlightTopN>0){const i=[...e].sort((e,t)=>t.info.count-e.info.count).slice(0,this.options.highlightTopN);i.forEach(e=>t.add(e.key)),d.debug(`VoxelSelector: Identified ${i.length} TopN voxels for forced inclusion`)}return t}_selectByDensityStrategy(e,t,i=new Set){const n=[...e].sort((e,t)=>t.info.count-e.info.count),a=[],o=new Set;n.forEach(e=>{i.has(e.key)&&a.length<t&&(a.push(e),o.add(e.key))}),n.forEach(e=>{!o.has(e.key)&&a.length<t&&(a.push(e),o.add(e.key))});const r=e.length-a.length;return this._createResult(a,"density",a.length,r)}_selectByCoverageStrategy(e,t,i,n=new Set){const a=[],o=new Set;e.forEach(e=>{n.has(e.key)&&a.length<t&&(a.push(e),o.add(e.key))});const r="auto"===this.options.coverageBinsXY?Math.ceil(Math.sqrt(t/4)):this.options.coverageBinsXY,s=new Map;e.filter(e=>!o.has(e.key)).forEach(e=>{const t=`${Math.max(0,Math.min(r-1,Math.floor(e.info.x/Math.max(1,i.numVoxelsX)*r)))},${Math.max(0,Math.min(r-1,Math.floor(e.info.y/Math.max(1,i.numVoxelsY)*r)))}`;s.has(t)||s.set(t,[]),s.get(t).push(e)});const l=Array.from(s.keys());let h=0;for(;a.length<t&&h<10*l.length;){const e=l[h%l.length],t=s.get(e);if(t&&t.length>0){t.sort((e,t)=>t.info.count-e.info.count);const i=t.shift();o.has(i.key)||(a.push(i),o.add(i.key)),0===t.length&&(s.delete(e),l.splice(l.indexOf(e),1))}h++}const c=e.length-a.length;return this._createResult(a,"coverage",a.length,c)}_selectByHybridStrategy(e,t,i,n=new Set){const a=this.options.minCoverageRatio||.2,o=[],r=new Set;e.forEach(e=>{n.has(e.key)&&o.length<t&&(o.push(e),r.add(e.key))});const s=t-o.length,l=Math.floor(s*a),h=s-l;l>0&&this._selectByCoverageStrategy(e.filter(e=>!r.has(e.key)),l,i,new Set).selectedVoxels.forEach(e=>{o.length<t&&!r.has(e.key)&&(o.push(e),r.add(e.key))}),h>0&&this._selectByDensityStrategy(e.filter(e=>!r.has(e.key)),h,new Set).selectedVoxels.forEach(e=>{o.length<t&&!r.has(e.key)&&(o.push(e),r.add(e.key))});const c=l>0?(o.length-n.size-h)/(o.length-n.size):0,d=e.length-o.length;return this._createResult(o,"hybrid",o.length,d,c)}_fallbackToDensitySelection(e,t){try{const i=new Set,n=this._selectByDensityStrategy(e,t,i);return n.strategy="density-fallback",this._lastSelectionStats={strategy:n.strategy,clippedNonEmpty:n.clippedNonEmpty,coverageRatio:null,selectedCount:n.selectedVoxels.length,totalCount:e.length,error:!0},n}catch(e){return d.error(`VoxelSelector: Even fallback failed: ${e.message}`),this._createEmptyResult()}}_createResult(e,t,i,n,a=null){return{selectedVoxels:e,strategy:t,clippedNonEmpty:n,coverageRatio:a}}_createEmptyResult(){return{selectedVoxels:[],strategy:"none",clippedNonEmpty:0,coverageRatio:null}}}const G=n.adaptiveParams||{};class K{constructor(e={}){const t={...G,...e.adaptiveParams||{}};this.options={...e,adaptiveParams:t},d.debug("AdaptiveController initialized with options:",this.options)}calculateNeighborhoodDensity(e,t,i=null,n=null){if(!t||"function"!=typeof t.get)return{isDenseArea:!1,neighborhoodDensity:0,neighborCount:0};const{x:a,y:o,z:r}=e,s={...G,...this.options?.adaptiveParams||{},...n?.adaptiveParams||{}},l=s.neighborhoodRadius??G.neighborhoodRadius??30,h=null!==i?i:Math.max(1,Math.floor(l/20));let c=0,d=0;for(let e=-h;e<=h;e++)for(let i=-h;i<=h;i++)for(let n=-h;n<=h;n++){if(0===e&&0===i&&0===n)continue;const s=`${a+e},${o+i},${r+n}`,l=t.get(s);l&&(c+=l.count,d++)}const u=d>0?c/d:0;return{totalDensity:c,neighborCount:d,avgDensity:u,isDenseArea:u>(s.densityThreshold??G.densityThreshold??5),searchRadius:h}}_calculateZScaleCompensation(e,t){const i=this.options.adaptiveParams||G;if(!t||!i.zScaleCompensation)return 1;const{cellSizeX:n,cellSizeY:a,cellSizeZ:o}=t;if(!n||!a||!o)return 1;const r=o/((n+a)/2);return r<.1?Math.max(.7,Math.min(1.3,1+2*(.1-r))):1}_countAdjacentVoxels(e,t){if(!e||!t||"function"!=typeof t.get)return 0;const{x:i,y:n,z:a}=e,o=[[1,0,0],[-1,0,0],[0,1,0],[0,-1,0],[0,0,1],[0,0,-1]];let r=0;for(const[e,s,l]of o){const o=`${i+e},${n+s},${a+l}`;t.get(o)&&r++}return r}_detectOverlapAndRecommendMode(e,t,i=null){const n=i||this.options||{},a={...G,...this.options?.adaptiveParams||{},...i?.adaptiveParams||{}},o=n.outlineRenderMode||"standard",r=n.outlineInset||0;if(!a.overlapDetection)return{recommendedMode:o,recommendedInset:r};const s=this._countAdjacentVoxels(e,t)/6;return s>.5&&"emulation-only"!==o?{recommendedMode:"inset",recommendedInset:Math.max(.3,.8-.4*s),reason:`High overlap risk (${(100*s).toFixed(0)}%)`}:{recommendedMode:o,recommendedInset:r}}applyPresetLogic(e,t,i,n,a){let o,r,s;switch(e){case"thin":o=Math.max(1,.8*a.outlineWidth),r=a.opacity,s=a.outlineOpacity||.8;break;case"medium":case"uniform":default:o=a.outlineWidth,r=a.opacity,s=a.outlineOpacity||1;break;case"thick":o=Math.max(1,1.5*a.outlineWidth),r=a.opacity,s=a.outlineOpacity||1;break;case"adaptive":case"adaptive-density":{const e=n?Math.max(.6,.8+.3*(i-.5)):1;o=Math.max(1,Math.min(3*a.outlineWidth,a.outlineWidth*e)),r=n?.8*a.opacity:a.opacity,s=n?.6:1;break}case"topn-focus":o=t?Math.max(1,Math.min(3*a.outlineWidth,a.outlineWidth*(1.5+.5*i))):Math.max(1,.8*a.outlineWidth),r=t?a.opacity:.6*a.opacity,s=t?1:.4}return{adaptiveWidth:o,adaptiveBoxOpacity:r,adaptiveOutlineOpacity:s}}calculateAdaptiveParams(e,t,i,a,o,r=null,s=null){if(!e||!a||!o)return{outlineWidth:null,boxOpacity:null,outlineOpacity:null,shouldUseEmulation:!1};const l=o.classification||{},h=l.classificationTargets||n.classification.classificationTargets||{},c=Boolean(l.enabled&&s),u=(h.opacity||h.width)&&c;if(!o.adaptiveOutlines&&!u)return{outlineWidth:null,boxOpacity:null,outlineOpacity:null,shouldUseEmulation:!1};const{count:p}=e,m=a.maxCount>a.minCount?(p-a.minCount)/(a.maxCount-a.minCount):0;let g=null,f=null;if(c)try{g=Math.max(0,Math.min(1,s.normalize(p??0))),f=s.classify(p??0)}catch(e){d.warn("AdaptiveController classification normalize failed, fallback to density:",e),g=null}const y=null!==g?g:m,x=this.calculateNeighborhoodDensity(e,i,null,o),{isDenseArea:v}=x,b=this._calculateZScaleCompensation(e,r),M=this._detectOverlapAndRecommendMode(e,i,o),w={...G,...this.options?.adaptiveParams||{},...o?.adaptiveParams||{}},_=w.cameraDistanceFactor??1,S=w.overlapRiskFactor??0,C=Math.min(1,1)*_,z=v?S:0,R=this.applyPresetLogic(o.outlineWidthPreset,t,m,v,o),A=o&&o.adaptiveParams||w||{},O=(e,t,i=null)=>{if(Array.isArray(e)&&2===e.length){const[i,n]=e,a=(n??0)-(i??0);return(i??0)+Math.max(0,Math.min(1,t))*a}return i};let N=R.adaptiveWidth*C*b,V=Math.max(.2,R.adaptiveOutlineOpacity*(1-z));if(h.width&&c){const e=O(A.outlineWidthRange,y,N);null!=e&&(N=e+(t&&o.highlightTopN&&o.highlightTopNWidthBoost||0))}if(h.opacity&&c){const e=O(A.boxOpacityRange,y,R.adaptiveBoxOpacity),t=O(A.outlineOpacityRange,y,V);null!=e&&(R.adaptiveBoxOpacity=e),null!=t&&(V=t)}const I=(e,t,i,n)=>{let a=e;if(Array.isArray(t)&&2===t.length){const[e,o]=t,r=null!=e?e:i,s=null!=o?o:n;a=Math.min(s??a,Math.max(r??a,a))}return null!=i&&(a=Math.max(i,a)),null!=n&&(a=Math.min(n,a)),a};return{outlineWidth:I(Math.max(1,N),A.outlineWidthRange,w.minOutlineWidth??1,w.maxOutlineWidth??null),boxOpacity:I(Math.max(0,Math.min(1,R.adaptiveBoxOpacity)),A.boxOpacityRange,0,1),outlineOpacity:I(Math.max(.2,Math.min(1,V)),A.outlineOpacityRange,0,1),shouldUseEmulation:v||N>2&&"standard"!==o.outlineRenderMode,_debug:{normalizedDensity:m,classificationNormalized:g,classificationIndex:f,neighborhoodResult:x,cameraFactor:C,overlapRisk:z,zScaleFactor:b,overlapRecommendation:M,preset:o.outlineWidthPreset}}}updateOptions(e){this.options={...this.options,...e,adaptiveParams:{...this.options.adaptiveParams,...e.adaptiveParams||{}}},d.debug("AdaptiveController options updated:",this.options)}getConfiguration(){return{...this.options,version:"0.1.11",phase:"ADR-0009 Phase 3"}}}const Q={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","`":"&#96;"},ee=/[&<>"'`]/g;function te(e){return"string"!=typeof e?null==e?"":String(e):e.replace(ee,e=>Q[e]||e)}class ie{constructor(e,t={}){this.viewer=e,this.options={wireframeOnly:!1,showOutline:!0,outlineWidth:2,outlineInset:0,outlineInsetMode:"all",outlineRenderMode:"standard",enableThickFrames:!1,...t},this.entities=[],d.debug("GeometryRenderer initialized with viewer and options:",this.options)}createVoxelBox(e){const{centerLon:t,centerLat:n,centerAlt:a,cellSizeX:o,cellSizeY:r,boxHeight:s,color:l,opacity:h,shouldShowOutline:c,outlineColor:u,outlineWidth:p,voxelInfo:m,voxelKey:g,emulateThick:f=!1}=e,y=Number.isFinite(t)?Math.max(-180,Math.min(180,t)):0,x=Number.isFinite(n)?Math.max(-90,Math.min(90,n)):0,v=Number.isFinite(a)?Math.max(-1e4,Math.min(1e5,a)):0,b=Number.isFinite(o)&&o>0?Math.min(o,1e6):1,M=Number.isFinite(r)&&r>0?Math.min(r,1e6):1,w=Number.isFinite(s)&&s>0?Math.min(s,1e6):1;y===t&&x===n&&v===a&&b===o&&M===r&&w===s||d.warn(`Clamped invalid geometry values for voxel ${g}:`,{original:{centerLon:t,centerLat:n,centerAlt:a,cellSizeX:o,cellSizeY:r,boxHeight:s},clamped:{safeCenterLon:y,safeCenterLat:x,safeCenterAlt:v,safeCellSizeX:b,safeCellSizeY:M,safeBoxHeight:w}});const _=Boolean(c&&!f),S={dimensions:new i.Cartesian3(b,M,w),outline:_};_&&(S.outlineColor=u,S.outlineWidth=Math.max(p||1,1));const C={position:i.Cartesian3.fromDegrees(y,x,v),box:S,properties:{type:"voxel",key:g,count:m.count,x:m.x,y:m.y,z:m.z},description:this.createVoxelDescription(m,g)};if(m.spatialId&&(C.properties.spatialId=m.spatialId),m.layerTop&&(C.properties.layerTop=m.layerTop),m.layerStats){const e={};for(const[t,i]of m.layerStats)e[t]=i;C.properties.layerStats=e}this.options.wireframeOnly||"emulation-only"===this.options.outlineRenderMode?(C.box.material=i.Color.TRANSPARENT,C.box.fill=!1):(C.box.material=l.withAlpha(h),C.box.fill=!0);const z=this.viewer.entities.add(C);return this.entities.push(z),z}createInsetOutline(e){const{centerLon:t,centerLat:n,centerAlt:a,baseSizeX:o,baseSizeY:r,baseSizeZ:s,outlineColor:l,outlineWidth:h,voxelKey:c,insetAmount:u=null}=e,p=Number.isFinite(t)?Math.max(-180,Math.min(180,t)):0,m=Number.isFinite(n)?Math.max(-90,Math.min(90,n)):0,g=Number.isFinite(a)?Math.max(-1e4,Math.min(1e5,a)):0,f=Number.isFinite(o)&&o>0?Math.min(o,1e6):1,y=Number.isFinite(r)&&r>0?Math.min(r,1e6):1,x=Number.isFinite(s)&&s>0?Math.min(s,1e6):1,v=.2*f,b=.2*y,M=.2*x,w=null!==u?u:this.options.outlineInset,_=Math.min(w,v),S=Math.min(w,b),C=Math.min(w,M),z=Math.max(f-2*_,.1*f),R=Math.max(y-2*S,.1*y),A=Math.max(x-2*C,.1*x),O=this.viewer.entities.add({position:i.Cartesian3.fromDegrees(p,m,g),box:{dimensions:new i.Cartesian3(z,R,A),fill:!1,outline:!0,outlineColor:l,outlineWidth:Math.max(h||1,1)},properties:{type:"voxel-inset-outline",parentKey:c,insetSize:{x:z,y:R,z:A}}});return this.entities.push(O),this.options.enableThickFrames&&(_>.1||S>.1||C>.1)&&this.createThickOutlineFrames({centerLon:p,centerLat:m,centerAlt:g,outerX:f,outerY:y,outerZ:x,innerX:z,innerY:R,innerZ:A,frameColor:l,voxelKey:c}),d.debug(`Inset outline created for voxel ${c}:`,{originalSize:{x:o,y:r,z:s},insetSize:{x:z,y:R,z:A},effectiveInset:{x:_,y:S,z:C}}),O}createThickOutlineFrames(e){const{centerLon:t,centerLat:n,centerAlt:a,outerX:o,outerY:r,outerZ:s,innerX:l,innerY:h,innerZ:c,frameColor:u,voxelKey:p}=e;let m=(o-l)/2,g=(r-h)/2,f=(s-c)/2;const y=.05;if(m<=0||g<=0||f<=0)return d.warn(`Invalid frame thickness for voxel ${p}, skipping thick frames`),[];m=Math.max(m,y),g=Math.max(g,y),f=Math.max(f,y);const x=o/2,v=r/2,b=s/2,M=[],w=[{x,z:b,sizeX:m,sizeZ:f},{x:-x,z:b,sizeX:m,sizeZ:f},{x,z:-b,sizeX:m,sizeZ:f},{x:-x,z:-b,sizeX:m,sizeZ:f}],_=[{x,y:v,sizeX:m,sizeY:g},{x:-x,y:v,sizeX:m,sizeY:g},{x,y:-v,sizeX:m,sizeY:g},{x:-x,y:-v,sizeX:m,sizeY:g}];return[{y:v,z:b,sizeY:g,sizeZ:f},{y:-v,z:b,sizeY:g,sizeZ:f},{y:v,z:-b,sizeY:g,sizeZ:f},{y:-v,z:-b,sizeY:g,sizeZ:f}].forEach((e,r)=>{const s=i.Cartesian3.fromDegrees(t,n+e.y/111320,a+e.z),l=this.viewer.entities.add({position:s,box:{dimensions:new i.Cartesian3(o,e.sizeY,e.sizeZ),fill:!0,material:u.withAlpha(.3),outline:!1},properties:{type:"voxel-thick-frame-x",parentKey:p,frameIndex:r}});this.entities.push(l),M.push(l)}),w.forEach((e,o)=>{const s=i.Cartesian3.fromDegrees(t+e.x/(111320*Math.cos(n*Math.PI/180)),n,a+e.z),l=this.viewer.entities.add({position:s,box:{dimensions:new i.Cartesian3(e.sizeX,r,e.sizeZ),fill:!0,material:u.withAlpha(.3),outline:!1},properties:{type:"voxel-thick-frame-y",parentKey:p,frameIndex:o}});this.entities.push(l),M.push(l)}),_.forEach((e,o)=>{const r=i.Cartesian3.fromDegrees(t+e.x/(111320*Math.cos(n*Math.PI/180)),n+e.y/111320,a),l=this.viewer.entities.add({position:r,box:{dimensions:new i.Cartesian3(e.sizeX,e.sizeY,s),fill:!0,material:u.withAlpha(.3),outline:!1},properties:{type:"voxel-thick-frame-z",parentKey:p,frameIndex:o}});this.entities.push(l),M.push(l)}),d.debug(`Created ${M.length} thick frame entities for voxel ${p}`),M}createEdgePolylines(e){const{centerLon:t,centerLat:n,centerAlt:a,cellSizeX:o,cellSizeY:r,boxHeight:s,outlineColor:l,outlineWidth:h,outlineOpacity:c=null,voxelKey:u}=e,p=[],m=Number.isFinite(t)?Math.max(-180,Math.min(180,t)):0,g=Number.isFinite(n)?Math.max(-85,Math.min(85,n)):0,f=Number.isFinite(a)?Math.max(-1e4,Math.min(1e5,a)):0,y=Number.isFinite(o)&&o>0?Math.min(o,1e5):1,x=Number.isFinite(r)&&r>0?Math.min(r,1e5):1,v=Number.isFinite(s)&&s>0?Math.min(s,1e5):1;if(y<.001||x<.001||v<.001)return d.warn(`Dimensions too small for voxel ${u}, skipping edge polylines`),p;const b=y/2,M=x/2,w=v/2,_=Math.cos(g*Math.PI/180),S=b/(111320*Math.max(.1,Math.abs(_))),C=M/111320;if(!Number.isFinite(S)||!Number.isFinite(C)||Math.abs(S)>.1||Math.abs(C)>.1)return d.warn(`Coordinate offsets out of range for voxel ${u}, skipping edge polylines`),p;const z=[[m-S,g-C,f-w],[m+S,g-C,f-w],[m+S,g+C,f-w],[m-S,g+C,f-w],[m-S,g-C,f+w],[m+S,g-C,f+w],[m+S,g+C,f+w],[m-S,g+C,f+w]];if(!z.every(([e,t,i])=>Number.isFinite(e)&&Number.isFinite(t)&&Number.isFinite(i)&&e>=-180&&e<=180&&t>=-85&&t<=85&&i>=-5e4&&i<=5e5))return d.warn(`Invalid vertex coordinates for voxel ${u}, skipping edge polylines`),p;let R;try{R=z.map(([e,t,n])=>i.Cartesian3.fromDegrees(e,t,n))}catch(e){return d.warn(`Failed to create Cartesian3 vertices for voxel ${u}:`,e),p}return R.every(e=>e&&Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.z))?([[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]].forEach((e,t)=>{try{const i=R[e[0]],n=R[e[1]];if(!i||!n)return void d.warn(`Missing vertices for edge ${t} in voxel ${u}`);const a=[i,n];if(2!==a.length)return void d.warn(`Invalid positions array length for edge ${t} in voxel ${u}`);let o=l;if(null!=c&&"function"==typeof l?.withAlpha){const e=Math.max(0,Math.min(1,c));o=l.withAlpha(e)}const r=Number.isFinite(h)?h:1,s=this.viewer.entities.add({polyline:{positions:a,width:Math.max(Math.min(r,20),1),material:o,clampToGround:!1},properties:{type:"voxel-edge-polyline",parentKey:u,edgeIndex:t}});this.entities.push(s),p.push(s)}catch(e){d.warn(`Failed to create polyline for edge ${t} in voxel ${u}:`,e)}}),d.debug(`Created ${p.length} edge polylines for voxel ${u}`),p):(d.warn(`Generated vertices contain invalid values for voxel ${u}, skipping edge polylines`),p)}createVoxelDescription(e,t){const i=e.spatialId?`\n <tr><td><b>空間ID:</b></td><td>${te(e.spatialId.id)}</td></tr>\n <tr><td><b>ズームレベル:</b></td><td>Z=${te(String(e.spatialId.z))}, F=${te(String(e.spatialId.f))}</td></tr>\n <tr><td><b>タイル座標:</b></td><td>X=${te(String(e.spatialId.x))}, Y=${te(String(e.spatialId.y))}</td></tr>\n `:"";let n="";if(this.options.aggregation?.enabled&&!1!==this.options.aggregation?.showInDescription&&e.layerStats&&e.layerStats.size>0){const t=Array.from(e.layerStats.entries()).sort((e,t)=>t[1]-e[1]).map(([t,i])=>{const n=e.count>0?(i/e.count*100).toFixed(1):"0.0";return`\n <tr><td style="padding-left: 10px;">${te(t)}</td><td>${i} (${n}%)</td></tr>\n `}).join("");n=`\n ${e.layerTop?`\n <tr><td><b>支配的レイヤ:</b></td><td>${te(e.layerTop)}</td></tr>\n `:""}\n <tr><td colspan="2"><b>レイヤ内訳:</b></td></tr>\n ${t}\n `}return`\n <div style="padding: 10px; font-family: Arial, sans-serif;">\n <h3 style="margin-top: 0;">ボクセル [${e.x}, ${e.y}, ${e.z}]</h3>\n <table style="width: 100%;">\n <tr><td><b>エンティティ数:</b></td><td>${e.count}</td></tr>\n <tr><td><b>ボクセルキー:</b></td><td>${te(t)}</td></tr>\n <tr><td><b>座標:</b></td><td>X=${e.x}, Y=${e.y}, Z=${e.z}</td></tr>${i}${n}\n </table>\n <p style="margin-bottom: 0;">\n <small>v0.1.18 GeometryRenderer (Layer aggregation support)</small>\n </p>\n </div>\n `}shouldApplyInsetOutline(e){switch(this.options.outlineInsetMode||"all"){case"topn":return e;case"all":default:return!0;case"none":return!1}}clear(){d.debug("GeometryRenderer.clear - Removing",this.entities.length,"entities"),this.entities.forEach(e=>{try{const t=!(!e||"function"!=typeof e.isDestroyed)&&e.isDestroyed();e&&!t&&this.viewer.entities.remove(e)}catch(e){d.warn("Entity removal error:",e)}}),this.entities=[]}renderBoundingBox(e){if(e)try{const t=(e.minLon+e.maxLon)/2,n=(e.minLat+e.maxLat)/2,a=(e.minAlt+e.maxAlt)/2,o=111e3*(e.maxLon-e.minLon)*Math.cos(n*Math.PI/180),r=111e3*(e.maxLat-e.minLat),s=e.maxAlt-e.minAlt,l=this.viewer.entities.add({position:i.Cartesian3.fromDegrees(t,n,a),box:{dimensions:new i.Cartesian3(o,r,s),material:i.Color.YELLOW.withAlpha(.1),outline:!0,outlineColor:i.Color.YELLOW.withAlpha(.3),outlineWidth:2},description:`Bounding Box<br>Size: ${o.toFixed(1)} x ${r.toFixed(1)} x ${s.toFixed(1)} m`});this.entities.push(l),d.debug("Debug bounding box added:",{center:{lon:t,lat:n,alt:a},size:{width:o,depth:r,height:s}})}catch(e){d.warn("Failed to render bounding box:",e)}}getEntityCount(){return this.entities.length}updateOptions(e){this.options={...this.options,...e},d.debug("GeometryRenderer options updated:",this.options)}getConfiguration(){return{...this.options,entityCount:this.entities.length,version:"0.1.11",phase:"ADR-0009 Phase 4"}}}class ne{constructor(e,t={}){this.viewer=e,this.options={minColor:[0,0,255],maxColor:[255,0,0],opacity:.8,emptyOpacity:.03,showOutline:!0,showEmptyVoxels:!1,wireframeOnly:!1,heightBased:!1,outlineWidth:2,outlineInset:0,outlineInsetMode:"all",outlineRenderMode:"standard",emulationScope:"off",adaptiveOutlines:!1,outlineWidthPreset:"medium",...t},this.options.classification&&"object"==typeof this.options.classification||(this.options.classification={enabled:!1}),this.voxelSelector=new J(this.options),this._selectionStats=null,this.adaptiveController=new K(this.options),this.geometryRenderer=new ie(this.viewer,this.options),Object.defineProperty(this,"voxelEntities",{get:()=>this.geometryRenderer.entities,enumerable:!0,configurable:!0}),this._currentVoxelData=null,this._classifier=null,d.debug("VoxelRenderer initialized with options:",this.options)}_calculateAdaptiveParams(e,t,i,n,a){return this.adaptiveController.calculateAdaptiveParams(e,t,i,n,this.options,a,this._classifier)}_shouldApplyInsetOutline(e){return this.geometryRenderer.shouldApplyInsetOutline(e)}render(e,t,i,n){this.geometryRenderer.clear(),d.debug("VoxelRenderer.render - Starting render with simplified approach",{voxelDataSize:e.size,bounds:t,grid:i,statistics:n}),this._currentVoxelData=e,this._prepareClassifier(n),this._shouldShowBounds()&&this.geometryRenderer.renderBoundingBox(t);let a=[];const o=new Set;if(this.options.showEmptyVoxels){const t=Math.min(i.totalVoxels,this.options.maxRenderVoxels||1e4);d.debug(`Generating grid for up to ${t} voxels`);for(let n=0;n<i.numVoxelsX;n++){for(let o=0;o<i.numVoxelsY;o++){for(let r=0;r<i.numVoxelsZ;r++){const i=`${n},${o},${r}`,s=e.get(i)||{x:n,y:o,z:r,count:0};if(a.push({key:i,info:s}),a.length>=t){d.debug(`Reached maximum voxel limit of ${t}`);break}}if(a.length>=t)break}if(a.length>=t)break}}else if(a=Array.from(e.entries()).map(([e,t])=>({key:e,info:t})),this.options.maxRenderVoxels&&a.length>this.options.maxRenderVoxels){const e=this._selectVoxelsForRendering(a,this.options.maxRenderVoxels,t,i);a=e.selectedVoxels,this._selectionStats={strategy:e.strategy,clippedNonEmpty:e.clippedNonEmpty,coverageRatio:e.coverageRatio||0},d.debug(`Applied ${e.strategy} strategy: ${a.length} voxels selected, ${e.clippedNonEmpty} clipped`)}this.options.highlightTopN&&this.options.highlightTopN>0&&([...a].sort((e,t)=>t.info.count-e.info.count).slice(0,this.options.highlightTopN).forEach(e=>o.add(e.key)),d.debug(`TopN highlight enabled: ${o.size} voxels will be highlighted`)),d.debug(`Rendering ${a.length} voxels`);let r=0;const s={x:0,y:0,z:0,count:0},l={voxel:s,isTopN:!1,normalizedDensity:0,statistics:n,adaptiveParams:null},h={voxel:s,isTopN:!1,normalizedDensity:0,statistics:n,adaptiveParams:null};return a.forEach(({key:e,info:a})=>{try{r+=this._renderSingleVoxel(e,a,t,i,n,o,s,l,h)}catch(e){d.warn("Error rendering voxel:",e)}}),d.info(`Successfully rendered ${r} voxels`),this._currentVoxelData=null,r}_renderSingleVoxel(e,t,i,n,a,o,r,s,l){const h=o.has(e),c=this._calculateVoxelRenderingParams(t,i,n,a,h,r,s,l);return c?(this._delegateVoxelRendering(e,c),1):0}_calculateVoxelRenderingParams(e,t,n,a,o,r,s,l){if(!(e&&t&&n&&a))return null;let h,c,d,u,p,m;if(e.bounds&&Array.isArray(e.bounds)&&8===e.bounds.length){const t=e.bounds;h=t.reduce((e,t)=>e+t.lng,0)/8,c=t.reduce((e,t)=>e+t.lat,0)/8,d=t.reduce((e,t)=>e+t.alt,0)/8;const n=i.Cartesian3.fromDegrees(t[0].lng,t[0].lat,t[0].alt),a=i.Cartesian3.fromDegrees(t[1].lng,t[1].lat,t[1].alt),o=i.Cartesian3.fromDegrees(t[3].lng,t[3].lat,t[3].alt),r=i.Cartesian3.fromDegrees(t[4].lng,t[4].lat,t[4].alt);u=i.Cartesian3.distance(n,a),p=i.Cartesian3.distance(n,o),m=i.Cartesian3.distance(n,r)}else{const{x:i,y:a,z:o}=e;h=t.minLon+(i+.5)*(t.maxLon-t.minLon)/n.numVoxelsX,c=t.minLat+(a+.5)*(t.maxLat-t.minLat)/n.numVoxelsY,d=t.minAlt+(o+.5)*(t.maxAlt-t.minAlt)/n.numVoxelsZ,u=n.cellSizeX||(n.lonRangeMeters?n.lonRangeMeters/n.numVoxelsX:n.voxelSizeMeters),p=n.cellSizeY||(n.latRangeMeters?n.latRangeMeters/n.numVoxelsY:n.voxelSizeMeters),m=n.cellSizeZ||(n.altRangeMeters?Math.max(n.altRangeMeters/Math.max(n.numVoxelsZ,1),1):Math.max(n.voxelSizeMeters,1))}const g=a.maxCount>a.minCount?(e.count-a.minCount)/(a.maxCount-a.minCount):0,f=this._calculateAdaptiveParams(e,o,this._currentVoxelData,a,n),{color:y,opacity:x}=this._calculateColorAndOpacity(e,g,o,f,a,r,l);let v,b,M;if(e.bounds){v=u,b=p;let e=m;this.options.voxelGap>0&&(v=Math.max(u-this.options.voxelGap,.1*u),b=Math.max(p-this.options.voxelGap,.1*p),e=Math.max(m-this.options.voxelGap,.1*m)),M=e,this.options.heightBased&&(M=e*(.1+.9*g))}else{const e=this._calculateDimensions(n,g);v=e.cellSizeX,b=e.cellSizeY,M=e.boxHeight}return{centerLon:h,centerLat:c,centerAlt:d,cellSizeX:v,cellSizeY:b,boxHeight:M,color:y,opacity:x,...this._calculateOutlineProperties(e,o,g,f,a,y,r,s),voxelInfo:e,isTopN:o,adaptiveParams:f}}_calculateColorAndOpacity(e,t,n,a,o,r,s){let l,h;if(0===e.count)l=i.Color.LIGHTGRAY,h=this.options.emptyOpacity;else{const i=this.options.classification?.classificationTargets||{};if(this._classifier&&!1!==i.color)try{const t=this._classifier.classify(e.count??0);l=this._classifier.getColorForClass(t)}catch(i){d.warn("Classification color calculation failed, falling back to legacy color:",i),l=Z.calculateColor(t,e.count,this.options)}else l=Z.calculateColor(t,e.count,this.options);if(this.options.boxOpacityResolver&&"function"==typeof this.options.boxOpacityResolver){r.x=e.x,r.y=e.y,r.z=e.z,r.count=e.count,s.isTopN=n,s.normalizedDensity=t,s.adaptiveParams=a;try{const e=this.options.boxOpacityResolver(s);h=isNaN(e)?this.options.opacity:Math.max(0,Math.min(1,e))}catch(e){d.warn("boxOpacityResolver error, using fallback:",e),h=a.boxOpacity??this.options.opacity}}else h=a.boxOpacity??this.options.opacity;this.options.highlightTopN&&!n&&(h*=1-(this.options.highlightStyle?.boostOpacity||.2))}return{color:l,opacity:h}}_calculateDimensions(e,t){let i=e.cellSizeX||(e.lonRangeMeters?e.lonRangeMeters/e.numVoxelsX:e.voxelSizeMeters),n=e.cellSizeY||(e.latRangeMeters?e.latRangeMeters/e.numVoxelsY:e.voxelSizeMeters),a=e.cellSizeZ||(e.altRangeMeters?Math.max(e.altRangeMeters/Math.max(e.numVoxelsZ,1),1):Math.max(e.voxelSizeMeters,1));this.options.voxelGap>0&&(i=Math.max(i-this.options.voxelGap,.1*i),n=Math.max(n-this.options.voxelGap,.1*n),a=Math.max(a-this.options.voxelGap,.1*a));let o=a;return this.options.heightBased&&(o=a*(.1+.9*t)),{cellSizeX:i,cellSizeY:n,boxHeight:o}}_calculateOutlineProperties(e,t,i,n,a,o,r,s){let l;if(this.options.outlineWidthResolver&&"function"==typeof this.options.outlineWidthResolver){r.x=e.x,r.y=e.y,r.z=e.z,r.count=e.count,s.isTopN=t,s.normalizedDensity=i,s.adaptiveParams=n;try{l=this.options.outlineWidthResolver(s),isNaN(l)&&(l=n.outlineWidth||this.options.outlineWidth)}catch(e){d.warn("outlineWidthResolver error, using fallback:",e),l=n.outlineWidth||this.options.outlineWidth}}else l=null!==n.outlineWidth&&void 0!==n.outlineWidth?n.outlineWidth:t&&this.options.highlightTopN&&this.options.highlightStyle?.outlineWidth||this.options.outlineWidth;const h=n.outlineOpacity??this.options.outlineOpacity??1,c=o.withAlpha(h),u=this._determineRenderModeConfig();let p=u.shouldUseEmulationOnly;if(!u.shouldUseEmulationOnly){const e=this.options.emulationScope||"off";"topn"===e?p=t&&(l||1)>1:"non-topn"===e?p=!t&&(l||1)>1:"all"===e?p=(l||1)>1:this.options.adaptiveOutlines&&n.shouldUseEmulation&&(p="off"!==e)}return{shouldShowOutline:u.shouldShowStandardOutline,outlineColor:c,outlineWidth:l||1,shouldShowInsetOutline:u.shouldShowInsetOutline,emulateThick:p}}_determineRenderModeConfig(){let e=!0,t=!1,i=!1;switch(this.options.outlineRenderMode){case"standard":e=this.options.showOutline,t=this.options.outlineInset>0;break;case"inset":e=!1,t=!0;break;case"emulation-only":e=!1,t=!1,i=!0}return{shouldShowStandardOutline:e,shouldShowInsetOutline:t,shouldUseEmulationOnly:i}}_delegateVoxelRendering(e,t){if(this.geometryRenderer.createVoxelBox({centerLon:t.centerLon,centerLat:t.centerLat,centerAlt:t.centerAlt,cellSizeX:t.cellSizeX,cellSizeY:t.cellSizeY,boxHeight:t.boxHeight,color:t.color,opacity:t.opacity,shouldShowOutline:t.shouldShowOutline,outlineColor:t.outlineColor,outlineWidth:t.outlineWidth,voxelInfo:t.voxelInfo,voxelKey:e,emulateThick:t.emulateThick}),t.shouldShowInsetOutline&&this.geometryRenderer.shouldApplyInsetOutline(t.isTopN))try{const i=this.options.outlineInset>0?this.options.outlineInset:1;this.geometryRenderer.createInsetOutline({centerLon:t.centerLon,centerLat:t.centerLat,centerAlt:t.centerAlt,baseSizeX:t.cellSizeX,baseSizeY:t.cellSizeY,baseSizeZ:t.boxHeight,outlineColor:t.outlineColor,outlineWidth:Math.max(t.outlineWidth,1),voxelKey:e,insetAmount:i})}catch(e){d.warn("Failed to create inset outline:",e)}if(("emulation-only"===this.options.outlineRenderMode||this.options.emulationScope&&"off"!==this.options.emulationScope)&&t.emulateThick)try{const i=t.adaptiveParams?.outlineOpacity??t.outlineColor?.alpha??null;this.geometryRenderer.createEdgePolylines({centerLon:t.centerLon,centerLat:t.centerLat,centerAlt:t.centerAlt,cellSizeX:t.cellSizeX,cellSizeY:t.cellSizeY,boxHeight:t.boxHeight,outlineColor:t.outlineColor,outlineWidth:Math.max(t.outlineWidth,1),outlineOpacity:i,voxelKey:e})}catch(e){d.warn("Failed to add emulated thick outline polylines:",e)}}interpolateColor(e,t=null){return Z.calculateColor(e,t,this.options)}_prepareClassifier(e){const t=this.options.classification,i=e?.classification||null;if(!t||!t.enabled)return void(this._classifier=null);const n=(t.scheme||"linear").toLowerCase();if(!["linear","log","equal-interval","quantize","threshold","quantile","jenks"].includes(n))return d.warn(`Classification scheme '${n}' is not supported in v1.0.0. Disabling classification.`),void(this._classifier=null);const a=Array.isArray(t.domain)&&2===t.domain.length?t.domain:Array.isArray(i?.domain)&&2===i.domain.length?i.domain:[e?.minCount??e?.min??0,e?.maxCount??e?.max??0];let o=null;const r=Array.isArray(i?.breaks)&&i.breaks.length>=2;if(!r&&this._currentVoxelData&&this._currentVoxelData.size>0){o=[];for(const e of this._currentVoxelData.values())e&&Number.isFinite(e.count)&&o.push(e.count);0===o.length&&(o=null)}try{this._classifier=Y({scheme:n,classes:t.classes,thresholds:t.thresholds,colorMap:t.colorMap,domain:a,breaks:r?i.breaks:null,values:o})}catch(e){d.warn("Failed to initialize classifier:",e),this._classifier=null}}clear(){this.geometryRenderer.clear()}_shouldShowBounds(){return!!this.options.debug&&("boolean"==typeof this.options.debug?this.options.debug:"object"==typeof this.options.debug&&null!==this.options.debug&&!0===this.options.debug.showBounds)}setVisible(e){d.debug("VoxelRenderer.setVisible:",e),this.voxelEntities.forEach(t=>{!t||t.isDestroyed&&t.isDestroyed()||(t.show=e)})}_selectVoxelsForRendering(e,t,i,n){const a=this.voxelSelector.selectVoxels(e,t,{grid:n,bounds:i});return this._selectionStats=this.voxelSelector.getLastSelectionStats(),a}getSelectionStats(){return this._selectionStats||null}}class ae{constructor(e={}){this.options={position:"top-right",fpsAveragingWindowMs:1e3,autoUpdate:!0,...e},this.element=null,this.isVisible=!1,this.updateInterval=null,this.frameTimeHistory=[],this.lastUpdateTime=Date.now(),this._createOverlay()}_createOverlay(){this.element=document.createElement("div"),this.element.id="cesium-heatbox-perf-overlay",this.element.style.cssText=`\n position: absolute;\n ${this._getPositionStyles()}\n background: rgba(0, 0, 0, 0.8);\n color: #fff;\n padding: 10px;\n border-radius: 5px;\n font-family: 'Courier New', monospace;\n font-size: 12px;\n line-height: 1.4;\n z-index: 1000;\n min-width: 200px;\n user-select: none;\n pointer-events: auto;\n display: none;\n `;const e=document.createElement("button");e.textContent="×",e.style.cssText="\n position: absolute;\n top: 2px;\n right: 5px;\n background: none;\n border: none;\n color: #fff;\n font-size: 16px;\n cursor: pointer;\n padding: 0;\n width: 20px;\n height: 20px;\n ",e.onclick=()=>this.hide(),this.element.appendChild(e),this.contentElement=document.createElement("div"),this.contentElement.style.marginTop="15px",this.element.appendChild(this.contentElement),document.body.appendChild(this.element)}_getPositionStyles(){const e={"top-left":"top: 10px; left: 10px;","top-right":"top: 10px; right: 10px;","bottom-left":"bottom: 10px; left: 10px;","bottom-right":"bottom: 10px; right: 10px;"};return e[this.options.position]||e["top-right"]}show(){this.element&&(this.element.style.display="block",this.isVisible=!0,this.options.autoUpdate&&this.startAutoUpdate())}hide(){this.element&&(this.element.style.display="none",this.isVisible=!1,this.stopAutoUpdate())}toggle(){this.isVisible?this.hide():this.show()}update(e,t){if(!this.contentElement||!this.isVisible)return;void 0!==t&&this._trackFrameTime(t);const i=this._calculateFPS(),n=this._formatStats(e,i,t);this.contentElement.innerHTML=n}_trackFrameTime(e){const t=Date.now();this.frameTimeHistory.push({time:t,frameTime:e});const i=t-this.options.fpsAveragingWindowMs;this.frameTimeHistory=this.frameTimeHistory.filter(e=>e.time>i)}_calculateFPS(){if(this.frameTimeHistory.length<2)return 0;const e=this.frameTimeHistory.reduce((e,t)=>e+t.frameTime,0)/this.frameTimeHistory.length;return e>0?Math.round(1e3/e):0}_formatStats(e,t,i){const n=[];if(n.push('<div style="font-weight: bold; color: #4CAF50;">🚀 Performance Stats</div>'),n.push(""),t>0){const e=t>=30?"#4CAF50":t>=15?"#FF9800":"#F44336";n.push(`<div style="color: ${e};">FPS: ${t}</div>`)}if(void 0!==i){const e=i<=33?"#4CAF50":i<=66?"#FF9800":"#F44336";n.push(`<div style="color: ${e};">Frame: ${i.toFixed(1)}ms</div>`)}if(n.push(""),e){if(n.push('<div style="font-weight: bold;">Voxels:</div>'),n.push(` Total: ${e.totalVoxels||0}`),n.push(` Rendered: ${e.renderedVoxels||0}`),e.totalVoxels>0){const t=((e.renderedVoxels||0)/e.totalVoxels*100).toFixed(1);n.push(` Ratio: ${t}%`)}if(e.topNCount&&n.push(` TopN: ${e.topNCount}`),n.push(""),e.selectionStrategy&&(n.push('<div style="font-weight: bold;">Strategy:</div>'),n.push(` Selection: ${e.selectionStrategy}`),void 0!==e.coverageRatio&&n.push(` Coverage: ${(100*e.coverageRatio).toFixed(1)}%`),e.renderBudgetTier&&n.push(` Budget Tier: ${e.renderBudgetTier}`),n.push("")),e.adaptive){if(n.push('<div style="font-weight: bold; color: #2196F3;">📊 Adaptive Control:</div>'),void 0!==e.adaptive.denseModeCount){const t=e.renderedVoxels>0?(e.adaptive.denseModeCount/e.renderedVoxels*100).toFixed(1):"0.0";n.push(` Dense Areas: ${e.adaptive.denseModeCount} (${t}%)`)}if(void 0!==e.adaptive.emulationModeCount){const t=e.renderedVoxels>0?(e.adaptive.emulationModeCount/e.renderedVoxels*100).toFixed(1):"0.0";n.push(` Emulation: ${e.adaptive.emulationModeCount} (${t}%)`)}if(void 0!==e.adaptive.avgOutlineWidth){const t=e.adaptive.avgOutlineWidth>=1&&e.adaptive.avgOutlineWidth<=3?"#4CAF50":"#FF9800";n.push(` <span style="color: ${t};">Avg Width: ${e.adaptive.avgOutlineWidth.toFixed(2)}px</span>`)}if(void 0!==e.adaptive.overlapDetections){const t=e.renderedVoxels>0?(e.adaptive.overlapDetections/e.renderedVoxels*100).toFixed(1):"0.0",i=e.adaptive.overlapDetections>0?"#FF9800":"#4CAF50";n.push(` <span style="color: ${i};">Overlaps: ${e.adaptive.overlapDetections} (${t}%)</span>`)}void 0!==e.adaptive.zScaleAdjustments&&e.adaptive.zScaleAdjustments>0&&n.push(` Z-Scale Adj: ${e.adaptive.zScaleAdjustments}`),n.push("")}if(void 0!==e.renderTimeMs){const t=e.renderTimeMs<=50?"#4CAF50":e.renderTimeMs<=100?"#FF9800":"#F44336";n.push(`<div style="color: ${t};">Render Time: ${e.renderTimeMs.toFixed(1)}ms</div>`)}if(void 0!==e.memoryUsageMB){const t=e.memoryUsageMB<=50?"#4CAF50":e.memoryUsageMB<=100?"#FF9800":"#F44336";n.push(`<div style="color: ${t};">Memory: ${e.memoryUsageMB.toFixed(1)}MB</div>`)}}return n.join("<br>")}startAutoUpdate(){this.stopAutoUpdate(),this.updateInterval=setInterval(()=>{},100)}stopAutoUpdate(){this.updateInterval&&(clearInterval(this.updateInterval),this.updateInterval=null)}destroy(){this.stopAutoUpdate(),this.element&&this.element.parentNode&&this.element.parentNode.removeChild(this.element),this.element=null,this.contentElement=null}}function oe(e){if(!e)return"rgba(0,0,0,0)";if("string"==typeof e)return e;if("function"==typeof e.toCssHexString)return e.toCssHexString();if("function"==typeof e.toCssColorString)return e.toCssColorString();if("function"==typeof e.withAlpha){const t=e.withAlpha(1);if(t&&"function"==typeof t.toCssColorString)return t.toCssColorString()}return`rgba(${Math.min(255,Math.max(0,Math.round(255*(e.red??0))))}, ${Math.min(255,Math.max(0,Math.round(255*(e.green??0))))}, ${Math.min(255,Math.max(0,Math.round(255*(e.blue??0))))}, ${Math.min(1,Math.max(0,e.alpha??1))})`}class re{constructor(e={}){this.document=e.documentRef||("undefined"!=typeof document?document:null),this.container=e.container||null,this._ownsContainer=!1,this._classifier=null,this._classificationOptions=null,this.document&&(this.container||(this.container=this.document.createElement("div"),this.container.className="heatbox-legend",this.document.body.appendChild(this.container),this._ownsContainer=!0))}render(e,t={}){if(!this.container||!this.document)return null;this._classifier=e,this._classificationOptions=t,this.container.innerHTML="",this.container.style.padding="8px",this.container.style.background="rgba(0,0,0,0.6)",this.container.style.color="#fff",this.container.style.fontSize="12px",this.container.style.borderRadius="4px",this.container.style.maxWidth="240px";const i=this.document.createElement("div");if(i.textContent="Legend",i.style.fontWeight="bold",i.style.marginBottom="6px",this.container.appendChild(i),!e){const e=this.document.createElement("div");return e.textContent="分類が有効ではありません",this.container.appendChild(e),this.container}const n=t.classificationTargets||{},a=Object.entries(n).filter(([,e])=>!1!==e).map(([e])=>e);if(a.length>0){const e=this.document.createElement("div");e.textContent=`Targets: ${a.join(", ")}`,e.style.marginBottom="4px",this.container.appendChild(e)}const o=this.document.createElement("div");o.style.display="flex",o.style.flexDirection="column",o.style.gap="4px";const r=e.breaks||[],s=e.classes??(r.length>1?r.length-1:0);for(let t=0;t<s;t++){const i=this.document.createElement("div");i.className="heatbox-legend-item",i.style.display="flex",i.style.alignItems="center",i.style.gap="6px";const n=this.document.createElement("span");n.className="heatbox-legend-swatch",n.style.display="inline-block",n.style.width="12px",n.style.height="12px",n.style.borderRadius="2px",n.style.border="1px solid rgba(255,255,255,0.3)",n.style.background=oe(e.getColorForClass(t));const a=this.document.createElement("span");let s=`Class ${t+1}`;r.length>t+1&&(s=`${r[t]} - ${r[t+1]}`),a.textContent=s,i.appendChild(n),i.appendChild(a),o.appendChild(i)}return this.container.appendChild(o),this.container}update(e,t){return this.render(e??this._classifier,t??this._classificationOptions)}destroy(){this.container&&this._ownsContainer&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=null,this.document=null}}class se{constructor(e,t={}){this._options=t,this._entries=this._normalizeAndSort(e),this._currentIndex=0,this._currentEntry=null,this._globalStatsCache={},this._searchCount=0,this._cacheHits=0}_normalizeAndSort(e){if(!Array.isArray(e)||0===e.length)throw new Error("Temporal data must be a non-empty array");const t=e.map((e,t)=>{if(!e.start||!e.stop||!e.data)throw new Error(`Invalid entry at index ${t}: missing start, stop, or data`);const n=this._toJulianDate(e.start),a=this._toJulianDate(e.stop);if(i.JulianDate.greaterThan(n,a))throw new Error(`Invalid time range at index ${t}: start > stop`);return i.JulianDate.equals(n,a)&&i.JulianDate.addSeconds(n,1,a),{start:n,stop:a,data:e.data}});t.sort((e,t)=>i.JulianDate.compare(e.start,t.start));const n=this._options.overlapResolution||"prefer-earlier";return"skip"===n?(this._validateNoOverlap(t),t):"prefer-earlier"===n?this._resolvePreferEarlier(t):"prefer-later"===n?this._resolvePreferLater(t):t}_toJulianDate(e){if(e instanceof i.JulianDate)return e;if("string"==typeof e)return i.JulianDate.fromIso8601(e);if(e instanceof Date)return i.JulianDate.fromDate(e);if("number"==typeof e)return i.JulianDate.fromDate(new Date(1e3*e));throw new Error("Unsupported time format: "+typeof e)}_validateNoOverlap(e){for(let t=0;t<e.length-1;t++){const n=e[t],a=e[t+1];if(i.JulianDate.greaterThan(n.stop,a.start))throw new Error(`Data overlap detected: entry ${t} stops at ${n.stop}, but entry ${t+1} starts at ${a.start}`)}}_resolvePreferEarlier(e){const t=[];for(const n of e){const e=t[t.length-1];if(e){if(i.JulianDate.greaterThan(e.stop,n.start)){if(i.JulianDate.greaterThanOrEquals(e.stop,n.stop))continue;if(n.start=i.JulianDate.clone(e.stop),!i.JulianDate.lessThan(n.start,n.stop))continue}t.push(n)}else t.push(n)}return t}_resolvePreferLater(e){const t=[];for(const n of e){for(;t.length>0;){const e=t[t.length-1];if(!i.JulianDate.greaterThan(e.stop,n.start))break;if(i.JulianDate.lessThan(n.start,e.start)||i.JulianDate.equals(n.start,e.start))t.pop();else{if(e.stop=i.JulianDate.clone(n.start),i.JulianDate.lessThan(e.start,e.stop))break;t.pop()}}t.push(n)}return t}getEntry(e){if(this._searchCount++,this._currentEntry&&i.JulianDate.greaterThanOrEquals(e,this._currentEntry.start)&&i.JulianDate.lessThan(e,this._currentEntry.stop))return this._cacheHits++,this._currentEntry;const t=[this._currentIndex,this._currentIndex+1,this._currentIndex-1];for(const i of t)if(i>=0&&i<this._entries.length){const t=this._entries[i];if(this._isInRange(e,t))return this._currentIndex=i,this._currentEntry=t,t}const n=this._binarySearch(e);return n>=0?(this._currentIndex=n,this._currentEntry=this._entries[n],this._currentEntry):(this._currentEntry=null,null)}_isInRange(e,t){return i.JulianDate.greaterThanOrEquals(e,t.start)&&i.JulianDate.lessThan(e,t.stop)}_binarySearch(e){let t=0,n=this._entries.length-1;for(;t<=n;){const a=Math.floor((t+n)/2),o=this._entries[a];if(this._isInRange(e,o))return a;i.JulianDate.lessThan(e,o.start)?n=a-1:t=a+1}return-1}calculateGlobalStats(e="weight",t=null){const i=JSON.stringify({valueProperty:e,classification:t||null});if(this._globalStatsCache[i])return this._globalStatsCache[i];let n=1/0,a=-1/0,o=0,r=0;const s=[];for(const t of this._entries)if(Array.isArray(t.data))for(const i of t.data){const t=i[e]??1;"number"==typeof t&&(n=Math.min(n,t),a=Math.max(a,t),o+=t,r++,s.push(t))}if(0===r)return null;const l=o/r;s.sort((e,t)=>e-t);const h={min:n,max:a,minCount:n,maxCount:a,mean:l,median:this._calculateMedian(s),quantiles:this._calculateQuantiles(s,[.25,.5,.75]),domain:[n,a],count:r};return t&&t.enabled&&(h.classification=X._buildClassificationStats(s,t,n,a)),this._globalStatsCache[i]=h,h}_calculateMedian(e){if(0===e.length)return 0;const t=Math.floor(e.length/2);return e.length%2==0?(e[t-1]+e[t])/2:e[t]}_calculateQuantiles(e,t){return t.map(t=>{const i=Math.floor(e.length*t);return e[Math.min(i,e.length-1)]})}getCacheHitRate(){return this._searchCount>0?this._cacheHits/this._searchCount:0}getTimeRange(){return 0===this._entries.length?null:{start:this._entries[0].start,stop:this._entries[this._entries.length-1].stop}}}class le{constructor(e,t,i){this._viewer=e,this._heatbox=t,this._options=i,this._slicer=new se(i.data,i),this._lastUpdateTime=null,this._lastEntry=null,this._removeListener=null,this._isActive=!1}activate(){if(!this._isActive){if(this._isActive=!0,"global"===this._options.classificationScope){const e=this._heatbox.options||{},t=e.valueProperty||"weight",i=this._slicer.calculateGlobalStats(t,e.classification||null);this._heatbox._globalStats=i}this._removeListener=this._viewer.clock.onTick.addEventListener(this._onTick.bind(this)),this._onTick(this._viewer.clock)}}deactivate(){this._isActive&&(this._isActive=!1,this._removeListener&&(this._removeListener(),this._removeListener=null))}_onTick(e){const t=e.currentTime;if(!this._shouldUpdate(t))return;const i=this._slicer.getEntry(t);null!==i&&i===this._lastEntry||(this._lastEntry=i,this._updateHeatbox(i))}_shouldUpdate(e){const t=this._options.updateInterval;if("frame"===t||!t)return!0;const i=Date.now();return(null===this._lastUpdateTime||i-this._lastUpdateTime>=t)&&(this._lastUpdateTime=i,!0)}_updateHeatbox(e){if(!e)return void("clear"===this._options.outOfRangeBehavior&&this._heatbox.clear());const t={_skipRebuild:!1};"global"===this._options.classificationScope&&this._heatbox._globalStats&&(t._externalStats=this._heatbox._globalStats),this._heatbox.setData(e.data,t)}}class he{constructor(e,t={}){if(!function(e){if(!e)return!1;if(!e.scene||!e.entities||!e.scene.canvas)return!1;const t=e.scene.canvas;return!!(t.getContext("webgl2")||t.getContext("webgl")||t.getContext("experimental-webgl"))}(e))throw new Error("CesiumJS Viewerが無効です");this.viewer=e;let i={...t||{}};i.profile&&g().includes(i.profile)&&(i=y(i.profile,i),delete i.profile);const o={...n,...i};this.options=M(function(e){if("auto"!==e.renderBudgetMode&&"auto"!==e.maxRenderVoxels)return e;const t=function(){try{const e=function(){try{const e=document.createElement("canvas"),t=e.getContext("webgl2")||e.getContext("webgl");if(!t)return{webgl2:!1,maxTextureSize:0,maxRenderbufferSize:0};const i={webgl2:!!e.getContext("webgl2"),maxTextureSize:t.getParameter(t.MAX_TEXTURE_SIZE),maxRenderbufferSize:t.getParameter(t.MAX_RENDERBUFFER_SIZE)};return e.remove(),i}catch(e){return d.warn("WebGL info detection failed:",e),{webgl2:!1,maxTextureSize:0,maxRenderbufferSize:0}}}(),t=function(){try{return{deviceMemory:navigator.deviceMemory||null,hardwareConcurrency:navigator.hardwareConcurrency||null,devicePixelRatio:window.devicePixelRatio||1,screenPixels:screen.width*screen.height*Math.pow(window.devicePixelRatio||1,2),userAgent:navigator.userAgent}}catch(e){return d.warn("Device info detection failed:",e),{deviceMemory:null,hardwareConcurrency:null,devicePixelRatio:1,screenPixels:2073600,userAgent:""}}}();let i="mid",n="fallback";if(null!==t.deviceMemory)i=t.deviceMemory<=4?"low":t.deviceMemory<=8?"mid":"high",n="deviceMemory";else if(null!==t.hardwareConcurrency){const e=t.hardwareConcurrency*Math.min(t.screenPixels/2073600,2);i=e<=4?"low":e<=8?"mid":"high",n="hardwareConcurrency+resolution"}(e.maxTextureSize<4096||!e.webgl2)&&(i="high"===i?"mid":"low",n+="+webglLimits");const o=S[i];let r=Math.min(Math.floor((o.min+o.max)/2),a);try{const e=navigator&&navigator.userAgent?navigator.userAgent:"",t=/iPhone|iPad|iPod|Android/i.test(e),i=/Safari\//.test(e)&&!/Chrome\//.test(e);(t||i)&&(r=Math.min(r,12e3))}catch(e){}return d.debug(`Device tier detected: ${i} (${n}), maxRenderVoxels: ${r}`),{tier:i,maxRenderVoxels:r,detectionMethod:n,deviceInfo:t,webglInfo:e}}catch(e){return d.warn("Device tier detection failed, using default mid tier:",e),{tier:"mid",maxRenderVoxels:Math.min(25e3,a),detectionMethod:"error-fallback",deviceInfo:null,webglInfo:null}}}(),i={...e,maxRenderVoxels:t.maxRenderVoxels,_autoRenderBudget:{tier:t.tier,detectionMethod:t.detectionMethod,autoMaxRenderVoxels:t.maxRenderVoxels}};return d.info(`Auto Render Budget applied: ${t.tier} tier, maxRenderVoxels: ${t.maxRenderVoxels}`),i}(o)),d.setLogLevel(this.options),this.renderer=new ne(this.viewer,this.options),this._bounds=null,this._grid=null,this._voxelData=null,this._statistics=null,this._spatialIdEdgeCaseMetrics=null,this._eventHandler=null,this._performanceOverlay=null,this._lastRenderTime=null,this._overlayLastUpdate=0,this._postRenderListener=null,this._prevFrameTimestamp=null,this._postRenderListener=null,this._prevFrameTimestamp=null,this._legend=null,this._timeController=null,this._timeControllerSignature=null,this._initializeEventListeners(),this.options.performanceOverlay&&this.options.performanceOverlay.enabled&&this._initializePerformanceOverlay(),this.options.temporal&&this.options.temporal.enabled&&this._initializeTimeController()}getEffectiveOptions(){try{return JSON.parse(JSON.stringify(this.options))}catch(e){return{...this.options}}}static listProfiles(){return g()}static getProfileDetails(e){return f(e)}_initializePerformanceOverlay(){if("undefined"==typeof window)return void d.warn("Performance overlay requires browser environment");const e={position:"top-right",fpsAveragingWindowMs:1e3,autoUpdate:!0,updateIntervalMs:500,...this.options.performanceOverlay};this._performanceOverlay=new ae(e),e.autoShow&&this._performanceOverlay.show(),d.debug("Performance overlay initialized"),this._hookPerformanceOverlayUpdates()}_initializeTimeController(){try{this._timeController=new le(this.viewer,this,this.options.temporal),this._timeController.activate(),this._timeControllerSignature=this._serializeTemporalOptions(this.options.temporal),d.info("TimeController initialized and activated")}catch(e){this._timeController=null,this._timeControllerSignature=null,d.error("Failed to initialize TimeController:",e)}}_teardownTimeController(){if(this._timeController){try{this._timeController.deactivate()}catch(e){d.debug("timeController deactivate failed (non-fatal)",e)}this._timeController=null,this._timeControllerSignature=null}}_syncTimeController(e,t,i){const n=!(!e||!e.enabled),a=!(!t||!t.enabled);if(n||!a)if(!n||a){if(a&&i){const e=this._serializeTemporalOptions(t);this._timeControllerSignature!==e&&(this._teardownTimeController(),this._initializeTimeController())}}else this._teardownTimeController();else this._initializeTimeController()}_serializeTemporalOptions(e){if(!e)return null;try{return JSON.stringify(e,(e,t)=>"function"==typeof t?`[Function:${t.name||"anonymous"}]`:t)}catch(e){return d.debug("Failed to serialize temporal options for comparison",e),null}}togglePerformanceOverlay(){return this._performanceOverlay?(this._performanceOverlay.toggle(),this._performanceOverlay.isVisible):(d.warn("Performance overlay not initialized. Set performanceOverlay.enabled: true in options."),!1)}showPerformanceOverlay(){this._performanceOverlay&&this._performanceOverlay.show()}hidePerformanceOverlay(){this._performanceOverlay&&this._performanceOverlay.hide()}setPerformanceOverlayEnabled(e,t={}){if(e)return this._performanceOverlay?(t&&Object.keys(t).length>0&&(this._performanceOverlay.options={...this._performanceOverlay.options,...t}),this._performanceOverlay.show()):(this.options.performanceOverlay={enabled:!0,...this.options.performanceOverlay||{},...t},this._initializePerformanceOverlay()),!0;if(this._performanceOverlay&&this._performanceOverlay.hide(),this._postRenderListener){try{this.viewer.scene.postRender.removeEventListener(this._postRenderListener)}catch(e){d.debug("postRender listener removal failed (non-fatal)")}this._postRenderListener=null}return!1}_estimateMemoryUsage(){try{const e=this.renderer?.geometryRenderer?.entities?.length||this.renderer?.voxelEntities?.length||0;let t=0;this._voxelData&&(this._voxelData instanceof Map||"number"==typeof this._voxelData.size?t=this._voxelData.size:Array.isArray(this._voxelData)?t=this._voxelData.length:"object"==typeof this._voxelData&&(t=Object.keys(this._voxelData).length));const i=(1024*e+100*t)/1048576;return Math.max(.1,i)}catch(e){return 0}}async setData(e){if(b(e))try{if(d.debug("Heatbox.setData - 処理開始:",e.length,"個のエンティティ"),d.debug("Step 1: 境界計算"),this._bounds=C.calculateBounds(e),!this._bounds)return d.error("境界計算に失敗"),void this.clear();d.debug("境界計算完了:",this._bounds);let t=this.options.voxelSize||n.voxelSize,i=null;if(this.options.autoVoxelSize&&!this.options.voxelSize)try{d.debug("自動ボクセルサイズ調整開始");const n={autoVoxelSizeMode:this.options.autoVoxelSizeMode,autoVoxelTargetFill:this.options.autoVoxelTargetFill,maxRenderVoxels:this.options.maxRenderVoxels},r=function(e,t,i={}){try{return"occupancy"===(i.autoVoxelSizeMode||"basic")?function(e,t,i){const n=_(e),a=i.maxRenderVoxels||5e4,r=i.autoVoxelTargetFill||.6;let s=w(e,t);d.debug(`Starting occupancy-based estimation: N=${t}, target=${r}, maxVoxels=${a}`);for(let i=0;i<10;i++){(!Number.isFinite(s)||s<=0)&&(d.warn(`Invalid currentSize detected: ${s}, using fallback`),s=w(e,t),(!Number.isFinite(s)||s<=0)&&(s=5));const l=Math.max(1,Math.ceil(Math.max(0,n.x)/s))*Math.max(1,Math.ceil(Math.max(0,n.y)/s))*Math.max(1,Math.ceil(Math.max(0,n.z)/s));if(!Number.isFinite(l)||l<=0||l>1e9){d.warn(`Invalid totalVoxels calculated: ${l}, breaking iteration`);break}const h=l*(1-Math.exp(-t/l)),c=Math.min(h/a,1);if(d.debug(`Iteration ${i}: size=${s.toFixed(1)}m, totalVoxels=${l}, expectedOccupied=${h.toFixed(0)}, fill=${c.toFixed(3)}`),Math.abs(c-r)<.05){d.debug(`Converged at iteration ${i}: size=${s.toFixed(1)}m, fill=${c.toFixed(3)}`);break}const u=Math.max(.1,Math.min(10,c/r));s*=Math.pow(u,.3),s=Math.max(5,Math.min(o,s))}const l=Math.round(s);return d.info(`Occupancy-based voxel size: ${l}m (target fill: ${r})`),l}(e,t,i):w(e,t)}catch(e){return d.warn("Initial voxel size estimation failed:",e),20}}(this._bounds,e.length,n),s=z.createGrid(this._bounds,r),l=function(e,t){const i={valid:!0,warning:!1,error:null,recommendedSize:null};if(e>a){i.valid=!1,i.error="ボクセル数が上限を超えています";const n=e/a,r=t*Math.pow(Math.max(1,Math.min(1e3,n)),1/3);i.recommendedSize=Math.ceil(Math.max(5,Math.min(o,r)))}else e>3e4&&(i.warning=!0,i.error="推定メモリ使用量が警告値を超えています");return i}(s.totalVoxels,r);!l.valid&&l.recommendedSize?(t=l.recommendedSize,i={enabled:!0,mode:this.options.autoVoxelSizeMode,originalSize:r,finalSize:t,adjusted:!0,reason:`Performance limit exceeded: ${s.totalVoxels} > 50000`},d.info(`Auto-adjusted voxelSize: ${r}m → ${t}m (${s.totalVoxels} voxels)`)):(t=r,i={enabled:!0,mode:this.options.autoVoxelSizeMode,originalSize:r,finalSize:t,adjusted:!1,reason:null},d.info(`Auto-determined voxelSize: ${t}m`))}catch(e){d.warn("Auto voxel size adjustment failed, using default:",e),t=n.voxelSize,i={enabled:!0,adjusted:!1,reason:"Estimation failed, using default size",originalSize:null,finalSize:t}}d.debug("Step 2: グリッド生成 (サイズ:",t,"m)"),this._grid=z.createGrid(this._bounds,t),d.debug("グリッド生成完了:",this._grid),d.debug("Step 3: エンティティ分類");const r={...this.options,voxelSize:t};this._voxelData=await X.classifyEntitiesIntoVoxels(e,this._bounds,this._grid,r),d.debug("エンティティ分類完了:",this._voxelData.size,"個のボクセル"),d.debug("Step 4: 統計計算"),this._statistics=X.calculateStatistics(this._voxelData,this._grid,this.options),d.debug("統計情報:",this._statistics),i&&(this._statistics.autoAdjusted=i.adjusted,this._statistics.originalVoxelSize=i.originalSize,this._statistics.finalVoxelSize=i.finalSize,this._statistics.adjustmentReason=i.reason),r.spatialId?.enabled?(this._statistics.spatialIdEnabled=!0,this._statistics.spatialIdMode=r.spatialId.mode,this._statistics.spatialIdProvider=r._spatialIdProvider||null,this._statistics.spatialIdZoom=r._resolvedZoom||null,this._statistics.zoomControl=r.spatialId.zoomControl):this._statistics.spatialIdEnabled=!1,d.debug("Step 5: 描画");const s="undefined"!=typeof performance&&performance.now?performance.now():Date.now(),l=this.renderer.render(this._voxelData,this._bounds,this._grid,this._statistics),h="undefined"!=typeof performance&&performance.now?performance.now():Date.now();if(this._lastRenderTime=Math.max(0,h-s),this._statistics.renderedVoxels=l,this._statistics.renderTimeMs=this._lastRenderTime,d.info("描画完了 - 実際の描画数:",l),this.options.autoView)try{d.debug("Auto view adjustment triggered"),await this.fitView(),d.debug("Auto view adjustment completed")}catch(e){d.warn("Auto view adjustment failed:",e)}if(d.debug("Heatbox.setData - 処理完了"),this._performanceOverlay&&this._performanceOverlay.isVisible){const e=this.getStatistics()||{};e.renderTimeMs=this._lastRenderTime,e.memoryUsageMB=this._estimateMemoryUsage(),this._performanceOverlay.update(e,void 0)}}catch(e){throw d.error("ヒートマップ作成エラー:",e),this.clear(),e}else this.clear()}async createFromEntities(e){if(!b(e))throw new Error(s);return await this.setData(e),this.getStatistics()}setVisible(e){this.renderer.setVisible(e)}clear(){this.renderer.clear(),this._bounds=null,this._grid=null,this._voxelData=null,this._statistics=null}destroy(){if(this.clear(),this._eventHandler&&!this._eventHandler.isDestroyed()&&this._eventHandler.destroy(),this._postRenderListener){try{this.viewer.scene.postRender.removeEventListener(this._postRenderListener)}catch(e){d.debug("postRender listener removal failed (non-fatal)")}this._postRenderListener=null}if(this._performanceOverlay){try{this._performanceOverlay.destroy()}catch(e){d.debug("overlay destroy failed (non-fatal)")}this._performanceOverlay=null}if(this._legend){try{this._legend.destroy()}catch(e){d.debug("legend destroy failed (non-fatal)")}this._legend=null}this._teardownTimeController(),this._eventHandler=null}dispose(){this.destroy()}getOptions(){return{...this.options}}updateOptions(e){const t=this.options?this.options.temporal:void 0,i=!!e&&Object.prototype.hasOwnProperty.call(e,"temporal");if(this.options=M({...this.options,...e}),this.renderer.options=this.options,this.renderer.adaptiveController&&"function"==typeof this.renderer.adaptiveController.updateOptions&&this.renderer.adaptiveController.updateOptions(this.options),this.renderer.geometryRenderer&&"function"==typeof this.renderer.geometryRenderer.updateOptions&&this.renderer.geometryRenderer.updateOptions(this.options),this._voxelData){const e=this.renderer.render(this._voxelData,this._bounds,this._grid,this._statistics);this._statistics.renderedVoxels=e}this._syncTimeController(t,this.options.temporal,i)}_initializeEventListeners(){this._eventHandler=new i.ScreenSpaceEventHandler(this.viewer.scene.canvas),this._eventHandler.setInputAction(e=>{const t=this.viewer.scene.pick(e.position);if(i.defined(t)&&t.id&&t.id.properties&&"voxel"===t.id.properties.type){const e=t.id.properties.key,n={x:t.id.properties.x,y:t.id.properties.y,z:t.id.properties.z,count:t.id.properties.count},a=new i.Entity({id:`voxel-${e}`,description:this.renderer.createVoxelDescription(n,e)});this.viewer.selectedEntity=a}},i.ScreenSpaceEventType.LEFT_CLICK)}getStatistics(){if(!this._statistics)return null;const e={...this._statistics},t=this.renderer.getSelectionStats();t&&(e.selectionStrategy=t.strategy,e.clippedNonEmpty=t.clippedNonEmpty,e.coverageRatio=t.coverageRatio??0),this.options._autoRenderBudget&&(e.renderBudgetTier=this.options._autoRenderBudget.tier,e.autoMaxRenderVoxels=this.options._autoRenderBudget.autoMaxRenderVoxels),"number"==typeof this.options.maxRenderVoxels&&this.options.maxRenderVoxels>0?e.occupancyRatio=Math.min(1,Math.max(0,(e.renderedVoxels||0)/this.options.maxRenderVoxels)):e.occupancyRatio=null;const i=this.options&&this.options.spatialId?this.options.spatialId:{},n=Boolean(e.spatialIdEnabled),a=this._spatialIdEdgeCaseMetrics??null;if(e.spatialId={enabled:n,provider:n?e.spatialIdProvider??null:null,zoom:n?e.spatialIdZoom??null:null,zoomControl:e.zoomControl??i.zoomControl??null,edgeCaseMetrics:a},this.options.aggregation?.enabled&&this._voxelData){const t=new Map;for(const e of this._voxelData.values())if(e.layerStats)for(const[i,n]of e.layerStats)t.set(i,(t.get(i)||0)+n);const i=this.options.aggregation?.topN??10,n=Array.from(t.entries()).sort((e,t)=>t[1]-e[1]).slice(0,i);e.layers=n.map(([e,t])=>({key:e,total:t})),d.debug(`[aggregation] Aggregated ${t.size} unique layers, returning top ${e.layers.length}`)}return e}getBounds(){return this._bounds}getDebugInfo(){const e={options:{...this.options},bounds:this._bounds,grid:this._grid,statistics:this._statistics};return this.options.autoVoxelSize&&(e.autoVoxelSizeInfo={enabled:this.options.autoVoxelSize,originalSize:this._statistics?.originalVoxelSize,finalSize:this._statistics?.finalVoxelSize,adjusted:this._statistics?.autoAdjusted||!1,reason:this._statistics?.adjustmentReason,dataRange:this._bounds?_(this._bounds):null,estimatedDensity:this._bounds&&this._statistics?this._statistics.totalEntities/(_(this._bounds).x*_(this._bounds).y*_(this._bounds).z):null}),e}_hookPerformanceOverlayUpdates(){if(!this._performanceOverlay||this._postRenderListener)return;const e=this._performanceOverlay.options?.updateIntervalMs??500;this._postRenderListener=()=>{if(!this._performanceOverlay||!this._performanceOverlay.isVisible)return;const t="undefined"!=typeof performance&&performance.now?performance.now():Date.now();let i;if(null!=this._prevFrameTimestamp&&(i=Math.max(0,t-this._prevFrameTimestamp)),this._prevFrameTimestamp=t,t-this._overlayLastUpdate<e)return;this._overlayLastUpdate=t;const n=this.getStatistics()||{};null!=this._lastRenderTime&&(n.renderTimeMs=this._lastRenderTime),n.memoryUsageMB=this._estimateMemoryUsage();try{this._performanceOverlay.update(n,i)}catch(e){}};try{this.viewer.scene.postRender.addEventListener(this._postRenderListener)}catch(e){}}async fitView(e=null,t={}){try{const i=e||this._bounds;if(!i)return void d.warn("No bounds available for fitView");if(!this._isValidBounds(i))return void d.warn("Invalid bounds provided to fitView:",i);const n={...this.options.fitViewOptions,...t};d.debug("fitView called with bounds:",i,"options:",n);const a={...n};return Number.isFinite(a.pitchDegrees)||(a.pitchDegrees=-35),Number.isFinite(a.headingDegrees)||(a.headingDegrees=0),await new Promise(e=>{let t=!1;const n=async()=>{if(!t){t=!0;try{await this._fitByBoundingSphere(i,a)}catch(e){d.warn("fitView (postRender) failed, trying fallback:",e);try{await this.viewer.zoomTo(this.viewer.entities)}catch(e){d.warn("zoomTo fallback failed:",e)}}finally{try{this.viewer.scene.postRender.removeEventListener(n)}catch(e){d.debug("postRender removeEventListener failed (non-fatal):",e)}e()}}};try{this.viewer.scene.postRender.addEventListener(n)}catch(t){d.warn("postRender addEventListener failed:",t),e()}})}catch(e){throw d.error("fitView failed:",e),e}}async _fitByBoundingSphere(e,t){const n=i.Rectangle.fromDegrees(e.minLon,e.minLat,e.maxLon,e.maxLat),a=i.BoundingSphere.fromRectangle3D(n,i.Ellipsoid.WGS84,Math.max(0,e.minAlt||0)),o=i.Math.toRadians(t.headingDegrees??0),r=Math.max(-85,Math.min(-10,t.pitchDegrees??-35)),s=i.Math.toRadians(r),l=Math.max(2.2*a.radius,1e3);await this.viewer.camera.flyToBoundingSphere(a,{duration:1.2,offset:new i.HeadingPitchRange(o,s,l)})}_isValidBounds(e){return e&&"number"==typeof e.minLon&&!isNaN(e.minLon)&&"number"==typeof e.maxLon&&!isNaN(e.maxLon)&&"number"==typeof e.minLat&&!isNaN(e.minLat)&&"number"==typeof e.maxLat&&!isNaN(e.maxLat)&&"number"==typeof e.minAlt&&!isNaN(e.minAlt)&&"number"==typeof e.maxAlt&&!isNaN(e.maxAlt)&&e.minLon<=e.maxLon&&e.minLat<=e.maxLat&&e.minAlt<=e.maxAlt}async _handleMinimalDataRange(e,t,n,a){d.debug("Handling minimal data range");const o=i.Cartesian3.fromDegrees(e,t,n+2e3),r=i.Math.toRadians(a.headingDegrees||a.heading),s=i.Math.toRadians(a.pitchDegrees||a.pitch);return this.viewer.camera.flyTo({destination:o,orientation:{heading:r,pitch:s,roll:0},duration:1.5})}async _handleLargeDataRange(e,t){d.debug("Handling large data range with bounding sphere");const n=(e.minLon+e.maxLon)/2,a=(e.minLat+e.maxLat)/2,o=(e.minAlt+e.maxAlt)/2,r=_(e),s=Math.max(r.x,r.y,r.z),l=new i.BoundingSphere(i.Cartesian3.fromDegrees(n,a,o),s/2),h=i.Math.toRadians(t.headingDegrees||t.heading),c=i.Math.toRadians(t.pitchDegrees||t.pitch);return this.viewer.camera.flyToBoundingSphere(l,{duration:2.5,offset:new i.HeadingPitchRange(h,c,0)})}_calculateOptimalCameraHeight(e,t,n){if("auto"!==n.altitudeStrategy)return n.altitude||5e3;try{const a=i.Math.toRadians(n.pitchDegrees||n.pitch),o=this.viewer.camera.frustum.fovy||i.Math.toRadians(60),r=(e+t)/(2*Math.tan(o/2)),s=Math.abs(a);let l=r*Math.max(.5,Math.sin(Math.PI/2-s)+.3);const h=e/Math.min(e,100);h>5&&(l*=Math.log10(h)+1);const c=Math.max(500,.1*e),u=Math.min(1e5,10*e);return l=Math.max(c,Math.min(u,l)),d.debug(`Camera height calculated: ${l.toFixed(0)}m (range: ${e.toFixed(0)}m, pitch: ${n.pitchDegrees||n.pitch}°)`),l}catch(t){return d.warn("Camera height calculation failed, using fallback:",t),Math.max(2e3,2*e)}}async _executeCameraMovement(e,t,n,a,o,r,s){try{const l=i.Cartesian3.fromDegrees(e,t,n+a),h=i.Math.toRadians(o.headingDegrees||o.heading),c=i.Math.toRadians(o.pitchDegrees||o.pitch),u={heading:h,pitch:c,roll:0};d.debug(`Camera target: position=${e.toFixed(6)},${t.toFixed(6)},${(n+a).toFixed(0)}, heading=${o.headingDegrees||o.heading}°, pitch=${o.pitchDegrees||o.pitch}°`);const p=Math.max(1,Math.min(3,.8*Math.log10(r))),m=this.viewer.camera.flyTo({destination:l,orientation:u,duration:p,complete:()=>{d.debug("fitView camera movement completed")},cancel:()=>{d.debug("fitView camera movement cancelled")}});if(m)await m;else{d.debug("Using fallback: flyToBoundingSphere");const a=new i.BoundingSphere(i.Cartesian3.fromDegrees(e,t,n),r/2+s);await this.viewer.camera.flyToBoundingSphere(a,{duration:p,offset:new i.HeadingPitchRange(h,c,0)})}d.info("fitView completed successfully")}catch(e){throw d.error("Camera movement execution failed:",e),e}}createLegend(e=null){return this._legend||(this._legend=new re({container:e})),this._legend.render(this.renderer?._classifier||null,this.options.classification||{}),this._legend.container||null}updateLegend(){this._legend&&this._legend.update(this.renderer?._classifier||null,this.options.classification||{})}destroyLegend(){this._legend&&(this._legend.destroy(),this._legend=null)}static filterEntities(e,t){return Array.isArray(e)&&"function"==typeof t?e.filter(t):[]}}function ce(e,t,n=500){if(!e)throw new Error("viewer is required");if(!(t&&"minLon"in t&&"maxLon"in t&&"minLat"in t&&"maxLat"in t))throw new Error("bounds must include minLon, maxLon, minLat, maxLat");const a=[],o=t.minAlt||0,r=t.maxAlt||100;for(let s=0;s<n;s++){const n=t.minLon+(t.maxLon-t.minLon)*Math.random(),l=t.minLat+(t.maxLat-t.minLat)*Math.random(),h=o+(r-o)*Math.random(),c=e.entities.add({id:`test-entity-${s}`,position:i.Cartesian3.fromDegrees(n,l,h),point:{pixelSize:5,color:i.Color.YELLOW,outlineColor:i.Color.BLACK,outlineWidth:1},label:{text:`Test ${s}`,font:"10pt sans-serif",pixelOffset:new i.Cartesian2(0,-30),fillColor:i.Color.WHITE,outlineColor:i.Color.BLACK,outlineWidth:1,style:i.LabelStyle.FILL_AND_OUTLINE}});a.push(c)}return a}function de(e){if(!e||!e.entities)throw new Error("Invalid viewer");return e.entities.values}const ue=he,pe="1.2.1-alpha.2",me="hiro-nyon",ge="https://github.com/hiro-nyon/cesium-heatbox";function fe(e,t){return new he(e,t)}function ye(){let e=!1;try{if("undefined"!=typeof WebGLRenderingContext){const t=document.createElement("canvas");e=!(!t.getContext("webgl")&&!t.getContext("experimental-webgl"))}}catch(t){e=!1}return{version:pe,cesiumVersion:"undefined"!=typeof Cesium?Cesium.VERSION:"N/A",userAgent:"undefined"!=typeof navigator?navigator.userAgent:"N/A",webglSupport:e,timestamp:(new Date).toISOString()}}d.info(`CesiumJS Heatbox v${pe} loaded`);export{me as AUTHOR,he as CesiumHeatbox,he as Heatbox,re as Legend,ge as REPOSITORY,pe as VERSION,fe as createHeatbox,ue as default,ce as generateTestEntities,de as getAllEntities,ye as getEnvironmentInfo};
1
+ import*as e from"cesium";var t={d:(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const i=(l={BoundingSphere:()=>e.BoundingSphere,Cartesian2:()=>e.Cartesian2,Cartesian3:()=>e.Cartesian3,Cartographic:()=>e.Cartographic,Color:()=>e.Color,Ellipsoid:()=>e.Ellipsoid,Entity:()=>e.Entity,HeadingPitchRange:()=>e.HeadingPitchRange,JulianDate:()=>e.JulianDate,LabelStyle:()=>e.LabelStyle,Math:()=>e.Math,Rectangle:()=>e.Rectangle,ScreenSpaceEventHandler:()=>e.ScreenSpaceEventHandler,ScreenSpaceEventType:()=>e.ScreenSpaceEventType,defined:()=>e.defined},h={},t.d(h,l),h),n={voxelSize:20,opacity:.8,emptyOpacity:.03,showOutline:!0,showEmptyVoxels:!1,wireframeOnly:!1,heightBased:!1,outlineWidth:2,minColor:[0,32,255],maxColor:[255,64,0],maxRenderVoxels:5e4,batchMode:"auto",debug:!1,autoVoxelSize:!1,colorMap:"custom",diverging:!1,divergingPivot:0,highlightTopN:null,highlightStyle:{outlineWidth:4,boostOpacity:.2},voxelGap:0,outlineOpacity:1,outlineWidthResolver:null,outlineEmulation:"off",outlineInset:0,outlineInsetMode:"all",enableThickFrames:!1,outlineRenderMode:"standard",emulationScope:"off",adaptiveOutlines:!1,outlineWidthPreset:"medium",boxOpacityResolver:null,outlineOpacityResolver:null,adaptiveParams:{neighborhoodRadius:30,densityThreshold:3,cameraDistanceFactor:.8,overlapRiskFactor:.4,minOutlineWidth:1,maxOutlineWidth:5,outlineWidthRange:null,boxOpacityRange:null,outlineOpacityRange:null,adaptiveOpacityEnabled:!1,zScaleCompensation:!0,overlapDetection:!1},renderLimitStrategy:"density",minCoverageRatio:.2,coverageBinsXY:"auto",autoVoxelSizeMode:"basic",autoVoxelTargetFill:.6,renderBudgetMode:"manual",autoView:!1,fitViewOptions:{paddingPercent:.1,pitchDegrees:-30,headingDegrees:0,altitudeStrategy:"auto"},spatialId:{enabled:!1,mode:"tile-grid",provider:"ouranos-gex",zoom:25,zoomControl:"auto",zoomTolerancePct:10},aggregation:{enabled:!1,byProperty:null,keyResolver:null,showInDescription:!0,topN:10},classification:{enabled:!1,scheme:"linear",classes:5,thresholds:null,colorMap:null,domain:null,classificationTargets:{color:!0,opacity:!1,width:!1}}},a=5e4,o=1e3,r=40075016.68557849,s=(Math.PI,"対象エンティティがありません");var l,h;let c="undefined"!=typeof process&&process.env&&"true"===process.env.DEBUG?3:"undefined"!=typeof process&&process.env?1:3;const d={error(...e){c>=0&&console.error("[Heatbox ERROR]",...e)},warn(...e){c>=1&&console.warn("[Heatbox WARN]",...e)},info(...e){c>=2&&console.log("[Heatbox INFO]",...e)},debug(...e){c>=3&&console.log("[Heatbox DEBUG]",...e)},setLogLevel:e=>(e&&void 0!==e.debug&&("boolean"==typeof e.debug?c=e.debug?3:1:"object"==typeof e.debug&&null!==e.debug&&(c=3)),c)},u=(d.debug,d.warn,d.error,d.info,new Set);function p(e,t){u.has(e)||(u.add(e),d.warn(t))}const m={"mobile-fast":{maxRenderVoxels:5e3,outlineRenderMode:"emulation-only",adaptiveOutlines:!1,outlineWidthPreset:"thin",opacity:.7,renderLimitStrategy:"density",minCoverageRatio:.1,topNHighlight:10,description:"Mobile devices - prioritizes performance over visual quality"},"desktop-balanced":{maxRenderVoxels:15e3,outlineRenderMode:"standard",adaptiveOutlines:!0,outlineWidthPreset:"medium",opacity:.8,renderLimitStrategy:"hybrid",minCoverageRatio:.2,topNHighlight:20,adaptiveParams:{outlineWidthRange:[1,4],outlineOpacityRange:[.4,1],boxOpacityRange:[.2,.8]},description:"Desktop environments - balanced performance and quality"},"dense-data":{maxRenderVoxels:25e3,outlineRenderMode:"inset",adaptiveOutlines:!0,outlineWidthPreset:"thin",opacity:.6,renderLimitStrategy:"hybrid",minCoverageRatio:.3,topNHighlight:30,outlineInset:.5,highlightTopN:!0,highlightStyle:{boostOpacity:.3,boostOutlineWidth:1.5},description:"High-density datasets - optimized for cluttered environments"},"sparse-data":{maxRenderVoxels:8e3,outlineRenderMode:"standard",adaptiveOutlines:!1,outlineWidthPreset:"thick",opacity:.9,renderLimitStrategy:"coverage",minCoverageRatio:.8,topNHighlight:50,emptyOpacity:.05,showEmptyVoxels:!0,description:"Sparse datasets - emphasizes visibility and coverage"}};function g(){return Object.keys(m)}function f(e){return m[e]||null}function y(e,t={}){const i=f(e);if(!i)return t;const{description:n,...a}=i;return x(a,t)}function x(e,t){const i={...e};for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&(t[e]&&"object"==typeof t[e]&&!Array.isArray(t[e])?i[e]=x(i[e]||{},t[e]):i[e]=t[e]);return i}function v(e,t=!1){if(null==e)return t;if("boolean"==typeof e)return e;if("string"==typeof e){const i=e.trim().toLowerCase();return""===i?t:!!["true","1","yes","on"].includes(i)||!["false","0","no","off"].includes(i)&&Boolean(i)}return"number"==typeof e?Number.isFinite(e)?0!==e:t:Boolean(e)}function b(e){return!!Array.isArray(e)&&0!==e.length&&(e.length>5e3&&d.warn(`エンティティ数が推奨値(5000)を超えています: ${e.length}`),!0)}function M(e={}){let t=e;var i;e.profile&&"none"!==e.profile&&("string"==typeof(i=e.profile)&&Object.prototype.hasOwnProperty.call(m,i)?(d.debug(`Applying profile: ${e.profile}`),t=y(e.profile,e),delete t.profile):d.warn(`Invalid profile name: ${e.profile}. Available profiles: mobile-fast, desktop-balanced, dense-data, sparse-data`));const a={...t};if(a.batchMode&&a.debug&&d.warn("batchMode option is deprecated and will be removed in v1.0.0. It is currently ignored."),void 0!==a.voxelSize&&("number"!=typeof(r=a.voxelSize)||isNaN(r)||r<5||r>o))throw new Error(`ボクセルサイズが無効です: ${a.voxelSize}`);var r;if(void 0!==a.opacity&&(a.opacity=Math.max(0,Math.min(1,a.opacity))),void 0!==a.emptyOpacity&&(a.emptyOpacity=Math.max(0,Math.min(1,a.emptyOpacity))),a.minColor&&Array.isArray(a.minColor)&&3===a.minColor.length&&(a.minColor=a.minColor.map(e=>Math.max(0,Math.min(255,Math.floor(e))))),a.maxColor&&Array.isArray(a.maxColor)&&3===a.maxColor.length&&(a.maxColor=a.maxColor.map(e=>Math.max(0,Math.min(255,Math.floor(e))))),void 0!==a.colorMap&&(["custom","viridis","inferno"].includes(a.colorMap)||(d.warn(`Invalid colorMap: ${a.colorMap}. Using 'custom'.`),a.colorMap="custom")),void 0!==a.highlightTopN&&null!==a.highlightTopN&&("number"!=typeof a.highlightTopN||a.highlightTopN<=0)&&(d.warn(`Invalid highlightTopN: ${a.highlightTopN}. Must be a positive number.`),a.highlightTopN=null),void 0!==a.voxelGap&&(a.voxelGap=Math.max(0,Math.min(100,parseFloat(a.voxelGap)||0))),void 0!==a.outlineOpacity&&(a.outlineOpacity=Math.max(0,Math.min(1,parseFloat(a.outlineOpacity)||1))),void 0!==a.outlineWidth){const e=parseFloat(a.outlineWidth);a.outlineWidth=Number.isFinite(e)?Math.max(.5,Math.min(20,e)):n.outlineWidth}if(void 0!==a.wireframeOnly&&(a.wireframeOnly=v(a.wireframeOnly)),void 0!==a.heightBased&&(a.heightBased=v(a.heightBased)),void 0!==a.outlineWidthResolver&&null!==a.outlineWidthResolver&&(p("outlineWidthResolver","[Heatbox][DEPRECATION][v1.0.0] outlineWidthResolver is deprecated; prefer adaptiveOutlines with outlineWidthPreset and adaptiveParams."),"function"!=typeof a.outlineWidthResolver&&(d.warn("outlineWidthResolver must be a function. Ignoring."),a.outlineWidthResolver=null)),void 0!==a.outlineOpacityResolver&&null!==a.outlineOpacityResolver&&(p("outlineOpacityResolver","[Heatbox][DEPRECATION][v1.0.0] outlineOpacityResolver is deprecated; prefer adaptiveOutlines with adaptiveParams.outlineOpacityRange."),"function"!=typeof a.outlineOpacityResolver&&(d.warn("outlineOpacityResolver must be a function. Ignoring."),a.outlineOpacityResolver=null)),void 0!==a.boxOpacityResolver&&null!==a.boxOpacityResolver&&(p("boxOpacityResolver","[Heatbox][DEPRECATION][v1.0.0] boxOpacityResolver is deprecated; prefer adaptiveOutlines with adaptiveParams.boxOpacityRange."),"function"!=typeof a.boxOpacityResolver&&(d.warn("boxOpacityResolver must be a function. Ignoring."),a.boxOpacityResolver=null)),void 0!==a.outlineEmulation&&(void 0===a.outlineRenderMode||"standard"===a.outlineRenderMode)){p("outlineEmulation","[Heatbox][DEPRECATION][v1.0.0] outlineEmulation is deprecated; use outlineRenderMode and emulationScope instead.");const e=a.outlineEmulation;!1===e||"off"===e?(a.outlineRenderMode="standard",a.emulationScope="off"):!0===e||"all"===e?(a.outlineRenderMode="emulation-only",a.emulationScope="all"):"topn"===e?(a.outlineRenderMode="standard",a.emulationScope="topn"):"non-topn"===e?(a.outlineRenderMode="standard",a.emulationScope="non-topn"):(d.warn(`Invalid outlineEmulation: ${e}. Using 'standard' mode.`),a.outlineRenderMode="standard"),delete a.outlineEmulation}if(void 0!==a.outlineWidthPreset){const e=a.outlineWidthPreset,t={uniform:"medium","adaptive-density":"adaptive","topn-focus":"thick"};t[e]&&(p(`outlineWidthPreset.${e}`,`[Heatbox][DEPRECATION][v1.0.0] outlineWidthPreset "${e}" is deprecated; use "${t[e]}".`),a.outlineWidthPreset=t[e])}if(void 0!==a.outlineInset){const e=parseFloat(a.outlineInset);a.outlineInset=isNaN(e)||e<0?0:e}if(void 0!==a.outlineInsetMode){let e=a.outlineInsetMode;"off"===e&&(e="none"),["all","topn","none"].includes(e)?a.outlineInsetMode=e:(d.warn(`Invalid outlineInsetMode: ${a.outlineInsetMode}. Using 'all'.`),a.outlineInsetMode="all")}if(void 0!==a.outlineInset){const e=parseFloat(a.outlineInset);a.outlineInset=Math.max(0,Math.min(100,isNaN(e)?0:e))}if(void 0!==a.outlineInsetMode){let e=a.outlineInsetMode;"off"===e&&(e="none"),["all","topn","none"].includes(e)?a.outlineInsetMode=e:(d.warn(`Invalid outlineInsetMode: ${a.outlineInsetMode}. Using 'all'.`),a.outlineInsetMode="all")}if(void 0!==a.enableThickFrames&&(a.enableThickFrames=v(a.enableThickFrames)),void 0!==a.renderLimitStrategy&&(["density","coverage","hybrid"].includes(a.renderLimitStrategy)||(d.warn(`Invalid renderLimitStrategy: ${a.renderLimitStrategy}. Using 'density'.`),a.renderLimitStrategy="density")),void 0!==a.minCoverageRatio){const e=parseFloat(a.minCoverageRatio);a.minCoverageRatio=isNaN(e)?.2:Math.max(0,Math.min(1,e))}if(void 0!==a.coverageBinsXY){const e=a.coverageBinsXY;if("auto"!==e){const t=parseInt(e,10);!Number.isFinite(t)||t<=0?(d.warn(`Invalid coverageBinsXY: ${e}. Using 'auto'.`),a.coverageBinsXY="auto"):a.coverageBinsXY=t}}if(void 0!==a.autoVoxelSizeMode&&(["basic","occupancy"].includes(a.autoVoxelSizeMode)||(d.warn(`Invalid autoVoxelSizeMode: ${a.autoVoxelSizeMode}. Using 'basic'.`),a.autoVoxelSizeMode="basic")),void 0!==a.autoVoxelTargetFill){const e=parseFloat(a.autoVoxelTargetFill);a.autoVoxelTargetFill=isNaN(e)?.6:Math.max(0,Math.min(1,e))}if(void 0!==a.renderBudgetMode&&(["manual","auto"].includes(a.renderBudgetMode)||(d.warn(`Invalid renderBudgetMode: ${a.renderBudgetMode}. Using 'manual'.`),a.renderBudgetMode="manual")),void 0!==a.fitViewOptions){const e=a.fitViewOptions||{};void 0!==e.pitch&&void 0===e.pitchDegrees&&p("fitViewOptions.pitch","[Heatbox][DEPRECATION][v1.0.0] fitViewOptions.pitch is deprecated; use fitViewOptions.pitchDegrees."),void 0!==e.heading&&void 0===e.headingDegrees&&p("fitViewOptions.heading","[Heatbox][DEPRECATION][v1.0.0] fitViewOptions.heading is deprecated; use fitViewOptions.headingDegrees.");const t=parseFloat(e.paddingPercent),i=void 0!==e.pitchDegrees?parseFloat(e.pitchDegrees):parseFloat(e.pitch),n=void 0!==e.headingDegrees?parseFloat(e.headingDegrees):parseFloat(e.heading),o=e.altitudeStrategy;a.fitViewOptions={paddingPercent:Number.isFinite(t)?Math.max(0,Math.min(1,t)):.1,pitchDegrees:Number.isFinite(i)?Math.max(-90,Math.min(0,i)):-30,headingDegrees:Number.isFinite(n)?n:0,altitudeStrategy:"manual"===o?"manual":"auto"}}const s=a.adaptiveParams?{...a.adaptiveParams}:{};a.adaptiveParams={...n.adaptiveParams,...s};const l=a.adaptiveParams;if(void 0!==s.minOutlineWidth&&void 0!==s.maxOutlineWidth&&void 0===s.outlineWidthRange&&(l.outlineWidthRange=[Math.max(1,parseFloat(s.minOutlineWidth)||1),Math.max(1,parseFloat(s.maxOutlineWidth)||5)],d.debug("adaptiveParams: minOutlineWidth/maxOutlineWidth normalized to outlineWidthRange")),void 0!==l.outlineWidthRange&&Array.isArray(l.outlineWidthRange)){const[e,t]=l.outlineWidthRange;l.outlineWidthRange=[Math.max(1,parseFloat(e)||1),Math.max(1,parseFloat(t)||5)],l.outlineWidthRange[0]>l.outlineWidthRange[1]&&(l.outlineWidthRange=[l.outlineWidthRange[1],l.outlineWidthRange[0]],d.warn("adaptiveParams.outlineWidthRange: min > max detected, swapped values"))}if(void 0!==l.boxOpacityRange&&Array.isArray(l.boxOpacityRange)){const[e,t]=l.boxOpacityRange;l.boxOpacityRange=[Math.max(0,Math.min(1,parseFloat(e)||0)),Math.max(0,Math.min(1,parseFloat(t)||1))],l.boxOpacityRange[0]>l.boxOpacityRange[1]&&(l.boxOpacityRange=[l.boxOpacityRange[1],l.boxOpacityRange[0]],d.warn("adaptiveParams.boxOpacityRange: min > max detected, swapped values"))}if(void 0!==l.outlineOpacityRange&&Array.isArray(l.outlineOpacityRange)){const[e,t]=l.outlineOpacityRange;l.outlineOpacityRange=[Math.max(0,Math.min(1,parseFloat(e)||0)),Math.max(0,Math.min(1,parseFloat(t)||1))],l.outlineOpacityRange[0]>l.outlineOpacityRange[1]&&(l.outlineOpacityRange=[l.outlineOpacityRange[1],l.outlineOpacityRange[0]],d.warn("adaptiveParams.outlineOpacityRange: min > max detected, swapped values"))}if(void 0!==l.overlapDetection&&(l.overlapDetection=v(l.overlapDetection)),void 0!==l.zScaleCompensation&&(l.zScaleCompensation=v(l.zScaleCompensation)),void 0!==l.adaptiveOpacityEnabled&&(l.adaptiveOpacityEnabled=v(l.adaptiveOpacityEnabled)),void 0!==l.neighborhoodRadius){const e=parseFloat(l.neighborhoodRadius);l.neighborhoodRadius=Number.isFinite(e)&&e>0?e:30}if(void 0!==l.densityThreshold){const e=parseFloat(l.densityThreshold);l.densityThreshold=Number.isFinite(e)&&e>0?e:3}if(void 0!==l.cameraDistanceFactor){const e=parseFloat(l.cameraDistanceFactor);l.cameraDistanceFactor=Number.isFinite(e)&&e>0?e:.8}if(void 0!==l.overlapRiskFactor){const e=parseFloat(l.overlapRiskFactor);l.overlapRiskFactor=Number.isFinite(e)?Math.max(0,Math.min(1,e)):.4}if(a.adaptiveParams=l,a.performanceOverlay){const e={...a.performanceOverlay};if(e.enabled=v(e.enabled,!1),e.autoShow=v(e.autoShow,!1),e.autoUpdate=v(e.autoUpdate,!0),e.position=["top-left","top-right","bottom-left","bottom-right"].includes(e.position)?e.position:"top-right",void 0!==e.updateIntervalMs){const t=parseFloat(e.updateIntervalMs);e.updateIntervalMs=Number.isFinite(t)?Math.max(100,t):500}if(void 0!==e.fpsAveragingWindowMs){const t=parseFloat(e.fpsAveragingWindowMs);e.fpsAveragingWindowMs=Number.isFinite(t)?Math.max(200,t):1e3}a.performanceOverlay=e}if(void 0!==t.spatialId){const e="object"==typeof t.spatialId&&null!==t.spatialId?{...t.spatialId}:{};if(e.enabled=v(e.enabled,!1),void 0!==e.mode?"tile-grid"!==e.mode&&(d.warn(`Invalid spatialId.mode: ${e.mode}. Using 'tile-grid'.`),e.mode="tile-grid"):e.mode="tile-grid",void 0!==e.provider?"ouranos-gex"!==e.provider&&(d.warn(`Unknown spatialId.provider: ${e.provider}. Using 'ouranos-gex'.`),e.provider="ouranos-gex"):e.provider="ouranos-gex",void 0!==e.zoom)if("auto"===e.zoom)e.zoom="auto";else{const t=parseInt(e.zoom,10);Number.isNaN(t)||t<0||t>35?(d.warn(`Invalid spatialId.zoom: ${e.zoom}. Using 25.`),e.zoom=25):e.zoom=t}else e.zoom=25;if(void 0!==e.zoomControl?["auto","manual"].includes(e.zoomControl)||(d.warn(`Invalid spatialId.zoomControl: ${e.zoomControl}. Using 'auto'.`),e.zoomControl="auto"):e.zoomControl="auto",void 0!==e.zoomTolerancePct){const t=parseFloat(e.zoomTolerancePct);!Number.isFinite(t)||t<=0||t>100?(d.warn(`Invalid spatialId.zoomTolerancePct: ${e.zoomTolerancePct}. Using 10.`),e.zoomTolerancePct=10):e.zoomTolerancePct=t}else e.zoomTolerancePct=10;a.spatialId=e}else a.spatialId={...n.spatialId};return a.classification=function(e){const t={...n.classification,classificationTargets:{...n.classification.classificationTargets}};if(void 0===e)return{...t};if(null===e||!1===e)return{...t,enabled:!1};const i={...t};let a=e;const o=["color","opacity","width"];if("string"==typeof e&&(a={scheme:e,enabled:"none"!==e}),"object"==typeof a){if(void 0!==a.enabled?i.enabled=v(a.enabled,t.enabled):i.enabled=!0,void 0!==a.scheme&&(i.scheme=function(e){if(!e||"string"!=typeof e)return"linear";const t=e.trim().toLowerCase();return["linear","log","equal-interval","quantize","threshold","quantile","jenks"].includes(t)?t:(d.warn(`[classification] Unknown scheme '${e}', falling back to 'linear'.`),"linear")}(a.scheme)),void 0!==a.classes){const e=Number(a.classes);i.classes=Number.isInteger(e)?Math.max(2,Math.min(20,e)):t.classes}if(Array.isArray(a.thresholds)){const e=a.thresholds.map(e=>Number(e)).filter(e=>Number.isFinite(e)).sort((e,t)=>e-t);i.thresholds=e.length>0?e:null}else null===a.thresholds&&(i.thresholds=null);if(Array.isArray(a.colorMap)?i.colorMap=a.colorMap.slice():null===a.colorMap?i.colorMap=null:void 0!==a.colorMap&&(d.warn("[classification] colorMap should be an array of colors or stop objects. Ignoring provided value."),i.colorMap=null),Array.isArray(a.domain)&&2===a.domain.length){const[e,t]=a.domain.map(e=>Number(e));Number.isFinite(e)&&Number.isFinite(t)&&(i.domain=[e,t])}else null===a.domain&&(i.domain=null);const e={...t.classificationTargets},n=(i,n)=>{if(null!=i)if("object"!=typeof i||Array.isArray(i))d.warn(`[classification] ${n} should be an object with boolean flags. Ignoring provided value.`);else for(const n of o)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=v(i[n],t.classificationTargets[n]))};n(a.targets,"targets"),n(a.classificationTargets,"classificationTargets"),i.classificationTargets=e}else d.warn("[classification] Unsupported configuration type. Expected string or object."),i.enabled=!1;return i.enabled?"threshold"!==i.scheme||Array.isArray(i.thresholds)?i:(d.warn("[classification] threshold scheme requires a thresholds array. Disabling classification."),{...t,enabled:!1}):{...t,enabled:!1}}(a.classification),void 0!==a.aggregation?a.aggregation=function(e){const t={...n.aggregation};if(!e||"object"!=typeof e)return t;if(void 0!==e.enabled&&(t.enabled=v(e.enabled,!1)),void 0!==e.byProperty&&null!==e.byProperty&&("string"==typeof e.byProperty&&""!==e.byProperty.trim()?t.byProperty=e.byProperty.trim():(d.warn("[aggregation] byProperty must be a non-empty string, ignoring"),t.byProperty=null)),void 0!==e.keyResolver&&null!==e.keyResolver&&("function"==typeof e.keyResolver?t.keyResolver=e.keyResolver:(d.warn("[aggregation] keyResolver must be a function, ignoring"),t.keyResolver=null)),void 0!==e.showInDescription&&(t.showInDescription=v(e.showInDescription,!0)),void 0!==e.topN){const i=Number(e.topN);Number.isInteger(i)&&i>0&&i<=100?t.topN=i:(d.warn("[aggregation] topN must be a positive integer <= 100, using default (10)"),t.topN=n.aggregation.topN)}return!t.enabled||t.byProperty||t.keyResolver||d.warn('[aggregation] enabled=true but neither byProperty nor keyResolver is set. Will use default key "default".'),t}(a.aggregation):a.aggregation={...n.aggregation},a}function w(e,t){const i=_(e),n=i.x*i.y*Math.max(i.z,10),a=t/n;let r;return r=a>.001?Math.max(10,Math.min(20,20/Math.sqrt(1e3*a))):a>1e-4?Math.max(20,Math.min(50,50/Math.sqrt(1e4*a))):Math.max(50,Math.min(100,100/Math.sqrt(1e5*a))),r=Math.max(5,Math.min(o,r)),d.debug(`Basic voxel size estimated: ${r}m (density: ${a}, volume: ${n})`),Math.round(r)}function _(e){try{const t={minLat:Number.isFinite(e.minLat)?Math.max(-90,Math.min(90,e.minLat)):0,maxLat:Number.isFinite(e.maxLat)?Math.max(-90,Math.min(90,e.maxLat)):.1,minLon:Number.isFinite(e.minLon)?Math.max(-180,Math.min(180,e.minLon)):0,maxLon:Number.isFinite(e.maxLon)?Math.max(-180,Math.min(180,e.maxLon)):.1,minAlt:Number.isFinite(e.minAlt)?e.minAlt:0,maxAlt:Number.isFinite(e.maxAlt)?e.maxAlt:100};t.maxLat<=t.minLat&&(t.maxLat=t.minLat+.001),t.maxLon<=t.minLon&&(t.maxLon=t.minLon+.001),t.maxAlt<=t.minAlt&&(t.maxAlt=t.minAlt+1);const i=(t.minLat+t.maxLat)/2,n=Math.cos(Math.max(-Math.PI/2,Math.min(Math.PI/2,i*Math.PI/180))),a=111e3*Math.abs(t.maxLon-t.minLon)*Math.abs(n),o=111e3*Math.abs(t.maxLat-t.minLat),r=Math.abs(t.maxAlt-t.minAlt);return{x:Math.max(1,Math.min(1e6,a)),y:Math.max(1,Math.min(1e6,o)),z:Math.max(1,Math.min(1e4,r))}}catch(e){return d.warn("Data range calculation failed:",e),{x:1e3,y:1e3,z:100}}}const S={low:{min:4e3,max:8e3},mid:{min:8e3,max:15e3},high:{min:15e3,max:25e3}};class C{static calculateBounds(e){if(!Array.isArray(e)||0===e.length)throw new Error("エンティティが提供されていません");let t=1/0,n=-1/0,a=1/0,o=-1/0,r=1/0,s=-1/0,l=0;const h=i.JulianDate.now();if(e.forEach((e,c)=>{try{let c,d,u,p;if(e.position&&(c="function"==typeof e.position.getValue?e.position.getValue(h):e.position),!c)return;if("number"==typeof c?.x&&"number"==typeof c?.y&&Math.abs(c.x)<=360&&Math.abs(c.y)<=90)d=c.x,u=c.y,p="number"==typeof c.z?c.z:0;else{const e=i.Cartographic.fromCartesian(c);if(!e)return;d=i.Math.toDegrees(e.longitude),u=i.Math.toDegrees(e.latitude),p=e.height}t=Math.min(t,d),n=Math.max(n,d),a=Math.min(a,u),o=Math.max(o,u),r=Math.min(r,p),s=Math.max(s,p),l++}catch(e){d.warn(`エンティティ ${c} の処理に失敗:`,e)}}),0===l)throw new Error("有効な位置情報を持つエンティティが見つかりません");return d.debug("座標範囲計算完了:",{validCount:l,bounds:{minLon:t,maxLon:n,minLat:a,maxLat:o,minAlt:r,maxAlt:s}}),{minLon:t,maxLon:n,minLat:a,maxLat:o,minAlt:r,maxAlt:s,centerLon:(t+n)/2,centerLat:(a+o)/2,centerAlt:(r+s)/2}}static voxelIndexToCoordinate(e,t,i,n,a){const{minLon:o,maxLon:r,minLat:s,maxLat:l,minAlt:h,maxAlt:c}=n,{numVoxelsX:d,numVoxelsY:u,numVoxelsZ:p}=a;return{lon:o+(e+.5)/d*(r-o),lat:s+(t+.5)/u*(l-s),alt:h+(i+.5)/p*(c-h)}}static coordinateToCartesian3(e,t,n){return i.Cartesian3.fromDegrees(e,t,n)}}class z{static createGrid(e,t){const i=(e.minLat+e.maxLat)/2,n=111e3*(e.maxLon-e.minLon)*Math.cos(i*Math.PI/180),a=111e3*(e.maxLat-e.minLat),o=e.maxAlt-e.minAlt,r=Math.max(1,Math.ceil(n/t)),s=Math.max(1,Math.ceil(a/t)),l=Math.max(1,Math.ceil(o/t)),h=r>0?n/r:t,c=s>0?a/s:t,u=l>0?Math.max(o/l,1):Math.max(t,1),p=r*s*l;return d.debug("VoxelGrid created:",{numVoxelsX:r,numVoxelsY:s,numVoxelsZ:l,totalVoxels:p,voxelSizeMeters:t,cellSizeX:h,cellSizeY:c,cellSizeZ:u,lonRangeMeters:n,latRangeMeters:a,altRangeMeters:o}),{numVoxelsX:r,numVoxelsY:s,numVoxelsZ:l,totalVoxels:p,voxelSizeMeters:t,cellSizeX:h,cellSizeY:c,cellSizeZ:u,lonRangeMeters:n,latRangeMeters:a,altRangeMeters:o}}static getVoxelKey(e,t,i){return`${e},${t},${i}`}static parseVoxelKey(e){const[t,i,n]=e.split(",").map(Number);return{x:t,y:i,z:n}}static iterateAllVoxels(e,t){const{numVoxelsX:i,numVoxelsY:n,numVoxelsZ:a}=e;for(let e=0;e<i;e++)for(let i=0;i<n;i++)for(let n=0;n<a;n++)t(e,i,n,this.getVoxelKey(e,i,n))}}class R{static convert(e,t,i,n){e=R._normalizeLongitude(e),t=R._clampLatitude(t),n=Math.max(0,Math.min(35,Math.floor(n)));const a=Math.pow(2,n),o=Math.floor((e+180)/360*a),r=t*Math.PI/180,s=Math.floor((1-Math.log(Math.tan(r)+1/Math.cos(r))/Math.PI)/2*a),l=R._getAltitudePerBin(n,t),h=Math.floor(i/l);return{zfxy:{z:n,f:h,x:o,y:s},zfxyStr:`/${n}/${h}/${o}/${s}`,vertices:R._calculateVertices(e,t,i,n,o,s,h,l)}}static _normalizeLongitude(e){if(180===e)return-180;for(;e>180;)e-=360;for(;e<-180;)e+=360;return e}static _clampLatitude(e){const t=85.0511287798;return Math.max(-t,Math.min(t,e))}static _getAltitudePerBin(e,t){const i=r,n=Math.max(0,Math.min(35,Math.floor(e))),a=Number.isFinite(t)?t*Math.PI/180:0,o=i*Math.max(Math.cos(a),1e-5)/Math.pow(2,n)*1;return Math.min(5e3,Math.max(.5,o))}static _calculateVertices(e,t,i,n,a,o,r,s){const l=Math.pow(2,n),h=a/l*360-180,c=(a+1)/l*360-180,d=Math.atan(Math.sinh(Math.PI*(1-2*(o+1)/l))),u=Math.atan(Math.sinh(Math.PI*(1-2*o/l))),p=180*d/Math.PI,m=180*u/Math.PI,g=r*s,f=(r+1)*s;return[{lng:h,lat:p,alt:g},{lng:c,lat:p,alt:g},{lng:c,lat:m,alt:g},{lng:h,lat:m,alt:g},{lng:h,lat:p,alt:f},{lng:c,lat:p,alt:f},{lng:c,lat:m,alt:f},{lng:h,lat:m,alt:f}]}static validateZFXY(e){if(!e||"object"!=typeof e)return!1;const{z:t,f:i,x:n,y:a}=e;if(!(Number.isInteger(t)&&Number.isInteger(i)&&Number.isInteger(n)&&Number.isInteger(a)))return!1;if(t<0||t>35)return!1;const o=Math.pow(2,t);return!(n<0||n>=o||a<0||a>=o)}static parseZFXYStr(e){if("string"!=typeof e)return null;const t=e.split("/").filter(e=>e.length>0);if(4!==t.length)return null;const[i,n,a,o]=t.map(e=>parseInt(e,10));if(Number.isNaN(i)||Number.isNaN(n)||Number.isNaN(a)||Number.isNaN(o))return null;const r={z:i,f:n,x:a,y:o};return R.validateZFXY(r)?r:null}}class A{constructor(e={}){this.provider=e.provider||"ouranos-gex",this.Space=null,this.fallbackMode=!1,this.loaded=!1}async loadProvider(){if(this.loaded)return!this.fallbackMode;if("ouranos-gex"!==this.provider)return d.warn(`SpatialIdAdapter: Unknown provider '${this.provider}', using built-in fallback`),this.fallbackMode=!0,this.loaded=!0,!1;try{const e=await Promise.resolve().then(function(){var e=new Error("Cannot find module 'ouranos-gex-lib-for-javascript'");throw e.code="MODULE_NOT_FOUND",e});return this.Space=e.Space,this.fallbackMode=!1,this.loaded=!0,d.info("SpatialIdAdapter: ouranos-gex loaded successfully"),!0}catch(e){return d.warn("SpatialIdAdapter: ouranos-gex not available, using built-in fallback",e.message),this.fallbackMode=!0,this.loaded=!0,!1}}neighbors(e){const{z:t,f:i,x:n,y:a}=e,o=Math.pow(2,t),r=[];for(let e=-1;e<=1;e++)for(let s=-1;s<=1;s++){if(0===s&&0===e)continue;const l=a+e;if(l<0||l>=o)continue;const h=(n+s+o)%o;r.push({z:t,f:i,x:h,y:l})}return r}children(e){const{z:t,f:i,x:n,y:a}=e,o=t+1,r=2*n,s=2*a,l=Math.pow(2,o),h=[];for(let e=0;e<=1;e++)for(let t=0;t<=1;t++){const n=(r+t)%l,a=s+e;a<0||a>=l||h.push({z:o,f:i,x:n,y:a})}return h}parent(e){const{z:t,f:i,x:n,y:a}=e;return t<=0?null:{z:t-1,f:i,x:Math.floor(n/2),y:Math.floor(a/2)}}getVoxelBounds(e,t,i,n){if(!this.loaded)throw new Error("SpatialIdAdapter: loadProvider() must be called before getVoxelBounds()");if(!this.Space||this.fallbackMode){const a=R.convert(e,t,i,n);return a.vertices=A._normalizeVertices(a.vertices),a}try{const a=new this.Space({lng:e,lat:t,alt:i},n),o="function"==typeof a.vertices3d?a.vertices3d():[],r=A._normalizeVertices(o);return{zfxy:a.zfxy,zfxyStr:a.zfxyStr,vertices:r}}catch(a){return d.warn("SpatialIdAdapter: ouranos-gex error, falling back to built-in converter",a.message),R.convert(e,t,i,n)}}calculateOptimalZoom(e,t,i=10){let n=25,a=1/0,o=null,r=1/0;for(let s=15;s<=30;s++){const l=this._calculateCellSizeAtZoom(s,t),h=Math.abs(l-e)/e;h<a&&(n=s,a=h),h<=i/100&&h<r&&(o=s,r=h)}const s=null!==o?o:n,l=this._calculateCellSizeAtZoom(s,t),h=Math.abs(l-e)/e*100;return d.debug(`SpatialIdAdapter: Optimal zoom ${s} for target size ${e}m (cell size: ${l.toFixed(1)}m, error: ${h.toFixed(1)}%)${null===o?" [closest, exceeds tolerance]":""}`),s}static _normalizeVertices(e){return Array.isArray(e)?e.map((e,t)=>{if(Array.isArray(e)){const[t,i,n]=e;return{lng:A._toNumber(t),lat:A._toNumber(i),alt:A._toNumber(n)}}if(e&&"object"==typeof e){const t=e.lng??e.lon??e.longitude,i=e.lat??e.latitude,n=e.alt??e.altitude??e.height;return{lng:A._toNumber(t),lat:A._toNumber(i),alt:A._toNumber(n)}}return d.warn("SpatialIdAdapter: Unexpected vertex format from provider",{index:t,vertex:e}),{lng:0,lat:0,alt:0}}):[]}static _toNumber(e){const t=Number(e);return Number.isFinite(t)?t:0}_calculateCellSizeAtZoom(e,t){const i=r,n=t*Math.PI/180;return i*Math.cos(n)/Math.pow(2,e)}getStatus(){return{provider:this.provider,loaded:this.loaded,fallbackMode:this.fallbackMode}}}function O(e,t=i.JulianDate.now()){if(null==e)return e;try{if("function"==typeof e.getValue)return e.getValue(t);if("function"==typeof e.get)return e.get(t)}catch(e){return}return e}function N(e){if(0===e.length)throw new Error("mean requires at least one data point");return function(e){if(0===e.length)return 0;var t,i=e[0],n=0;if("number"!=typeof i)return Number.NaN;for(var a=1;a<e.length;a++){if("number"!=typeof e[a])return Number.NaN;t=i+e[a],Math.abs(i)>=Math.abs(e[a])?n+=i-t+e[a]:n+=e[a]-t+i,i=t}return i+n}(e)/e.length}function V(e){if(1===e.length)return 0;var t=function(e){if(0===e.length)throw new Error("variance requires at least one data point");return function(e,t){var i,n,a=N(e),o=0;if(2===t)for(n=0;n<e.length;n++)o+=(i=e[n]-a)*i;else for(n=0;n<e.length;n++)o+=Math.pow(e[n]-a,t);return o}(e,2)/e.length}(e);return Math.sqrt(t)}function I(e){if(0===e.length)throw new Error("min requires at least one data point");for(var t=e[0],i=1;i<e.length;i++)e[i]<t&&(t=e[i]);return t}function F(e){if(0===e.length)throw new Error("max requires at least one data point");for(var t=e[0],i=1;i<e.length;i++)e[i]>t&&(t=e[i]);return t}function L(e,t){for(var i=[],n=0;n<e;n++){for(var a=[],o=0;o<t;o++)a.push(0);i.push(a)}return i}function k(e,t,i,n){var a;if(e>0){var o=(i[t]-i[e-1])/(t-e+1);a=n[t]-n[e-1]-(t-e+1)*o*o}else a=n[t]-i[t]*i[t]/(t+1);return a<0?0:a}function D(e,t,i,n,a,o,r){if(!(e>t)){var s=Math.floor((e+t)/2);n[i][s]=n[i-1][s-1],a[i][s]=s;var l=i;e>i&&(l=Math.max(l,a[i][e-1]||0)),l=Math.max(l,a[i-1][s]||0);var h,c,d,u=s-1;t<n[0].length-1&&(u=Math.min(u,a[i][t+1]||0));for(var p=u;p>=l&&!((h=k(p,s,o,r))+n[i-1][l-1]>=n[i][s]);--p)(c=k(l,s,o,r)+n[i-1][l-1])<n[i][s]&&(n[i][s]=c,a[i][s]=l),l++,(d=h+n[i-1][p-1])<n[i][s]&&(n[i][s]=d,a[i][s]=p);D(e,s-1,i,n,a,o,r),D(s+1,t,i,n,a,o,r)}}var $=function(){this.totalCount=0,this.data={}};$.prototype.train=function(e,t){for(var i in this.data[t]||(this.data[t]={}),e){var n=e[i];void 0===this.data[t][i]&&(this.data[t][i]={}),void 0===this.data[t][i][n]&&(this.data[t][i][n]=0),this.data[t][i][n]++}this.totalCount++},$.prototype.score=function(e){var t,i={};for(var n in e){var a=e[n];for(t in this.data)i[t]={},this.data[t][n]?i[t][n+"_"+a]=(this.data[t][n][a]||0)/this.totalCount:i[t][n+"_"+a]=0}var o={};for(t in i)for(var r in o[t]=0,i[t])o[t]+=i[t][r];return o};var E=function(){this.weights=[],this.bias=0};E.prototype.predict=function(e){if(e.length!==this.weights.length)return null;for(var t=0,i=0;i<this.weights.length;i++)t+=this.weights[i]*e[i];return(t+=this.bias)>0?1:0},E.prototype.train=function(e,t){if(0!==t&&1!==t)return null;e.length!==this.weights.length&&(this.weights=e,this.bias=1);var i=this.predict(e);if("number"==typeof i&&i!==t){for(var n=t-i,a=0;a<this.weights.length;a++)this.weights[a]+=n*e[a];this.bias+=n}return this},Math.log(Math.sqrt(2*Math.PI)),Math.sqrt(2*Math.PI);var T=Math.sqrt(2*Math.PI);function P(e){for(var t=e,i=e,n=1;n<15;n++)t+=i*=e*e/(2*n+1);return Math.round(1e4*(.5+t/T*Math.exp(-e*e/2)))/1e4}for(var W=[],B=0;B<=3.09;B+=.01)W.push(P(B));let j={quantile:(e,t)=>Array.isArray(e)&&0!==e.length?function(e,t){var i=e.length*t;if(0===e.length)throw new Error("quantile requires at least one data point.");if(t<0||t>1)throw new Error("quantiles must be between 0 and 1");return 1===t?e[e.length-1]:0===t?e[0]:i%1!=0?e[Math.ceil(i)-1]:e.length%2==0?(e[i-1]+e[i])/2:e[i]}([...e].sort((e,t)=>e-t),t):NaN,ckmeans(e,t){if(!Array.isArray(e)||0===e.length||!t||t<2)return[];try{return function(e,t){if(t>e.length)throw new Error("cannot generate more classes than there are data values");var i=function(e){return e.slice().sort(function(e,t){return e-t})}(e),n=function(e){for(var t,i=0,n=0;n<e.length;n++)0!==n&&e[n]===t||(t=e[n],i++);return i}(i);if(1===n)return[i];var a=L(t,i.length),o=L(t,i.length);!function(e,t,i){for(var n=t[0].length,a=e[Math.floor(n/2)],o=[],r=[],s=0,l=void 0;s<n;++s)l=e[s]-a,0===s?(o.push(l),r.push(l*l)):(o.push(o[s-1]+l),r.push(r[s-1]+l*l)),t[0][s]=k(0,s,o,r),i[0][s]=0;for(var h=1;h<t.length;++h)D(h<t.length-1?h:n-1,n-1,h,t,i,o,r)}(i,a,o);for(var r=[],s=o[0].length-1,l=o.length-1;l>=0;l--){var h=o[l][s];r[l]=i.slice(h,s+1),l>0&&(s=h-1)}return r}(e,t)}catch(e){return[]}},jenksBreaks(e,t){if(!Array.isArray(e)||0===e.length||!t||t<2)return[];const i="function"==typeof this?.ckmeans?this.ckmeans(e,t):[],n=[];for(let e=0;e<i.length-1;e++){const t=i[e];Array.isArray(t)&&t.length>0&&n.push(t[t.length-1])}return n},summary:e=>Array.isArray(e)&&0!==e.length?{min:I(e),max:F(e),mean:N(e),stddev:V(e)}:{min:NaN,max:NaN,mean:NaN,stddev:NaN}};function H(){return j}function U(e){if(e instanceof i.Color)return e;if(Array.isArray(e)){const[t,n,a,o=1]=e;return new i.Color(t,n,a,o)}return"string"==typeof e?i.Color.fromCssColorString(e):i.Color.WHITE.clone()}function Y(e={}){const{scheme:t="linear",values:n=null,domain:a=null,breaks:o=null,classes:r=5,thresholds:s=null,colorMap:l=null}=e,h=Math.max(2,r||2);let c,d=0,u=1;if(Array.isArray(a)&&2===a.length)[d,u]=a;else if(Array.isArray(n)&&n.length>0){const e=H().summary(n);d=e.min,u=e.max}u===d&&(u=d+1);let p=[];switch(t){case"linear":{const e=u-d||1;c=t=>(t-d)/e,p=[d,u];break}case"log":{d<=0&&(d=1);const e=Math.log(d),t=Math.log(u>d?u:d+1)-e||1;c=i=>i<=0?0:(Math.log(i)-e)/t,p=[d,u];break}case"equal-interval":if(Array.isArray(o)&&o.length>=2)p=[...o];else{p=[];for(let e=0;e<=h;e++)p.push(d+e/h*(u-d))}c=e=>{for(let t=0;t<p.length-1;t++){const i=p[t],n=p[t+1];if(e<=n)return(t+(e-i)/(n-i||1))/h}return 1};break;case"quantize":if(Array.isArray(o)&&o.length>=2)p=[...o];else{p=[];for(let e=0;e<=h;e++)p.push(d+e/h*(u-d))}c=e=>{for(let t=0;t<p.length-1;t++)if(e<=p[t+1])return t/(h-1);return 1};break;case"threshold":if(Array.isArray(o)&&o.length>=2)p=[...o];else{if(!Array.isArray(s)||0===s.length)throw new Error("threshold scheme requires thresholds array");p=[d,...s,u]}c=e=>{for(let t=0;t<p.length-1;t++)if(e<=p[t+1])return t/(p.length-2);return 1};break;case"quantile":if(Array.isArray(o)&&o.length>=2)p=[...o];else{if(!Array.isArray(n)||0===n.length)throw new Error("quantile scheme requires values array");{const e=H();p=[d];const t=Math.max(2,h);for(let i=1;i<t;i++)p.push(e.quantile(n,i/t));p.push(u)}}c=e=>{for(let t=0;t<p.length-1;t++)if(e<=p[t+1])return p.length>2?t/(p.length-2):0;return 1};break;case"jenks":if(Array.isArray(o)&&o.length>=2)p=[...o];else{if(!Array.isArray(n)||0===n.length)throw new Error("jenks scheme requires values array");{const e=H().jenksBreaks(n,h);if(p=[d],Array.isArray(e))for(const t of e)Number.isFinite(t)&&t>d&&t<u&&p.push(t);p.push(u)}}c=e=>{for(let t=0;t<p.length-1;t++)if(e<=p[t+1])return p.length>2?t/(p.length-2):0;return 1};break;default:throw new Error(`unknown classification scheme: ${t}`)}const m=function(e){if(!Array.isArray(e)||0===e.length)return null;if(e.every(e=>e&&"object"==typeof e&&Object.prototype.hasOwnProperty.call(e,"position")))return e;const t=e.length>1?e.length-1:1;return e.map((i,n)=>({position:1===e.length?0:n/t,color:i}))}(l),g=m?e=>function(e,t){if(!Array.isArray(e)||0===e.length)return i.Color.WHITE.clone();if(1===e.length)return U(e[0].color).clone();const n=Math.max(0,Math.min(1,t)),a=[...e].sort((e,t)=>e.position-t.position);if(n<=a[0].position)return U(a[0].color).clone();if(n>=a[a.length-1].position)return U(a[a.length-1].color).clone();for(let e=0;e<a.length-1;e++){const t=a[e],o=a[e+1];if(n>=t.position&&n<=o.position){const e=o.position-t.position||1,a=(n-t.position)/e,r=U(t.color),s=U(o.color);return i.Color.lerp(r,s,a,new i.Color)}}return U(a[a.length-1].color).clone()}(m,Math.max(0,Math.min(1,e))):e=>i.Color.lerp(i.Color.BLUE||new i.Color(0,0,1,1),i.Color.RED||new i.Color(1,0,0,1),Math.max(0,Math.min(1,e)),new i.Color),f="threshold"===t?Math.max(1,p.length>1?p.length-1:h):Math.max(1,h);let y;return y="threshold"===t?e=>{for(let t=0;t<p.length-1;t++)if(e<=p[t+1])return t;return p.length-2}:e=>{const t=Math.max(0,Math.min(1,c(e)));return Math.min(h-1,Math.floor(t*h))},{scheme:t,domain:[d,u],breaks:p,classes:"threshold"===t&&p.length>1?p.length-1:h,normalize:c,getColorForClass:e=>{const t=Number.isFinite(e)?Math.max(0,Math.min(f-1,Math.round(e))):0;return g(1===f?0:t/(f-1))},getColor:e=>g(Math.max(0,Math.min(1,e))),classify:y}}class X{static async classifyEntitiesIntoVoxels(e,t,n,a={}){if(a.spatialId?.enabled)return await X._classifyBySpatialId(e,t,n,a);const o=new Map;let r=0,s=0;const l=a.aggregation||{},h=Boolean(l.enabled),c=i.JulianDate.now(),u="string"==typeof l.byProperty&&""!==l.byProperty.trim()?l.byProperty.trim():null,p="function"==typeof l.keyResolver?l.keyResolver:null;let m=null;if(h&&(p||u?m=(e,t)=>{let i;if(p){try{i=p(e)}catch(e){return d.warn(`[aggregation] keyResolver threw error for entity ${t}, using "unknown"`,e),"unknown"}i=O(i,c)}else if(u){let t;try{const i=e.properties?.getValue?.(c);i&&"object"==typeof i&&u in i&&(t=i[u])}catch(e){d.warn(`[aggregation] Failed to resolve PropertyBag for ${u}, fallback to direct property`,e)}if(void 0===t){const i=e.properties?.[u];t=O(i,c)}i=t}if(null==i||"number"==typeof i&&Number.isNaN(i))return"unknown";const n=String(i);return""===n.trim()?"unknown":n}:(d.warn('[aggregation] enabled but no byProperty or keyResolver specified, using "default" key'),m=()=>"default")),d.debug(`Processing ${e.length} entities for classification`),e.forEach((e,a)=>{try{let l,d,u,p;if(e.position&&(l="function"==typeof e.position.getValue?e.position.getValue(c):e.position),!l)return void s++;if("number"==typeof l?.x&&"number"==typeof l?.y&&Math.abs(l.x)<=360&&Math.abs(l.y)<=90)d=l.x,u=l.y,p="number"==typeof l.z?l.z:0;else if(i.Cartographic&&"function"==typeof i.Cartographic.fromCartesian){const e=i.Cartographic.fromCartesian(l);if(!e)return void s++;d=i.Math.toDegrees(e.longitude),u=i.Math.toDegrees(e.latitude),p=e.height}else{if("number"!=typeof l.x||"number"!=typeof l.y)return void s++;d=l.x,u=l.y,p="number"==typeof l.z?l.z:0}if(d<t.minLon-.001||d>t.maxLon+.001||u<t.minLat-.001||u>t.maxLat+.001||p<t.minAlt-1||p>t.maxAlt+1)return void s++;const{x:g,y:f,z:y}=X._normalizeGridIndices(d,u,p,t,n);if(g>=0&&g<n.numVoxelsX&&f>=0&&f<n.numVoxelsY&&y>=0&&y<n.numVoxelsZ){const t=z.getVoxelKey(g,f,y);if(!o.has(t)){const e={x:g,y:f,z:y,entities:[],count:0};h&&(e.layerStats=new Map),o.set(t,e)}const i=o.get(t);if(i.entities.push(e),i.count++,h&&m){const t=m(e,a)||"unknown",n=i.layerStats.get(t)||0;i.layerStats.set(t,n+1)}r++}else s++}catch(e){d.warn(`エンティティ ${a} の処理に失敗:`,e),s++}}),h){for(const e of o.values())if(e.layerStats&&e.layerStats.size>0){let t=0,i=null;for(const[n,a]of e.layerStats)a>t&&(t=a,i=n);e.layerTop=i}d.debug(`[aggregation] Calculated layerTop for ${o.size} voxels`)}return d.info(`${r}個のエンティティを${o.size}個のボクセルに分類(${s}個はスキップ)`),o}static calculateStatistics(e,t,i={}){if(i._externalStats){d.debug("Using external statistics:",i._externalStats);const n=Number.isFinite(i._externalStats.minCount)?i._externalStats.minCount:Number.isFinite(i._externalStats.min)?i._externalStats.min:0,a=Number.isFinite(i._externalStats.maxCount)?i._externalStats.maxCount:Number.isFinite(i._externalStats.max)?i._externalStats.max:n,o={...i._externalStats,min:n,max:a,minCount:n,maxCount:a,totalVoxels:t.totalVoxels,renderedVoxels:0,nonEmptyVoxels:e.size,emptyVoxels:Math.max(0,t.totalVoxels-e.size),totalEntities:0};let r=0;for(const t of e.values())r+=t.count;return o.totalEntities=r,o.averageCount=e.size>0?r/e.size:0,o.classification||(o.classification=X._buildClassificationStats([],i.classification,o.minCount,o.maxCount),o.domain&&(o.classification.domain=o.domain)),o}if(0===e.size){const e={totalVoxels:t.totalVoxels,renderedVoxels:0,nonEmptyVoxels:0,emptyVoxels:t.totalVoxels,totalEntities:0,minCount:0,maxCount:0,averageCount:0,autoAdjusted:!1,originalVoxelSize:null,finalVoxelSize:null,adjustmentReason:null};return e.classification=X._buildClassificationStats([],i.classification,0,0),e}const n=Array.from(e.values()).map(e=>e.count),a=n.reduce((e,t)=>e+t,0),o=Math.max(0,t.totalVoxels-e.size),r={totalVoxels:t.totalVoxels,renderedVoxels:0,nonEmptyVoxels:e.size,emptyVoxels:o,totalEntities:a,minCount:Math.min(...n),maxCount:Math.max(...n),averageCount:a/e.size,autoAdjusted:!1,originalVoxelSize:null,finalVoxelSize:null,adjustmentReason:null};return r.classification=X._buildClassificationStats(n,i.classification,r.minCount,r.maxCount),d.debug("統計情報計算完了:",r),r}static _normalizeGridIndices(e,t,i,n,a){const o=(e,t,i,n)=>{const a=Number.isFinite(i-t)?i-t:0,o=Number.isFinite(e)?e:t,r=(e=>{const t=Number.isFinite(e)?Math.floor(e):0;return t>0?t:1})(n);if(0===a)return 0;const s=(o-t)/a,l=Math.floor(s*r),h=r-1,c=Number.isFinite(l)?l:0;return Math.max(0,Math.min(h,c))};return{x:o(e,n.minLon,n.maxLon,a.numVoxelsX),y:o(t,n.minLat,n.maxLat,a.numVoxelsY),z:o(i,n.minAlt,n.maxAlt,a.numVoxelsZ)}}static getTopNVoxels(e,t){if(0===e.size||t<=0)return[];const i=Array.from(e.values()).sort((e,t)=>t.count-e.count);return i.slice(0,Math.min(t,i.length))}static async _classifyBySpatialId(e,t,n,a){d.debug(`Spatial ID mode enabled: ${a.spatialId.mode}`);const o=new A({provider:a.spatialId.provider||"ouranos-gex"});let r;await o.loadProvider();const s=(t.minLat+t.maxLat)/2;if("auto"===a.spatialId.zoomControl){const e=a.voxelSize||30,t=a.spatialId.zoomTolerancePct||10;r=o.calculateOptimalZoom(e,s,t),d.info(`Auto-selected zoom level ${r} for target size ${e}m (lat: ${s.toFixed(4)}°)`)}else{const e=a.spatialId.zoom;"number"==typeof e&&Number.isFinite(e)&&e>=0&&e<=35?r=Math.floor(e):(r=25,d.warn(`Invalid zoom value in manual mode (${e}), using default zoom level ${r}`)),d.info(`Using manual zoom level ${r}`)}a._resolvedZoom=r,a._spatialIdProvider=o.fallbackMode?null:a.spatialId.provider;const l=a.aggregation||{},h=Boolean(l.enabled),c=i.JulianDate.now(),u="string"==typeof l.byProperty&&""!==l.byProperty.trim()?l.byProperty.trim():null,p="function"==typeof l.keyResolver?l.keyResolver:null;let m=null;h&&(p||u?m=(e,t)=>{let i;if(p){try{i=p(e)}catch(e){return d.warn(`[aggregation] keyResolver threw error for entity ${t}, using "unknown"`,e),"unknown"}i=O(i,c)}else if(u){let t;try{const i=e.properties?.getValue?.(c);i&&"object"==typeof i&&u in i&&(t=i[u])}catch(e){d.warn(`[aggregation] Failed to resolve PropertyBag for ${u}, fallback to direct property`,e)}if(void 0===t){const i=e.properties?.[u];t=O(i,c)}i=t}if(null==i||"number"==typeof i&&Number.isNaN(i))return"unknown";const n=String(i);return""===n.trim()?"unknown":n}:(d.warn('[aggregation] enabled but no byProperty or keyResolver specified, using "default" key'),m=()=>"default"));const g=new Map;let f=0,y=0,x=0;for(const a of e){try{let e,s,l,d;if(a.position&&(e="function"==typeof a.position.getValue?a.position.getValue(c):a.position),!e){y++;continue}if("number"==typeof e?.x&&"number"==typeof e?.y&&Math.abs(e.x)<=360&&Math.abs(e.y)<=90)s=e.x,l=e.y,d="number"==typeof e.z?e.z:0;else if(i.Cartographic&&"function"==typeof i.Cartographic.fromCartesian){const t=i.Cartographic.fromCartesian(e);if(!t){y++;continue}s=i.Math.toDegrees(t.longitude),l=i.Math.toDegrees(t.latitude),d=t.height}else{if("number"!=typeof e.x||"number"!=typeof e.y){y++;continue}s=e.x,l=e.y,d="number"==typeof e.z?e.z:0}const{zfxy:u,zfxyStr:p,vertices:v}=o.getVoxelBounds(s,l,d,r);if(!g.has(p)){const e=v.reduce((e,t)=>e+t.lng,0)/8,i=v.reduce((e,t)=>e+t.lat,0)/8,a=v.reduce((e,t)=>e+t.alt,0)/8,{x:o,y:r,z:s}=X._normalizeGridIndices(e,i,a,t,n),l={key:p,x:o,y:r,z:s,bounds:v,spatialId:{...u,id:p},entities:[],count:0};h&&(l.layerStats=new Map),g.set(p,l)}const b=g.get(p);if(b.entities.push(a),b.count++,h&&m){const e=m(a,x)||"unknown",t=b.layerStats.get(e)||0;b.layerStats.set(e,t+1)}f++}catch(e){d.warn("Failed to process entity for spatial ID:",e),y++}x++}if(h){for(const e of g.values())if(e.layerStats&&e.layerStats.size>0){let t=0,i=null;for(const[n,a]of e.layerStats)a>t&&(t=a,i=n);e.layerTop=i}d.debug(`[aggregation] Calculated layerTop for ${g.size} voxels (Spatial ID mode)`)}return d.info(`Spatial ID: ${f} entities classified into ${g.size} voxels (${y} skipped)`),g}static _buildClassificationStats(e,t={},i,n){const a=t&&"object"==typeof t?t:{},o=Boolean(a.enabled),r=(a.scheme||"linear").toLowerCase(),s=Math.max(2,a.classes||5);let l=null;if(Array.isArray(a.domain)&&2===a.domain.length){const[e,t]=a.domain;Number.isFinite(e)&&Number.isFinite(t)&&(l=[e,t])}if(!l){const e=Number.isFinite(i)?i:0;l=[e,Number.isFinite(n)?n:e]}const h=[...Array.isArray(e)?e.filter(e=>Number.isFinite(e)):[]].sort((e,t)=>e-t),c={enabled:o,scheme:r,domain:l,classes:a.classes??s,thresholds:a.thresholds??null,sampleSize:h.length,quantiles:null,histogram:null,breaks:null,jenksBreaks:null,ckmeansClusters:null};if(0===h.length)return c;try{const e=H();c.quantiles=[e.quantile(h,.25),e.quantile(h,.5),e.quantile(h,.75),e.quantile(h,1)]}catch(e){d.warn("Failed to compute quantiles for classification statistics:",e),c.quantiles=null}c.histogram=X._createHistogramFromSorted(h);const u=Math.min(Math.max(2,s),h.length);if(o&&"jenks"===r&&h.length>=2&&u>=2)try{const e=H(),t=e.jenksBreaks(h,u);if(c.jenksBreaks=Array.isArray(t)&&t.length>0?t:null,"function"==typeof e.ckmeans){const t=e.ckmeans(h,u);c.ckmeansClusters=Array.isArray(t)&&t.length>0?t:null}}catch(e){d.warn("Failed to compute jenks statistics:",e),c.jenksBreaks=null,c.ckmeansClusters=null}if(o)try{const e=Y({scheme:r,classes:a.classes,thresholds:a.thresholds,colorMap:a.colorMap,domain:l,values:h});c.breaks=e.breaks||null}catch(e){d.warn("Failed to build classifier for statistics:",e),c.breaks=null}return c}static _createHistogramFromSorted(e,t=10){if(!Array.isArray(e)||0===e.length)return null;const i=e[0],n=e[e.length-1];if(!Number.isFinite(i)||!Number.isFinite(n))return null;if(i===n)return{bins:[{start:i,end:n}],counts:[e.length]};const a=Math.max(1,Math.min(t,e.length)),o=(n-i)/a||1,r=[],s=new Array(a).fill(0);for(let e=0;e<a;e++){const t=i+o*e,s=e===a-1?n:t+o;r.push({start:t,end:s})}for(const t of e){if(!Number.isFinite(t))continue;let e=Math.floor((t-i)/o);e<0?e=0:e>=a&&(e=a-1),s[e]++}return{bins:r,counts:s}}}const q=Object.freeze({viridis:Object.freeze([[68,1,84],[72,40,120],[62,74,137],[49,104,142],[38,130,142],[31,158,137],[53,183,121],[109,205,89],[180,222,44],[253,231,37]]),inferno:Object.freeze([[0,0,4],[31,12,72],[85,15,109],[136,34,106],[186,54,85],[227,89,51],[249,142,8],[252,187,17],[245,219,76],[252,255,164]]),diverging:Object.freeze([[0,0,255],[32,64,255],[64,128,255],[96,160,255],[128,192,255],[160,224,255],[192,240,255],[224,248,255],[255,255,255],[255,248,224],[255,240,192],[255,224,160],[255,192,128],[255,160,96],[255,128,64],[255,64,32],[255,0,0]])});class Z{static calculateColor(e,t=null,n={}){try{Number.isFinite(e)||(d.warn(`Invalid normalizedDensity: ${e}. Using 0.5 as fallback.`),e=.5);const{minColor:i=[0,0,255],maxColor:a=[255,0,0],colorMap:o,diverging:r=!1,divergingPivot:s=0}=n;if(r&&null!==t){const e="number"==typeof s?s:0;return Z.calculateDivergingColor(t,{divergingPivot:e})}return o&&"custom"!==o?Z.interpolateFromColorMap(e,o):Z.interpolateLinear(e,i,a)}catch(e){return d.warn(`Color calculation failed: ${e.message}. Falling back to gray.`),i.Color.GRAY}}static interpolateLinear(e,t,n){const a=Math.max(0,Math.min(1,e)),[o,r,s]=t,[l,h,c]=n,d=Math.round(o+(l-o)*a),u=Math.round(r+(h-r)*a),p=Math.round(s+(c-s)*a);return i.Color.fromBytes(d,u,p)}static interpolateFromColorMap(e,t){const n=q[t];if(!n)return d.warn(`Unknown color map: ${t}. Falling back to linear interpolation.`),Z.interpolateLinear(e,[0,0,255],[255,0,0]);const a=Math.max(0,Math.min(1,e))*(n.length-1),o=Math.floor(a),r=Math.min(o+1,n.length-1),s=a-o,[l,h,c]=n[o],[u,p,m]=n[r],g=Math.round(l+(u-l)*s),f=Math.round(h+(p-h)*s),y=Math.round(c+(m-c)*s);return i.Color.fromBytes(g,f,y)}static calculateDivergingColor(e,t={}){const{divergingPivot:i=0}=t,n=i;let a;return 0===n?e<0?(a=1/(1-e)*.5,a=Math.max(0,Math.min(.5,a))):e>0?(a=.5+e/(1+e)*.5,a=Math.max(.5,Math.min(1,a))):a=.5:e<=n?(a=e/n*.5,a=Math.max(0,Math.min(.5,a))):(a=.5+(e-n)/n*.5,a=Math.max(.5,Math.min(1,a))),Z.interpolateFromColorMap(a,"diverging")}static getAvailableColorMaps(){return Object.keys(q)}static isValidColorMap(e){return Object.hasOwn(q,e)}}class J{constructor(e={}){this.options={renderLimitStrategy:"density",highlightTopN:0,coverageBinsXY:"auto",minCoverageRatio:.2,...e},this._lastSelectionStats=null,d.debug(`VoxelSelector initialized with strategy: ${this.options.renderLimitStrategy}`)}selectVoxels(e,t,i={}){try{if(!Array.isArray(e)||0===e.length)return d.warn("VoxelSelector: Empty or invalid voxel array provided"),this._createEmptyResult();if(t<=0)return d.warn(`VoxelSelector: Invalid maxCount: ${t}`),this._createEmptyResult();if(e.length<=t)return this._createResult(e,this.options.renderLimitStrategy,e.length,0);const{grid:n}=i,a=this.options.renderLimitStrategy||"density",o=this._identifyTopNVoxels(e);let r;switch(a){case"coverage":r=this._selectByCoverageStrategy(e,t,n,o);break;case"hybrid":r=this._selectByHybridStrategy(e,t,n,o);break;default:r=this._selectByDensityStrategy(e,t,o)}return this._lastSelectionStats={strategy:r.strategy,clippedNonEmpty:r.clippedNonEmpty,coverageRatio:r.coverageRatio||null,selectedCount:r.selectedVoxels.length,totalCount:e.length},d.debug(`VoxelSelector: Applied ${r.strategy} strategy - selected ${r.selectedVoxels.length}/${e.length} voxels`),r}catch(i){return d.error(`VoxelSelector: Selection failed: ${i.message}. Falling back to density strategy.`),this._fallbackToDensitySelection(e,t)}}getLastSelectionStats(){return this._lastSelectionStats}_identifyTopNVoxels(e){const t=new Set;if(this.options.highlightTopN&&this.options.highlightTopN>0){const i=[...e].sort((e,t)=>t.info.count-e.info.count).slice(0,this.options.highlightTopN);i.forEach(e=>t.add(e.key)),d.debug(`VoxelSelector: Identified ${i.length} TopN voxels for forced inclusion`)}return t}_selectByDensityStrategy(e,t,i=new Set){const n=[...e].sort((e,t)=>t.info.count-e.info.count),a=[],o=new Set;n.forEach(e=>{i.has(e.key)&&a.length<t&&(a.push(e),o.add(e.key))}),n.forEach(e=>{!o.has(e.key)&&a.length<t&&(a.push(e),o.add(e.key))});const r=e.length-a.length;return this._createResult(a,"density",a.length,r)}_selectByCoverageStrategy(e,t,i,n=new Set){const a=[],o=new Set;e.forEach(e=>{n.has(e.key)&&a.length<t&&(a.push(e),o.add(e.key))});const r="auto"===this.options.coverageBinsXY?Math.ceil(Math.sqrt(t/4)):this.options.coverageBinsXY,s=new Map;e.filter(e=>!o.has(e.key)).forEach(e=>{const t=`${Math.max(0,Math.min(r-1,Math.floor(e.info.x/Math.max(1,i.numVoxelsX)*r)))},${Math.max(0,Math.min(r-1,Math.floor(e.info.y/Math.max(1,i.numVoxelsY)*r)))}`;s.has(t)||s.set(t,[]),s.get(t).push(e)});const l=Array.from(s.keys());let h=0;for(;a.length<t&&h<10*l.length;){const e=l[h%l.length],t=s.get(e);if(t&&t.length>0){t.sort((e,t)=>t.info.count-e.info.count);const i=t.shift();o.has(i.key)||(a.push(i),o.add(i.key)),0===t.length&&(s.delete(e),l.splice(l.indexOf(e),1))}h++}const c=e.length-a.length;return this._createResult(a,"coverage",a.length,c)}_selectByHybridStrategy(e,t,i,n=new Set){const a=this.options.minCoverageRatio||.2,o=[],r=new Set;e.forEach(e=>{n.has(e.key)&&o.length<t&&(o.push(e),r.add(e.key))});const s=t-o.length,l=Math.floor(s*a),h=s-l;l>0&&this._selectByCoverageStrategy(e.filter(e=>!r.has(e.key)),l,i,new Set).selectedVoxels.forEach(e=>{o.length<t&&!r.has(e.key)&&(o.push(e),r.add(e.key))}),h>0&&this._selectByDensityStrategy(e.filter(e=>!r.has(e.key)),h,new Set).selectedVoxels.forEach(e=>{o.length<t&&!r.has(e.key)&&(o.push(e),r.add(e.key))});const c=l>0?(o.length-n.size-h)/(o.length-n.size):0,d=e.length-o.length;return this._createResult(o,"hybrid",o.length,d,c)}_fallbackToDensitySelection(e,t){try{const i=new Set,n=this._selectByDensityStrategy(e,t,i);return n.strategy="density-fallback",this._lastSelectionStats={strategy:n.strategy,clippedNonEmpty:n.clippedNonEmpty,coverageRatio:null,selectedCount:n.selectedVoxels.length,totalCount:e.length,error:!0},n}catch(e){return d.error(`VoxelSelector: Even fallback failed: ${e.message}`),this._createEmptyResult()}}_createResult(e,t,i,n,a=null){return{selectedVoxels:e,strategy:t,clippedNonEmpty:n,coverageRatio:a}}_createEmptyResult(){return{selectedVoxels:[],strategy:"none",clippedNonEmpty:0,coverageRatio:null}}}const G=n.adaptiveParams||{};class K{constructor(e={}){const t={...G,...e.adaptiveParams||{}};this.options={...e,adaptiveParams:t},d.debug("AdaptiveController initialized with options:",this.options)}calculateNeighborhoodDensity(e,t,i=null,n=null){if(!t||"function"!=typeof t.get)return{isDenseArea:!1,neighborhoodDensity:0,neighborCount:0};const{x:a,y:o,z:r}=e,s={...G,...this.options?.adaptiveParams||{},...n?.adaptiveParams||{}},l=s.neighborhoodRadius??G.neighborhoodRadius??30,h=null!==i?i:Math.max(1,Math.floor(l/20));let c=0,d=0;for(let e=-h;e<=h;e++)for(let i=-h;i<=h;i++)for(let n=-h;n<=h;n++){if(0===e&&0===i&&0===n)continue;const s=`${a+e},${o+i},${r+n}`,l=t.get(s);l&&(c+=l.count,d++)}const u=d>0?c/d:0;return{totalDensity:c,neighborCount:d,avgDensity:u,isDenseArea:u>(s.densityThreshold??G.densityThreshold??5),searchRadius:h}}_calculateZScaleCompensation(e,t){const i=this.options.adaptiveParams||G;if(!t||!i.zScaleCompensation)return 1;const{cellSizeX:n,cellSizeY:a,cellSizeZ:o}=t;if(!n||!a||!o)return 1;const r=o/((n+a)/2);return r<.1?Math.max(.7,Math.min(1.3,1+2*(.1-r))):1}_countAdjacentVoxels(e,t){if(!e||!t||"function"!=typeof t.get)return 0;const{x:i,y:n,z:a}=e,o=[[1,0,0],[-1,0,0],[0,1,0],[0,-1,0],[0,0,1],[0,0,-1]];let r=0;for(const[e,s,l]of o){const o=`${i+e},${n+s},${a+l}`;t.get(o)&&r++}return r}_detectOverlapAndRecommendMode(e,t,i=null){const n=i||this.options||{},a={...G,...this.options?.adaptiveParams||{},...i?.adaptiveParams||{}},o=n.outlineRenderMode||"standard",r=n.outlineInset||0;if(!a.overlapDetection)return{recommendedMode:o,recommendedInset:r};const s=this._countAdjacentVoxels(e,t)/6;return s>.5&&"emulation-only"!==o?{recommendedMode:"inset",recommendedInset:Math.max(.3,.8-.4*s),reason:`High overlap risk (${(100*s).toFixed(0)}%)`}:{recommendedMode:o,recommendedInset:r}}applyPresetLogic(e,t,i,n,a){let o,r,s;switch(e){case"thin":o=Math.max(1,.8*a.outlineWidth),r=a.opacity,s=a.outlineOpacity||.8;break;case"medium":case"uniform":default:o=a.outlineWidth,r=a.opacity,s=a.outlineOpacity||1;break;case"thick":o=Math.max(1,1.5*a.outlineWidth),r=a.opacity,s=a.outlineOpacity||1;break;case"adaptive":case"adaptive-density":{const e=n?Math.max(.6,.8+.3*(i-.5)):1;o=Math.max(1,Math.min(3*a.outlineWidth,a.outlineWidth*e)),r=n?.8*a.opacity:a.opacity,s=n?.6:1;break}case"topn-focus":o=t?Math.max(1,Math.min(3*a.outlineWidth,a.outlineWidth*(1.5+.5*i))):Math.max(1,.8*a.outlineWidth),r=t?a.opacity:.6*a.opacity,s=t?1:.4}return{adaptiveWidth:o,adaptiveBoxOpacity:r,adaptiveOutlineOpacity:s}}calculateAdaptiveParams(e,t,i,a,o,r=null,s=null){if(!e||!a||!o)return{outlineWidth:null,boxOpacity:null,outlineOpacity:null,shouldUseEmulation:!1};const l=o.classification||{},h=l.classificationTargets||n.classification.classificationTargets||{},c=Boolean(l.enabled&&s),u=(h.opacity||h.width)&&c;if(!o.adaptiveOutlines&&!u)return{outlineWidth:null,boxOpacity:null,outlineOpacity:null,shouldUseEmulation:!1};const{count:p}=e,m=a.maxCount>a.minCount?(p-a.minCount)/(a.maxCount-a.minCount):0;let g=null,f=null;if(c)try{g=Math.max(0,Math.min(1,s.normalize(p??0))),f=s.classify(p??0)}catch(e){d.warn("AdaptiveController classification normalize failed, fallback to density:",e),g=null}const y=null!==g?g:m,x=this.calculateNeighborhoodDensity(e,i,null,o),{isDenseArea:v}=x,b=this._calculateZScaleCompensation(e,r),M=this._detectOverlapAndRecommendMode(e,i,o),w={...G,...this.options?.adaptiveParams||{},...o?.adaptiveParams||{}},_=w.cameraDistanceFactor??1,S=w.overlapRiskFactor??0,C=Math.min(1,1)*_,z=v?S:0,R=this.applyPresetLogic(o.outlineWidthPreset,t,m,v,o),A=o&&o.adaptiveParams||w||{},O=(e,t,i=null)=>{if(Array.isArray(e)&&2===e.length){const[i,n]=e,a=(n??0)-(i??0);return(i??0)+Math.max(0,Math.min(1,t))*a}return i};let N=R.adaptiveWidth*C*b,V=Math.max(.2,R.adaptiveOutlineOpacity*(1-z));if(h.width&&c){const e=O(A.outlineWidthRange,y,N);null!=e&&(N=e+(t&&o.highlightTopN&&o.highlightTopNWidthBoost||0))}if(h.opacity&&c){const e=O(A.boxOpacityRange,y,R.adaptiveBoxOpacity),t=O(A.outlineOpacityRange,y,V);null!=e&&(R.adaptiveBoxOpacity=e),null!=t&&(V=t)}const I=(e,t,i,n)=>{let a=e;if(Array.isArray(t)&&2===t.length){const[e,o]=t,r=null!=e?e:i,s=null!=o?o:n;a=Math.min(s??a,Math.max(r??a,a))}return null!=i&&(a=Math.max(i,a)),null!=n&&(a=Math.min(n,a)),a};return{outlineWidth:I(Math.max(1,N),A.outlineWidthRange,w.minOutlineWidth??1,w.maxOutlineWidth??null),boxOpacity:I(Math.max(0,Math.min(1,R.adaptiveBoxOpacity)),A.boxOpacityRange,0,1),outlineOpacity:I(Math.max(.2,Math.min(1,V)),A.outlineOpacityRange,0,1),shouldUseEmulation:v||N>2&&"standard"!==o.outlineRenderMode,_debug:{normalizedDensity:m,classificationNormalized:g,classificationIndex:f,neighborhoodResult:x,cameraFactor:C,overlapRisk:z,zScaleFactor:b,overlapRecommendation:M,preset:o.outlineWidthPreset}}}updateOptions(e){this.options={...this.options,...e,adaptiveParams:{...this.options.adaptiveParams,...e.adaptiveParams||{}}},d.debug("AdaptiveController options updated:",this.options)}getConfiguration(){return{...this.options,version:"0.1.11",phase:"ADR-0009 Phase 3"}}}const Q={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","`":"&#96;"},ee=/[&<>"'`]/g;function te(e){return"string"!=typeof e?null==e?"":String(e):e.replace(ee,e=>Q[e]||e)}class ie{constructor(e,t={}){this.viewer=e,this.options={wireframeOnly:!1,showOutline:!0,outlineWidth:2,outlineInset:0,outlineInsetMode:"all",outlineRenderMode:"standard",enableThickFrames:!1,...t},this.entities=[],d.debug("GeometryRenderer initialized with viewer and options:",this.options)}createVoxelBox(e){const{centerLon:t,centerLat:n,centerAlt:a,cellSizeX:o,cellSizeY:r,boxHeight:s,color:l,opacity:h,shouldShowOutline:c,outlineColor:u,outlineWidth:p,voxelInfo:m,voxelKey:g,emulateThick:f=!1}=e,y=Number.isFinite(t)?Math.max(-180,Math.min(180,t)):0,x=Number.isFinite(n)?Math.max(-90,Math.min(90,n)):0,v=Number.isFinite(a)?Math.max(-1e4,Math.min(1e5,a)):0,b=Number.isFinite(o)&&o>0?Math.min(o,1e6):1,M=Number.isFinite(r)&&r>0?Math.min(r,1e6):1,w=Number.isFinite(s)&&s>0?Math.min(s,1e6):1;y===t&&x===n&&v===a&&b===o&&M===r&&w===s||d.warn(`Clamped invalid geometry values for voxel ${g}:`,{original:{centerLon:t,centerLat:n,centerAlt:a,cellSizeX:o,cellSizeY:r,boxHeight:s},clamped:{safeCenterLon:y,safeCenterLat:x,safeCenterAlt:v,safeCellSizeX:b,safeCellSizeY:M,safeBoxHeight:w}});const _=Boolean(c&&!f),S={dimensions:new i.Cartesian3(b,M,w),outline:_};_&&(S.outlineColor=u,S.outlineWidth=Math.max(p||1,1));const C={position:i.Cartesian3.fromDegrees(y,x,v),box:S,properties:{type:"voxel",key:g,count:m.count,x:m.x,y:m.y,z:m.z},description:this.createVoxelDescription(m,g)};if(m.spatialId&&(C.properties.spatialId=m.spatialId),m.layerTop&&(C.properties.layerTop=m.layerTop),m.layerStats){const e={};for(const[t,i]of m.layerStats)e[t]=i;C.properties.layerStats=e}this.options.wireframeOnly||"emulation-only"===this.options.outlineRenderMode?(C.box.material=i.Color.TRANSPARENT,C.box.fill=!1):(C.box.material=l.withAlpha(h),C.box.fill=!0);const z=this.viewer.entities.add(C);return this.entities.push(z),z}createInsetOutline(e){const{centerLon:t,centerLat:n,centerAlt:a,baseSizeX:o,baseSizeY:r,baseSizeZ:s,outlineColor:l,outlineWidth:h,voxelKey:c,insetAmount:u=null}=e,p=Number.isFinite(t)?Math.max(-180,Math.min(180,t)):0,m=Number.isFinite(n)?Math.max(-90,Math.min(90,n)):0,g=Number.isFinite(a)?Math.max(-1e4,Math.min(1e5,a)):0,f=Number.isFinite(o)&&o>0?Math.min(o,1e6):1,y=Number.isFinite(r)&&r>0?Math.min(r,1e6):1,x=Number.isFinite(s)&&s>0?Math.min(s,1e6):1,v=.2*f,b=.2*y,M=.2*x,w=null!==u?u:this.options.outlineInset,_=Math.min(w,v),S=Math.min(w,b),C=Math.min(w,M),z=Math.max(f-2*_,.1*f),R=Math.max(y-2*S,.1*y),A=Math.max(x-2*C,.1*x),O=this.viewer.entities.add({position:i.Cartesian3.fromDegrees(p,m,g),box:{dimensions:new i.Cartesian3(z,R,A),fill:!1,outline:!0,outlineColor:l,outlineWidth:Math.max(h||1,1)},properties:{type:"voxel-inset-outline",parentKey:c,insetSize:{x:z,y:R,z:A}}});return this.entities.push(O),this.options.enableThickFrames&&(_>.1||S>.1||C>.1)&&this.createThickOutlineFrames({centerLon:p,centerLat:m,centerAlt:g,outerX:f,outerY:y,outerZ:x,innerX:z,innerY:R,innerZ:A,frameColor:l,voxelKey:c}),d.debug(`Inset outline created for voxel ${c}:`,{originalSize:{x:o,y:r,z:s},insetSize:{x:z,y:R,z:A},effectiveInset:{x:_,y:S,z:C}}),O}createThickOutlineFrames(e){const{centerLon:t,centerLat:n,centerAlt:a,outerX:o,outerY:r,outerZ:s,innerX:l,innerY:h,innerZ:c,frameColor:u,voxelKey:p}=e;let m=(o-l)/2,g=(r-h)/2,f=(s-c)/2;const y=.05;if(m<=0||g<=0||f<=0)return d.warn(`Invalid frame thickness for voxel ${p}, skipping thick frames`),[];m=Math.max(m,y),g=Math.max(g,y),f=Math.max(f,y);const x=o/2,v=r/2,b=s/2,M=[],w=[{x,z:b,sizeX:m,sizeZ:f},{x:-x,z:b,sizeX:m,sizeZ:f},{x,z:-b,sizeX:m,sizeZ:f},{x:-x,z:-b,sizeX:m,sizeZ:f}],_=[{x,y:v,sizeX:m,sizeY:g},{x:-x,y:v,sizeX:m,sizeY:g},{x,y:-v,sizeX:m,sizeY:g},{x:-x,y:-v,sizeX:m,sizeY:g}];return[{y:v,z:b,sizeY:g,sizeZ:f},{y:-v,z:b,sizeY:g,sizeZ:f},{y:v,z:-b,sizeY:g,sizeZ:f},{y:-v,z:-b,sizeY:g,sizeZ:f}].forEach((e,r)=>{const s=i.Cartesian3.fromDegrees(t,n+e.y/111320,a+e.z),l=this.viewer.entities.add({position:s,box:{dimensions:new i.Cartesian3(o,e.sizeY,e.sizeZ),fill:!0,material:u.withAlpha(.3),outline:!1},properties:{type:"voxel-thick-frame-x",parentKey:p,frameIndex:r}});this.entities.push(l),M.push(l)}),w.forEach((e,o)=>{const s=i.Cartesian3.fromDegrees(t+e.x/(111320*Math.cos(n*Math.PI/180)),n,a+e.z),l=this.viewer.entities.add({position:s,box:{dimensions:new i.Cartesian3(e.sizeX,r,e.sizeZ),fill:!0,material:u.withAlpha(.3),outline:!1},properties:{type:"voxel-thick-frame-y",parentKey:p,frameIndex:o}});this.entities.push(l),M.push(l)}),_.forEach((e,o)=>{const r=i.Cartesian3.fromDegrees(t+e.x/(111320*Math.cos(n*Math.PI/180)),n+e.y/111320,a),l=this.viewer.entities.add({position:r,box:{dimensions:new i.Cartesian3(e.sizeX,e.sizeY,s),fill:!0,material:u.withAlpha(.3),outline:!1},properties:{type:"voxel-thick-frame-z",parentKey:p,frameIndex:o}});this.entities.push(l),M.push(l)}),d.debug(`Created ${M.length} thick frame entities for voxel ${p}`),M}createEdgePolylines(e){const{centerLon:t,centerLat:n,centerAlt:a,cellSizeX:o,cellSizeY:r,boxHeight:s,outlineColor:l,outlineWidth:h,outlineOpacity:c=null,voxelKey:u}=e,p=[],m=Number.isFinite(t)?Math.max(-180,Math.min(180,t)):0,g=Number.isFinite(n)?Math.max(-85,Math.min(85,n)):0,f=Number.isFinite(a)?Math.max(-1e4,Math.min(1e5,a)):0,y=Number.isFinite(o)&&o>0?Math.min(o,1e5):1,x=Number.isFinite(r)&&r>0?Math.min(r,1e5):1,v=Number.isFinite(s)&&s>0?Math.min(s,1e5):1;if(y<.001||x<.001||v<.001)return d.warn(`Dimensions too small for voxel ${u}, skipping edge polylines`),p;const b=y/2,M=x/2,w=v/2,_=Math.cos(g*Math.PI/180),S=b/(111320*Math.max(.1,Math.abs(_))),C=M/111320;if(!Number.isFinite(S)||!Number.isFinite(C)||Math.abs(S)>.1||Math.abs(C)>.1)return d.warn(`Coordinate offsets out of range for voxel ${u}, skipping edge polylines`),p;const z=[[m-S,g-C,f-w],[m+S,g-C,f-w],[m+S,g+C,f-w],[m-S,g+C,f-w],[m-S,g-C,f+w],[m+S,g-C,f+w],[m+S,g+C,f+w],[m-S,g+C,f+w]];if(!z.every(([e,t,i])=>Number.isFinite(e)&&Number.isFinite(t)&&Number.isFinite(i)&&e>=-180&&e<=180&&t>=-85&&t<=85&&i>=-5e4&&i<=5e5))return d.warn(`Invalid vertex coordinates for voxel ${u}, skipping edge polylines`),p;let R;try{R=z.map(([e,t,n])=>i.Cartesian3.fromDegrees(e,t,n))}catch(e){return d.warn(`Failed to create Cartesian3 vertices for voxel ${u}:`,e),p}return R.every(e=>e&&Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.z))?([[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]].forEach((e,t)=>{try{const i=R[e[0]],n=R[e[1]];if(!i||!n)return void d.warn(`Missing vertices for edge ${t} in voxel ${u}`);const a=[i,n];if(2!==a.length)return void d.warn(`Invalid positions array length for edge ${t} in voxel ${u}`);let o=l;if(null!=c&&"function"==typeof l?.withAlpha){const e=Math.max(0,Math.min(1,c));o=l.withAlpha(e)}const r=Number.isFinite(h)?h:1,s=this.viewer.entities.add({polyline:{positions:a,width:Math.max(Math.min(r,20),1),material:o,clampToGround:!1},properties:{type:"voxel-edge-polyline",parentKey:u,edgeIndex:t}});this.entities.push(s),p.push(s)}catch(e){d.warn(`Failed to create polyline for edge ${t} in voxel ${u}:`,e)}}),d.debug(`Created ${p.length} edge polylines for voxel ${u}`),p):(d.warn(`Generated vertices contain invalid values for voxel ${u}, skipping edge polylines`),p)}createVoxelDescription(e,t){const i=e.spatialId?`\n <tr><td><b>空間ID:</b></td><td>${te(e.spatialId.id)}</td></tr>\n <tr><td><b>ズームレベル:</b></td><td>Z=${te(String(e.spatialId.z))}, F=${te(String(e.spatialId.f))}</td></tr>\n <tr><td><b>タイル座標:</b></td><td>X=${te(String(e.spatialId.x))}, Y=${te(String(e.spatialId.y))}</td></tr>\n `:"";let n="";if(this.options.aggregation?.enabled&&!1!==this.options.aggregation?.showInDescription&&e.layerStats&&e.layerStats.size>0){const t=Array.from(e.layerStats.entries()).sort((e,t)=>t[1]-e[1]).map(([t,i])=>{const n=e.count>0?(i/e.count*100).toFixed(1):"0.0";return`\n <tr><td style="padding-left: 10px;">${te(t)}</td><td>${i} (${n}%)</td></tr>\n `}).join("");n=`\n ${e.layerTop?`\n <tr><td><b>支配的レイヤ:</b></td><td>${te(e.layerTop)}</td></tr>\n `:""}\n <tr><td colspan="2"><b>レイヤ内訳:</b></td></tr>\n ${t}\n `}return`\n <div style="padding: 10px; font-family: Arial, sans-serif;">\n <h3 style="margin-top: 0;">ボクセル [${e.x}, ${e.y}, ${e.z}]</h3>\n <table style="width: 100%;">\n <tr><td><b>エンティティ数:</b></td><td>${e.count}</td></tr>\n <tr><td><b>ボクセルキー:</b></td><td>${te(t)}</td></tr>\n <tr><td><b>座標:</b></td><td>X=${e.x}, Y=${e.y}, Z=${e.z}</td></tr>${i}${n}\n </table>\n <p style="margin-bottom: 0;">\n <small>v0.1.18 GeometryRenderer (Layer aggregation support)</small>\n </p>\n </div>\n `}shouldApplyInsetOutline(e){switch(this.options.outlineInsetMode||"all"){case"topn":return e;case"all":default:return!0;case"none":return!1}}clear(){d.debug("GeometryRenderer.clear - Removing",this.entities.length,"entities"),this.entities.forEach(e=>{try{const t=!(!e||"function"!=typeof e.isDestroyed)&&e.isDestroyed();e&&!t&&this.viewer.entities.remove(e)}catch(e){d.warn("Entity removal error:",e)}}),this.entities=[]}renderBoundingBox(e){if(e)try{const t=(e.minLon+e.maxLon)/2,n=(e.minLat+e.maxLat)/2,a=(e.minAlt+e.maxAlt)/2,o=111e3*(e.maxLon-e.minLon)*Math.cos(n*Math.PI/180),r=111e3*(e.maxLat-e.minLat),s=e.maxAlt-e.minAlt,l=this.viewer.entities.add({position:i.Cartesian3.fromDegrees(t,n,a),box:{dimensions:new i.Cartesian3(o,r,s),material:i.Color.YELLOW.withAlpha(.1),outline:!0,outlineColor:i.Color.YELLOW.withAlpha(.3),outlineWidth:2},description:`Bounding Box<br>Size: ${o.toFixed(1)} x ${r.toFixed(1)} x ${s.toFixed(1)} m`});this.entities.push(l),d.debug("Debug bounding box added:",{center:{lon:t,lat:n,alt:a},size:{width:o,depth:r,height:s}})}catch(e){d.warn("Failed to render bounding box:",e)}}getEntityCount(){return this.entities.length}updateOptions(e){this.options={...this.options,...e},d.debug("GeometryRenderer options updated:",this.options)}getConfiguration(){return{...this.options,entityCount:this.entities.length,version:"0.1.11",phase:"ADR-0009 Phase 4"}}}class ne{constructor(e,t={}){this.viewer=e,this.options={minColor:[0,0,255],maxColor:[255,0,0],opacity:.8,emptyOpacity:.03,showOutline:!0,showEmptyVoxels:!1,wireframeOnly:!1,heightBased:!1,outlineWidth:2,outlineInset:0,outlineInsetMode:"all",outlineRenderMode:"standard",emulationScope:"off",adaptiveOutlines:!1,outlineWidthPreset:"medium",...t},this.options.classification&&"object"==typeof this.options.classification||(this.options.classification={enabled:!1}),this.voxelSelector=new J(this.options),this._selectionStats=null,this.adaptiveController=new K(this.options),this.geometryRenderer=new ie(this.viewer,this.options),Object.defineProperty(this,"voxelEntities",{get:()=>this.geometryRenderer.entities,enumerable:!0,configurable:!0}),this._currentVoxelData=null,this._classifier=null,d.debug("VoxelRenderer initialized with options:",this.options)}_calculateAdaptiveParams(e,t,i,n,a){return this.adaptiveController.calculateAdaptiveParams(e,t,i,n,this.options,a,this._classifier)}_shouldApplyInsetOutline(e){return this.geometryRenderer.shouldApplyInsetOutline(e)}render(e,t,i,n){this.geometryRenderer.clear(),d.debug("VoxelRenderer.render - Starting render with simplified approach",{voxelDataSize:e.size,bounds:t,grid:i,statistics:n}),this._currentVoxelData=e,this._prepareClassifier(n),this._shouldShowBounds()&&this.geometryRenderer.renderBoundingBox(t);let a=[];const o=new Set;if(this.options.showEmptyVoxels){const t=Math.min(i.totalVoxels,this.options.maxRenderVoxels||1e4);d.debug(`Generating grid for up to ${t} voxels`);for(let n=0;n<i.numVoxelsX;n++){for(let o=0;o<i.numVoxelsY;o++){for(let r=0;r<i.numVoxelsZ;r++){const i=`${n},${o},${r}`,s=e.get(i)||{x:n,y:o,z:r,count:0};if(a.push({key:i,info:s}),a.length>=t){d.debug(`Reached maximum voxel limit of ${t}`);break}}if(a.length>=t)break}if(a.length>=t)break}}else if(a=Array.from(e.entries()).map(([e,t])=>({key:e,info:t})),this.options.maxRenderVoxels&&a.length>this.options.maxRenderVoxels){const e=this._selectVoxelsForRendering(a,this.options.maxRenderVoxels,t,i);a=e.selectedVoxels,this._selectionStats={strategy:e.strategy,clippedNonEmpty:e.clippedNonEmpty,coverageRatio:e.coverageRatio||0},d.debug(`Applied ${e.strategy} strategy: ${a.length} voxels selected, ${e.clippedNonEmpty} clipped`)}this.options.highlightTopN&&this.options.highlightTopN>0&&([...a].sort((e,t)=>t.info.count-e.info.count).slice(0,this.options.highlightTopN).forEach(e=>o.add(e.key)),d.debug(`TopN highlight enabled: ${o.size} voxels will be highlighted`)),d.debug(`Rendering ${a.length} voxels`);let r=0;const s={x:0,y:0,z:0,count:0},l={voxel:s,isTopN:!1,normalizedDensity:0,statistics:n,adaptiveParams:null},h={voxel:s,isTopN:!1,normalizedDensity:0,statistics:n,adaptiveParams:null};return a.forEach(({key:e,info:a})=>{try{r+=this._renderSingleVoxel(e,a,t,i,n,o,s,l,h)}catch(e){d.warn("Error rendering voxel:",e)}}),d.info(`Successfully rendered ${r} voxels`),this._currentVoxelData=null,r}_renderSingleVoxel(e,t,i,n,a,o,r,s,l){const h=o.has(e),c=this._calculateVoxelRenderingParams(t,i,n,a,h,r,s,l);return c?(this._delegateVoxelRendering(e,c),1):0}_calculateVoxelRenderingParams(e,t,n,a,o,r,s,l){if(!(e&&t&&n&&a))return null;let h,c,d,u,p,m;if(e.bounds&&Array.isArray(e.bounds)&&8===e.bounds.length){const t=e.bounds;h=t.reduce((e,t)=>e+t.lng,0)/8,c=t.reduce((e,t)=>e+t.lat,0)/8,d=t.reduce((e,t)=>e+t.alt,0)/8;const n=i.Cartesian3.fromDegrees(t[0].lng,t[0].lat,t[0].alt),a=i.Cartesian3.fromDegrees(t[1].lng,t[1].lat,t[1].alt),o=i.Cartesian3.fromDegrees(t[3].lng,t[3].lat,t[3].alt),r=i.Cartesian3.fromDegrees(t[4].lng,t[4].lat,t[4].alt);u=i.Cartesian3.distance(n,a),p=i.Cartesian3.distance(n,o),m=i.Cartesian3.distance(n,r)}else{const{x:i,y:a,z:o}=e;h=t.minLon+(i+.5)*(t.maxLon-t.minLon)/n.numVoxelsX,c=t.minLat+(a+.5)*(t.maxLat-t.minLat)/n.numVoxelsY,d=t.minAlt+(o+.5)*(t.maxAlt-t.minAlt)/n.numVoxelsZ,u=n.cellSizeX||(n.lonRangeMeters?n.lonRangeMeters/n.numVoxelsX:n.voxelSizeMeters),p=n.cellSizeY||(n.latRangeMeters?n.latRangeMeters/n.numVoxelsY:n.voxelSizeMeters),m=n.cellSizeZ||(n.altRangeMeters?Math.max(n.altRangeMeters/Math.max(n.numVoxelsZ,1),1):Math.max(n.voxelSizeMeters,1))}const g=a.maxCount>a.minCount?(e.count-a.minCount)/(a.maxCount-a.minCount):0,f=this._calculateAdaptiveParams(e,o,this._currentVoxelData,a,n),{color:y,opacity:x}=this._calculateColorAndOpacity(e,g,o,f,a,r,l);let v,b,M;if(e.bounds){v=u,b=p;let e=m;this.options.voxelGap>0&&(v=Math.max(u-this.options.voxelGap,.1*u),b=Math.max(p-this.options.voxelGap,.1*p),e=Math.max(m-this.options.voxelGap,.1*m)),M=e,this.options.heightBased&&(M=e*(.1+.9*g))}else{const e=this._calculateDimensions(n,g);v=e.cellSizeX,b=e.cellSizeY,M=e.boxHeight}return{centerLon:h,centerLat:c,centerAlt:d,cellSizeX:v,cellSizeY:b,boxHeight:M,color:y,opacity:x,...this._calculateOutlineProperties(e,o,g,f,a,y,r,s),voxelInfo:e,isTopN:o,adaptiveParams:f}}_calculateColorAndOpacity(e,t,n,a,o,r,s){let l,h;if(0===e.count)l=i.Color.LIGHTGRAY,h=this.options.emptyOpacity;else{const i=this.options.classification?.classificationTargets||{};if(this._classifier&&!1!==i.color)try{const t=this._classifier.classify(e.count??0);l=this._classifier.getColorForClass(t)}catch(i){d.warn("Classification color calculation failed, falling back to legacy color:",i),l=Z.calculateColor(t,e.count,this.options)}else l=Z.calculateColor(t,e.count,this.options);if(this.options.boxOpacityResolver&&"function"==typeof this.options.boxOpacityResolver){r.x=e.x,r.y=e.y,r.z=e.z,r.count=e.count,s.isTopN=n,s.normalizedDensity=t,s.adaptiveParams=a;try{const e=this.options.boxOpacityResolver(s);h=isNaN(e)?this.options.opacity:Math.max(0,Math.min(1,e))}catch(e){d.warn("boxOpacityResolver error, using fallback:",e),h=a.boxOpacity??this.options.opacity}}else h=a.boxOpacity??this.options.opacity;this.options.highlightTopN&&!n&&(h*=1-(this.options.highlightStyle?.boostOpacity||.2))}return{color:l,opacity:h}}_calculateDimensions(e,t){let i=e.cellSizeX||(e.lonRangeMeters?e.lonRangeMeters/e.numVoxelsX:e.voxelSizeMeters),n=e.cellSizeY||(e.latRangeMeters?e.latRangeMeters/e.numVoxelsY:e.voxelSizeMeters),a=e.cellSizeZ||(e.altRangeMeters?Math.max(e.altRangeMeters/Math.max(e.numVoxelsZ,1),1):Math.max(e.voxelSizeMeters,1));this.options.voxelGap>0&&(i=Math.max(i-this.options.voxelGap,.1*i),n=Math.max(n-this.options.voxelGap,.1*n),a=Math.max(a-this.options.voxelGap,.1*a));let o=a;return this.options.heightBased&&(o=a*(.1+.9*t)),{cellSizeX:i,cellSizeY:n,boxHeight:o}}_calculateOutlineProperties(e,t,i,n,a,o,r,s){let l;if(this.options.outlineWidthResolver&&"function"==typeof this.options.outlineWidthResolver){r.x=e.x,r.y=e.y,r.z=e.z,r.count=e.count,s.isTopN=t,s.normalizedDensity=i,s.adaptiveParams=n;try{l=this.options.outlineWidthResolver(s),isNaN(l)&&(l=n.outlineWidth||this.options.outlineWidth)}catch(e){d.warn("outlineWidthResolver error, using fallback:",e),l=n.outlineWidth||this.options.outlineWidth}}else l=null!==n.outlineWidth&&void 0!==n.outlineWidth?n.outlineWidth:t&&this.options.highlightTopN&&this.options.highlightStyle?.outlineWidth||this.options.outlineWidth;const h=n.outlineOpacity??this.options.outlineOpacity??1,c=o.withAlpha(h),u=this._determineRenderModeConfig();let p=u.shouldUseEmulationOnly;if(!u.shouldUseEmulationOnly){const e=this.options.emulationScope||"off";"topn"===e?p=t&&(l||1)>1:"non-topn"===e?p=!t&&(l||1)>1:"all"===e?p=(l||1)>1:this.options.adaptiveOutlines&&n.shouldUseEmulation&&(p="off"!==e)}return{shouldShowOutline:u.shouldShowStandardOutline,outlineColor:c,outlineWidth:l||1,shouldShowInsetOutline:u.shouldShowInsetOutline,emulateThick:p}}_determineRenderModeConfig(){let e=!0,t=!1,i=!1;switch(this.options.outlineRenderMode){case"standard":e=this.options.showOutline,t=this.options.outlineInset>0;break;case"inset":e=!1,t=!0;break;case"emulation-only":e=!1,t=!1,i=!0}return{shouldShowStandardOutline:e,shouldShowInsetOutline:t,shouldUseEmulationOnly:i}}_delegateVoxelRendering(e,t){if(this.geometryRenderer.createVoxelBox({centerLon:t.centerLon,centerLat:t.centerLat,centerAlt:t.centerAlt,cellSizeX:t.cellSizeX,cellSizeY:t.cellSizeY,boxHeight:t.boxHeight,color:t.color,opacity:t.opacity,shouldShowOutline:t.shouldShowOutline,outlineColor:t.outlineColor,outlineWidth:t.outlineWidth,voxelInfo:t.voxelInfo,voxelKey:e,emulateThick:t.emulateThick}),t.shouldShowInsetOutline&&this.geometryRenderer.shouldApplyInsetOutline(t.isTopN))try{const i=this.options.outlineInset>0?this.options.outlineInset:1;this.geometryRenderer.createInsetOutline({centerLon:t.centerLon,centerLat:t.centerLat,centerAlt:t.centerAlt,baseSizeX:t.cellSizeX,baseSizeY:t.cellSizeY,baseSizeZ:t.boxHeight,outlineColor:t.outlineColor,outlineWidth:Math.max(t.outlineWidth,1),voxelKey:e,insetAmount:i})}catch(e){d.warn("Failed to create inset outline:",e)}if(("emulation-only"===this.options.outlineRenderMode||this.options.emulationScope&&"off"!==this.options.emulationScope)&&t.emulateThick)try{const i=t.adaptiveParams?.outlineOpacity??t.outlineColor?.alpha??null;this.geometryRenderer.createEdgePolylines({centerLon:t.centerLon,centerLat:t.centerLat,centerAlt:t.centerAlt,cellSizeX:t.cellSizeX,cellSizeY:t.cellSizeY,boxHeight:t.boxHeight,outlineColor:t.outlineColor,outlineWidth:Math.max(t.outlineWidth,1),outlineOpacity:i,voxelKey:e})}catch(e){d.warn("Failed to add emulated thick outline polylines:",e)}}interpolateColor(e,t=null){return Z.calculateColor(e,t,this.options)}_prepareClassifier(e){const t=this.options.classification,i=e?.classification||null;if(!t||!t.enabled)return void(this._classifier=null);const n=(t.scheme||"linear").toLowerCase();if(!["linear","log","equal-interval","quantize","threshold","quantile","jenks"].includes(n))return d.warn(`Classification scheme '${n}' is not supported in v1.0.0. Disabling classification.`),void(this._classifier=null);const a=Array.isArray(t.domain)&&2===t.domain.length?t.domain:Array.isArray(i?.domain)&&2===i.domain.length?i.domain:[e?.minCount??e?.min??0,e?.maxCount??e?.max??0];let o=null;const r=Array.isArray(i?.breaks)&&i.breaks.length>=2;if(!r&&this._currentVoxelData&&this._currentVoxelData.size>0){o=[];for(const e of this._currentVoxelData.values())e&&Number.isFinite(e.count)&&o.push(e.count);0===o.length&&(o=null)}try{this._classifier=Y({scheme:n,classes:t.classes,thresholds:t.thresholds,colorMap:t.colorMap,domain:a,breaks:r?i.breaks:null,values:o})}catch(e){d.warn("Failed to initialize classifier:",e),this._classifier=null}}clear(){this.geometryRenderer.clear()}_shouldShowBounds(){return!!this.options.debug&&("boolean"==typeof this.options.debug?this.options.debug:"object"==typeof this.options.debug&&null!==this.options.debug&&!0===this.options.debug.showBounds)}setVisible(e){d.debug("VoxelRenderer.setVisible:",e),this.voxelEntities.forEach(t=>{!t||t.isDestroyed&&t.isDestroyed()||(t.show=e)})}_selectVoxelsForRendering(e,t,i,n){const a=this.voxelSelector.selectVoxels(e,t,{grid:n,bounds:i});return this._selectionStats=this.voxelSelector.getLastSelectionStats(),a}getSelectionStats(){return this._selectionStats||null}}class ae{constructor(e={}){this.options={position:"top-right",fpsAveragingWindowMs:1e3,autoUpdate:!0,...e},this.element=null,this.isVisible=!1,this.updateInterval=null,this.frameTimeHistory=[],this.lastUpdateTime=Date.now(),this._createOverlay()}_createOverlay(){this.element=document.createElement("div"),this.element.id="cesium-heatbox-perf-overlay",this.element.style.cssText=`\n position: absolute;\n ${this._getPositionStyles()}\n background: rgba(0, 0, 0, 0.8);\n color: #fff;\n padding: 10px;\n border-radius: 5px;\n font-family: 'Courier New', monospace;\n font-size: 12px;\n line-height: 1.4;\n z-index: 1000;\n min-width: 200px;\n user-select: none;\n pointer-events: auto;\n display: none;\n `;const e=document.createElement("button");e.textContent="×",e.style.cssText="\n position: absolute;\n top: 2px;\n right: 5px;\n background: none;\n border: none;\n color: #fff;\n font-size: 16px;\n cursor: pointer;\n padding: 0;\n width: 20px;\n height: 20px;\n ",e.onclick=()=>this.hide(),this.element.appendChild(e),this.contentElement=document.createElement("div"),this.contentElement.style.marginTop="15px",this.element.appendChild(this.contentElement),document.body.appendChild(this.element)}_getPositionStyles(){const e={"top-left":"top: 10px; left: 10px;","top-right":"top: 10px; right: 10px;","bottom-left":"bottom: 10px; left: 10px;","bottom-right":"bottom: 10px; right: 10px;"};return e[this.options.position]||e["top-right"]}show(){this.element&&(this.element.style.display="block",this.isVisible=!0,this.options.autoUpdate&&this.startAutoUpdate())}hide(){this.element&&(this.element.style.display="none",this.isVisible=!1,this.stopAutoUpdate())}toggle(){this.isVisible?this.hide():this.show()}update(e,t){if(!this.contentElement||!this.isVisible)return;void 0!==t&&this._trackFrameTime(t);const i=this._calculateFPS(),n=this._formatStats(e,i,t);this.contentElement.innerHTML=n}_trackFrameTime(e){const t=Date.now();this.frameTimeHistory.push({time:t,frameTime:e});const i=t-this.options.fpsAveragingWindowMs;this.frameTimeHistory=this.frameTimeHistory.filter(e=>e.time>i)}_calculateFPS(){if(this.frameTimeHistory.length<2)return 0;const e=this.frameTimeHistory.reduce((e,t)=>e+t.frameTime,0)/this.frameTimeHistory.length;return e>0?Math.round(1e3/e):0}_formatStats(e,t,i){const n=[];if(n.push('<div style="font-weight: bold; color: #4CAF50;">🚀 Performance Stats</div>'),n.push(""),t>0){const e=t>=30?"#4CAF50":t>=15?"#FF9800":"#F44336";n.push(`<div style="color: ${e};">FPS: ${t}</div>`)}if(void 0!==i){const e=i<=33?"#4CAF50":i<=66?"#FF9800":"#F44336";n.push(`<div style="color: ${e};">Frame: ${i.toFixed(1)}ms</div>`)}if(n.push(""),e){if(n.push('<div style="font-weight: bold;">Voxels:</div>'),n.push(` Total: ${e.totalVoxels||0}`),n.push(` Rendered: ${e.renderedVoxels||0}`),e.totalVoxels>0){const t=((e.renderedVoxels||0)/e.totalVoxels*100).toFixed(1);n.push(` Ratio: ${t}%`)}if(e.topNCount&&n.push(` TopN: ${e.topNCount}`),n.push(""),e.selectionStrategy&&(n.push('<div style="font-weight: bold;">Strategy:</div>'),n.push(` Selection: ${e.selectionStrategy}`),void 0!==e.coverageRatio&&n.push(` Coverage: ${(100*e.coverageRatio).toFixed(1)}%`),e.renderBudgetTier&&n.push(` Budget Tier: ${e.renderBudgetTier}`),n.push("")),e.adaptive){if(n.push('<div style="font-weight: bold; color: #2196F3;">📊 Adaptive Control:</div>'),void 0!==e.adaptive.denseModeCount){const t=e.renderedVoxels>0?(e.adaptive.denseModeCount/e.renderedVoxels*100).toFixed(1):"0.0";n.push(` Dense Areas: ${e.adaptive.denseModeCount} (${t}%)`)}if(void 0!==e.adaptive.emulationModeCount){const t=e.renderedVoxels>0?(e.adaptive.emulationModeCount/e.renderedVoxels*100).toFixed(1):"0.0";n.push(` Emulation: ${e.adaptive.emulationModeCount} (${t}%)`)}if(void 0!==e.adaptive.avgOutlineWidth){const t=e.adaptive.avgOutlineWidth>=1&&e.adaptive.avgOutlineWidth<=3?"#4CAF50":"#FF9800";n.push(` <span style="color: ${t};">Avg Width: ${e.adaptive.avgOutlineWidth.toFixed(2)}px</span>`)}if(void 0!==e.adaptive.overlapDetections){const t=e.renderedVoxels>0?(e.adaptive.overlapDetections/e.renderedVoxels*100).toFixed(1):"0.0",i=e.adaptive.overlapDetections>0?"#FF9800":"#4CAF50";n.push(` <span style="color: ${i};">Overlaps: ${e.adaptive.overlapDetections} (${t}%)</span>`)}void 0!==e.adaptive.zScaleAdjustments&&e.adaptive.zScaleAdjustments>0&&n.push(` Z-Scale Adj: ${e.adaptive.zScaleAdjustments}`),n.push("")}if(void 0!==e.renderTimeMs){const t=e.renderTimeMs<=50?"#4CAF50":e.renderTimeMs<=100?"#FF9800":"#F44336";n.push(`<div style="color: ${t};">Render Time: ${e.renderTimeMs.toFixed(1)}ms</div>`)}if(void 0!==e.memoryUsageMB){const t=e.memoryUsageMB<=50?"#4CAF50":e.memoryUsageMB<=100?"#FF9800":"#F44336";n.push(`<div style="color: ${t};">Memory: ${e.memoryUsageMB.toFixed(1)}MB</div>`)}}return n.join("<br>")}startAutoUpdate(){this.stopAutoUpdate(),this.updateInterval=setInterval(()=>{},100)}stopAutoUpdate(){this.updateInterval&&(clearInterval(this.updateInterval),this.updateInterval=null)}destroy(){this.stopAutoUpdate(),this.element&&this.element.parentNode&&this.element.parentNode.removeChild(this.element),this.element=null,this.contentElement=null}}function oe(e){if(!e)return"rgba(0,0,0,0)";if("string"==typeof e)return e;if("function"==typeof e.toCssHexString)return e.toCssHexString();if("function"==typeof e.toCssColorString)return e.toCssColorString();if("function"==typeof e.withAlpha){const t=e.withAlpha(1);if(t&&"function"==typeof t.toCssColorString)return t.toCssColorString()}return`rgba(${Math.min(255,Math.max(0,Math.round(255*(e.red??0))))}, ${Math.min(255,Math.max(0,Math.round(255*(e.green??0))))}, ${Math.min(255,Math.max(0,Math.round(255*(e.blue??0))))}, ${Math.min(1,Math.max(0,e.alpha??1))})`}class re{constructor(e={}){this.document=e.documentRef||("undefined"!=typeof document?document:null),this.container=e.container||null,this._ownsContainer=!1,this._classifier=null,this._classificationOptions=null,this.document&&(this.container||(this.container=this.document.createElement("div"),this.container.className="heatbox-legend",this.document.body.appendChild(this.container),this._ownsContainer=!0))}render(e,t={}){if(!this.container||!this.document)return null;this._classifier=e,this._classificationOptions=t,this.container.innerHTML="",this.container.style.padding="8px",this.container.style.background="rgba(0,0,0,0.6)",this.container.style.color="#fff",this.container.style.fontSize="12px",this.container.style.borderRadius="4px",this.container.style.maxWidth="240px";const i=this.document.createElement("div");if(i.textContent="Legend",i.style.fontWeight="bold",i.style.marginBottom="6px",this.container.appendChild(i),!e){const e=this.document.createElement("div");return e.textContent="分類が有効ではありません",this.container.appendChild(e),this.container}const n=t.classificationTargets||{},a=Object.entries(n).filter(([,e])=>!1!==e).map(([e])=>e);if(a.length>0){const e=this.document.createElement("div");e.textContent=`Targets: ${a.join(", ")}`,e.style.marginBottom="4px",this.container.appendChild(e)}const o=this.document.createElement("div");o.style.display="flex",o.style.flexDirection="column",o.style.gap="4px";const r=e.breaks||[],s=e.classes??(r.length>1?r.length-1:0);for(let t=0;t<s;t++){const i=this.document.createElement("div");i.className="heatbox-legend-item",i.style.display="flex",i.style.alignItems="center",i.style.gap="6px";const n=this.document.createElement("span");n.className="heatbox-legend-swatch",n.style.display="inline-block",n.style.width="12px",n.style.height="12px",n.style.borderRadius="2px",n.style.border="1px solid rgba(255,255,255,0.3)",n.style.background=oe(e.getColorForClass(t));const a=this.document.createElement("span");let s=`Class ${t+1}`;r.length>t+1&&(s=`${r[t]} - ${r[t+1]}`),a.textContent=s,i.appendChild(n),i.appendChild(a),o.appendChild(i)}return this.container.appendChild(o),this.container}update(e,t){return this.render(e??this._classifier,t??this._classificationOptions)}destroy(){this.container&&this._ownsContainer&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=null,this.document=null}}class se{constructor(e,t={}){this._options=t,this._entries=this._normalizeAndSort(e),this._currentIndex=0,this._currentEntry=null,this._globalStatsCache={},this._searchCount=0,this._cacheHits=0}_normalizeAndSort(e){if(!Array.isArray(e)||0===e.length)throw new Error("Temporal data must be a non-empty array");const t=e.map((e,t)=>{if(!e.start||!e.stop||!e.data)throw new Error(`Invalid entry at index ${t}: missing start, stop, or data`);const n=this._toJulianDate(e.start),a=this._toJulianDate(e.stop);if(i.JulianDate.greaterThan(n,a))throw new Error(`Invalid time range at index ${t}: start > stop`);return i.JulianDate.equals(n,a)&&i.JulianDate.addSeconds(n,1,a),{start:n,stop:a,data:e.data}});t.sort((e,t)=>i.JulianDate.compare(e.start,t.start));const n=this._options.overlapResolution||"prefer-earlier";return"skip"===n?(this._validateNoOverlap(t),t):"prefer-earlier"===n?this._resolvePreferEarlier(t):"prefer-later"===n?this._resolvePreferLater(t):t}_toJulianDate(e){if(e instanceof i.JulianDate)return e;if("string"==typeof e)return i.JulianDate.fromIso8601(e);if(e instanceof Date)return i.JulianDate.fromDate(e);if("number"==typeof e)return i.JulianDate.fromDate(new Date(1e3*e));throw new Error("Unsupported time format: "+typeof e)}_validateNoOverlap(e){for(let t=0;t<e.length-1;t++){const n=e[t],a=e[t+1];if(i.JulianDate.greaterThan(n.stop,a.start))throw new Error(`Data overlap detected: entry ${t} stops at ${n.stop}, but entry ${t+1} starts at ${a.start}`)}}_resolvePreferEarlier(e){const t=[];for(const n of e){const e=t[t.length-1];if(e){if(i.JulianDate.greaterThan(e.stop,n.start)){if(i.JulianDate.greaterThanOrEquals(e.stop,n.stop))continue;if(n.start=i.JulianDate.clone(e.stop),!i.JulianDate.lessThan(n.start,n.stop))continue}t.push(n)}else t.push(n)}return t}_resolvePreferLater(e){const t=[];for(const n of e){for(;t.length>0;){const e=t[t.length-1];if(!i.JulianDate.greaterThan(e.stop,n.start))break;if(i.JulianDate.lessThan(n.start,e.start)||i.JulianDate.equals(n.start,e.start))t.pop();else{if(e.stop=i.JulianDate.clone(n.start),i.JulianDate.lessThan(e.start,e.stop))break;t.pop()}}t.push(n)}return t}getEntry(e){if(this._searchCount++,this._currentEntry&&i.JulianDate.greaterThanOrEquals(e,this._currentEntry.start)&&i.JulianDate.lessThan(e,this._currentEntry.stop))return this._cacheHits++,this._currentEntry;const t=[this._currentIndex,this._currentIndex+1,this._currentIndex-1];for(const i of t)if(i>=0&&i<this._entries.length){const t=this._entries[i];if(this._isInRange(e,t))return this._currentIndex=i,this._currentEntry=t,t}const n=this._binarySearch(e);return n>=0?(this._currentIndex=n,this._currentEntry=this._entries[n],this._currentEntry):(this._currentEntry=null,null)}_isInRange(e,t){return i.JulianDate.greaterThanOrEquals(e,t.start)&&i.JulianDate.lessThan(e,t.stop)}_binarySearch(e){let t=0,n=this._entries.length-1;for(;t<=n;){const a=Math.floor((t+n)/2),o=this._entries[a];if(this._isInRange(e,o))return a;i.JulianDate.lessThan(e,o.start)?n=a-1:t=a+1}return-1}calculateGlobalStats(e="weight",t=null){const i=JSON.stringify({valueProperty:e,classification:t||null});if(this._globalStatsCache[i])return this._globalStatsCache[i];let n=1/0,a=-1/0,o=0,r=0;const s=[];for(const t of this._entries)if(Array.isArray(t.data))for(const i of t.data){const t=i[e]??1;"number"==typeof t&&(n=Math.min(n,t),a=Math.max(a,t),o+=t,r++,s.push(t))}if(0===r)return null;const l=o/r;s.sort((e,t)=>e-t);const h={min:n,max:a,minCount:n,maxCount:a,mean:l,median:this._calculateMedian(s),quantiles:this._calculateQuantiles(s,[.25,.5,.75]),domain:[n,a],count:r};return t&&t.enabled&&(h.classification=X._buildClassificationStats(s,t,n,a)),this._globalStatsCache[i]=h,h}_calculateMedian(e){if(0===e.length)return 0;const t=Math.floor(e.length/2);return e.length%2==0?(e[t-1]+e[t])/2:e[t]}_calculateQuantiles(e,t){return t.map(t=>{const i=Math.floor(e.length*t);return e[Math.min(i,e.length-1)]})}getCacheHitRate(){return this._searchCount>0?this._cacheHits/this._searchCount:0}getTimeRange(){return 0===this._entries.length?null:{start:this._entries[0].start,stop:this._entries[this._entries.length-1].stop}}}class le{constructor(e,t,i){this._viewer=e,this._heatbox=t,this._options=i,this._slicer=new se(i.data,i),this._lastUpdateTime=null,this._lastEntry=null,this._removeListener=null,this._isActive=!1}activate(){if(!this._isActive){if(this._isActive=!0,"global"===this._options.classificationScope){const e=this._heatbox.options||{},t=e.valueProperty||"weight",i=this._slicer.calculateGlobalStats(t,e.classification||null);this._heatbox._globalStats=i}this._removeListener=this._viewer.clock.onTick.addEventListener(this._onTick.bind(this)),this._onTick(this._viewer.clock)}}deactivate(){this._isActive&&(this._isActive=!1,this._removeListener&&(this._removeListener(),this._removeListener=null))}_onTick(e){const t=e.currentTime;if(!this._shouldUpdate(t))return;const i=this._slicer.getEntry(t);null!==i&&i===this._lastEntry||(this._lastEntry=i,this._updateHeatbox(i))}_shouldUpdate(e){const t=this._options.updateInterval;if("frame"===t||!t)return!0;const i=Date.now();return(null===this._lastUpdateTime||i-this._lastUpdateTime>=t)&&(this._lastUpdateTime=i,!0)}_updateHeatbox(e){if(!e)return void("clear"===this._options.outOfRangeBehavior&&this._heatbox.clear());const t={_skipRebuild:!1};"global"===this._options.classificationScope&&this._heatbox._globalStats&&(t._externalStats=this._heatbox._globalStats),this._heatbox.setData(e.data,t)}}class he{constructor(e,t={}){if(!function(e){if(!e)return!1;if(!e.scene||!e.entities||!e.scene.canvas)return!1;const t=e.scene.canvas;return!!(t.getContext("webgl2")||t.getContext("webgl")||t.getContext("experimental-webgl"))}(e))throw new Error("CesiumJS Viewerが無効です");this.viewer=e;let i={...t||{}};i.profile&&g().includes(i.profile)&&(i=y(i.profile,i),delete i.profile);const o={...n,...i};this.options=M(function(e){if("auto"!==e.renderBudgetMode&&"auto"!==e.maxRenderVoxels)return e;const t=function(){try{const e=function(){try{const e=document.createElement("canvas"),t=e.getContext("webgl2")||e.getContext("webgl");if(!t)return{webgl2:!1,maxTextureSize:0,maxRenderbufferSize:0};const i={webgl2:!!e.getContext("webgl2"),maxTextureSize:t.getParameter(t.MAX_TEXTURE_SIZE),maxRenderbufferSize:t.getParameter(t.MAX_RENDERBUFFER_SIZE)};return e.remove(),i}catch(e){return d.warn("WebGL info detection failed:",e),{webgl2:!1,maxTextureSize:0,maxRenderbufferSize:0}}}(),t=function(){try{return{deviceMemory:navigator.deviceMemory||null,hardwareConcurrency:navigator.hardwareConcurrency||null,devicePixelRatio:window.devicePixelRatio||1,screenPixels:screen.width*screen.height*Math.pow(window.devicePixelRatio||1,2),userAgent:navigator.userAgent}}catch(e){return d.warn("Device info detection failed:",e),{deviceMemory:null,hardwareConcurrency:null,devicePixelRatio:1,screenPixels:2073600,userAgent:""}}}();let i="mid",n="fallback";if(null!==t.deviceMemory)i=t.deviceMemory<=4?"low":t.deviceMemory<=8?"mid":"high",n="deviceMemory";else if(null!==t.hardwareConcurrency){const e=t.hardwareConcurrency*Math.min(t.screenPixels/2073600,2);i=e<=4?"low":e<=8?"mid":"high",n="hardwareConcurrency+resolution"}(e.maxTextureSize<4096||!e.webgl2)&&(i="high"===i?"mid":"low",n+="+webglLimits");const o=S[i];let r=Math.min(Math.floor((o.min+o.max)/2),a);try{const e=navigator&&navigator.userAgent?navigator.userAgent:"",t=/iPhone|iPad|iPod|Android/i.test(e),i=/Safari\//.test(e)&&!/Chrome\//.test(e);(t||i)&&(r=Math.min(r,12e3))}catch(e){}return d.debug(`Device tier detected: ${i} (${n}), maxRenderVoxels: ${r}`),{tier:i,maxRenderVoxels:r,detectionMethod:n,deviceInfo:t,webglInfo:e}}catch(e){return d.warn("Device tier detection failed, using default mid tier:",e),{tier:"mid",maxRenderVoxels:Math.min(25e3,a),detectionMethod:"error-fallback",deviceInfo:null,webglInfo:null}}}(),i={...e,maxRenderVoxels:t.maxRenderVoxels,_autoRenderBudget:{tier:t.tier,detectionMethod:t.detectionMethod,autoMaxRenderVoxels:t.maxRenderVoxels}};return d.info(`Auto Render Budget applied: ${t.tier} tier, maxRenderVoxels: ${t.maxRenderVoxels}`),i}(o)),d.setLogLevel(this.options),this.renderer=new ne(this.viewer,this.options),this._bounds=null,this._grid=null,this._voxelData=null,this._statistics=null,this._spatialIdEdgeCaseMetrics=null,this._eventHandler=null,this._performanceOverlay=null,this._lastRenderTime=null,this._overlayLastUpdate=0,this._postRenderListener=null,this._prevFrameTimestamp=null,this._postRenderListener=null,this._prevFrameTimestamp=null,this._legend=null,this._timeController=null,this._timeControllerSignature=null,this._initializeEventListeners(),this.options.performanceOverlay&&this.options.performanceOverlay.enabled&&this._initializePerformanceOverlay(),this.options.temporal&&this.options.temporal.enabled&&this._initializeTimeController()}getEffectiveOptions(){try{return JSON.parse(JSON.stringify(this.options))}catch(e){return{...this.options}}}static listProfiles(){return g()}static getProfileDetails(e){return f(e)}_initializePerformanceOverlay(){if("undefined"==typeof window)return void d.warn("Performance overlay requires browser environment");const e={position:"top-right",fpsAveragingWindowMs:1e3,autoUpdate:!0,updateIntervalMs:500,...this.options.performanceOverlay};this._performanceOverlay=new ae(e),e.autoShow&&this._performanceOverlay.show(),d.debug("Performance overlay initialized"),this._hookPerformanceOverlayUpdates()}_initializeTimeController(){try{this._timeController=new le(this.viewer,this,this.options.temporal),this._timeController.activate(),this._timeControllerSignature=this._serializeTemporalOptions(this.options.temporal),d.info("TimeController initialized and activated")}catch(e){this._timeController=null,this._timeControllerSignature=null,d.error("Failed to initialize TimeController:",e)}}_teardownTimeController(){if(this._timeController){try{this._timeController.deactivate()}catch(e){d.debug("timeController deactivate failed (non-fatal)",e)}this._timeController=null,this._timeControllerSignature=null}}_syncTimeController(e,t,i){const n=!(!e||!e.enabled),a=!(!t||!t.enabled);if(n||!a)if(!n||a){if(a&&i){const e=this._serializeTemporalOptions(t);this._timeControllerSignature!==e&&(this._teardownTimeController(),this._initializeTimeController())}}else this._teardownTimeController();else this._initializeTimeController()}_serializeTemporalOptions(e){if(!e)return null;try{return JSON.stringify(e,(e,t)=>"function"==typeof t?`[Function:${t.name||"anonymous"}]`:t)}catch(e){return d.debug("Failed to serialize temporal options for comparison",e),null}}togglePerformanceOverlay(){return this._performanceOverlay?(this._performanceOverlay.toggle(),this._performanceOverlay.isVisible):(d.warn("Performance overlay not initialized. Set performanceOverlay.enabled: true in options."),!1)}showPerformanceOverlay(){this._performanceOverlay&&this._performanceOverlay.show()}hidePerformanceOverlay(){this._performanceOverlay&&this._performanceOverlay.hide()}setPerformanceOverlayEnabled(e,t={}){if(e)return this._performanceOverlay?(t&&Object.keys(t).length>0&&(this._performanceOverlay.options={...this._performanceOverlay.options,...t}),this._performanceOverlay.show()):(this.options.performanceOverlay={enabled:!0,...this.options.performanceOverlay||{},...t},this._initializePerformanceOverlay()),!0;if(this._performanceOverlay&&this._performanceOverlay.hide(),this._postRenderListener){try{this.viewer.scene.postRender.removeEventListener(this._postRenderListener)}catch(e){d.debug("postRender listener removal failed (non-fatal)")}this._postRenderListener=null}return!1}_estimateMemoryUsage(){try{const e=this.renderer?.geometryRenderer?.entities?.length||this.renderer?.voxelEntities?.length||0;let t=0;this._voxelData&&(this._voxelData instanceof Map||"number"==typeof this._voxelData.size?t=this._voxelData.size:Array.isArray(this._voxelData)?t=this._voxelData.length:"object"==typeof this._voxelData&&(t=Object.keys(this._voxelData).length));const i=(1024*e+100*t)/1048576;return Math.max(.1,i)}catch(e){return 0}}async setData(e){if(b(e))try{if(d.debug("Heatbox.setData - 処理開始:",e.length,"個のエンティティ"),d.debug("Step 1: 境界計算"),this._bounds=C.calculateBounds(e),!this._bounds)return d.error("境界計算に失敗"),void this.clear();d.debug("境界計算完了:",this._bounds);let t=this.options.voxelSize||n.voxelSize,i=null;if(this.options.autoVoxelSize&&!this.options.voxelSize)try{d.debug("自動ボクセルサイズ調整開始");const n={autoVoxelSizeMode:this.options.autoVoxelSizeMode,autoVoxelTargetFill:this.options.autoVoxelTargetFill,maxRenderVoxels:this.options.maxRenderVoxels},r=function(e,t,i={}){try{return"occupancy"===(i.autoVoxelSizeMode||"basic")?function(e,t,i){const n=_(e),a=i.maxRenderVoxels||5e4,r=i.autoVoxelTargetFill||.6;let s=w(e,t);d.debug(`Starting occupancy-based estimation: N=${t}, target=${r}, maxVoxels=${a}`);for(let i=0;i<10;i++){(!Number.isFinite(s)||s<=0)&&(d.warn(`Invalid currentSize detected: ${s}, using fallback`),s=w(e,t),(!Number.isFinite(s)||s<=0)&&(s=5));const l=Math.max(1,Math.ceil(Math.max(0,n.x)/s))*Math.max(1,Math.ceil(Math.max(0,n.y)/s))*Math.max(1,Math.ceil(Math.max(0,n.z)/s));if(!Number.isFinite(l)||l<=0||l>1e9){d.warn(`Invalid totalVoxels calculated: ${l}, breaking iteration`);break}const h=l*(1-Math.exp(-t/l)),c=Math.min(h/a,1);if(d.debug(`Iteration ${i}: size=${s.toFixed(1)}m, totalVoxels=${l}, expectedOccupied=${h.toFixed(0)}, fill=${c.toFixed(3)}`),Math.abs(c-r)<.05){d.debug(`Converged at iteration ${i}: size=${s.toFixed(1)}m, fill=${c.toFixed(3)}`);break}const u=Math.max(.1,Math.min(10,c/r));s*=Math.pow(u,.3),s=Math.max(5,Math.min(o,s))}const l=Math.round(s);return d.info(`Occupancy-based voxel size: ${l}m (target fill: ${r})`),l}(e,t,i):w(e,t)}catch(e){return d.warn("Initial voxel size estimation failed:",e),20}}(this._bounds,e.length,n),s=z.createGrid(this._bounds,r),l=function(e,t){const i={valid:!0,warning:!1,error:null,recommendedSize:null};if(e>a){i.valid=!1,i.error="ボクセル数が上限を超えています";const n=e/a,r=t*Math.pow(Math.max(1,Math.min(1e3,n)),1/3);i.recommendedSize=Math.ceil(Math.max(5,Math.min(o,r)))}else e>3e4&&(i.warning=!0,i.error="推定メモリ使用量が警告値を超えています");return i}(s.totalVoxels,r);!l.valid&&l.recommendedSize?(t=l.recommendedSize,i={enabled:!0,mode:this.options.autoVoxelSizeMode,originalSize:r,finalSize:t,adjusted:!0,reason:`Performance limit exceeded: ${s.totalVoxels} > 50000`},d.info(`Auto-adjusted voxelSize: ${r}m → ${t}m (${s.totalVoxels} voxels)`)):(t=r,i={enabled:!0,mode:this.options.autoVoxelSizeMode,originalSize:r,finalSize:t,adjusted:!1,reason:null},d.info(`Auto-determined voxelSize: ${t}m`))}catch(e){d.warn("Auto voxel size adjustment failed, using default:",e),t=n.voxelSize,i={enabled:!0,adjusted:!1,reason:"Estimation failed, using default size",originalSize:null,finalSize:t}}d.debug("Step 2: グリッド生成 (サイズ:",t,"m)"),this._grid=z.createGrid(this._bounds,t),d.debug("グリッド生成完了:",this._grid),d.debug("Step 3: エンティティ分類");const r={...this.options,voxelSize:t};this._voxelData=await X.classifyEntitiesIntoVoxels(e,this._bounds,this._grid,r),d.debug("エンティティ分類完了:",this._voxelData.size,"個のボクセル"),d.debug("Step 4: 統計計算"),this._statistics=X.calculateStatistics(this._voxelData,this._grid,this.options),d.debug("統計情報:",this._statistics),i&&(this._statistics.autoAdjusted=i.adjusted,this._statistics.originalVoxelSize=i.originalSize,this._statistics.finalVoxelSize=i.finalSize,this._statistics.adjustmentReason=i.reason),r.spatialId?.enabled?(this._statistics.spatialIdEnabled=!0,this._statistics.spatialIdMode=r.spatialId.mode,this._statistics.spatialIdProvider=r._spatialIdProvider||null,this._statistics.spatialIdZoom=r._resolvedZoom||null,this._statistics.zoomControl=r.spatialId.zoomControl):this._statistics.spatialIdEnabled=!1,d.debug("Step 5: 描画");const s="undefined"!=typeof performance&&performance.now?performance.now():Date.now(),l=this.renderer.render(this._voxelData,this._bounds,this._grid,this._statistics),h="undefined"!=typeof performance&&performance.now?performance.now():Date.now();if(this._lastRenderTime=Math.max(0,h-s),this._statistics.renderedVoxels=l,this._statistics.renderTimeMs=this._lastRenderTime,d.info("描画完了 - 実際の描画数:",l),this.options.autoView)try{d.debug("Auto view adjustment triggered"),await this.fitView(),d.debug("Auto view adjustment completed")}catch(e){d.warn("Auto view adjustment failed:",e)}if(d.debug("Heatbox.setData - 処理完了"),this._performanceOverlay&&this._performanceOverlay.isVisible){const e=this.getStatistics()||{};e.renderTimeMs=this._lastRenderTime,e.memoryUsageMB=this._estimateMemoryUsage(),this._performanceOverlay.update(e,void 0)}}catch(e){throw d.error("ヒートマップ作成エラー:",e),this.clear(),e}else this.clear()}async createFromEntities(e){if(!b(e))throw new Error(s);return await this.setData(e),this.getStatistics()}setVisible(e){this.renderer.setVisible(e)}clear(){this.renderer.clear(),this._bounds=null,this._grid=null,this._voxelData=null,this._statistics=null}destroy(){if(this.clear(),this._eventHandler&&!this._eventHandler.isDestroyed()&&this._eventHandler.destroy(),this._postRenderListener){try{this.viewer.scene.postRender.removeEventListener(this._postRenderListener)}catch(e){d.debug("postRender listener removal failed (non-fatal)")}this._postRenderListener=null}if(this._performanceOverlay){try{this._performanceOverlay.destroy()}catch(e){d.debug("overlay destroy failed (non-fatal)")}this._performanceOverlay=null}if(this._legend){try{this._legend.destroy()}catch(e){d.debug("legend destroy failed (non-fatal)")}this._legend=null}this._teardownTimeController(),this._eventHandler=null}dispose(){this.destroy()}getOptions(){return{...this.options}}updateOptions(e){const t=this.options?this.options.temporal:void 0,i=!!e&&Object.prototype.hasOwnProperty.call(e,"temporal");if(this.options=M({...this.options,...e}),this.renderer.options=this.options,this.renderer.adaptiveController&&"function"==typeof this.renderer.adaptiveController.updateOptions&&this.renderer.adaptiveController.updateOptions(this.options),this.renderer.geometryRenderer&&"function"==typeof this.renderer.geometryRenderer.updateOptions&&this.renderer.geometryRenderer.updateOptions(this.options),this._voxelData){const e=this.renderer.render(this._voxelData,this._bounds,this._grid,this._statistics);this._statistics.renderedVoxels=e}this._syncTimeController(t,this.options.temporal,i)}_initializeEventListeners(){this._eventHandler=new i.ScreenSpaceEventHandler(this.viewer.scene.canvas),this._eventHandler.setInputAction(e=>{const t=this.viewer.scene.pick(e.position);if(i.defined(t)&&t.id&&t.id.properties&&"voxel"===t.id.properties.type){const e=t.id.properties.key,n={x:t.id.properties.x,y:t.id.properties.y,z:t.id.properties.z,count:t.id.properties.count},a=new i.Entity({id:`voxel-${e}`,description:this.renderer.createVoxelDescription(n,e)});this.viewer.selectedEntity=a}},i.ScreenSpaceEventType.LEFT_CLICK)}getStatistics(){if(!this._statistics)return null;const e={...this._statistics},t=this.renderer.getSelectionStats();t&&(e.selectionStrategy=t.strategy,e.clippedNonEmpty=t.clippedNonEmpty,e.coverageRatio=t.coverageRatio??0),this.options._autoRenderBudget&&(e.renderBudgetTier=this.options._autoRenderBudget.tier,e.autoMaxRenderVoxels=this.options._autoRenderBudget.autoMaxRenderVoxels),"number"==typeof this.options.maxRenderVoxels&&this.options.maxRenderVoxels>0?e.occupancyRatio=Math.min(1,Math.max(0,(e.renderedVoxels||0)/this.options.maxRenderVoxels)):e.occupancyRatio=null;const i=this.options&&this.options.spatialId?this.options.spatialId:{},n=Boolean(e.spatialIdEnabled),a=this._spatialIdEdgeCaseMetrics??null;if(e.spatialId={enabled:n,provider:n?e.spatialIdProvider??null:null,zoom:n?e.spatialIdZoom??null:null,zoomControl:e.zoomControl??i.zoomControl??null,edgeCaseMetrics:a},this.options.aggregation?.enabled&&this._voxelData){const t=new Map;for(const e of this._voxelData.values())if(e.layerStats)for(const[i,n]of e.layerStats)t.set(i,(t.get(i)||0)+n);const i=this.options.aggregation?.topN??10,n=Array.from(t.entries()).sort((e,t)=>t[1]-e[1]).slice(0,i);e.layers=n.map(([e,t])=>({key:e,total:t})),d.debug(`[aggregation] Aggregated ${t.size} unique layers, returning top ${e.layers.length}`)}return e}getBounds(){return this._bounds}getDebugInfo(){const e={options:{...this.options},bounds:this._bounds,grid:this._grid,statistics:this._statistics};return this.options.autoVoxelSize&&(e.autoVoxelSizeInfo={enabled:this.options.autoVoxelSize,originalSize:this._statistics?.originalVoxelSize,finalSize:this._statistics?.finalVoxelSize,adjusted:this._statistics?.autoAdjusted||!1,reason:this._statistics?.adjustmentReason,dataRange:this._bounds?_(this._bounds):null,estimatedDensity:this._bounds&&this._statistics?this._statistics.totalEntities/(_(this._bounds).x*_(this._bounds).y*_(this._bounds).z):null}),e}_hookPerformanceOverlayUpdates(){if(!this._performanceOverlay||this._postRenderListener)return;const e=this._performanceOverlay.options?.updateIntervalMs??500;this._postRenderListener=()=>{if(!this._performanceOverlay||!this._performanceOverlay.isVisible)return;const t="undefined"!=typeof performance&&performance.now?performance.now():Date.now();let i;if(null!=this._prevFrameTimestamp&&(i=Math.max(0,t-this._prevFrameTimestamp)),this._prevFrameTimestamp=t,t-this._overlayLastUpdate<e)return;this._overlayLastUpdate=t;const n=this.getStatistics()||{};null!=this._lastRenderTime&&(n.renderTimeMs=this._lastRenderTime),n.memoryUsageMB=this._estimateMemoryUsage();try{this._performanceOverlay.update(n,i)}catch(e){}};try{this.viewer.scene.postRender.addEventListener(this._postRenderListener)}catch(e){}}async fitView(e=null,t={}){try{const i=e||this._bounds;if(!i)return void d.warn("No bounds available for fitView");if(!this._isValidBounds(i))return void d.warn("Invalid bounds provided to fitView:",i);const n={...this.options.fitViewOptions,...t};d.debug("fitView called with bounds:",i,"options:",n);const a={...n};return Number.isFinite(a.pitchDegrees)||(a.pitchDegrees=-35),Number.isFinite(a.headingDegrees)||(a.headingDegrees=0),await new Promise(e=>{let t=!1;const n=async()=>{if(!t){t=!0;try{await this._fitByBoundingSphere(i,a)}catch(e){d.warn("fitView (postRender) failed, trying fallback:",e);try{await this.viewer.zoomTo(this.viewer.entities)}catch(e){d.warn("zoomTo fallback failed:",e)}}finally{try{this.viewer.scene.postRender.removeEventListener(n)}catch(e){d.debug("postRender removeEventListener failed (non-fatal):",e)}e()}}};try{this.viewer.scene.postRender.addEventListener(n)}catch(t){d.warn("postRender addEventListener failed:",t),e()}})}catch(e){throw d.error("fitView failed:",e),e}}async _fitByBoundingSphere(e,t){const n=i.Rectangle.fromDegrees(e.minLon,e.minLat,e.maxLon,e.maxLat),a=i.BoundingSphere.fromRectangle3D(n,i.Ellipsoid.WGS84,Math.max(0,e.minAlt||0)),o=i.Math.toRadians(t.headingDegrees??0),r=Math.max(-85,Math.min(-10,t.pitchDegrees??-35)),s=i.Math.toRadians(r),l=Math.max(2.2*a.radius,1e3);await this.viewer.camera.flyToBoundingSphere(a,{duration:1.2,offset:new i.HeadingPitchRange(o,s,l)})}_isValidBounds(e){return e&&"number"==typeof e.minLon&&!isNaN(e.minLon)&&"number"==typeof e.maxLon&&!isNaN(e.maxLon)&&"number"==typeof e.minLat&&!isNaN(e.minLat)&&"number"==typeof e.maxLat&&!isNaN(e.maxLat)&&"number"==typeof e.minAlt&&!isNaN(e.minAlt)&&"number"==typeof e.maxAlt&&!isNaN(e.maxAlt)&&e.minLon<=e.maxLon&&e.minLat<=e.maxLat&&e.minAlt<=e.maxAlt}async _handleMinimalDataRange(e,t,n,a){d.debug("Handling minimal data range");const o=i.Cartesian3.fromDegrees(e,t,n+2e3),r=i.Math.toRadians(a.headingDegrees||a.heading),s=i.Math.toRadians(a.pitchDegrees||a.pitch);return this.viewer.camera.flyTo({destination:o,orientation:{heading:r,pitch:s,roll:0},duration:1.5})}async _handleLargeDataRange(e,t){d.debug("Handling large data range with bounding sphere");const n=(e.minLon+e.maxLon)/2,a=(e.minLat+e.maxLat)/2,o=(e.minAlt+e.maxAlt)/2,r=_(e),s=Math.max(r.x,r.y,r.z),l=new i.BoundingSphere(i.Cartesian3.fromDegrees(n,a,o),s/2),h=i.Math.toRadians(t.headingDegrees||t.heading),c=i.Math.toRadians(t.pitchDegrees||t.pitch);return this.viewer.camera.flyToBoundingSphere(l,{duration:2.5,offset:new i.HeadingPitchRange(h,c,0)})}_calculateOptimalCameraHeight(e,t,n){if("auto"!==n.altitudeStrategy)return n.altitude||5e3;try{const a=i.Math.toRadians(n.pitchDegrees||n.pitch),o=this.viewer.camera.frustum.fovy||i.Math.toRadians(60),r=(e+t)/(2*Math.tan(o/2)),s=Math.abs(a);let l=r*Math.max(.5,Math.sin(Math.PI/2-s)+.3);const h=e/Math.min(e,100);h>5&&(l*=Math.log10(h)+1);const c=Math.max(500,.1*e),u=Math.min(1e5,10*e);return l=Math.max(c,Math.min(u,l)),d.debug(`Camera height calculated: ${l.toFixed(0)}m (range: ${e.toFixed(0)}m, pitch: ${n.pitchDegrees||n.pitch}°)`),l}catch(t){return d.warn("Camera height calculation failed, using fallback:",t),Math.max(2e3,2*e)}}async _executeCameraMovement(e,t,n,a,o,r,s){try{const l=i.Cartesian3.fromDegrees(e,t,n+a),h=i.Math.toRadians(o.headingDegrees||o.heading),c=i.Math.toRadians(o.pitchDegrees||o.pitch),u={heading:h,pitch:c,roll:0};d.debug(`Camera target: position=${e.toFixed(6)},${t.toFixed(6)},${(n+a).toFixed(0)}, heading=${o.headingDegrees||o.heading}°, pitch=${o.pitchDegrees||o.pitch}°`);const p=Math.max(1,Math.min(3,.8*Math.log10(r))),m=this.viewer.camera.flyTo({destination:l,orientation:u,duration:p,complete:()=>{d.debug("fitView camera movement completed")},cancel:()=>{d.debug("fitView camera movement cancelled")}});if(m)await m;else{d.debug("Using fallback: flyToBoundingSphere");const a=new i.BoundingSphere(i.Cartesian3.fromDegrees(e,t,n),r/2+s);await this.viewer.camera.flyToBoundingSphere(a,{duration:p,offset:new i.HeadingPitchRange(h,c,0)})}d.info("fitView completed successfully")}catch(e){throw d.error("Camera movement execution failed:",e),e}}createLegend(e=null){return this._legend||(this._legend=new re({container:e})),this._legend.render(this.renderer?._classifier||null,this.options.classification||{}),this._legend.container||null}updateLegend(){this._legend&&this._legend.update(this.renderer?._classifier||null,this.options.classification||{})}destroyLegend(){this._legend&&(this._legend.destroy(),this._legend=null)}static filterEntities(e,t){return Array.isArray(e)&&"function"==typeof t?e.filter(t):[]}}function ce(e,t,n=500){if(!e)throw new Error("viewer is required");if(!(t&&"minLon"in t&&"maxLon"in t&&"minLat"in t&&"maxLat"in t))throw new Error("bounds must include minLon, maxLon, minLat, maxLat");const a=[],o=t.minAlt||0,r=t.maxAlt||100;for(let s=0;s<n;s++){const n=t.minLon+(t.maxLon-t.minLon)*Math.random(),l=t.minLat+(t.maxLat-t.minLat)*Math.random(),h=o+(r-o)*Math.random(),c=e.entities.add({id:`test-entity-${s}`,position:i.Cartesian3.fromDegrees(n,l,h),point:{pixelSize:5,color:i.Color.YELLOW,outlineColor:i.Color.BLACK,outlineWidth:1},label:{text:`Test ${s}`,font:"10pt sans-serif",pixelOffset:new i.Cartesian2(0,-30),fillColor:i.Color.WHITE,outlineColor:i.Color.BLACK,outlineWidth:1,style:i.LabelStyle.FILL_AND_OUTLINE}});a.push(c)}return a}function de(e){if(!e||!e.entities)throw new Error("Invalid viewer");return e.entities.values}const ue=he,pe="1.2.1",me="hiro-nyon",ge="https://github.com/hiro-nyon/cesium-heatbox";function fe(e,t){return new he(e,t)}function ye(){let e=!1;try{if("undefined"!=typeof WebGLRenderingContext){const t=document.createElement("canvas");e=!(!t.getContext("webgl")&&!t.getContext("experimental-webgl"))}}catch(t){e=!1}return{version:pe,cesiumVersion:"undefined"!=typeof Cesium?Cesium.VERSION:"N/A",userAgent:"undefined"!=typeof navigator?navigator.userAgent:"N/A",webglSupport:e,timestamp:(new Date).toISOString()}}d.info(`CesiumJS Heatbox v${pe} loaded`);export{me as AUTHOR,he as CesiumHeatbox,he as Heatbox,re as Legend,ge as REPOSITORY,pe as VERSION,fe as createHeatbox,ue as default,ce as generateTestEntities,de as getAllEntities,ye as getEnvironmentInfo};
2
2
  //# sourceMappingURL=cesium-heatbox.min.js.map