0
votes

Can someone please explain to me why when I move point from one layer to another by doing this:

var previousLayer = activeItem.getLayers()[0];

activeItem.removeLayer(previousLayer); // activeItem is FeatureGroup
mapItems.addLayer(previousLayer); // mapItems is MarkerClusterGroup

And then try to change a marker class with:

previousLayer._icon.classList.remove('marker-active');
previousLayer._icon.classList.add('marker-shown');

I get and error that _icon is null when that marker goes inside a visible cluster on the map?

Is it some kind of MarkerCluster bug or I am missing something?

P.S. I tried to find parent cluster, cycle through all markers inside it and all of those markers don't have _icon option...

angular.forEach(mapItems.getVisibleParent(previousLayer)._markers, function (marker) {
     console.log(marker._icon); // error every time
});
1

1 Answers

0
votes

Is it some kind of MarkerCluster bug or I am missing something?

No. If you haven't noticed before, anything with a _ in front of it is a private variable in Leaflet terminology. That means, if you rely on anything with a _ in front of it, it will easily break when you

  • upgrade Leaflet
  • use plugins
  • use a different browser

And this breakage is not Leaflet's fault, but your own.

Answer: don't use ._icon, and in this case, introspect the marker with console.log to find out what type it is.