Skip to content

Commit

Permalink
CARTO: API v3.3 reenable (#8265)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixpalmer authored Nov 8, 2023
1 parent adaa6fc commit 79b3e9d
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 42 deletions.
2 changes: 1 addition & 1 deletion modules/carto/src/api/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
export const DEFAULT_CLIENT = 'deck-gl-carto';
export const V3_MINOR_VERSION = '3.2';
export const V3_MINOR_VERSION = '3.3';
export const MAX_GET_LENGTH = 8192;

export const DEFAULT_PARAMETERS = {
Expand Down
23 changes: 16 additions & 7 deletions modules/carto/src/sources/h3-query-source.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
/* eslint-disable camelcase */
import {baseSource} from './base-source';
import type {AggregationOptions, QuerySourceOptions, SourceOptions, TilejsonResult} from './types';
import type {
AggregationOptions,
QuerySourceOptions,
SourceOptions,
SpatialDataType,
TilejsonResult
} from './types';

export type H3QuerySourceOptions = SourceOptions & QuerySourceOptions & AggregationOptions;
type UrlParameters = {
aggregationExp: string;
aggregationResLevel?: string;
geo_column?: string;
spatialDataType: SpatialDataType;
spatialDataColumn?: string;
q: string;
queryParameters?: string;
};
Expand All @@ -18,17 +25,19 @@ export const h3QuerySource = async function (
aggregationExp,
aggregationResLevel = 4,
sqlQuery,
spatialDataColumn = 'h3:h3',
spatialDataColumn = 'h3',
queryParameters
} = options;
const urlParameters: UrlParameters = {aggregationExp, q: sqlQuery};
const urlParameters: UrlParameters = {
aggregationExp,
spatialDataColumn,
spatialDataType: 'h3',
q: sqlQuery
};

if (aggregationResLevel) {
urlParameters.aggregationResLevel = String(aggregationResLevel);
}
if (spatialDataColumn) {
urlParameters.geo_column = spatialDataColumn;
}
if (queryParameters) {
urlParameters.queryParameters = JSON.stringify(queryParameters);
}
Expand Down
23 changes: 16 additions & 7 deletions modules/carto/src/sources/h3-table-source.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
/* eslint-disable camelcase */
import {baseSource} from './base-source';
import type {AggregationOptions, SourceOptions, TableSourceOptions, TilejsonResult} from './types';
import type {
AggregationOptions,
SourceOptions,
SpatialDataType,
TableSourceOptions,
TilejsonResult
} from './types';

export type H3TableSourceOptions = SourceOptions & TableSourceOptions & AggregationOptions;

type UrlParameters = {
aggregationExp: string;
aggregationResLevel?: string;
columns?: string;
geo_column?: string;
spatialDataType: SpatialDataType;
spatialDataColumn?: string;
name: string;
};

Expand All @@ -19,19 +26,21 @@ export const h3TableSource = async function (
aggregationExp,
aggregationResLevel = 4,
columns,
spatialDataColumn = 'h3:h3',
spatialDataColumn = 'h3',
tableName
} = options;
const urlParameters: UrlParameters = {aggregationExp, name: tableName};
const urlParameters: UrlParameters = {
aggregationExp,
name: tableName,
spatialDataColumn,
spatialDataType: 'h3'
};

if (aggregationResLevel) {
urlParameters.aggregationResLevel = String(aggregationResLevel);
}
if (columns) {
urlParameters.columns = columns.join(',');
}
if (spatialDataColumn) {
urlParameters.geo_column = spatialDataColumn;
}
return baseSource<UrlParameters>('table', options, urlParameters) as Promise<TilejsonResult>;
};
23 changes: 16 additions & 7 deletions modules/carto/src/sources/quadbin-query-source.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
/* eslint-disable camelcase */
import {baseSource} from './base-source';
import type {AggregationOptions, QuerySourceOptions, SourceOptions, TilejsonResult} from './types';
import type {
AggregationOptions,
QuerySourceOptions,
SourceOptions,
SpatialDataType,
TilejsonResult
} from './types';

export type QuadbinQuerySourceOptions = SourceOptions & QuerySourceOptions & AggregationOptions;

type UrlParameters = {
aggregationExp: string;
aggregationResLevel?: string;
geo_column?: string;
spatialDataType: SpatialDataType;
spatialDataColumn?: string;
q: string;
queryParameters?: string;
};
Expand All @@ -19,17 +26,19 @@ export const quadbinQuerySource = async function (
aggregationExp,
aggregationResLevel = 6,
sqlQuery,
spatialDataColumn = 'quadbin:quadbin',
spatialDataColumn = 'quadbin',
queryParameters
} = options;
const urlParameters: UrlParameters = {aggregationExp, q: sqlQuery};
const urlParameters: UrlParameters = {
aggregationExp,
q: sqlQuery,
spatialDataColumn,
spatialDataType: 'quadbin'
};

if (aggregationResLevel) {
urlParameters.aggregationResLevel = String(aggregationResLevel);
}
if (spatialDataColumn) {
urlParameters.geo_column = spatialDataColumn;
}
if (queryParameters) {
urlParameters.queryParameters = JSON.stringify(queryParameters);
}
Expand Down
24 changes: 17 additions & 7 deletions modules/carto/src/sources/quadbin-table-source.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
/* eslint-disable camelcase */
import {baseSource} from './base-source';
import type {AggregationOptions, SourceOptions, TableSourceOptions, TilejsonResult} from './types';
import type {
AggregationOptions,
SourceOptions,
SpatialDataType,
TableSourceOptions,
TilejsonResult
} from './types';

export type QuadbinTableSourceOptions = SourceOptions & TableSourceOptions & AggregationOptions;

type UrlParameters = {
aggregationExp: string;
aggregationResLevel?: string;
columns?: string;
geo_column?: string;
spatialDataType: SpatialDataType;
spatialDataColumn?: string;
name: string;
};

Expand All @@ -19,19 +26,22 @@ export const quadbinTableSource = async function (
aggregationExp,
aggregationResLevel = 6,
columns,
spatialDataColumn = 'quadbin:quadbin',
spatialDataColumn = 'quadbin',
tableName
} = options;
const urlParameters: UrlParameters = {aggregationExp, name: tableName};

const urlParameters: UrlParameters = {
aggregationExp,
name: tableName,
spatialDataColumn,
spatialDataType: 'quadbin'
};

if (aggregationResLevel) {
urlParameters.aggregationResLevel = String(aggregationResLevel);
}
if (columns) {
urlParameters.columns = columns.join(',');
}
if (spatialDataColumn) {
urlParameters.geo_column = spatialDataColumn;
}
return baseSource<UrlParameters>('table', options, urlParameters) as Promise<TilejsonResult>;
};
2 changes: 1 addition & 1 deletion modules/carto/src/sources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type TilesetSourceOptions = {
tableName: string;
};

export type SpatialDataType = 'geometry' | 'h3' | 'quadbin';
export type SpatialDataType = 'geo' | 'h3' | 'quadbin';

export type TilejsonMapInstantiation = MapInstantiation & {
tilejson: {url: string[]};
Expand Down
14 changes: 8 additions & 6 deletions modules/carto/src/sources/vector-query-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import {baseSource} from './base-source';
import type {SourceOptions, QuerySourceOptions, SpatialDataType, TilejsonResult} from './types';

export type VectorQuerySourceOptions = SourceOptions & QuerySourceOptions;
type UrlParameters = {geo_column?: string; q: string; queryParameters?: string};
type UrlParameters = {
spatialDataType: SpatialDataType;
spatialDataColumn?: string;
q: string;
queryParameters?: string;
};

export const vectorQuerySource = async function (
options: VectorQuerySourceOptions
): Promise<TilejsonResult> {
const {spatialDataColumn, sqlQuery, queryParameters} = options;
const urlParameters: UrlParameters = {q: sqlQuery};
const {spatialDataColumn = 'geom', sqlQuery, queryParameters} = options;
const urlParameters: UrlParameters = {spatialDataColumn, spatialDataType: 'geo', q: sqlQuery};

if (spatialDataColumn) {
urlParameters.geo_column = spatialDataColumn;
}
if (queryParameters) {
urlParameters.queryParameters = JSON.stringify(queryParameters);
}
Expand Down
14 changes: 8 additions & 6 deletions modules/carto/src/sources/vector-table-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ import {baseSource} from './base-source';
import type {SourceOptions, SpatialDataType, TableSourceOptions, TilejsonResult} from './types';

export type VectorTableSourceOptions = SourceOptions & TableSourceOptions;
type UrlParameters = {columns?: string; geo_column?: string; name: string};
type UrlParameters = {
columns?: string;
spatialDataType: SpatialDataType;
spatialDataColumn?: string;
name: string;
};

export const vectorTableSource = async function (
options: VectorTableSourceOptions
): Promise<TilejsonResult> {
const {columns, spatialDataColumn, tableName} = options;
const urlParameters: UrlParameters = {name: tableName};
const {columns, spatialDataColumn = 'geom', tableName} = options;
const urlParameters: UrlParameters = {name: tableName, spatialDataColumn, spatialDataType: 'geo'};

if (columns) {
urlParameters.columns = columns.join(',');
}
if (spatialDataColumn) {
urlParameters.geo_column = spatialDataColumn;
}
return baseSource<UrlParameters>('table', options, urlParameters) as Promise<TilejsonResult>;
};

0 comments on commit 79b3e9d

Please sign in to comment.