I'm having trouble integrating OverlappingMarkerSpiderfier with React-Leaflet and using FeatureGroup for panning on the map. FeatureGroups are really useful when you have complicated panning logic.
Here is a plain JS demo. The markers spiderfy and the pan button works with no issues.
Here is the react-leaflet demo. The panning will fail with the following error if spiderfy is enabled/checked in the UI. This is based on this SO post.
layer.getLatLng is not a function
I think the problem is that with regular JS, I can add the markers array to both oms and the featureGroup imperatively but with React-leaflet, I don't see how I can achieve the same result.
Is the error because <Spiderfy> layer does not have a getLatLng function for some reason even though I am extending the MapLayer.
I'm unsure of what needs fixing, the JS version seems to work so the OverlappingMarkerSpiderfier library likely doesn't need changes. It could be a React-leaflet specific problem/limitation that can possibly be fixed with a custom FeatureGroup/MapLayer?
It appears the error
occurs since FeatureGroup.getBounds function expects underlying layers to implement either
getBoundsorgetLatLngmethods which is not the case with customSpiderfy.jscomponent where container (layerContainerprop) is ofL.layerGrouptype.One option to consider would be to refactor
Spiderfy.jscomponent:L.layerGroupas a layer container16.8or above) replaceES6 classcomponent with function to implementSpiderfycomponentSpiderfy.jscomponentThis way
FeatureGroup.getBoundsfunction should return the expected result, identical to provided in plain JS demo.Forked example