@deck.gl/carto 8.7.0-alpha.8 → 8.7.0-alpha.9

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-alpha.8",
5
+ "version": "8.7.0-alpha.9",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
@@ -31,9 +31,10 @@
31
31
  "prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env.dev"
32
32
  },
33
33
  "dependencies": {
34
- "@loaders.gl/loader-utils": "^3.1.0",
35
- "@loaders.gl/mvt": "^3.1.0",
36
- "@loaders.gl/tiles": "^3.1.0",
34
+ "@loaders.gl/gis": "^3.1.3",
35
+ "@loaders.gl/loader-utils": "^3.1.3",
36
+ "@loaders.gl/mvt": "^3.1.3",
37
+ "@loaders.gl/tiles": "^3.1.3",
37
38
  "@math.gl/web-mercator": "^3.5.6",
38
39
  "cartocolor": "^4.0.2",
39
40
  "d3-array": "^2.8.0",
@@ -46,7 +47,7 @@
46
47
  "@deck.gl/core": "^8.0.0",
47
48
  "@deck.gl/geo-layers": "^8.0.0",
48
49
  "@deck.gl/layers": "^8.0.0",
49
- "@loaders.gl/core": "^3.1.0"
50
+ "@loaders.gl/core": "^3.1.3"
50
51
  },
51
- "gitHead": "c16c8941fe5f2e823bd15a4b9ca4be12d589b0b2"
52
+ "gitHead": "495e0f2afb3449fe523190ab664c37c5e8976c5d"
52
53
  }
@@ -0,0 +1,87 @@
1
+ /* global TextDecoder */
2
+ import {log} from '@deck.gl/core';
3
+ import {ClipExtension} from '@deck.gl/extensions';
4
+ import {MVTLayer} from '@deck.gl/geo-layers';
5
+ import {GeoJsonLayer} from '@deck.gl/layers';
6
+ import {geojsonToBinary} from '@loaders.gl/gis';
7
+ import {encodeParameter} from '../api/maps-api-common';
8
+ import {getURLFromTemplate} from '@deck.gl/geo-layers/tile-layer/utils';
9
+
10
+ function parseJSON(arrayBuffer) {
11
+ return JSON.parse(new TextDecoder().decode(arrayBuffer));
12
+ }
13
+
14
+ function parseCartoDynamicTile(arrayBuffer, options) {
15
+ if (!arrayBuffer) return null;
16
+ const formatTiles = options && options.cartoDynamicTile && options.cartoDynamicTile.formatTiles;
17
+ if (formatTiles === 'geojson') return geojsonToBinary(parseJSON(arrayBuffer).features);
18
+ return null;
19
+ }
20
+
21
+ const CartoDynamicTileLoader = {
22
+ name: 'CARTO Dynamic Tile',
23
+ id: 'cartoDynamicTile',
24
+ module: 'carto',
25
+ extensions: ['pbf'],
26
+ mimeTypes: ['application/x-protobuf'],
27
+ category: 'geometry',
28
+ worker: false,
29
+ parse: async (arrayBuffer, options) => parseCartoDynamicTile(arrayBuffer, options),
30
+ parseSync: parseCartoDynamicTile,
31
+ options: {
32
+ cartoDynamicTile: {
33
+ formatTiles: 'geojson'
34
+ }
35
+ }
36
+ };
37
+
38
+ export default class CartoDynamicTileLayer extends MVTLayer {
39
+ getTileData(tile) {
40
+ let url = getURLFromTemplate(this.state.data, tile);
41
+ if (!url) {
42
+ return Promise.reject('Invalid URL');
43
+ }
44
+
45
+ let loadOptions = this.getLoadOptions();
46
+ const {fetch, formatTiles} = this.props;
47
+ const {signal} = tile;
48
+
49
+ loadOptions = {
50
+ ...loadOptions,
51
+ mimeType: 'application/x-protobuf'
52
+ };
53
+
54
+ if (formatTiles) {
55
+ log.assert(
56
+ ['geojson'].includes(formatTiles),
57
+ `Invalid value for formatTiles: ${formatTiles}`
58
+ );
59
+ url += `&${encodeParameter('formatTiles', formatTiles)}`;
60
+ loadOptions.cartoBinaryTile = {formatTiles};
61
+ }
62
+
63
+ return fetch(url, {propName: 'data', layer: this, loadOptions, signal});
64
+ }
65
+
66
+ renderSubLayers(props) {
67
+ if (props.data === null) {
68
+ return null;
69
+ }
70
+
71
+ props.autoHighlight = false;
72
+
73
+ const {
74
+ bbox: {west, south, east, north}
75
+ } = props.tile;
76
+ props.extensions = [new ClipExtension()];
77
+ props.clipBounds = [west, south, east, north];
78
+
79
+ const subLayer = new GeoJsonLayer({
80
+ ...props
81
+ });
82
+ return subLayer;
83
+ }
84
+ }
85
+
86
+ CartoDynamicTileLayer.layerName = 'CartoDynamicTileLayer';
87
+ CartoDynamicTileLayer.defaultProps = {...MVTLayer.defaultProps, loaders: [CartoDynamicTileLoader]};
@@ -1,4 +1,5 @@
1
1
  import {CompositeLayer, log} from '@deck.gl/core';
2
+ import CartoDynamicTileLayer from './carto-dynamic-tile-layer';
2
3
  import {MVTLayer} from '@deck.gl/geo-layers';
3
4
  import {GeoJsonLayer} from '@deck.gl/layers';
4
5
  import {fetchLayerData, getDataV2, API_VERSIONS} from '../api';
@@ -124,11 +125,13 @@ export default class CartoLayer extends CompositeLayer {
124
125
 
125
126
  if (!data) return null;
126
127
 
127
- const {updateTriggers} = this.props;
128
+ const {type, updateTriggers} = this.props;
128
129
 
129
130
  let layer;
130
131
 
131
- if (
132
+ if (apiVersion === API_VERSIONS.V3 && type === MAP_TYPES.TABLE && format === FORMATS.TILEJSON) {
133
+ layer = CartoDynamicTileLayer;
134
+ } else if (
132
135
  apiVersion === API_VERSIONS.V1 ||
133
136
  apiVersion === API_VERSIONS.V2 ||
134
137
  format === FORMATS.TILEJSON