forked from alex3165/react-mapbox-gl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcluster.js
More file actions
71 lines (65 loc) · 1.68 KB
/
cluster.js
File metadata and controls
71 lines (65 loc) · 1.68 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
import React, { Component } from 'react';
import style from './style.json';
import config from './config.json';
import places from './places.json';
import ReactMapboxGl, { Marker, Cluster } from "react-mapbox-gl";
const containerStyle = {
height: '100vh',
width: '100%'
};
const styles = {
clusterMarker: {
width: 30,
height: 30,
borderRadius: '50%',
backgroundColor: '#51D5A0',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
color: 'white',
border: '2px solid #56C498'
},
marker: {
width: 30,
height: 30,
borderRadius: '50%',
backgroundColor: '#E0E0E0',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
border: '2px solid #C9C9C9'
}
}
export default class ClusterExample extends Component {
onMarkerClick(coords) {
console.log(coords);
}
clusterMarker = (coordinates, pointCount) => (
<Marker coordinates={coordinates} key={coordinates.toString()} style={styles.clusterMarker}>
{ pointCount }
</Marker>
);
render() {
return (
<ReactMapboxGl
style={style}
zoom={[4]}
accessToken={config.accessToken}
containerStyle={containerStyle}>
<Cluster ClusterMarkerFactory={this.clusterMarker} clusterThreshold={8}>
{
places.features.map((feature, key) =>
<Marker
key={key}
style={styles.marker}
coordinates={feature.geometry.coordinates}
onClick={this.onMarkerClick.bind(this, feature.geometry.coordinates)}>
M
</Marker>
)
}
</Cluster>
</ReactMapboxGl>
);
}
}