|
| 1 | +# CartoLayer |
| 2 | + |
| 3 | +`CartoLayer` is the layer to visualize data using the CARTO Maps API. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +```js |
| 8 | +import DeckGL from '@deck.gl/react'; |
| 9 | +import {CartoLayer, setDefaultCredentials, MAP_TYPES, API_VERSIONS} from '@deck.gl/carto'; |
| 10 | + |
| 11 | +setDefaultCredentials({ |
| 12 | + apiVersion: API_VERSIONS.V2, |
| 13 | + username: 'public', |
| 14 | + apiKey: 'default_public' |
| 15 | +}); |
| 16 | + |
| 17 | +function App({viewState}) { |
| 18 | + const layer = new CartoLayer({ |
| 19 | + type: MAP_TYPES.QUERY, |
| 20 | + data: 'SELECT * FROM world_population_2015', |
| 21 | + pointRadiusMinPixels: 2, |
| 22 | + getLineColor: [0, 0, 0, 125], |
| 23 | + getFillColor: [238, 77, 90], |
| 24 | + lineWidthMinPixels: 1 |
| 25 | + }) |
| 26 | + |
| 27 | + return <DeckGL viewState={viewState} layers={[layer]} />; |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +## Usage Carto Cloud Native |
| 32 | + |
| 33 | +```js |
| 34 | +import DeckGL from '@deck.gl/react'; |
| 35 | +import {CartoLayer, setDefaultCredentials, MAP_TYPES, API_VERSIONS} from '@deck.gl/carto'; |
| 36 | + |
| 37 | +setDefaultCredentials({ |
| 38 | + apiVersion: API_VERSIONS.V3 |
| 39 | + apiBaseUrl: 'https://gcp-us-east1.api.carto.com', |
| 40 | + accessToken: 'XXX', |
| 41 | +}); |
| 42 | + |
| 43 | +function App({viewState}) { |
| 44 | + const layer = new CartoLayer({ |
| 45 | + type: MAP_TYPES.QUERY, |
| 46 | + connection: 'bigquery', |
| 47 | + data: 'SELECT * FROM cartobq.testtables.points_10k', |
| 48 | + pointRadiusMinPixels: 2, |
| 49 | + getLineColor: [0, 0, 0, 200], |
| 50 | + getFillColor: [238, 77, 90], |
| 51 | + lineWidthMinPixels: 1 |
| 52 | + }) |
| 53 | + |
| 54 | + return <DeckGL viewState={viewState} layers={[layer]} />; |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +> **CARTO Cloud Native** is currently available only in a private beta. If you want to test it, please contact us at [[email protected]](mailto:[email protected]?subject=Access%20to%20Cloud%20%Native%20%API%20(v3)). |
| 59 | +
|
| 60 | +## Installation |
| 61 | + |
| 62 | +To install the dependencies from NPM: |
| 63 | + |
| 64 | +```bash |
| 65 | +npm install deck.gl |
| 66 | +# or |
| 67 | +npm install @deck.gl/core @deck.gl/layers @deck.gl/carto |
| 68 | +``` |
| 69 | + |
| 70 | +```js |
| 71 | +import {CartoLayer} from '@deck.gl/carto'; |
| 72 | +new CartoLayer({}); |
| 73 | +``` |
| 74 | + |
| 75 | +To use pre-bundled scripts: |
| 76 | + |
| 77 | +```html |
| 78 | +<script src="https://unpkg.com/deck.gl@^8.5.0/dist.min.js"></script> |
| 79 | +<script src="https://unpkg.com/@deck.gl/carto@^8.5.0/dist.min.js"></script> |
| 80 | + |
| 81 | +<!-- or --> |
| 82 | +<script src="https://unpkg.com/@deck.gl/core@^8.5.0/dist.min.js"></script> |
| 83 | +<script src="https://unpkg.com/@deck.gl/layers@^8.5.0/dist.min.js"></script> |
| 84 | +<script src="https://unpkg.com/@deck.gl/geo-layers@^8.5.0/dist.min.js"></script> |
| 85 | +<script src="https://unpkg.com/@deck.gl/carto@^8.5.0/dist.min.js"></script> |
| 86 | +``` |
| 87 | + |
| 88 | +```js |
| 89 | +new deck.carto.CartoLayer({}); |
| 90 | +``` |
| 91 | + |
| 92 | +## Properties |
| 93 | + |
| 94 | +This layer allows to work with the different CARTO Maps API versions (v1, v2 and v3). When using version v1 and v2, the layer always works with vector tiles so it inherits all properties from [`MVTLayer`](/docs/api-reference/geo-layers/mvt-layer.md). When using v3, the layer works with vector tiles if the `type` property is `MAP_TYPES.TILESET` and with GeoJSON data if the `type` is `MAP_TYPES.QUERY` or `MAP_TYPES.TABLE`. When using GeoJSON data, the layer inherits all properties from [`GeoJsonLayer`](/docs/api-reference/layers/geojson-layer.md). |
| 95 | + |
| 96 | +##### `data` (String) |
| 97 | + |
| 98 | +Required. Either a SQL query or a name of dataset/tileset. |
| 99 | + |
| 100 | +##### `type` (String) |
| 101 | + |
| 102 | +Required. Data type. Possible values are: |
| 103 | + |
| 104 | +- `MAP_TYPES.QUERY`, if `data` is a SQL query. |
| 105 | +- `MAP_TYPES.TILESET`, if `data` is a tileset name. |
| 106 | +- `MAP_TYPES.TABLE`, if `data` is a dataset name. Only supported with API v3. |
| 107 | + |
| 108 | +##### `connection` (String) |
| 109 | + |
| 110 | +Required when apiVersion is `API_VERSIONS.V3`. |
| 111 | + |
| 112 | +Name of the connection registered in the [CARTO workspace]. |
| 113 | + |
| 114 | +##### `uniqueIdProperty` (String) |
| 115 | + |
| 116 | +* Default: `cartodb_id` |
| 117 | + |
| 118 | +Optional. A string pointing to a unique attribute at the result of the query. A unique attribute is needed for highlighting with vector tiles when a feature is split across two or more tiles. |
| 119 | + |
| 120 | +##### `credentials` (Object) |
| 121 | + |
| 122 | +Optional. Overrides the configuration to connect with CARTO. Check the parameters [here](overview#carto-credentials). |
| 123 | + |
| 124 | + |
| 125 | +### Callbacks |
| 126 | + |
| 127 | +#### `onDataLoad` (Function, optional) |
| 128 | + |
| 129 | +`onDataLoad` is called when the request to the CARTO Maps API was completed successfully. |
| 130 | + |
| 131 | +* Default: `data => {}` |
| 132 | + |
| 133 | +Receives arguments: |
| 134 | + |
| 135 | +* `data` (Object) - Data received from CARTO Maps API |
| 136 | + |
| 137 | +##### `onDataError` (Function, optional) |
| 138 | + |
| 139 | +`onDataError` is called when the request to the CARTO Maps API failed. By default the Error is thrown. |
| 140 | + |
| 141 | +* Default: `null` |
| 142 | + |
| 143 | +Receives arguments: |
| 144 | + |
| 145 | +* `error` (`Error`) |
| 146 | + |
| 147 | +## Source |
| 148 | + |
| 149 | +[modules/carto/src/layers/carto-layer.js](https://github.com/visgl/deck.gl/tree/master/modules/carto/src/layers/carto-layer.js) |
0 commit comments