-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.js
96 lines (84 loc) · 2.16 KB
/
App.js
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
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { MapView } from "expo";
import ClusterMarker from "./components/ClusterMarker";
import { getCluster } from "./utils/MapUtils";
const Style = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
map: {
...StyleSheet.absoluteFill
}
});
const INITIAL_POSITION = {
latitude: 41.924447,
longitude: -87.687339,
latitudeDelta: 1,
longitudeDelta: 1
}
const COORDS = [
{ lat: 42, lon: -87 },
{ lat: 42.1, lon: -87 },
{ lat: 42.2, lon: -87 },
{ lat: 42.3, lon: -87 },
{ lat: 42.4, lon: -87 }
];
export default class App extends React.Component {
state = {
region: INITIAL_POSITION
};
renderMarker = (marker, index) => {
const key = index + marker.geometry.coordinates[0];
// If a cluster
if (marker.properties) {
return (
<MapView.Marker
key={`${key}${marker.properties.cluster_id}`}
coordinate={{
latitude: marker.geometry.coordinates[1],
longitude: marker.geometry.coordinates[0]
}}
>
<ClusterMarker count={marker.properties.point_count} />
</MapView.Marker>
);
}
// If a single marker
return (
<MapView.Marker
key={key}
coordinate={{
latitude: marker.geometry.coordinates[1],
longitude: marker.geometry.coordinates[0]
}}
/>
);
};
render() {
const { region } = this.state;
const allCoords = COORDS.map(c => ({
geometry: {
coordinates: [c.lon, c.lat]
}
}));
const cluster = getCluster(allCoords, region);
return (
<View style={Style.container}>
<MapView
provider={MapView.PROVIDER_GOOGLE}
style={Style.map}
loadingIndicatorColor={"#ffbbbb"}
loadingBackgroundColor={"#ffbbbb"}
region={region}
onRegionChangeComplete={region => this.setState({ region })}
>
{cluster.markers.map((marker, index) => this.renderMarker(marker, index))}
</MapView>
</View>
);
}
}