|
@@ -28,13 +28,27 @@ export default class Leaflet extends React.Component{
|
|
|
}
|
|
|
return res.json();
|
|
|
}).then(data => {
|
|
|
- this.setState({path: data.path})
|
|
|
+ this.setState({path: data})
|
|
|
this.getDistance()
|
|
|
}, err => {
|
|
|
console.log(err)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ setPath = () => {
|
|
|
+ let json = JSON.stringify({
|
|
|
+ "path": this.state.path
|
|
|
+ })
|
|
|
+ fetch("http://localhost:5000/set-path", {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {
|
|
|
+ 'Accept': 'application/json',
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
+ },
|
|
|
+ body: json
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
newPathPoint = event => {
|
|
|
const { lat, lng } = event.latlng
|
|
|
console.log("Clicked at", lat, "/", lng)
|
|
@@ -101,6 +115,7 @@ export default class Leaflet extends React.Component{
|
|
|
<button onClick={this.clearPath}>Clear path</button>
|
|
|
<button onClick={this.getDistance}>Calculate Distance</button>
|
|
|
<button onClick={this.fetchPath}>fetch path</button>
|
|
|
+ <button onClick={this.setPath}>save path</button>
|
|
|
<p>
|
|
|
Distanz: {Math.round(this.state.distance*100)/100} km
|
|
|
</p>
|