有没有办法用 GridLayer 复制 L.LayerGroup.eachLayer() 的行为?我正在使用 Leaflet.VectorGrid (L.VectorGrid.Slicer) 来包装世界各地的一些 GeoJSON,并且我想将每个功能添加到一个或多个图层组。例如,下面的代码适用于 GeoJSON 对象,但不适用于网格层。
// want to do something like this; layer groups defined previously
L.geoJSON(usData, {
style: // styling logic
})
.eachLayer(layer => {
layerGroup1.addLayer(layer);
if (category2.indexOf(layer.someProperty) !== -1) {
layerGroup2.addLayer(layer);
}
if (category3.indexOf(layer.someProperty) !== -1) {
layerGroup3.addLayer(layer);
}
})
.addTo(mapObject);
// no eachLayer() method for grid layers or slicers; how could you do this with grid layers?
L.vectorGrid.slicer(usData, {
vectorTileLayerStyles: {
sliced: properties => someFunction(properties)
},
interactive: true
})
.eachLayer(layer => {
// do something with each layer
})
.addTo(mapObject);
最佳答案
创建多个 L.VectorGrid.Slicer
实例,每个所需的LayerGroup
一个实例。相应地过滤您的 GeoJSON 数据。
关于javascript - Leaflet - 相当于 L.GridLayer 和 L.VectorGrid.Slicer 的eachLayer(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58941498/