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);
console.log(distance);
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.push({lat: firstPoint.lat, lng: lastPoint.lng});
}
console.log(points);
areaFunctions.collatePolygons(res, gameID, userID, points);
} else {
res.send([]);
@ -61,4 +64,4 @@ module.exports = {
}
}
}
}

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

Loading…
Cancel
Save