Skip to content

Commit 92a8124

Browse files
authored
Merge pull request #124 from CodeCutterUK/master
Support react-leaflet v3.0
2 parents 7713479 + 5c0eeef commit 92a8124

File tree

4 files changed

+49
-167
lines changed

4 files changed

+49
-167
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@
4848
"terser": "^4.6.10"
4949
},
5050
"dependencies": {
51+
"@react-leaflet/core": "^1.0.2",
5152
"leaflet": "^1.6.0",
5253
"leaflet.markercluster": "^1.4.1",
53-
"react-leaflet": "^2.6.3"
54+
"react-leaflet": "^3.0.0"
5455
},
5556
"peerDependencies": {
5657
"leaflet": "^1.6.0",
5758
"leaflet.markercluster": "^1.4.1",
58-
"react-leaflet": "^2.6.3"
59+
"react-leaflet": "^3.0.0"
5960
},
6061
"husky": {
6162
"hooks": {

src/react-leaflet-markercluster.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
import { MapLayer, withLeaflet } from 'react-leaflet';
1+
import { createPathComponent } from '@react-leaflet/core';
22
import L from 'leaflet';
33

44
require('leaflet.markercluster');
55

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 = {};
1012

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+
);
1719

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);
2122

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+
);
2930

30-
return markerClusterGroup;
31-
}
32-
}
31+
return { instance: markerClusterGroup, context: { ...ctx, layerContainer: markerClusterGroup } };
32+
});
3333

34-
export default withLeaflet(MarkerClusterGroup);
34+
export default MarkerClusterGroup;

0 commit comments

Comments
 (0)