Skip to content

Commit a895fd1

Browse files
committed
Update globalnav
1 parent 1ab3d58 commit a895fd1

File tree

1 file changed

+12
-38
lines changed
  • exercises/static/exercises/global_navigation/react-components

1 file changed

+12
-38
lines changed

exercises/static/exercises/global_navigation/react-components/WebGUI.js

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import { useExercise } from "Contexts/ExerciseContext";
44
import {updatePath} from "./helpers/GlobalNavigationHelper";
55
import Car from "../resources/images/car-top-view.svg";
66
import CityMap from "../resources/images/cityLargenBin.png";
7-
7+
import WebGUIImage from "Components/exercise/WebGUIImage";
8+
import WebGUIContainer from "Components/exercise/WebGUIContainer";
89
import "./css/GUICanvas.css";
910

1011
var coords = undefined;
1112

1213
function WebGUI(props) {
13-
const [showImage, setShowImage] = useState(false);
1414
const [carPose, setCarPose] = useState(null)
1515
const [destination, setDestination] = useState(null)
1616
const [path, setPath] = useState("")
17+
const [userImage, setUserImage] = useState(undefined);
1718
const exerciseContext = useExercise();
1819
const [manager, setManager] = useState(exerciseContext.manager);
1920

@@ -61,20 +62,10 @@ function WebGUI(props) {
6162
}
6263

6364
const getImageAndDisplay = (data) => {
64-
if(data.image) {
65-
let canvas = document.getElementById("gui-canvas-numpy");
66-
//Parse encoded image data and decode it
67-
function decode_utf8(s) {
68-
return decodeURIComponent(escape(s))
69-
}
70-
var image_data = JSON.parse(data.image),
71-
source = decode_utf8(image_data.image),
72-
shape = image_data.shape;
73-
74-
if(source !== ""){
75-
canvas.src = "data:image/png;base64," + source;
76-
canvas.width = shape[1];
77-
canvas.height = shape[0];
65+
if (data.image) {
66+
let image = JSON.parse(data.image);
67+
if (image.image != "" && image.shape instanceof Array) {
68+
setUserImage(`data:image/png;base64,${image.image}`);
7869
}
7970
}
8071
}
@@ -106,12 +97,11 @@ function WebGUI(props) {
10697
console.log(message.data.state)
10798
if (message.data.state === "tools_ready") {
10899
showMap = false
109-
setShowImage(false)
110100
trail = []
111101
setPath("")
102+
setUserImage()
112103
} else {
113104
showMap = true
114-
setShowImage(true)
115105
// Resend Target
116106
console.log("Resend target:", coords)
117107
if (coords) {
@@ -153,7 +143,8 @@ function WebGUI(props) {
153143
}
154144

155145
return (
156-
<div style={{display: "flex", width: "100%", height: "100%", position:"relative"}}>
146+
<WebGUIContainer>
147+
{/* <WebGUIImage id="left_img" style={{ left: "0" }} src={CityMap} /> */}
157148
<img src={CityMap} alt="" className="exercise-canvas" id="exercise-img"
158149
onClick={ function pickLoc(event){
159150
var data = destinationPicker(event)
@@ -177,25 +168,8 @@ function WebGUI(props) {
177168
/>
178169
</svg>
179170
}
180-
{ showImage ?
181-
(
182-
<img id="gui-canvas-numpy" width="400" height="400" style={{
183-
position: "absolute",
184-
left: "50%",
185-
width: "50%",
186-
height: "100%",
187-
}}></img>
188-
) : (
189-
<div id="gui-canvas-numpy-empty" width="400" height="400" style={{
190-
position: "absolute",
191-
left: "50%",
192-
width: "50%",
193-
height: "100%",
194-
backgroundColor: "#000000"
195-
}}></div>
196-
)
197-
}
198-
</div>
171+
<WebGUIImage id="user-img" style={{ left: "50%" }} src={userImage} />
172+
</WebGUIContainer>
199173
);
200174
}
201175

0 commit comments

Comments
 (0)