Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
sutpc
/
heatmap
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 5b138bcf
authored
Nov 04, 2026
by
liimin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化视觉
1 parent
7a1cbd3d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
150 additions
and
12 deletions
.workbuddy/memory/2026-11-04.md
src/features/heatmap/MapStage.tsx
src/features/heatmap/map/HotspotLayer.ts
src/features/heatmap/map/focusView.test.ts
src/features/heatmap/map/focusView.ts
src/features/heatmap/map/hotspotLayer.test.ts
src/layout/HeaderBar.tsx
.workbuddy/memory/2026-11-04.md
View file @
5b138bc
...
...
@@ -277,3 +277,34 @@ keep=null/无黑点/无栅格不分割/缓存键含 grid+sig)。
-
测试:
`hotspotLayer.test.ts`
满配用例改为断言
`clip === 0`
、
`stroke >= 6`
;
首个闭合轮廓用例
`stroke >= 4`
下调为
`>= 3`
(精简档两层光雾 + 主边)。
-
校验:tsc 0 错;
`src/features/heatmap/map`
102 passed(11 文件)、全量此前 470 passed;eslint 0。未提交。
## 内圈光晕根治 + 切换黑点自动取景(第二轮反馈)
**① 内圈光晕的真正来源**
:不是上一轮删掉的
`clip`
内侧发光,而是
**外光雾本身**
。
光雾是「同一条轮廓描 2~3 遍宽线」,线宽必然一半落在轮廓内;后面那层 fill 只有
0.
14 透明度,0.34 的光雾隔一层 14% 的膜照样看得见 —— 屏上就是轮廓里又套了一圈亮边。
修法:
`paintFootprint`
在光雾之后加一步
`globalCompositeOperation='destination-out'`
+
`fill(path)`
,把本层画布上轮廓内的像素擦成透明(不动底下热力与地图,本层是独立画布),
硬边由暗底 4px + 主边 2.2px 盖住;
`fill`
用默认 nonzero,带洞脚印的洞(轮廓外)保留光。
**两个坑**
:
-
擦除时
`destination-out`
也吃
`globalAlpha`
,而选中某片时其余片按
`DIMMED_ALPHA=0.62`
画 ——
必须临时把 globalAlpha 拉满再擦,否则只擦掉 62%、留 38% 残光(且只在选中时复发)。
-
每片每帧多一次 fill,相比原来两次几十像素宽描边仍便宜。
**② 切换黑点自动取景**
:
-
新
`hotspotBounds(grid,mask,domainId)`
取代
`hotspotExtentMeters`
:按域内格子取 geobbox,
交给
`frameBounds`
(宽高两头各算、避开右缘抽屉与左侧清单、四周 56px 呼吸位),
不再用「质心 + 包围半径」的圆 —— L 形/细长脚印按圆取景会把枝留在屏外。
-
上限
`HOTSPOT_FIT_MAX_ZOOM=17`
(frameBounds 默认 16;黑点最小一格 100m,z16 才 45px 太小)。
-
决策抽成纯函数
`hotspotCameraIntent`
(focusView.ts),四条分支:
`fit-switch`
(切到另一片,放大缩小都允许)/
`fit-recover`
(同一片但质心出屏)/
`fit-zoom-in`
(同一片在屏但当前更小)/
`hold`
(同一片且已够大,绝不动、绝不往回缩)。
「切换」按
**行对象判等**
判(
`lastFocusRowRef`
),不用序号:筛选一变同序号可能是另一片。
-
**不看来源**
(地图点 / 清单定位):早先按来源分叉的代价是「城市级别点同一个黑点没反应」。
连带删除
`spotFromMapRef`
与
`focusHotspot(idx, quiet)`
的 quiet 参数(原来 4 处接线)。
-
点击空白清黑点时
`lastFocusRowRef=null`
,重新点同一片按切换处理。
-
日志新增
`黑点取景(切换)/(拉回视野)/(放大)`
三种原因字样,
`[camera]`
可区分动因。
**测试**
:
`hotspotLayer.test.ts`
满配用例断言
`clip===0`
、
`erase>=1`
(fake ctx 的 fill 记录
调用时的合成模式)、
`fill>=2`
;
`focusView.test.ts`
新增 4 例钉死四种动因(含浮点抖动 0.01)。
**校验**
:tsc 0 错;vitest
**474 passed(38 文件)**
;eslint 0;vite build 通过。未提交。
src/features/heatmap/MapStage.tsx
View file @
5b138bc
This diff is collapsed.
Click to expand it.
src/features/heatmap/map/HotspotLayer.ts
View file @
5b138bc
...
...
@@ -677,11 +677,13 @@ export class HotspotLayer {
*
* 层次(由外到内):
* 1. 外光雾:同一条路径叠 2~3 层描边,由内到外逐层加宽、变淡 —— 冲击力主要来自这一层;
* 2. 底面填充:圈内那层蒙层,压住已经淡掉的热力;
* 3. 三明治描边:暗底(宽)→ 主边(分档色)→ 亮线(细高光),边界因此有厚度。
* 2. 擦内半:destination-out 把光雾落在轮廓里的那一半擦掉,光只留在外面;
* 3. 底面填充:圈内那层蒙层,压住已经淡掉的热力;
* 4. 三明治描边:暗底(宽)→ 主边(分档色)→ 亮线(细高光),边界因此有厚度。
*
* ⚠️ 轮廓内侧不再做发光:那两笔要把轮廓裁进路径再描几十像素宽线,是整片最贵的两次描边,
* 而它换来的只是「圈里比圈外亮一点」——圈内本来就有填充,读起来没有增益。
* ⚠️ 第 2 步不能省。光雾是「描宽线」,线宽必然一半在内、一半在外;只拿一层 0.14 的
* 填充去压,0.34 的光隔着一层 14% 的膜照样看得见 —— 屏上就是轮廓里还套着一圈亮边
* (用户连着反馈了两次)。擦掉才是真的只在外面。
*
* ⚠️ 分档:屏幕上的片越大(用户看得越近),笔数越多。全市视图下几十片同时在场、
* 每片才十几像素,把满配的笔全画上会把拖动拖慢;近看时一屏通常只有几片,正好上满。
...
...
@@ -712,7 +714,7 @@ export class HotspotLayer {
ctx
.
lineCap
=
'round'
;
// ---- 1. 外光雾 ----
//
先画光、再填充:填充压住光晕朝内的那一半,留下的就只是轮廓外那一圈光
。
//
光雾本来是「内外各一半」的:轮廓内侧那一半由下一步擦掉,只留外面这一圈
。
const
glow
=
active
?
p
.
glowActive
:
p
.
glow
;
const
w0
=
Math
.
max
(
9
,
Math
.
min
(
active
?
34
:
24
,
effR
*
0.55
));
if
(
rich
)
{
...
...
@@ -730,11 +732,29 @@ export class HotspotLayer {
}
}
// ---- 2. 底面填充 ----
// ---- 2. 擦掉光雾朝内的那一半 ----
// 光雾是「同一条轮廓描几遍宽线」,线宽有一半落在轮廓内侧。只靠后面那层 fill 压不住:
// fill 只有 0.14 透明度,0.34 的光雾隔着一层 14% 的膜照样看得见 ——
// 屏上就是「轮廓里面还套着一圈亮边」。
// destination-out 把本层画布上轮廓内部的像素直接擦成透明,底下的热力与地图一点不受影响
// (本层自己有独立画布)。擦出来的硬边随后由暗底(4px)与主边(2.2px)盖住。
// 用默认的 nonzero 填充:带洞的脚印洞里那圈光本来就该留着 —— 洞是轮廓外。
//
// ⚠️ 擦的时候必须临时把 globalAlpha 拉满:选中某一片时,其余各片是按 0.62 画的
// (见 DIMMED_ALPHA),而 destination-out 也吃 globalAlpha —— 0.62 只能擦掉 62%,
// 剩下 38% 的内圈光正好留在屏上,问题会「只在选中时复发」。
const
alpha
=
ctx
.
globalAlpha
;
ctx
.
globalAlpha
=
1
;
ctx
.
globalCompositeOperation
=
'destination-out'
;
fillPath
(
ctx
,
path
);
ctx
.
globalCompositeOperation
=
'source-over'
;
ctx
.
globalAlpha
=
alpha
;
// ---- 3. 底面填充 ----
ctx
.
fillStyle
=
active
?
p
.
fillActive
:
p
.
fill
;
fillPath
(
ctx
,
path
);
// ----
3
. 暗底 ----
// ----
4
. 暗底 ----
// 宽而深的一圈,把轮廓从暖色热力底图里「切」出来。
// 只在满配档做:它靠「宽」起作用,片太小时压到轮廓上只会糊成脏边。
if
(
rich
)
{
...
...
@@ -743,7 +763,7 @@ export class HotspotLayer {
strokePath
(
ctx
,
path
);
}
// ----
4
. 主边 + 边上的高光 ----
// ----
5
. 主边 + 边上的高光 ----
// 边界要「实」,光才托得住。选中再粗一档。
ctx
.
lineWidth
=
active
?
3
:
2.2
;
ctx
.
strokeStyle
=
active
?
p
.
ringActive
:
p
.
ring
;
...
...
src/features/heatmap/map/focusView.test.ts
View file @
5b138bc
...
...
@@ -6,6 +6,7 @@ import {
centerForPointAt
,
FRAME_PAD_PX
,
frameBounds
,
hotspotCameraIntent
,
RECENTER_MS
,
SPOTLIGHT_MAX_ZOOM
,
visibleSpot
,
...
...
@@ -229,3 +230,41 @@ describe('取景时长 · 定位与复位的快慢关系', () => {
expect
(
RECENTER_MS
).
toBeLessThanOrEqual
(
400
);
});
});
/**
* 点黑点之后镜头要不要动、怎么动。
*
* 钉的是四件事,每一件都对应一次真实的坏体验:
* 1. 切换黑点必须重新取景 —— 用户原话「切换黑点,我想让该黑点出现自动调整后合适的视口」;
* 2. 切换时允许缩小 —— 不允的话,从 z16 的路口切到两公里外的大片,屏上只剩几个格子;
* 3. 同一片、已经够大 → 绝不动镜头 —— 早先「点一下地图画面就跳」的投诉来源;
* 4. 同一片、比合适视口更小 → 放大,但绝不往回缩(往回缩只发生在切换那一条)。
*/
describe
(
'hotspotCameraIntent · 黑点取景的四种动因'
,
()
=>
{
const
base
=
{
switched
:
false
,
onScreen
:
true
,
currentZoom
:
13
,
fitZoom
:
15
,
};
it
(
'切到另一片:一律重新取景,哪怕当前已经比合适视口更近'
,
()
=>
{
expect
(
hotspotCameraIntent
({
...
base
,
switched
:
true
,
currentZoom
:
17
})).
toBe
(
'fit-switch'
);
expect
(
hotspotCameraIntent
({
...
base
,
switched
:
true
,
onScreen
:
false
})).
toBe
(
'fit-switch'
);
});
it
(
'同一片但质心在屏幕外:拉回视野'
,
()
=>
{
expect
(
hotspotCameraIntent
({
...
base
,
onScreen
:
false
})).
toBe
(
'fit-recover'
);
});
it
(
'同一片、比合适视口更小:放大到位(城市级别点一个小黑点,不放大等于没反应)'
,
()
=>
{
expect
(
hotspotCameraIntent
({
...
base
,
currentZoom
:
12
,
fitZoom
:
16
})).
toBe
(
'fit-zoom-in'
);
});
it
(
'同一片、已经与合适视口持平或更近:不动,绝不往回缩'
,
()
=>
{
expect
(
hotspotCameraIntent
({
...
base
,
currentZoom
:
15
,
fitZoom
:
15
})).
toBe
(
'hold'
);
expect
(
hotspotCameraIntent
({
...
base
,
currentZoom
:
16.5
,
fitZoom
:
15
})).
toBe
(
'hold'
);
// 浮点误差不触发第二次取景
expect
(
hotspotCameraIntent
({
...
base
,
currentZoom
:
14.995
,
fitZoom
:
15
})).
toBe
(
'hold'
);
});
});
src/features/heatmap/map/focusView.ts
View file @
5b138bc
...
...
@@ -94,6 +94,41 @@ export function centerForPointAt(
return
[
point
.
lng
-
dx
/
pxPerDegLng
(
zoom
),
point
.
lat
+
dy
/
pxPerDegLat
(
zoom
,
point
.
lat
)];
}
/**
* 点到一片黑点之后,镜头该怎么办。
*
* - `fit-switch`:切到了另一片 —— 按这一片的包围盒重新取景,放大、缩小都允许。
* 用户的原话是「切换黑点,我想让该黑点出现自动调整后合适的视口」;
* 这里若沿用「只放大不缩小」的老规则,从一片小路口的 z16 切到两公里外的大片,
* 屏幕上就只剩几个格子。
* - `fit-recover`:同一片,但质心已经不在屏幕上(用户在别处拖走了)—— 拉回来。
* - `fit-zoom-in`:同一片、在屏幕上,但当前比合适视口更小 —— 放大到位。
* 城市级别点一个小黑点,屏幕上它只有十几像素,不放大就等于「点了没反应」。
* - `hold`:什么都不做。同一片、在屏幕上、而且已经不比合适视口更远 —— 不动。
* 这一档是「点一下地图,画面就跳」的解药:用户放大核对某一处时再点它一次,
* 镜头纹丝不动;而这里也绝不会往回缩(只有 `fit-switch` 允许缩小)。
*
* ⚠️ 不看这一下是「从地图点的」还是「从清单点定位」的:来源只解释了用户为什么点,
* 不改变「这一片此刻在屏幕上够不够大」这个事实。早先按来源分叉,代价是城市级别
* 点同一个黑点没反应。
*/
export
type
HotspotCameraIntent
=
'fit-switch'
|
'fit-recover'
|
'fit-zoom-in'
|
'hold'
;
export
function
hotspotCameraIntent
(
opts
:
{
/** 这次点的是不是另一片(按行对象判等,不是序号,见 MapStage 的 lastFocusRowRef) */
switched
:
boolean
;
/** 质心还在不在当前视野里 */
onScreen
:
boolean
;
currentZoom
:
number
;
fitZoom
:
number
;
}):
HotspotCameraIntent
{
if
(
opts
.
switched
)
return
'fit-switch'
;
if
(
!
opts
.
onScreen
)
return
'fit-recover'
;
// 0.01 是防抖:取景到位后立刻再点一次,浮点误差不该被当成「还差一点」又动一次镜头
if
(
opts
.
currentZoom
<
opts
.
fitZoom
-
0.01
)
return
'fit-zoom-in'
;
return
'hold'
;
}
/** 一块地理范围(真实度数) */
export
interface
GeoBounds
{
minLng
:
number
;
...
...
src/features/heatmap/map/hotspotLayer.test.ts
View file @
5b138bc
...
...
@@ -47,6 +47,14 @@ function fakeCtx(): FakeCtx {
ctx
[
name
]
=
()
=>
hit
(
name
);
}
ctx
.
measureText
=
(
text
:
string
)
=>
({
width
:
String
(
text
).
length
*
6
});
/**
* fill 单独记一笔:光雾朝内的那一半靠 destination-out 擦掉,是**用 fill 擦的**。
* 只看 fill 的总数分不出「擦」和「填」,所以按调用那一刻的合成模式再记一个计数。
*/
ctx
.
fill
=
()
=>
{
hit
(
'fill'
);
if
(
ctx
.
globalCompositeOperation
===
'destination-out'
)
hit
(
'erase'
);
};
return
ctx
;
}
...
...
@@ -206,7 +214,7 @@ describe('黑点图形 · 光效分档', () => {
return
{
mask
,
row
};
}
it
(
'大片走满配:三档光雾 + 暗底 + 主边 + 高光,且
不再往轮廓内侧打光
'
,
()
=>
{
it
(
'大片走满配:三档光雾 + 暗底 + 主边 + 高光,且
光雾只留在轮廓外
'
,
()
=>
{
const
layer
=
new
HotspotLayer
(
fakeMap
());
const
{
mask
,
row
}
=
bigDomain
();
layer
.
setData
([
row
],
GRID
,
mask
);
...
...
@@ -214,9 +222,13 @@ describe('黑点图形 · 光效分档', () => {
// 内侧发光已去掉:不再需要把轮廓 clip 一次再描宽线
expect
(
ctx
.
calls
.
get
(
'clip'
)
??
0
).
toBe
(
0
);
// 光雾是描宽线,线宽一半在内 —— 必须用 destination-out 把里面那半擦掉。
// 这一笔是「内圈光晕」这个问题的根治处:只靠 0.14 的填充压不住 0.34 的光。
expect
(
ctx
.
calls
.
get
(
'erase'
)
??
0
).
toBeGreaterThanOrEqual
(
1
);
// 三档光雾 + 暗底 + 主边 + 高光 = 6 笔
expect
(
ctx
.
calls
.
get
(
'stroke'
)
??
0
).
toBeGreaterThanOrEqual
(
6
);
expect
(
ctx
.
calls
.
get
(
'fill'
)
??
0
).
toBeGreaterThanOrEqual
(
1
);
// 一次擦 + 一次填充
expect
(
ctx
.
calls
.
get
(
'fill'
)
??
0
).
toBeGreaterThanOrEqual
(
2
);
layer
.
destroy
();
});
...
...
src/layout/HeaderBar.tsx
View file @
5b138bc
...
...
@@ -277,10 +277,10 @@ export function HeaderBar() {
/>
<Pill
icon={<AppstoreOutlined />}
label="
状态
"
label=""
value={
dataReady ? (
<span style={{ display: 'inline-flex', alignItems: 'center',
color: '#52c41a'
}}>
<span style={{ display: 'inline-flex', alignItems: 'center', }}>
<span
style={{
display: 'inline-block',
...
...
@@ -290,6 +290,7 @@ export function HeaderBar() {
background: '#52c41a',
marginRight: 6,
boxShadow: '0 0 0 3px rgba(82,196,26,0.22)',
color: '#52c41a'
}}
/>
数据已就绪
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment