added area post

main
lesmaux 7 years ago
parent 21c230e77b
commit 3ebabe2a88

@ -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<Props> {
}, 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<Props> {
}
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<Props> {
latitudeDelta: 0.02,
longitudeDelta: 0.02,
}}
// onRegionChange = {(region)=> this.addMarker((region))}
>
<MapView.Polyline
coordinates={this.state.walkMarkers.map((marker) => marker.coordinate)}
strokeWidth={5}
strokeColor={"rgb(148,0,211)"}
/>
{this.state.captures.map((capture, i) => {
return <MapView.Polygon

@ -9,7 +9,7 @@ exports.connect = function(done){
state.pool = mysql.createPool({
host: 'localhost',
user: 'root',
password: 'root',
password: '',
port: 3306,
database: "territory-walker",
//multipleStatements: true

568
api/package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -5,7 +5,6 @@ let areaFunctions = require("./areaFunctions.js");
module.exports = {
getPolygons : function (req, res) {
mathFunc.calculateArea([]);
if (req.query.gameID != null) {
let query = "CALL getPolygonPoints(\"" + req.query.gameID + "\");";
db.get().query(query, function(err, rows){

@ -37,7 +37,7 @@ export default class WalkButton extends Component {
buttonText: "Start Capture",
buttonColour: 'rgba(0,255,0,0.5)'
})
this.start();
this.stop();
}else{
console.log("state false to true")
this.setState({
@ -45,7 +45,7 @@ export default class WalkButton extends Component {
buttonText: "Stop Capture",
buttonColour: 'rgba(255,0,0,0.5)'
})
this.stop()
this.start()
}}}
// style={sharedStyles.new}
>

@ -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 = []

Loading…
Cancel
Save