@deck.gl/extensions 9.0.0-beta.2 → 9.0.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.
Files changed (244) hide show
  1. package/dist/brushing/brushing-extension.js +80 -0
  2. package/{typed → dist}/brushing/shader-module.d.ts +1 -1
  3. package/{typed → dist}/brushing/shader-module.d.ts.map +1 -1
  4. package/dist/{esm/brushing → brushing}/shader-module.js +24 -30
  5. package/dist/clip/clip-extension.js +117 -0
  6. package/{typed → dist}/collision-filter/collision-filter-effect.d.ts.map +1 -1
  7. package/dist/collision-filter/collision-filter-effect.js +193 -0
  8. package/dist/collision-filter/collision-filter-extension.js +49 -0
  9. package/{typed → dist}/collision-filter/collision-filter-pass.d.ts.map +1 -1
  10. package/dist/collision-filter/collision-filter-pass.js +25 -0
  11. package/dist/{esm/collision-filter → collision-filter}/shader-module.js +17 -24
  12. package/dist/data-filter/aggregator.js +104 -0
  13. package/{typed → dist}/data-filter/data-filter-extension.d.ts +36 -5
  14. package/dist/data-filter/data-filter-extension.d.ts.map +1 -0
  15. package/dist/data-filter/data-filter-extension.js +243 -0
  16. package/{typed → dist}/data-filter/shader-module.d.ts +1 -1
  17. package/dist/data-filter/shader-module.d.ts.map +1 -0
  18. package/dist/data-filter/shader-module.js +187 -0
  19. package/dist/dist.dev.js +1847 -13033
  20. package/dist/fill-style/fill-style-extension.js +118 -0
  21. package/dist/{esm/fill-style → fill-style}/shaders.glsl.js +37 -43
  22. package/dist/fp64/fp64-extension.js +35 -0
  23. package/dist/{esm/fp64 → fp64}/project64.glsl.js +19 -1
  24. package/dist/fp64/project64.js +50 -0
  25. package/dist/index.cjs +2814 -0
  26. package/dist/index.cjs.map +7 -0
  27. package/dist/index.d.ts +19 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +11 -0
  30. package/{typed → dist}/mask/mask-effect.d.ts +1 -1
  31. package/dist/mask/mask-effect.d.ts.map +1 -0
  32. package/dist/mask/mask-effect.js +194 -0
  33. package/dist/mask/mask-extension.js +57 -0
  34. package/{typed → dist}/mask/mask-pass.d.ts.map +1 -1
  35. package/dist/mask/mask-pass.js +44 -0
  36. package/dist/{esm/mask → mask}/shader-module.js +18 -21
  37. package/dist/path-style/path-style-extension.js +111 -0
  38. package/dist/{esm/path-style → path-style}/shaders.glsl.js +20 -13
  39. package/{typed → dist}/terrain/height-map-builder.d.ts +1 -1
  40. package/dist/terrain/height-map-builder.d.ts.map +1 -0
  41. package/dist/terrain/height-map-builder.js +104 -0
  42. package/{typed → dist}/terrain/shader-module.d.ts +2 -2
  43. package/dist/terrain/shader-module.d.ts.map +1 -0
  44. package/dist/terrain/shader-module.js +139 -0
  45. package/{typed → dist}/terrain/terrain-cover.d.ts +1 -1
  46. package/dist/terrain/terrain-cover.d.ts.map +1 -0
  47. package/dist/terrain/terrain-cover.js +187 -0
  48. package/{typed → dist}/terrain/terrain-effect.d.ts +1 -1
  49. package/dist/terrain/terrain-effect.d.ts.map +1 -0
  50. package/dist/terrain/terrain-effect.js +184 -0
  51. package/dist/terrain/terrain-extension.js +44 -0
  52. package/{typed → dist}/terrain/terrain-pass.d.ts +2 -2
  53. package/dist/terrain/terrain-pass.d.ts.map +1 -0
  54. package/dist/terrain/terrain-pass.js +61 -0
  55. package/{typed → dist}/terrain/terrain-picking-pass.d.ts +1 -1
  56. package/dist/terrain/terrain-picking-pass.d.ts.map +1 -0
  57. package/dist/terrain/terrain-picking-pass.js +66 -0
  58. package/dist/terrain/utils.js +21 -0
  59. package/{typed → dist}/utils/debug.d.ts.map +1 -1
  60. package/dist/utils/debug.js +50 -0
  61. package/dist/utils/projection-utils.js +153 -0
  62. package/dist.min.js +104 -208
  63. package/package.json +19 -12
  64. package/src/collision-filter/collision-filter-effect.ts +12 -8
  65. package/src/collision-filter/collision-filter-pass.ts +1 -3
  66. package/src/data-filter/data-filter-extension.ts +136 -29
  67. package/src/data-filter/shader-module.ts +31 -3
  68. package/src/mask/mask-effect.ts +0 -1
  69. package/src/mask/mask-pass.ts +1 -3
  70. package/src/terrain/terrain-effect.ts +8 -2
  71. package/src/terrain/terrain-pass.ts +2 -5
  72. package/src/terrain/terrain-picking-pass.ts +1 -3
  73. package/src/utils/debug.ts +1 -2
  74. package/dist/es5/brushing/brushing-extension.js +0 -108
  75. package/dist/es5/brushing/brushing-extension.js.map +0 -1
  76. package/dist/es5/brushing/shader-module.js +0 -50
  77. package/dist/es5/brushing/shader-module.js.map +0 -1
  78. package/dist/es5/clip/clip-extension.js +0 -98
  79. package/dist/es5/clip/clip-extension.js.map +0 -1
  80. package/dist/es5/collision-filter/collision-filter-effect.js +0 -294
  81. package/dist/es5/collision-filter/collision-filter-effect.js.map +0 -1
  82. package/dist/es5/collision-filter/collision-filter-extension.js +0 -109
  83. package/dist/es5/collision-filter/collision-filter-extension.js.map +0 -1
  84. package/dist/es5/collision-filter/collision-filter-pass.js +0 -79
  85. package/dist/es5/collision-filter/collision-filter-pass.js.map +0 -1
  86. package/dist/es5/collision-filter/shader-module.js +0 -39
  87. package/dist/es5/collision-filter/shader-module.js.map +0 -1
  88. package/dist/es5/data-filter/aggregator.js +0 -79
  89. package/dist/es5/data-filter/aggregator.js.map +0 -1
  90. package/dist/es5/data-filter/data-filter-extension.js +0 -236
  91. package/dist/es5/data-filter/data-filter-extension.js.map +0 -1
  92. package/dist/es5/data-filter/shader-module.js +0 -122
  93. package/dist/es5/data-filter/shader-module.js.map +0 -1
  94. package/dist/es5/fill-style/fill-style-extension.js +0 -190
  95. package/dist/es5/fill-style/fill-style-extension.js.map +0 -1
  96. package/dist/es5/fill-style/shaders.glsl.js +0 -59
  97. package/dist/es5/fill-style/shaders.glsl.js.map +0 -1
  98. package/dist/es5/fp64/fp64-extension.js +0 -55
  99. package/dist/es5/fp64/fp64-extension.js.map +0 -1
  100. package/dist/es5/fp64/project64.glsl.js +0 -9
  101. package/dist/es5/fp64/project64.glsl.js.map +0 -1
  102. package/dist/es5/fp64/project64.js +0 -52
  103. package/dist/es5/fp64/project64.js.map +0 -1
  104. package/dist/es5/index.js +0 -88
  105. package/dist/es5/index.js.map +0 -1
  106. package/dist/es5/mask/mask-effect.js +0 -279
  107. package/dist/es5/mask/mask-effect.js.map +0 -1
  108. package/dist/es5/mask/mask-extension.js +0 -113
  109. package/dist/es5/mask/mask-extension.js.map +0 -1
  110. package/dist/es5/mask/mask-pass.js +0 -106
  111. package/dist/es5/mask/mask-pass.js.map +0 -1
  112. package/dist/es5/mask/shader-module.js +0 -38
  113. package/dist/es5/mask/shader-module.js.map +0 -1
  114. package/dist/es5/path-style/path-style-extension.js +0 -169
  115. package/dist/es5/path-style/path-style-extension.js.map +0 -1
  116. package/dist/es5/path-style/shaders.glsl.js +0 -25
  117. package/dist/es5/path-style/shaders.glsl.js.map +0 -1
  118. package/dist/es5/terrain/height-map-builder.js +0 -111
  119. package/dist/es5/terrain/height-map-builder.js.map +0 -1
  120. package/dist/es5/terrain/shader-module.js +0 -86
  121. package/dist/es5/terrain/shader-module.js.map +0 -1
  122. package/dist/es5/terrain/terrain-cover.js +0 -256
  123. package/dist/es5/terrain/terrain-cover.js.map +0 -1
  124. package/dist/es5/terrain/terrain-effect.js +0 -326
  125. package/dist/es5/terrain/terrain-effect.js.map +0 -1
  126. package/dist/es5/terrain/terrain-extension.js +0 -94
  127. package/dist/es5/terrain/terrain-extension.js.map +0 -1
  128. package/dist/es5/terrain/terrain-pass.js +0 -121
  129. package/dist/es5/terrain/terrain-pass.js.map +0 -1
  130. package/dist/es5/terrain/terrain-picking-pass.js +0 -124
  131. package/dist/es5/terrain/terrain-picking-pass.js.map +0 -1
  132. package/dist/es5/terrain/utils.js +0 -35
  133. package/dist/es5/terrain/utils.js.map +0 -1
  134. package/dist/es5/utils/debug.js +0 -71
  135. package/dist/es5/utils/debug.js.map +0 -1
  136. package/dist/es5/utils/projection-utils.js +0 -168
  137. package/dist/es5/utils/projection-utils.js.map +0 -1
  138. package/dist/esm/brushing/brushing-extension.js +0 -68
  139. package/dist/esm/brushing/brushing-extension.js.map +0 -1
  140. package/dist/esm/brushing/shader-module.js.map +0 -1
  141. package/dist/esm/clip/clip-extension.js +0 -86
  142. package/dist/esm/clip/clip-extension.js.map +0 -1
  143. package/dist/esm/collision-filter/collision-filter-effect.js +0 -246
  144. package/dist/esm/collision-filter/collision-filter-effect.js.map +0 -1
  145. package/dist/esm/collision-filter/collision-filter-extension.js +0 -75
  146. package/dist/esm/collision-filter/collision-filter-extension.js.map +0 -1
  147. package/dist/esm/collision-filter/collision-filter-pass.js +0 -32
  148. package/dist/esm/collision-filter/collision-filter-pass.js.map +0 -1
  149. package/dist/esm/collision-filter/shader-module.js.map +0 -1
  150. package/dist/esm/data-filter/aggregator.js +0 -102
  151. package/dist/esm/data-filter/aggregator.js.map +0 -1
  152. package/dist/esm/data-filter/data-filter-extension.js +0 -189
  153. package/dist/esm/data-filter/data-filter-extension.js.map +0 -1
  154. package/dist/esm/data-filter/shader-module.js +0 -164
  155. package/dist/esm/data-filter/shader-module.js.map +0 -1
  156. package/dist/esm/fill-style/fill-style-extension.js +0 -156
  157. package/dist/esm/fill-style/fill-style-extension.js.map +0 -1
  158. package/dist/esm/fill-style/shaders.glsl.js.map +0 -1
  159. package/dist/esm/fp64/fp64-extension.js +0 -20
  160. package/dist/esm/fp64/fp64-extension.js.map +0 -1
  161. package/dist/esm/fp64/project64.glsl.js.map +0 -1
  162. package/dist/esm/fp64/project64.js +0 -43
  163. package/dist/esm/fp64/project64.js.map +0 -1
  164. package/dist/esm/index.js +0 -11
  165. package/dist/esm/index.js.map +0 -1
  166. package/dist/esm/mask/mask-effect.js +0 -228
  167. package/dist/esm/mask/mask-effect.js.map +0 -1
  168. package/dist/esm/mask/mask-extension.js +0 -83
  169. package/dist/esm/mask/mask-extension.js.map +0 -1
  170. package/dist/esm/mask/mask-pass.js +0 -58
  171. package/dist/esm/mask/mask-pass.js.map +0 -1
  172. package/dist/esm/mask/shader-module.js.map +0 -1
  173. package/dist/esm/path-style/path-style-extension.js +0 -130
  174. package/dist/esm/path-style/path-style-extension.js.map +0 -1
  175. package/dist/esm/path-style/shaders.glsl.js.map +0 -1
  176. package/dist/esm/terrain/height-map-builder.js +0 -86
  177. package/dist/esm/terrain/height-map-builder.js.map +0 -1
  178. package/dist/esm/terrain/shader-module.js +0 -127
  179. package/dist/esm/terrain/shader-module.js.map +0 -1
  180. package/dist/esm/terrain/terrain-cover.js +0 -212
  181. package/dist/esm/terrain/terrain-cover.js.map +0 -1
  182. package/dist/esm/terrain/terrain-effect.js +0 -219
  183. package/dist/esm/terrain/terrain-effect.js.map +0 -1
  184. package/dist/esm/terrain/terrain-extension.js +0 -59
  185. package/dist/esm/terrain/terrain-extension.js.map +0 -1
  186. package/dist/esm/terrain/terrain-pass.js +0 -71
  187. package/dist/esm/terrain/terrain-pass.js.map +0 -1
  188. package/dist/esm/terrain/terrain-picking-pass.js +0 -73
  189. package/dist/esm/terrain/terrain-picking-pass.js.map +0 -1
  190. package/dist/esm/terrain/utils.js +0 -19
  191. package/dist/esm/terrain/utils.js.map +0 -1
  192. package/dist/esm/utils/debug.js +0 -61
  193. package/dist/esm/utils/debug.js.map +0 -1
  194. package/dist/esm/utils/projection-utils.js +0 -134
  195. package/dist/esm/utils/projection-utils.js.map +0 -1
  196. package/typed/data-filter/data-filter-extension.d.ts.map +0 -1
  197. package/typed/data-filter/shader-module.d.ts.map +0 -1
  198. package/typed/index.d.ts +0 -19
  199. package/typed/index.d.ts.map +0 -1
  200. package/typed/mask/mask-effect.d.ts.map +0 -1
  201. package/typed/terrain/height-map-builder.d.ts.map +0 -1
  202. package/typed/terrain/shader-module.d.ts.map +0 -1
  203. package/typed/terrain/terrain-cover.d.ts.map +0 -1
  204. package/typed/terrain/terrain-effect.d.ts.map +0 -1
  205. package/typed/terrain/terrain-pass.d.ts.map +0 -1
  206. package/typed/terrain/terrain-picking-pass.d.ts.map +0 -1
  207. /package/{typed → dist}/brushing/brushing-extension.d.ts +0 -0
  208. /package/{typed → dist}/brushing/brushing-extension.d.ts.map +0 -0
  209. /package/{typed → dist}/clip/clip-extension.d.ts +0 -0
  210. /package/{typed → dist}/clip/clip-extension.d.ts.map +0 -0
  211. /package/{typed → dist}/collision-filter/collision-filter-effect.d.ts +0 -0
  212. /package/{typed → dist}/collision-filter/collision-filter-extension.d.ts +0 -0
  213. /package/{typed → dist}/collision-filter/collision-filter-extension.d.ts.map +0 -0
  214. /package/{typed → dist}/collision-filter/collision-filter-pass.d.ts +0 -0
  215. /package/{typed → dist}/collision-filter/shader-module.d.ts +0 -0
  216. /package/{typed → dist}/collision-filter/shader-module.d.ts.map +0 -0
  217. /package/{typed → dist}/data-filter/aggregator.d.ts +0 -0
  218. /package/{typed → dist}/data-filter/aggregator.d.ts.map +0 -0
  219. /package/{typed → dist}/fill-style/fill-style-extension.d.ts +0 -0
  220. /package/{typed → dist}/fill-style/fill-style-extension.d.ts.map +0 -0
  221. /package/{typed → dist}/fill-style/shaders.glsl.d.ts +0 -0
  222. /package/{typed → dist}/fill-style/shaders.glsl.d.ts.map +0 -0
  223. /package/{typed → dist}/fp64/fp64-extension.d.ts +0 -0
  224. /package/{typed → dist}/fp64/fp64-extension.d.ts.map +0 -0
  225. /package/{typed → dist}/fp64/project64.d.ts +0 -0
  226. /package/{typed → dist}/fp64/project64.d.ts.map +0 -0
  227. /package/{typed → dist}/fp64/project64.glsl.d.ts +0 -0
  228. /package/{typed → dist}/fp64/project64.glsl.d.ts.map +0 -0
  229. /package/{typed → dist}/mask/mask-extension.d.ts +0 -0
  230. /package/{typed → dist}/mask/mask-extension.d.ts.map +0 -0
  231. /package/{typed → dist}/mask/mask-pass.d.ts +0 -0
  232. /package/{typed → dist}/mask/shader-module.d.ts +0 -0
  233. /package/{typed → dist}/mask/shader-module.d.ts.map +0 -0
  234. /package/{typed → dist}/path-style/path-style-extension.d.ts +0 -0
  235. /package/{typed → dist}/path-style/path-style-extension.d.ts.map +0 -0
  236. /package/{typed → dist}/path-style/shaders.glsl.d.ts +0 -0
  237. /package/{typed → dist}/path-style/shaders.glsl.d.ts.map +0 -0
  238. /package/{typed → dist}/terrain/terrain-extension.d.ts +0 -0
  239. /package/{typed → dist}/terrain/terrain-extension.d.ts.map +0 -0
  240. /package/{typed → dist}/terrain/utils.d.ts +0 -0
  241. /package/{typed → dist}/terrain/utils.d.ts.map +0 -0
  242. /package/{typed → dist}/utils/debug.d.ts +0 -0
  243. /package/{typed → dist}/utils/projection-utils.d.ts +0 -0
  244. /package/{typed → dist}/utils/projection-utils.d.ts.map +0 -0
@@ -0,0 +1,66 @@
1
+ import { _PickLayersPass as PickLayersPass } from '@deck.gl/core';
2
+ /** Renders textures used by the TerrainEffect picking pass */
3
+ export class TerrainPickingPass extends PickLayersPass {
4
+ constructor() {
5
+ super(...arguments);
6
+ /** Save layer index for use when drawing to terrain cover.
7
+ * When a terrain cover's picking buffer is rendered,
8
+ * we need to make sure each layer receives a consistent index (encoded in the alpha channel)
9
+ * so that a picked color can be decoded back to the correct layer.
10
+ * Updated in getRenderableLayers which is called in TerrainEffect.preRender
11
+ */
12
+ this.drawParameters = {};
13
+ }
14
+ getRenderableLayers(viewport, opts) {
15
+ const { layers } = opts;
16
+ const result = [];
17
+ this.drawParameters = {};
18
+ this._resetColorEncoder(opts.pickZ);
19
+ const drawParamsByIndex = this._getDrawLayerParams(viewport, opts);
20
+ for (let i = 0; i < layers.length; i++) {
21
+ const layer = layers[i];
22
+ if (!layer.isComposite && drawParamsByIndex[i].shouldDrawLayer) {
23
+ result.push(layer);
24
+ this.drawParameters[layer.id] = drawParamsByIndex[i].layerParameters;
25
+ }
26
+ }
27
+ return result;
28
+ }
29
+ renderTerrainCover(terrainCover, opts) {
30
+ // console.log('Updating terrain cover for picking ' + terrainCover.id)
31
+ const target = terrainCover.getPickingFramebuffer();
32
+ const viewport = terrainCover.renderViewport;
33
+ if (!target || !viewport) {
34
+ return;
35
+ }
36
+ const layers = terrainCover.filterLayers(opts.layers);
37
+ const terrainLayer = terrainCover.targetLayer;
38
+ if (terrainLayer.props.pickable) {
39
+ layers.unshift(terrainLayer);
40
+ }
41
+ target.resize(viewport);
42
+ this.device.withParametersWebGL({
43
+ depthTest: false
44
+ }, () => this.render({
45
+ ...opts,
46
+ pickingFBO: target,
47
+ pass: `terrain-cover-picking-${terrainCover.id}`,
48
+ layers,
49
+ effects: [],
50
+ viewports: [viewport],
51
+ // Disable the default culling because TileLayer would cull sublayers based on the screen viewport,
52
+ // not the viewport of the terrain cover. Culling is already done by `terrainCover.filterLayers`
53
+ cullRect: undefined,
54
+ deviceRect: viewport,
55
+ pickZ: false
56
+ }));
57
+ }
58
+ getLayerParameters(layer, layerIndex, viewport) {
59
+ if (this.drawParameters[layer.id]) {
60
+ return this.drawParameters[layer.id];
61
+ }
62
+ const parameters = super.getLayerParameters(layer, layerIndex, viewport);
63
+ parameters.blend = true;
64
+ return parameters;
65
+ }
66
+ }
@@ -0,0 +1,21 @@
1
+ import { GL } from '@luma.gl/constants';
2
+ export function createRenderTarget(device, opts) {
3
+ return device.createFramebuffer({
4
+ id: opts.id,
5
+ colorAttachments: [
6
+ device.createTexture({
7
+ ...(opts.float && {
8
+ format: device.info.type === 'webgl2' ? 'rgba32float' : 'rgba8unorm',
9
+ type: GL.FLOAT
10
+ }),
11
+ mipmaps: false,
12
+ sampler: {
13
+ minFilter: 'linear',
14
+ magFilter: 'linear',
15
+ addressModeU: 'clamp-to-edge',
16
+ addressModeV: 'clamp-to-edge'
17
+ }
18
+ })
19
+ ]
20
+ });
21
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/utils/debug.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAG1C,qDAAqD;AAErD,eAAO,MAAM,QAAQ,QACd,WAAW;;;UAmDjB,CAAC"}
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/utils/debug.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAE1C,qDAAqD;AAErD,eAAO,MAAM,QAAQ,QACd,WAAW;;;UAmDjB,CAAC"}
@@ -0,0 +1,50 @@
1
+ /* global document */
2
+ /** Debug utility to draw FBO contents onto screen */
3
+ // eslint-disable-next-line
4
+ export const debugFBO = function (fbo, { minimap, opaque } = {}) {
5
+ const color = fbo.device.readPixelsToArrayWebGL(fbo);
6
+ let canvas = document.getElementById('fbo-canvas');
7
+ const canvasHeight = (minimap ? 2 : 1) * fbo.height;
8
+ if (!canvas) {
9
+ canvas = document.createElement('canvas');
10
+ canvas.id = 'fbo-canvas';
11
+ canvas.style.zIndex = '100';
12
+ canvas.style.position = 'absolute';
13
+ canvas.style.top = '0';
14
+ canvas.style.right = '0';
15
+ canvas.style.border = 'blue 1px solid';
16
+ canvas.style.transform = 'scaleY(-1)';
17
+ document.body.appendChild(canvas);
18
+ }
19
+ if (canvas.width !== fbo.width || canvas.height !== canvasHeight) {
20
+ canvas.width = fbo.width;
21
+ canvas.height = canvasHeight;
22
+ canvas.style.width = '400px';
23
+ }
24
+ const ctx = canvas.getContext('2d');
25
+ const imageData = ctx.createImageData(canvas.width, canvas.height);
26
+ // Minimap
27
+ if (minimap) {
28
+ const zoom = 8; // Zoom factor for minimap
29
+ const { width, height } = canvas;
30
+ for (let y = 0; y < height; y++) {
31
+ for (let x = 0; x < width; x++) {
32
+ const d = 4 * (x + y * width); // destination pixel
33
+ const s = 4 * (Math.floor(x / zoom) + Math.floor(y / zoom) * width); // source
34
+ imageData.data[d + 0] = color[s + 0];
35
+ imageData.data[d + 1] = color[s + 1];
36
+ imageData.data[d + 2] = color[s + 2];
37
+ imageData.data[d + 3] = opaque ? 255 : color[s + 3];
38
+ }
39
+ }
40
+ }
41
+ // Full map
42
+ const offset = minimap ? color.length : 0;
43
+ for (let i = 0; i < color.length; i += 4) {
44
+ imageData.data[offset + i + 0] = color[i + 0];
45
+ imageData.data[offset + i + 1] = color[i + 1];
46
+ imageData.data[offset + i + 2] = color[i + 2];
47
+ imageData.data[offset + i + 3] = opaque ? 255 : color[i + 3];
48
+ }
49
+ ctx.putImageData(imageData, 0, 0);
50
+ };
@@ -0,0 +1,153 @@
1
+ import { WebMercatorViewport, OrthographicViewport } from '@deck.gl/core';
2
+ /*
3
+ * Compute the union of bounds from multiple layers
4
+ * Returns bounds in CARTESIAN coordinates
5
+ */
6
+ export function joinLayerBounds(
7
+ /** The layers to combine */
8
+ layers,
9
+ /** A Viewport instance that is used to determine the type of the view */
10
+ viewport) {
11
+ // Join the bounds of layer data
12
+ const bounds = [Infinity, Infinity, -Infinity, -Infinity];
13
+ for (const layer of layers) {
14
+ const layerBounds = layer.getBounds();
15
+ if (layerBounds) {
16
+ const bottomLeftCommon = layer.projectPosition(layerBounds[0], { viewport, autoOffset: false });
17
+ const topRightCommon = layer.projectPosition(layerBounds[1], { viewport, autoOffset: false });
18
+ bounds[0] = Math.min(bounds[0], bottomLeftCommon[0]);
19
+ bounds[1] = Math.min(bounds[1], bottomLeftCommon[1]);
20
+ bounds[2] = Math.max(bounds[2], topRightCommon[0]);
21
+ bounds[3] = Math.max(bounds[3], topRightCommon[1]);
22
+ }
23
+ }
24
+ if (Number.isFinite(bounds[0])) {
25
+ return bounds;
26
+ }
27
+ return null;
28
+ }
29
+ const MAX_VIEWPORT_SIZE = 2048;
30
+ /** Construct a viewport that just covers the target bounds. Used for rendering to common space indexed texture. */
31
+ export function makeViewport(opts) {
32
+ const { bounds, viewport, border = 0 } = opts;
33
+ const { isGeospatial } = viewport;
34
+ if (bounds[2] <= bounds[0] || bounds[3] <= bounds[1]) {
35
+ return null;
36
+ }
37
+ const centerWorld = viewport.unprojectPosition([
38
+ (bounds[0] + bounds[2]) / 2,
39
+ (bounds[1] + bounds[3]) / 2,
40
+ 0
41
+ ]);
42
+ let { width, height, zoom } = opts;
43
+ if (zoom === undefined) {
44
+ // Use width and height to determine zoom
45
+ width = width - border * 2;
46
+ height = height - border * 2;
47
+ const scale = Math.min(width / (bounds[2] - bounds[0]), height / (bounds[3] - bounds[1]));
48
+ zoom = Math.min(Math.log2(scale), 20);
49
+ }
50
+ else if (!width || !height) {
51
+ // Use zoom to determine width and height
52
+ const scale = 2 ** zoom;
53
+ width = Math.round(Math.abs(bounds[2] - bounds[0]) * scale);
54
+ height = Math.round(Math.abs(bounds[3] - bounds[1]) * scale);
55
+ const maxSize = MAX_VIEWPORT_SIZE - border * 2;
56
+ if (width > maxSize || height > maxSize) {
57
+ const r = maxSize / Math.max(width, height);
58
+ width = Math.round(width * r);
59
+ height = Math.round(height * r);
60
+ zoom += Math.log2(r);
61
+ }
62
+ }
63
+ // TODO - find a more generic way to construct this viewport
64
+ // Geospatial viewports may not be web-mercator
65
+ return isGeospatial
66
+ ? new WebMercatorViewport({
67
+ id: viewport.id,
68
+ x: border,
69
+ y: border,
70
+ width,
71
+ height,
72
+ longitude: centerWorld[0],
73
+ latitude: centerWorld[1],
74
+ zoom,
75
+ orthographic: true
76
+ })
77
+ : new OrthographicViewport({
78
+ id: viewport.id,
79
+ x: border,
80
+ y: border,
81
+ width,
82
+ height,
83
+ target: centerWorld,
84
+ zoom,
85
+ flipY: false
86
+ });
87
+ }
88
+ /** Returns viewport bounds in CARTESIAN coordinates */
89
+ export function getViewportBounds(viewport, zRange) {
90
+ // Viewport bounds in world coordinates
91
+ let viewportBoundsWorld;
92
+ if (zRange && zRange.length === 2) {
93
+ const [minZ, maxZ] = zRange;
94
+ const bounds0 = viewport.getBounds({ z: minZ });
95
+ const bounds1 = viewport.getBounds({ z: maxZ });
96
+ viewportBoundsWorld = [
97
+ Math.min(bounds0[0], bounds1[0]),
98
+ Math.min(bounds0[1], bounds1[1]),
99
+ Math.max(bounds0[2], bounds1[2]),
100
+ Math.max(bounds0[3], bounds1[3])
101
+ ];
102
+ }
103
+ else {
104
+ viewportBoundsWorld = viewport.getBounds();
105
+ }
106
+ // Viewport bounds in cartesian coordinates
107
+ const viewportBottomLeftCommon = viewport.projectPosition(viewportBoundsWorld.slice(0, 2));
108
+ const viewportTopRightCommon = viewport.projectPosition(viewportBoundsWorld.slice(2, 4));
109
+ return [
110
+ viewportBottomLeftCommon[0],
111
+ viewportBottomLeftCommon[1],
112
+ viewportTopRightCommon[0],
113
+ viewportTopRightCommon[1]
114
+ ];
115
+ }
116
+ /*
117
+ * Determine the common space bounds that best cover the given data for the given viewport
118
+ * Returns bounds in CARTESIAN coordinates
119
+ */
120
+ export function getRenderBounds(layerBounds, viewport, zRange) {
121
+ if (!layerBounds) {
122
+ return [0, 0, 1, 1];
123
+ }
124
+ const viewportBounds = getViewportBounds(viewport, zRange);
125
+ // Expand viewport bounds by 2X. Heurestically chosen to avoid masking
126
+ // errors when mask is partially out of view
127
+ const paddedBounds = doubleBounds(viewportBounds);
128
+ // When bounds of the layers are smaller than the viewport bounds simply use
129
+ // mask bounds, so as to maximize resolution & avoid rerenders
130
+ if (layerBounds[2] - layerBounds[0] <= paddedBounds[2] - paddedBounds[0] &&
131
+ layerBounds[3] - layerBounds[1] <= paddedBounds[3] - paddedBounds[1]) {
132
+ return layerBounds;
133
+ }
134
+ // As viewport shrinks, to avoid pixelation along mask edges
135
+ // we need to reduce the bounds and only render the visible portion
136
+ // of the mask.
137
+ // We pad the viewport bounds to capture the section
138
+ // of the mask just outside the viewport to correctly maskByInstance.
139
+ // Intersect mask & padded viewport bounds
140
+ return [
141
+ Math.max(layerBounds[0], paddedBounds[0]),
142
+ Math.max(layerBounds[1], paddedBounds[1]),
143
+ Math.min(layerBounds[2], paddedBounds[2]),
144
+ Math.min(layerBounds[3], paddedBounds[3])
145
+ ];
146
+ }
147
+ function doubleBounds(bounds) {
148
+ const dx = bounds[2] - bounds[0];
149
+ const dy = bounds[3] - bounds[1];
150
+ const centerX = (bounds[0] + bounds[2]) / 2;
151
+ const centerY = (bounds[1] + bounds[3]) / 2;
152
+ return [centerX - dx, centerY - dy, centerX + dx, centerY + dy];
153
+ }