diff options
| author | Yuval Adam <_@yuv.al> | 2018-11-18 10:06:56 +0200 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2018-11-18 10:06:56 +0200 |
| commit | 56b999e0a95fb412cb4ffc1b83cb031e47b0c291 (patch) | |
| tree | ee7b844592f03c3f592975abf2cbee71544ba84c /src | |
| parent | b3ec8233391c08298edc3644c647da83131e87db (diff) | |
Add basic geolocation centering
Diffstat (limited to 'src')
| -rw-r--r-- | src/Geshem.js | 21 |
1 files changed, 20 insertions, 1 deletions
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') : ''; |
