Leaflet path: how can I set a css class?

后端 未结 6 1457
一个人的身影
一个人的身影 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:46

    The code below will allow you to add a class after the paths are created by the geoJosn method with D3.

    var svg = d3.select(map.getPanes().overlayPane).append("svg"),
    g = svg.append("g").attr("class", "your_class");
    

    However, if you want to add them on creation using only leaflet, try returning them in the style(feature) method like this:

    function style(feature) {
            return {
              weight: 1,
              opacity: .5,
              fillOpacity: 0.7,
              className: feature.properties.name_of_node
            };
    }
    

    That worked really well for me.

提交回复
热议问题