Skip to content

Commit

Permalink
Changed behavior of getGeometryToIntersect
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefano Pettini committed Apr 27, 2023
1 parent 8260b99 commit 614e899
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/react-core/src/filters/tileFeatures.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TileFeatures, TileFeaturesResponse } from '../types';
import { Geometry, Feature, Polygon, MultiPolygon } from 'geojson';

export function getGeometryToIntersect(viewport: number[], geometry: Geometry | null): Feature<Polygon | MultiPolygon> | null;
export function getGeometryToIntersect(viewport: number[] | null, geometry: Geometry | null): Feature<Polygon | MultiPolygon> | null;
export function tileFeatures(arg: TileFeatures): TileFeaturesResponse;
16 changes: 14 additions & 2 deletions packages/react-core/src/filters/tileFeatures.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import bboxPolygon from '@turf/bbox-polygon';
import intersect from '@turf/intersect';
import tileFeaturesGeometries from './tileFeaturesGeometries';
import tileFeaturesSpatialIndex from './tileFeaturesSpatialIndex';

/**
* Select the geometry to use for widget calculation and data filtering.
* If a geometry (mask) is set, use the mask otherwise use the current viewport.
* Since it's possible that no mask and no viewport is set, return null in this case.
*
* @typedef { import("geojson").Polygon | import("geojson").MultiPolygon } Geometry
* @typedef { import("geojson").Feature<Geometry> } Feature
* @typedef { import("geojson").BBox } BBox
*
* @param { BBox? } viewport viewport [minX, minY, maxX, maxY], if any
* @param { Feature? } geometry the active mask, if any
* @returns { Feature? } the geometry to use for filtering
*/
export function getGeometryToIntersect(viewport, geometry) {
return geometry ? intersect(bboxPolygon(viewport), geometry) : bboxPolygon(viewport);
return geometry ? geometry : viewport ? bboxPolygon(viewport) : null;
}

export function tileFeatures({
Expand Down

0 comments on commit 614e899

Please sign in to comment.