Fixed some errors which was not completeing the polygon if either the lat or long were different'

main
root 7 years ago
commit de6f166171

@ -49,10 +49,13 @@ module.exports = {
let distance = mathFunc.gpsToMeters(firstPoint.lat, firstPoint.lng, lastPoint.lat, lastPoint.lng); let distance = mathFunc.gpsToMeters(firstPoint.lat, firstPoint.lng, lastPoint.lat, lastPoint.lng);
console.log(distance); console.log(distance);
if (distance < 20) { if (distance < 20) {
if (lastPoint.lat != firstPoint.lat && lastPoint.lng != firstPoint.lng) { console.log(lastPoint);
console.log(firstPoint);
if (lastPoint.lat != firstPoint.lat || lastPoint.lng != firstPoint.lng) {
// points.pop(); // points.pop();
points.push({lat: firstPoint.lat, lng: lastPoint.lng}); points.push({lat: firstPoint.lat, lng: lastPoint.lng});
} }
console.log(points);
areaFunctions.collatePolygons(res, gameID, userID, points); areaFunctions.collatePolygons(res, gameID, userID, points);
} else { } else {
res.send([]); res.send([]);

@ -5,7 +5,7 @@ let mathFunc = require("./mathFunc.js");
module.exports = { module.exports = {
organisePolygonPoints(polygonPoints) { organisePolygonPoints(polygonPoints) {
console.log(polygonPoints); // console.log(polygonPoints);
let polygons = [] let polygons = []
let polygonDict = {}; let polygonDict = {};
polygonPoints.map((point) => { polygonPoints.map((point) => {
@ -81,14 +81,16 @@ module.exports = {
console.log(err); console.log(err);
res.send(500); res.send(500);
} }
// console.log("points: %s", JSON.stringify(points));
let polygonPoints = points; let polygonPoints = points;
let polygons = module.exports.organisePolygonPoints(rows[0]); let polygons = module.exports.organisePolygonPoints(rows[0]);
let polygonResult = []; let polygonResult = [];
let polygonsMerged = []; let polygonsMerged = [];
polygons.map((polygon) => { polygons.map((polygon) => {
console.log(polygon); console.log(polygon);
if (polygon.coords[0].lat != polygon.coords[polygon.length - 1].lat && if (polygon.coords[0].lat != polygon.coords[polygon.coords.length - 1].lat &&
polygon.coords[0].lng != polygon.coords[polygon.length - 1].lng) { polygon.coords[0].lng != polygon.coords[polygon.coords.length - 1].lng) {
console.log("Duplicated");
polygon.coords.push({lat: polygon.coords[0].lat, lng: polygon.coords[0].lng}) polygon.coords.push({lat: polygon.coords[0].lat, lng: polygon.coords[0].lng})
} }
let intersect = module.exports.checkIntersects(polygonPoints, polygon.coords); let intersect = module.exports.checkIntersects(polygonPoints, polygon.coords);
@ -116,6 +118,8 @@ module.exports = {
checkIntersects(points1, points2) { checkIntersects(points1, points2) {
let arrayPoints1 = [module.exports.convertPointsObjToArray(points1)]; let arrayPoints1 = [module.exports.convertPointsObjToArray(points1)];
let arrayPoints2 = [module.exports.convertPointsObjToArray(points2)]; let arrayPoints2 = [module.exports.convertPointsObjToArray(points2)];
console.log("apt1: %s", arrayPoints1);
console.log("apt2: %s", arrayPoints2);
let poly1 = turf.polygon(arrayPoints1); let poly1 = turf.polygon(arrayPoints1);
let poly2 = turf.polygon(arrayPoints2); let poly2 = turf.polygon(arrayPoints2);
return turf.intersect(poly1, poly2); return turf.intersect(poly1, poly2);

Loading…
Cancel
Save