I am using React and Leaflet and trying to paint some CircleMarkers whenever I place the mouse over a div. This div contains information of 1 or more CircleMarkers' coordinates (those are the circleMarkers I want to change colors of).
I initialize the map like this:
this.map = L.map("map", { zoomControl: false });
let layer = L.tileLayer(
"https://api.tiles.mapbox.com/v4/...",
{ [...] }
);
And then add the circleMarkers like this: (as suggested in https://stackoverflow.com/a/43019740/2211939)
this.totalElements.forEach(value => {
let circle = new L.CircleMarker(
[value.geometry.coordinates[1], value.geometry.coordinates[0]],
{
renderer: this.myRenderer,
radius: 5,
[...]
}
)
.addTo(this.map)
}
Then, when I hover the div, the function executed is this one:
changeCirclesColor = parent => {
this.map.eachLayer(layer => {
if (layer instanceof L.CircleMarker) {
for (let child of parent.childrenGeometry) {
if ( //THE GEOMETRY IS THE SAME) {
console.log('PAINTED!'); // THIS IS PRINTED ONLY ONCE
layer.setStyle({
fillColor: "#00d3be",
[...]
});
[...]
However, even if there is just one child element, there are many other circleMarkers that change their style as well. If there is only one child, when I print 'layer._latlng', there's just one pair of coordinates, which (I guess) means there's only on circleMarker in that layer. Also, the layer.setStyle() function is only executed once, I'd say, since the console.log is only printed once.
What am I missing?