Failed to update icon for marker layers in markerClusterGroup

19 views
Skip to first unread message

Shubhankar Dimri

unread,
Jun 1, 2022, 5:01:36 PM6/1/22
to Leaflet
  • Leaflet version I’m using: 1.8.0
  • Leaflet.MarkerCluster version I’m using: 1.4.1
  • Browser (with version) I’m using: Brave [(Version 1.32.113 Chromium: 96.0.4664.45 (Official Build) (64-bit)]
  • OS/Platform (with version) I’m using: Ubuntu 20.04
  • step 1
    • Create a markerClusterGroup, add marker layers to it
  • step 2
    • Zoom to level 12 and above and update the marker icon for a layer using setIcon method after getting layers from markerClusterGroup

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

Expected Behaviour: Icon to be updated with the provided config, it works for zoom level below 12 and above disableClusteringAtZoom option

Behaviour seen: “Uncaught TypeError: Cannot read properties of null (reading ‘style’)” while updating marker icon on zoom level 12 and above

Minimal example reproducing the issue

Updating markerClusterGroup’s layer icon using the following method, which fails for zoom level 12 and above

function (imageUrl, markerClusterGroup) {
    let layers = markerClusterGroup.getLayers();
    let icon = L.icon({
        iconUrl: imageUrl,
        iconSize: [32, 32],
        iconAnchor: [16, 32]
    })
    for (let layer of layers) {
        if (layer.options.alt == 'store') {
            layer.setIcon(icon);
        }
    }

Is it a valid way to update icons?

Reply all
Reply to author
Forward
0 new messages