forked from react-native-maps/react-native-maps
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMapCluster.tsx
74 lines (64 loc) · 1.74 KB
/
MapCluster.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
import * as React from 'react';
import { NativeSyntheticEvent, StyleSheet, ViewProps, View } from 'react-native';
import decorateMapComponent, {
MapManagerCommand,
NativeComponent,
ProviderContext,
SUPPORTED,
UIManagerCommand,
USES_DEFAULT_IMPLEMENTATION,
} from './decorateMapComponent';
import { LatLng, Point } from './sharedTypes';
export type MapClusterProps = ViewProps & {
/**
* 聚合节点聚合的距离
*/
distance: number;
/**
* 待聚合节点数组
*/
clusterItems: Array<{ position: LatLng }>;
/**
* Callback that is called when the user presses on the overlay
*/
onPress?: (event: ClusterPressEvent) => void;
};
type NativeProps = MapClusterProps;
export class MapCluster extends React.Component<MapClusterProps> {
// 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;
render() {
const AIRMapCluster = this.getNativeComponent();
return (
<AIRMapCluster
{...this.props}
style={[styles.cluster, this.props.style]}
onPress={event => {
if (this.props.onPress) {
this.props.onPress(event);
}
}}
/>
);
}
}
const styles = StyleSheet.create({
cluster: {
position: 'absolute',
backgroundColor: 'transparent',
},
});
type ClusterPressEvent = NativeSyntheticEvent<{
action: 'cluster-press';
points: string;
id?: string;
}>;
export default decorateMapComponent(MapCluster, 'Cluster', {
google: {
ios: SUPPORTED,
android: USES_DEFAULT_IMPLEMENTATION,
},
});