Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for min and max zoom handling #660

Closed
wants to merge 2 commits into from
Closed

Fix for min and max zoom handling #660

wants to merge 2 commits into from

Conversation

rowanwins
Copy link
Contributor

Hi guys,

I've had a crack at fixing issue #643 , I'm not sure its the most optimal way and happy to take feedback but it seems to be working ok on the test case provided.

Cheers
Rowan

@patrickarlt
Copy link
Contributor

@rowanwins sorry it has taken me so long to look at this.

Taking a look at the code I the the problem is in this line https://github.com/Esri/esri-leaflet/blob/master/src/Layers/FeatureLayer/FeatureLayer.js#L164.

Basically this works around a case where FeatureGrid fires a cellLeave for a cell that is on the departing zoom level so we don't remove the features from it. Let me mess around locally to see if I can fix this.

@patrickarlt
Copy link
Contributor

@rowanwins ok I have some more insight on this.

Right now all the minZoom and maxZoom options do is control if cell events get fired. The alternative to this behavior is that you keep listening to events on the map even after the layer has been removed. I don't really like this for 2 reasons.

  1. There is probably a risk of memory leaks from continuing to listen to map events even when the layer is removed.
  2. This starts to break down if I want to add the layer to another map (more then 1 map per page)

Given these complications I think that FeatureGrid is actually just fine and it is probably FeatureManager or FeatureLayer that we need to worry about.

Lets just assume FeatureManager because fixing a bug in FeatureManager will also fix it in the heatmap and cluster layers. So here is how I would fix this.

  1. When feature manager gets added to the map have it start listening to zoomend
  2. If a zoomend event ends up outside the minZoom/maxZoom range we need to remove all the active features that are rendered not the layer itself.
  3. If a zoomend event ends up inside the minZoom/maxZoom rand we need to add all of the features that are inside the current bounds.

Removing features is easy I think you can just call this.removeLayers(this._currentSnapshot) and then set this._currentSnapshot to an empty array. This should remove every feature that is currently active.

Adding the features back is a little harder. For every cell in this._activeCells you need to do the following:

  1. Get the cache key for the coords of the cell ` var key = this._cacheKey(coords);
  2. If this._cache[key] exists it will be an array of feature IDs.
  3. Call this.addLayers(this._cache[key]) to instruct the feature layer to add the layers back.

This approach is more complicated but it avoids FeatureGrid which i think is working as intended and uses FeatureManager which is used to manage the actual representations of the features on the map. It also avoids what might be some sticky scenarios.

@patrickarlt
Copy link
Contributor

@rowanwins if you want to attempt the above by all means do so. Otherwise I can get around to tacking this soon.

@rowanwins
Copy link
Contributor Author

Gday @patrickarlt

It certainly helps knowing the internals of how FeatureLayer vs FeatureManager vs FeatureGrid etc all interact, I was just kind of guessing a bit! I'm happy to have a play sometime over the next few days to see if I can implement your proposed solution, if I dont make any progress I'll let you know. Thanks for the pointers.

Cheers
Rowan

@patrickarlt
Copy link
Contributor

@rowanwins looks like @jgravois beat you to it with #695. I'm going to close this in favor of his approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants