Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animated transition of leaflet Marker icon

I have a Leaflet marker with a BLUE icon (from a PNG image source). On mouse hovering, I want to make that a RED icon.

This is the code for doing so:

            let placeMarker = L.marker(...);

            let cssSetter = function (imarker, iicon) {
                imarker.setIcon(iicon);
            };

            placeMarker.on('mouseover', 
                L.bind(cssSetter, null, placeMarker, markerIcon_red)
            );
            placeMarker.on('mouseout', 
                L.bind(cssSetter, null, placeMarker, markerIcon)
            );

Now I want to do this transition gradually, with an animation.

How can I do this?

like image 328
manatttta Avatar asked Oct 11 '25 20:10

manatttta


1 Answers

Write your own CSS transition.

http://css3.bradshawenterprises.com/cfimg/


Or use plugin Leaflet.TransitionedIcon

https://github.com/naturalatlas/leaflet-transitionedicon

like image 79
northtree Avatar answered Oct 14 '25 10:10

northtree