PruneCluster icon indicating copy to clipboard operation
PruneCluster copied to clipboard

FitBounds does not work, if map view is not already set

Open bcalik opened this issue 8 years ago • 4 comments

Hello,

I get this error when I call FitBounds and map's view is not predefined or set yet. I have to call map.setView(latlng) before using fitBounds, but what I actually want is to set and fit map view and zoom to marker bounds.

screen shot 2016-02-08 at 12 27 14

bcalik avatar Feb 08 '16 10:02 bcalik

Btw, it works well when I do the work myself like this:

var bounds = pruneCluster.Cluster.ComputeGlobalBounds();
if (bounds) {
    map.fitBounds(new L.LatLngBounds(new L.LatLng(bounds.minLat, bounds.maxLng), new L.LatLng(bounds.maxLat, bounds.minLng)));
}

bcalik avatar Feb 08 '16 10:02 bcalik

Hei,

It looks like this._map is undefined. It is defined when you add the PruneCluster layer to your map. Do you call FitBounds before adding the layer ?

fungiboletus avatar Feb 08 '16 11:02 fungiboletus

No, PruneCluster layer is already added. I will prepare a html file if you can not reproduce.

bcalik avatar Feb 08 '16 13:02 bcalik

Yes, that will be helpful.

fungiboletus avatar Feb 08 '16 15:02 fungiboletus