diff --git a/src/index.ts b/src/index.ts index 8026617..3badd79 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ export * from './filters.js'; export * from './geo.js'; export * from './widget-sources/index.js'; export * from './types.js'; -export * from './spatial-index.js' +export * from './spatial-index.js'; export { APIErrorContext, diff --git a/src/models/model.ts b/src/models/model.ts index 50dbb5d..ffdce14 100644 --- a/src/models/model.ts +++ b/src/models/model.ts @@ -10,7 +10,7 @@ import {$TODO} from '../types-internal.js'; import {assert} from '../utils.js'; import {ModelRequestOptions, makeCall} from './common.js'; import {ApiVersion} from '../constants.js'; -import { SpatialDataType, SpatialFilterPolyfillMode } from '../sources/types.js'; +import {SpatialDataType, SpatialFilterPolyfillMode} from '../sources/types.js'; /** @internalRemarks Source: @carto/react-api */ const AVAILABLE_MODELS = [ diff --git a/src/sources/quadbin-table-source.ts b/src/sources/quadbin-table-source.ts index 2a9a66a..b7deaa4 100644 --- a/src/sources/quadbin-table-source.ts +++ b/src/sources/quadbin-table-source.ts @@ -62,7 +62,7 @@ export const quadbinTableSource = async function ( ...options, // NOTE: passing redundant spatialDataColumn here to apply the default value 'quadbin' spatialDataColumn, - spatialDataType: 'quadbin' + spatialDataType: 'quadbin', }), }) ); diff --git a/src/sources/vector-query-source.ts b/src/sources/vector-query-source.ts index 264f270..44f1bf4 100644 --- a/src/sources/vector-query-source.ts +++ b/src/sources/vector-query-source.ts @@ -22,7 +22,7 @@ export type VectorQuerySourceOptions = SourceOptions & QuerySourceOptions & FilterOptions & ColumnsOption & { - spatialDataType: 'geo' + spatialDataType: 'geo'; }; type UrlParameters = { diff --git a/src/spatial-index.ts b/src/spatial-index.ts index 6fc5c04..3121785 100644 --- a/src/spatial-index.ts +++ b/src/spatial-index.ts @@ -1,17 +1,23 @@ -import { DEFAULT_AGGREGATION_RES_LEVEL_H3, DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN } from "./constants-internal"; -import { ModelSource } from "./models/model"; -import { AggregationOptions } from "./sources/types"; +import { + DEFAULT_AGGREGATION_RES_LEVEL_H3, + DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN, +} from './constants-internal'; +import {ModelSource} from './models/model'; +import {AggregationOptions} from './sources/types'; const DEFAULT_TILE_SIZE = 512; const QUADBIN_ZOOM_MAX_OFFSET = 4; -export function getSpatialFiltersResolution({ source, viewState }: { +export function getSpatialFiltersResolution({ + source, + viewState, +}: { source: ModelSource & AggregationOptions; viewState: { zoom: number; latitude: number; longitude: number; - } + }; }) { if (source.spatialDataType === 'geo') { return undefined; @@ -27,14 +33,18 @@ export function getSpatialFiltersResolution({ source, viewState }: { ? DEFAULT_AGGREGATION_RES_LEVEL_H3 : DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN); - const aggregationResLevelOffset = Math.max(0, Math.floor(aggregationResLevel)); + const aggregationResLevelOffset = Math.max( + 0, + Math.floor(aggregationResLevel) + ); const currentZoomInt = Math.ceil(currentZoom); if (source.spatialDataType === 'h3') { const tileSize = DEFAULT_TILE_SIZE; const maxResolutionForZoom = - maxH3SpatialFiltersResolutions.find(([zoom]) => zoom === currentZoomInt)?.[1] ?? - Math.max(0, currentZoomInt - 3); + maxH3SpatialFiltersResolutions.find( + ([zoom]) => zoom === currentZoomInt + )?.[1] ?? Math.max(0, currentZoomInt - 3); const maxSpatialFiltersResolution = maxResolutionForZoom ? Math.min(dataResolution, maxResolutionForZoom) @@ -42,7 +52,7 @@ export function getSpatialFiltersResolution({ source, viewState }: { const hexagonResolution = getHexagonResolution( - { zoom: currentZoom, latitude: viewState.latitude }, + {zoom: currentZoom, latitude: viewState.latitude}, tileSize ) + aggregationResLevelOffset; @@ -51,9 +61,13 @@ export function getSpatialFiltersResolution({ source, viewState }: { if (source.spatialDataType === 'quadbin') { const maxResolutionForZoom = currentZoomInt + QUADBIN_ZOOM_MAX_OFFSET; - const maxSpatialFiltersResolution = Math.min(dataResolution, maxResolutionForZoom); + const maxSpatialFiltersResolution = Math.min( + dataResolution, + maxResolutionForZoom + ); - const quadsResolution = Math.floor(viewState.zoom) + aggregationResLevelOffset; + const quadsResolution = + Math.floor(viewState.zoom) + aggregationResLevelOffset; return Math.min(quadsResolution, maxSpatialFiltersResolution); } @@ -80,7 +94,7 @@ const maxH3SpatialFiltersResolutions = [ [4, 2], [3, 1], [2, 1], - [1, 0] + [1, 0], ]; // stolen from https://github.com/visgl/deck.gl/blob/master/modules/carto/src/layers/h3-tileset-2d.ts @@ -99,8 +113,13 @@ export function getHexagonResolution( // expressed as an offset to the viewport zoom. const zoomOffset = Math.log2(tileSize / DEFAULT_TILE_SIZE); const hexagonScaleFactor = (2 / 3) * (viewport.zoom - zoomOffset); - const latitudeScaleFactor = Math.log(1 / Math.cos((Math.PI * viewport.latitude) / 180)); + const latitudeScaleFactor = Math.log( + 1 / Math.cos((Math.PI * viewport.latitude) / 180) + ); // Clip and bias - return Math.max(0, Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS)); + return Math.max( + 0, + Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS) + ); } diff --git a/src/widget-sources/widget-base-source.ts b/src/widget-sources/widget-base-source.ts index 0ffa126..f8e9bba 100644 --- a/src/widget-sources/widget-base-source.ts +++ b/src/widget-sources/widget-base-source.ts @@ -93,7 +93,14 @@ export abstract class WidgetBaseSource { async getCategories( options: CategoryRequestOptions ): Promise { - const {filterOwner, spatialFilter, spatialFiltersMode, spatialFiltersResolution, abortController, ...params} = options; + const { + filterOwner, + spatialFilter, + spatialFiltersMode, + spatialFiltersResolution, + abortController, + ...params + } = options; const {column, operation, operationColumn} = params; type CategoriesModelResponse = {rows: {name: string; value: number}[]}; @@ -130,7 +137,14 @@ export abstract class WidgetBaseSource { async getFeatures( options: FeaturesRequestOptions ): Promise { - const {filterOwner, spatialFilter, spatialFiltersMode, spatialFiltersResolution, abortController, ...params} = options; + const { + filterOwner, + spatialFilter, + spatialFiltersMode, + spatialFiltersResolution, + abortController, + ...params + } = options; const {columns, dataType, featureIds, z, limit, tileResolution} = params; type FeaturesModelResponse = {rows: Record[]}; @@ -141,7 +155,7 @@ export abstract class WidgetBaseSource { ...this.getModelSource(filterOwner), spatialFiltersResolution, spatialFiltersMode, - spatialFilter + spatialFilter, }, params: { columns, @@ -185,7 +199,7 @@ export abstract class WidgetBaseSource { ...this.getModelSource(filterOwner), spatialFiltersResolution, spatialFiltersMode, - spatialFilter + spatialFilter, }, params: {column: column ?? '*', operation, operationExp}, opts: {abortController}, @@ -203,7 +217,14 @@ export abstract class WidgetBaseSource { async getHistogram( options: HistogramRequestOptions ): Promise { - const {filterOwner, spatialFilter, spatialFiltersMode, spatialFiltersResolution, abortController, ...params} = options; + const { + filterOwner, + spatialFilter, + spatialFiltersMode, + spatialFiltersResolution, + abortController, + ...params + } = options; const {column, operation, ticks} = params; type HistogramModelResponse = {rows: {tick: number; value: number}[]}; @@ -214,7 +235,7 @@ export abstract class WidgetBaseSource { ...this.getModelSource(filterOwner), spatialFiltersResolution, spatialFiltersMode, - spatialFilter + spatialFilter, }, params: {column, operation, ticks}, opts: {abortController}, @@ -243,7 +264,14 @@ export abstract class WidgetBaseSource { * or rendering a range slider UI for filtering. */ async getRange(options: RangeRequestOptions): Promise { - const {filterOwner, spatialFilter, spatialFiltersMode, spatialFiltersResolution, abortController, ...params} = options; + const { + filterOwner, + spatialFilter, + spatialFiltersMode, + spatialFiltersResolution, + abortController, + ...params + } = options; const {column} = params; type RangeModelResponse = {rows: {min: number; max: number}[]}; @@ -254,7 +282,7 @@ export abstract class WidgetBaseSource { ...this.getModelSource(filterOwner), spatialFiltersResolution, spatialFiltersMode, - spatialFilter + spatialFilter, }, params: {column}, opts: {abortController}, @@ -270,7 +298,14 @@ export abstract class WidgetBaseSource { * values. Suitable for rendering scatter plots. */ async getScatter(options: ScatterRequestOptions): Promise { - const {filterOwner, spatialFilter, spatialFiltersMode, spatialFiltersResolution, abortController, ...params} = options; + const { + filterOwner, + spatialFilter, + spatialFiltersMode, + spatialFiltersResolution, + abortController, + ...params + } = options; const {xAxisColumn, xAxisJoinOperation, yAxisColumn, yAxisJoinOperation} = params; @@ -285,7 +320,7 @@ export abstract class WidgetBaseSource { ...this.getModelSource(filterOwner), spatialFiltersResolution, spatialFiltersMode, - spatialFilter + spatialFilter, }, params: { xAxisColumn, @@ -309,7 +344,14 @@ export abstract class WidgetBaseSource { * sorting. Suitable for displaying tables and lists. */ async getTable(options: TableRequestOptions): Promise { - const {filterOwner, spatialFilter, spatialFiltersMode, spatialFiltersResolution, abortController, ...params} = options; + const { + filterOwner, + spatialFilter, + spatialFiltersMode, + spatialFiltersResolution, + abortController, + ...params + } = options; const {columns, sortBy, sortDirection, offset = 0, limit = 10} = params; type TableModelResponse = { @@ -323,7 +365,7 @@ export abstract class WidgetBaseSource { ...this.getModelSource(filterOwner), spatialFiltersResolution, spatialFiltersMode, - spatialFilter + spatialFilter, }, params: { column: columns, @@ -351,7 +393,14 @@ export abstract class WidgetBaseSource { async getTimeSeries( options: TimeSeriesRequestOptions ): Promise { - const {filterOwner, abortController, spatialFilter, spatialFiltersMode, spatialFiltersResolution, ...params} = options; + const { + filterOwner, + abortController, + spatialFilter, + spatialFiltersMode, + spatialFiltersResolution, + ...params + } = options; const { column, operationColumn, @@ -375,7 +424,7 @@ export abstract class WidgetBaseSource { ...this.getModelSource(filterOwner), spatialFiltersResolution, spatialFiltersMode, - spatialFilter + spatialFilter, }, params: { column,