From d7f205151230859dcd883a6df759c61a9e0f97df Mon Sep 17 00:00:00 2001 From: Fan-Wu Yang Date: Mon, 15 Oct 2018 16:25:40 +1300 Subject: [PATCH] Linked Camera to game, and also fixed polygon last points are not equal --- App.js | 115 +++++++++++++++++++++++----------------- api/v1/areaFunctions.js | 4 ++ gpx.gpx | 4 ++ update-map.js | 4 +- 4 files changed, 77 insertions(+), 50 deletions(-) diff --git a/App.js b/App.js index 2c0b130..92491b4 100644 --- a/App.js +++ b/App.js @@ -36,10 +36,29 @@ export default class App extends Component { constructor(props) { super(props); + let watchID = navigator.geolocation.watchPosition((position) => { + 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, - username: "", - gameNumber: "", + username: "samded", + gameNumber: "samdum", walkMarkers: [], captures: [ // new CapturedArea("fanded", [ @@ -56,30 +75,12 @@ export default class App extends Component { {latitude: -43.5668, longitude:172.5615} ], 'rgba(0,0,255, 1)', 'rgba(0,0,255, 0.2)', 53) ], - watchID + watchID, + activity: "map" }; } componentDidMount() { - let watchID = navigator.geolocation.watchPosition((position) => { - 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}); - setInterval(() => { this.updateCaptures(); }, 5000); @@ -104,6 +105,12 @@ export default class App extends Component { stopWalk(){ console.log("stopping walk") sendArea(this.state.gameNumber, this.state.username, this.state.walkMarkers) + .then(data => { + console.log(data); + if (data != []) { + this.takePicture(data.polygonID); + } + }); this.setState({activeWalk: false}) } @@ -111,41 +118,26 @@ export default class App extends Component { componentWillUnmount() { navigator.geolocation.stopWatch(this.state.watchID); } - takePicture = async function() { + + takePicture = async function(polygonID) { if (this.camera) { const options = { quality: 0.5, base64: true }; const data = await this.camera.takePictureAsync(options) console.log(data.uri); + this.setState({activity: "map"}); } }; + + showCamera() { + this.setState({activity: "takePicture"}); + } render() { - return ( - // - // { - // this.camera = ref; - // }} - // style = {styles.preview} - // type={RNCamera.Constants.Type.back} - // flashMode={RNCamera.Constants.FlashMode.on} - // permissionDialogTitle={'Permission to use camera'} - // permissionDialogMessage={'We need your permission to use your camera phone'} - // onGoogleVisionBarcodesDetected={({ barcodes }) => { - // console.log(barcodes) - // }} - // /> - // - // - // SNAP - // - // - // + let view = ""; + if (this.state.activity === "map") { + view = { - ); + } else if (this.state.activity === "takePicture") { + view = + { + this.camera = ref; + }} + style = {styles.preview} + type={RNCamera.Constants.Type.back} + flashMode={RNCamera.Constants.FlashMode.on} + permissionDialogTitle={'Permission to use camera'} + permissionDialogMessage={'We need your permission to use your camera phone'} + onGoogleVisionBarcodesDetected={({ barcodes }) => { + console.log(barcodes) + }} + /> + + + SNAP + + + + } + + + return view; } } diff --git a/api/v1/areaFunctions.js b/api/v1/areaFunctions.js index 837d33d..ba40277 100644 --- a/api/v1/areaFunctions.js +++ b/api/v1/areaFunctions.js @@ -85,6 +85,10 @@ module.exports = { let polygonResult = []; let polygonsMerged = []; polygons.map((polygon) => { + if (polygon[0].lat != polygon[polygon.length - 1].lat && + polygon[0].lng != polygon[polygon.length - 1].lng) { + polygon.push({lat: polygon[0].lat, lng: polygon[0].lng}) + } let intersect = module.exports.checkIntersects(polygonPoints, polygon.coords); if (intersect != null) { polygonPoints = module.exports.unionPolygon(polygonPoints, polygon.coords); diff --git a/gpx.gpx b/gpx.gpx index 61ee382..43cab66 100644 --- a/gpx.gpx +++ b/gpx.gpx @@ -56,4 +56,8 @@ 20.00 + + 20.00 + + \ No newline at end of file diff --git a/update-map.js b/update-map.js index 8f771e9..b849cc2 100644 --- a/update-map.js +++ b/update-map.js @@ -13,12 +13,12 @@ export const sendArea = (gameID, username, polygon) => { formBody.push("points=" + JSON.stringify(points)); formBody = formBody.join("&"); console.log(formBody) - fetch("http://"+config.host + ":" + config.port + "/v1/polygon", { + return 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()}).then(data => console.log(data)); + .then(res => {return res.json()}); } export const updateAreas = (gameID, update) => {