Esri/esri-leaflet

`addfeature` and `removefeature` events are called too often since v2.4.0 when using minZoom/maxZoom

gavinr opened this issue · 2 comments

Describe the bug

Since Esri Leaflet v2.4.0, the addfeature and removefeature events are not working properly on a FeatureLayer with a minZoom/maxZoom.

Expected behavior

When there is a minZoom or maxZoom defined on the layer, the addfeature and removefeature events should get called as the user zooms "when a feature on the layer is removed from the map" (removefeature) and "when a previously removed feature is added back to the map" (addfeature) (quotes from the docs)

Actual behavior

As you zoom out and in, the addfeature and removefeature events are fired too many times.

To Reproduce

Esri Leaflet v2.3.3 - working as expected: https://jsbin.com/duyupof/edit?html,output

  1. Open the developer tools
  2. Zoom out 3-4 times
  3. Notice that "remove feature" events are only fired once when the points disappear (expected).

Esri Leaflet v3.0.3 (latest) - NOT working as expected: https://jsbin.com/yoyifa/2/edit?html,output

  1. Open the developer tools
  2. Zoom out 3-4 times
  3. Notice that "remove feature" events are fired multiple times. Expected: Only fire once.

Environment Information

  • Version of Leaflet (L.version): 1.7.1
  • Version of Esri Leaflet (L.esri.VERSION): happening on > v2.4.0

Additional context

  1. I think this behavior started in v2.4.0, from PR #1189.
  2. A more specific version of this bug was originally reported in #1297.
  3. Potential solution: I think we need to move or change the code where we are currently firing the events (here and here)

A fix for this was released in v3.0.4.

Thank you!