@carto/api-client 0.5.0-alpha.1 → 0.5.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -764,6 +764,91 @@ const boundaryTableSource = async function boundaryTableSource(options) {
|
|
|
764
764
|
return baseSource('boundary', options, urlParameters);
|
|
765
765
|
};
|
|
766
766
|
|
|
767
|
+
const DEFAULT_TILE_SIZE = 512;
|
|
768
|
+
const QUADBIN_ZOOM_MAX_OFFSET = 4;
|
|
769
|
+
function getSpatialFiltersResolution(source, viewState) {
|
|
770
|
+
var _source$dataResolutio, _source$aggregationRe;
|
|
771
|
+
const dataResolution = (_source$dataResolutio = source.dataResolution) != null ? _source$dataResolutio : Number.MAX_VALUE;
|
|
772
|
+
const aggregationResLevel = (_source$aggregationRe = source.aggregationResLevel) != null ? _source$aggregationRe : source.spatialDataType === 'h3' ? DEFAULT_AGGREGATION_RES_LEVEL_H3 : DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN;
|
|
773
|
+
const aggregationResLevelOffset = Math.max(0, Math.floor(aggregationResLevel));
|
|
774
|
+
const currentZoomInt = Math.ceil(viewState.zoom);
|
|
775
|
+
if (source.spatialDataType === 'h3') {
|
|
776
|
+
var _maxH3SpatialFiltersR, _maxH3SpatialFiltersR2;
|
|
777
|
+
const tileSize = DEFAULT_TILE_SIZE;
|
|
778
|
+
const maxResolutionForZoom = (_maxH3SpatialFiltersR = (_maxH3SpatialFiltersR2 = maxH3SpatialFiltersResolutions.find(([zoom]) => zoom === currentZoomInt)) == null ? void 0 : _maxH3SpatialFiltersR2[1]) != null ? _maxH3SpatialFiltersR : Math.max(0, currentZoomInt - 3);
|
|
779
|
+
const maxSpatialFiltersResolution = maxResolutionForZoom ? Math.min(dataResolution, maxResolutionForZoom) : dataResolution;
|
|
780
|
+
const hexagonResolution = getHexagonResolution(viewState, tileSize) + aggregationResLevelOffset;
|
|
781
|
+
return Math.min(hexagonResolution, maxSpatialFiltersResolution);
|
|
782
|
+
}
|
|
783
|
+
if (source.spatialDataType === 'quadbin') {
|
|
784
|
+
const maxResolutionForZoom = currentZoomInt + QUADBIN_ZOOM_MAX_OFFSET;
|
|
785
|
+
const maxSpatialFiltersResolution = Math.min(dataResolution, maxResolutionForZoom);
|
|
786
|
+
const quadsResolution = Math.floor(viewState.zoom) + aggregationResLevelOffset;
|
|
787
|
+
return Math.min(quadsResolution, maxSpatialFiltersResolution);
|
|
788
|
+
}
|
|
789
|
+
return undefined;
|
|
790
|
+
}
|
|
791
|
+
const maxH3SpatialFiltersResolutions = [[20, 14], [19, 13], [18, 12], [17, 11], [16, 10], [15, 9], [14, 8], [13, 7], [12, 7], [11, 7], [10, 6], [9, 6], [8, 5], [7, 4], [6, 4], [5, 3], [4, 2], [3, 1], [2, 1], [1, 0]];
|
|
792
|
+
// stolen from https://github.com/visgl/deck.gl/blob/master/modules/carto/src/layers/h3-tileset-2d.ts
|
|
793
|
+
// Relative scale factor (0 = no biasing, 2 = a few hexagons cover view)
|
|
794
|
+
const BIAS = 2;
|
|
795
|
+
// Resolution conversion function. Takes a WebMercatorViewport and returns
|
|
796
|
+
// a H3 resolution such that the screen space size of the hexagons is
|
|
797
|
+
// similar
|
|
798
|
+
function getHexagonResolution(viewport, tileSize) {
|
|
799
|
+
// Difference in given tile size compared to deck's internal 512px tile size,
|
|
800
|
+
// expressed as an offset to the viewport zoom.
|
|
801
|
+
const zoomOffset = Math.log2(tileSize / DEFAULT_TILE_SIZE);
|
|
802
|
+
const hexagonScaleFactor = 2 / 3 * (viewport.zoom - zoomOffset);
|
|
803
|
+
const latitudeScaleFactor = Math.log(1 / Math.cos(Math.PI * viewport.latitude / 180));
|
|
804
|
+
// Clip and bias
|
|
805
|
+
return Math.max(0, Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS));
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* Source for Widget API requests on a data source defined by a SQL query.
|
|
810
|
+
*
|
|
811
|
+
* Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
|
|
812
|
+
*/
|
|
813
|
+
class WidgetSource {
|
|
814
|
+
constructor(props) {
|
|
815
|
+
this.props = void 0;
|
|
816
|
+
this.props = _extends({}, WidgetSource.defaultProps, props);
|
|
817
|
+
}
|
|
818
|
+
_getModelSource(owner) {
|
|
819
|
+
const props = this.props;
|
|
820
|
+
return {
|
|
821
|
+
apiVersion: props.apiVersion,
|
|
822
|
+
apiBaseUrl: props.apiBaseUrl,
|
|
823
|
+
clientId: props.clientId,
|
|
824
|
+
accessToken: props.accessToken,
|
|
825
|
+
connectionName: props.connectionName,
|
|
826
|
+
filters: getApplicableFilters(owner, props.filters),
|
|
827
|
+
filtersLogicalOperator: props.filtersLogicalOperator,
|
|
828
|
+
spatialDataType: props.spatialDataType,
|
|
829
|
+
spatialDataColumn: props.spatialDataColumn,
|
|
830
|
+
dataResolution: props.dataResolution
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
_getSpatialFiltersResolution(source, spatialFilter, referenceViewState) {
|
|
834
|
+
// spatialFiltersResolution applies only to spatial index sources.
|
|
835
|
+
if (!spatialFilter || source.spatialDataType === 'geo') {
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
if (!referenceViewState) {
|
|
839
|
+
throw new Error('Missing required option, "spatialIndexReferenceViewState".');
|
|
840
|
+
}
|
|
841
|
+
return getSpatialFiltersResolution(source, referenceViewState);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
WidgetSource.defaultProps = {
|
|
845
|
+
apiVersion: ApiVersion.V3,
|
|
846
|
+
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
847
|
+
clientId: getClient(),
|
|
848
|
+
filters: {},
|
|
849
|
+
filtersLogicalOperator: 'and'
|
|
850
|
+
};
|
|
851
|
+
|
|
767
852
|
/**
|
|
768
853
|
* Return more descriptive error from API
|
|
769
854
|
* @internalRemarks Source: @carto/react-api
|
|
@@ -928,91 +1013,6 @@ function objectToURLSearchParams(object) {
|
|
|
928
1013
|
return params;
|
|
929
1014
|
}
|
|
930
1015
|
|
|
931
|
-
const DEFAULT_TILE_SIZE = 512;
|
|
932
|
-
const QUADBIN_ZOOM_MAX_OFFSET = 4;
|
|
933
|
-
function getSpatialFiltersResolution(source, viewState) {
|
|
934
|
-
var _source$dataResolutio, _source$aggregationRe;
|
|
935
|
-
const dataResolution = (_source$dataResolutio = source.dataResolution) != null ? _source$dataResolutio : Number.MAX_VALUE;
|
|
936
|
-
const aggregationResLevel = (_source$aggregationRe = source.aggregationResLevel) != null ? _source$aggregationRe : source.spatialDataType === 'h3' ? DEFAULT_AGGREGATION_RES_LEVEL_H3 : DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN;
|
|
937
|
-
const aggregationResLevelOffset = Math.max(0, Math.floor(aggregationResLevel));
|
|
938
|
-
const currentZoomInt = Math.ceil(viewState.zoom);
|
|
939
|
-
if (source.spatialDataType === 'h3') {
|
|
940
|
-
var _maxH3SpatialFiltersR, _maxH3SpatialFiltersR2;
|
|
941
|
-
const tileSize = DEFAULT_TILE_SIZE;
|
|
942
|
-
const maxResolutionForZoom = (_maxH3SpatialFiltersR = (_maxH3SpatialFiltersR2 = maxH3SpatialFiltersResolutions.find(([zoom]) => zoom === currentZoomInt)) == null ? void 0 : _maxH3SpatialFiltersR2[1]) != null ? _maxH3SpatialFiltersR : Math.max(0, currentZoomInt - 3);
|
|
943
|
-
const maxSpatialFiltersResolution = maxResolutionForZoom ? Math.min(dataResolution, maxResolutionForZoom) : dataResolution;
|
|
944
|
-
const hexagonResolution = getHexagonResolution(viewState, tileSize) + aggregationResLevelOffset;
|
|
945
|
-
return Math.min(hexagonResolution, maxSpatialFiltersResolution);
|
|
946
|
-
}
|
|
947
|
-
if (source.spatialDataType === 'quadbin') {
|
|
948
|
-
const maxResolutionForZoom = currentZoomInt + QUADBIN_ZOOM_MAX_OFFSET;
|
|
949
|
-
const maxSpatialFiltersResolution = Math.min(dataResolution, maxResolutionForZoom);
|
|
950
|
-
const quadsResolution = Math.floor(viewState.zoom) + aggregationResLevelOffset;
|
|
951
|
-
return Math.min(quadsResolution, maxSpatialFiltersResolution);
|
|
952
|
-
}
|
|
953
|
-
return undefined;
|
|
954
|
-
}
|
|
955
|
-
const maxH3SpatialFiltersResolutions = [[20, 14], [19, 13], [18, 12], [17, 11], [16, 10], [15, 9], [14, 8], [13, 7], [12, 7], [11, 7], [10, 6], [9, 6], [8, 5], [7, 4], [6, 4], [5, 3], [4, 2], [3, 1], [2, 1], [1, 0]];
|
|
956
|
-
// stolen from https://github.com/visgl/deck.gl/blob/master/modules/carto/src/layers/h3-tileset-2d.ts
|
|
957
|
-
// Relative scale factor (0 = no biasing, 2 = a few hexagons cover view)
|
|
958
|
-
const BIAS = 2;
|
|
959
|
-
// Resolution conversion function. Takes a WebMercatorViewport and returns
|
|
960
|
-
// a H3 resolution such that the screen space size of the hexagons is
|
|
961
|
-
// similar
|
|
962
|
-
function getHexagonResolution(viewport, tileSize) {
|
|
963
|
-
// Difference in given tile size compared to deck's internal 512px tile size,
|
|
964
|
-
// expressed as an offset to the viewport zoom.
|
|
965
|
-
const zoomOffset = Math.log2(tileSize / DEFAULT_TILE_SIZE);
|
|
966
|
-
const hexagonScaleFactor = 2 / 3 * (viewport.zoom - zoomOffset);
|
|
967
|
-
const latitudeScaleFactor = Math.log(1 / Math.cos(Math.PI * viewport.latitude / 180));
|
|
968
|
-
// Clip and bias
|
|
969
|
-
return Math.max(0, Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS));
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
/**
|
|
973
|
-
* Source for Widget API requests on a data source defined by a SQL query.
|
|
974
|
-
*
|
|
975
|
-
* Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
|
|
976
|
-
*/
|
|
977
|
-
class WidgetSource {
|
|
978
|
-
constructor(props) {
|
|
979
|
-
this.props = void 0;
|
|
980
|
-
this.props = _extends({}, WidgetSource.defaultProps, props);
|
|
981
|
-
}
|
|
982
|
-
_getModelSource(owner) {
|
|
983
|
-
const props = this.props;
|
|
984
|
-
return {
|
|
985
|
-
apiVersion: props.apiVersion,
|
|
986
|
-
apiBaseUrl: props.apiBaseUrl,
|
|
987
|
-
clientId: props.clientId,
|
|
988
|
-
accessToken: props.accessToken,
|
|
989
|
-
connectionName: props.connectionName,
|
|
990
|
-
filters: getApplicableFilters(owner, props.filters),
|
|
991
|
-
filtersLogicalOperator: props.filtersLogicalOperator,
|
|
992
|
-
spatialDataType: props.spatialDataType,
|
|
993
|
-
spatialDataColumn: props.spatialDataColumn,
|
|
994
|
-
dataResolution: props.dataResolution
|
|
995
|
-
};
|
|
996
|
-
}
|
|
997
|
-
_getSpatialFiltersResolution(source, spatialFilter, referenceViewState) {
|
|
998
|
-
// spatialFiltersResolution applies only to spatial index sources.
|
|
999
|
-
if (!spatialFilter || source.spatialDataType === 'geo') {
|
|
1000
|
-
return;
|
|
1001
|
-
}
|
|
1002
|
-
if (!referenceViewState) {
|
|
1003
|
-
throw new Error('Missing required option, "spatialIndexReferenceViewState".');
|
|
1004
|
-
}
|
|
1005
|
-
return getSpatialFiltersResolution(source, referenceViewState);
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
WidgetSource.defaultProps = {
|
|
1009
|
-
apiVersion: ApiVersion.V3,
|
|
1010
|
-
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
1011
|
-
clientId: getClient(),
|
|
1012
|
-
filters: {},
|
|
1013
|
-
filtersLogicalOperator: 'and'
|
|
1014
|
-
};
|
|
1015
|
-
|
|
1016
1016
|
const _excluded$1 = ["filterOwner", "spatialFilter", "spatialFiltersMode", "spatialIndexReferenceViewState", "abortController"],
|
|
1017
1017
|
_excluded2 = ["filterOwner", "spatialFilter", "spatialFiltersMode", "spatialIndexReferenceViewState", "abortController"],
|
|
1018
1018
|
_excluded3 = ["filterOwner", "spatialFilter", "spatialFiltersMode", "spatialIndexReferenceViewState", "abortController", "operationExp"],
|
|
@@ -3570,5 +3570,5 @@ const query = async function query(options) {
|
|
|
3570
3570
|
});
|
|
3571
3571
|
};
|
|
3572
3572
|
|
|
3573
|
-
export { ApiVersion, CartoAPIError, DEFAULT_API_BASE_URL, FEATURE_GEOM_PROPERTY, FilterType, Provider, SOURCE_DEFAULTS, SpatialIndex, TileFormat, WidgetQuerySource, WidgetRemoteSource, WidgetTableSource, WidgetTilesetSource, addFilter, aggregate, aggregationFunctions, applyFilters, applySorting, boundaryQuerySource, boundaryTableSource, buildBinaryFeatureFilter, buildFeatureFilter, buildPublicMapUrl, buildStatsUrl, clearFilters, createPolygonSpatialFilter, createViewportSpatialFilter, filterFunctions, geojsonFeatures, getClient, getFilter, groupValuesByColumn, groupValuesByDateColumn, h3QuerySource, h3TableSource, h3TilesetSource, hasFilter, histogram, makeIntervalComplete, quadbinQuerySource, quadbinTableSource, quadbinTilesetSource, query, rasterSource, removeFilter, requestWithParameters, scatterPlot, setClient, tileFeatures, tileFeaturesGeometries, tileFeaturesSpatialIndex, transformToTileCoords, vectorQuerySource, vectorTableSource, vectorTilesetSource };
|
|
3573
|
+
export { ApiVersion, CartoAPIError, DEFAULT_API_BASE_URL, FEATURE_GEOM_PROPERTY, FilterType, Provider, SOURCE_DEFAULTS, SpatialIndex, TileFormat, WidgetQuerySource, WidgetRemoteSource, WidgetSource, WidgetTableSource, WidgetTilesetSource, addFilter, aggregate, aggregationFunctions, applyFilters, applySorting, boundaryQuerySource, boundaryTableSource, buildBinaryFeatureFilter, buildFeatureFilter, buildPublicMapUrl, buildStatsUrl, clearFilters, createPolygonSpatialFilter, createViewportSpatialFilter, filterFunctions, geojsonFeatures, getClient, getFilter, groupValuesByColumn, groupValuesByDateColumn, h3QuerySource, h3TableSource, h3TilesetSource, hasFilter, histogram, makeIntervalComplete, quadbinQuerySource, quadbinTableSource, quadbinTilesetSource, query, rasterSource, removeFilter, requestWithParameters, scatterPlot, setClient, tileFeatures, tileFeaturesGeometries, tileFeaturesSpatialIndex, transformToTileCoords, vectorQuerySource, vectorTableSource, vectorTilesetSource };
|
|
3574
3574
|
//# sourceMappingURL=api-client.modern.js.map
|