@deck.gl/geo-layers 8.8.0-beta.5 → 8.8.2

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.
Files changed (40) hide show
  1. package/dist/dist.dev.js +1633 -1615
  2. package/dist/es5/mesh-layer/mesh-layer.js +21 -2
  3. package/dist/es5/mesh-layer/mesh-layer.js.map +1 -1
  4. package/dist/es5/tile-layer/tile-layer.js.map +1 -1
  5. package/dist/esm/mesh-layer/mesh-layer.js +20 -2
  6. package/dist/esm/mesh-layer/mesh-layer.js.map +1 -1
  7. package/dist/esm/tile-layer/tile-layer.js.map +1 -1
  8. package/dist.min.js +1 -1
  9. package/package.json +2 -2
  10. package/src/mesh-layer/mesh-layer.ts +17 -3
  11. package/src/tile-layer/tile-layer.ts +1 -1
  12. package/typed/geo-cell-layer/GeoCellLayer.js +49 -0
  13. package/typed/great-circle-layer/great-circle-layer.js +29 -0
  14. package/typed/h3-layers/h3-cluster-layer.js +33 -0
  15. package/typed/h3-layers/h3-hexagon-layer.js +251 -0
  16. package/typed/index.js +33 -0
  17. package/typed/mesh-layer/mesh-layer-fragment.glsl.js +55 -0
  18. package/typed/mesh-layer/mesh-layer-vertex.glsl.js +80 -0
  19. package/typed/mesh-layer/mesh-layer.d.ts +2 -1
  20. package/typed/mesh-layer/mesh-layer.d.ts.map +1 -1
  21. package/typed/mesh-layer/mesh-layer.js +110 -0
  22. package/typed/mvt-layer/coordinate-transform.js +41 -0
  23. package/typed/mvt-layer/find-index-binary.js +96 -0
  24. package/typed/mvt-layer/mvt-layer.js +297 -0
  25. package/typed/quadkey-layer/quadkey-layer.js +18 -0
  26. package/typed/quadkey-layer/quadkey-utils.js +26 -0
  27. package/typed/s2-layer/s2-geometry.js +123 -0
  28. package/typed/s2-layer/s2-layer.js +37 -0
  29. package/typed/s2-layer/s2-utils.js +88 -0
  30. package/typed/terrain-layer/terrain-layer.js +226 -0
  31. package/typed/tile-3d-layer/tile-3d-layer.js +294 -0
  32. package/typed/tile-layer/tile-2d-header.js +113 -0
  33. package/typed/tile-layer/tile-2d-traversal.js +181 -0
  34. package/typed/tile-layer/tile-layer.d.ts +1 -1
  35. package/typed/tile-layer/tile-layer.d.ts.map +1 -1
  36. package/typed/tile-layer/tile-layer.js +192 -0
  37. package/typed/tile-layer/tileset-2d.js +399 -0
  38. package/typed/tile-layer/types.js +1 -0
  39. package/typed/tile-layer/utils.js +197 -0
  40. package/typed/trips-layer/trips-layer.js +92 -0
@@ -0,0 +1,197 @@
1
+ import { getOSMTileIndices } from './tile-2d-traversal';
2
+ const TILE_SIZE = 512;
3
+ const DEFAULT_EXTENT = [-Infinity, -Infinity, Infinity, Infinity];
4
+ export const urlType = {
5
+ type: 'url',
6
+ value: null,
7
+ validate: (value, propType) => (propType.optional && value === null) ||
8
+ typeof value === 'string' ||
9
+ (Array.isArray(value) && value.every(url => typeof url === 'string')),
10
+ equals: (value1, value2) => {
11
+ if (value1 === value2) {
12
+ return true;
13
+ }
14
+ if (!Array.isArray(value1) || !Array.isArray(value2)) {
15
+ return false;
16
+ }
17
+ const len = value1.length;
18
+ if (len !== value2.length) {
19
+ return false;
20
+ }
21
+ for (let i = 0; i < len; i++) {
22
+ if (value1[i] !== value2[i]) {
23
+ return false;
24
+ }
25
+ }
26
+ return true;
27
+ }
28
+ };
29
+ function transformBox(bbox, modelMatrix) {
30
+ const transformedCoords = [
31
+ // top-left
32
+ modelMatrix.transformAsPoint([bbox[0], bbox[1]]),
33
+ // top-right
34
+ modelMatrix.transformAsPoint([bbox[2], bbox[1]]),
35
+ // bottom-left
36
+ modelMatrix.transformAsPoint([bbox[0], bbox[3]]),
37
+ // bottom-right
38
+ modelMatrix.transformAsPoint([bbox[2], bbox[3]])
39
+ ];
40
+ const transformedBox = [
41
+ // Minimum x coord
42
+ Math.min(...transformedCoords.map(i => i[0])),
43
+ // Minimum y coord
44
+ Math.min(...transformedCoords.map(i => i[1])),
45
+ // Max x coord
46
+ Math.max(...transformedCoords.map(i => i[0])),
47
+ // Max y coord
48
+ Math.max(...transformedCoords.map(i => i[1]))
49
+ ];
50
+ return transformedBox;
51
+ }
52
+ function stringHash(s) {
53
+ return Math.abs(s.split('').reduce((a, b) => ((a << 5) - a + b.charCodeAt(0)) | 0, 0));
54
+ }
55
+ export function getURLFromTemplate(template, tile) {
56
+ if (!template || !template.length) {
57
+ return null;
58
+ }
59
+ const { index, id } = tile;
60
+ if (Array.isArray(template)) {
61
+ const i = stringHash(id) % template.length;
62
+ template = template[i];
63
+ }
64
+ let url = template;
65
+ for (const key of Object.keys(index)) {
66
+ const regex = new RegExp(`{${key}}`, 'g');
67
+ url = url.replace(regex, String(index[key]));
68
+ }
69
+ // Back-compatible support for {-y}
70
+ if (Number.isInteger(index.y) && Number.isInteger(index.z)) {
71
+ url = url.replace(/\{-y\}/g, String(Math.pow(2, index.z) - index.y - 1));
72
+ }
73
+ return url;
74
+ }
75
+ /**
76
+ * gets the bounding box of a viewport
77
+ */
78
+ function getBoundingBox(viewport, zRange, extent) {
79
+ let bounds;
80
+ if (zRange && zRange.length === 2) {
81
+ const [minZ, maxZ] = zRange;
82
+ const bounds0 = viewport.getBounds({ z: minZ });
83
+ const bounds1 = viewport.getBounds({ z: maxZ });
84
+ bounds = [
85
+ Math.min(bounds0[0], bounds1[0]),
86
+ Math.min(bounds0[1], bounds1[1]),
87
+ Math.max(bounds0[2], bounds1[2]),
88
+ Math.max(bounds0[3], bounds1[3])
89
+ ];
90
+ }
91
+ else {
92
+ bounds = viewport.getBounds();
93
+ }
94
+ if (!viewport.isGeospatial) {
95
+ return [
96
+ // Top corner should not be more then bottom corner in either direction
97
+ Math.max(Math.min(bounds[0], extent[2]), extent[0]),
98
+ Math.max(Math.min(bounds[1], extent[3]), extent[1]),
99
+ // Bottom corner should not be less then top corner in either direction
100
+ Math.min(Math.max(bounds[2], extent[0]), extent[2]),
101
+ Math.min(Math.max(bounds[3], extent[1]), extent[3])
102
+ ];
103
+ }
104
+ return [
105
+ Math.max(bounds[0], extent[0]),
106
+ Math.max(bounds[1], extent[1]),
107
+ Math.min(bounds[2], extent[2]),
108
+ Math.min(bounds[3], extent[3])
109
+ ];
110
+ }
111
+ function getIndexingCoords(bbox, scale, modelMatrixInverse) {
112
+ if (modelMatrixInverse) {
113
+ const transformedTileIndex = transformBox(bbox, modelMatrixInverse).map(i => (i * scale) / TILE_SIZE);
114
+ return transformedTileIndex;
115
+ }
116
+ return bbox.map(i => (i * scale) / TILE_SIZE);
117
+ }
118
+ function getScale(z, tileSize) {
119
+ return (Math.pow(2, z) * TILE_SIZE) / tileSize;
120
+ }
121
+ // https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Lon..2Flat._to_tile_numbers_2
122
+ export function osmTile2lngLat(x, y, z) {
123
+ const scale = getScale(z, TILE_SIZE);
124
+ const lng = (x / scale) * 360 - 180;
125
+ const n = Math.PI - (2 * Math.PI * y) / scale;
126
+ const lat = (180 / Math.PI) * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
127
+ return [lng, lat];
128
+ }
129
+ function tile2XY(x, y, z, tileSize) {
130
+ const scale = getScale(z, tileSize);
131
+ return [(x / scale) * TILE_SIZE, (y / scale) * TILE_SIZE];
132
+ }
133
+ export function tileToBoundingBox(viewport, x, y, z, tileSize = TILE_SIZE) {
134
+ if (viewport.isGeospatial) {
135
+ const [west, north] = osmTile2lngLat(x, y, z);
136
+ const [east, south] = osmTile2lngLat(x + 1, y + 1, z);
137
+ return { west, north, east, south };
138
+ }
139
+ const [left, top] = tile2XY(x, y, z, tileSize);
140
+ const [right, bottom] = tile2XY(x + 1, y + 1, z, tileSize);
141
+ return { left, top, right, bottom };
142
+ }
143
+ function getIdentityTileIndices(viewport, z, tileSize, extent, modelMatrixInverse) {
144
+ const bbox = getBoundingBox(viewport, null, extent);
145
+ const scale = getScale(z, tileSize);
146
+ const [minX, minY, maxX, maxY] = getIndexingCoords(bbox, scale, modelMatrixInverse);
147
+ const indices = [];
148
+ /*
149
+ | TILE | TILE | TILE |
150
+ |(minX) |(maxX)
151
+ */
152
+ for (let x = Math.floor(minX); x < maxX; x++) {
153
+ for (let y = Math.floor(minY); y < maxY; y++) {
154
+ indices.push({ x, y, z });
155
+ }
156
+ }
157
+ return indices;
158
+ }
159
+ /**
160
+ * Returns all tile indices in the current viewport. If the current zoom level is smaller
161
+ * than minZoom, return an empty array. If the current zoom level is greater than maxZoom,
162
+ * return tiles that are on maxZoom.
163
+ */
164
+ // eslint-disable-next-line complexity
165
+ export function getTileIndices({ viewport, maxZoom, minZoom, zRange, extent, tileSize = TILE_SIZE, modelMatrix, modelMatrixInverse, zoomOffset = 0 }) {
166
+ let z = viewport.isGeospatial
167
+ ? Math.round(viewport.zoom + Math.log2(TILE_SIZE / tileSize)) + zoomOffset
168
+ : Math.ceil(viewport.zoom) + zoomOffset;
169
+ if (typeof minZoom === 'number' && Number.isFinite(minZoom) && z < minZoom) {
170
+ if (!extent) {
171
+ return [];
172
+ }
173
+ z = minZoom;
174
+ }
175
+ if (typeof maxZoom === 'number' && Number.isFinite(maxZoom) && z > maxZoom) {
176
+ z = maxZoom;
177
+ }
178
+ let transformedExtent = extent;
179
+ if (modelMatrix && modelMatrixInverse && extent && !viewport.isGeospatial) {
180
+ transformedExtent = transformBox(extent, modelMatrix);
181
+ }
182
+ return viewport.isGeospatial
183
+ ? getOSMTileIndices(viewport, z, zRange, extent)
184
+ : getIdentityTileIndices(viewport, z, tileSize, transformedExtent || DEFAULT_EXTENT, modelMatrixInverse);
185
+ }
186
+ /**
187
+ * Returns true if s is a valid URL template
188
+ */
189
+ export function isURLTemplate(s) {
190
+ return /(?=.*{z})(?=.*{x})(?=.*({y}|{-y}))/.test(s);
191
+ }
192
+ export function isGeoBoundingBox(v) {
193
+ return (Number.isFinite(v.west) &&
194
+ Number.isFinite(v.north) &&
195
+ Number.isFinite(v.east) &&
196
+ Number.isFinite(v.south));
197
+ }
@@ -0,0 +1,92 @@
1
+ // Copyright (c) 2015 - 2017 Uber Technologies, Inc.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in
11
+ // all copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ // THE SOFTWARE.
20
+ import { PathLayer } from '@deck.gl/layers';
21
+ const defaultProps = {
22
+ fadeTrail: true,
23
+ trailLength: { type: 'number', value: 120, min: 0 },
24
+ currentTime: { type: 'number', value: 0, min: 0 },
25
+ getTimestamps: { type: 'accessor', value: null }
26
+ };
27
+ export default class TripsLayer extends PathLayer {
28
+ getShaders() {
29
+ const shaders = super.getShaders();
30
+ shaders.inject = {
31
+ 'vs:#decl': `\
32
+ uniform float trailLength;
33
+ attribute float instanceTimestamps;
34
+ attribute float instanceNextTimestamps;
35
+ varying float vTime;
36
+ `,
37
+ // Timestamp of the vertex
38
+ 'vs:#main-end': `\
39
+ vTime = instanceTimestamps + (instanceNextTimestamps - instanceTimestamps) * vPathPosition.y / vPathLength;
40
+ `,
41
+ 'fs:#decl': `\
42
+ uniform bool fadeTrail;
43
+ uniform float trailLength;
44
+ uniform float currentTime;
45
+ varying float vTime;
46
+ `,
47
+ // Drop the segments outside of the time window
48
+ 'fs:#main-start': `\
49
+ if(vTime > currentTime || (fadeTrail && (vTime < currentTime - trailLength))) {
50
+ discard;
51
+ }
52
+ `,
53
+ // Fade the color (currentTime - 100%, end of trail - 0%)
54
+ 'fs:DECKGL_FILTER_COLOR': `\
55
+ if(fadeTrail) {
56
+ color.a *= 1.0 - (currentTime - vTime) / trailLength;
57
+ }
58
+ `
59
+ };
60
+ return shaders;
61
+ }
62
+ initializeState() {
63
+ super.initializeState();
64
+ const attributeManager = this.getAttributeManager();
65
+ attributeManager.addInstanced({
66
+ timestamps: {
67
+ size: 1,
68
+ accessor: 'getTimestamps',
69
+ shaderAttributes: {
70
+ instanceTimestamps: {
71
+ vertexOffset: 0
72
+ },
73
+ instanceNextTimestamps: {
74
+ vertexOffset: 1
75
+ }
76
+ }
77
+ }
78
+ });
79
+ }
80
+ draw(params) {
81
+ const { fadeTrail, trailLength, currentTime } = this.props;
82
+ params.uniforms = {
83
+ ...params.uniforms,
84
+ fadeTrail,
85
+ trailLength,
86
+ currentTime
87
+ };
88
+ super.draw(params);
89
+ }
90
+ }
91
+ TripsLayer.layerName = 'TripsLayer';
92
+ TripsLayer.defaultProps = defaultProps;