Skip to content

Commit a8b1a23

Browse files
authored
fix: rerender for pinmap (#84)
1 parent 9d0cda7 commit a8b1a23

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

.changeset/thick-garlics-enter.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@antv/gpt-vis': patch
3+
---
4+
5+
fix: rerender for pinmap

src/HeatMap/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ export type HeatMapProps = MapProps & {
3434
};
3535

3636
const HeatMap: FC<HeatMapProps> = (props) => {
37-
const { children, data = [], ...mapConfigRest } = useMapConfig('HeatMap', props);
37+
const { children, data, ...mapConfigRest } = useMapConfig('HeatMap', props);
3838

3939
const source = useMemo(
4040
() => ({
41-
data,
41+
data: data || [],
4242
parser: { type: 'json', x: 'longitude', y: 'latitude' },
4343
}),
4444
[data],

src/PathMap/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import { formatMakerStyle, formatPolylineStyle } from '../utils/map';
88
export type PathMapProps = MapProps & _PathMap;
99

1010
const PathMap: FC<PathMapProps> = (props) => {
11-
const { data = [], markerStyle = {}, pathStyle = {}, ...rest } = useMapConfig('PathMap', props);
11+
const { data, markerStyle, pathStyle, ...rest } = useMapConfig('PathMap', props);
1212

1313
const markerdata = useMemo(() => {
1414
const markers: MarkerData[] = [];
15-
data.forEach((item) => {
15+
(data || []).forEach((item) => {
1616
if (item.markers) {
1717
markers.push(...item.markers);
1818
}
@@ -21,7 +21,7 @@ const PathMap: FC<PathMapProps> = (props) => {
2121
}, [data, markerStyle]);
2222

2323
const linedata = useMemo(() => {
24-
const lines = data.map((item) => {
24+
const lines = (data || []).map((item) => {
2525
return item.path;
2626
}) as Polyline[];
2727
return formatPolylineStyle(lines, pathStyle);

src/PinMap/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import { formatMakerStyle } from '../utils/map';
88
export type PinMapProps = PinMapType & MapProps;
99

1010
const PinMap: FC<PinMapProps> = (props) => {
11-
const { data = [], markerStyle = {}, ...rest } = useMapConfig('PinMap', props);
11+
const { data, markerStyle, ...rest } = useMapConfig('PinMap', props);
1212

13-
const markerdata = useMemo(() => formatMakerStyle(data, markerStyle), [data, markerStyle]);
13+
const markerdata = useMemo(() => formatMakerStyle(data || [], markerStyle), [data, markerStyle]);
1414

1515
return <Map markers={markerdata} includePoints={markerdata} {...rest} />;
1616
};

src/utils/map/style.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const DefaultMarkerStyle = {
5454
'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*3XdDTbsQ84QAAAAAAAAAAAAADmJ7AQ/original',
5555
};
5656

57-
const formatMakerStyle = (data: MarkerData[], markerStyle: Partial<Marker>) => {
57+
const formatMakerStyle = (data: MarkerData[], markerStyle?: Partial<Marker>) => {
5858
const labelStyle = Object.assign({}, DefaultMarkerStyle.label, markerStyle?.label);
5959
// label 优先级 data > markerStyle > DefaultMarkerStyle
6060
return data.map((marker: MarkerData, index: number) => {
@@ -79,7 +79,7 @@ const DefaultPolylineStyle = {
7979
zIndex: 1,
8080
};
8181

82-
const formatPolylineStyle = (data: Polyline[] = [], polylineStyle: Partial<Marker>) => {
82+
const formatPolylineStyle = (data: Polyline[], polylineStyle?: Partial<Marker>) => {
8383
return data.map((item: any) => {
8484
return {
8585
...DefaultPolylineStyle,

0 commit comments

Comments
 (0)