@developmentseed/deck.gl-raster 0.1.0-beta.2 → 0.1.0-beta.4
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 +0 -725
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -141
- package/dist/index.d.ts +5 -142
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -722
- package/dist/index.js.map +1 -1
- package/dist/layer.d.ts +72 -0
- package/dist/layer.d.ts.map +1 -0
- package/dist/layer.js +88 -0
- package/dist/layer.js.map +1 -0
- package/dist/mesh.d.ts +1 -0
- package/dist/mesh.d.ts.map +1 -0
- package/dist/mesh.js +2 -0
- package/dist/mesh.js.map +1 -0
- package/dist/raster-debug-layer.d.ts +51 -0
- package/dist/raster-debug-layer.d.ts.map +1 -0
- package/dist/raster-debug-layer.js +102 -0
- package/dist/raster-debug-layer.js.map +1 -0
- package/dist/raster-layer.d.ts +63 -0
- package/dist/raster-layer.d.ts.map +1 -0
- package/dist/raster-layer.js +102 -0
- package/dist/raster-layer.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/layer.d.ts +1 -0
- package/dist/src/layer.d.ts.map +1 -0
- package/dist/src/layer.js +3 -0
- package/dist/src/layer.js.map +1 -0
- package/dist/src/mesh.d.ts +1 -0
- package/dist/src/mesh.d.ts.map +1 -0
- package/dist/src/mesh.js +2 -0
- package/dist/src/mesh.js.map +1 -0
- package/dist/tests/placeholder.test.d.ts +2 -0
- package/dist/tests/placeholder.test.d.ts.map +1 -0
- package/dist/tests/placeholder.test.js +7 -0
- package/dist/tests/placeholder.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +24 -26
- package/README.md +0 -80
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { CompositeLayer } from "@deck.gl/core";
|
|
2
|
+
import { SimpleMeshLayer } from "@deck.gl/mesh-layers";
|
|
3
|
+
import { RasterReprojector } from "@developmentseed/raster-reproject";
|
|
4
|
+
const DEFAULT_MAX_ERROR = 0.125;
|
|
5
|
+
const defaultProps = {
|
|
6
|
+
maxError: DEFAULT_MAX_ERROR,
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* RasterLayer renders georeferenced raster data with client-side reprojection.
|
|
10
|
+
*
|
|
11
|
+
* This is a composite layer that uses raster-reproject to generate an adaptive mesh
|
|
12
|
+
* that accurately represents the reprojected raster, then renders it using SimpleMeshLayer.
|
|
13
|
+
*/
|
|
14
|
+
export class RasterLayer extends CompositeLayer {
|
|
15
|
+
static layerName = "RasterLayer";
|
|
16
|
+
static defaultProps = defaultProps;
|
|
17
|
+
initializeState() {
|
|
18
|
+
this.setState({});
|
|
19
|
+
}
|
|
20
|
+
updateState(params) {
|
|
21
|
+
super.updateState(params);
|
|
22
|
+
const { props, oldProps, changeFlags } = params;
|
|
23
|
+
// Regenerate mesh if key properties change
|
|
24
|
+
const needsUpdate = Boolean(changeFlags.dataChanged) ||
|
|
25
|
+
props.width !== oldProps.width ||
|
|
26
|
+
props.height !== oldProps.height ||
|
|
27
|
+
props.reprojectionFns !== oldProps.reprojectionFns ||
|
|
28
|
+
props.maxError !== oldProps.maxError;
|
|
29
|
+
if (needsUpdate) {
|
|
30
|
+
this._generateMesh();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
_generateMesh() {
|
|
34
|
+
const { width, height, reprojectionFns, maxError = DEFAULT_MAX_ERROR, } = this.props;
|
|
35
|
+
const reprojector = new RasterReprojector(reprojectionFns, width, height);
|
|
36
|
+
reprojector.run(maxError);
|
|
37
|
+
const { indices, positions, texCoords } = reprojectorToMesh(reprojector);
|
|
38
|
+
this.setState({
|
|
39
|
+
reprojector,
|
|
40
|
+
mesh: {
|
|
41
|
+
positions,
|
|
42
|
+
indices,
|
|
43
|
+
texCoords,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
renderLayers() {
|
|
48
|
+
const { mesh } = this.state;
|
|
49
|
+
const { texture } = this.props;
|
|
50
|
+
if (!mesh) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const { indices, positions, texCoords } = mesh;
|
|
54
|
+
return new SimpleMeshLayer(this.getSubLayerProps({
|
|
55
|
+
id: "raster",
|
|
56
|
+
texture,
|
|
57
|
+
// Dummy data because we're only rendering _one_ instance of this mesh
|
|
58
|
+
// https://github.com/visgl/deck.gl/blob/93111b667b919148da06ff1918410cf66381904f/modules/geo-layers/src/terrain-layer/terrain-layer.ts#L241
|
|
59
|
+
data: [1],
|
|
60
|
+
mesh: {
|
|
61
|
+
indices: { value: indices, size: 1 },
|
|
62
|
+
attributes: {
|
|
63
|
+
POSITION: {
|
|
64
|
+
value: positions,
|
|
65
|
+
size: 3,
|
|
66
|
+
},
|
|
67
|
+
TEXCOORD_0: {
|
|
68
|
+
value: texCoords,
|
|
69
|
+
size: 2,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
// We're only rendering a single mesh, without instancing
|
|
74
|
+
// https://github.com/visgl/deck.gl/blob/93111b667b919148da06ff1918410cf66381904f/modules/geo-layers/src/terrain-layer/terrain-layer.ts#L244
|
|
75
|
+
_instanced: false,
|
|
76
|
+
// Dummy accessors for the dummy data
|
|
77
|
+
// We place our mesh at the coordinate origin
|
|
78
|
+
getPosition: [0, 0, 0],
|
|
79
|
+
// We give a white color to turn off color mixing with the texture
|
|
80
|
+
getColor: [255, 255, 255],
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function reprojectorToMesh(reprojector) {
|
|
85
|
+
const numVertices = reprojector.uvs.length / 2;
|
|
86
|
+
const positions = new Float32Array(numVertices * 3);
|
|
87
|
+
const texCoords = new Float32Array(reprojector.uvs);
|
|
88
|
+
for (let i = 0; i < numVertices; i++) {
|
|
89
|
+
positions[i * 3] = reprojector.exactOutputPositions[i * 2];
|
|
90
|
+
positions[i * 3 + 1] = reprojector.exactOutputPositions[i * 2 + 1];
|
|
91
|
+
// z (flat on the ground)
|
|
92
|
+
positions[i * 3 + 2] = 0;
|
|
93
|
+
}
|
|
94
|
+
// TODO: Consider using 16-bit indices if the mesh is small enough
|
|
95
|
+
const indices = new Uint32Array(reprojector.triangles);
|
|
96
|
+
return {
|
|
97
|
+
indices,
|
|
98
|
+
positions,
|
|
99
|
+
texCoords,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=raster-layer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raster-layer.js","sourceRoot":"","sources":["../src/raster-layer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAwChC,MAAM,YAAY,GAAG;IACnB,QAAQ,EAAE,iBAAiB;CAC5B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,OAAO,WAAY,SAAQ,cAAgC;IAC/D,MAAM,CAAU,SAAS,GAAG,aAAa,CAAC;IAC1C,MAAM,CAAU,YAAY,GAAG,YAAY,CAAC;IAWnC,eAAe;QACtB,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACpB,CAAC;IAEQ,WAAW,CAAC,MAA8B;QACjD,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAE1B,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;QAEhD,2CAA2C;QAC3C,MAAM,WAAW,GACf,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC;YAChC,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK;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QACL,OAAO;QACP,SAAS;QACT,SAAS;KACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layer.d.ts","sourceRoot":"","sources":["../../src/layer.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layer.js","sourceRoot":"","sources":["../../src/layer.ts"],"names":[],"mappings":";AAAA,qDAAqD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=mesh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mesh.d.ts","sourceRoot":"","sources":["../../src/mesh.ts"],"names":[],"mappings":""}
|
package/dist/src/mesh.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mesh.js","sourceRoot":"","sources":["../../src/mesh.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placeholder.test.d.ts","sourceRoot":"","sources":["../../tests/placeholder.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placeholder.test.js","sourceRoot":"","sources":["../../tests/placeholder.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAC1B,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|