I am using PruneCluster with Leaflet and I have custom logic happening to attempt to add and remove polygons when clusters are created. It mostly works, but I have an issue when I leave the page, and come back. I need all the markers that were put on the map previously, to be added again. This seems to work fine for markers without a geoJson layer, but when I try to add back a geoJson layer I get Uncaught TypeError: Cannot read property 'min' of undefined
which is being triggered by this in Leaflet:
_getBitCode: function (/*Point*/ p, bounds) {
var code = 0;
if (p.x < bounds.min.x) { // left
code |= 1;
} else if (p.x > bounds.max.x) { // right
code |= 2;
}
if (p.y < bounds.min.y) { // bottom
code |= 4;
} else if (p.y > bounds.max.y) { // top
code |= 8;
}
return code;
},
My custom code to add shapes, when the marker is not clustered looks like this:
pruneCluster.PrepareLeafletMarker = function (leafletMarker, data) {
if (data.isShape) {
map.addLayer(data.geoJsonLayer);
}
leafletMarker.on('click', function (e) {
GenerateRrosePopup(e, data.popupContent);
if(data.isShape) {
map.fitBounds(data.boundsForFit);
}
});
leafletMarker.setIcon(data.icon);
};
map.addLayer(data.geoJsonLayer)
is what causes the issue. I'm not sure why though because my geoJson object looks as I expect it to.
Why would this same code work for initially adding the geoJson layer, but then fail when I come back to the page and try to add the points and shapes I previously added?