@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/dist/index.cjs CHANGED
@@ -63,29 +63,45 @@ var import_geo_layers3 = require("@deck.gl/geo-layers");
63
63
  // dist/layers/h3-tileset-2d.js
64
64
  var import_geo_layers = require("@deck.gl/geo-layers");
65
65
  var import_h3_js = require("h3-js");
66
+ var MAX_LATITUDE = 85.051128;
67
+ function padBoundingBox({ west, north, east, south }, resolution) {
68
+ const corners = [
69
+ [north, east],
70
+ [south, east],
71
+ [south, west],
72
+ [north, west]
73
+ ];
74
+ const cornerCells = corners.map((c) => (0, import_h3_js.latLngToCell)(c[0], c[1], resolution));
75
+ const cornerEdgeLengths = cornerCells.map((c) => Math.max(...(0, import_h3_js.originToDirectedEdges)(c).map((e) => (0, import_h3_js.edgeLength)(e, import_h3_js.UNITS.rads))) * 180 / Math.PI);
76
+ const bufferLat = Math.max(...cornerEdgeLengths);
77
+ const bufferLon = Math.min(180, bufferLat / Math.cos((north + south) / 2 * Math.PI / 180));
78
+ return {
79
+ north: Math.min(north + bufferLat, MAX_LATITUDE),
80
+ east: east + bufferLon,
81
+ south: Math.max(south - bufferLat, -MAX_LATITUDE),
82
+ west: west - bufferLon
83
+ };
84
+ }
66
85
  function getHexagonsInBoundingBox({ west, north, east, south }, resolution) {
67
86
  const longitudeSpan = Math.abs(east - west);
68
87
  if (longitudeSpan > 180) {
69
88
  const nSegments = Math.ceil(longitudeSpan / 180);
70
- let h3Indices2 = [];
89
+ let h3Indices = [];
71
90
  for (let s = 0; s < nSegments; s++) {
72
- const segmentEast = east + s * 180;
73
- const segmentWest = Math.min(segmentEast + 179.9999999, west);
74
- h3Indices2 = h3Indices2.concat(getHexagonsInBoundingBox({ west: segmentWest, north, east: segmentEast, south }, resolution));
91
+ const segmentWest = west + s * 180;
92
+ const segmentEast = Math.min(segmentWest + 179.9999999, east);
93
+ h3Indices = h3Indices.concat(getHexagonsInBoundingBox({ west: segmentWest, north, east: segmentEast, south }, resolution));
75
94
  }
76
- return [...new Set(h3Indices2)];
77
- }
78
- const oversample = 2;
79
- const h3Indices = (0, import_h3_js.polygonToCells)([
80
- [
81
- [west, north],
82
- [west, south],
83
- [east, south],
84
- [east, north],
85
- [west, north]
86
- ]
87
- ], resolution + oversample, true);
88
- return oversample ? [...new Set(h3Indices.map((i) => (0, import_h3_js.cellToParent)(i, resolution)))] : h3Indices;
95
+ return [...new Set(h3Indices)];
96
+ }
97
+ const polygon = [
98
+ [north, east],
99
+ [south, east],
100
+ [south, west],
101
+ [north, west],
102
+ [north, east]
103
+ ];
104
+ return (0, import_h3_js.polygonToCells)(polygon, resolution);
89
105
  }
90
106
  function tileToBoundingBox(index) {
91
107
  const coordinates = (0, import_h3_js.cellToBoundary)(index);
@@ -98,8 +114,9 @@ function tileToBoundingBox(index) {
98
114
  return { west, south, east, north };
99
115
  }
100
116
  var BIAS = 2;
101
- function getHexagonResolution(viewport) {
102
- const hexagonScaleFactor = 2 / 3 * viewport.zoom;
117
+ function getHexagonResolution(viewport, tileSize) {
118
+ const zoomOffset = Math.log2(tileSize / 512);
119
+ const hexagonScaleFactor = 2 / 3 * (viewport.zoom - zoomOffset);
103
120
  const latitudeScaleFactor = Math.log(1 / Math.cos(Math.PI * viewport.latitude / 180));
104
121
  return Math.max(0, Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS));
105
122
  }
@@ -107,8 +124,9 @@ var H3Tileset2D = class extends import_geo_layers._Tileset2D {
107
124
  getTileIndices({ viewport, minZoom, maxZoom }) {
108
125
  if (viewport.latitude === void 0)
109
126
  return [];
110
- const [east, south, west, north] = viewport.getBounds();
111
- let z = getHexagonResolution(viewport);
127
+ const [west, south, east, north] = viewport.getBounds();
128
+ const { tileSize } = this.opts;
129
+ let z = getHexagonResolution(viewport, tileSize);
112
130
  let indices;
113
131
  if (typeof minZoom === "number" && Number.isFinite(minZoom) && z < minZoom) {
114
132
  return [];
@@ -118,7 +136,8 @@ var H3Tileset2D = class extends import_geo_layers._Tileset2D {
118
136
  const center = (0, import_h3_js.latLngToCell)(viewport.latitude, viewport.longitude, maxZoom);
119
137
  indices = (0, import_h3_js.gridDisk)(center, 1);
120
138
  } else {
121
- indices = getHexagonsInBoundingBox({ west, north, east, south }, z);
139
+ const paddedBounds = padBoundingBox({ west, north, east, south }, z);
140
+ indices = getHexagonsInBoundingBox(paddedBounds, z);
122
141
  }
123
142
  return indices.map((i) => ({ i }));
124
143
  }
@@ -245,7 +264,7 @@ function scaleIdentity() {
245
264
  }
246
265
 
247
266
  // dist/layers/schema/carto-raster-tile-loader.js
248
- var VERSION = true ? "9.0.0-beta.9" : "latest";
267
+ var VERSION = true ? "9.0.0-beta.11" : "latest";
249
268
  var id = "cartoRasterTile";
250
269
  var DEFAULT_OPTIONS = {
251
270
  cartoRasterTile: {
@@ -516,7 +535,7 @@ function binaryToSpatialjson(binary) {
516
535
  }
517
536
 
518
537
  // dist/layers/schema/carto-spatial-tile-loader.js
519
- var VERSION2 = true ? "9.0.0-beta.9" : "latest";
538
+ var VERSION2 = true ? "9.0.0-beta.11" : "latest";
520
539
  var id2 = "cartoSpatialTile";
521
540
  var DEFAULT_OPTIONS2 = {
522
541
  cartoSpatialTile: {
@@ -721,10 +740,10 @@ var _H3TileLayer = class extends import_core5.CompositeLayer {
721
740
  const { tiles: data } = tileJSON;
722
741
  let { minresolution, maxresolution } = tileJSON;
723
742
  if (this.props.minZoom) {
724
- minresolution = Math.max(minresolution, getHexagonResolution({ zoom: this.props.minZoom, latitude: 0 }));
743
+ minresolution = Math.max(minresolution, getHexagonResolution({ zoom: this.props.minZoom, latitude: 0 }, this.props.tileSize));
725
744
  }
726
745
  if (this.props.maxZoom) {
727
- maxresolution = Math.min(maxresolution, getHexagonResolution({ zoom: this.props.maxZoom, latitude: 0 }));
746
+ maxresolution = Math.min(maxresolution, getHexagonResolution({ zoom: this.props.maxZoom, latitude: 0 }, this.props.tileSize));
728
747
  }
729
748
  return [
730
749
  new SpatialIndexTileLayer(this.props, {
@@ -1268,7 +1287,7 @@ var carto_properties_tile_loader_default = CartoPropertiesTileLoader;
1268
1287
 
1269
1288
  // dist/layers/schema/carto-vector-tile-loader.js
1270
1289
  var import_earcut = __toESM(require("earcut"), 1);
1271
- var VERSION3 = true ? "9.0.0-beta.9" : "latest";
1290
+ var VERSION3 = true ? "9.0.0-beta.11" : "latest";
1272
1291
  var id3 = "cartoVectorTile";
1273
1292
  var DEFAULT_OPTIONS3 = {
1274
1293
  cartoVectorTile: {
@@ -1585,12 +1604,14 @@ function formatErrorKey(key) {
1585
1604
  }
1586
1605
 
1587
1606
  // dist/api/common.js
1607
+ var import_core11 = require("@deck.gl/core");
1588
1608
  var DEFAULT_API_BASE_URL = "https://gcp-us-east1.api.carto.com";
1589
1609
  var DEFAULT_CLIENT = "deck-gl-carto";
1590
1610
  var V3_MINOR_VERSION = "3.4";
1591
1611
  var MAX_GET_LENGTH = 8192;
1592
1612
  var DEFAULT_PARAMETERS = {
1593
- v: V3_MINOR_VERSION
1613
+ v: V3_MINOR_VERSION,
1614
+ deckglVersion: import_core11.VERSION
1594
1615
  };
1595
1616
  var DEFAULT_HEADERS = {
1596
1617
  Accept: "application/json",
@@ -1625,7 +1646,7 @@ function encodeParameter(name, value) {
1625
1646
  return `${name}=${encodeURIComponent(value)}`;
1626
1647
  }
1627
1648
  var REQUEST_CACHE = /* @__PURE__ */ new Map();
1628
- async function requestWithParameters({ accessToken, baseUrl: baseUrl2, parameters, headers: customHeaders, errorContext }) {
1649
+ async function requestWithParameters({ baseUrl: baseUrl2, parameters, headers: customHeaders, errorContext }) {
1629
1650
  const key = createCacheKey(baseUrl2, parameters || {}, customHeaders || {});
1630
1651
  if (REQUEST_CACHE.has(key)) {
1631
1652
  return REQUEST_CACHE.get(key);
@@ -1641,9 +1662,6 @@ async function requestWithParameters({ accessToken, baseUrl: baseUrl2, parameter
1641
1662
  if (!response || !response.ok) {
1642
1663
  throw new Error(json.error);
1643
1664
  }
1644
- if (accessToken) {
1645
- json.accessToken = accessToken;
1646
- }
1647
1665
  return json;
1648
1666
  }).catch((error) => {
1649
1667
  REQUEST_CACHE.delete(key);
@@ -1701,12 +1719,15 @@ async function baseSource(endpoint, options, urlParameters) {
1701
1719
  }
1702
1720
  errorContext.requestType = "Map data";
1703
1721
  if (format === "tilejson") {
1704
- return await requestWithParameters({
1705
- accessToken,
1722
+ const json = await requestWithParameters({
1706
1723
  baseUrl: dataUrl,
1707
1724
  headers,
1708
1725
  errorContext
1709
1726
  });
1727
+ if (accessToken) {
1728
+ json.accessToken = accessToken;
1729
+ }
1730
+ return json;
1710
1731
  }
1711
1732
  return await requestWithParameters({
1712
1733
  baseUrl: dataUrl,
@@ -1887,7 +1908,7 @@ var vectorTilesetSource = async function(options) {
1887
1908
 
1888
1909
  // dist/api/parse-map.js
1889
1910
  var import_constants12 = require("@luma.gl/constants");
1890
- var import_core11 = require("@deck.gl/core");
1911
+ var import_core12 = require("@deck.gl/core");
1891
1912
 
1892
1913
  // dist/api/layer-map.js
1893
1914
  var import_d3_array = require("d3-array");
@@ -2278,7 +2299,7 @@ function parseMap(json) {
2278
2299
  ...createLoadOptions(token)
2279
2300
  });
2280
2301
  } catch (e) {
2281
- import_core11.log.error(e.message)();
2302
+ import_core12.log.error(e.message)();
2282
2303
  return void 0;
2283
2304
  }
2284
2305
  })