@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.
@@ -41,10 +41,10 @@ export default class H3TileLayer extends CompositeLayer {
41
41
  // Convert Mercator zooms provided in props into H3 res levels
42
42
  // and clip into valid range provided from the tilejson
43
43
  if (this.props.minZoom) {
44
- minresolution = Math.max(minresolution, getHexagonResolution({ zoom: this.props.minZoom, latitude: 0 }));
44
+ minresolution = Math.max(minresolution, getHexagonResolution({ zoom: this.props.minZoom, latitude: 0 }, this.props.tileSize));
45
45
  }
46
46
  if (this.props.maxZoom) {
47
- maxresolution = Math.min(maxresolution, getHexagonResolution({ zoom: this.props.maxZoom, latitude: 0 }));
47
+ maxresolution = Math.min(maxresolution, getHexagonResolution({ zoom: this.props.maxZoom, latitude: 0 }, this.props.tileSize));
48
48
  }
49
49
  // The naming is unfortunate, but minZoom & maxZoom in the context
50
50
  // of a Tileset2D refer to the resolution levels, not the Mercator zooms
@@ -2,7 +2,10 @@ import { _Tileset2D as Tileset2D, GeoBoundingBox } from '@deck.gl/geo-layers';
2
2
  export type H3TileIndex = {
3
3
  i: string;
4
4
  };
5
- export declare function getHexagonResolution(viewport: any): number;
5
+ export declare function getHexagonResolution(viewport: {
6
+ zoom: number;
7
+ latitude: number;
8
+ }, tileSize: number): number;
6
9
  export default class H3Tileset2D extends Tileset2D {
7
10
  /**
8
11
  * Returns all tile indices in the current viewport. If the current zoom level is smaller
@@ -1 +1 @@
1
- {"version":3,"file":"h3-tileset-2d.d.ts","sourceRoot":"","sources":["../../src/layers/h3-tileset-2d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,IAAI,SAAS,EAAE,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAU5E,MAAM,MAAM,WAAW,GAAG;IAAC,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC;AA0DtC,wBAAgB,oBAAoB,CAAC,QAAQ,KA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D } from '@deck.gl/geo-layers';
2
- import { polygonToCells, latLngToCell, getResolution, cellToBoundary, cellToParent, gridDisk } from 'h3-js';
2
+ import { polygonToCells, latLngToCell, getResolution, cellToBoundary, cellToParent, gridDisk, edgeLength, UNITS, originToDirectedEdges } from 'h3-js';
3
+ const MAX_LATITUDE = 85.051128;
4
+ // `polygonToCells()` fills based on hexagon center, this function will
5
+ // pad the bounds such that all cells that overlap the bounds will be included
6
+ function padBoundingBox({ west, north, east, south }, resolution) {
7
+ const corners = [
8
+ [north, east],
9
+ [south, east],
10
+ [south, west],
11
+ [north, west]
12
+ ];
13
+ const cornerCells = corners.map(c => latLngToCell(c[0], c[1], resolution));
14
+ const cornerEdgeLengths = cornerCells.map(c => (Math.max(...originToDirectedEdges(c).map(e => edgeLength(e, UNITS.rads))) * 180) / Math.PI);
15
+ const bufferLat = Math.max(...cornerEdgeLengths);
16
+ const bufferLon = Math.min(180, bufferLat / Math.cos((((north + south) / 2) * Math.PI) / 180));
17
+ return {
18
+ north: Math.min(north + bufferLat, MAX_LATITUDE),
19
+ east: east + bufferLon,
20
+ south: Math.max(south - bufferLat, -MAX_LATITUDE),
21
+ west: west - bufferLon
22
+ };
23
+ }
3
24
  function getHexagonsInBoundingBox({ west, north, east, south }, resolution) {
4
25
  const longitudeSpan = Math.abs(east - west);
5
26
  if (longitudeSpan > 180) {
@@ -8,25 +29,20 @@ function getHexagonsInBoundingBox({ west, north, east, south }, resolution) {
8
29
  const nSegments = Math.ceil(longitudeSpan / 180);
9
30
  let h3Indices = [];
10
31
  for (let s = 0; s < nSegments; s++) {
11
- const segmentEast = east + s * 180;
12
- const segmentWest = Math.min(segmentEast + 179.9999999, west);
32
+ const segmentWest = west + s * 180;
33
+ const segmentEast = Math.min(segmentWest + 179.9999999, east);
13
34
  h3Indices = h3Indices.concat(getHexagonsInBoundingBox({ west: segmentWest, north, east: segmentEast, south }, resolution));
14
35
  }
15
36
  return [...new Set(h3Indices)];
16
37
  }
17
- // `polygonToCells()` fills based on hexagon center, which means tiles vanish
18
- // prematurely. Get more accurate coverage by oversampling
19
- const oversample = 2;
20
- const h3Indices = polygonToCells([
21
- [
22
- [west, north],
23
- [west, south],
24
- [east, south],
25
- [east, north],
26
- [west, north]
27
- ]
28
- ], resolution + oversample, true);
29
- return oversample ? [...new Set(h3Indices.map(i => cellToParent(i, resolution)))] : h3Indices;
38
+ const polygon = [
39
+ [north, east],
40
+ [south, east],
41
+ [south, west],
42
+ [north, west],
43
+ [north, east]
44
+ ];
45
+ return polygonToCells(polygon, resolution);
30
46
  }
31
47
  function tileToBoundingBox(index) {
32
48
  const coordinates = cellToBoundary(index);
@@ -43,8 +59,11 @@ function tileToBoundingBox(index) {
43
59
  // similar
44
60
  // Relative scale factor (0 = no biasing, 2 = a few hexagons cover view)
45
61
  const BIAS = 2;
46
- export function getHexagonResolution(viewport) {
47
- const hexagonScaleFactor = (2 / 3) * viewport.zoom;
62
+ export function getHexagonResolution(viewport, tileSize) {
63
+ // Difference in given tile size compared to deck's internal 512px tile size,
64
+ // expressed as an offset to the viewport zoom.
65
+ const zoomOffset = Math.log2(tileSize / 512);
66
+ const hexagonScaleFactor = (2 / 3) * (viewport.zoom - zoomOffset);
48
67
  const latitudeScaleFactor = Math.log(1 / Math.cos((Math.PI * viewport.latitude) / 180));
49
68
  // Clip and bias
50
69
  return Math.max(0, Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS));
@@ -59,8 +78,9 @@ export default class H3Tileset2D extends Tileset2D {
59
78
  getTileIndices({ viewport, minZoom, maxZoom }) {
60
79
  if (viewport.latitude === undefined)
61
80
  return [];
62
- const [east, south, west, north] = viewport.getBounds();
63
- let z = getHexagonResolution(viewport);
81
+ const [west, south, east, north] = viewport.getBounds();
82
+ const { tileSize } = this.opts;
83
+ let z = getHexagonResolution(viewport, tileSize);
64
84
  let indices;
65
85
  if (typeof minZoom === 'number' && Number.isFinite(minZoom) && z < minZoom) {
66
86
  // TODO support `extent` prop
@@ -74,7 +94,8 @@ export default class H3Tileset2D extends Tileset2D {
74
94
  indices = gridDisk(center, 1);
75
95
  }
76
96
  else {
77
- indices = getHexagonsInBoundingBox({ west, north, east, south }, z);
97
+ const paddedBounds = padBoundingBox({ west, north, east, south }, z);
98
+ indices = getHexagonsInBoundingBox(paddedBounds, z);
78
99
  }
79
100
  return indices.map(i => ({ i }));
80
101
  }
@@ -1,7 +1,7 @@
1
1
  import { TileReader } from "./carto-raster-tile.js";
2
2
  import { parsePbf } from "./tile-loader-utils.js";
3
3
  import { getWorkerUrl } from "../../utils.js";
4
- const VERSION = typeof "9.0.0-beta.9" !== 'undefined' ? "9.0.0-beta.9" : 'latest';
4
+ const VERSION = typeof "9.0.0-beta.11" !== 'undefined' ? "9.0.0-beta.11" : 'latest';
5
5
  const id = 'cartoRasterTile';
6
6
  const DEFAULT_OPTIONS = {
7
7
  cartoRasterTile: {
@@ -2,7 +2,7 @@ import { TileReader } from "./carto-spatial-tile.js";
2
2
  import { parsePbf } from "./tile-loader-utils.js";
3
3
  import { getWorkerUrl } from "../../utils.js";
4
4
  import { binaryToSpatialjson } from "./spatialjson-utils.js";
5
- const VERSION = typeof "9.0.0-beta.9" !== 'undefined' ? "9.0.0-beta.9" : 'latest';
5
+ const VERSION = typeof "9.0.0-beta.11" !== 'undefined' ? "9.0.0-beta.11" : 'latest';
6
6
  const id = 'cartoSpatialTile';
7
7
  const DEFAULT_OPTIONS = {
8
8
  cartoSpatialTile: {
@@ -2,7 +2,7 @@ import earcut from 'earcut';
2
2
  import { TileReader } from "./carto-tile.js";
3
3
  import { parsePbf } from "./tile-loader-utils.js";
4
4
  import { getWorkerUrl } from "../../utils.js";
5
- const VERSION = typeof "9.0.0-beta.9" !== 'undefined' ? "9.0.0-beta.9" : 'latest';
5
+ const VERSION = typeof "9.0.0-beta.11" !== 'undefined' ? "9.0.0-beta.11" : 'latest';
6
6
  const id = 'cartoVectorTile';
7
7
  const DEFAULT_OPTIONS = {
8
8
  cartoVectorTile: {
@@ -1 +1 @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KAAA;IAWtB,cAAc,IAAI,GAAG;IASf,WAAW,CAAC,IAAI,EAAE,aAAa;IAqCrC,eAAe,CACb,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG;QAC1B,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,GAAG,CAAC;QACV,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,aAAa,CAAC;KACrB,GACA,YAAY,GAAG,IAAI;IAuBtB,cAAc,CAAC,MAAM,KAAA;CAYtB"}
@@ -43,6 +43,7 @@ export default class VectorTileLayer extends MVTLayer {
43
43
  loadOptions.gis = { format: 'binary' }; // Use binary for MVT loading
44
44
  return loadOptions;
45
45
  }
46
+ /* eslint-disable camelcase */
46
47
  async getTileData(tile) {
47
48
  const tileJSON = this.props.data;
48
49
  const { tiles, properties_tiles } = tileJSON;
@@ -73,6 +74,7 @@ export default class VectorTileLayer extends MVTLayer {
73
74
  return null;
74
75
  return attributes ? mergeBoundaryData(geometry, attributes) : geometry;
75
76
  }
77
+ /* eslint-enable camelcase */
76
78
  renderSubLayers(props) {
77
79
  if (props.data === null) {
78
80
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"base-source.d.ts","sourceRoot":"","sources":["../../src/sources/base-source.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAkB,OAAO,EAAC,wBAAqB;AAC3D,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EACV,qBAAqB,EACrB,qBAAqB,EAErB,cAAc,EACf,mBAAgB;AAEjB,eAAO,MAAM,eAAe,EAAE,qBAK7B,CAAC;AAEF,wBAAsB,UAAU,CAAC,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC3E,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG,qBAAqB,EAC/D,aAAa,EAAE,aAAa,GAC3B,OAAO,CAAC,cAAc,GAAG,aAAa,GAAG,UAAU,CAAC,CA8CtD"}
1
+ {"version":3,"file":"base-source.d.ts","sourceRoot":"","sources":["../../src/sources/base-source.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAkB,OAAO,EAAC,wBAAqB;AAC3D,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EACV,qBAAqB,EACrB,qBAAqB,EAErB,cAAc,EACf,mBAAgB;AAEjB,eAAO,MAAM,eAAe,EAAE,qBAK7B,CAAC;AAEF,wBAAsB,UAAU,CAAC,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC3E,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG,qBAAqB,EAC/D,aAAa,EAAE,aAAa,GAC3B,OAAO,CAAC,cAAc,GAAG,aAAa,GAAG,UAAU,CAAC,CAiDtD"}
@@ -38,12 +38,15 @@ export async function baseSource(endpoint, options, urlParameters) {
38
38
  }
39
39
  errorContext.requestType = 'Map data';
40
40
  if (format === 'tilejson') {
41
- return await requestWithParameters({
42
- accessToken,
41
+ const json = await requestWithParameters({
43
42
  baseUrl: dataUrl,
44
43
  headers,
45
44
  errorContext
46
45
  });
46
+ if (accessToken) {
47
+ json.accessToken = accessToken;
48
+ }
49
+ return json;
47
50
  }
48
51
  return await requestWithParameters({
49
52
  baseUrl: dataUrl,