Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140705

Leaflet - equivalent of eachLayer() for L.GridLayer & L.VectorGrid.Slicer

$
0
0

Is there a way to replicate the behavior of L.LayerGroup.eachLayer() with GridLayer? I'm using Leaflet.VectorGrid (L.VectorGrid.Slicer) in order to wrap some GeoJSON around the world, and I'd like to add each feature to one or more layer groups. For example, the code below for GeoJSON objects works, but not for grid layers.

// 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);

Viewing all articles
Browse latest Browse all 140705

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>