Esri / esri-leaflet

A lightweight set of tools for working with ArcGIS services in Leaflet. :rocket:
https://developers.arcgis.com/esri-leaflet/
Apache License 2.0
1.61k stars 799 forks source link

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

Closed gavinr closed 2 years ago

gavinr commented 3 years ago

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

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)
gavinr commented 2 years ago

A fix for this was released in v3.0.4.

main-kun commented 2 years ago

Thank you!