Browse Source

google: added pathbuttons

Bernadette Elena Hammerle 4 years ago
parent
commit
edf2702b53
1 changed files with 18 additions and 7 deletions
  1. 18 7
      src/maps/Google.js

+ 18 - 7
src/maps/Google.js

@@ -5,6 +5,7 @@ import apiKey from './../config/googleApiKey.js';
 import {calcDistance} from './../helpers/distance';
 import {longitude, latitude, mapWidth, mapHeight, markerIcon, testPath} from "./../config/variables";
 import {Button} from "reactstrap";
+import PathButtons from "./../PathButtons";
 
 const svgStyle = {
   top: "-20",
@@ -21,19 +22,27 @@ const Marker = ({ text }) =>
   </div>;
 
 export default class Google extends React.Component{
-  state = {
-    latitude: latitude,
-    longitude: longitude,
-    zoom: 15,
-    distance: 0,
-    path: testPath,
-    draggable: true
+  constructor(props){
+    super(props);
+    this.state = {
+      latitude: latitude,
+      longitude: longitude,
+      zoom: 15,
+      distance: 0,
+      path: testPath,
+      draggable: true
+    }
   }
 
   componentDidUpdate(){
     this.drawPath()
   }
 
+  updateState = (key, value) => {
+    this.setState({[key]: value})
+    this.getDistance()
+  }
+
   getRoute = (lng, lat) => {
     let pathCopy = this.state.path.slice();
     var end = [lat, lng];
@@ -166,6 +175,8 @@ export default class Google extends React.Component{
           <p>
             Distanz: {Math.round(this.state.distance*100)/100} km
           </p>
+
+          <PathButtons updateState={this.updateState} path={this.state.path}/>
         </div>
       </div>
     );