Leaflet / Leaflet.VectorGrid

Display gridded vector data (sliced GeoJSON or protobuf vector tiles) in Leaflet 1.0.0
601 stars 194 forks source link

protobuf vectorTileLayerStyles: filter out some elements #192

Open bagage opened 5 years ago

bagage commented 5 years ago

I am using a protobuf tile server which returns me cities, and I'd like to draw only some of them, for instance the one starting with letter A (could be anything else actually).

Yet I am using:

L.vectorGrid.protobuf(
  tilesServerUrl,
  vectorTileLayerStyles: {
    "cities": (properties, zoom) => {
      if (properties.name.indexOf('a') !== 0) {
        return {
          fillOpacity: 0,
          stroke: false,
          fill: false,
          opacity: 0,
          weight: 0,
        };
      } else {
        return {
          weight: 2,
          color: 'red',
          fill: true,
          fillOpacity: 0.8
        };
      }
    }
  }
);

~~My issue is, I believe, that all my cities are still drawn and that makes the map scroll very laggy because there are too much points on the map. ~~ Actually vectorGrid by itself is fine, it is combined with angular that the issue rises really. But filtering out points would solve the issue so still keeping this issue open for my part.

Thus I'd like to totally filter out the cities not matching given criteria. Is that possible?

jamesurobertson commented 3 years ago

For anyone else finding this page you should be able to return an empty array [] and it wont draw anything on the map.