Skip to content
Snippets Groups Projects
Commit 534fc706 authored by Taneli Riihimäki's avatar Taneli Riihimäki
Browse files

Add a button to change map layers

parent 33faf98b
No related branches found
No related tags found
2 merge requests!11Combine gamelist and new game form,!7Change map layers
...@@ -7,20 +7,30 @@ import Header from './components/Header'; ...@@ -7,20 +7,30 @@ import Header from './components/Header';
class App extends Component { class App extends Component {
constructor() { constructor() {
super(); super();
// set initial state // set initial state
this.state = { this.state = {
lat: 62.2416479, lat: 62.2416479,
lng: 25.7597186, lng: 25.7597186,
zoom: 13 zoom: 13,
mapUrl: 'https://tiles.kartat.kapsi.fi/taustakartta/{z}/{x}/{y}.jpg'
}; };
this.handleLayerChange = this.handleLayerChange.bind(this);
} }
// Toggles through the list and changes the mapUrl state
handleLayerChange = () => {
const maps = ['https://tiles.kartat.kapsi.fi/taustakartta/{z}/{x}/{y}.jpg', 'https://tiles.kartat.kapsi.fi/peruskartta/{z}/{x}/{y}.jpg','https://tiles.kartat.kapsi.fi/ortokuva/{z}/{x}/{y}.jpg'];
this.setState({mapUrl: maps.indexOf(this.state.mapUrl) < maps.length - 1 ? maps[maps.indexOf(this.state.mapUrl) + 1] : maps[0]})
};
render() { render() {
const initialPosition = [this.state.lat, this.state.lng]; const initialPosition = [this.state.lat, this.state.lng];
return ( return (
<div> <div>
<UserMap position={initialPosition} zoom={this.state.zoom} />, <UserMap position={initialPosition} zoom={this.state.zoom} mapUrl={this.state.mapUrl} />,
<Header /> <Header handleLayerChange={this.handleLayerChange} />
</div> </div>
); );
} }
......
...@@ -77,6 +77,7 @@ class Header extends React.Component { ...@@ -77,6 +77,7 @@ class Header extends React.Component {
<button onClick={this.handleLogout}>logout</button> <button onClick={this.handleLogout}>logout</button>
)} )}
{this.state.username && <button>{this.state.username}</button>} {this.state.username && <button>{this.state.username}</button>}
<button onClick={this.props.handleLayerChange}>change layer</button>
</div> </div>
{this.state.register && ( {this.state.register && (
<RegisterForm <RegisterForm
...@@ -92,6 +93,7 @@ class Header extends React.Component { ...@@ -92,6 +93,7 @@ class Header extends React.Component {
toggleView={this.toggleView} toggleView={this.toggleView}
/> />
)} )}
</div> </div>
); );
} }
......
...@@ -14,6 +14,7 @@ class UserMap extends Component { ...@@ -14,6 +14,7 @@ class UserMap extends Component {
this.state = { this.state = {
ownLat: null, ownLat: null,
ownLng: null, ownLng: null,
mapUrl: 'https://tiles.kartat.kapsi.fi/taustakartta/{z}/{x}/{y}.jpg'
} }
this.watchPositionId = null; this.watchPositionId = null;
...@@ -68,10 +69,10 @@ class UserMap extends Component { ...@@ -68,10 +69,10 @@ class UserMap extends Component {
<Map className='map' center={this.props.position} zoom={this.props.zoom}> <Map className='map' center={this.props.position} zoom={this.props.zoom}>
<TileLayer <TileLayer
attribution='&copy; <a href="https://www.maanmittauslaitos.fi/">Maanmittauslaitos</a>' attribution='&copy; <a href="https://www.maanmittauslaitos.fi/">Maanmittauslaitos</a>'
url=' https://tiles.kartat.kapsi.fi/taustakartta/{z}/{x}/{y}.jpg' url={this.props.mapUrl}
/> />
<ZoomControl position='topright' /> <ZoomControl position='topright' />
<DrawTools position={this.props.position} /> <DrawTools position={this.props.position} />
<Marker position={this.props.position}> <Marker position={this.props.position}>
<Popup> <Popup>
Se on perjantai, my dudes <br /> Se on perjantai, my dudes <br />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment