Leaflet path: how can I set a css class?

后端 未结 6 1471
一个人的身影
一个人的身影 2021-01-07 23:13

Well the title says it all but here is some code so you see what i mean.

function eachFeature(feature, layer) {
     layer.on({
         mouseover: highlight         


        
6条回答
  •  南笙
    南笙 (楼主)
    2021-01-07 23:50

    Using Leaflet 1.x, here is a slightly different way to do this - in my case the map was already initialized, so the className styling mentioned above did not work.

    function eachFeature(feature, layer) {
         layer.on({
             mouseover: function(e) {$(e.target.getElement()).addClass("active");},
             mouseout: function(e) {$(e.target.getElement()).removeClass("active");}
         });
    }
    

    You can also set the class attribute directly using setAttribute on e.target.getElement() if you're not using jQuery.

提交回复
热议问题