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

Made refreshClusters to re-draw markers in singleMarkerMode #583

Merged
merged 6 commits into from
Oct 21, 2015

Conversation

ghybs
Copy link
Contributor

@ghybs ghybs commented Oct 19, 2015

Following issue #581, improved refreshClusters() method so that it detects singleMarkerMode and re-draws all passed markers as well, not only parent clusters. Took the opportunity to factorize code with _addLayer() method, creating a new _overrideMarkerIcon() method that re-styles the marker using the iconCreateFunction from clusters.

Added an extra test in RefreshSpec test suite to cover this case. Also re-factored it using it2 wrapper to avoid hanging test process.

Also created the singleMarkerModeSpec test suite to test singleMarkerMode option and included it into the new suite into spec/index.

ghybs added 4 commits October 19, 2015 12:44
Following issue Leaflet#581, improved refreshClusters() method so that it detects singleMarkerMode and re-draws all passed markers as well, not only parent clusters.

Also created the singleMarkerModeSpec test suite to test singleMarkerMode option, added an extra test in RefreshSpec test suite to cover this case, and added the new suite into spec/index.
into a dedicated private method, as it has nothing to do in `_flagParentsIconsNeedUpdate()`.
After many testing, it turns out that the beforeEach and afterEach functions do not cause that much trouble regarding the memory leak issue of PhantomJS. Just re-using objects as much as possible (in particular, avoiding re-creating the div and map between each individual test) already brings significant improvement. The custom `it2` function was working, but it was breaking the readability of the spec/index file report. So I switched the test suite back to using the native functions.
to use back the standard beforeEach and afterEach functions, but re-using objects as much as possible. This avoids too much memory leak in PhantomJS while still having a spec/index readable.
@danzel
Copy link
Member

danzel commented Oct 21, 2015

Do we need to worry about a marker that is not in the cluster being passed in to the refresh method?
It would have its icon replaced I think based on a read of this change.

@ghybs
Copy link
Contributor Author

ghybs commented Oct 21, 2015

Hi,

Indeed there is currently no check that the passed markers really belong to the MCG.

In that case, the method would silently flag the parent clusters (if there are) as having a "dirty" icon, which will make them be re-drawn by the legitimate MCG when needed (but it will not immediately refresh the currently visible ones). Which is close to the "expected" behaviour, minus the temporary not refreshed visible clusters.

We should probably make a decision on whether we should check internally if the passed arguments are legitimate (and possibly ignore them silently), or if we simply charge the application developer of this step.

Another option would be to use a "static" function (like "L.MarkerClusterGroup.refresh") rather than an object method. It could easily determine the involved MCG's. That way, the application does not need to care about which MCG the markers belong to (if they belong to any).

What are your thoughts?

@danzel
Copy link
Member

danzel commented Oct 21, 2015

Sorry that's not what I meant.
I'm not too worried about that use case.

I mean if I make a new Marker, and don't add it to any MCG, then pass it to the icon refresh method, it will have its icon replaced with a (1) icon.
This probably isn't something we care about either though, but it would be nice to not happen

@ghybs
Copy link
Contributor Author

ghybs commented Oct 21, 2015

Oh ok you mean when the method is called while the singleMarkerMode is on?
Sorry I overlooked your comment.

Indeed you are right about what would happen in that case: icons are also re-drawn.

I agree the consequences are more worrying than the previous case, even if we would still blame the application developer... :-)

It could be worth adding hasLayer checks to avoid it. Will do shortly.

ghybs added 2 commits October 21, 2015 14:16
to avoid overriding icons of markers that do not belong to the current MCG.
Otherwise, we change icons that have nothing to do with the group.
Following comment Leaflet#583 (comment)
@ghybs
Copy link
Contributor Author

ghybs commented Oct 21, 2015

Should be good now.
Let me know if you find anything else.

danzel added a commit that referenced this pull request Oct 21, 2015
Made refreshClusters to re-draw markers in singleMarkerMode
@danzel danzel merged commit d55e219 into Leaflet:master Oct 21, 2015
@danzel
Copy link
Member

danzel commented Oct 21, 2015

Looks good thanks

@ghybs ghybs deleted the refreshClusters branch October 22, 2015 04:58
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