Commit 7a1cbd3d by liimin

优化

1 parent 48cf3fa2
...@@ -76,6 +76,18 @@ class AggregateClient { ...@@ -76,6 +76,18 @@ class AggregateClient {
private ready: Promise<void> | null = null; private ready: Promise<void> | null = null;
private detailReady = false; private detailReady = false;
/** /**
* 主线程侧记录的「期望点数」:init 时按 lng 的字节数算出(与 Worker 侧 handleInit 同款算法),
* 代表「这一份数据本应有几条」。analyze 跑完会把 Worker 实际装入的 `n` 随结果回传,
* 两者对不上就说明 Worker 装错了数据(旧 Worker 残留 / 半截导入),需要重建。
*/
private _loadedN = 0;
/**
* 重建当前数据集的入口:由 bootstrap 注册。它内部重新从 IndexedDB 读一份最新、完整的
* 数据再 init(initFromColumns 会 transfer 掉 buffer,所以每次都得是新读出来的那份)。
* 自检发现「Worker 装入点数 ≠ 期望点数」时调用它换一个干净的 Worker,而不是直接拿脏数据算。
*/
reload: (() => Promise<void>) | null = null;
/**
* 当前 Worker 里装的是哪一份数据(由调用方给的标识,如「导入时间 + 条数」)。 * 当前 Worker 里装的是哪一份数据(由调用方给的标识,如「导入时间 + 条数」)。
* *
* 这个字段存在的唯一理由是 `postInit` 的那道去重:同一份数据被 init 两次 * 这个字段存在的唯一理由是 `postInit` 的那道去重:同一份数据被 init 两次
...@@ -84,6 +96,11 @@ class AggregateClient { ...@@ -84,6 +96,11 @@ class AggregateClient {
*/ */
private datasetKey: string | null = null; private datasetKey: string | null = null;
/** 主线程期望 Worker 装入的点数;0 表示尚未装载 */
get loadedN(): number {
return this._loadedN;
}
/** 启动 Worker 并把列式点位数据的所有权转交过去(number[] → TypedArray 后零拷贝) */ /** 启动 Worker 并把列式点位数据的所有权转交过去(number[] → TypedArray 后零拷贝) */
init( init(
meta: Pick<MetaFile, 'dict' | 'grid' | 'bounds' | 'timeRange' | 'coordScale'>, meta: Pick<MetaFile, 'dict' | 'grid' | 'bounds' | 'timeRange' | 'coordScale'>,
...@@ -225,6 +242,8 @@ class AggregateClient { ...@@ -225,6 +242,8 @@ class AggregateClient {
type: 'module', type: 'module',
name: 'heatmap-aggregate', name: 'heatmap-aggregate',
}); });
// 记录期望点数:与 Worker 侧 handleInit 用同样的「lng 字节数 / 4」口径,保证两侧 n 可比
this._loadedN = incidents.lng.byteLength / Int32Array.BYTES_PER_ELEMENT;
this.worker.onmessage = (e: MessageEvent<WorkerResponse>) => this.onMessage(e.data); this.worker.onmessage = (e: MessageEvent<WorkerResponse>) => this.onMessage(e.data);
this.worker.onerror = (e) => { this.worker.onerror = (e) => {
...@@ -504,6 +523,7 @@ class AggregateClient { ...@@ -504,6 +523,7 @@ class AggregateClient {
this.ready = null; this.ready = null;
this.datasetKey = null; this.datasetKey = null;
this.detailReady = false; this.detailReady = false;
this._loadedN = 0;
} }
} }
......
...@@ -266,6 +266,7 @@ export function analyze(input: AnalysisInput): AnalysisResult { ...@@ -266,6 +266,7 @@ export function analyze(input: AnalysisInput): AnalysisResult {
const empty = (msg: string): AnalysisResult => ({ const empty = (msg: string): AnalysisResult => ({
matched: input.matched, matched: input.matched,
n: input.n,
grid: { originLng, originLat, dLng, dLat, w: gw, h: gh }, grid: { originLng, originLat, dLng, dLat, w: gw, h: gh },
gridSource, gridSource,
cellMeters: p.cellMeters, cellMeters: p.cellMeters,
...@@ -350,16 +351,27 @@ export function analyze(input: AnalysisInput): AnalysisResult { ...@@ -350,16 +351,27 @@ export function analyze(input: AnalysisInput): AnalysisResult {
const { label, domains: domainCount } = labelDomains(sig, gw, gh); const { label, domains: domainCount } = labelDomains(sig, gw, gh);
// 域内原始案件数 —— 决定哪些域够格叫黑点 // 域内原始案件数 —— 决定哪些域够格叫黑点
// domainCells:整个连通域(含被高斯光晕染成「显著」的空格)的格子数,用于报尺寸/半径;
// domainOcc:域内「有案」格子数 —— 跟 background(每有案格的案件数)单位对齐,才用来算期望值。
// ⚠️ 之前这里用 domainCells 当期望值分母,等于把光晕里的空格也算进「应该有多少案」,
// 而空格不贡献案件,于是 exp 被凭空放大几倍 → 紧凑真簇的泊松 z 被压到 4σ 以下 →
// 75 个候选域全被否、静默 0 处。这是单位错配,不是调参问题。
const domainCells = new Int32Array(domainCount + 1); const domainCells = new Int32Array(domainCount + 1);
const domainOcc = new Int32Array(domainCount + 1);
const domainObs = new Int32Array(domainCount + 1); const domainObs = new Int32Array(domainCount + 1);
for (let i = 0; i < cells; i += 1) { for (let i = 0; i < cells; i += 1) {
const l = label[i]; const l = label[i];
if (l === 0) continue; if (l === 0) continue;
domainCells[l] += 1; domainCells[l] += 1;
if (counts[i] > 0) domainOcc[l] += 1;
domainObs[l] += counts[i]; domainObs[l] += counts[i];
} }
const keep = new Uint8Array(domainCount + 1); const keep = new Uint8Array(domainCount + 1);
let keptDomains = 0; let keptDomains = 0;
// 临时诊断:记录被否域里「最接近过关」的那个,方便复现 0 处时看差多远
let bestRejZ = 0;
let bestRejObs = 0;
let bestRejCells = 0;
for (let l = 1; l <= domainCount; l += 1) { for (let l = 1; l <= domainCount; l += 1) {
// 两道门槛,缺一不可,理由不同: // 两道门槛,缺一不可,理由不同:
// · minCount 管「够不够格进清单」—— 三五起的碎块即使密度高也不值得派人去看; // · minCount 管「够不够格进清单」—— 三五起的碎块即使密度高也不值得派人去看;
...@@ -367,11 +379,16 @@ export function analyze(input: AnalysisInput): AnalysisResult { ...@@ -367,11 +379,16 @@ export function analyze(input: AnalysisInput): AnalysisResult {
// 「挑出前 X% 的格子」,被挑中的格子平均密度必然高于全局,于是随机密团也能 // 「挑出前 X% 的格子」,被挑中的格子平均密度必然高于全局,于是随机密团也能
// 凑成一个过得了百分位的域。只有按泊松检验把 obs 和 exp 的差距卡住, // 凑成一个过得了百分位的域。只有按泊松检验把 obs 和 exp 的差距卡住,
// 「均匀散布 = 没有黑点」才成立,这一条是整个降噪功能的判据所在。 // 「均匀散布 = 没有黑点」才成立,这一条是整个降噪功能的判据所在。
const exp = background * domainCells[l]; // exp 用 domainOcc(有案格)而非 domainCells(含光晕空格),单位才和 background 对上。
const exp = background * domainOcc[l];
const z = exp > 0 ? (domainObs[l] - exp) / Math.sqrt(exp) : 0; const z = exp > 0 ? (domainObs[l] - exp) / Math.sqrt(exp) : 0;
if (domainObs[l] >= p.minCount && z >= MIN_DOMAIN_Z) { if (domainObs[l] >= p.minCount && z >= MIN_DOMAIN_Z) {
keep[l] = 1; keep[l] = 1;
keptDomains += 1; keptDomains += 1;
} else if (z > bestRejZ) {
bestRejZ = z;
bestRejObs = domainObs[l];
bestRejCells = domainCells[l];
} }
} }
if (keptDomains === 0) { if (keptDomains === 0) {
...@@ -379,13 +396,23 @@ export function analyze(input: AnalysisInput): AnalysisResult { ...@@ -379,13 +396,23 @@ export function analyze(input: AnalysisInput): AnalysisResult {
// (数据边界写坏退回外包框 / 参数太严 / 这批案子本来就散)。屏上也会念 gridSource 与判定输入。 // (数据边界写坏退回外包框 / 参数太严 / 这批案子本来就散)。屏上也会念 gridSource 与判定输入。
if (input.matched > 0) { if (input.matched > 0) {
console.warn( console.warn(
'[analysis] 本次识别 0 处(命中 %d 起 · 有案方格 %d 个 · 候选域 %d 个 · 基线 %s 起/格 · 阈值 %s · 网格来源 %s)', '[analysis] 本次识别 0 处(n=%d 起 · 命中 %d 起 · 有案方格 %d 个 · 候选域 %d 个 · 基线 %s 起/格 · 阈值 %s · 网格来源 %s · 边界中心 %s,%s · 时间窗 %d~%d · 参数 kp=%d mc=%d)· 最强被否域 z=%s obs=%d cells=%d',
input.n,
input.matched, input.matched,
occupied, occupied,
domainCount, domainCount,
background.toFixed(2), background.toFixed(2),
threshold.toFixed(2), threshold.toFixed(2),
gridSource, gridSource,
((input.bounds.minLng + input.bounds.maxLng) / 2).toFixed(4),
((input.bounds.minLat + input.bounds.maxLat) / 2).toFixed(4),
input.timeMin,
input.timeMax,
input.params.keepPercent,
input.params.minCount,
bestRejZ.toFixed(2),
bestRejObs,
bestRejCells,
); );
} }
return { return {
...@@ -505,7 +532,11 @@ export function analyze(input: AnalysisInput): AnalysisResult { ...@@ -505,7 +532,11 @@ export function analyze(input: AnalysisInput): AnalysisResult {
if (count === 0) continue; if (count === 0) continue;
const cellCount = domainCells[l]; const cellCount = domainCells[l];
const expected = background * cellCount; // expected / z / ratio / excess 用「域内有案格」domainOcc 算:background 是「每有案格的案件数」,
// 跟全连通域(含高斯光晕空格)混用会放大期望值、压低显著性,见上方 domainOcc 注释。
// cellCount(全连通域)只用于报半径/面积这种「这块区域有多大」的几何量。
const occCount = domainOcc[l];
const expected = background * occCount;
const areaM2 = cellCount * p.cellMeters * p.cellMeters; const areaM2 = cellCount * p.cellMeters * p.cellMeters;
const districtBase = idx * nDistricts; const districtBase = idx * nDistricts;
let district = 0; let district = 0;
...@@ -524,7 +555,7 @@ export function analyze(input: AnalysisInput): AnalysisResult { ...@@ -524,7 +555,7 @@ export function analyze(input: AnalysisInput): AnalysisResult {
expected, expected,
// 泊松超额显著性:观察数与「按全市平均密度应有的数量」差了几个标准差 // 泊松超额显著性:观察数与「按全市平均密度应有的数量」差了几个标准差
z: expected > 0 ? (count - expected) / Math.sqrt(expected) : 0, z: expected > 0 ? (count - expected) / Math.sqrt(expected) : 0,
ratio: background > 0 ? count / cellCount / background : 0, ratio: background > 0 ? count / occCount / background : 0,
excess: count - expected, excess: count - expected,
cells: cellCount, cells: cellCount,
timeMin: Number.isFinite(tMin[idx]) ? tMin[idx] : 0, timeMin: Number.isFinite(tMin[idx]) ? tMin[idx] : 0,
...@@ -553,6 +584,7 @@ export function analyze(input: AnalysisInput): AnalysisResult { ...@@ -553,6 +584,7 @@ export function analyze(input: AnalysisInput): AnalysisResult {
return { return {
matched: input.matched, matched: input.matched,
n: input.n,
grid: { originLng, originLat, dLng, dLat, w: gw, h: gh }, grid: { originLng, originLat, dLng, dLat, w: gw, h: gh },
gridSource, gridSource,
cellMeters: p.cellMeters, cellMeters: p.cellMeters,
...@@ -590,6 +622,12 @@ export function labelDomains( ...@@ -590,6 +622,12 @@ export function labelDomains(
gw: number, gw: number,
gh: number, gh: number,
): { label: Int32Array; domains: number } { ): { label: Int32Array; domains: number } {
// 同一份掩码在一次聚合回包里会被问好几遍:取景范围(MapStage)、
// 数字让位(ClusterLayer)、脚印轮廓(HotspotLayer)各要一次。
// 结果只依赖掩码引用与尺寸,而每次扫描是整幅栅格 —— 留一份最近的就够,
// 那一遍通常能命中两次,等于把三四次全栅格扫描压成一次。
if (cache && cache.sig === sig && cache.gw === gw && cache.gh === gh) return cache.result;
const cells = gw * gh; const cells = gw * gh;
const label = new Int32Array(cells); // 0 = 不属于任何域,域编号从 1 开始 const label = new Int32Array(cells); // 0 = 不属于任何域,域编号从 1 开始
let domainCount = 0; let domainCount = 0;
...@@ -631,9 +669,20 @@ export function labelDomains( ...@@ -631,9 +669,20 @@ export function labelDomains(
} }
} }
} }
return { label, domains: domainCount }; const result = { label, domains: domainCount };
cache = { sig, gw, gh, result };
return result;
} }
/**
* 最近一次 labelDomains 的结果。
*
* 只留一份:调用方都是「拿到就只读」,而真正会反复问的是同一份掩码在同一轮回包里
* 被取景、让位、画轮廓三处各问一遍。留多了反而是几十万格的数组长期占着内存。
*/
let cache: { sig: Uint8Array; gw: number; gh: number; result: { label: Int32Array; domains: number } } | null =
null;
/** 参数兜底。cellMeters 过小会让栅格爆炸(内存与耗时双杀),这里自动放大到安全范围 */ /** 参数兜底。cellMeters 过小会让栅格爆炸(内存与耗时双杀),这里自动放大到安全范围 */
function normalizeParams( function normalizeParams(
p: AnalysisParams, p: AnalysisParams,
......
import { describe, expect, it } from 'vitest';
import { analyze, type AnalysisInput } from './hotspotAnalysis';
import type { AnalysisParams, HotspotRow } from './types';
/**
* 黑点「读数正确性」核验 —— 直接回应超人「上轮改完数据是不是变大了」的担忧。
*
* 上轮把期望值分母从「整个连通域格子数(含高斯光晕空格)」改成「域内有案格子数」,
* 效果是让更多真实簇通过泊松 z 检验(修复前被压到 4σ 以下、静默 0 处的那批)。
* 这个改动**只动「哪些域够格叫黑点」的门槛,不动每个域报出来的案件数** —— 域的 count
* 是「该连通显著区里落了多少个点」的硬计数,与分母无关。
*
* 本文件用「已知规模的合成簇」把这件事钉死:
* 1. 读数 = 真实簇规模(绝不会被放大,且贴近真实落入热区的点数);
* 2. 均匀背景不产出假黑点(修复不能引入假阳性);
* 3. 中等强度簇(修复前会被误杀)现在能被识别(回归保护);
* 4. 多个不同规模簇同时存在时,各自独立计数、互不串味、不合并成一个巨无霸。
*/
const PARAMS: AnalysisParams = {
cellMeters: 100,
smoothMeters: 250,
keepPercent: 8,
minCount: 15,
topN: 24,
sort: 'count',
};
const BOUNDS = { minLng: 113.75, minLat: 22.45, maxLng: 114.45, maxLat: 22.78 };
const T0 = 1_750_000_000;
const HALF_YEAR = 180 * 86_400;
function mulberry32(seed: number) {
let t = seed >>> 0;
return () => {
t = (t + 0x6d2b79f5) >>> 0;
let r = Math.imul(t ^ (t >>> 15), 1 | t);
r = (r + Math.imul(r ^ (r >>> 7), 61 | r)) ^ r;
return ((r ^ (r >>> 14)) >>> 0) / 4294967296;
};
}
interface ClusterSpec {
cx: number;
cy: number;
size: number;
}
/** 均匀背景 + 若干已知规模、已知位置的真实簇 */
function makeMixed(clusters: ClusterSpec[], background: number): AnalysisInput {
const rnd = mulberry32(20261104);
const total = background + clusters.reduce((s, c) => s + c.size, 0);
const lng = new Int32Array(total);
const lat = new Int32Array(total);
const ts = new Uint32Array(total);
const d = new Uint8Array(total);
const s = new Uint16Array(total);
const mask = new Uint8Array(total);
let i = 0;
for (; i < background; i += 1) {
const x = BOUNDS.minLng + rnd() * (BOUNDS.maxLng - BOUNDS.minLng);
const y = BOUNDS.minLat + rnd() * (BOUNDS.maxLat - BOUNDS.minLat);
lng[i] = Math.round(x * 1e6);
lat[i] = Math.round(y * 1e6);
ts[i] = T0 + Math.floor(rnd() * HALF_YEAR);
d[i] = Math.floor(rnd() * 10);
s[i] = Math.floor(rnd() * 60);
mask[i] = 1;
}
for (const c of clusters) {
for (let k = 0; k < c.size; k += 1) {
const a = rnd() * Math.PI * 2;
const r = Math.sqrt(rnd()) * 0.0018; // ≈200m 半径内的真实报案散布
const x = c.cx + Math.cos(a) * r;
const y = c.cy + Math.sin(a) * r;
lng[i] = Math.round(x * 1e6);
lat[i] = Math.round(y * 1e6);
ts[i] = T0 + Math.floor(rnd() * HALF_YEAR);
d[i] = Math.floor(rnd() * 10);
s[i] = Math.floor(rnd() * 60);
mask[i] = 1;
i += 1;
}
}
return {
n: total,
lng,
lat,
ts,
d,
s,
a: null,
mask,
matched: total,
dict: {
districts: Array.from({ length: 10 }, (_, k) => `区${k}`),
streets: Array.from({ length: 60 }, (_, k) => `区|街道${k}`),
addrDetails: [],
},
bounds: BOUNDS,
timeMin: T0,
timeMax: T0 + HALF_YEAR,
params: PARAMS,
};
}
/** 找离 (cx,cy) 最近的那条黑点,断言簇规模用 */
function nearest(res: { hotspots: HotspotRow[] }, cx: number, cy: number): HotspotRow | null {
let best: HotspotRow | null = null;
let bestD = Infinity;
for (const h of res.hotspots) {
const dd = Math.abs(h.lng - cx) + Math.abs(h.lat - cy);
if (dd < bestD) {
bestD = dd;
best = h;
}
}
return best;
}
const CLUSTERS: ClusterSpec[] = [
{ cx: 113.9, cy: 22.55, size: 40 }, // 原来说的「几十起」
{ cx: 114.1, cy: 22.55, size: 120 }, // 一百上下
{ cx: 113.9, cy: 22.65, size: 300 }, // 几百
{ cx: 114.1, cy: 22.65, size: 600 }, // 几百(更密)
];
describe('黑点读数正确性 · 回应「数据变大了」', () => {
it('读数 = 真实簇规模:不被放大,且贴近落入热区的点数', () => {
const m = makeMixed(CLUSTERS, 7000);
const res = analyze(m);
expect(res.keptDomains).toBe(CLUSTERS.length);
for (const c of CLUSTERS) {
const h = nearest(res, c.cx, c.cy);
expect(h, `簇(${c.cx},${c.cy}) 应被识别`).not.toBeNull();
// 上限:黑点 count = 热区(连通显著区)内全部案件,会把极少数恰好落在热区里的背景点也算进来,
// 所以允许比「放进的簇规模」略大;但绝不允许量级性膨胀(10x 那种才是真 bug)。2x 是留足余量的安全线。
expect(h!.count, `簇规模 ${c.size} 却被报成 ${h!.count},疑似读数膨胀`).toBeLessThanOrEqual(
Math.ceil(c.size * 2),
);
// 软下限:紧凑簇绝大多数点落在显著区,读数应贴近真实规模(>=60%)
expect(h!.count, `簇规模 ${c.size} 但只读到 ${h!.count},疑似被压没`).toBeGreaterThanOrEqual(
Math.floor(c.size * 0.6),
);
// 显著性必须成立:观察量明显高于按全市平均密度该有的量
expect(h!.z).toBeGreaterThan(4);
}
});
it('均匀背景不产出假黑点:修复不能引入假阳性', () => {
// 和上面同样的背景量,但不放任何簇
const m = makeMixed([], 7000);
const res = analyze(m);
expect(res.hotspots.length).toBe(0);
expect(res.keptDomains).toBe(0);
expect(res.note).toContain('未发现明显集中的区域');
});
it('中等强度簇(修复前会被误杀)现在能被识别 —— 这正是「区域变多」的来源', () => {
// 纯背景 + 一处 50 起的簇:修复前按整连通域分母算,exp 被放大、z 压到 4σ 以下 → 0 处;
// 修复后按有案格算,这处真实簇能浮上来。锁住这个回归,免得哪天又被人「顺手调参」改回去。
const m = makeMixed([{ cx: 114.0, cy: 22.6, size: 50 }], 7000);
const res = analyze(m);
expect(res.keptDomains).toBeGreaterThanOrEqual(1);
const h = nearest(res, 114.0, 22.6);
expect(h).not.toBeNull();
// 读数包含热区里极少量背景点,允许略高于放置的 50;但远不到「膨胀」的程度
expect(h!.count).toBeLessThanOrEqual(80);
expect(h!.count).toBeGreaterThanOrEqual(30);
});
it('多规模簇各自独立:不合并成一个巨无霸、读数互不串味', () => {
const m = makeMixed(CLUSTERS, 7000);
const res = analyze(m);
// 4 个簇 → 4 处黑点,而不是被并成 1 个「几百+几十」的怪胎
expect(res.keptDomains).toBe(CLUSTERS.length);
expect(res.hotspots.length).toBe(CLUSTERS.length);
// 被黑点覆盖的案件总数 ≈ 四簇之和(热区里少量背景点会让它略高于四簇之和,但应是同一量级)
const inHot = res.hotspots.reduce((s, h) => s + h.count, 0);
const expected = CLUSTERS.reduce((s, c) => s + c.size, 0);
expect(inHot).toBeLessThanOrEqual(Math.ceil(expected * 1.5));
expect(inHot).toBeGreaterThanOrEqual(Math.floor(expected * 0.7));
// 榜首应是最大的那个簇(600 起),而不是把若干小簇并起来凑数
expect(res.hotspots[0].count).toBeGreaterThanOrEqual(300);
});
it('diagnostic 实读:打印四簇的真实读数,便于人工核对是否「膨胀」', () => {
const m = makeMixed(CLUSTERS, 7000);
const res = analyze(m);
// 这条日志只在跑测试时可见,作用是把「算法到底读出了什么」摊开给人看
const lines = CLUSTERS.map((c) => {
const h = nearest(res, c.cx, c.cy);
return ` 簇真值=${c.size} → 读出=${h?.count ?? '未识别'} z=${h?.z.toFixed(1) ?? '-'} ratio=${h?.ratio.toFixed(1) ?? '-'}`;
});
console.info(
`[correctness] 背景=${res.background.toFixed(2)} 起/格 · 识别 ${res.keptDomains} 处\n${lines.join('\n')}`,
);
expect(res.keptDomains).toBe(CLUSTERS.length);
});
});
...@@ -988,7 +988,7 @@ export interface HotspotRow { ...@@ -988,7 +988,7 @@ export interface HotspotRow {
* 点一个黑点去看它的案件明细时,靠这个编号回到当初划出的那一片方格, * 点一个黑点去看它的案件明细时,靠这个编号回到当初划出的那一片方格,
* 而不是拿等效圆去重新圈一遍 —— 圆和连通域是两种形状,用圆取点必然和清单上那个 * 而不是拿等效圆去重新圈一遍 —— 圆和连通域是两种形状,用圆取点必然和清单上那个
* 起数对不上(差两三成),而「同一个位置两个数」在这个看板上就是数据出错。 * 起数对不上(差两三成),而「同一个位置两个数」在这个看板上就是数据出错。
* 圆盘仍然画那个圆,它说的是「示意覆盖范围」;清单取的是这批方格。 * 地图上画的就是这批方格的真实脚印轮廓,清单取的也是这批方格,两边同一片区域。
*/ */
domainId: number; domainId: number;
lng: number; lng: number;
...@@ -1055,6 +1055,8 @@ export interface HotspotDomain { ...@@ -1055,6 +1055,8 @@ export interface HotspotDomain {
export interface AnalysisResult { export interface AnalysisResult {
matched: number; matched: number;
/** Worker 实际装入并参与计算的点数(= 列长行数)。供主线程校验「装进 Worker 的数据」与「期望的那份」是否一致 */
n: number;
/** 栅格几何。mask 按它解释;渲染层用它把桶中心换算成格子编号 */ /** 栅格几何。mask 按它解释;渲染层用它把桶中心换算成格子编号 */
grid: { originLng: number; originLat: number; dLng: number; dLat: number; w: number; h: number }; grid: { originLng: number; originLat: number; dLng: number; dLat: number; w: number; h: number };
/** /**
......
import { fmtCompact } from '@/utils/format'; import { fmtCompact } from '@/utils/format';
import { createBucketsLayer, type BucketsLayer } from '@hm/map-overlay'; import { createBucketsLayer, type BucketsLayer } from '@hm/map-overlay';
import { GRID } from '../aggregate/grid'; import { labelDomains } from '../aggregate/hotspotAnalysis';
import type { HotspotRow } from '../aggregate/types'; import type { HotspotRow } from '../aggregate/types';
import { defineAppOverlay } from './appOverlay'; import { defineAppOverlay } from './appOverlay';
import { CLUSTER_LABEL, inkAt } from './palette'; import { CLUSTER_LABEL, inkAt } from './palette';
import { reference } from './HeatLayer'; import { reference } from './HeatLayer';
import { computeKeepMask, type SignificanceMask } from './significance'; import { computeKeepMask, type SignificanceMask } from './significance';
import { HOTSPOT_MAX_DRAW_PX, hotspotSpan } from './hotspotGeometry'; import type { HotspotGrid } from './HotspotLayer';
export type { SignificanceMask }; export type { SignificanceMask };
...@@ -68,6 +68,8 @@ export const LABEL_MIN_R = 9; ...@@ -68,6 +68,8 @@ export const LABEL_MIN_R = 9;
const HIT_PAD = 7; const HIT_PAD = 7;
/** 关掉数字时那个定位点的命中半径(画出来只有 3.5px,点中范围不能跟着一起缩) */ /** 关掉数字时那个定位点的命中半径(画出来只有 3.5px,点中范围不能跟着一起缩) */
const DOT_HIT_R = 5; const DOT_HIT_R = 5;
/** 空黑点清单的共用常量:让 recomputeUnder 的引用比对在「没有黑点」时也能命中 */
const EMPTY_ROWS: HotspotRow[] = [];
/** /**
* 聚合数字层 —— 在本项目里**没有**使用高德的 AMap.MarkerCluster,原因有两条,都是硬约束: * 聚合数字层 —— 在本项目里**没有**使用高德的 AMap.MarkerCluster,原因有两条,都是硬约束:
...@@ -144,10 +146,26 @@ export class ClusterLayer { ...@@ -144,10 +146,26 @@ export class ClusterLayer {
private dLat = 0; private dLat = 0;
/** 每个桶是否够亮(1)或该淡出(0)。由 recomputeKeep 生成 */ /** 每个桶是否够亮(1)或该淡出(0)。由 recomputeKeep 生成 */
private keep = new Uint8Array(0); private keep = new Uint8Array(0);
/** 黑点范围盘。这些盘压住的桶整块不写数字,见 recomputeUnder */ /** 黑点范围(脚印)。这些范围压住的桶整块不写数字,见 recomputeUnder */
private discs: HotspotRow[] = []; private discs: HotspotRow[] = [];
/** 每个桶是否被黑点盘压住(1 = 数字让位)。与 keep 分开两张表:一张管深浅,一张管画不画 */ /** 黑点分析的栅格与显著掩码:让位判定按连通域格子成员(与脚印轮廓同一口径) */
private discGrid: HotspotGrid | null = null;
private discSig: Uint8Array | null = null;
/** 每个桶是否被黑点范围压住(1 = 数字让位)。与 keep 分开两张表:一张管深浅,一张管画不画 */
private under = new Uint8Array(0); private under = new Uint8Array(0);
/**
* 上一次算让位表时的输入指纹。
*
* applyAnalysis 不只在数据变了的时候跑:点一个黑点(activeHotspot 变)也会把它叫起来一次,
* 而那时黑点清单、栅格、掩码三个引用都没动过。逐桶五点判定是 O(桶数 × 5),
* 一两万桶就是十万次取整与哈希查找 —— 输入没变就没有理由再算一遍。
*/
private underKey: {
discs: HotspotRow[] | null;
grid: HotspotGrid | null;
sig: Uint8Array | null;
n: number;
} | null = null;
constructor(map: AMap.Map) { constructor(map: AMap.Map) {
this.buckets = createBucketsLayer(map, { this.buckets = createBucketsLayer(map, {
...@@ -253,18 +271,37 @@ export class ClusterLayer { ...@@ -253,18 +271,37 @@ export class ClusterLayer {
/** 传入 null 即关掉淡化,恢复「所有格子都写数字」的原始视图 */ /** 传入 null 即关掉淡化,恢复「所有格子都写数字」的原始视图 */
setSignificance(sig: SignificanceMask | null) { setSignificance(sig: SignificanceMask | null) {
// 同一份掩码重复喂(applyAnalysis 会因为点击、切换视图而重跑)时不必重算:
// computeKeepMask 是逐桶扫一遍显著格子,一两万桶时不是白拿的
if (this.sig === sig) return;
this.sig = sig; this.sig = sig;
this.recomputeKeep(); this.recomputeKeep();
this.applyMasks(); this.applyMasks();
} }
/** /**
* 告诉聚合层「哪些位置已经被黑点盘占了」。 * 告诉聚合层「哪些位置已经被黑点范围占了」。
*
* grid+sig 与 rows 同一次分析送来:让位按连通域格子成员判定(与脚印轮廓、
* 明细清单同一口径),不再按等效圆 —— 否则脚印里、等效圆外那一圈会留下一排
* 聚合数字顶着脚印,一个位置又出现两个数。
* *
* 传 null / 空数组即恢复原样(关掉降噪时就是这么走)。 * 传 null / 空数组即恢复原样(关掉降噪时就是这么走)。
*/ */
setHotspotDiscs(rows: HotspotRow[] | null) { setHotspotDiscs(
this.discs = rows ?? []; rows: HotspotRow[] | null,
grid?: HotspotGrid | null,
sig?: Uint8Array | null,
) {
const rows2 = rows ?? EMPTY_ROWS;
const grid2 = grid ?? null;
const sig2 = sig ?? null;
// 三个引用都没变 → 让位表与逐桶掩码必然一样,连重建数组的力气都不必花。
// 走这条路的典型场景:点一个黑点,applyAnalysis 被叫起来,但分析结果没换。
if (this.discs === rows2 && this.discGrid === grid2 && this.discSig === sig2) return;
this.discs = rows2;
this.discGrid = grid2;
this.discSig = sig2;
this.recomputeUnder(); this.recomputeUnder();
this.applyMasks(); this.applyMasks();
} }
...@@ -305,55 +342,66 @@ export class ClusterLayer { ...@@ -305,55 +342,66 @@ export class ClusterLayer {
* 为什么必须让位:桶是屏幕像素网格的实时计数,黑点是地理连通域的域内计数, * 为什么必须让位:桶是屏幕像素网格的实时计数,黑点是地理连通域的域内计数,
* 两个口径本就不同。以前两者叠在同一个位置各写一个数,用户读到的是 * 两个口径本就不同。以前两者叠在同一个位置各写一个数,用户读到的是
* 「清单 51 起、圈里 30 起」,于是整套东西的可信度都没了。现在一个位置只留一个数, * 「清单 51 起、圈里 30 起」,于是整套东西的可信度都没了。现在一个位置只留一个数,
* 由黑点层报它自己的那个(与清单同源),聚合数字在盘内不出现。 * 由黑点层报它自己的那个(与清单同源),聚合数字在脚印内不出现。
* *
* 判据用「桶中心落在盘内」,并按桶自身半个边长做缓冲:只判严格圆内的话, * 判据用「桶(含四角)落在任一上榜黑点的连通域格子里」,并按桶自身半个边长做缓冲:
* 压在盘沿上的那个桶会留下半个数字顶着盘的白描边,看着像黑点少算了一圈。 * 只判桶中心的话,压在轮廓沿上的那个桶会留下半个数字顶着脚印的描边,看着像黑点
* 要么整个让位,要么整个留下。 * 少算了一圈。要么整个让位,要么整个留下。
* *
* 缓冲还顺带解决一个更隐蔽的问题:黑点盘的绘制半径封顶在 HOTSPOT_MAX_DRAW_PX, * 拿不到 grid/sig(异常兜底)时不让位 —— 全部照写,好过按错的范围吃掉数字。
* 深度缩放后真实范围可能远超屏幕上的那个圆。所以让位范围也用同一个像素上限换算, * 脚印绘制没有像素上限(按真实地面尺寸画),原先「绘制半径封顶导致让位范围
* 否则盘只画到屏幕这么大,外围一圈数字却被无声无息地吃掉了。 * 也得跟着封」的那条换算随之作废。
*/ */
private recomputeUnder() { private recomputeUnder() {
const n = this.count.length; const n = this.count.length;
// 输入引用一模一样 → 结论必然一样。这里要挡住的是「点黑点、切换视图」这类
// 只换了 activeHotspot、却会把 applyAnalysis 连带叫一遍的情况。
const key = this.underKey;
if (
key &&
key.n === n &&
key.discs === this.discs &&
key.grid === this.discGrid &&
key.sig === this.discSig
) {
return;
}
this.underKey = { discs: this.discs, grid: this.discGrid, sig: this.discSig, n };
if (n === 0) { if (n === 0) {
this.under = new Uint8Array(0); this.under = new Uint8Array(0);
return; return;
} }
if (this.discs.length === 0 || this.dLng <= 0 || this.dLat <= 0) { const g = this.discGrid;
if (this.discs.length === 0 || !g || !this.discSig || g.dLng <= 0 || g.dLat <= 0) {
this.under = new Uint8Array(n); this.under = new Uint8Array(n);
return; return;
} }
// 桶半个边长 = 让位缓冲;盘的上限换成度数:MAX_DRAW_PX 像素 ÷ 每像素多少度 const hotDomains = new Set(this.discs.map((d) => d.domainId));
const { label } = labelDomains(this.discSig, g.w, g.h);
const invLng = 1 / g.dLng;
const invLat = 1 / g.dLat;
// 桶半个边长 = 让位缓冲:桶中心 + 四角,五点任一落在上榜域内即整桶让位
const padLng = this.dLng / 2; const padLng = this.dLng / 2;
const padLat = this.dLat / 2; const padLat = this.dLat / 2;
const capLng = (HOTSPOT_MAX_DRAW_PX * padLng) / (GRID.gridPx / 2); const inHot = (lng: number, lat: number): boolean => {
const capLat = (HOTSPOT_MAX_DRAW_PX * padLat) / (GRID.gridPx / 2); const cx = Math.min(g.w - 1, Math.max(0, ((lng - g.originLng) * invLng) | 0));
const cy = Math.min(g.h - 1, Math.max(0, ((lat - g.originLat) * invLat) | 0));
const shapes = this.discs.map((c) => { return hotDomains.has(label[cy * g.w + cx]);
const span = hotspotSpan(c.lat, c.radiusM); };
return {
lng: c.lng,
lat: c.lat,
a: Math.min(span.halfLng, capLng) + padLng,
b: Math.min(span.halfLat, capLat) + padLat,
};
});
const under = new Uint8Array(n); const under = new Uint8Array(n);
for (let i = 0; i < n; i += 1) { for (let i = 0; i < n; i += 1) {
const lng = this.lngDeg[i]; const lng = this.lngDeg[i];
const lat = this.latDeg[i]; const lat = this.latDeg[i];
for (let k = 0; k < shapes.length; k += 1) { if (
const s = shapes[k]; inHot(lng, lat) ||
const dx = (lng - s.lng) / s.a; inHot(lng - padLng, lat - padLat) ||
if (dx > 1 || dx < -1) continue; inHot(lng + padLng, lat - padLat) ||
const dy = (lat - s.lat) / s.b; inHot(lng - padLng, lat + padLat) ||
if (dx * dx + dy * dy <= 1) { inHot(lng + padLng, lat + padLat)
under[i] = 1; ) {
break; under[i] = 1;
}
} }
} }
this.under = under; this.under = under;
......
...@@ -235,7 +235,16 @@ export class HeatLayer { ...@@ -235,7 +235,16 @@ export class HeatLayer {
if (y >= 0 && y <= size.height) inView[v++] = c; if (y >= 0 && y <= size.height) inView[v++] = c;
} }
this.feed = { lng, lat, count, keep: keep ?? null, data }; this.feed = { lng, lat, count, keep: keep ?? null, data };
this.dataset = { data, max: reference(v > 0 ? inView.subarray(0, v) : all.subarray(0, a)) }; const max = reference(v > 0 ? inView.subarray(0, v) : all.subarray(0, a));
// 点表的对象与归一化上限都和上一份一模一样 → 高德那边换了也是同一张图。
// 而 setDataSet 会把整批点重新塞进 WebGL(几万个顶点 + 一次纹理上传),
// 这件事在「开抽屉、切图层、点黑点」这类不会改变视野的调用里发生得莫名其妙地频繁。
// visible 仍然要设:那条路只管显隐,不重传数据。
if (prev !== null && prev.data === data && this.dataset !== null && this.dataset.max === max) {
heat.setOptions({ visible: this.visible });
return;
}
this.dataset = { data, max };
heat.setDataSet(this.dataset); heat.setDataSet(this.dataset);
heat.setOptions({ visible: this.visible }); heat.setOptions({ visible: this.visible });
} }
......
import { describe, expect, it } from 'vitest';
import { domainOutline } from './footprintOutline';
/**
* 轮廓环的守卫。
*
* 这组测试盯的是「一片格子能不能拼成一个闭合环」,而不是像素好不好看。
* 上一版是逐条格边单独描,最短的边只有一格,密集台阶上到处是 butt 端点的缺口,
* 屏幕上看起来就是一堆没连起来的短线。改成闭合环之后,下面这几条必须始终成立:
* - 实心块不管多大,去共线后都只剩 4 个角(不是每个格子 4 个点)
* - 凹形保留凹角的顶点(不能被简化掉)
* - 有洞时洞是独立的反向环
* - 8 邻接的斜角相接算同一片,轮廓要连过去而不是断成两截
*/
/** 用「哪些格属于本域」构造 label(其余为 0),返回 [label, cells] */
function gridOf(w: number, h: number, inside: Array<[number, number]>) {
const label = new Int32Array(w * h);
const cells: number[] = [];
for (const [x, y] of inside) {
label[y * w + x] = 1;
cells.push(y * w + x);
}
return { label, w, h, cells };
}
/** 环的顶点集合(排序成可直接比较的字符串) */
function verts(ring: Int32Array): string[] {
const out: string[] = [];
for (let i = 0; i < ring.length; i += 2) out.push(`${ring[i]},${ring[i + 1]}`);
return out.sort();
}
describe('domainOutline · 格子拼成闭合环', () => {
it('2×2 实心块 → 一个环,去共线后只有 4 个角', () => {
const g = gridOf(4, 4, [
[0, 0],
[1, 0],
[0, 1],
[1, 1],
]);
const rings = domainOutline(g.label, g.w, g.h, 1, g.cells);
expect(rings).toHaveLength(1);
expect(verts(rings[0])).toEqual(['0,0', '0,2', '2,0', '2,2']);
});
it('3×3 实心块 → 仍然 4 个角(长直边不按格子拆成小段)', () => {
const inside: Array<[number, number]> = [];
for (let y = 0; y < 3; y += 1) for (let x = 0; x < 3; x += 1) inside.push([x, y]);
const g = gridOf(5, 5, inside);
const rings = domainOutline(g.label, g.w, g.h, 1, g.cells);
expect(rings).toHaveLength(1);
expect(verts(rings[0])).toEqual(['0,0', '0,3', '3,0', '3,3']);
});
it('L 形保留凹角:6 个顶点,一个都不多一个都不少', () => {
// 3×2 去掉右上角 → 5 格,轮廓 6 个角
const g = gridOf(5, 5, [
[0, 0],
[1, 0],
[0, 1],
[1, 1],
[0, 2],
]);
const rings = domainOutline(g.label, g.w, g.h, 1, g.cells);
expect(rings).toHaveLength(1);
// 形状是 2×2 的方块 + 左下再凸一格:右下凹进一格 (1,2)→(1,3),凹角必须留着
expect(verts(rings[0])).toEqual(['0,0', '0,3', '1,2', '1,3', '2,0', '2,2'].sort());
});
it('中间挖空 → 外环 + 洞环两个闭合环(nonzero 填充才会挖洞)', () => {
const inside: Array<[number, number]> = [];
for (let y = 0; y < 3; y += 1) {
for (let x = 0; x < 3; x += 1) {
if (x === 1 && y === 1) continue;
inside.push([x, y]);
}
}
const g = gridOf(5, 5, inside);
const rings = domainOutline(g.label, g.w, g.h, 1, g.cells);
expect(rings).toHaveLength(2);
const sizes = rings.map((r) => r.length / 2).sort((a, b) => a - b);
// 3×3 实心块(去中心)的外轮廓仍是 4 个角,洞是 1 格 → 4 个角
expect(sizes).toEqual([4, 4]);
});
it('8 邻接的斜角相接算同一片:轮廓不裂成两截', () => {
// 两格只在对角 (1,1) 接触 —— 分析里算同一个域,轮廓也必须连成一个环
const g = gridOf(4, 4, [
[0, 0],
[1, 1],
]);
const rings = domainOutline(g.label, g.w, g.h, 1, g.cells);
expect(rings).toHaveLength(1);
// 两格各自 4 个角,只有接触点 (1,1) 重合 → 7 个不同顶点
expect(new Set(verts(rings[0])).size).toBe(7);
});
it('域内格子列表为空时返回空数组(不抛错)', () => {
const g = gridOf(3, 3, []);
expect(domainOutline(g.label, g.w, g.h, 1, g.cells)).toEqual([]);
});
});
/**
* 格子集合 → 闭合轮廓环。
*
* 黑点范围要画成「一片」而不是「一堆格子边」,关键就在于把格子边界拼成闭合环:
* 逐条边单独 moveTo/lineTo 时,每段都是 butt 端点,台阶拐角外侧会缺一个三角,
* 密集台阶上看起来就是断断续续的碎线(实测截图正是这样)。拼成环之后一次 stroke,
* 拐角由 lineJoin 连起来,轮廓才真的是一整片。
*
* 输出的顶点用**格角整数坐标**(gx∈[0,gw], gy∈[0,gh],gy 向北增),与缩放无关:
* 投影到屏幕是绘制时的事,所以这份拓扑只在喂数据时算一次,缩放平移都不用重算。
*
* 环的方向按「格子的四条边首尾相接」统一(SW→NW→NE→SE→SW),因此域里的洞会自然
* 呈反向环 —— canvas 的 nonzero 填充规则会自己把洞挖出来,不需要额外区分。
*/
/** 方向表:E,N,W,S(与 (dx,dy) 一一对应,相邻格角差恒为 ±1,可直接换算下标) */
const DX = [1, 0, -1, 0];
const DY = [0, 1, 0, -1];
function dirOf(dx: number, dy: number): number {
for (let i = 0; i < 4; i += 1) {
if (DX[i] === dx && DY[i] === dy) return i;
}
return -1;
}
/**
* 去掉共线顶点。
*
* 台阶轮廓里一条直边会被拆成好几段(每个格子贡献一段),不合并的话:
* 1. 顶点数按格子数线性膨胀,投影成本白白翻几倍;
* 2. lineJoin 在一条直线的接缝处也会做一次圆角,长边看起来像一串小鼓包。
*/
function dropCollinear(pts: number[]): number[] {
const n = pts.length / 2;
if (n < 3) return pts;
const out: number[] = [];
for (let i = 0; i < n; i += 1) {
const p = ((i - 1 + n) % n) * 2;
const c = i * 2;
const q = ((i + 1) % n) * 2;
const ax = pts[c] - pts[p];
const ay = pts[c + 1] - pts[p + 1];
const bx = pts[q] - pts[c];
const by = pts[q + 1] - pts[c + 1];
// 叉积为 0 且同向 → 这个点只是直边上的过渡点,去掉
if (ax * by - ay * bx === 0 && ax * bx + ay * by > 0) continue;
out.push(pts[c], pts[c + 1]);
}
return out;
}
/**
* 把一片连通域的格子还原成闭合环(通常 1 个外环;域里有洞时多出反向的洞环)。
*
* @param label 逐格连通域编号(labelDomains 的结果,0 = 不属于任何域)
* @param cells 该域的格子下标(ny * gw + nx)
* @param domainId 该域编号,用来判断邻格是否同域
*
* 只在**域边界**上收集有向边:某格某侧邻格不同域(或出界)才收这条边。
* 边走边拼,遇到对角接触这类「一个角点有两条出边」的歧义时优先左转 ——
* 8 邻接把斜角相接的斑块算成同一域,轮廓也要跟着连过去,不能断成两片。
*/
export function domainOutline(
label: Int32Array,
gw: number,
gh: number,
domainId: number,
cells: readonly number[],
): Int32Array[] {
if (cells.length === 0) return [];
const stride = gw + 1;
const nVerts = stride * (gh + 1);
const cornerKey = (gx: number, gy: number) => gy * stride + gx;
const inDomain = (cx: number, cy: number): boolean => {
if (cx < 0 || cy < 0 || cx >= gw || cy >= gh) return false;
return label[cy * gw + cx] === domainId;
};
// from 角点 → 出边终点列表(一般只有一个;对角接触会有两个)
const outgoing = new Map<number, number[]>();
const addEdge = (ax: number, ay: number, bx: number, by: number) => {
const from = cornerKey(ax, ay);
const to = cornerKey(bx, by);
const arr = outgoing.get(from);
if (arr) arr.push(to);
else outgoing.set(from, [to]);
};
for (let k = 0; k < cells.length; k += 1) {
const cell = cells[k];
const cx = cell % gw;
const cy = (cell / gw) | 0;
// 绕格一圈(SW→NW→NE→SE),只为出界/异域的那条边建边,首尾自然相接
if (!inDomain(cx - 1, cy)) addEdge(cx, cy, cx, cy + 1);
if (!inDomain(cx, cy + 1)) addEdge(cx, cy + 1, cx + 1, cy + 1);
if (!inDomain(cx + 1, cy)) addEdge(cx + 1, cy + 1, cx + 1, cy);
if (!inDomain(cx, cy - 1)) addEdge(cx + 1, cy, cx, cy);
}
const used = new Set<number>();
const rings: Int32Array[] = [];
for (const [start, firstTos] of outgoing) {
for (let fi = 0; fi < firstTos.length; fi += 1) {
const firstTo = firstTos[fi];
if (used.has(start * nVerts + firstTo)) continue;
const pts: number[] = [];
let from = start;
let to = firstTo;
// 沿边界走一圈:每条边只走一次,回到起点即闭合
for (let guard = 0; guard <= nVerts * 4; guard += 1) {
used.add(from * nVerts + to);
pts.push(to % stride, (to / stride) | 0);
if (to === start) break;
const cands = outgoing.get(to);
let next = -1;
if (cands) {
const inDir = dirOf((to % stride) - (from % stride), ((to / stride) | 0) - ((from / stride) | 0));
// 优先级:左转 → 直行 → 右转 → 掉头。左转优先让斜角相接的斑块并成一个环。
const order = [1, 0, 3, 2];
for (let oi = 0; oi < order.length && next < 0; oi += 1) {
for (let ci = 0; ci < cands.length; ci += 1) {
const c = cands[ci];
if (used.has(to * nVerts + c)) continue;
const od = dirOf((c % stride) - (to % stride), ((c / stride) | 0) - ((to / stride) | 0));
if (inDir < 0 || (od - inDir + 4) % 4 === order[oi]) {
next = c;
break;
}
}
}
}
if (next < 0) break; // 走不通(理论上不会发生):把已走的部分当开口环收下
from = to;
to = next;
}
if (pts.length >= 6) {
const simplified = dropCollinear(pts);
if (simplified.length >= 6) rings.push(Int32Array.from(simplified));
}
}
}
return rings;
}
...@@ -70,18 +70,23 @@ describe('HeatLayer.setDataset · 缓存后的点表仍然等于现算的那一 ...@@ -70,18 +70,23 @@ describe('HeatLayer.setDataset · 缓存后的点表仍然等于现算的那一
heat.setDataset(LNG, LAT, COUNT); heat.setDataset(LNG, LAT, COUNT);
heat.setDataset(LNG, LAT, COUNT); heat.setDataset(LNG, LAT, COUNT);
expect(feeds).toHaveLength(2); // 同一批桶、同一视野再喂一次:点表对象与归一化上限都没变,画面必然一样,
// 于是不再向高德重传(那边是一次几万顶点的 WebGL 上传)
expect(feeds).toHaveLength(1);
expect(feeds[0].data).toEqual(expected(null)); expect(feeds[0].data).toEqual(expected(null));
// 第二次拿到的是同一份点表(缓存生效),但内容必须仍然等于现算结果
expect(feeds[1].data).toEqual(expected(null));
const cityMax = feeds[0].max; const cityMax = feeds[0].max;
// 收到街区视野:屏幕外那几个桶不再参与深浅的归一,点表本身却一个都不能少 // 收到街区视野:点表复用同一份引用,但深浅分母必须按新视野重算 → 这一次一定重传
const hood = { zoom: 15, lng: 114.01, lat: 22.6, w: 400, h: 300 }; city.zoom = 15;
const heat2 = new HeatLayer(fakeMap(hood)); city.lng = 114.01;
heat2.setDataset(LNG, LAT, COUNT); city.w = 400;
expect(heat2.count).toBe(6); city.h = 300;
expect(heat2.maxWeight).toBeLessThan(cityMax); heat.setDataset(LNG, LAT, COUNT);
expect(feeds).toHaveLength(2);
expect(feeds[1].data).toBe(feeds[0].data);
expect(feeds[1].max).toBeLessThan(cityMax);
// 点表本身一个都不能少:视野外那几个桶只是不参与分位,仍要画在图上
expect(heat.count).toBe(6);
}); });
it('换过滤器掩码时必须重算点表,不能拿旧点表画新范围', () => { it('换过滤器掩码时必须重算点表,不能拿旧点表画新范围', () => {
......
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { HotspotLayer, type HotspotGrid } from './HotspotLayer';
import type { HotspotRow } from '../aggregate/types';
/**
* 黑点图形的绘制守卫。
*
* 这一组只盯一件事:一片黑点的范围是**一条闭合轮廓**画出来的,不是一堆格子边。
*
* 为什么值得钉死:逐条格边 stroke 时,每段都是独立子路径、butt 端点,90° 台阶拐角
* 外侧缺一个三角。格子越密缺口越多,屏幕上就是一堆没连起来的短线(实测截图如此,
* 用户的原话是「线条杂乱 都没有连接起来」)。闭合环一次 stroke 后,拐角由 lineJoin
* 连起来,这个失效模式就回不来了 —— 而它只在真实地图上肉眼可见,typecheck 与
* 数字类断言都发现不了,所以只能把「画了几条子路径」记下来守。
*/
interface FakeCtx {
calls: Map<string, number>;
[key: string]: unknown;
}
function fakeCtx(): FakeCtx {
const calls = new Map<string, number>();
const hit = (name: string) => calls.set(name, (calls.get(name) ?? 0) + 1);
const ctx: FakeCtx = { calls };
for (const name of [
'setTransform',
'clearRect',
'beginPath',
'closePath',
'moveTo',
'lineTo',
'rect',
'arc',
'arcTo',
'fill',
'stroke',
'fillRect',
'fillText',
'strokeText',
'save',
'restore',
'translate',
'setLineDash',
'clip',
]) {
ctx[name] = () => hit(name);
}
ctx.measureText = (text: string) => ({ width: String(text).length * 6 });
return ctx;
}
class FakeCustomLayer {
static created: FakeCustomLayer[] = [];
render: (() => void) | null = null;
constructor(readonly canvas: HTMLCanvasElement) {
FakeCustomLayer.created.push(this);
}
setMap() {}
show() {}
hide() {}
}
const VIEW = { zoom: 13, lng: 114.0015, lat: 22.5015, w: 800, h: 600 };
function fakeMap() {
return {
getSize: () => ({ width: VIEW.w, height: VIEW.h }),
getCenter: () => ({ getLng: () => VIEW.lng, getLat: () => VIEW.lat }),
getZoom: () => VIEW.zoom,
lngLatToContainer: () => ({ x: VIEW.w / 2, y: VIEW.h / 2 }),
containerToLngLat: () => ({ getLng: () => VIEW.lng, getLat: () => VIEW.lat }),
} as unknown as AMap.Map;
}
const ctx = fakeCtx();
let restoreCanvas: (() => void) | null = null;
let restoreAmap: (() => void) | null = null;
beforeEach(() => {
ctx.calls.clear();
FakeCustomLayer.created = [];
const proto = window.HTMLCanvasElement.prototype as unknown as { getContext: () => unknown };
const original = proto.getContext;
proto.getContext = () => ctx;
restoreCanvas = () => {
proto.getContext = original;
};
const g = globalThis as Record<string, unknown>;
const prev = g.AMap;
g.AMap = { CustomLayer: FakeCustomLayer };
restoreAmap = () => {
g.AMap = prev;
};
});
afterEach(() => {
restoreCanvas?.();
restoreAmap?.();
});
/** 100m 见方的栅格,域是一块 4×4(16 格) */
const GRID: HotspotGrid = {
originLng: 114.0,
originLat: 22.5,
dLng: 0.001,
dLat: 0.001,
w: 40,
h: 40,
};
function squareDomain(): { mask: Uint8Array; row: HotspotRow } {
const mask = new Uint8Array(GRID.w * GRID.h);
for (let y = 0; y < 4; y += 1) {
for (let x = 0; x < 4; x += 1) mask[y * GRID.w + x] = 1;
}
const row = {
id: 0,
domainId: 1,
lng: 114.0015,
lat: 22.5015,
count: 42,
cells: 16,
radiusM: 113,
cellMeters: 100,
} as unknown as HotspotRow;
return { mask, row };
}
describe('黑点图形 · 一片一条闭合轮廓', () => {
it('4×4 的域只产生 1 条闭合子路径,而不是 16 个格子的边', () => {
const layer = new HotspotLayer(fakeMap());
const { mask, row } = squareDomain();
layer.setData([row], GRID, mask);
const render = FakeCustomLayer.created[0]?.render;
expect(render).toBeTypeOf('function');
render!();
// 一条闭合环 = 一次 closePath;旧的逐格描边根本不 closePath。
// 注意排名牌也走 roundRectPath(内部会 closePath),所以不能断言「恰好 1 次」,
// 改用 moveTo 的次数来区分:整片轮廓只有 1 个起点,旧画法每条格边都是一个起点。
expect(ctx.calls.get('closePath') ?? 0).toBeGreaterThanOrEqual(1);
expect(ctx.calls.get('moveTo') ?? 0).toBeLessThanOrEqual(5);
// 旧画法每格一个 ctx.rect;闭合环用 lineTo 连边,一次 rect 都不该有
expect(ctx.calls.get('rect') ?? 0).toBe(0);
expect(ctx.calls.get('stroke') ?? 0).toBeGreaterThanOrEqual(1);
expect(ctx.calls.get('fill') ?? 0).toBeGreaterThanOrEqual(1);
// 圆角:轮廓的每个顶点一次 arcTo(4×4 方块去共线后 4 个角)。
// 排名牌走 roundRectPath 也会各贡献 4 次,所以只断下界。
expect(ctx.calls.get('arcTo') ?? 0).toBeGreaterThanOrEqual(4);
// 外发光 = 同一路径两层宽描边 + 一层主边,至少 3 次 stroke
expect(ctx.calls.get('stroke') ?? 0).toBeGreaterThanOrEqual(3);
layer.destroy();
});
it('轮廓内的点能命中这一片,轮廓外的点不命中', () => {
const layer = new HotspotLayer(fakeMap());
const { mask, row } = squareDomain();
layer.setData([row], GRID, mask);
FakeCustomLayer.created[0]?.render?.();
// 视图中心就是这一片的中心 → 屏幕中心必落在格子内
expect(layer.hitAt(VIEW.w / 2, VIEW.h / 2)).toBe(0);
// 域只占中心一小块,左上角远在域外
expect(layer.hitAt(30, 30)).toBe(-1);
layer.destroy();
});
it('没拿到 grid+mask 时退回圆:走 arc,不画格子路径', () => {
const layer = new HotspotLayer(fakeMap());
const { row } = squareDomain();
layer.setData([row]);
FakeCustomLayer.created[0]?.render?.();
expect(ctx.calls.get('arc') ?? 0).toBeGreaterThanOrEqual(1);
expect(ctx.calls.get('rect') ?? 0).toBe(0);
layer.destroy();
});
});
/**
* 这两条守的是「炫」的那部分:外光雾 + 三明治描边,以及选中那一下不加戏。
*
* 它们都属于「画得好看」而不是「算得对」,没有数值可以断言,只能钉住笔数:
* 少画一笔就退回一个平淡的描边圈,多画一笔则会在几十片同屏时拖慢拖动。
*/
describe('黑点图形 · 光效分档', () => {
/** 20×20 的域:z13 下等效半径远超满配门槛,走完整特效 */
function bigDomain(): { mask: Uint8Array; row: HotspotRow } {
const mask = new Uint8Array(GRID.w * GRID.h);
for (let y = 0; y < 20; y += 1) {
for (let x = 0; x < 20; x += 1) mask[y * GRID.w + x] = 1;
}
const row = {
id: 0,
domainId: 1,
lng: 114.0015,
lat: 22.5015,
count: 420,
cells: 400,
radiusM: 565,
cellMeters: 100,
} as unknown as HotspotRow;
return { mask, row };
}
it('大片走满配:三档光雾 + 暗底 + 主边 + 高光,且不再往轮廓内侧打光', () => {
const layer = new HotspotLayer(fakeMap());
const { mask, row } = bigDomain();
layer.setData([row], GRID, mask);
FakeCustomLayer.created[0]?.render?.();
// 内侧发光已去掉:不再需要把轮廓 clip 一次再描宽线
expect(ctx.calls.get('clip') ?? 0).toBe(0);
// 三档光雾 + 暗底 + 主边 + 高光 = 6 笔
expect(ctx.calls.get('stroke') ?? 0).toBeGreaterThanOrEqual(6);
expect(ctx.calls.get('fill') ?? 0).toBeGreaterThanOrEqual(1);
layer.destroy();
});
it('选中只在本层加粗描边,不额外建画布、不起动画', () => {
const layer = new HotspotLayer(fakeMap());
const { mask, row } = bigDomain();
layer.setData([row], GRID, mask);
FakeCustomLayer.created[0]?.render?.();
const idle = ctx.calls.get('stroke') ?? 0;
ctx.calls.clear();
layer.setOptions({ active: 0 });
FakeCustomLayer.created[0]?.render?.();
// 同一批笔画,选中只是把线宽与浓度提一档 —— 不再有扩散光圈那几笔
expect(ctx.calls.get('stroke') ?? 0).toBe(idle);
// 全程只有一张画布:每片都配一张全屏 backing store 在 DPR 2 下是几十兆
expect(FakeCustomLayer.created).toHaveLength(1);
layer.destroy();
});
});
/**
* 把一组闭合轮廓环描进当前 path,折点处倒圆角。
*
* 黑点轮廓是格子拼出来的,全是 90° 台阶;直接连折线就是锯齿。arcTo 只动角、不动边 ——
* 长直边仍然笔直,台阶尖角化成小圆弧,「看起来是圆弧」和「边界仍然贴着格子」才能同时成立。
*
* 起笔放在最后一条边的中点:闭合后正好回到这里,最后一条边也能被圆角化,
* 否则会在起点处留一个尖角。
*
* ⚠️ `beginPath` 由调用方负责:同一片要复用同一条路径画光雾、填充、描边,
* 复用比 trace 几遍便宜得多。
*/
/**
* 只要这三件事就够描一条路径 —— CanvasRenderingContext2D 与 Path2D 都满足。
* 于是同一段代码既能画进画布的当前路径,也能建一条可复用的 Path2D。
*/
type PathSink = Pick<CanvasRenderingContext2D, 'moveTo' | 'arcTo' | 'closePath'>;
export function traceRoundedRings(
ctx: PathSink,
rings: Float32Array[],
radius: number,
): void {
for (let r = 0; r < rings.length; r += 1) {
const ring = rings[r];
const n = ring.length / 2;
if (n < 3) continue;
ctx.moveTo((ring[(n - 1) * 2] + ring[0]) / 2, (ring[(n - 1) * 2 + 1] + ring[1]) / 2);
for (let i = 0; i < n; i += 1) {
const j = (i + 1) % n;
ctx.arcTo(ring[i * 2], ring[i * 2 + 1], ring[j * 2], ring[j * 2 + 1], radius);
}
ctx.closePath();
}
}
...@@ -303,26 +303,24 @@ function AlgoGuide({ params, background }: { params: AnalysisParams; background: ...@@ -303,26 +303,24 @@ function AlgoGuide({ params, background }: { params: AnalysisParams; background:
<div className="hm-algo__sec-title">图上每种标记的含义</div> <div className="hm-algo__sec-title">图上每种标记的含义</div>
<dl className="hm-algo__marks"> <dl className="hm-algo__marks">
<div> <div>
<dt>圆盘 + 细环</dt> <dt>范围块 + 轮廓</dt>
<dd> <dd>
{'该黑点的'} {'该黑点的'}
<b>覆盖范围</b> <b>覆盖范围</b>
{'。圆盘随地图同步缩放,放大后可沿盘边核对范围。它是依据实际面积折算的'} {'。画的正是构成这个黑点的那批方格的'}
<b>示意圈</b> <b>真实脚印</b>
{' —— '} {'(随地图同步缩放,放大后可沿轮廓核对)—— 范围块内的案件就是清单里列出的那些,明细列表里每一行都落在范围内;边界贴合方格,不代表街道划分。需要查看该片的具体案件,点击范围块或清单对应行即可展开明细。'}
<b>范围准确,边界不代表街道划分</b>
{';需要查看该片的具体案件,点击圆盘或清单对应行即可展开明细。'}
</dd> </dd>
</div> </div>
<div> <div>
<dt>盘心的数字</dt> <dt>块心的数字</dt>
<dd> <dd>
{'该黑点的'} {'该黑点的'}
<b>案件总数</b> <b>案件总数</b>
{',与左侧清单同一行为'} {',与左侧清单同一行为'}
<b>同一个数值</b> <b>同一个数值</b>
{ {
'。圆盘覆盖区域内的方格数字已整块让位 —— 一个位置只保留一个数,不会出现「圈里 30、清单 51」这类对不上的读法。' '。范围块覆盖区域内的方格数字已整块让位 —— 一个位置只保留一个数,不会出现「圈里 30、清单 51」这类对不上的读法。'
} }
</dd> </dd>
</div> </div>
...@@ -332,12 +330,12 @@ function AlgoGuide({ params, background }: { params: AnalysisParams; background: ...@@ -332,12 +330,12 @@ function AlgoGuide({ params, background }: { params: AnalysisParams; background:
{'该处在左侧清单中的'} {'该处在左侧清单中的'}
<b>名次</b> <b>名次</b>
{ {
'。颜色一一对应:1~3 名红、4~8 名橙、其余蓝。点击圆盘或清单条目会定位到该处,并展开这一片的案件明细。' '。颜色一一对应:1~3 名红、4~8 名橙、其余蓝。点击范围块或清单条目会定位到该处,并展开这一片的案件明细。'
} }
</dd> </dd>
</div> </div>
<div> <div>
<dt>盘外的数字</dt> <dt>块外的数字</dt>
<dd> <dd>
{'屏幕方格('} {'屏幕方格('}
<b>48×48 像素</b> <b>48×48 像素</b>
......
...@@ -35,6 +35,7 @@ export function useBootstrap(): void { ...@@ -35,6 +35,7 @@ export function useBootstrap(): void {
const setDataOrigin = useHeatmapStore((s) => s.setDataOrigin); const setDataOrigin = useHeatmapStore((s) => s.setDataOrigin);
const patchPerf = useHeatmapStore((s) => s.patchPerf); const patchPerf = useHeatmapStore((s) => s.patchPerf);
const setDataWarn = useHeatmapStore((s) => s.setDataWarn); const setDataWarn = useHeatmapStore((s) => s.setDataWarn);
const setDataReady = useHeatmapStore((s) => s.setDataReady);
useEffect(() => { useEffect(() => {
let cancelled = false; let cancelled = false;
...@@ -71,6 +72,7 @@ export function useBootstrap(): void { ...@@ -71,6 +72,7 @@ export function useBootstrap(): void {
if (!imported) { if (!imported) {
setDataWarn(null); setDataWarn(null);
setDataReady(false);
setStatus('empty'); setStatus('empty');
return; return;
} }
...@@ -133,17 +135,45 @@ export function useBootstrap(): void { ...@@ -133,17 +135,45 @@ export function useBootstrap(): void {
} else { } else {
setDataWarn(null); setDataWarn(null);
} }
// 换一份数据 → 旧绿灯立刻熄灭,等这一轮分析跑完、三层自检通过再点亮(见 MapStage)
setDataReady(false);
/**
* 装载前先确保聚合 Worker 是干净的。
* 原因:aggregateClient 是模块级单例,Worker 里的 `store` 只在 handleInit 时建一次。
* 开发期 HMR、React 严格模式重复 bootstrap、或换数据集时,若旧 Worker 没被正确收掉,
* 它仍装着「上一份 / 半截」数据 —— 于是同一份文件出现「刷新前 0 处、刷新后正常」这类偶发:
* 刷新强制建了一个干净 Worker 才对。这里每次装载先 dispose,从根上消灭这种脏状态。
* 正常整页加载时 Worker 本就是 null,dispose 是空操作,无额外开销。
*/
aggregateClient.dispose();
await aggregateClient.initFromColumns( await aggregateClient.initFromColumns(
imported.meta, imported.meta,
imported.columns, imported.columns,
// 数据标识:同一份数据重复 init 不重建 Worker,换了一份就重建(见 aggregateClient.postInit) // 数据标识:同一份数据重复 init 不重建 Worker,换了一份就重建(见 aggregateClient.postInit)
`${imported.manifest.importedAt}:${imported.manifest.count}`, `${imported.manifest.importedAt}:${imported.manifest.count}`,
); );
/**
* 注册「重建当前数据集」的入口,供降噪自检在发现数据漂移时调用。
* initFromColumns 会把 columns 的 buffer transfer 给 Worker(detach),所以这里不能复用
* imported.columns —— 每次 reload 都重新从 IndexedDB 读一份新的完整数据再建干净 Worker。
*/
aggregateClient.reload = async () => {
const rec = await readImportedIncidents();
if (!rec) return;
await aggregateClient.initFromColumns(
rec.meta,
rec.columns,
`${rec.manifest.importedAt}:${rec.manifest.count}`,
);
};
if (cancelled) return; if (cancelled) return;
patchPerf({ loadMs: performance.now() - t0 }); patchPerf({ loadMs: performance.now() - t0 });
setProgress(null); setProgress(null);
// 数据已加载 + 体检(gridBoxSource 判 bounds)已做:点亮头部绿灯,表示数据层就绪(含黑点)。
// 黑点分析若后续明确失败,runAnalysis 会把它灭掉;正常出黑点 / 0 处都维持亮。
setDataReady(true);
setStatus('ready'); setStatus('ready');
scheduleDetail(); scheduleDetail();
} catch (err) { } catch (err) {
...@@ -160,5 +190,5 @@ export function useBootstrap(): void { ...@@ -160,5 +190,5 @@ export function useBootstrap(): void {
return () => { return () => {
cancelled = true; cancelled = true;
}; };
}, [setStatus, setProgress, setMeta, setDetailReady, setDataOrigin, patchPerf, setDataWarn]); }, [setStatus, setProgress, setMeta, setDetailReady, setDataOrigin, patchPerf, setDataWarn, setDataReady]);
} }
...@@ -27,7 +27,7 @@ function Pill({ ...@@ -27,7 +27,7 @@ function Pill({
}: { }: {
icon: ReactNode; icon: ReactNode;
label: string; label: string;
value: string; value: ReactNode;
/** 悬浮说明:这个数字是从哪儿来的、精确到个位是多少 */ /** 悬浮说明:这个数字是从哪儿来的、精确到个位是多少 */
tip?: ReactNode; tip?: ReactNode;
}) { }) {
...@@ -196,6 +196,7 @@ export function HeaderBar() { ...@@ -196,6 +196,7 @@ export function HeaderBar() {
const meta = useHeatmapStore((s) => s.meta); const meta = useHeatmapStore((s) => s.meta);
const status = useHeatmapStore((s) => s.status); const status = useHeatmapStore((s) => s.status);
const dataOrigin = useHeatmapStore((s) => s.dataOrigin); const dataOrigin = useHeatmapStore((s) => s.dataOrigin);
const dataReady = useHeatmapStore((s) => s.dataReady);
const importInfo = useHeatmapStore((s) => s.importInfo); const importInfo = useHeatmapStore((s) => s.importInfo);
const coverage = meta ? spanDays(meta.timeRange.min, meta.timeRange.max) : 0; const coverage = meta ? spanDays(meta.timeRange.min, meta.timeRange.max) : 0;
const { active: isFs, toggle: toggleFs } = useFullscreen(); const { active: isFs, toggle: toggleFs } = useFullscreen();
...@@ -274,7 +275,30 @@ export function HeaderBar() { ...@@ -274,7 +275,30 @@ export function HeaderBar() {
value={coverage ? `${coverage}天` : '—'} value={coverage ? `${coverage}天` : '—'}
tip={coverageTip} tip={coverageTip}
/> />
<Pill icon={<AppstoreOutlined />} label="状态" value={statusText} /> <Pill
icon={<AppstoreOutlined />}
label="状态"
value={
dataReady ? (
<span style={{ display: 'inline-flex', alignItems: 'center', color: '#52c41a' }}>
<span
style={{
display: 'inline-block',
width: 8,
height: 8,
borderRadius: '50%',
background: '#52c41a',
marginRight: 6,
boxShadow: '0 0 0 3px rgba(82,196,26,0.22)',
}}
/>
数据已就绪
</span>
) : (
statusText
)
}
/>
<ImportControl /> <ImportControl />
{username && ( {username && (
<Dropdown <Dropdown
......
...@@ -550,6 +550,15 @@ interface HeatmapState { ...@@ -550,6 +550,15 @@ interface HeatmapState {
* 为空表示体检通过。见 useBootstrap.validateImportedForAnalysis。 * 为空表示体检通过。见 useBootstrap.validateImportedForAnalysis。
*/ */
dataWarn: string | null; dataWarn: string | null;
/**
* 黑点分析「数据正确性校验」通过的绿灯标志。
*
* 与 `dataWarn`(这份数据字段写坏)不同:那是加载时一次性体检的结论;这是**每一次
* 黑点分析跑完、三层自检(筛选就绪 / 无数据漂移 / 输入未中途变化)都过**之后才点亮,
* 表示「这次装入的数据、筛选、参数都齐了,黑点计算本身也正常完成」—— 包括黑点结果。
* 一旦分析失败 / 筛选未就绪 / 触发了自动重跑,立即熄灭,绝不让旧绿灯误导判断。
*/
dataReady: boolean;
/** 清单里被点中的黑点下标,地图高亮 + 明细抽屉共用 */ /** 清单里被点中的黑点下标,地图高亮 + 明细抽屉共用 */
activeHotspot: number | null; activeHotspot: number | null;
/** /**
...@@ -706,6 +715,8 @@ interface HeatmapState { ...@@ -706,6 +715,8 @@ interface HeatmapState {
setDataOrigin: (origin: HeatmapState['dataOrigin'], info?: ImportManifest | null) => void; setDataOrigin: (origin: HeatmapState['dataOrigin'], info?: ImportManifest | null) => void;
/** 加载后写入数据体检结论(meta.bounds 等写坏时给一句告警,正常为空) */ /** 加载后写入数据体检结论(meta.bounds 等写坏时给一句告警,正常为空) */
setDataWarn: (msg: string | null) => void; setDataWarn: (msg: string | null) => void;
/** 黑点分析数据校验通过 → 点亮头部绿灯;失败 / 未就绪 → 熄灭 */
setDataReady: (v: boolean) => void;
/** 导入解析的实时进度;传 null 表示这一轮解析结束了 */ /** 导入解析的实时进度;传 null 表示这一轮解析结束了 */
setImportProgress: (p: ImportProgressInfo | null) => void; setImportProgress: (p: ImportProgressInfo | null) => void;
...@@ -860,6 +871,7 @@ export const useHeatmapStore = create<HeatmapState>((set, get) => ({ ...@@ -860,6 +871,7 @@ export const useHeatmapStore = create<HeatmapState>((set, get) => ({
analysisLoading: false, analysisLoading: false,
analysisError: null, analysisError: null,
dataWarn: null, dataWarn: null,
dataReady: false,
activeHotspot: null, activeHotspot: null,
hotspotFocusSeq: 0, hotspotFocusSeq: 0,
analysisSeq: 0, analysisSeq: 0,
...@@ -1037,6 +1049,7 @@ export const useHeatmapStore = create<HeatmapState>((set, get) => ({ ...@@ -1037,6 +1049,7 @@ export const useHeatmapStore = create<HeatmapState>((set, get) => ({
set((s) => ({ analysisSeq: s.analysisSeq + 1, analysisError: null })), set((s) => ({ analysisSeq: s.analysisSeq + 1, analysisError: null })),
/** 加载后写入数据体检结论(meta.bounds 等写坏时给一句告警,正常为空) */ /** 加载后写入数据体检结论(meta.bounds 等写坏时给一句告警,正常为空) */
setDataWarn: (msg: string | null) => set({ dataWarn: msg }), setDataWarn: (msg: string | null) => set({ dataWarn: msg }),
setDataReady: (v: boolean) => set({ dataReady: v }),
/** /**
* 点中一个黑点:地图要飞到那一片、黑点盘要亮起来,所以先把一屏聚焦收回。 * 点中一个黑点:地图要飞到那一片、黑点盘要亮起来,所以先把一屏聚焦收回。
* *
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!