-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
arcgis-deck-layer-view-2d.js
100 lines (81 loc) · 2.73 KB
/
arcgis-deck-layer-view-2d.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import {initializeResources, createOrResizeFramebuffer, initializeDeckGL} from './commons';
import {withParameters} from '@luma.gl/core';
export default function loadArcGISDeckLayerView2D(BaseLayerViewGL2D) {
return BaseLayerViewGL2D.createSubclass({
properties: {
deckgl: {},
deckFbo: {},
model: {},
buffer: {}
},
initializeResources,
createOrResizeFramebuffer,
initializeDeckGL,
// Attach is called as soon as the layer view is ready to start rendering.
attach() {
// We use a full-screen quad and shaders to composite the frame rendered
// with deck.gl on top of the MapView. Composition uses the MapView context.
const gl = this.context;
this.initializeResources(gl);
this.initializeDeckGL(gl);
// Update deck props
this.layer.on('deckpropchanged', props => this.deckgl.setProps(props));
// We need to start drawing the deck.gl layer immediately.
this.deckgl.setProps(this.layer.deck.toJSON());
},
redraw() {
this.requestRender();
},
// Called when the layer must be destroyed.
detach() {
this.handles.removeAll();
this.deckgl.finalize();
this.deckgl = null;
if (this.model) {
this.model.delete();
}
if (this.buffer) {
this.buffer.delete();
}
if (this.deckFbo) {
this.deckFbo.delete();
}
},
// Called every time that the layer view must be rendered.
render(renderParameters) {
const gl = renderParameters.context;
const screenFbo = gl.getParameter(gl.FRAMEBUFFER_BINDING);
// eslint-disable-next-line
const dpr = window.devicePixelRatio;
const width = Math.round(this.view.state.size[0] * dpr);
const height = Math.round(this.view.state.size[1] * dpr);
this.createOrResizeFramebuffer(gl, width, height);
// The view state must be kept in-sync with the MapView of the ArcGIS API.
const state = renderParameters.state;
this.deckgl.setProps({
viewState: {
latitude: this.view.center.latitude,
longitude: this.view.center.longitude,
zoom: this.view.featuresTilingScheme.scaleToLevel(state.scale),
bearing: -state.rotation,
pitch: 0
}
});
// We redraw the deck immediately.
this.deckgl.redraw('arcgis');
// We overlay the texture on top of the map using the full-screen quad.
withParameters(
gl,
{
blend: true,
blendFunc: [gl.ONE, gl.ONE_MINUS_SRC_ALPHA],
framebuffer: screenFbo,
viewport: [0, 0, width, height]
},
() => {
this.model.setUniforms({u_texture: this.deckFbo}).draw();
}
);
}
});
}