-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mark Ison <mark@codecutter.uk>
- Loading branch information
1 parent
7713479
commit 31380e0
Showing
4 changed files
with
49 additions
and
167 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
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 clusterProps = {}; | ||
const clusterEvents = {}; | ||
const MarkerClusterGroup = createPathComponent(( | ||
{ children: _c, ...props }, | ||
ctx | ||
) => { | ||
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 | ||
); | ||
// 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 }; | ||
// Creating markerClusterGroup Leaflet element | ||
const markerClusterGroup = new L.markerClusterGroup(clusterProps); | ||
|
||
// Initializing event listeners | ||
Object.entries(clusterEvents).forEach( | ||
([eventAsProp, callback]) => { | ||
const clusterEvent = `cluster${eventAsProp.substring(2).toLowerCase()}`; | ||
markerClusterGroup.on(clusterEvent, callback); | ||
}, | ||
); | ||
// Initializing event listeners | ||
Object.entries(clusterEvents).forEach( | ||
([eventAsProp, callback]) => { | ||
const clusterEvent = `cluster${eventAsProp.substring(2).toLowerCase()}`; | ||
markerClusterGroup.on(clusterEvent, callback); | ||
}, | ||
); | ||
|
||
return markerClusterGroup; | ||
} | ||
} | ||
return { instance: markerClusterGroup, context: { ...ctx, layerContainer: markerClusterGroup } }; | ||
}); | ||
|
||
export default withLeaflet(MarkerClusterGroup); | ||
export default MarkerClusterGroup; |
Oops, something went wrong.