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

Icon disappearance when moving out of the viewport #555

Closed
aaaaahaaaaa opened this issue Sep 16, 2015 · 7 comments
Closed

Icon disappearance when moving out of the viewport #555

aaaaahaaaaa opened this issue Sep 16, 2015 · 7 comments

Comments

@aaaaahaaaaa
Copy link

If I'm not mistaken, icons markers managed by markercluster disappear when they are at some distance from the viewport.

I need to nanually add a class to some of the icons displayed on the map, either they are inside the viewport or not. I currently have two problems regarding this situation :

  • my css class is removed from the icon when the icon is back in the viewport (I guess the previous icon has been deleted and a new marker has been added instead)
  • I can't add a class to an icon marker ouside of the viewport (the icon doesn't exist)

If there's a kind of event I can listen to when a marker is restored on the map, it should be enough for me to get around the problem.

@aaaaahaaaaa
Copy link
Author

Note: my problem is also present when the marker is inside the viewport but the zoom level has changed. I've already found a workaround by listening to the animationend event in order to reapply my css class, but there's a few millisecondes timeframe where the marker icon won't have it.

@ghybs
Copy link
Contributor

ghybs commented Sep 21, 2015

Hi,

Please have you tried to set the CSS class when initializing your Marker Cluster Group, as described here? https://github.com/Leaflet/Leaflet.markercluster#customising-the-clustered-markers

Along html property, you can also set a className property. Simply set the value of this property as your CSS class name. See also the source code of example http://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-custom.html, normally it should be straight forward.

As you figured out, there is actually one Cluster per zoom level, even if they appear identical. Clusters icon are also re-drawn every time they appear back on the viewport. They use the instructions passed at initialization time, but if you fiddle with it later on (change yourMarkerClusterGroup.options.iconCreateFunction), it should probably update your clusters gradually as you move / zoom.

Hopefully this option can cover your usage.

@danzel
Copy link
Member

danzel commented Sep 22, 2015

Yeah, sounds like you should be using className when creating (or updating) icons.

@aaaaahaaaaa
Copy link
Author

Ok, I customized my iconCreateFunction to dynamically use a different Icon with a different className option when needed. But then I realized this method is only called once per cluster. Once the cluster has been created, it will never be called again. So there's no way for me to update the class of the icon dynamically.

@aaaaahaaaaa
Copy link
Author

Here is my complete use case :

  • a marker on the map can be, at any time, "active" or not (the icon needs to have a specific CSS class)
  • a marker can be set as active even if it's not currently inside the viewport
  • if a cluster contains an active marker, the cluster needs to be active as well (same CSS class)

@ghybs
Copy link
Contributor

ghybs commented Oct 1, 2015 via email

ghybs added a commit to ghybs/Leaflet.markercluster that referenced this issue Oct 1, 2015
@danzel
Copy link
Member

danzel commented Oct 13, 2015

#564 has been merged

@danzel danzel closed this as completed Oct 13, 2015
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

No branches or pull requests

3 participants