-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMarkerClusterGroup.js
34 lines (27 loc) · 1.13 KB
/
MarkerClusterGroup.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
import {MapLayer, withLeaflet} from 'react-leaflet';
import L from 'leaflet';
import './LeafletMakeClusterLib'
class MarkerClusterGroup extends MapLayer {
createLeafletElement({children, leaflet: {map}, ...props}) {
const clusterProps = {};
const clusterEvents = {};
// Splitting props and events to different objects
Object.entries(props).forEach(
([propName, prop]) => propName.startsWith('on')
? clusterEvents[propName] = prop
: clusterProps[propName] = prop
);
// Creating markerClusterGroup Leaflet element
const markerClusterGroup = new L.markerClusterGroup(clusterProps);
this.contextValue = {layerContainer: markerClusterGroup, map};
// Initializing event listeners
Object.entries(clusterEvents).forEach(
([eventAsProp, callback]) => {
const clusterEvent = `cluster${eventAsProp.substring(2).toLowerCase()}`;
markerClusterGroup.on(clusterEvent, callback);
}
);
return markerClusterGroup;
}
}
export default withLeaflet(MarkerClusterGroup);