Leaflet / Leaflet.VectorGrid

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

Filter not working with L.VectorGrid.Protobuf 🔴 #285

Open geekypradip opened 2 months ago

geekypradip commented 2 months ago

I'm currently working with Leaflet's VectorGrid and I'm encountering an issue with the filter option. Here's a snippet of my code:

const vectorGrid = L.vectorGrid.protobuf(url, {
      vectorTileLayerStyles: vectorTileLayerStyles as Record<
        string,
        PathOptions
      >,
      rendererFactory: L.svg.tile,
      maxNativeZoom: 28,
      maxZoom: 28,
      interactive: true,
      fetchOptions: {headers: {Authorization: `Bearer ${token}`}},
      bounds: bounds,
      zIndex: 1000,
      filter: (properties, zoom) => {
        console.log(properties, zoom);
        return false;
      },
    });

In the above code, I've provided a filter function that should prevent any feature from being rendered on the map, as I'm returning false. However, it seems like the filter function is not being called at all. I've tried to debug this using Chrome's devtools and added a console.log statement inside the filter function, but it's not printing anything.

The strange thing is, whether I pass the filter option or not, the result is the same. It's as if the filter function is being completely ignored.

Any help or guidance on this issue would be greatly appreciated.

IvanSanchez commented 2 months ago

@geekypradip My question to you is: Why did you think there's a filter option implemented in VectorGrid?

geekypradip commented 2 months ago

@geekypradip My question to you is: Why did you think there's a filter option implemented in VectorGrid?

Thank you for your prompt response. I assumed the filter option was available because it's mentioned in the TypeScript definitions for leaflet.vectorgrid on npm. Here's the link for reference: DefinitelyTyped vector grid

Upon further investigation, I noticed a discrepancy between the npm package version and the master branch of the repository. The npm package is at version 1.3.0, where the filter option is not available. However, the TypeScript definitions seem to be based on the master branch, where the filter option is indeed present in the VectorGrid options.

This mismatch between the released version and the TypeScript definitions could be causing some confusion. I would appreciate any guidance on how to proceed with this.