forked from react-native-maps/react-native-maps
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMapHeatmap.tsx
124 lines (110 loc) · 3.05 KB
/
MapHeatmap.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import * as React from 'react';
import {processColor, ProcessedColorValue, View, ViewProps} from 'react-native';
import decorateMapComponent, {
MapManagerCommand,
NativeComponent,
ProviderContext,
SUPPORTED,
UIManagerCommand,
USES_DEFAULT_IMPLEMENTATION,
} from './decorateMapComponent';
import {LatLng} from './sharedTypes';
import {Modify} from './sharedTypesInternal';
export type MapHeatmapProps = ViewProps & {
gradient?: {
/**
* Resolution of color map -- number corresponding to the number of steps colors are interpolated into.
*
* @default 256
* @platform iOS: Google Maps only
* @platform Android: Supported
*/
colorMapSize: number;
/**
* Colors (one or more) to used for gradient.
*
* @platform iOS: Google Maps only
* @platform Android: Supported
*/
colors: string[];
/**
* Array of floating point values from 0 to 1 representing where each color starts.
*
* Array length must be equal to `colors` array length.
*
* @platform iOS: Google Maps only
* @platform Android: Supported
*/
startPoints: number[];
};
/**
* The opacity of the heatmap.
*
* @default 0.7
* @platform iOS: Google Maps only
* @platform Android: Supported
*/
opacity?: number;
/**
* Array of heatmap entries to apply towards density.
*
* @platform iOS: Google Maps only
* @platform Android: Supported
*/
points?: WeightedLatLng[];
/**
* The radius of the heatmap points in pixels, between 10 and 50.
*
* @default 20
* @platform iOS: Google Maps only
* @platform Android: Supported
*/
radius?: number;
};
type NativeProps = Modify<
MapHeatmapProps,
{
gradient?: Modify<
MapHeatmapProps['gradient'],
{colors: (ProcessedColorValue | null | undefined)[]}
>;
}
> & {
ref: React.RefObject<View>;
};
export class MapHeatmap extends React.Component<MapHeatmapProps> {
// declaration only, as they are set through decorateMap
declare context: React.ContextType<typeof ProviderContext>;
getNativeComponent!: () => NativeComponent<NativeProps>;
getMapManagerCommand!: (name: string) => MapManagerCommand;
getUIManagerCommand!: (name: string) => UIManagerCommand;
private heatmap: NativeProps['ref'];
constructor(props: MapHeatmapProps) {
super(props);
this.heatmap = React.createRef<View>();
}
setNativeProps(props: Partial<NativeProps>) {
this.heatmap.current?.setNativeProps(props);
}
render() {
const AIRMapHeatmap = this.getNativeComponent();
const propGradient = this.props.gradient;
let gradient: NativeProps['gradient'];
if (propGradient) {
const colors = propGradient.colors.map(c => processColor(c));
gradient = {...propGradient, colors};
}
return (
<AIRMapHeatmap {...this.props} gradient={gradient} ref={this.heatmap} />
);
}
}
export default decorateMapComponent(MapHeatmap, 'Heatmap', {
google: {
ios: SUPPORTED,
android: USES_DEFAULT_IMPLEMENTATION,
},
});
type WeightedLatLng = LatLng & {
weight?: number;
};