Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
Support react-leaflet v3.0
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Ison <mark@codecutter.uk>
  • Loading branch information
CodeCutterUK committed Nov 10, 2020
1 parent 7713479 commit 7fedf51
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"peerDependencies": {
"leaflet": "^1.6.0",
"leaflet.markercluster": "^1.4.1",
"react-leaflet": "^2.6.3"
"react-leaflet": "^3.0.0"
},
"husky": {
"hooks": {
Expand Down
13 changes: 7 additions & 6 deletions src/react-leaflet-markercluster.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { MapLayer, withLeaflet } from 'react-leaflet';
import { createPathComponent } from '@react-leaflet/core';
import L from 'leaflet';

require('leaflet.markercluster');

class MarkerClusterGroup extends MapLayer {
createLeafletElement({ children, leaflet: { map }, ...props }) {
const MarkerClusterGroup = createPathComponent(function createMarkerClusterGroup(
{ children: _c, ...options },
ctx
) {
const clusterProps = {};
const clusterEvents = {};

Expand All @@ -17,7 +19,6 @@ class MarkerClusterGroup extends MapLayer {

// Creating markerClusterGroup Leaflet element
const markerClusterGroup = new L.markerClusterGroup(clusterProps);
this.contextValue = { layerContainer: markerClusterGroup, map };

// Initializing event listeners
Object.entries(clusterEvents).forEach(
Expand All @@ -27,8 +28,8 @@ class MarkerClusterGroup extends MapLayer {
},
);

return markerClusterGroup;
return { instance:markerClusterGroup, context: { ...ctx, layerContainer: markerClusterGroup } };
}
}

export default withLeaflet(MarkerClusterGroup);
export default MarkerClusterGroup;

0 comments on commit 7fedf51

Please sign in to comment.