Skip to content

Commit 52816cf

Browse files
fix(HeatmapLayer): support reactive data updates
- Remove structuredClone to fix DataCloneError with Vue reactive objects - Create new options object only when data transformation is needed - Preserve reactivity by avoiding deep cloning of proxy objects - Maintain backward compatibility with all existing data formats Fixes #318, #269 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent db0515f commit 52816cf

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/components/HeatmapLayer.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ export default defineComponent({
2727
const hasChanged = !equal(options, oldOptions) || map.value !== oldMap;
2828

2929
if (map.value && api.value && hasChanged) {
30-
const opts: ExtendedHeatmapLayerOptions = structuredClone(options);
30+
let opts: HeatmapLayerOptions;
3131

32-
if (opts.data && !(opts.data instanceof api.value.MVCArray)) {
32+
if (options.data && !(options.data instanceof api.value.MVCArray)) {
3333
const LatLng = api.value.LatLng;
3434

35-
opts.data = opts.data?.map((point) => {
35+
const transformedData = options.data.map((point) => {
3636
if (
3737
point instanceof LatLng ||
3838
("location" in point && (point.location instanceof LatLng || point.location === null))
@@ -46,16 +46,25 @@ export default defineComponent({
4646
return new LatLng(point);
4747
}
4848
}) as HeatmapLayerOptions["data"];
49+
50+
// Create new options object with transformed data
51+
opts = {
52+
...options,
53+
data: transformedData,
54+
};
55+
} else {
56+
// Use options as-is when no transformation needed
57+
opts = options as HeatmapLayerOptions;
4958
}
5059

5160
if (heatmapLayer.value) {
52-
heatmapLayer.value.setOptions(opts as HeatmapLayerOptions);
61+
heatmapLayer.value.setOptions(opts);
5362
} else {
5463
heatmapLayer.value = markRaw(
5564
new api.value.visualization.HeatmapLayer({
5665
...opts,
5766
map: map.value,
58-
} as HeatmapLayerOptions)
67+
})
5968
);
6069
}
6170
}

0 commit comments

Comments
 (0)