[GIS] Leaflet multiple circle riseOnHover or bringToFront problem

leaflet

I am drawing a multiple circle using Leaflet API. I need to apply hover effect so that I can hover on circle it will rise up or bring to front. I am using the following codes

for (var i = 0; i < count; i++) {
var circleLayer = L.circle([latitude[i], longitude[i]], bufferDistance[i], {
    color: 'white',
    weight: 1,
    fillColor: getColor(data),
    fillOpacity: 0.8,
    riseOnHover: true
}).addTo(map);
circleLayer.on('mouseover', function(circleLayer) {
    circleLayer.bringToFront();
});
circleLayer.addTo(map);
}

All the circles are drawing accordingly but there is no mouseover or hover action is taking place. What I am doing wrong?

Best Answer

Your mistake is in the mouseover event function. The parameter given to an event function is the event itself. To get the object inside the event function you have access to the "target" property of the event.

circleLayer.on('mouseover', function(e) {
    e.target.bringToFront();
});

This fiddle shows how to make it work.

Little extra detail : "riseOnHover" option is useless for circle.