Repository navigation
Expand file tree
/
Copy pathImageOverlay.js
More file actions
executable file
·113 lines (100 loc) · 2.74 KB
/
Copy pathImageOverlay.js
File metadata and controls
executable file
·113 lines (100 loc) · 2.74 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
import React from 'react';
import MapLibreGL from '@maplibre/maplibre-react-native';
import {Text} from 'react-native';
import Bubble from '../common/Bubble';
import sheet from '../../styles/sheet';
import radar0 from '../../assets/radar.png';
import radar1 from '../../assets/radar1.png';
import radar2 from '../../assets/radar2.png';
import Page from '../common/Page';
import BaseExamplePropTypes from '../common/BaseExamplePropTypes';
const styles = {
rasterLayer: {rasterOpacity: 0.6},
bubble: {bottom: 100},
};
const frames = [radar0, radar1, radar2];
const coordQuads = [
[
[-80.425, 46.437], // top left
[-71.516, 46.437], // top right
[-71.516, 37.936], // bottom right
[-80.425, 37.936], // bottom left
],
[
[-85.425, 45.437], // top left
[-75.516, 45.437], // top right
[-75.516, 36.936], // bottom right
[-85.425, 36.936], // bottom left
],
];
class ImageOverlay extends React.Component {
static propTypes = {
...BaseExamplePropTypes,
};
state = {
radarFrameIndex: 0,
coords: coordQuads[0],
dynamic: false,
};
_timeout = null;
componentDidMount() {
this.heartbeat();
}
heartbeat() {
this._timeout = setTimeout(() => {
requestAnimationFrame(() => {
let nextFrame = this.state.radarFrameIndex + 1;
if (nextFrame > 1) {
nextFrame = 0;
}
if (this.state.dynamic) {
this.setState({
radarFrameIndex: nextFrame,
coords: coordQuads[nextFrame],
});
} else {
this.setState({radarFrameIndex: nextFrame});
}
this.heartbeat();
});
}, 1000);
}
componentWillUnmount() {
if (this._timeout) {
clearTimeout(this._timeout);
}
}
render() {
const bubbleText = this.state.dynamic
? 'Static coordinates'
: 'Dynamic coordinates';
return (
<Page {...this.props}>
<MapLibreGL.MapView
ref={ref => (this.map = ref)}
style={sheet.matchParent}
styleURL={MapLibreGL.StyleURL.Satellite}>
<MapLibreGL.Camera zoomLevel={4} centerCoordinate={[-79, 40]} />
<MapLibreGL.Animated.ImageSource
key="d"
id="radarSource"
coordinates={this.state.coords}
url={frames[this.state.radarFrameIndex]}>
<MapLibreGL.RasterLayer
id="radarLayer"
style={styles.rasterLayer}
/>
</MapLibreGL.Animated.ImageSource>
</MapLibreGL.MapView>
<Bubble
onPress={() => {
this.setState({dynamic: !this.state.dynamic});
}}
style={styles.bubble}>
<Text>{bubbleText}</Text>
</Bubble>
</Page>
);
}
}
export default ImageOverlay;