/** Distance-dependent SSE policy. * Lower SSE requests more detail; this is not a separate preload/render policy. * A constant SSE=20 yields a theoretical ge=20 boundary near 701m at H=810/fovy=60. * That does NOT imply the dynamic curve starts loading at 701m: solve SSE(distance) * together with the individual tile distance. Region admission distance, viewport, * memoryAdjustedScreenSpaceError and current geometry bounds also affect selection. */ /** * 由距离算出该区域的细化阈值。 * * @param {number} distanceM 到该区域内容球面的距离(米) * @param {object} [options] * @param {number} [options.baseThreshold] 基准阈值(远距离用,默认 56) * @param {number} [options.nearThreshold] 近距离阈值(更小 = 更早细化,默认 20) * @param {number} [options.nearBandM] 近档距离(默认 200m,此距离内用 nearThreshold) * @param {number} [options.farBandM] 远档距离(默认 1200m,此距离外用 baseThreshold) * @returns {number} 该区域这一帧应使用的 maximumScreenSpaceError */ export function refineThresholdForDistance(distanceM, options = {}) { const opts = options || {} const num = (v, f) => (Number.isFinite(Number(v)) ? Number(v) : f) const base = Math.max(1, num(opts.baseThreshold, 56)) const near = Math.max(1, num(opts.nearThreshold, 20)) const nearBand = Math.max(1, num(opts.nearBandM, 200)) const farBand = Math.max(nearBand + 1, num(opts.farBandM, 1200)) const d = Number(distanceM) // 距离未知(还没算过):用基准阈值,不要因为 NaN 就疯狂细化。 if (!Number.isFinite(d)) return base // 近档内:直接给最紧阈值(最早细化)。 if (d <= nearBand) return near // 远档外:基准阈值。 if (d >= farBand) return base // 中间:线性插值(近→紧、远→宽),保证连续、无跳变。 const t = (d - nearBand) / (farBand - nearBand) return near + (base - near) * t } /** * 该阈值下,某层几何误差对应的细化距离(诊断/闸门用)。 * @param {number} geometricError * @param {number} threshold * @param {number} [viewportHeightPx] * @returns {number} 米 */ export function refineDistance(geometricError, threshold, viewportHeightPx = 810) { const ge = Number(geometricError) const thr = Number(threshold) if (!Number.isFinite(ge) || !Number.isFinite(thr) || thr <= 0) return Infinity const factor = 2 * Math.tan(Math.PI / 6) return (ge * viewportHeightPx) / (thr * factor) }