Skip to content

Issue: moveend Event Triggered by zoomToBounds Even Without Bounds Change #1112

@Karan9615-off

Description

@Karan9615-off

Bug Report: moveend Event Triggered by zoomToBounds Even Without Bounds Change

Description:
The moveend event is being fired when calling zoomToBounds even though the map's visible bounds have not changed. This behavior is causing unnecessary updates and performance issues.

Steps to Reproduce:

  1. Create a map with clusters using Leaflet.markercluster.
  2. Call the zoomToBounds method on a cluster.
  3. Observe that the moveend event is fired even if the map's visible bounds remain the same.

Expected Behavior:
The moveend event should only be fired when the map's visible bounds have actually changed.

Suggested Fix:
Modify the _moveEnd method in src/MarkerClusterGroup.js to check if the map's visible bounds have actually changed before performing updates.

JS Fiddle:
Please look into this https://jsfiddle.net/4r8k9hLj/14/.

Example Code:

_moveEnd: function () {
    if (this._inZoomAnimation) {
        return;
    }

    var newBounds = this._getExpandedVisibleBounds();

    // Check if the map has visibly moved
    if (!this._currentShownBounds.equals(newBounds)) {
        this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, Math.floor(this._map.getMinZoom()), this._zoom, newBounds);
        this._topClusterLevel._recursivelyAddChildrenToMap(null, Math.round(this._map._zoom), newBounds);
        this._currentShownBounds = newBounds;
    }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions