From 3ebabe2a886f0ade4b474f6bd3228606b9bc1676 Mon Sep 17 00:00:00 2001 From: lesmaux Date: Sat, 13 Oct 2018 21:27:59 +1300 Subject: [PATCH 1/2] added area post --- App.js | 35 ++- api/config/db.js | 2 +- api/package-lock.json | 568 +++++++++++++++++++-------------------- api/v1/api.js | 1 - components/new-button.js | 4 +- update-map.js | 19 ++ 6 files changed, 330 insertions(+), 299 deletions(-) diff --git a/App.js b/App.js index 939a95f..2a68b63 100644 --- a/App.js +++ b/App.js @@ -15,7 +15,7 @@ import { import RunInfo from './components/run-info'; import RunInfoNumeric from './components/run-info-num'; -import {updateAreas} from './update-map' +import {updateAreas, sendArea} from './update-map' import MapView from 'react-native-maps'; import WalkButton from "./components/new-button"; import JoinButton from "./components/join-button"; @@ -39,15 +39,23 @@ export default class App extends Component { }, 5000); let watchID = navigator.geolocation.watchPosition((position) => { - this.setState({ - walkMarkers: [ - ...this.state.walkMarkers, { - coordinate: position.coords, - key: id++ - } - ] - }); - }, null, {enableHighAccuracy: true, timeout: 20000, distanceFilter: 15}); + console.log(this.state.activeWalk) + if(this.state.activeWalk){ + this.setState({ + walkMarkers: [ + ...this.state.walkMarkers, { + coordinate: position.coords, + key: id++ + } + ] + }); + } + // if(!this.state.activeWalk){ + // this.setState({ + // walkMarkers: [] + // }) + // } + }, null, {enableHighAccuracy: true, timeout: 20000, distanceFilter: 10}); this.state = { activeWalk: false, @@ -84,11 +92,15 @@ export default class App extends Component { } startWalk(){ + console.log("starting walk") this.setState({walkMarkers: [], activeWalk: true}) } stopWalk(){ + console.log("stopping walk") + sendArea(this.state.gameNumber, this.state.username, this.state.walkMarkers) this.setState({activeWalk: false}) + } componentWillUnmount() { @@ -108,12 +120,13 @@ export default class App extends Component { latitudeDelta: 0.02, longitudeDelta: 0.02, }} - // onRegionChange = {(region)=> this.addMarker((region))} + > marker.coordinate)} strokeWidth={5} + strokeColor={"rgb(148,0,211)"} /> {this.state.captures.map((capture, i) => { return diff --git a/update-map.js b/update-map.js index a24f69e..92cc32f 100644 --- a/update-map.js +++ b/update-map.js @@ -1,6 +1,25 @@ const config = require("./config.json"); import CapturedArea from "./components/captured-area"; +export const sendArea = (gameID, username, polygon) => { + console.log(polygon) + points = [] + polygon.map((point) => { + points.push({lat: point.coordinate.latitude, lon: point.coordinate.longitude}) + }) + let formBody = []; + formBody.push("gameID=" + gameID); + formBody.push("userID=" + username); + formBody.push("points=" + JSON.stringify(points)); + formBody = formBody.join("&"); + fetch("http://"+config.host + ":" + config.port + "/v1/polygon", { + method: "post", + headers: {'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'}, + body: formBody + }) + .then(res => {return res.json()}) +} + export const updateAreas = (gameID, update) => { getPolygons(gameID).then((responseJson) => { let polygons = [] From 16f961935a682912b6145526181850a007b59965 Mon Sep 17 00:00:00 2001 From: lesmaux Date: Sat, 13 Oct 2018 21:58:15 +1300 Subject: [PATCH 2/2] fixed string --- api/v1/areaFunctions.js | 2 +- update-map.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api/v1/areaFunctions.js b/api/v1/areaFunctions.js index 3ee54c0..837d33d 100644 --- a/api/v1/areaFunctions.js +++ b/api/v1/areaFunctions.js @@ -95,7 +95,7 @@ module.exports = { }); let area = mathFunc.calculateArea(points); - module.exports.polygonDestruction(res, gameID, userID, polygonPoints, area, polygonsMerged); + // module.exports.polygonDestruction(res, gameID, userID, polygonPoints, area, polygonsMerged); module.exports.submitFinalCollation(res, gameID, userID, polygonPoints, area, polygonsMerged); }); }, diff --git a/update-map.js b/update-map.js index 92cc32f..63a5d42 100644 --- a/update-map.js +++ b/update-map.js @@ -2,16 +2,17 @@ const config = require("./config.json"); import CapturedArea from "./components/captured-area"; export const sendArea = (gameID, username, polygon) => { - console.log(polygon) + // console.log(polygon) points = [] polygon.map((point) => { - points.push({lat: point.coordinate.latitude, lon: point.coordinate.longitude}) + points.push({lat: point.coordinate.latitude, lng: point.coordinate.longitude}) }) let formBody = []; formBody.push("gameID=" + gameID); formBody.push("userID=" + username); formBody.push("points=" + JSON.stringify(points)); formBody = formBody.join("&"); + console.log(formBody) fetch("http://"+config.host + ":" + config.port + "/v1/polygon", { method: "post", headers: {'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'},