Newer
Older
// https://github.com/linghuam/Leaflet.TrackPlayBack
import React from "react";
import L from "leaflet";
import "../track-playback/src/leaflet.trackplayback/clock";
import "../track-playback/src/leaflet.trackplayback/index";
import "../track-playback/src/control.trackplayback/control.playback";
import "../track-playback/src/control.trackplayback/index";
export default class ReplayMap extends React.Component {
constructor(props) {
super(props);
this.state = {
// stores all factions from the game
factions: [],
await this.setState({
gameId: await new URL(window.location.href).searchParams.get("id")
});
// fetch all data and set it to state
let replaydata = await this.fetchReplayData();
} else {
alert("Game not found");
window.document.location.href = "/";
}
return this.state.allGeoJSON.map(drawing => {
return drawing[0];
// create a map for the replay, setView to game's center cords
this.map = L.map(this.refs.map).setView(
this.state.location || [62.3, 25.7],
14
);
L.tileLayer("https://tiles.kartat.kapsi.fi/taustakartta/{z}/{x}/{y}.jpg", {
attribution:
'© <a href="https://www.maanmittauslaitos.fi/">Maanmittauslaitos</a>'
}).addTo(this.map);
// import options from ReplayConfig.js
this.trackplayback = new L.TrackPlayBack(this.state, this.map, options);
this.trackplaybackControl = L.trackplaybackcontrol(this.trackplayback);
this.trackplaybackControl.addTo(this.map);
};
render() {
return (
<Link to="/">
<button>Game selection</button>
</Link>