有没有办法用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);发布于 2019-11-20 22:09:30
为每个所需的LayerGroup创建多个L.VectorGrid.Slicer实例。相应地过滤您的GeoJSON数据。
发布于 2019-11-20 16:33:19
你可以用以下命令得到每一个“层”:
Object.keys(vectorGrid._vectorTiles).forEach(function(e){console.log(vectorGrid._vectorTiles[e])})
但问题是,这些层没有latlng,它们有路径。因此您不能将它们添加到图层组中。
也许你可以在从特征中获取路径坐标并将其转换为latlng时创建新的多边形。
https://stackoverflow.com/questions/58941498
复制相似问题