added area post
This commit is contained in:
@@ -15,7 +15,7 @@ import {
|
|||||||
|
|
||||||
import RunInfo from './components/run-info';
|
import RunInfo from './components/run-info';
|
||||||
import RunInfoNumeric from './components/run-info-num';
|
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 MapView from 'react-native-maps';
|
||||||
import WalkButton from "./components/new-button";
|
import WalkButton from "./components/new-button";
|
||||||
import JoinButton from "./components/join-button";
|
import JoinButton from "./components/join-button";
|
||||||
@@ -39,6 +39,8 @@ export default class App extends Component<Props> {
|
|||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
let watchID = navigator.geolocation.watchPosition((position) => {
|
let watchID = navigator.geolocation.watchPosition((position) => {
|
||||||
|
console.log(this.state.activeWalk)
|
||||||
|
if(this.state.activeWalk){
|
||||||
this.setState({
|
this.setState({
|
||||||
walkMarkers: [
|
walkMarkers: [
|
||||||
...this.state.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 = {
|
this.state = {
|
||||||
activeWalk: false,
|
activeWalk: false,
|
||||||
@@ -84,11 +92,15 @@ export default class App extends Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startWalk(){
|
startWalk(){
|
||||||
|
console.log("starting walk")
|
||||||
this.setState({walkMarkers: [], activeWalk: true})
|
this.setState({walkMarkers: [], activeWalk: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
stopWalk(){
|
stopWalk(){
|
||||||
|
console.log("stopping walk")
|
||||||
|
sendArea(this.state.gameNumber, this.state.username, this.state.walkMarkers)
|
||||||
this.setState({activeWalk: false})
|
this.setState({activeWalk: false})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
@@ -108,12 +120,13 @@ export default class App extends Component<Props> {
|
|||||||
latitudeDelta: 0.02,
|
latitudeDelta: 0.02,
|
||||||
longitudeDelta: 0.02,
|
longitudeDelta: 0.02,
|
||||||
}}
|
}}
|
||||||
// onRegionChange = {(region)=> this.addMarker((region))}
|
|
||||||
>
|
>
|
||||||
|
|
||||||
<MapView.Polyline
|
<MapView.Polyline
|
||||||
coordinates={this.state.walkMarkers.map((marker) => marker.coordinate)}
|
coordinates={this.state.walkMarkers.map((marker) => marker.coordinate)}
|
||||||
strokeWidth={5}
|
strokeWidth={5}
|
||||||
|
strokeColor={"rgb(148,0,211)"}
|
||||||
/>
|
/>
|
||||||
{this.state.captures.map((capture, i) => {
|
{this.state.captures.map((capture, i) => {
|
||||||
return <MapView.Polygon
|
return <MapView.Polygon
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ exports.connect = function(done){
|
|||||||
state.pool = mysql.createPool({
|
state.pool = mysql.createPool({
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
user: 'root',
|
user: 'root',
|
||||||
password: 'root',
|
password: '',
|
||||||
port: 3306,
|
port: 3306,
|
||||||
database: "territory-walker",
|
database: "territory-walker",
|
||||||
//multipleStatements: true
|
//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 = {
|
module.exports = {
|
||||||
getPolygons : function (req, res) {
|
getPolygons : function (req, res) {
|
||||||
mathFunc.calculateArea([]);
|
|
||||||
if (req.query.gameID != null) {
|
if (req.query.gameID != null) {
|
||||||
let query = "CALL getPolygonPoints(\"" + req.query.gameID + "\");";
|
let query = "CALL getPolygonPoints(\"" + req.query.gameID + "\");";
|
||||||
db.get().query(query, function(err, rows){
|
db.get().query(query, function(err, rows){
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export default class WalkButton extends Component {
|
|||||||
buttonText: "Start Capture",
|
buttonText: "Start Capture",
|
||||||
buttonColour: 'rgba(0,255,0,0.5)'
|
buttonColour: 'rgba(0,255,0,0.5)'
|
||||||
})
|
})
|
||||||
this.start();
|
this.stop();
|
||||||
}else{
|
}else{
|
||||||
console.log("state false to true")
|
console.log("state false to true")
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -45,7 +45,7 @@ export default class WalkButton extends Component {
|
|||||||
buttonText: "Stop Capture",
|
buttonText: "Stop Capture",
|
||||||
buttonColour: 'rgba(255,0,0,0.5)'
|
buttonColour: 'rgba(255,0,0,0.5)'
|
||||||
})
|
})
|
||||||
this.stop()
|
this.start()
|
||||||
}}}
|
}}}
|
||||||
// style={sharedStyles.new}
|
// style={sharedStyles.new}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,6 +1,25 @@
|
|||||||
const config = require("./config.json");
|
const config = require("./config.json");
|
||||||
import CapturedArea from "./components/captured-area";
|
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) => {
|
export const updateAreas = (gameID, update) => {
|
||||||
getPolygons(gameID).then((responseJson) => {
|
getPolygons(gameID).then((responseJson) => {
|
||||||
let polygons = []
|
let polygons = []
|
||||||
|
|||||||
Reference in New Issue
Block a user