ClusteredMarker.js
2.08 KB
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
import React, { memo } from "react";
import { Text, View, StyleSheet, TouchableOpacity } from "react-native";
import { Marker } from "react-native-maps";
import { returnMarkerStyle } from "./helpers";
const ClusteredMarker = ({
geometry,
properties,
onPress,
clusterColor,
clusterTextColor,
clusterFontFamily,
tracksViewChanges,
}) => {
const points = properties.point_count;
const { width, height, fontSize, size } = returnMarkerStyle(points);
return (
<Marker
key={`${geometry.coordinates[0]}_${geometry.coordinates[1]}`}
coordinate={{
longitude: geometry.coordinates[0],
latitude: geometry.coordinates[1],
}}
style={{ zIndex: points + 1 }}
onPress={onPress}
tracksViewChanges={tracksViewChanges}
>
<TouchableOpacity
activeOpacity={0.5}
style={[styles.container, { width, height }]}
>
<View
style={[
styles.wrapper,
{
backgroundColor: clusterColor,
width,
height,
borderRadius: width / 2,
},
]}
/>
<View
style={[
styles.cluster,
{
backgroundColor: clusterColor,
width: size,
height: size,
borderRadius: size / 2,
},
]}
>
<Text
style={[
styles.text,
{
color: clusterTextColor,
fontSize,
fontFamily: clusterFontFamily,
},
]}
>
{points}
</Text>
</View>
</TouchableOpacity>
</Marker>
);
};
const styles = StyleSheet.create({
container: {
display: "flex",
justifyContent: "center",
alignItems: "center",
},
wrapper: {
position: "absolute",
opacity: 0.5,
zIndex: 0,
},
cluster: {
display: "flex",
justifyContent: "center",
alignItems: "center",
zIndex: 1,
},
text: {
fontWeight: "bold",
},
});
export default memo(ClusteredMarker);