|
@@ -20,6 +20,21 @@ export default class Leaflet extends React.Component{
|
|
|
distance: 0
|
|
|
}
|
|
|
|
|
|
+ fetchPath = () => {
|
|
|
+ fetch("http://localhost:5000/get-path")
|
|
|
+ .then(res => {
|
|
|
+ if(res.status >= 400) {
|
|
|
+ throw new Error("Server responds with error!");
|
|
|
+ }
|
|
|
+ return res.json();
|
|
|
+ }).then(data => {
|
|
|
+ this.setState({path: data.path})
|
|
|
+ this.getDistance()
|
|
|
+ }, err => {
|
|
|
+ console.log(err)
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
newPathPoint = event => {
|
|
|
const { lat, lng } = event.latlng
|
|
|
console.log("Clicked at", lat, "/", lng)
|
|
@@ -85,6 +100,7 @@ export default class Leaflet extends React.Component{
|
|
|
<div className="mapInfo">
|
|
|
<button onClick={this.clearPath}>Clear path</button>
|
|
|
<button onClick={this.getDistance}>Calculate Distance</button>
|
|
|
+ <button onClick={this.fetchPath}>fetch path</button>
|
|
|
<p>
|
|
|
Distanz: {Math.round(this.state.distance*100)/100} km
|
|
|
</p>
|