Esri/esri-leaflet

eachActiveFeature doesn't respect minZoom/maxZoom parameters

Voileexperiments opened this issue · 9 comments

jsbin: https://jsbin.com/ketilafebo/edit?html,console,output

There is a feature layer set to minZoom = 7 while the map has initial zoom = 6, so the features in the feature layer are not loaded and there are no active features:

var features = [];
parks.eachActiveFeature(layer => features.push(layer));
console.log(features.length); // 0

When I zoom in once, the map now has zoom = 7 so the features are loaded, as expected:

var features = [];
parks.eachActiveFeature(layer => features.push(layer));
console.log(features.length); // 42

When I zoom out again, zoom = 6 again and the features are not shown on the map, as expected. However these features still show up in eachActiveFeature:

var features = [];
parks.eachActiveFeature(layer => features.push(layer));
console.log(features.length); // 69

This contradicts what eachActiveFeature is supposed to do:

Calls the passed function against every feature that is currently being displayed.

(I only used minZoom in the jsbin but I'd assume maxZoom has the same problem. Also there are other filter fields in featureLayer, like from/to. Also cacheLayers is not considered a solution here.)

@Voileexperiments thank you for the report, and sorry for the delay. It seems like your jsbin link is not including your exaple code, I think it got lost - can you please post an updated jsbin that demonstrates the issue?

It's already demonstrated? They're meant be executed in the console after doing what was described, so as to not clutter the console with output every extent change.

Besides, load event doesn't fire when map zoom is outside minZoom/maxZoom bounds so it's useless here.

They're meant be executed in the console after doing what was described, so as to not clutter the console with output every extent change.

Which code is meant to be executed in the console? Can you please provide step-by-step replication steps?

I already detailed it in the OP. The code blocks are meant to be executed in the console.

stale commented

This issue has been automatically marked as stale because we're waiting on more information or details, but have not received any response. It will be closed if no further activity occurs. Thank you!

This issue still exists in the latest version.

@gavinr I already provided step-by-step replication steps in the OP, so if it's not clear how to replicate it you may have to specify exactly which part it is unclear. As far as I can tell it should take a few seconds to replicate the issue.

@Voileexperiments as a quick patch in your own code while we find time to investigate this, could you do a check in your logic to compare the current Leaflet map zoom level to the minZoom property of the feature layer? Then you could if/else depending on what you need to do.

Rough idea:

const features = [];
parks.eachActiveFeature(layer => {
  if (myLeafletMap.getZoom() < parks.options.minZoom) {
    features.push(layer);
  } else { }
});

@jwasilgeo That is my current workaround since I only need to count active features inside current extent. A proper fix probably needs to consider more.

A fix for this was released in v3.0.4.