@deck.gl/carto 9.0.0-beta.10 → 9.0.0-beta.11

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
@@ -3,7 +3,7 @@
3
3
  "description": "CARTO official integration with Deck.gl. Build geospatial applications using CARTO and Deck.gl.",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
- "version": "9.0.0-beta.10",
6
+ "version": "9.0.0-beta.11",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -42,12 +42,12 @@
42
42
  "prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env=dev"
43
43
  },
44
44
  "dependencies": {
45
- "@loaders.gl/gis": "^4.1.4",
46
- "@loaders.gl/loader-utils": "^4.1.4",
47
- "@loaders.gl/mvt": "^4.1.4",
48
- "@loaders.gl/schema": "^4.1.4",
49
- "@loaders.gl/tiles": "^4.1.4",
50
- "@luma.gl/constants": "^9.0.4",
45
+ "@loaders.gl/gis": "^4.2.0",
46
+ "@loaders.gl/loader-utils": "^4.2.0",
47
+ "@loaders.gl/mvt": "^4.2.0",
48
+ "@loaders.gl/schema": "^4.2.0",
49
+ "@loaders.gl/tiles": "^4.2.0",
50
+ "@luma.gl/constants": "^9.0.11",
51
51
  "@math.gl/web-mercator": "^4.0.0",
52
52
  "@types/d3-array": "^3.0.2",
53
53
  "@types/d3-color": "^1.4.2",
@@ -69,8 +69,8 @@
69
69
  "@deck.gl/extensions": "^9.0.0-beta",
70
70
  "@deck.gl/geo-layers": "^9.0.0-beta",
71
71
  "@deck.gl/layers": "^9.0.0-beta",
72
- "@loaders.gl/core": "^4.1.4",
73
- "@luma.gl/core": "^9.0.4"
72
+ "@loaders.gl/core": "^4.2.0",
73
+ "@luma.gl/core": "^9.0.0"
74
74
  },
75
- "gitHead": "6c44f602069374cd21268ff279c5bf818c905ff7"
75
+ "gitHead": "d8a3f5bdb644f85caba9d5c1e74baff8f8a3d439"
76
76
  }
package/src/api/common.ts CHANGED
@@ -1,10 +1,13 @@
1
+ import {VERSION} from '@deck.gl/core';
2
+
1
3
  export const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
2
4
  export const DEFAULT_CLIENT = 'deck-gl-carto';
3
5
  export const V3_MINOR_VERSION = '3.4';
4
6
  export const MAX_GET_LENGTH = 8192;
5
7
 
6
8
  export const DEFAULT_PARAMETERS = {
7
- v: V3_MINOR_VERSION
9
+ v: V3_MINOR_VERSION,
10
+ deckglVersion: VERSION
8
11
  };
9
12
 
10
13
  export const DEFAULT_HEADERS = {
@@ -11,13 +11,11 @@ function encodeParameter(name: string, value: string | boolean | number): string
11
11
 
12
12
  const REQUEST_CACHE = new Map<string, Promise<unknown>>();
13
13
  export async function requestWithParameters<T = any>({
14
- accessToken,
15
14
  baseUrl,
16
15
  parameters,
17
16
  headers: customHeaders,
18
17
  errorContext
19
18
  }: {
20
- accessToken?: string;
21
19
  baseUrl: string;
22
20
  parameters?: Record<string, string>;
23
21
  headers: Record<string, string>;
@@ -47,9 +45,6 @@ export async function requestWithParameters<T = any>({
47
45
  if (!response || !response.ok) {
48
46
  throw new Error(json.error);
49
47
  }
50
- if (accessToken) {
51
- json.accessToken = accessToken;
52
- }
53
48
  return json;
54
49
  })
55
50
  .catch((error: Error) => {
@@ -61,13 +61,13 @@ export default class H3TileLayer<DataT = any, ExtraPropsT extends {} = {}> exten
61
61
  if (this.props.minZoom) {
62
62
  minresolution = Math.max(
63
63
  minresolution,
64
- getHexagonResolution({zoom: this.props.minZoom, latitude: 0})
64
+ getHexagonResolution({zoom: this.props.minZoom, latitude: 0}, this.props.tileSize)
65
65
  );
66
66
  }
67
67
  if (this.props.maxZoom) {
68
68
  maxresolution = Math.min(
69
69
  maxresolution,
70
- getHexagonResolution({zoom: this.props.maxZoom, latitude: 0})
70
+ getHexagonResolution({zoom: this.props.maxZoom, latitude: 0}, this.props.tileSize)
71
71
  );
72
72
  }
73
73
 
@@ -5,11 +5,43 @@ import {
5
5
  getResolution,
6
6
  cellToBoundary,
7
7
  cellToParent,
8
- gridDisk
8
+ gridDisk,
9
+ edgeLength,
10
+ UNITS,
11
+ originToDirectedEdges
9
12
  } from 'h3-js';
10
13
 
11
14
  export type H3TileIndex = {i: string};
12
15
 
16
+ const MAX_LATITUDE = 85.051128;
17
+
18
+ // `polygonToCells()` fills based on hexagon center, this function will
19
+ // pad the bounds such that all cells that overlap the bounds will be included
20
+ function padBoundingBox(
21
+ {west, north, east, south}: GeoBoundingBox,
22
+ resolution: number
23
+ ): GeoBoundingBox {
24
+ const corners = [
25
+ [north, east],
26
+ [south, east],
27
+ [south, west],
28
+ [north, west]
29
+ ];
30
+ const cornerCells = corners.map(c => latLngToCell(c[0], c[1], resolution));
31
+ const cornerEdgeLengths = cornerCells.map(
32
+ c => (Math.max(...originToDirectedEdges(c).map(e => edgeLength(e, UNITS.rads))) * 180) / Math.PI
33
+ );
34
+ const bufferLat = Math.max(...cornerEdgeLengths);
35
+ const bufferLon = Math.min(180, bufferLat / Math.cos((((north + south) / 2) * Math.PI) / 180));
36
+
37
+ return {
38
+ north: Math.min(north + bufferLat, MAX_LATITUDE),
39
+ east: east + bufferLon,
40
+ south: Math.max(south - bufferLat, -MAX_LATITUDE),
41
+ west: west - bufferLon
42
+ };
43
+ }
44
+
13
45
  function getHexagonsInBoundingBox(
14
46
  {west, north, east, south}: GeoBoundingBox,
15
47
  resolution: number
@@ -21,8 +53,8 @@ function getHexagonsInBoundingBox(
21
53
  const nSegments = Math.ceil(longitudeSpan / 180);
22
54
  let h3Indices: string[] = [];
23
55
  for (let s = 0; s < nSegments; s++) {
24
- const segmentEast = east + s * 180;
25
- const segmentWest = Math.min(segmentEast + 179.9999999, west);
56
+ const segmentWest = west + s * 180;
57
+ const segmentEast = Math.min(segmentWest + 179.9999999, east);
26
58
  h3Indices = h3Indices.concat(
27
59
  getHexagonsInBoundingBox({west: segmentWest, north, east: segmentEast, south}, resolution)
28
60
  );
@@ -30,24 +62,14 @@ function getHexagonsInBoundingBox(
30
62
  return [...new Set(h3Indices)];
31
63
  }
32
64
 
33
- // `polygonToCells()` fills based on hexagon center, which means tiles vanish
34
- // prematurely. Get more accurate coverage by oversampling
35
- const oversample = 2;
36
- const h3Indices = polygonToCells(
37
- [
38
- [
39
- [west, north],
40
- [west, south],
41
- [east, south],
42
- [east, north],
43
- [west, north]
44
- ]
45
- ],
46
- resolution + oversample,
47
- true
48
- );
49
-
50
- return oversample ? [...new Set(h3Indices.map(i => cellToParent(i, resolution)))] : h3Indices;
65
+ const polygon = [
66
+ [north, east],
67
+ [south, east],
68
+ [south, west],
69
+ [north, west],
70
+ [north, east]
71
+ ];
72
+ return polygonToCells(polygon, resolution);
51
73
  }
52
74
 
53
75
  function tileToBoundingBox(index: string): GeoBoundingBox {
@@ -66,8 +88,14 @@ function tileToBoundingBox(index: string): GeoBoundingBox {
66
88
  // similar
67
89
  // Relative scale factor (0 = no biasing, 2 = a few hexagons cover view)
68
90
  const BIAS = 2;
69
- export function getHexagonResolution(viewport): number {
70
- const hexagonScaleFactor = (2 / 3) * viewport.zoom;
91
+ export function getHexagonResolution(
92
+ viewport: {zoom: number; latitude: number},
93
+ tileSize: number
94
+ ): number {
95
+ // Difference in given tile size compared to deck's internal 512px tile size,
96
+ // expressed as an offset to the viewport zoom.
97
+ const zoomOffset = Math.log2(tileSize / 512);
98
+ const hexagonScaleFactor = (2 / 3) * (viewport.zoom - zoomOffset);
71
99
  const latitudeScaleFactor = Math.log(1 / Math.cos((Math.PI * viewport.latitude) / 180));
72
100
 
73
101
  // Clip and bias
@@ -83,9 +111,10 @@ export default class H3Tileset2D extends Tileset2D {
83
111
  // @ts-expect-error Tileset2D should be generic over TileIndex
84
112
  getTileIndices({viewport, minZoom, maxZoom}): H3TileIndex[] {
85
113
  if (viewport.latitude === undefined) return [];
86
- const [east, south, west, north] = viewport.getBounds();
114
+ const [west, south, east, north] = viewport.getBounds();
115
+ const {tileSize} = this.opts;
87
116
 
88
- let z = getHexagonResolution(viewport);
117
+ let z = getHexagonResolution(viewport, tileSize);
89
118
  let indices: string[];
90
119
  if (typeof minZoom === 'number' && Number.isFinite(minZoom) && z < minZoom) {
91
120
  // TODO support `extent` prop
@@ -99,7 +128,8 @@ export default class H3Tileset2D extends Tileset2D {
99
128
  const center = latLngToCell(viewport.latitude, viewport.longitude, maxZoom);
100
129
  indices = gridDisk(center, 1);
101
130
  } else {
102
- indices = getHexagonsInBoundingBox({west, north, east, south}, z);
131
+ const paddedBounds = padBoundingBox({west, north, east, south}, z);
132
+ indices = getHexagonsInBoundingBox(paddedBounds, z);
103
133
  }
104
134
 
105
135
  return indices.map(i => ({i}));
@@ -80,6 +80,7 @@ export default class VectorTileLayer<
80
80
  return loadOptions;
81
81
  }
82
82
 
83
+ /* eslint-disable camelcase */
83
84
  async getTileData(tile: TileLoadProps) {
84
85
  const tileJSON = this.props.data as TilejsonResult;
85
86
  const {tiles, properties_tiles} = tileJSON;
@@ -115,6 +116,7 @@ export default class VectorTileLayer<
115
116
 
116
117
  return attributes ? mergeBoundaryData(geometry, attributes) : geometry;
117
118
  }
119
+ /* eslint-enable camelcase */
118
120
 
119
121
  renderSubLayers(
120
122
  props: TileLayer['props'] & {
@@ -56,12 +56,15 @@ export async function baseSource<UrlParameters extends Record<string, string>>(
56
56
  errorContext.requestType = 'Map data';
57
57
 
58
58
  if (format === 'tilejson') {
59
- return await requestWithParameters<TilejsonResult>({
60
- accessToken,
59
+ const json = await requestWithParameters<TilejsonResult>({
61
60
  baseUrl: dataUrl,
62
61
  headers,
63
62
  errorContext
64
63
  });
64
+ if (accessToken) {
65
+ json.accessToken = accessToken;
66
+ }
67
+ return json;
65
68
  }
66
69
 
67
70
  return await requestWithParameters<GeojsonResult | JsonResult>({