I am experiencing an issue with leaflet and it's mouseout event.
In the code below, sometimes (particulary if you move the mouse fast), the mouseout event is not triggered. The Mouse out ! doesn't appear in the console.
I found out that this behaviour is related to the icon replacement. A simple layer.setStyle works every time. (Here I use the leaflet-gpx plugin but it works the same way as leaflet's IconUrl or shadowUrl)
// This works every time
gpxPath.on('mouseover', function (e) {
var layer = e.target;
layer.options.marker_options.startIconUrl = 'myHoverIconStartUrl';
layer.options.marker_options.endIconUrl = 'myHoverIconEndUrl';
layer.reload();
});
gpxPath.on('mouseout', function (e) {
console.log('Mouse out !')
var layer = e.target;
/* those two lines below cause the issue */
layer.options.marker_options.startIconUrl = '';
layer.options.marker_options.endIconUrl = '';
layer.reload();
});
I know that the mouseout event sometimes causes issues like this one, but in this particular case I am forced to use the leaflet events and I am a little bit out of ideas.