简体   繁体   English

有没有一种方法可以将CSS类添加到传单元素中?

[英]Is there a way to add a css-class to a leaflet element?

I very much like the much cleaner dom-output of leaflet compared with google maps, but I wonder if there is a way to add a css class to markers, layers or polylines. 与Google地图相比,我非常喜欢传单的dom输出更加简洁,但是我想知道是否有办法在标记,图层或折线中添加CSS类。

It would be great if something like this would be possible: 像这样的事情将是很好的:

function onEachFeature(feature, layer) {
  layer.on({
    click: addClass
  });
}

function addClass(e){
    layer = e.target;
    layer.addClass('soo-wonderful');
}

At least for layers there is: 至少对于图层有:

function onEachFeature(feature, layer) {
  layer.on({
    click: addClass
  });
}

function addClass(e){
    layer = e.target;
    var container = layer._container;
    $(container).attr('class', 'test');
}

Haven't tested all different cases yet, but its a good starting point. 尚未测试所有不同的案例,但这是一个很好的起点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM