Bugfixes to correct some null checks. Changed colors of map markers

master
Joshua Sigona 4 years ago
parent 2a4d72c848
commit a8d79a0161
  1. 28
      family-tracker/src/App.js
  2. 6
      src/main/java/sig/family/FamilyApp.java

@ -41,16 +41,30 @@ setInterval(()=>{
if (loc.safe) { if (loc.safe) {
ctx.fillStyle="#6a6" ctx.fillStyle="#6a6"
} else { } else {
ctx.fillStyle="#a66" ctx.fillStyle="#d66"
} }
ctx.arc((loc.x-mapX)/mapXScale,(loc.y-mapY)/mapYScale,10,0,2*Math.PI) ctx.arc((loc.x-mapX)/mapXScale,(loc.y-mapY)/mapYScale,10,0,2*Math.PI)
ctx.fill(); ctx.fill();
} }
for (var m of members) { for (var m of members) {
ctx.beginPath(); ctx.beginPath();
ctx.fillStyle="#22f" switch (m.relationship) {
case "Father":{
ctx.fillStyle="#22f"
}break;
case "Mother":{
ctx.fillStyle="#f26"
}break;
case "Brother":{
ctx.fillStyle="#4df"
}break;
case "Sister":{
ctx.fillStyle="#f4f"
}break;
}
ctx.arc((m.x-mapX)/mapXScale,(m.y-mapY)/mapYScale,5,0,2*Math.PI); ctx.arc((m.x-mapX)/mapXScale,(m.y-mapY)/mapYScale,5,0,2*Math.PI);
ctx.fill(); ctx.fill();
ctx.stroke();
} }
ctx.font = "22px Verdana"; ctx.font = "22px Verdana";
for (var loc of locations) { for (var loc of locations) {
@ -193,6 +207,7 @@ function Message(p) {
); );
} }
function Member(p) { function Member(p) {
const [familyId,setFamilyId] = useState(0) const [familyId,setFamilyId] = useState(0)
@ -202,6 +217,11 @@ function Member(p) {
const [mobileDevice,setMobileDevice] = useState("") const [mobileDevice,setMobileDevice] = useState("")
const [disabled,setDisabled] = useState(false) const [disabled,setDisabled] = useState(false)
const options = [{display:"Father",value:"Father"},
{display:"Mother",value:"Mother"},
{display:"Son",value:"Brother"},
{display:"Daughter",value:"Sister"},]
useEffect(()=>{ useEffect(()=>{
p.setActive("/members") p.setActive("/members")
}) })
@ -227,7 +247,9 @@ function Member(p) {
<div className="row"> <div className="row">
<div className="col-sm-12 col-lg-8"> <div className="col-sm-12 col-lg-8">
<label htmlFor="name">Add Member:</label> <label htmlFor="name">Add Member:</label>
<br/><input type="text" disabled={disabled} onChange={(e)=>{setFirstName(e.target.value);}} value={firstName} id="firstName" style={{width:"30%"}}/><input type="text" disabled={disabled} onChange={(e)=>{setLastName(e.target.value);}} value={lastName} id="lastName" style={{width:"30%"}}/><input type="text" disabled={disabled} onChange={(e)=>{setMobileDevice(e.target.value);}} value={mobileDevice} id="mobileDevice" style={{width:"30%"}}/><input type="text" disabled={disabled} onChange={(e)=>{setRelationship(e.target.value);}} value={relationship} id="relationship" style={{width:"30%"}}/><button disabled={disabled} style={{width:"10%"}} onClick={()=>{ <br/><div className="form-group"><label for="firstName">First Name</label><input type="text" className="form-control form-control-sm" name="firstName" disabled={disabled} onChange={(e)=>{setFirstName(e.target.value);}} value={firstName} id="firstName"/></div><div className="form-group"><label for="lastName">Last Name</label><input type="text" className="form-control form-control-sm" name="lastName" disabled={disabled} onChange={(e)=>{setLastName(e.target.value);}} value={lastName} id="lastName"/></div><div className="form-group"><label for="mobileDevice">Mobile Device</label><input type="text" name="mobileDevice" className="form-control form-control-sm" disabled={disabled} onChange={(e)=>{setMobileDevice(e.target.value);}} value={mobileDevice} id="mobileDevice"/></div><div className="form-group"><label for="relationship">Relationship</label><select className="form-control form-control-sm" name="relationship" disabled={disabled} onChange={(e)=>{setRelationship(e.target.value);}} id="relationship" value={relationship}>
{options.map((option)=><option value={option.value} key={option.value}>{option.display}</option>)}
</select></div><button disabled={disabled} style={{width:"10%"}} onClick={()=>{
setDisabled(true) setDisabled(true)
axios.post("http://localhost:8080/member/create",{firstName:firstName,lastName:lastName,mobileId:mobileDevice}) axios.post("http://localhost:8080/member/create",{firstName:firstName,lastName:lastName,mobileId:mobileDevice})
.then((data)=>{ .then((data)=>{

@ -22,7 +22,7 @@ public class FamilyApp {
static HashMap<Long,GPSUser> map = new HashMap<>(); static HashMap<Long,GPSUser> map = new HashMap<>();
static RestTemplate connection = new RestTemplate(); static RestTemplate connection = new RestTemplate();
public final static int WAITMULT=3; public final static int WAITMULT=2;
public static Location postMessage(Message message) { public static Location postMessage(Message message) {
// Construct a URI from a template // Construct a URI from a template
@ -109,6 +109,7 @@ public class FamilyApp {
} else { } else {
g.targetX=l.getX(); g.targetX=l.getX();
g.targetY=l.getY(); g.targetY=l.getY();
System.out.println("New target for "+g.id+" is now "+l.getName());
//System.out.println(connection.postForObject("http://localhost:8080", String.class, "6ba5969a",q)); //System.out.println(connection.postForObject("http://localhost:8080", String.class, "6ba5969a",q));
break; break;
} }
@ -124,7 +125,7 @@ public class FamilyApp {
if (u.waitTime>0) { if (u.waitTime>0) {
u.waitTime--; u.waitTime--;
} else { } else {
if (u.targetX!=u.x || u.targetY!=u.y) { if (Math.abs(u.targetX-u.x)>0.001 || Math.abs(u.targetY-u.y)>0.001) {
switch ((int)(Math.random()*6)) { switch ((int)(Math.random()*6)) {
case 0:{ case 0:{
//Sometimes go a random direction. //Sometimes go a random direction.
@ -164,6 +165,7 @@ public class FamilyApp {
} else { } else {
u.targetX=l.getX(); u.targetX=l.getX();
u.targetY=l.getY(); u.targetY=l.getY();
System.out.println("New target for "+u.id+" is now "+l.getName());
//System.out.println(connection.postForObject("http://localhost:8080", String.class, "6ba5969a",q)); //System.out.println(connection.postForObject("http://localhost:8080", String.class, "6ba5969a",q));
break; break;
} }

Loading…
Cancel
Save