Merge branch 'master' of https://eng-git.canterbury.ac.nz/fwy13/territory_walker
commit
a18ba767d6
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"host" : "192.168.178.74",
|
||||||
|
"port" : "8080"
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
const config = require("./config.json");
|
||||||
|
import CapturedArea from "./components/captured-area";
|
||||||
|
|
||||||
|
export const updateAreas = (gameID, update) => {
|
||||||
|
getPolygons(gameID).then((responseJson) => {
|
||||||
|
let polygons = []
|
||||||
|
responseJson.map((polygon) => {
|
||||||
|
let userID = polygon.userID
|
||||||
|
let strokeColor = "#"+polygon.colour
|
||||||
|
let fillColor = "#"+polygon.colour
|
||||||
|
let coordinates = []
|
||||||
|
polygon.coords.map((point) => {
|
||||||
|
coordinates.push({
|
||||||
|
"latitude" : point.lat,
|
||||||
|
"longitude" : point.lng
|
||||||
|
})
|
||||||
|
});
|
||||||
|
polygons.push(new CapturedArea(userID, coordinates, strokeColor, hexToRgbA(fillColor,0.2), 1));
|
||||||
|
});
|
||||||
|
update(polygons);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPolygons(gameID) {
|
||||||
|
console.log("http://"+config.host + ":" + config.port + "/v1/polygons?gameID=" + gameID)
|
||||||
|
return fetch("http://"+config.host + ":" + config.port + "/v1/polygons?gameID=" + gameID, {method: 'GET',
|
||||||
|
headers: {'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'},})
|
||||||
|
.then((response) => response.json())
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function hexToRgbA(hex, a){
|
||||||
|
var c;
|
||||||
|
if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){
|
||||||
|
c= hex.substring(1).split('');
|
||||||
|
if(c.length== 3){
|
||||||
|
c= [c[0], c[0], c[1], c[1], c[2], c[2]];
|
||||||
|
}
|
||||||
|
c= '0x'+c.join('');
|
||||||
|
return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+',' + a + ')';
|
||||||
|
}
|
||||||
|
throw new Error('Bad Hex');
|
||||||
|
}
|
||||||
Loading…
Reference in new issue