|
1 |
| -import { MapLayer, withLeaflet } from 'react-leaflet'; |
| 1 | +import { createPathComponent } from '@react-leaflet/core'; |
2 | 2 | import L from 'leaflet';
|
3 | 3 |
|
4 | 4 | require('leaflet.markercluster');
|
5 | 5 |
|
6 |
| -class MarkerClusterGroup extends MapLayer { |
7 |
| - createLeafletElement({ children, leaflet: { map }, ...props }) { |
8 |
| - const clusterProps = {}; |
9 |
| - const clusterEvents = {}; |
| 6 | +const MarkerClusterGroup = createPathComponent(( |
| 7 | + { children: _c, ...props }, |
| 8 | + ctx |
| 9 | +) => { |
| 10 | + const clusterProps = {}; |
| 11 | + const clusterEvents = {}; |
10 | 12 |
|
11 |
| - // Splitting props and events to different objects |
12 |
| - Object.entries(props).forEach( |
13 |
| - ([propName, prop]) => propName.startsWith('on') |
14 |
| - ? clusterEvents[propName] = prop |
15 |
| - : clusterProps[propName] = prop |
16 |
| - ); |
| 13 | + // Splitting props and events to different objects |
| 14 | + Object.entries(props).forEach( |
| 15 | + ([propName, prop]) => propName.startsWith('on') |
| 16 | + ? clusterEvents[propName] = prop |
| 17 | + : clusterProps[propName] = prop |
| 18 | + ); |
17 | 19 |
|
18 |
| - // Creating markerClusterGroup Leaflet element |
19 |
| - const markerClusterGroup = new L.markerClusterGroup(clusterProps); |
20 |
| - this.contextValue = { layerContainer: markerClusterGroup, map }; |
| 20 | + // Creating markerClusterGroup Leaflet element |
| 21 | + const markerClusterGroup = new L.markerClusterGroup(clusterProps); |
21 | 22 |
|
22 |
| - // Initializing event listeners |
23 |
| - Object.entries(clusterEvents).forEach( |
24 |
| - ([eventAsProp, callback]) => { |
25 |
| - const clusterEvent = `cluster${eventAsProp.substring(2).toLowerCase()}`; |
26 |
| - markerClusterGroup.on(clusterEvent, callback); |
27 |
| - }, |
28 |
| - ); |
| 23 | + // Initializing event listeners |
| 24 | + Object.entries(clusterEvents).forEach( |
| 25 | + ([eventAsProp, callback]) => { |
| 26 | + const clusterEvent = `cluster${eventAsProp.substring(2).toLowerCase()}`; |
| 27 | + markerClusterGroup.on(clusterEvent, callback); |
| 28 | + }, |
| 29 | + ); |
29 | 30 |
|
30 |
| - return markerClusterGroup; |
31 |
| - } |
32 |
| -} |
| 31 | + return { instance: markerClusterGroup, context: { ...ctx, layerContainer: markerClusterGroup } }; |
| 32 | +}); |
33 | 33 |
|
34 |
| -export default withLeaflet(MarkerClusterGroup); |
| 34 | +export default MarkerClusterGroup; |
0 commit comments