From 56b999e0a95fb412cb4ffc1b83cb031e47b0c291 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Sun, 18 Nov 2018 10:06:56 +0200 Subject: Add basic geolocation centering --- src/Geshem.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Geshem.js b/src/Geshem.js index 4bb90b5..c1046a0 100644 --- a/src/Geshem.js +++ b/src/Geshem.js @@ -42,6 +42,25 @@ class Geshem extends Component { }; } + getGeolocation() { + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition((pos) => { + const {longitude, latitude} = pos.coords; + this.setState({ + lng: longitude, + lat: latitude, + zoom: 11 + }); + if (this.state.mapLoaded) { + this.map.jumpTo({ + center: [longitude, latitude], + zoom: 11 + }); + } + }) + } + } + loadSources() { const { imgs } = this.state; let i = 0; @@ -148,6 +167,7 @@ class Geshem extends Component { } componentDidMount() { + this.getGeolocation(); this.loadRadarData(); this.initMap(); } @@ -183,7 +203,6 @@ class Geshem extends Component { } const datetime = this.getDateTime(); - console.log(datetime); const date = datetime ? datetime.toFormat('y-MM-dd') : ''; const time = datetime ? datetime.toFormat('HH:mm') : ''; -- cgit v1.3.1