From 7fedf5128e8fe6346b75580b85a6ca400182ed64 Mon Sep 17 00:00:00 2001 From: Mark Ison Date: Tue, 10 Nov 2020 14:24:24 +0000 Subject: [PATCH] Support react-leaflet v3.0 Signed-off-by: Mark Ison --- package.json | 2 +- src/react-leaflet-markercluster.js | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 1ec7129..d0913ce 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/react-leaflet-markercluster.js b/src/react-leaflet-markercluster.js index 85401cc..732c2ae 100644 --- a/src/react-leaflet-markercluster.js +++ b/src/react-leaflet-markercluster.js @@ -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 = {}; @@ -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( @@ -27,8 +28,8 @@ class MarkerClusterGroup extends MapLayer { }, ); - return markerClusterGroup; + return { instance:markerClusterGroup, context: { ...ctx, layerContainer: markerClusterGroup } }; } } -export default withLeaflet(MarkerClusterGroup); +export default MarkerClusterGroup;