Leaflet / Leaflet.markercluster

Marker Clustering plugin for Leaflet
MIT License
3.98k stars 1k forks source link

Doesn't display anything when only one marker is present #1063

Open RoboVij opened 2 years ago

RoboVij commented 2 years ago

I'm not reporting a bug, asking for help.

Clustering works properly when multiple (even only 2) markers are present but when I filter to 1 marker, it's not displaying anything. But in a different project it works fine even when it's just 1 marker i.e. it displays the marker icon instead of cluster icon and that's fine. I'm using almost the same code in both projects. Any idea what could cause this problem of not displaying, theoretically?

BartjeD commented 2 years ago

Were you able to solve this?

I'm having the same issue.

RoboVij commented 2 years ago

@BartjeD Unfortunately, no.

BartjeD commented 2 years ago

I worked around it by adding a fake marker if there was only 1 marker in the collection. Just copy the position of the first marker and it displays the markers on the map.

Obviously we needed to adjust the count mechanism as well, to exclude the fake marker from the count.

It's very ugly and probably only works in this exact situation.

We noticed sometimes clusters with only 1 marker also don't show on the map, so we suddely miss clusters after zooming. If we can recognize those clusters with only one marker programatically this hack wil also work there.

But I didn't take it that far. (yet)

RoboVij commented 2 years ago

Sounds like a good enough workaround.

But I guess there won't be any one-marker clusters. From what I understood, the plugin displays the marker instead of cluster in the only-one-marker case, even after zooming in.

BartjeD commented 2 years ago

They overlap perfectly if you copy the coordinates, you can also hide them via CSS if you want.

In our case we don't show the markers. For low-zoom navigation purposes. With only the clusters it wasn't a problem anyway.

bonga1245 commented 2 years ago

Hi @BartjeD @RoboVij I am experiencing the same issue Did you find any good solution to the problem?

BartjeD commented 2 years ago

We're still using the mentioned work around.

NikiSkaarup commented 2 years ago

If it helps anyone my solution is to just skip the usage of markercluster and add it directly to the map instead when there is only one marker

BeAllAround commented 2 years ago

Hi everyone,

Please, have a look at

https://stackoverflow.com/questions/57383443/single-marker-fails-to-get-rendered-if-it-is-not-in-or-close-to-a-cluster

I provided a description as to why this occurs. Hope it helps

BartjeD commented 1 year ago

In our case we still require the work around even if we apply the zoom rounding you mentioned. @BeAllAround

It doesn't seem to be the same issue.