-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmap2d.js
More file actions
150 lines (138 loc) · 3.89 KB
/
map2d.js
File metadata and controls
150 lines (138 loc) · 3.89 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import React from 'react';
import DeckGL from '@deck.gl/react';
import { MapboxLayer } from '@deck.gl/mapbox';
import { PostProcessEffect, View, MapView } from '@deck.gl/core';
import { StaticMap } from 'react-map-gl';
import { getNaipUrl } from '../util';
import { NAIPLayer, MODISLayer } from '../mapbox-layers';
import { LandsatTileLayer } from '../deck-layers';
import { vibrance } from '@luma.gl/shadertools';
// You'll get obscure errors without including the Mapbox GL CSS
import '../../css/mapbox-gl.css';
const mapStyle = require('./style.json');
const initialViewState = {
longitude: -112.1861,
latitude: 36.1284,
zoom: 11.5,
pitch: 0,
bearing: 0,
};
const vibranceEffect = new PostProcessEffect(vibrance, {
amount: 1,
});
export default class Map extends React.Component {
state = {
gl: null,
viewState: initialViewState,
naipTileUrl: getNaipUrl(),
// Show NAIP imagery at zoom >= 12
useNaip: true
};
// DeckGL and mapbox will both draw into this WebGL context
_onWebGLInitialized = gl => {
this.setState({ gl });
};
_onMapLoad = () => {
const map = this._map;
const deck = this._deck;
// This id has to match the id of the Deck layer
map.addLayer(
new MapboxLayer({ id: 'landsat-tile-layer', deck }),
'waterway_other'
);
};
onViewStateChange = ({viewState}) => {
this.setState({viewState})
}
render() {
const { gl, naipTileUrl, viewState, useNaip } = this.state;
const layers = [
new LandsatTileLayer({
id: 'landsat-tile-layer',
gl,
rgbBands: [4, 3, 2],
visible: viewState.zoom >= 7 && (viewState.zoom <= 12 || !useNaip),
}),
];
return (
<DeckGL
ref={ref => {
// save a reference to the Deck instance
this._deck = ref && ref.deck;
}}
layers={layers}
viewState={viewState}
onViewStateChange={this.onViewStateChange}
// controller
views={[
new MapView({
id: 'left-view',
width: '50%',
controller: true,
}),
new MapView({
id: 'right-view',
width: '50%',
x: '50%',
controller: true,
}),
]}
onWebGLInitialized={this._onWebGLInitialized}
glOptions={{ stencil: true }}
// Weird effects with MapboxLayer
// effects={[vibranceEffect]}
>
{gl && (
<View id="left-view">
<StaticMap
ref={ref => {
// save a reference to the mapboxgl.Map instance
this._map = ref && ref.getMap();
}}
gl={gl}
onLoad={this._onMapLoad}
mapStyle={mapStyle}
mapOptions={{ hash: true }}
>
<MODISLayer
dateStr="2018-06-01"
visible={true}
beforeId="waterway_other"
/>
<NAIPLayer
tileUrl={naipTileUrl}
visible={useNaip}
beforeId="waterway_other"
/>
</StaticMap>
</View>
)}
{gl && (
<View id="right-view">
<StaticMap
ref={ref => {
// save a reference to the mapboxgl.Map instance
this._map = ref && ref.getMap();
}}
gl={gl}
onLoad={this._onMapLoad}
mapStyle={mapStyle}
mapOptions={{ hash: true }}
>
<MODISLayer
dateStr="2018-06-01"
visible={true}
beforeId="waterway_other"
/>
<NAIPLayer
tileUrl={naipTileUrl}
visible={useNaip}
beforeId="waterway_other"
/>
</StaticMap>
</View>
)}
</DeckGL>
);
}
}