mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-27 08:02:51 +02:00
Change zoomToBounds to only zoom in as far as it needs to to show all child markers. Fixes #185
This commit is contained in:
@@ -96,6 +96,7 @@ markers.on('clusterclick', function (a) {
|
||||
|
||||
### Zooming to the bounds of a cluster
|
||||
When you recieve an event from a cluster you can zoom to its bounds in one easy step.
|
||||
If all of the markers will appear at a higher zoom level, that zoom level is zoomed to instead.
|
||||
See [marker-clustering-zoomtobounds.html](http://leaflet.github.com/Leaflet.markercluster/example/marker-clustering-zoomtobounds.html) for a working example.
|
||||
```javascript
|
||||
markers.on('clusterclick', function (a) {
|
||||
|
||||
+21
-2
@@ -42,9 +42,28 @@ L.MarkerCluster = L.Marker.extend({
|
||||
return this._childCount;
|
||||
},
|
||||
|
||||
//Zoom to the extents of this cluster
|
||||
//Zoom to the minimum of showing all of the child markers, or the extents of this cluster
|
||||
zoomToBounds: function () {
|
||||
this._group._map.fitBounds(this._bounds);
|
||||
var childClusters = this._childClusters.slice(),
|
||||
map = this._group._map,
|
||||
boundsZoom = map.getBoundsZoom(this._bounds),
|
||||
zoom = this._zoom + 1,
|
||||
i;
|
||||
|
||||
while (childClusters.length > 0 && boundsZoom > zoom) {
|
||||
zoom++;
|
||||
var newClusters = [];
|
||||
for (i = 0; i < childClusters.length; i++) {
|
||||
newClusters = newClusters.concat(childClusters[i]._childClusters);
|
||||
}
|
||||
childClusters = newClusters;
|
||||
}
|
||||
|
||||
if (boundsZoom > zoom) {
|
||||
this._group._map.setView(this._latlng, zoom);
|
||||
} else {
|
||||
this._group._map.fitBounds(this._bounds);
|
||||
}
|
||||
},
|
||||
|
||||
getBounds: function () {
|
||||
|
||||
Reference in New Issue
Block a user