Skip to content

Commit 1843778

Browse files
authored
Update CarJunction.js
1 parent 5c3d5d4 commit 1843778

File tree

1 file changed

+18
-79
lines changed
  • exercises/static/exercises/car_junction/react-components

1 file changed

+18
-79
lines changed
Lines changed: 18 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,20 @@
11
import * as React from "react";
2-
import { Box } from "@mui/material";
3-
import "./css/GUICanvas.css";
4-
5-
const CarJunction = (props) => {
6-
7-
const [carPose, setCarPose] = React.useState(null)
8-
const canvasRef = React.useRef(null)
2+
import PropTypes from "prop-types";
3+
import { drawImage } from "./helpers/showImagesFollowRoad";
4+
import noImage from "../../assets/img/noImage.png";
95

6+
import "./css/GUICanvas.css"
7+
function CarJunction(props) {
108
React.useEffect(() => {
119
console.log("TestShowScreen subscribing to ['update'] events");
1210
const callback = (message) => {
13-
if(message.data.update.image){
14-
const image = JSON.parse(message.data.update.image)
15-
if(image.image){
16-
let canvas = document.getElementById("canvas");
17-
//Parse encoded image data and decode it
18-
function decode_utf8(s) {
19-
return decodeURIComponent(escape(s))
20-
}
21-
var source = decode_utf8(image.image),
22-
shape = image.shape;
11+
console.log(message);
2312

24-
if(source !== ""){
25-
canvas.src = "data:image/png;base64," + source;
26-
canvas.width = shape[1];
27-
canvas.height = shape[0];
28-
}
29-
}
30-
try {
31-
const pose = message.data.update.map
32-
setCarPose(pose)
33-
} catch (error) {
34-
35-
}
13+
if (message.data.update.image_front) {
14+
console.log("image_front");
15+
drawImage(message.data.update);
3616
}
37-
17+
// Send the ACK of the msg
3818
window.RoboticsExerciseComponents.commsManager.send("gui", "ack");
3919
};
4020

@@ -52,57 +32,16 @@ const CarJunction = (props) => {
5232
};
5333
}, []);
5434

55-
React.useEffect(() => {
56-
const callback = (message) => {
57-
console.log(message)
58-
if (message.data.state === "application_running") {
59-
window.RoboticsExerciseComponents.commsManager.send("gui", "start");
60-
} else if (message.data.state === "paused") {
61-
window.RoboticsExerciseComponents.commsManager.send("gui", "pause");
62-
} else if (message.data.state === "tools_ready") {
63-
setCarPose(null)
64-
}
65-
}
66-
67-
window.RoboticsExerciseComponents.commsManager.subscribe(
68-
[window.RoboticsExerciseComponents.commsManager.events.STATE_CHANGED],
69-
callback
70-
);
71-
72-
return () => {
73-
console.log("TestShowScreen unsubscribing from ['state-changed'] events");
74-
window.RoboticsExerciseComponents.commsManager.unsubscribe(
75-
[window.RoboticsExerciseComponents.commsManager.events.STATE_CHANGED],
76-
callback
77-
);
78-
};
79-
}, [])
80-
8135
return (
82-
<Box sx={{ height: "100%", position: "relative"}}>
83-
<img ref={canvasRef} className={"exercise-canvas"} id="canvas"></img>
84-
{carPose && (
85-
<div className="overlay" style={{
86-
position: 'absolute',
87-
bottom: '20px',
88-
left: '20px',
89-
backgroundColor: 'rgba(0,0,0,0.7)',
90-
color: 'white',
91-
padding: '10px',
92-
borderRadius: '5px',
93-
fontFamily: 'monospace',
94-
fontSize: '16px'
95-
}}>
96-
Position: {carPose}
97-
</div>
98-
)}
99-
</Box>
36+
<div style={{display: "flex", width: "100%", height: "100%",justifyContent: "center", alignItems: "center"}}>
37+
<img className="image" id="gui_canvas_front" style={{ maxWidth: "100%", maxHeight: "100%" }}
38+
src={noImage}/>
39+
</div>
10040
);
101-
};
41+
}
10242

103-
CarJunction.defaultProps = {
104-
width: 800,
105-
height: 600,
43+
CarJunction.propTypes = {
44+
circuit: PropTypes.string,
10645
};
10746

108-
export default CarJunction
47+
export default CarJunction;

0 commit comments

Comments
 (0)