Skip to content

Commit c3cc0a5

Browse files
committed
fetch weather-info-all.json
1 parent 7b3b6cf commit c3cc0a5

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
6-
<title>Relief map</title>
6+
<title>Weather info map</title>
77
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css" />
88
<style>
99
body { margin: 0; padding: 0; }

src/WeatherInfoLayer.js

+23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import React, { Component } from 'react';
22
import mapboxgl from 'mapbox-gl';
33

44
export default class Map extends Component {
5+
componentDidMount() {
6+
this.loadWeatherInfo();
7+
}
8+
59
onload(map) {
610
this.map = map;
711

@@ -21,6 +25,25 @@ export default class Map extends Component {
2125
"line-color": "rgba(123, 124, 125, 0.7)"
2226
}
2327
});
28+
29+
this.renderWeatherInfo();
30+
}
31+
32+
loadWeatherInfo() {
33+
const timestamp = new Date().getTime();
34+
fetch('https://storage.googleapis.com/weather-info/weather-info-all.json?' + timestamp, {mode: 'cors'})
35+
.then(res => res.json())
36+
.then(data => {
37+
console.log(data);
38+
this.weatherInfo = data;
39+
this.renderWeatherInfo();
40+
});
41+
}
42+
43+
renderWeatherInfo() {
44+
if (!this.map || this.weatherInfo) return;
45+
46+
2447
}
2548

2649
render() {

0 commit comments

Comments
 (0)