summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2019-04-24 10:39:03 +0300
committerYuval Adam <_@yuv.al>2019-04-24 10:39:03 +0300
commit3eb6b25e595144bbe6334c6d67f8687ea3eed25b (patch)
treeb3d7294d9d2c1a5820be73d43b27ce861c198892 /src
parente334f3f6f4e03cba147e103dc7e29a634718bb72 (diff)
Add history playback feature
Diffstat (limited to 'src')
-rw-r--r--src/Geshem.js43
-rw-r--r--src/index.js6
2 files changed, 43 insertions, 6 deletions
diff --git a/src/Geshem.js b/src/Geshem.js
index 820e0e8..97db64a 100644
--- a/src/Geshem.js
+++ b/src/Geshem.js
@@ -1,4 +1,5 @@
import React, { Component } from 'react';
+import { BrowserRouter as Router, Route } from "react-router-dom";
import Slider from 'rc-slider';
import { DateTime } from 'luxon';
import axios from 'axios';
@@ -13,15 +14,27 @@ mapboxgl.accessToken = 'pk.eyJ1IjoieXV2YWRtIiwiYSI6ImNpcnMxbzBuaTAwZWdoa25oczlzZ
const IMGS_BASE_URL = 'https://imgs.geshem.space/'
+function App() {
+ return (
+ <Router>
+ <Route exact path="/" component={Geshem} />
+ <Route path="/history/:date" component={Geshem} />
+ </Router>
+ );
+}
+
+
class Geshem extends Component {
constructor(props) {
super(props);
+ const playback = props.match.params.date;
this.state = {
mapLoaded: false,
imgs: null,
+ playback: playback,
res: 280,
- slider: 9,
+ slider: playback ? 143 : 9,
lng: 35,
lat: 31.9,
zoom: 6.3,
@@ -65,6 +78,23 @@ class Geshem extends Component {
this.showRadarLayer('280', 9)
}
+ loadPlaybackData() {
+ const date = this.state.playback;
+ const hours = [...Array(24).keys()].map(h => `${String(h).padStart(2, '0')}`);
+ const minutes = [...Array(6).keys()].map(m => `${String(m * 10).padStart(2, '0')}`);
+ const paths = hours.reduce((acc, h) => acc.concat(
+ minutes.map(
+ m => `imgs/${date}/${h}${m}/280.png`
+ )
+ ), []);
+ this.setState({
+ imgs: {'280': paths}
+ });
+ if (this.state.mapLoaded) {
+ this.loadSources();
+ }
+ }
+
loadRadarData() {
axios({
url: IMGS_BASE_URL + 'imgs.json',
@@ -146,7 +176,12 @@ class Geshem extends Component {
componentDidMount() {
// this.getGeolocation();
- this.loadRadarData();
+ if (this.state.playback) {
+ this.loadPlaybackData();
+ }
+ else {
+ this.loadRadarData();
+ }
this.initMap();
}
@@ -192,7 +227,7 @@ class Geshem extends Component {
<div id="time">{ time }</div>
</div>
<div id="slider">
- <Slider mix={0} max={9} defaultValue={this.state.slider} handleStyle={handleStyle}
+ <Slider mix={0} max={this.state.playback ? 143 : 9} defaultValue={this.state.slider} handleStyle={handleStyle}
railStyle={railStyle} trackStyle={trackStyle} onChange={(val) => this.onChangeSlider(val)}/>
</div>
</div>
@@ -200,4 +235,4 @@ class Geshem extends Component {
}
}
-export default Geshem;
+export default App;
diff --git a/src/index.js b/src/index.js
index a27f6af..dbc6663 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,9 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
-import Geshem from './Geshem';
+import App from './Geshem';
import * as serviceWorker from './serviceWorker';
-ReactDOM.render(<Geshem />, document.getElementById('root'));
+console.log()
+
+ReactDOM.render(<App />, document.getElementById('root'));
serviceWorker.unregister();