-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
arcgis-deck-external-renderer.js
78 lines (63 loc) · 2.15 KB
/
arcgis-deck-external-renderer.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
/* eslint-disable no-invalid-this */
import {initializeResources, createOrResizeFramebuffer, initializeDeckGL} from './commons';
import {withParameters} from '@luma.gl/core';
export default function loadArcGISDeckExternalRenderer(DeckProps, externalRenderers) {
class ArcGISDeckExternalRenderer {
constructor(view, props) {
this.view = view;
this.deck = new DeckProps(props);
this.initializeResources = initializeResources;
this.createOrResizeFramebuffer = createOrResizeFramebuffer;
this.initializeDeckGL = initializeDeckGL;
}
setup(context) {
const gl = context.gl;
this.initializeResources(gl);
this.initializeDeckGL(gl);
this.deck.watch(Object.keys(this.deck.properties), (newValue, oldValue, propName) => {
this.deckgl.setProps({[propName]: newValue});
});
this.deckgl.setProps(this.deck.toJSON());
}
setProps(props) {
this.deck.set(props);
}
redraw() {
externalRenderers.requestRender(this.view);
}
render(context) {
const gl = context.gl;
const screenFbo = gl.getParameter(gl.FRAMEBUFFER_BINDING);
// eslint-disable-next-line
const dpr = window.devicePixelRatio;
const width = Math.round(this.view.size[0] * dpr);
const height = Math.round(this.view.size[1] * dpr);
this.createOrResizeFramebuffer(gl, width, height);
this.deckgl.setProps({
viewState: {
latitude: this.view.center.latitude,
longitude: this.view.center.longitude,
zoom: this.view.zoom,
bearing: this.view.camera.heading,
pitch: this.view.camera.tilt
}
});
// 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();
}
);
}
}
return ArcGISDeckExternalRenderer;
}