@deck.gl/carto 8.7.0-beta.4 → 8.7.0-beta.5

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@deck.gl/carto",
3
3
  "description": "CARTO official integration with Deck.gl. Build geospatial applications using CARTO and Deck.gl.",
4
4
  "license": "MIT",
5
- "version": "8.7.0-beta.4",
5
+ "version": "8.7.0-beta.5",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
@@ -50,5 +50,5 @@
50
50
  "@deck.gl/layers": "^8.0.0",
51
51
  "@loaders.gl/core": "^3.1.5"
52
52
  },
53
- "gitHead": "fc41a854c97a421dec38411fc593bcdf625cdf84"
53
+ "gitHead": "02b67ab8085c6283c0cae45e37a9b70b24f4434b"
54
54
  }
@@ -14,6 +14,7 @@ import moment from 'moment-timezone';
14
14
  import {log} from '@deck.gl/core';
15
15
  import {H3HexagonLayer, MVTLayer} from '@deck.gl/geo-layers';
16
16
  import {GeoJsonLayer} from '@deck.gl/layers';
17
+ import {_CartoDynamicTileLayer, TILE_FORMATS} from '@deck.gl/carto';
17
18
 
18
19
  const SCALE_FUNCS = {
19
20
  linear: scaleLinear,
@@ -63,9 +64,12 @@ function mergePropMaps(a, b) {
63
64
  return {...a, ...b, visConfig: {...a.visConfig, ...b.visConfig}};
64
65
  }
65
66
 
66
- export function getLayer(type, config) {
67
- const hexagonId = config.columns?.hex_id;
67
+ export function getLayer(type, config, dataset) {
68
+ if (type === 'mvt' || type === 'tileset') {
69
+ return getTileLayer(dataset);
70
+ }
68
71
 
72
+ const hexagonId = config.columns?.hex_id;
69
73
  const layer = {
70
74
  point: {
71
75
  Layer: GeoJsonLayer,
@@ -85,16 +89,6 @@ export function getLayer(type, config) {
85
89
  visConfig: {coverage: 'coverage', elevationScale: 'elevationScale'}
86
90
  }),
87
91
  defaultProps: {...defaultProps, getHexagon: d => d[hexagonId]}
88
- },
89
- mvt: {
90
- Layer: MVTLayer,
91
- propMap: sharedPropMap,
92
- defaultProps: {
93
- ...defaultProps,
94
- pointRadiusScale: 0.3,
95
- lineWidthScale: 2,
96
- uniqueIdProperty: 'geoid'
97
- }
98
92
  }
99
93
  }[type];
100
94
 
@@ -103,6 +97,28 @@ export function getLayer(type, config) {
103
97
  return layer;
104
98
  }
105
99
 
100
+ function getTileLayer(dataset) {
101
+ const {
102
+ data: {
103
+ tiles: [tileUrl]
104
+ }
105
+ } = dataset;
106
+ /* global URL */
107
+ const formatTiles = new URL(tileUrl).searchParams.get('formatTiles') || TILE_FORMATS.MVT;
108
+
109
+ return {
110
+ Layer: formatTiles === TILE_FORMATS.MVT ? MVTLayer : _CartoDynamicTileLayer,
111
+ propMap: sharedPropMap,
112
+ defaultProps: {
113
+ ...defaultProps,
114
+ pointRadiusScale: 0.3,
115
+ lineWidthScale: 2,
116
+ uniqueIdProperty: 'geoid',
117
+ formatTiles
118
+ }
119
+ };
120
+ }
121
+
106
122
  function domainFromAttribute(attribute, scaleType) {
107
123
  if (scaleType === 'ordinal' || scaleType === 'point') {
108
124
  return attribute.categories.map(c => c.category).filter(c => c !== undefined && c !== null);
@@ -255,7 +255,7 @@ export async function getData({
255
255
  return layerData.data;
256
256
  }
257
257
 
258
- /* global clearInterval, setInterval, URLSearchParams */
258
+ /* global clearInterval, setInterval, URL */
259
259
  async function _fetchMapDataset(dataset, accessToken, credentials, clientId) {
260
260
  // First fetch metadata
261
261
  const {connectionName: connection, source, type} = dataset;
@@ -268,7 +268,7 @@ async function _fetchMapDataset(dataset, accessToken, credentials, clientId) {
268
268
  });
269
269
 
270
270
  // Extract the last time the data changed
271
- const cache = parseInt(new URLSearchParams(url).get('cache'), 10);
271
+ const cache = parseInt(new URL(url).searchParams.get('cache'), 10);
272
272
  if (cache && dataset.cache === cache) {
273
273
  return false;
274
274
  }
@@ -291,6 +291,7 @@ export async function fetchMap({cartoMapId, clientId, credentials, autoRefresh,
291
291
  ...(defaultCredentials.apiVersion === API_VERSIONS.V3 && defaultCredentials),
292
292
  ...credentials
293
293
  };
294
+ const {accessToken} = localCreds;
294
295
 
295
296
  log.assert(cartoMapId, `Must define CARTO map id: fetchMap({cartoMapId: 'XXXX-XXXX-XXXX'})`);
296
297
 
@@ -307,7 +308,7 @@ export async function fetchMap({cartoMapId, clientId, credentials, autoRefresh,
307
308
  }
308
309
 
309
310
  const url = `${localCreds.mapsUrl}/public/${cartoMapId}`;
310
- const map = await request({url});
311
+ const map = await request({url, accessToken});
311
312
 
312
313
  // Periodically check if the data has changed. Note that this
313
314
  // will not update when a map is published.
@@ -24,12 +24,12 @@ export function parseMap(json) {
24
24
  mapStyle,
25
25
  layers: extractTextLayers(layers.reverse()).map(({id, type, config, visualChannels}) => {
26
26
  try {
27
- const {Layer, propMap, defaultProps} = getLayer(type, config);
28
27
  const {dataId} = config;
29
28
  const dataset = datasets.find(d => d.id === dataId);
30
29
  log.assert(dataset, `No dataset matching dataId: ${dataId}`);
31
30
  const {data} = dataset;
32
31
  log.assert(data, `No data loaded for dataId: ${dataId}`);
32
+ const {Layer, propMap, defaultProps} = getLayer(type, config, dataset);
33
33
  return new Layer({
34
34
  id,
35
35
  data,
@@ -6,7 +6,7 @@ import {MVTLayer, _getURLFromTemplate} from '@deck.gl/geo-layers';
6
6
  import {GeoJsonLayer} from '@deck.gl/layers';
7
7
  import {geojsonToBinary} from '@loaders.gl/gis';
8
8
  import {Tile} from './schema/carto-dynamic-tile';
9
- import {encodeParameter, TILE_FORMATS} from '../api/maps-api-common';
9
+ import {TILE_FORMATS} from '../api/maps-api-common';
10
10
 
11
11
  function parseJSON(arrayBuffer) {
12
12
  return JSON.parse(new TextDecoder().decode(arrayBuffer));
@@ -60,7 +60,8 @@ const CartoDynamicTileLoader = {
60
60
  parseSync: parseCartoDynamicTile,
61
61
  options: {
62
62
  cartoDynamicTile: {
63
- formatTiles: TILE_FORMATS.BINARY
63
+ // TODO change to BINARY for 8.7 prod release
64
+ formatTiles: TILE_FORMATS.GEOJSON
64
65
  }
65
66
  }
66
67
  };
@@ -86,7 +87,10 @@ export default class CartoDynamicTileLayer extends MVTLayer {
86
87
  Object.values(TILE_FORMATS).includes(formatTiles),
87
88
  `Invalid value for formatTiles: ${formatTiles}. Use value from TILE_FORMATS`
88
89
  );
89
- url += `&${encodeParameter('formatTiles', formatTiles)}`;
90
+ // eslint-disable-next-line no-undef
91
+ const newUrl = new URL(url);
92
+ newUrl.searchParams.set('formatTiles', formatTiles);
93
+ url = newUrl.toString();
90
94
  loadOptions.cartoDynamicTile = {formatTiles};
91
95
  }
92
96
 
@@ -103,7 +107,7 @@ export default class CartoDynamicTileLayer extends MVTLayer {
103
107
  const {
104
108
  bbox: {west, south, east, north}
105
109
  } = props.tile;
106
- props.extensions = [new ClipExtension(), ...props.extensions];
110
+ props.extensions = [new ClipExtension(), ...(props.extensions || [])];
107
111
  props.clipBounds = [west, south, east, north];
108
112
 
109
113
  const subLayer = new GeoJsonLayer({
@@ -27,8 +27,8 @@ const defaultProps = {
27
27
  // (String, optional): format of data
28
28
  format: null,
29
29
 
30
- // (String, optional): format of data
31
- formatTiles: TILE_FORMATS.GEOJSON, // TODO: for 8.7 release switch to BINARY
30
+ // (String, optional): force format of data for tiles
31
+ formatTiles: null,
32
32
 
33
33
  // (String, optional): clientId identifier used for internal tracing, place here a string to identify the client who is doing the request.
34
34
  clientId: null,
@@ -126,37 +126,35 @@ export default class CartoLayer extends CompositeLayer {
126
126
  }
127
127
  }
128
128
 
129
- renderLayers() {
129
+ _getRenderLayer() {
130
130
  const {data, format, apiVersion} = this.state;
131
131
 
132
- if (!data) return null;
132
+ if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
133
+ return MVTLayer;
134
+ }
133
135
 
134
- const {type, updateTriggers} = this.props;
135
-
136
- let layer;
137
-
138
- /* global URLSearchParams */
139
- const tilesFormat =
140
- apiVersion === API_VERSIONS.V3 &&
141
- format === FORMATS.TILEJSON &&
142
- new URLSearchParams(data.tiles[0]).get('format');
143
- const nonMvtTiles = tilesFormat && tilesFormat !== TILE_FORMATS.MVT;
144
-
145
- const dynamicTiles =
146
- apiVersion === API_VERSIONS.V3 && type === MAP_TYPES.TABLE && format === FORMATS.TILEJSON;
147
-
148
- if (nonMvtTiles || dynamicTiles) {
149
- layer = CartoDynamicTileLayer;
150
- } else if (
151
- apiVersion === API_VERSIONS.V1 ||
152
- apiVersion === API_VERSIONS.V2 ||
153
- format === FORMATS.TILEJSON
154
- ) {
155
- layer = MVTLayer;
156
- } else {
157
- layer = GeoJsonLayer;
136
+ if (format === FORMATS.TILEJSON) {
137
+ /* global URL */
138
+ const formatTiles =
139
+ this.props.formatTiles ||
140
+ new URL(data.tiles[0]).searchParams.get('formatTiles') ||
141
+ TILE_FORMATS.MVT;
142
+ return formatTiles === TILE_FORMATS.MVT ? MVTLayer : CartoDynamicTileLayer;
158
143
  }
159
144
 
145
+ // It's a geojson layer
146
+ return GeoJsonLayer;
147
+ }
148
+
149
+ renderLayers() {
150
+ const {data} = this.state;
151
+
152
+ if (!data) return null;
153
+
154
+ const {updateTriggers} = this.props;
155
+
156
+ const layer = this._getRenderLayer();
157
+
160
158
  const {formatTiles, uniqueIdProperty} = defaultProps;
161
159
  const props = {formatTiles, uniqueIdProperty, ...this.props};
162
160
  delete props.data;