@carto/api-client 0.1.1 → 0.2.0
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.
- package/CHANGELOG.md +2 -2
- package/README.md +10 -26
- package/build/api-client.cjs +1 -1
- package/build/api-client.modern.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -17,8 +17,6 @@ npm install --save @carto/api-client
|
|
|
17
17
|
|
|
18
18
|
## Documentation
|
|
19
19
|
|
|
20
|
-
WORK IN PROGRESS.
|
|
21
|
-
|
|
22
20
|
### Fetching data
|
|
23
21
|
|
|
24
22
|
Import `vectorTableSource`, `vectorQuerySource`, and other data source functions
|
|
@@ -27,25 +25,23 @@ from the `@carto/api-client` package. These are drop-in replacements for the equ
|
|
|
27
25
|
```javascript
|
|
28
26
|
import { vectorTableSource } from '@carto/api-client';
|
|
29
27
|
|
|
30
|
-
const data = vectorTableSource({
|
|
28
|
+
const data = await vectorTableSource({
|
|
31
29
|
accessToken: '••••',
|
|
32
30
|
connectionName: 'carto_dw',
|
|
33
31
|
tableName: 'carto-demo-data.demo_tables.retail_stores'
|
|
34
32
|
});
|
|
35
33
|
|
|
36
|
-
const { widgetSource } = await data;
|
|
37
|
-
|
|
38
34
|
// → {name: string; value: number}[]
|
|
39
|
-
const categories = await widgetSource.getCategories({
|
|
35
|
+
const categories = await data.widgetSource.getCategories({
|
|
40
36
|
column: 'store_type',
|
|
41
37
|
operation: 'count',
|
|
42
38
|
});
|
|
43
39
|
|
|
44
40
|
// → {value: number}
|
|
45
|
-
const formula = await widgetSource.getFormula({operation: 'count'});
|
|
41
|
+
const formula = await data.widgetSource.getFormula({operation: 'count'});
|
|
46
42
|
|
|
47
43
|
// → {totalCount: number; rows: Record<string, number | string>[]}
|
|
48
|
-
const table = await widgetSource.getTable({
|
|
44
|
+
const table = await data.widgetSource.getTable({
|
|
49
45
|
columns: ['a', 'b', 'c'],
|
|
50
46
|
sortBy: ['a'],
|
|
51
47
|
rowsPerPage: 20
|
|
@@ -62,7 +58,7 @@ property to the source factory function.
|
|
|
62
58
|
```javascript
|
|
63
59
|
import {vectorTableSource} from '@carto/api-client';
|
|
64
60
|
|
|
65
|
-
const data = vectorTableSource({
|
|
61
|
+
const data = await vectorTableSource({
|
|
66
62
|
accessToken: '••••',
|
|
67
63
|
connectionName: 'carto_dw',
|
|
68
64
|
tableName: 'carto-demo-data.demo_tables.retail_stores',
|
|
@@ -79,7 +75,7 @@ results should not be affected by a filter that the widget itself created.
|
|
|
79
75
|
|
|
80
76
|
```javascript
|
|
81
77
|
// → {name: string; value: number}[]
|
|
82
|
-
const categories = await widgetSource.getCategories({
|
|
78
|
+
const categories = await data.widgetSource.getCategories({
|
|
83
79
|
filterOwner: 'widget-id',
|
|
84
80
|
column: 'store_type',
|
|
85
81
|
operation: 'count',
|
|
@@ -92,7 +88,7 @@ To filter the widget source to a spatial region, pass a `spatialFilter` paramete
|
|
|
92
88
|
|
|
93
89
|
```javascript
|
|
94
90
|
// → {name: string; value: number}[]
|
|
95
|
-
const categories = await widgetSource.getCategories({
|
|
91
|
+
const categories = await data.widgetSource.getCategories({
|
|
96
92
|
column: 'store_type',
|
|
97
93
|
operation: 'count',
|
|
98
94
|
spatialFilter: {
|
|
@@ -114,22 +110,10 @@ To create a spatial filter from the current [deck.gl `viewState`](https://deck.g
|
|
|
114
110
|
|
|
115
111
|
```javascript
|
|
116
112
|
import {WebMercatorViewport} from '@deck.gl/core';
|
|
113
|
+
import {createViewportSpatialFilter} from '@carto/api-client';
|
|
117
114
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return {
|
|
121
|
-
type: 'Polygon',
|
|
122
|
-
coordinates: [
|
|
123
|
-
[
|
|
124
|
-
viewport.unproject([0, 0]),
|
|
125
|
-
viewport.unproject([viewport.width, 0]),
|
|
126
|
-
viewport.unproject([viewport.width, viewport.height]),
|
|
127
|
-
viewport.unproject([0, viewport.height]),
|
|
128
|
-
viewport.unproject([0, 0]),
|
|
129
|
-
],
|
|
130
|
-
],
|
|
131
|
-
};
|
|
132
|
-
}
|
|
115
|
+
const viewport = new WebMercatorViewport(viewState);
|
|
116
|
+
const spatialFilter = createViewportSpatialFilter(viewport.getBounds());
|
|
133
117
|
```
|
|
134
118
|
|
|
135
119
|
### Specifying columns to fetch
|
package/build/api-client.cjs
CHANGED
package/package.json
CHANGED