question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

zoomToShowLayer doesn't fire callback when using CircleMarkers

See original GitHub issue

How to reproduce

  • Leaflet version I’m using: 1.3.1
  • Leaflet.MarkerCluster version I’m using: 1.3.0
  • Browser (with version) I’m using: Chrome 67.0.3396.87
  • OS/Platform (with version) I’m using: macOS High Sierra
  • Add three circle markers to the map (in my case, 2 in Hong Kong and 1 in the Phillipines - see example).
  • Zoom out so all three markers cluster together.
  • Call zoomToShowLayer passing the Phillipines marker.

What behaviour I’m expecting and which behaviour I’m seeing

Expecting the zoomToShowLayer callback to be fired. It’s not fired because it’s checking for an icon on the marker before firing the callback, which doesn’t exist on a CircleMarker. The Hong Kong buttons because the parent (i.e. the cluster) has an icon.

if ((layer._icon || layer.__parent._icon) && !this._inZoomAnimation) {

Minimal example reproducing the issue

Clicking on Zoom to Marker 1 doesn’t open the popup. http://jsfiddle.net/7cxwu248/28/

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ghybscommented, Jun 22, 2018

Hi,

Seems that it works for spiderfied Circle Markers (i.e. Markers 2 and 3 in the provided example) because in that case the callback is executed once "spiderfied" event fires, whether the Layer has an _icon or not. https://github.com/Leaflet/Leaflet.markercluster/blob/4cea2dfba189972c7ce06a0ab3cbc9cc8aa0b694/src/MarkerClusterGroup.js#L544-L556

Since the check for layer._icon and layer.__parent._icon is to know whether they are visible (added) on map or not, we could simply use map.hasLayer instead (if it is not on map, it is collected in a cluster, or not part of this cluster group at all…)

Updated JSFiddle: https://jsfiddle.net/7cxwu248/39/

BTW this is the same case on the next lines: https://github.com/Leaflet/Leaflet.markercluster/blob/4cea2dfba189972c7ce06a0ab3cbc9cc8aa0b694/src/MarkerClusterGroup.js#L558-L560 It is less of a problem, since in this case we move first then execute the callback, instead of just executing the callback.

0reactions
mirko77commented, Jun 11, 2020

I downloaded the sources and made my changes, I just realized this repo is not maintained anymore.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Zoom in so a marker is visible in LeafletJS - Stack Overflow
zoomToShowLayer (layer, callback): Zooms to show the given marker (spiderfying if required), calls the callback when the marker is visible on ...
Read more >
Leaflet.markercluster | Marker Clustering plugin for Leaflet
zoomToShowLayer (layer, callback): Zooms to show the given marker (spiderfying if required), calls the callback when the marker is visible on the map....
Read more >
leaflet.markercluster-src.js in extensions/piwigo ...
//Removes all layers from the MarkerClusterGroup · clearLayers: function () { · //Need our own special implementation as the LayerGroup one doesn't work...
Read more >
sardonyx test dashboard - Popular Blocks
in main div. might also use relative positioning here, for now assume ... addLayer(marker); }); }; /* Callback functions */ function ...
Read more >
Changeset 315 for binary-improvements/webserver/leaflet
r173 r315 3 3 https://github.com/Leaflet/Leaflet.markercluster 4 (c) 2012‑201 3, Dave Leaver, smartrak 4 (c) 2012‑201 7, Dave Leaver
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found