Skip to content

setLatLng adds marker back to map when hidden using LayerControl #1096

@divadsn

Description

@divadsn
  • I'm reporting a bug, not asking for help
  • I'm sure this is a Leaflet.MarkerCluster code issue, not an issue with my own code nor with the framework I'm using (Cordova, Ionic, Angular, React…)
  • I've searched through the issues to make sure it's not yet reported

  • Leaflet version I'm using: 1.9.4
  • Leaflet.MarkerCluster version I'm using: latest from master
  • Browser (with version) I'm using: Firefox 121 (although it's not a browser related issue)
  • OS/Platform (with version) I'm using: Windows 10

How to reproduce

  • Create a map and add markerClusterGroup
  • Create LayerControl with L.Control.Layers and add to map
  • Add layerGroup to MCG and LayerControl
  • Create new marker, add to layerGroup
  • Hide the layer using the LayerControl
  • Change the latlng of the marker to map.getCenter() for example
  • The marker will re-appear despite the layer being hidden!

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

I've reproduced the same using the LayerControl demo, the marker did not re-appear using the same approach from above.

I found this to be the cause of the bug: https://github.com/Leaflet/Leaflet.markercluster/blob/master/src/MarkerClusterGroup.js#L716

This causes the layer to be re-added, without checking if it's added or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions