-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
117 lines (101 loc) · 3.14 KB
/
app.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* global fetch, DOMParser */
import React, {useMemo, useState} from 'react';
import {render} from 'react-dom';
import {DeckGL} from "@deck.gl/react";
import {OrthographicView, COORDINATE_SYSTEM, CompositeLayer} from "@deck.gl/core";
import {TileLayer} from '@deck.gl/geo-layers';
import {IconLayer} from '@deck.gl/layers';
const INITIAL_VIEW_STATE = {
target: [13000, 13000, 0],
zoom: -7
};
const ICON_MAPPING = {
marker: {x: 0, y: 0, width: 128, height: 128, mask: true},
};
const SAMPLE_DATA = Array.from({length: 500000}, (_, i) => ({
index: i,
position: [Math.random() * 24000, Math.random() * 24000],
}));
console.log(SAMPLE_DATA[4]);
async function getData(bbox, z) {
// Stall for 20ms - simulate an async request
await new Promise(resolve => setTimeout(resolve, 20));
return SAMPLE_DATA.filter(
d =>
d.position[0] > bbox.left &&
d.position[0] < bbox.right &&
d.position[1] > bbox.top &&
d.position[1] < bbox.bottom &&
d.index % Math.max(1, Math.pow(z, 2)) === 0 // subsample
);
}
class ExampleCompositeLayer extends CompositeLayer {
constructor(props) {
// By default, deckgl will attempt to _fetch_ any data of type string
// Here, we want to accept data of type string, but simply pass that data along to
// the TileLayer, so we explicitly turn off the _fetch_ capability here.
props.fetch = undefined;
super(props);
}
renderLayers() {
return [new TileLayer({
tileSize: this.props.dimensions.tileSize,
highlightColor: [60, 60, 60, 100],
minZoom: -7,
maxZoom: 0,
coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
// extent: [0, 0, dimensions.width, dimensions.height],
getTileData: async ({z, bbox}) => {
return await getData(bbox, z);
},
// onViewportLoad: this.props.onTilesLoad,
renderSubLayers: props => {
return new IconLayer(
// This is where the issue is happening. If we remove `this.getSubLayerProps` the issue goes away
this.getSubLayerProps({
data: props.data,
filled: true,
getColor: () => [255, 255, 255],
getIcon: () => "marker",
iconAtlas:
"https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/icon-atlas.png",
iconMapping: ICON_MAPPING,
id: `icon-layer-${props.id}`,
sizeMinPixels: 10,
updateTriggers: {},
})
);
}
})];
}
}
export default function App({onTilesLoad}) {
const dimensions = useMemo(() => ({
height: 24000,
tileSize: 512,
width: 24000
}));
const [viewState, setViewState] =
useState(INITIAL_VIEW_STATE);
const tileLayer =
dimensions &&
new ExampleCompositeLayer({
dimensions,
id: "test",
onTilesLoad
});
const onViewStateChange = ({viewState}) => {
setViewState(viewState);
};
return (
<DeckGL
views={[new OrthographicView({controller: true, id: 'ortho'})]}
layers={[tileLayer]}
onViewStateChange={onViewStateChange}
viewState={viewState}
/>
);
}
export function renderToDOM(container) {
render(<App/>, container);
}