Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在运行时将css类添加到传单层_Css_Typescript_Leaflet - Fatal编程技术网

在运行时将css类添加到传单层

在运行时将css类添加到传单层,css,typescript,leaflet,Css,Typescript,Leaflet,我用传单在地图上画了几层圆圈(所以有几个图层,每个图层由几个圆圈组成) 我已保存featuregroup上的所有图层: this.globalLayer = L.featureGroup(); 我通过创建一个新的圈featuregroup,并将featuregroup添加到globalLayer,向其中添加新的圈: let circleLayer: L.featureGroup(); let point1 = L.circle([pos_lat, pos_long], {color: col

我用传单在地图上画了几层圆圈(所以有几个图层,每个图层由几个圆圈组成)

我已保存featuregroup上的所有图层:

this.globalLayer = L.featureGroup();
我通过创建一个新的圈featuregroup,并将featuregroup添加到globalLayer,向其中添加新的圈:

let circleLayer: L.featureGroup();

let point1 = L.circle([pos_lat, pos_long], {color: color, opacity: 1, 
radius: radius});
let point2 = L.circle([pos_lat, pos_long], {color: color, opacity: 1, 
radius: radius});
circleLayer.addLayer(point1);
circleLayer.addLayer(point2);
// etc.

this.globalLayer.addLayer(circleLayer);
现在,我想在一些层中添加一个css类:

for (let cssLayer of cssLayers) { // cssLayers is a L.featureGroup[]
    this.globalLayer.removeLayer(cssLayer);
    cssLayer.setStyle({className: 'animate'});
    this.globalLayer.addLayer(cssLayer);
}
这是可行的,但由于层包含很多圆,因此需要一段时间来计算。有没有一种方法可以只添加一个css类而不删除并再次添加它们

我试过了

this.globalLayer.eachLayer(layer => {
    layer.setStyle({className: 'animate'})
});
但是
setStyle()
在类型
L.Layer上不存在


使用我当前的解决方案,您需要先将类添加到相应的层,然后再将其添加到其他标签,如

circleLayer1.setStyle({className: 'myListener'});
然后,您可以随时找到该类:

$('#blink').click(function() {
    $(".myListener").addClass("blink");
});

.

我不确定这是否是最佳做法,但我发现您可以使用图层的_路径属性:

this.globalLayer.eachLayer(层=>{
图层。\u path.classList.add('animate'))

});