Leaflet.markercluster icon indicating copy to clipboard operation
Leaflet.markercluster copied to clipboard

Doesn't display anything when only one marker is present

Open RoboVij opened this issue 2 years ago • 10 comments

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?

RoboVij avatar May 24 '22 10:05 RoboVij

Were you able to solve this?

I'm having the same issue.

BartjeD avatar Jun 07 '22 16:06 BartjeD

@BartjeD Unfortunately, no.

RoboVij avatar Jun 08 '22 12:06 RoboVij

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)

BartjeD avatar Jun 08 '22 12:06 BartjeD

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.

RoboVij avatar Jun 08 '22 12:06 RoboVij

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.

BartjeD avatar Jun 08 '22 14:06 BartjeD

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

bonga1245 avatar Oct 17 '22 08:10 bonga1245

We're still using the mentioned work around.

BartjeD avatar Oct 17 '22 14:10 BartjeD

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

NikiSkaarup avatar Nov 01 '22 09:11 NikiSkaarup

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

BeAllAround avatar Nov 26 '22 17:11 BeAllAround

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.

BartjeD avatar May 16 '23 07:05 BartjeD