From 7397406ae24a3da85c01a4c23baf623dda331946 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Taneli=20Riihim=C3=A4ki?= <m3034@student.jamk.fi>
Date: Thu, 13 Jun 2019 10:38:34 +0300
Subject: [PATCH] First tests, succesfully adding some geojson(ish?) data to
 the database

---
 src/components/UserMap.js | 54 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 48 insertions(+), 6 deletions(-)

diff --git a/src/components/UserMap.js b/src/components/UserMap.js
index ad9bf57..b6c4363 100644
--- a/src/components/UserMap.js
+++ b/src/components/UserMap.js
@@ -13,17 +13,46 @@ class UserMap extends Component {
     this.state = {
       ownLat: null,
       ownLng: null,
-      mapUrl: 'https://tiles.kartat.kapsi.fi/taustakartta/{z}/{x}/{y}.jpg'
+      mapUrl: 'https://tiles.kartat.kapsi.fi/taustakartta/{z}/{x}/{y}.jpg',
+      marker: {
+        type: "FeatureCollection",
+        latitude: "",
+        longitude: "",
+        timestamp: "",
+        features: [{
+          type: "Feature",
+          properties: {},
+          geometry: {
+            type: "Point",
+            coordinates: [
+              null,
+              null
+            ]
+          }
+        }]
+      }
     }
 
     this.watchPositionId = null;
   }
 
-  // componentDidMount(){
-  //   this.getCurrentPosition((position) => {
-  //     this.setCurrentPosition(position);
-  //   });
-  // }
+  componentDidMount(){
+    this.getCurrentPosition((position) => {
+      this.setCurrentPosition(position);
+    });
+    console.log(JSON.stringify(this.state.marker))
+    fetch('http://localhost:5000/mapmarkers/insertLocation', {
+      method: 'PUT',
+      headers: {
+        Authorization: 'Bearer ' + sessionStorage.getItem('token'),
+        Accept: 'application/json',
+        'Content-Type': 'application/json'
+      },
+      body: JSON.stringify(this.state.marker)
+    })
+      .then(res => res.json())
+      .then(result => console.log(result))
+  }
 
   componentWillUnmount(){
     if(this.watchPositionId != null){
@@ -35,6 +64,19 @@ class UserMap extends Component {
     this.setState({
       ownLat: position.coords.latitude,
       ownLng: position.coords.longitude,
+      marker: {
+        features: [
+            {
+              geometry: {
+                type: "Point",
+                coordinates: [
+                  position.coords.latitude,
+                  position.coords.longitude
+                ]
+              }
+            }
+          ]
+      }
     });
   }
 
-- 
GitLab