Skip to content

Commit

Permalink
feat(tileset): Add WidgetTilesetSource#extractTileFeatures() (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy authored Jan 15, 2025
1 parent c070abd commit 9affa4f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion examples/03-tileset/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ function updateLayers() {
onViewportLoad: (tiles) => {
const viewport = new WebMercatorViewport(viewState);
const spatialFilter = createViewportSpatialFilter(viewport.getBounds())!;
data.widgetSource.loadTiles({tiles, spatialFilter});
data.widgetSource.loadTiles(tiles);
data.widgetSource.extractTileFeatures({spatialFilter});
updateWidgets();
},
});
Expand Down
3 changes: 2 additions & 1 deletion examples/04-tileset-h3/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ function updateLayers() {
onViewportLoad: (tiles) => {
const viewport = new WebMercatorViewport(viewState);
const spatialFilter = createViewportSpatialFilter(viewport.getBounds())!;
data.widgetSource.loadTiles({tiles, spatialFilter});
data.widgetSource.loadTiles(tiles);
data.widgetSource.extractTileFeatures({spatialFilter});
updateWidgets();
},
});
Expand Down
21 changes: 16 additions & 5 deletions src/widget-sources/widget-tileset-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export type WidgetTilesetSourceResult = {widgetSource: WidgetTilesetSource};
* ```
*/
export class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps> {
private _tiles: Tile[] = [];
private _features: FeatureData[] = [];

protected override getModelSource(owner: string): ModelSource {
Expand All @@ -86,14 +87,24 @@ export class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps>
};
}

/** Loads features as a list of tiles (typically provided by deck.gl). */
loadTiles({
tiles,
/**
* Loads features as a list of tiles (typically provided by deck.gl).
* After tiles are loaded, {@link extractTileFeatures} must be called
* before computing statistics on the tiles.
*/
loadTiles(tiles: unknown[]) {
this._tiles = tiles as Tile[];
}

/**
* Extracts feature data from tiles previously loaded with {@link loadTiles}.
* Must be called before computing statistics on tiles.
*/
extractTileFeatures({
spatialFilter,
uniqueIdProperty,
options,
}: {
tiles: Tile[];
spatialFilter: SpatialFilter;
// TODO(cleanup): As an optional property, 'uniqueIdProperty' will be easy to forget.
// Would it be better to configure it on the source function, rather than separately
Expand All @@ -102,7 +113,7 @@ export class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps>
options?: TileFeatureExtractOptions;
}) {
this._features = tileFeatures({
tiles,
tiles: this._tiles,
options,
spatialFilter,
uniqueIdProperty,
Expand Down

0 comments on commit 9affa4f

Please sign in to comment.