Skip to content

Commit

Permalink
fix(picking): Fixes for Picking Model API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed Nov 14, 2024
1 parent 52a7ba0 commit 623c54e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/models/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ export function executeModel(props: {

let url = `${apiBaseUrl}/v3/sql/${connectionName}/model/${model}`;

const {filters, filtersLogicalOperator = 'and', data} = source;
const {
data,
filters,
filtersLogicalOperator = 'and',
geoColumn = DEFAULT_GEO_COLUMN,
} = source;

const queryParameters = source.queryParameters
? JSON.stringify(source.queryParameters)
: '';
Expand All @@ -90,12 +96,14 @@ export function executeModel(props: {
filtersLogicalOperator,
};

// Picking Model API requires 'spatialDataColumn'.
if (model === 'pick') {
queryParams.spatialDataColumn = geoColumn;
}

// API supports multiple filters, we apply it only to geoColumn
const spatialFilters = source.spatialFilter
? {
[source.geoColumn ? source.geoColumn : DEFAULT_GEO_COLUMN]:
source.spatialFilter,
}
? {[geoColumn]: source.spatialFilter}
: undefined;

if (spatialFilters) {
Expand Down
3 changes: 3 additions & 0 deletions src/widget-sources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export interface FeaturesRequestOptions extends BaseRequestOptions {
/** Topology of objects to be picked. */
dataType: 'points' | 'lines' | 'polygons';

/** Zoom level, required if using 'points' data type. */
z?: number;

/**
* Maximum number of objects to return in the result set. For datasets
* containing features with identical geometry, those features will have
Expand Down
3 changes: 2 additions & 1 deletion src/widget-sources/widget-base-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
options: FeaturesRequestOptions
): Promise<FeaturesResponse> {
const {filterOwner, spatialFilter, abortController, ...params} = options;
const {columns, dataType, featureIds, limit, tileResolution} = params;
const {columns, dataType, featureIds, z, limit, tileResolution} = params;

type FeaturesModelResponse = {rows: Record<string, unknown>[]};

Expand All @@ -137,6 +137,7 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
columns,
dataType,
featureIds,
z,
limit: limit || 1000,
tileResolution: tileResolution || DEFAULT_TILE_RESOLUTION,
},
Expand Down

0 comments on commit 623c54e

Please sign in to comment.