summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2019-10-15 23:34:54 +0300
committerYuval Adam <_@yuv.al>2019-10-16 10:31:54 +0300
commit67a1524062f1fc2e45a9f35dbb582e072315ef9e (patch)
treedc1fabf984fdd0b3ed277a490432f50e62c78e17 /src
parentcad678c781b7d137470c0efa06b4f911eacc2000 (diff)
Initial fetchImages() implementation doesn't work due to CORS
Diffstat (limited to 'src')
-rw-r--r--src/Geshem.js6
-rw-r--r--src/Map.js16
-rw-r--r--src/config.js5
3 files changed, 20 insertions, 7 deletions
diff --git a/src/Geshem.js b/src/Geshem.js
index e272e3a..c2b6e6e 100644
--- a/src/Geshem.js
+++ b/src/Geshem.js
@@ -9,9 +9,6 @@ import Map from './Map'
import './Geshem.css';
import 'rc-slider/assets/index.css';
-
-const IMGS_BASE_URL = 'https://imgs.geshem.space/'
-
function App() {
return (
<Router>
@@ -100,7 +97,6 @@ class OldGeshem extends Component {
loadRadarData() {
axios({
- url: IMGS_BASE_URL + 'imgs.json',
method: 'get',
}).then((res) => {
this.setState({
@@ -117,7 +113,7 @@ class OldGeshem extends Component {
addRadarSource(res, i, url) {
this.map.addSource(`radar-${res}-${i}`, {
type: 'image',
- url: IMGS_BASE_URL + url,
+ // url: IMGS_BASE_URL + url,
coordinates: this.state.rasterCoords[res]
})
}
diff --git a/src/Map.js b/src/Map.js
index 78dbebf..0a8065b 100644
--- a/src/Map.js
+++ b/src/Map.js
@@ -1,8 +1,10 @@
-import React, { useState } from 'react';
+import React, { useState, useEffect } from 'react';
import ReactMapboxGl, { Layer, Feature } from 'react-mapbox-gl';
+
+import { IMAGES_BASE_URL, MAPBOX_ACCESS_TOKEN } from './config';
+
import 'mapbox-gl/dist/mapbox-gl.css';
-const MAPBOX_ACCESS_TOKEN = 'pk.eyJ1IjoieXV2YWRtIiwiYSI6ImNpcnMxbzBuaTAwZWdoa25oczlzZmkwbHcifQ.UHtLngbKm9O8945pJm23Nw';
const Mapbox = ReactMapboxGl({
accessToken: MAPBOX_ACCESS_TOKEN,
@@ -14,6 +16,16 @@ const Mapbox = ReactMapboxGl({
function Map() {
const [center, setCenter] = useState([35, 31.9]);
const [zoom, setZoom] = useState([6.3]);
+ const [images, setImages] = useState({});
+
+ useEffect(() => {
+ const fetchImages = async() => {
+ const res = await fetch(`${IMAGES_BASE_URL}/imgs.json`);
+ const imgs = await res.json();
+ setImages(imgs);
+ };
+ fetchImages();
+ }, []);
return (
<Mapbox style="mapbox://styles/mapbox/dark-v9" center={center} zoom={zoom}
diff --git a/src/config.js b/src/config.js
new file mode 100644
index 0000000..83f0192
--- /dev/null
+++ b/src/config.js
@@ -0,0 +1,5 @@
+const IMAGES_BASE_URL = 'https://imgs.geshem.space'
+
+const MAPBOX_ACCESS_TOKEN = 'pk.eyJ1IjoieXV2YWRtIiwiYSI6ImNpcnMxbzBuaTAwZWdoa25oczlzZmkwbHcifQ.UHtLngbKm9O8945pJm23Nw';
+
+module.exports = { IMAGES_BASE_URL, MAPBOX_ACCESS_TOKEN };