-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add hasLayer() to the markercluster object #44
Comments
+1, This would be nice. |
How about if calling addLayer when the layer was already added it didn't re-add the same marker? |
Hm. I can see how that would be good but I can also see cases where you just want to check if that layer is there. I would be more for the hasLayer method to keep it similar to what the normal map object has. I also wonder if there may be some reason to add a duplicate layer. |
Yep fair enough. Just a bit hard in the code ATM as we don't keep a list of all markers around to easily check against, so we'll need to traverse the tree. I don't think you should be adding the same marker to the map twice. Currently if you do that with the clusterer it clusters with it self and results in all sorts of weirdness. |
Ah true true about duplicate markers. Right now, my duplicate detection is working like so. (pretty much ripped it from hasLayer on the map object).
Seems to be working alright so far. |
I think that will only work if the given marker is currently visible on the map. |
Ah that makes sense. I just checked over my code and in a host of changes in the past week, I'm reseting the entire cluster markering since I'm loading markers through AJAX while moving around the map so my check doesn't even make sense anyways. I had added it at one point when I wasn't resetting the layer. |
Any plans to incorporate the check if a layer exists when adding as mentioned? That alone would be nice. the hasLayer() would be great too, but if the check when adding is easier, that's good too. |
Yep, might be looking at this later today, we'll see how my day unfolds. Out of personal interest, what sort of projects are you guys using the markercluster on? |
Alrighty! I've added this and also made addLayer check if the layer is already in the cluster before adding it. |
Hello. In my application sometime I need to readd markers that were removed from clusterGroup. hasLayer(marker) method returns "true" if marker was removed from cluster. I think it's because at that moment marker.__parent._group === clusterGroup. To my mind it would be better if hasLayer returns correct answer for remove markers (doesn't metter were they removed by removeLayer[s] or clearLayers). What do you think about that? |
Now there are 4 ways of adding layers to clusterGroup:
Now only one of them (3rd) checks for duplicates. Maybe you can make all of them do that checking. And add some MarkerClusterGroup option (for example, "checkDuplicates: true") to allow developer to decide if he wants that checking (with understanding that it will decresase productivity) or not (in order to increase performance) |
I refactored how hasLayer works so that it is super efficient and we always (or at least should always) be testing it before adding a layer to the map. |
Thanks for the report, have fixed up the issue now. |
Great! Thanks for hasLayer. It works now for previously removed layers. As far as I understood you didn't include yet dups testing into adding layers process when cluster group is not on the map, did you? |
Will take a look, that does sound like something I may have missed, thanks :) |
…es adding the same layer multiple times before adding the MarkerClusterGroup to the map. Refs #44
@cvisto yep, was a bug, fixed. Thanks! |
When adding new markers to a map, it'd be great to be able to easily check if it already has that layer. It's pretty simple to do without this function but it would be a nice added feature.
The text was updated successfully, but these errors were encountered: