Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
sutpc
/
heatmap-plus
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 2e69c4bf
authored
Nov 24, 2026
by
limin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix: 百度热力缓冲按默认 max=100 归一化导致一片红,构造时传真实上限并调整提交顺序
1 parent
a41eb563
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
5 deletions
src/features/heatmap/map/provider/baidu/HeatLayer.ts
src/features/heatmap/map/provider/baidu/HeatLayer.ts
View file @
2e69c4b
...
@@ -65,7 +65,19 @@ export class BaiduHeatLayer implements HeatLayerLike {
...
@@ -65,7 +65,19 @@ export class BaiduHeatLayer implements HeatLayerLike {
});
});
}
}
private
ensure
():
BaiduLayerLike
{
/**
* ⚠️ max 必须在**构造时**就传对,不能只靠 setOptions 后补。
*
* 百度 4.0 脚本里 fz(Heatmap) 的 max 默认是 100;setData 触发 _rebuild 生成 GPU 缓冲,
* 归一化就在那一刻按当时的 _style.max 算;而 _onOptionsChanged 只在 gradient /
* weightField 变化时重建,**改 max 不重建**。所以旧的「先 setData(max=100)→ 再
* setOptions({max:真实值})」会让缓冲一直按 100 归一化:count 上百的桶全 clamp 到 1,
* 整片饱和成红色(2026-11-24 实测)。
*
* 两处一起保证:构造传入首帧 max;后续换 max 时先 setOptions 再 setData,
* 让重建缓冲时读到的已经是新上限。
*/
private
ensure
(
max
:
number
):
BaiduLayerLike
{
if
(
!
this
.
heat
)
{
if
(
!
this
.
heat
)
{
const
Ctor
=
this
.
basemap
.
gl
.
Heatmap
;
const
Ctor
=
this
.
basemap
.
gl
.
Heatmap
;
if
(
!
Ctor
)
{
if
(
!
Ctor
)
{
...
@@ -74,6 +86,8 @@ export class BaiduHeatLayer implements HeatLayerLike {
...
@@ -74,6 +86,8 @@ export class BaiduHeatLayer implements HeatLayerLike {
this
.
heat
=
new
Ctor
({
this
.
heat
=
new
Ctor
({
size
:
this
.
style
.
radius
,
size
:
this
.
style
.
radius
,
unit
:
'px'
,
unit
:
'px'
,
max
,
min
:
0
,
minOpacity
:
HEAT_MIN_OPACITY
,
minOpacity
:
HEAT_MIN_OPACITY
,
maxOpacity
:
this
.
style
.
opacity
,
maxOpacity
:
this
.
style
.
opacity
,
gradient
:
HEAT_GRADIENT
,
gradient
:
HEAT_GRADIENT
,
...
@@ -95,7 +109,6 @@ export class BaiduHeatLayer implements HeatLayerLike {
...
@@ -95,7 +109,6 @@ export class BaiduHeatLayer implements HeatLayerLike {
count
:
Int32Array
,
count
:
Int32Array
,
keep
?:
Uint8Array
|
null
,
keep
?:
Uint8Array
|
null
,
):
void
{
):
void
{
const
heat
=
this
.
ensure
();
const
n
=
lng
.
length
;
const
n
=
lng
.
length
;
const
size
=
this
.
basemap
.
getSize
();
const
size
=
this
.
basemap
.
getSize
();
const
center
=
this
.
basemap
.
getCenter
();
const
center
=
this
.
basemap
.
getCenter
();
...
@@ -137,22 +150,25 @@ export class BaiduHeatLayer implements HeatLayerLike {
...
@@ -137,22 +150,25 @@ export class BaiduHeatLayer implements HeatLayerLike {
// 数据与归一化上限都没变 → 只管显隐,不重传 GPU 数据
// 数据与归一化上限都没变 → 只管显隐,不重传 GPU 数据
if
(
sameSource
&&
this
.
lastMax
===
this
.
max
)
{
if
(
sameSource
&&
this
.
lastMax
===
this
.
max
)
{
heat
.
setVisible
?.(
this
.
visible
);
this
.
heat
?
.
setVisible
?.(
this
.
visible
);
return
;
return
;
}
}
this
.
lastMax
=
this
.
max
;
this
.
lastMax
=
this
.
max
;
const
heat
=
this
.
ensure
(
this
.
max
);
this
.
geo
.
features
=
data
.
map
((
p
)
=>
({
this
.
geo
.
features
=
data
.
map
((
p
)
=>
({
type
:
'Feature'
,
type
:
'Feature'
,
geometry
:
{
type
:
'Point'
,
coordinates
:
[
p
.
lng
,
p
.
lat
]
},
geometry
:
{
type
:
'Point'
,
coordinates
:
[
p
.
lng
,
p
.
lat
]
},
properties
:
{
count
:
p
.
count
},
properties
:
{
count
:
p
.
count
},
}));
}));
heat
.
setData
(
this
.
geo
);
// 顺序要紧:先把新 max 写进 _style,再 setData 重建缓冲。
// 反过来(旧代码)缓冲会按上一次的 max 归一化,就是"一片红"的来源。
heat
.
setOptions
?.({
heat
.
setOptions
?.({
max
:
this
.
max
,
max
:
this
.
max
,
size
:
this
.
style
.
radius
,
size
:
this
.
style
.
radius
,
minOpacity
:
HEAT_MIN_OPACITY
,
minOpacity
:
HEAT_MIN_OPACITY
,
maxOpacity
:
this
.
visible
?
this
.
style
.
opacity
:
0
,
maxOpacity
:
this
.
visible
?
this
.
style
.
opacity
:
0
,
});
});
heat
.
setData
(
this
.
geo
);
heat
.
setVisible
?.(
this
.
visible
);
heat
.
setVisible
?.(
this
.
visible
);
}
}
...
@@ -173,7 +189,7 @@ export class BaiduHeatLayer implements HeatLayerLike {
...
@@ -173,7 +189,7 @@ export class BaiduHeatLayer implements HeatLayerLike {
setVisible
(
visible
:
boolean
)
{
setVisible
(
visible
:
boolean
)
{
this
.
visible
=
visible
;
this
.
visible
=
visible
;
if
(
visible
)
this
.
ensure
().
setVisible
?.(
true
);
if
(
visible
)
this
.
ensure
(
Math
.
max
(
this
.
max
,
1
)
).
setVisible
?.(
true
);
else
this
.
heat
?.
setVisible
?.(
false
);
else
this
.
heat
?.
setVisible
?.(
false
);
}
}
...
...
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