Skip to content

Commit

Permalink
Add docs for viewState to spatial filter
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed Jun 25, 2024
1 parent beba096 commit 71f6445
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ const categories = await widgetSource.getCategories({

### Spatial filter

To filter the widget source by a geospatial column, including the map viewport,
pass a `spatialFilter` parameter (GeoJSON Polygon or MultiPolygon geometry) to any widget data fetching function.
To filter the widget source to a spatial region, pass a `spatialFilter` parameter (GeoJSON Polygon or MultiPolygon geometry) to any data fetching function.

```javascript
// → {name: string; value: number}[]
Expand All @@ -103,6 +102,28 @@ const categories = await widgetSource.getCategories({
});
```

To create a spatial filter from the current [deck.gl `viewState`](https://deck.gl/docs/developer-guide/views#using-a-view-with-view-state):

```javascript
import {WebMercatorViewport} from '@deck.gl/core';

function createViewStatePolygon(viewState) {
const viewport = new WebMercatorViewport(viewState);
return {
type: 'Polygon',
coordinates: [
[
viewport.unproject([0, 0]),
viewport.unproject([viewport.width, 0]),
viewport.unproject([viewport.width, viewport.height]),
viewport.unproject([0, viewport.height]),
viewport.unproject([0, 0]),
],
],
};
}
```

## Versioning

Package versioning follows [Semantic Versioning 2.0.0](https://semver.org/).
Expand Down

0 comments on commit 71f6445

Please sign in to comment.