Rotate marker in Leaflet

后端 未结 4 2080
天命终不由人
天命终不由人 2021-02-04 06:59

How can I rotate a marker in leaflet? I will have a lot of markers, all with a rotation angle.

I\'ve tried this solution from runanet/coomsie at Leaflet on GitH

4条回答
  •  一个人的身影
    2021-02-04 07:27

    What works very well for me is adding a data-rotate="[angle]" attribute to each marker. This allows you to call the following JQuery statement on each refresh when necessary:

        $('.your-marker-class').each(function () {            
            var deg = $(this).data('rotate') || 0;
            var rotate = 'rotate(' + $(this).data('rotate') + 'deg) scale(0.5,0.5)';
            $(this).css({
                '-webkit-transform': rotate,
                '-moz-transform': rotate,
                '-o-transform': rotate,
                '-ms-transform': rotate,
                'transform': rotate
            });
        });
    

    Works very fast and with hundreds/thousands of markers. Found this method in some other post somewhere on the internets but seemed right to share here also.

提交回复
热议问题