added area post
This commit is contained in:
@@ -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,6 +39,8 @@ export default class App extends Component<Props> {
|
||||
}, 5000);
|
||||
|
||||
let watchID = navigator.geolocation.watchPosition((position) => {
|
||||
console.log(this.state.activeWalk)
|
||||
if(this.state.activeWalk){
|
||||
this.setState({
|
||||
walkMarkers: [
|
||||
...this.state.walkMarkers, {
|
||||
@@ -47,7 +49,13 @@ export default class App extends Component<Props> {
|
||||
}
|
||||
]
|
||||
});
|
||||
}, null, {enableHighAccuracy: true, timeout: 20000, distanceFilter: 15});
|
||||
}
|
||||
// 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
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
Generated
+284
-284
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 = []
|
||||
|
||||
Reference in New Issue
Block a user