@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.
- package/dist/dist.dev.js +1633 -1615
- package/dist/es5/mesh-layer/mesh-layer.js +21 -2
- package/dist/es5/mesh-layer/mesh-layer.js.map +1 -1
- package/dist/es5/tile-layer/tile-layer.js.map +1 -1
- package/dist/esm/mesh-layer/mesh-layer.js +20 -2
- package/dist/esm/mesh-layer/mesh-layer.js.map +1 -1
- package/dist/esm/tile-layer/tile-layer.js.map +1 -1
- package/dist.min.js +1 -1
- package/package.json +2 -2
- package/src/mesh-layer/mesh-layer.ts +17 -3
- package/src/tile-layer/tile-layer.ts +1 -1
- package/typed/geo-cell-layer/GeoCellLayer.js +49 -0
- package/typed/great-circle-layer/great-circle-layer.js +29 -0
- package/typed/h3-layers/h3-cluster-layer.js +33 -0
- package/typed/h3-layers/h3-hexagon-layer.js +251 -0
- package/typed/index.js +33 -0
- package/typed/mesh-layer/mesh-layer-fragment.glsl.js +55 -0
- package/typed/mesh-layer/mesh-layer-vertex.glsl.js +80 -0
- package/typed/mesh-layer/mesh-layer.d.ts +2 -1
- package/typed/mesh-layer/mesh-layer.d.ts.map +1 -1
- package/typed/mesh-layer/mesh-layer.js +110 -0
- package/typed/mvt-layer/coordinate-transform.js +41 -0
- package/typed/mvt-layer/find-index-binary.js +96 -0
- package/typed/mvt-layer/mvt-layer.js +297 -0
- package/typed/quadkey-layer/quadkey-layer.js +18 -0
- package/typed/quadkey-layer/quadkey-utils.js +26 -0
- package/typed/s2-layer/s2-geometry.js +123 -0
- package/typed/s2-layer/s2-layer.js +37 -0
- package/typed/s2-layer/s2-utils.js +88 -0
- package/typed/terrain-layer/terrain-layer.js +226 -0
- package/typed/tile-3d-layer/tile-3d-layer.js +294 -0
- package/typed/tile-layer/tile-2d-header.js +113 -0
- package/typed/tile-layer/tile-2d-traversal.js +181 -0
- package/typed/tile-layer/tile-layer.d.ts +1 -1
- package/typed/tile-layer/tile-layer.d.ts.map +1 -1
- package/typed/tile-layer/tile-layer.js +192 -0
- package/typed/tile-layer/tileset-2d.js +399 -0
- package/typed/tile-layer/types.js +1 -0
- package/typed/tile-layer/utils.js +197 -0
- package/typed/trips-layer/trips-layer.js +92 -0
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@deck.gl/geo-layers",
|
|
3
3
|
"description": "deck.gl layers supporting geospatial use cases and GIS formats",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "8.8.
|
|
5
|
+
"version": "8.8.2",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"@loaders.gl/core": "^3.0.0",
|
|
55
55
|
"@luma.gl/core": "^8.0.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "17d768baed9e2149d3b62863e9db2b9d23bbf5ba"
|
|
58
58
|
}
|
|
@@ -3,7 +3,7 @@ import {GLTFMaterialParser} from '@luma.gl/experimental';
|
|
|
3
3
|
import {Model, pbr} from '@luma.gl/core';
|
|
4
4
|
import GL from '@luma.gl/constants';
|
|
5
5
|
import type {MeshAttribute, MeshAttributes} from '@loaders.gl/schema';
|
|
6
|
-
import type {UpdateParameters, DefaultProps} from '@deck.gl/core';
|
|
6
|
+
import type {UpdateParameters, DefaultProps, LayerContext} from '@deck.gl/core';
|
|
7
7
|
import {SimpleMeshLayer, SimpleMeshLayerProps} from '@deck.gl/mesh-layers';
|
|
8
8
|
|
|
9
9
|
import vs from './mesh-layer-vertex.glsl';
|
|
@@ -102,6 +102,8 @@ export default class MeshLayer<DataT = any, ExtraProps = {}> extends SimpleMeshL
|
|
|
102
102
|
protected getModel(mesh: Mesh): Model {
|
|
103
103
|
const {id, pbrMaterial} = this.props;
|
|
104
104
|
const materialParser = this.parseMaterial(pbrMaterial, mesh);
|
|
105
|
+
// Keep material parser to explicitly remove textures
|
|
106
|
+
this.setState({materialParser});
|
|
105
107
|
const shaders = this.getShaders();
|
|
106
108
|
validateGeometryAttributes(mesh.attributes);
|
|
107
109
|
const model = new Model(this.context.gl, {
|
|
@@ -125,6 +127,8 @@ export default class MeshLayer<DataT = any, ExtraProps = {}> extends SimpleMeshL
|
|
|
125
127
|
if (model) {
|
|
126
128
|
const {mesh} = this.props;
|
|
127
129
|
const materialParser = this.parseMaterial(pbrMaterial, mesh);
|
|
130
|
+
// Keep material parser to explicitly remove textures
|
|
131
|
+
this.setState({materialParser});
|
|
128
132
|
model.setUniforms(materialParser.uniforms);
|
|
129
133
|
}
|
|
130
134
|
}
|
|
@@ -133,7 +137,11 @@ export default class MeshLayer<DataT = any, ExtraProps = {}> extends SimpleMeshL
|
|
|
133
137
|
const unlit = Boolean(
|
|
134
138
|
pbrMaterial.pbrMetallicRoughness && pbrMaterial.pbrMetallicRoughness.baseColorTexture
|
|
135
139
|
);
|
|
136
|
-
|
|
140
|
+
|
|
141
|
+
// @ts-expect-error - Need to add delete method to the luma gltf-material-parser.d.ts
|
|
142
|
+
this.state.materialParser?.delete();
|
|
143
|
+
|
|
144
|
+
return new GLTFMaterialParser(this.context.gl, {
|
|
137
145
|
attributes: {NORMAL: mesh.attributes.normals, TEXCOORD_0: mesh.attributes.texCoords},
|
|
138
146
|
material: {unlit, ...pbrMaterial},
|
|
139
147
|
pbrDebug: false,
|
|
@@ -141,7 +149,6 @@ export default class MeshLayer<DataT = any, ExtraProps = {}> extends SimpleMeshL
|
|
|
141
149
|
lights: true,
|
|
142
150
|
useTangents: false
|
|
143
151
|
});
|
|
144
|
-
return materialParser;
|
|
145
152
|
}
|
|
146
153
|
|
|
147
154
|
calculateFeatureIdsPickingColors(attribute) {
|
|
@@ -160,4 +167,11 @@ export default class MeshLayer<DataT = any, ExtraProps = {}> extends SimpleMeshL
|
|
|
160
167
|
|
|
161
168
|
attribute.value = value;
|
|
162
169
|
}
|
|
170
|
+
|
|
171
|
+
finalizeState(context: LayerContext) {
|
|
172
|
+
super.finalizeState(context);
|
|
173
|
+
// @ts-expect-error - Need to add delete method to the luma gltf-material-parser.d.ts
|
|
174
|
+
this.state.materialParser?.delete();
|
|
175
|
+
this.setState({materialParser: null});
|
|
176
|
+
}
|
|
163
177
|
}
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
_flatten as flatten
|
|
12
12
|
} from '@deck.gl/core';
|
|
13
13
|
import {GeoJsonLayer} from '@deck.gl/layers';
|
|
14
|
-
import {LayersList} from '
|
|
14
|
+
import {LayersList} from '@deck.gl/core';
|
|
15
15
|
import Tile2DHeader from './tile-2d-header';
|
|
16
16
|
|
|
17
17
|
import Tileset2D, {RefinementStrategy, STRATEGY_DEFAULT, Tileset2DProps} from './tileset-2d';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { CompositeLayer } from '@deck.gl/core';
|
|
2
|
+
import { PolygonLayer } from '@deck.gl/layers';
|
|
3
|
+
const defaultProps = {
|
|
4
|
+
...PolygonLayer.defaultProps
|
|
5
|
+
};
|
|
6
|
+
export default class GeoCellLayer extends CompositeLayer {
|
|
7
|
+
/** Implement to generate props to create geometry. */
|
|
8
|
+
indexToBounds() {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
renderLayers() {
|
|
12
|
+
// Rendering props underlying layer
|
|
13
|
+
const { elevationScale, extruded, wireframe, filled, stroked, lineWidthUnits, lineWidthScale, lineWidthMinPixels, lineWidthMaxPixels, lineJointRounded, lineMiterLimit, lineDashJustified, getElevation, getFillColor, getLineColor, getLineWidth } = this.props;
|
|
14
|
+
// Accessor props for underlying layers
|
|
15
|
+
const { updateTriggers, material, transitions } = this.props;
|
|
16
|
+
// Filled Polygon Layer
|
|
17
|
+
const CellLayer = this.getSubLayerClass('cell', PolygonLayer);
|
|
18
|
+
return new CellLayer({
|
|
19
|
+
filled,
|
|
20
|
+
wireframe,
|
|
21
|
+
extruded,
|
|
22
|
+
elevationScale,
|
|
23
|
+
stroked,
|
|
24
|
+
lineWidthUnits,
|
|
25
|
+
lineWidthScale,
|
|
26
|
+
lineWidthMinPixels,
|
|
27
|
+
lineWidthMaxPixels,
|
|
28
|
+
lineJointRounded,
|
|
29
|
+
lineMiterLimit,
|
|
30
|
+
lineDashJustified,
|
|
31
|
+
material,
|
|
32
|
+
transitions,
|
|
33
|
+
getElevation,
|
|
34
|
+
getFillColor,
|
|
35
|
+
getLineColor,
|
|
36
|
+
getLineWidth
|
|
37
|
+
}, this.getSubLayerProps({
|
|
38
|
+
id: 'cell',
|
|
39
|
+
updateTriggers: updateTriggers && {
|
|
40
|
+
getElevation: updateTriggers.getElevation,
|
|
41
|
+
getFillColor: updateTriggers.getFillColor,
|
|
42
|
+
getLineColor: updateTriggers.getLineColor,
|
|
43
|
+
getLineWidth: updateTriggers.getLineWidth
|
|
44
|
+
}
|
|
45
|
+
}), this.indexToBounds());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
GeoCellLayer.layerName = 'GeoCellLayer';
|
|
49
|
+
GeoCellLayer.defaultProps = defaultProps;
|
|
@@ -0,0 +1,29 @@
|
|
|
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 { ArcLayer } from '@deck.gl/layers';
|
|
21
|
+
// This layer has been merged into the core ArcLayer
|
|
22
|
+
// Keeping for backward-compatibility
|
|
23
|
+
export default class GreatCircleLayer extends ArcLayer {
|
|
24
|
+
}
|
|
25
|
+
GreatCircleLayer.layerName = 'GreatCircleLayer';
|
|
26
|
+
GreatCircleLayer.defaultProps = {
|
|
27
|
+
getHeight: { type: 'accessor', value: 0 },
|
|
28
|
+
greatCircle: true
|
|
29
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { h3SetToMultiPolygon } from 'h3-js';
|
|
2
|
+
import { createIterable } from '@deck.gl/core';
|
|
3
|
+
import GeoCellLayer from '../geo-cell-layer/GeoCellLayer';
|
|
4
|
+
const defaultProps = {
|
|
5
|
+
getHexagons: { type: 'accessor', value: d => d.hexagons }
|
|
6
|
+
};
|
|
7
|
+
export default class H3ClusterLayer extends GeoCellLayer {
|
|
8
|
+
updateState({ props, oldProps, changeFlags }) {
|
|
9
|
+
if (changeFlags.dataChanged ||
|
|
10
|
+
(changeFlags.updateTriggers && changeFlags.updateTriggers.getHexagons)) {
|
|
11
|
+
const { data, getHexagons } = props;
|
|
12
|
+
const polygons = [];
|
|
13
|
+
const { iterable, objectInfo } = createIterable(data);
|
|
14
|
+
for (const object of iterable) {
|
|
15
|
+
objectInfo.index++;
|
|
16
|
+
const hexagons = getHexagons(object, objectInfo);
|
|
17
|
+
const multiPolygon = h3SetToMultiPolygon(hexagons, true);
|
|
18
|
+
for (const polygon of multiPolygon) {
|
|
19
|
+
polygons.push(this.getSubLayerRow({ polygon }, object, objectInfo.index));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
this.setState({ polygons });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
indexToBounds() {
|
|
26
|
+
return {
|
|
27
|
+
data: this.state.polygons,
|
|
28
|
+
getPolygon: d => d.polygon
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
H3ClusterLayer.defaultProps = defaultProps;
|
|
33
|
+
H3ClusterLayer.layerName = 'H3ClusterLayer';
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { h3ToGeoBoundary, h3GetResolution, h3ToGeo, geoToH3, h3IsPentagon, h3Distance, edgeLength, UNITS } from 'h3-js';
|
|
2
|
+
import { lerp } from '@math.gl/core';
|
|
3
|
+
import { CompositeLayer, createIterable } from '@deck.gl/core';
|
|
4
|
+
import { ColumnLayer, PolygonLayer } from '@deck.gl/layers';
|
|
5
|
+
// There is a cost to updating the instanced geometries when using highPrecision: false
|
|
6
|
+
// This constant defines the distance between two hexagons that leads to "significant
|
|
7
|
+
// distortion." Smaller value makes the column layer more sensitive to viewport change.
|
|
8
|
+
const UPDATE_THRESHOLD_KM = 10;
|
|
9
|
+
// normalize longitudes w.r.t center (refLng), when not provided first vertex
|
|
10
|
+
export function normalizeLongitudes(vertices, refLng) {
|
|
11
|
+
refLng = refLng === undefined ? vertices[0][0] : refLng;
|
|
12
|
+
for (const pt of vertices) {
|
|
13
|
+
const deltaLng = pt[0] - refLng;
|
|
14
|
+
if (deltaLng > 180) {
|
|
15
|
+
pt[0] -= 360;
|
|
16
|
+
}
|
|
17
|
+
else if (deltaLng < -180) {
|
|
18
|
+
pt[0] += 360;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// scale polygon vertices w.r.t center (hexId)
|
|
23
|
+
export function scalePolygon(hexId, vertices, factor) {
|
|
24
|
+
const [lat, lng] = h3ToGeo(hexId);
|
|
25
|
+
const actualCount = vertices.length;
|
|
26
|
+
// normalize with respect to center
|
|
27
|
+
normalizeLongitudes(vertices, lng);
|
|
28
|
+
// `h3ToGeoBoundary` returns same array object for first and last vertex (closed polygon),
|
|
29
|
+
// if so skip scaling the last vertex
|
|
30
|
+
const vertexCount = vertices[0] === vertices[actualCount - 1] ? actualCount - 1 : actualCount;
|
|
31
|
+
for (let i = 0; i < vertexCount; i++) {
|
|
32
|
+
vertices[i][0] = lerp(lng, vertices[i][0], factor);
|
|
33
|
+
vertices[i][1] = lerp(lat, vertices[i][1], factor);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function getHexagonCentroid(getHexagon, object, objectInfo) {
|
|
37
|
+
const hexagonId = getHexagon(object, objectInfo);
|
|
38
|
+
const [lat, lng] = h3ToGeo(hexagonId);
|
|
39
|
+
return [lng, lat];
|
|
40
|
+
}
|
|
41
|
+
function h3ToPolygon(hexId, coverage = 1, flatten) {
|
|
42
|
+
const vertices = h3ToGeoBoundary(hexId, true);
|
|
43
|
+
if (coverage !== 1) {
|
|
44
|
+
// scale and normalize vertices w.r.t to center
|
|
45
|
+
scalePolygon(hexId, vertices, coverage);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// normalize w.r.t to start vertex
|
|
49
|
+
normalizeLongitudes(vertices);
|
|
50
|
+
}
|
|
51
|
+
if (flatten) {
|
|
52
|
+
const positions = new Float64Array(vertices.length * 2);
|
|
53
|
+
let i = 0;
|
|
54
|
+
for (const pt of vertices) {
|
|
55
|
+
positions[i++] = pt[0];
|
|
56
|
+
positions[i++] = pt[1];
|
|
57
|
+
}
|
|
58
|
+
return positions;
|
|
59
|
+
}
|
|
60
|
+
return vertices;
|
|
61
|
+
}
|
|
62
|
+
function mergeTriggers(getHexagon, coverage) {
|
|
63
|
+
let trigger;
|
|
64
|
+
if (getHexagon === undefined || getHexagon === null) {
|
|
65
|
+
trigger = coverage;
|
|
66
|
+
}
|
|
67
|
+
else if (typeof getHexagon === 'object') {
|
|
68
|
+
trigger = { ...getHexagon, coverage };
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
trigger = { getHexagon, coverage };
|
|
72
|
+
}
|
|
73
|
+
return trigger;
|
|
74
|
+
}
|
|
75
|
+
const defaultProps = {
|
|
76
|
+
...PolygonLayer.defaultProps,
|
|
77
|
+
highPrecision: 'auto',
|
|
78
|
+
coverage: { type: 'number', min: 0, max: 1, value: 1 },
|
|
79
|
+
centerHexagon: null,
|
|
80
|
+
getHexagon: { type: 'accessor', value: x => x.hexagon },
|
|
81
|
+
extruded: true
|
|
82
|
+
};
|
|
83
|
+
// not supported
|
|
84
|
+
delete defaultProps.getLineDashArray;
|
|
85
|
+
/**
|
|
86
|
+
* A subclass of HexagonLayer that uses H3 hexagonIds in data objects
|
|
87
|
+
* rather than centroid lat/longs. The shape of each hexagon is determined
|
|
88
|
+
* based on a single "center" hexagon, which can be selected by passing in
|
|
89
|
+
* a center lat/lon pair. If not provided, the map center will be used.
|
|
90
|
+
*
|
|
91
|
+
* Also sets the `hexagonId` field in the onHover/onClick callback's info
|
|
92
|
+
* objects. Since this is calculated using math, hexagonId will be present
|
|
93
|
+
* even when no corresponding hexagon is in the data set. You can check
|
|
94
|
+
* index !== -1 to see if picking matches an actual object.
|
|
95
|
+
*/
|
|
96
|
+
export default class H3HexagonLayer extends CompositeLayer {
|
|
97
|
+
shouldUpdateState({ changeFlags }) {
|
|
98
|
+
return this._shouldUseHighPrecision()
|
|
99
|
+
? changeFlags.propsOrDataChanged
|
|
100
|
+
: changeFlags.somethingChanged;
|
|
101
|
+
}
|
|
102
|
+
updateState({ props, oldProps, changeFlags }) {
|
|
103
|
+
if (props.highPrecision !== true &&
|
|
104
|
+
(changeFlags.dataChanged ||
|
|
105
|
+
(changeFlags.updateTriggers && changeFlags.updateTriggers.getHexagon))) {
|
|
106
|
+
const dataProps = this._calculateH3DataProps(props);
|
|
107
|
+
this.setState(dataProps);
|
|
108
|
+
}
|
|
109
|
+
this._updateVertices(this.context.viewport);
|
|
110
|
+
}
|
|
111
|
+
_calculateH3DataProps(props) {
|
|
112
|
+
let resolution = -1;
|
|
113
|
+
let hasPentagon = false;
|
|
114
|
+
let hasMultipleRes = false;
|
|
115
|
+
const { iterable, objectInfo } = createIterable(props.data);
|
|
116
|
+
for (const object of iterable) {
|
|
117
|
+
objectInfo.index++;
|
|
118
|
+
const hexId = props.getHexagon(object, objectInfo);
|
|
119
|
+
// Take the resolution of the first hex
|
|
120
|
+
const hexResolution = h3GetResolution(hexId);
|
|
121
|
+
if (resolution < 0) {
|
|
122
|
+
resolution = hexResolution;
|
|
123
|
+
if (!props.highPrecision)
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
else if (resolution !== hexResolution) {
|
|
127
|
+
hasMultipleRes = true;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
if (h3IsPentagon(hexId)) {
|
|
131
|
+
hasPentagon = true;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
resolution,
|
|
137
|
+
edgeLengthKM: resolution >= 0 ? edgeLength(resolution, UNITS.km) : 0,
|
|
138
|
+
hasMultipleRes,
|
|
139
|
+
hasPentagon
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
_shouldUseHighPrecision() {
|
|
143
|
+
if (this.props.highPrecision === 'auto') {
|
|
144
|
+
const { resolution, hasPentagon, hasMultipleRes } = this.state;
|
|
145
|
+
const { viewport } = this.context;
|
|
146
|
+
return (viewport.resolution || hasMultipleRes || hasPentagon || (resolution >= 0 && resolution <= 5));
|
|
147
|
+
}
|
|
148
|
+
return this.props.highPrecision;
|
|
149
|
+
}
|
|
150
|
+
_updateVertices(viewport) {
|
|
151
|
+
if (this._shouldUseHighPrecision()) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const { resolution, edgeLengthKM, centerHex } = this.state;
|
|
155
|
+
if (resolution < 0) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const hex = this.props.centerHexagon || geoToH3(viewport.latitude, viewport.longitude, resolution);
|
|
159
|
+
if (centerHex === hex) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (centerHex) {
|
|
163
|
+
const distance = h3Distance(centerHex, hex);
|
|
164
|
+
// h3Distance returns a negative number if the distance could not be computed
|
|
165
|
+
// due to the two indexes very far apart or on opposite sides of a pentagon.
|
|
166
|
+
if (distance >= 0 && distance * edgeLengthKM < UPDATE_THRESHOLD_KM) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const { unitsPerMeter } = viewport.distanceScales;
|
|
171
|
+
let vertices = h3ToPolygon(hex);
|
|
172
|
+
const [centerLat, centerLng] = h3ToGeo(hex);
|
|
173
|
+
const [centerX, centerY] = viewport.projectFlat([centerLng, centerLat]);
|
|
174
|
+
vertices = vertices.map(p => {
|
|
175
|
+
const worldPosition = viewport.projectFlat(p);
|
|
176
|
+
return [
|
|
177
|
+
(worldPosition[0] - centerX) / unitsPerMeter[0],
|
|
178
|
+
(worldPosition[1] - centerY) / unitsPerMeter[1]
|
|
179
|
+
];
|
|
180
|
+
});
|
|
181
|
+
this.setState({ centerHex: hex, vertices });
|
|
182
|
+
}
|
|
183
|
+
renderLayers() {
|
|
184
|
+
return this._shouldUseHighPrecision() ? this._renderPolygonLayer() : this._renderColumnLayer();
|
|
185
|
+
}
|
|
186
|
+
_getForwardProps() {
|
|
187
|
+
const { elevationScale, material, coverage, extruded, wireframe, stroked, filled, lineWidthUnits, lineWidthScale, lineWidthMinPixels, lineWidthMaxPixels, getFillColor, getElevation, getLineColor, getLineWidth, transitions, updateTriggers } = this.props;
|
|
188
|
+
return {
|
|
189
|
+
elevationScale,
|
|
190
|
+
extruded,
|
|
191
|
+
coverage,
|
|
192
|
+
wireframe,
|
|
193
|
+
stroked,
|
|
194
|
+
filled,
|
|
195
|
+
lineWidthUnits,
|
|
196
|
+
lineWidthScale,
|
|
197
|
+
lineWidthMinPixels,
|
|
198
|
+
lineWidthMaxPixels,
|
|
199
|
+
material,
|
|
200
|
+
getElevation,
|
|
201
|
+
getFillColor,
|
|
202
|
+
getLineColor,
|
|
203
|
+
getLineWidth,
|
|
204
|
+
transitions,
|
|
205
|
+
updateTriggers: {
|
|
206
|
+
getFillColor: updateTriggers.getFillColor,
|
|
207
|
+
getElevation: updateTriggers.getElevation,
|
|
208
|
+
getLineColor: updateTriggers.getLineColor,
|
|
209
|
+
getLineWidth: updateTriggers.getLineWidth
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
_renderPolygonLayer() {
|
|
214
|
+
const { data, getHexagon, updateTriggers, coverage } = this.props;
|
|
215
|
+
const SubLayerClass = this.getSubLayerClass('hexagon-cell-hifi', PolygonLayer);
|
|
216
|
+
const forwardProps = this._getForwardProps();
|
|
217
|
+
forwardProps.updateTriggers.getPolygon = mergeTriggers(updateTriggers.getHexagon, coverage);
|
|
218
|
+
return new SubLayerClass(forwardProps, this.getSubLayerProps({
|
|
219
|
+
id: 'hexagon-cell-hifi',
|
|
220
|
+
updateTriggers: forwardProps.updateTriggers
|
|
221
|
+
}), {
|
|
222
|
+
data,
|
|
223
|
+
_normalize: false,
|
|
224
|
+
_windingOrder: 'CCW',
|
|
225
|
+
positionFormat: 'XY',
|
|
226
|
+
getPolygon: (object, objectInfo) => {
|
|
227
|
+
const hexagonId = getHexagon(object, objectInfo);
|
|
228
|
+
return h3ToPolygon(hexagonId, coverage, true);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
_renderColumnLayer() {
|
|
233
|
+
const { data, getHexagon, updateTriggers } = this.props;
|
|
234
|
+
const SubLayerClass = this.getSubLayerClass('hexagon-cell', ColumnLayer);
|
|
235
|
+
const forwardProps = this._getForwardProps();
|
|
236
|
+
forwardProps.updateTriggers.getPosition = updateTriggers.getHexagon;
|
|
237
|
+
return new SubLayerClass(forwardProps, this.getSubLayerProps({
|
|
238
|
+
id: 'hexagon-cell',
|
|
239
|
+
flatShading: true,
|
|
240
|
+
updateTriggers: forwardProps.updateTriggers
|
|
241
|
+
}), {
|
|
242
|
+
data,
|
|
243
|
+
diskResolution: 6,
|
|
244
|
+
radius: 1,
|
|
245
|
+
vertices: this.state.vertices,
|
|
246
|
+
getPosition: getHexagonCentroid.bind(null, getHexagon)
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
H3HexagonLayer.defaultProps = defaultProps;
|
|
251
|
+
H3HexagonLayer.layerName = 'H3HexagonLayer';
|
package/typed/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
/* eslint-disable max-len */
|
|
21
|
+
export { default as GreatCircleLayer } from './great-circle-layer/great-circle-layer';
|
|
22
|
+
export { default as S2Layer } from './s2-layer/s2-layer';
|
|
23
|
+
export { default as QuadkeyLayer } from './quadkey-layer/quadkey-layer';
|
|
24
|
+
export { default as TileLayer } from './tile-layer/tile-layer';
|
|
25
|
+
export { default as TripsLayer } from './trips-layer/trips-layer';
|
|
26
|
+
export { default as H3ClusterLayer } from './h3-layers/h3-cluster-layer';
|
|
27
|
+
export { default as H3HexagonLayer } from './h3-layers/h3-hexagon-layer';
|
|
28
|
+
export { default as Tile3DLayer } from './tile-3d-layer/tile-3d-layer';
|
|
29
|
+
export { default as TerrainLayer } from './terrain-layer/terrain-layer';
|
|
30
|
+
export { default as MVTLayer } from './mvt-layer/mvt-layer';
|
|
31
|
+
export { getURLFromTemplate as _getURLFromTemplate } from './tile-layer/utils';
|
|
32
|
+
export { default as _Tileset2D } from './tile-layer/tileset-2d';
|
|
33
|
+
export { default as _Tile2DHeader } from './tile-layer/tile-2d-header';
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export default `#version 300 es
|
|
2
|
+
#define SHADER_NAME simple-mesh-layer-fs
|
|
3
|
+
|
|
4
|
+
precision highp float;
|
|
5
|
+
|
|
6
|
+
uniform bool hasTexture;
|
|
7
|
+
uniform sampler2D sampler;
|
|
8
|
+
uniform bool flatShading;
|
|
9
|
+
uniform float opacity;
|
|
10
|
+
|
|
11
|
+
in vec2 vTexCoord;
|
|
12
|
+
in vec3 cameraPosition;
|
|
13
|
+
in vec3 normals_commonspace;
|
|
14
|
+
in vec4 position_commonspace;
|
|
15
|
+
in vec4 vColor;
|
|
16
|
+
|
|
17
|
+
out vec4 fragColor;
|
|
18
|
+
|
|
19
|
+
void main(void) {
|
|
20
|
+
|
|
21
|
+
#ifdef MODULE_PBR
|
|
22
|
+
|
|
23
|
+
fragColor = vColor * pbr_filterColor(vec4(0));
|
|
24
|
+
geometry.uv = pbr_vUV;
|
|
25
|
+
fragColor.a *= opacity;
|
|
26
|
+
|
|
27
|
+
#else
|
|
28
|
+
|
|
29
|
+
geometry.uv = vTexCoord;
|
|
30
|
+
|
|
31
|
+
vec3 normal;
|
|
32
|
+
if (flatShading) {
|
|
33
|
+
|
|
34
|
+
// NOTE(Tarek): This is necessary because
|
|
35
|
+
// headless.gl reports the extension as
|
|
36
|
+
// available but does not support it in
|
|
37
|
+
// the shader.
|
|
38
|
+
#ifdef DERIVATIVES_AVAILABLE
|
|
39
|
+
normal = normalize(cross(dFdx(position_commonspace.xyz), dFdy(position_commonspace.xyz)));
|
|
40
|
+
#else
|
|
41
|
+
normal = vec3(0.0, 0.0, 1.0);
|
|
42
|
+
#endif
|
|
43
|
+
} else {
|
|
44
|
+
normal = normals_commonspace;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
vec4 color = hasTexture ? texture(sampler, vTexCoord) : vColor;
|
|
48
|
+
vec3 lightColor = lighting_getLightColor(color.rgb, cameraPosition, position_commonspace.xyz, normal);
|
|
49
|
+
fragColor = vec4(lightColor, color.a * opacity);
|
|
50
|
+
|
|
51
|
+
#endif
|
|
52
|
+
|
|
53
|
+
DECKGL_FILTER_COLOR(fragColor, geometry);
|
|
54
|
+
}
|
|
55
|
+
`;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export default `#version 300 es
|
|
2
|
+
#define SHADER_NAME simple-mesh-layer-vs
|
|
3
|
+
|
|
4
|
+
// Scale the model
|
|
5
|
+
uniform float sizeScale;
|
|
6
|
+
uniform bool composeModelMatrix;
|
|
7
|
+
uniform bool u_pickFeatureIds;
|
|
8
|
+
|
|
9
|
+
// Primitive attributes
|
|
10
|
+
in vec3 positions;
|
|
11
|
+
in vec3 normals;
|
|
12
|
+
in vec3 colors;
|
|
13
|
+
in vec2 texCoords;
|
|
14
|
+
in vec4 uvRegions;
|
|
15
|
+
in vec3 featureIdsPickingColors;
|
|
16
|
+
|
|
17
|
+
// Instance attributes
|
|
18
|
+
in vec4 instanceColors;
|
|
19
|
+
in vec3 instancePickingColors;
|
|
20
|
+
in mat3 instanceModelMatrix;
|
|
21
|
+
|
|
22
|
+
// Outputs to fragment shader
|
|
23
|
+
out vec2 vTexCoord;
|
|
24
|
+
out vec3 cameraPosition;
|
|
25
|
+
out vec3 normals_commonspace;
|
|
26
|
+
out vec4 position_commonspace;
|
|
27
|
+
out vec4 vColor;
|
|
28
|
+
|
|
29
|
+
vec2 applyUVRegion(vec2 uv) {
|
|
30
|
+
#ifdef HAS_UV_REGIONS
|
|
31
|
+
// https://github.com/Esri/i3s-spec/blob/master/docs/1.7/geometryUVRegion.cmn.md
|
|
32
|
+
return fract(uv) * (uvRegions.zw - uvRegions.xy) + uvRegions.xy;
|
|
33
|
+
#else
|
|
34
|
+
return uv;
|
|
35
|
+
#endif
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
void main(void) {
|
|
39
|
+
vec2 uv = applyUVRegion(texCoords);
|
|
40
|
+
geometry.uv = uv;
|
|
41
|
+
|
|
42
|
+
if (u_pickFeatureIds) {
|
|
43
|
+
geometry.pickingColor = featureIdsPickingColors;
|
|
44
|
+
} else {
|
|
45
|
+
geometry.pickingColor = instancePickingColors;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
vTexCoord = uv;
|
|
49
|
+
cameraPosition = project_uCameraPosition;
|
|
50
|
+
vColor = vec4(colors * instanceColors.rgb, instanceColors.a);
|
|
51
|
+
|
|
52
|
+
vec3 pos = (instanceModelMatrix * positions) * sizeScale;
|
|
53
|
+
vec3 projectedPosition = project_position(positions);
|
|
54
|
+
position_commonspace = vec4(projectedPosition, 1.0);
|
|
55
|
+
gl_Position = project_common_position_to_clipspace(position_commonspace);
|
|
56
|
+
|
|
57
|
+
geometry.position = position_commonspace;
|
|
58
|
+
normals_commonspace = project_normal(instanceModelMatrix * normals);
|
|
59
|
+
geometry.normal = normals_commonspace;
|
|
60
|
+
|
|
61
|
+
DECKGL_FILTER_GL_POSITION(gl_Position, geometry);
|
|
62
|
+
|
|
63
|
+
#ifdef MODULE_PBR
|
|
64
|
+
// set PBR data
|
|
65
|
+
pbr_vPosition = geometry.position.xyz;
|
|
66
|
+
#ifdef HAS_NORMALS
|
|
67
|
+
pbr_vNormal = geometry.normal;
|
|
68
|
+
#endif
|
|
69
|
+
|
|
70
|
+
#ifdef HAS_UV
|
|
71
|
+
pbr_vUV = uv;
|
|
72
|
+
#else
|
|
73
|
+
pbr_vUV = vec2(0., 0.);
|
|
74
|
+
#endif
|
|
75
|
+
geometry.uv = pbr_vUV;
|
|
76
|
+
#endif
|
|
77
|
+
|
|
78
|
+
DECKGL_FILTER_COLOR(vColor, geometry);
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
@@ -2,7 +2,7 @@ import type { NumericArray } from '@math.gl/core';
|
|
|
2
2
|
import { GLTFMaterialParser } from '@luma.gl/experimental';
|
|
3
3
|
import { Model } from '@luma.gl/core';
|
|
4
4
|
import type { MeshAttribute, MeshAttributes } from '@loaders.gl/schema';
|
|
5
|
-
import type { UpdateParameters, DefaultProps } from '@deck.gl/core/typed';
|
|
5
|
+
import type { UpdateParameters, DefaultProps, LayerContext } from '@deck.gl/core/typed';
|
|
6
6
|
import { SimpleMeshLayer, SimpleMeshLayerProps } from '@deck.gl/mesh-layers/typed';
|
|
7
7
|
export declare type Mesh = {
|
|
8
8
|
attributes: MeshAttributes;
|
|
@@ -32,6 +32,7 @@ export default class MeshLayer<DataT = any, ExtraProps = {}> extends SimpleMeshL
|
|
|
32
32
|
updatePbrMaterialUniforms(pbrMaterial: any): void;
|
|
33
33
|
parseMaterial(pbrMaterial: any, mesh: any): GLTFMaterialParser;
|
|
34
34
|
calculateFeatureIdsPickingColors(attribute: any): void;
|
|
35
|
+
finalizeState(context: LayerContext): void;
|
|
35
36
|
}
|
|
36
37
|
export {};
|
|
37
38
|
//# sourceMappingURL=mesh-layer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mesh-layer.d.ts","sourceRoot":"","sources":["../../src/mesh-layer/mesh-layer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAChD,OAAO,EAAC,kBAAkB,EAAC,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAC,KAAK,EAAM,MAAM,eAAe,CAAC;AAEzC,OAAO,KAAK,EAAC,aAAa,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AACtE,OAAO,KAAK,EAAC,gBAAgB,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"mesh-layer.d.ts","sourceRoot":"","sources":["../../src/mesh-layer/mesh-layer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAChD,OAAO,EAAC,kBAAkB,EAAC,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAC,KAAK,EAAM,MAAM,eAAe,CAAC;AAEzC,OAAO,KAAK,EAAC,aAAa,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AACtE,OAAO,KAAK,EAAC,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAChF,OAAO,EAAC,eAAe,EAAE,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AAK3E,oBAAY,IAAI,GAAG;IACjB,UAAU,EAAE,cAAc,CAAC;IAC3B,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB,CAAC;AAcF,6CAA6C;AAC7C,oBAAY,cAAc,CAAC,KAAK,GAAG,GAAG,IAAI,eAAe,CAAC,KAAK,CAAC,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;AAE/F,qCAAqC;AACrC,aAAK,eAAe,CAAC,KAAK,IAAI;IAC5B;;OAEG;IACH,WAAW,CAAC,EAAE,GAAG,CAAC;IAElB;;OAEG;IACH,UAAU,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CAClC,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,SAAS,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,GAAG,EAAE,CAAE,SAAQ,eAAe,CAClF,KAAK,EACL,QAAQ,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,GAAG,UAAU,CAC9C;IACC,MAAM,CAAC,SAAS,SAAe;IAC/B,MAAM,CAAC,YAAY,oCAAgB;IAEnC,UAAU;IAOV,eAAe;IAmBf,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,IAAI,CAAC;IAS1C,IAAI,CAAC,IAAI,KAAA;IAeT,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,KAAK;IAuBrC,yBAAyB,CAAC,WAAW,KAAA;IAWrC,aAAa,CAAC,WAAW,KAAA,EAAE,IAAI,KAAA;IAkB/B,gCAAgC,CAAC,SAAS,KAAA;IAiB1C,aAAa,CAAC,OAAO,EAAE,YAAY;CAMpC"}
|