API
Package | Version | Downloads |
---|---|---|
@carto/react-api |
Set of functions that allow to work with CARTO APIs.
Functions
executeSQL
Async function that executes a SQL query against CARTO SQL API
Input:
Receives a single
Object
argument with the following properties:
Param | Type | Description |
---|---|---|
credentials |
| CARTO user credentials (check the parameters here) |
credentials.apiVersion |
| SQL API version |
credentials.username |
| CARTO username (required for CARTO 2) |
credentials.apiKey |
| CARTO API Key (required for CARTO 2) |
credentials.apiBaseUrl |
| API Base URL (required for CARTO 3) |
credentials.accessToken |
| Access token (required for CARTO 3) |
query |
| SQL query to be executed |
connection |
| Connection name (required for CARTO 3) |
opts |
| Optional. Additional options for the HTTP request, following the Request interface |
opts.abortController |
| To cancel the network request using AbortController |
opts.format |
| Output format to be passed to SQL API (i.e. ‘geojson’) |
queryParameters |
| Optional. SQL query parameters |
Returns:
Object
- Data returned from the SQL query executionExample:
useCartoLayerProps
React hook that allows a more powerful use of CARTO deck.gl layers, creating a set of layer props (see @deck.gl/carto module). It manages automatically filtering and viewport-related calculations, for common use cases.
Input:
Param | Type | Default | Description |
---|---|---|---|
props |
| { source, [layerConfig], [uniqueIdProperty], [viewportFeatures], [viewportFeaturesDebounceTimeout]} | |
props.source |
| { id, type, connection, data, [credentials] } | |
props.source.id |
| Unique source ID. | |
props.source.type |
| Source type. Check available types here | |
props.source.connection |
| Connection name. Required only for CARTO 3. | |
props.source.data |
| Table name, tileset name or SQL query. | |
props.source.queryParameters |
| SQL query parameters | |
[props.source.credentials] |
| (optional) Credentials for accessing the source (check the object props here). | |
[props.layerConfig] |
| (optional) { id, opacity, visible } | |
[props.layerConfig.id] |
| (optional) Unique layer ID. | |
[props.layerConfig.opacity] |
|
| (optional) Initial layer opacity. |
[props.layerConfig.visible] |
|
| (optional) Indicates whether the layer is visible by default or not. |
[props.uniqueIdProperty] |
| (optional) Name of the column for identifying features uniquely. See note below. | |
[props.viewportFeatures] |
|
| (optional) Whether to calculate viewport features for this layer or not. |
[props.viewportFeaturesDebounceTimeout] |
|
| (optional) Timeout for calculating viewport features when there’s a change. It’s used to avoid repeated viewport calculations in a short amount of time. |
About uniqueIdProperty
: the uniqueIdProperty allows to identify a feature uniquely. When using tiles, it allows to detect portions of a same feature present in different tiles (think about a road segment crossing 2 tiles) and apply correct calculations (eg. avoid counting the same feature more than once). These are the rules used internally, in this precise order:
if user indicates a particular property, it will be honoured.
if
cartodb_id
is present, it will be used (all features coming from aCartoLayer
with Maps API version v2 have this field, just be sure to include it in the SQL you use)if
geoid
is present, it will be used. Some datasets withMAP_TYPES.TILESET
type have this identifier.finally, if a value isn’t set for this param and none
cartodb_id
orgeoid
are found, every feature (or portion of a feature), will be treated as a unique feature.
Returns: a set of props for the layer.
Param | Type | Description |
---|---|---|
props |
| Default props required for layers |
props.binary |
| Returns true. The internal viewportFeatures calculation requires MVT property set to true |
props.uniqueIdProperty |
| Returns same unique id property for the layer as the input one |
props.type |
| Source type. Check available types here |
props.connection |
| Connection name. Used only for CARTO 3. |
props.data |
| Table name, tileset name or SQL query |
props.credentials |
| Credentials for accessing the source |
props.onViewportLoad |
| Function that is called when all tiles in the current viewport are loaded. Available when using vector tile sources. Vector tiles are returned if using Maps API v2, or if using Maps API v3 with |
props.onDataLoad |
| Function that is called when all the dataset features are loaded. Available when using Maps API v3 with |
props.getFilterValue |
| Accessor to the filterable value of each data object |
props.filterRange |
| The [min, max] bounds of the filter values to display |
props.extensions |
| Bonus features to add to the core deck.gl layers |
props.updateTriggers |
| Tells deck.gl exactly which attributes need to change, and when |
props.updateTriggers.getFilterValue |
| Updating |
Example
Last updated