From 13388abdc7cfac9e542853e621cf4f99397b02b0 Mon Sep 17 00:00:00 2001 From: Joni Laukka <joni.laukka.overflow@gmail.com> Date: Fri, 19 Jul 2019 14:09:25 +0300 Subject: [PATCH] Map centers to game's center on load --- src/components/GameView.js | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/components/GameView.js b/src/components/GameView.js index 73f61c6..2215bf2 100644 --- a/src/components/GameView.js +++ b/src/components/GameView.js @@ -146,7 +146,10 @@ export default class GameView extends React.Component { }; render() { - const initialPosition = [this.state.lat, this.state.lng]; + console.log(this.state.gameInfo); + const initialPosition = this.state.gameInfo + ? [this.state.gameInfo.center.lat, this.state.gameInfo.center.lng] + : null; return ( <div> <Link to="/"> @@ -223,20 +226,22 @@ export default class GameView extends React.Component { gameId={this.state.gameInfo.id} /> )} - <UserMap - position={initialPosition} - zoom={this.state.zoom} - mapUrl={this.state.mapUrl} - currentGameId={this.state.gameInfo.id} - socketSignal={ - this.state.socketSignal === null - ? null - : this.state.socketSignal.type - } - role={this.state.role} - > - <NotificationPopup socketSignal={this.state.socketSignal} /> - </UserMap> + {initialPosition && ( + <UserMap + position={initialPosition} + zoom={this.state.zoom} + mapUrl={this.state.mapUrl} + currentGameId={this.state.gameInfo.id} + socketSignal={ + this.state.socketSignal === null + ? null + : this.state.socketSignal.type + } + role={this.state.role} + > + <NotificationPopup socketSignal={this.state.socketSignal} /> + </UserMap> + )} {this.state.form === "edit" && ( <EditGameForm gameId={this.state.gameInfo.id} -- GitLab