-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathar1101-dynamic-content-array.html
79 lines (71 loc) · 2.88 KB
/
ar1101-dynamic-content-array.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<title>WebAR: Dynamic Content from Array</title>
<script src="./js/aframe/aframe.min.js"></script>
<script src="./js/arjs/aframe-ar.js"></script>
</head>
<body style="margin : 0px; overflow: hidden;">
<a-scene embedded vr-mode-ui="enabled: false" arjs="detectionMode: mono_and_matrix; matrixCodeType: 3x3; debugUIEnabled: false;">
<!-- add a simple camera -->
<a-entity camera></a-entity>
</a-scene>
<script>
// mengakses DOM scene
scene = document.querySelector("a-scene");
// Fungsi membuat obyek tulisan pada a-frame
function listRuang(ruang, scenel) {
for (let i = 0; i < ruang.length; i++) {
let marker = document.createElement("a-marker");
marker.setAttribute("type", "barcode");
marker.setAttribute("value", i + 1);
let labelRuangan = document.createElement("a-text");
let informasi = "";
informasi += ruang[i].nama + " sedang " + ruang[i].dipakai;
labelRuangan.setAttribute("value", informasi);
labelRuangan.setAttribute("rotation", "-90 0 0");
labelRuangan.setAttribute("color", "green");
labelRuangan.setAttribute("align", "center");
marker.appendChild(labelRuangan);
scenel.appendChild(marker);
}
}
// Variabel penampung nilai dari server
let ruanganJSON = {};
// Membuat data array lokal
let ruangan = [{
"nama": "H17",
"dipakai": "dipakai"
}, {
"nama": "H18",
"dipakai": "dipakai"
}, {
"nama": "H19",
"dipakai": " tidak dipakai"
}, {
"nama": "H20",
"dipakai": "dipakai"
}, ]
// Isi nilai dengan data yang ada
ruanganJSON = ruangan;
// Membuat obyek dari data array lokal
// listRuang(ruangan, scene); // membuat obyek
for (let i = 0; i < ruangan.length; i++) {
let marker = document.createElement("a-marker");
marker.setAttribute("type", "barcode");
marker.setAttribute("value", i + 1);
let labelRuangan = document.createElement("a-text");
let informasi = "";
informasi += ruangan[i].nama + " sedang " + ruangan[i].dipakai;
labelRuangan.setAttribute("value", informasi);
labelRuangan.setAttribute("rotation", "-90 0 0");
labelRuangan.setAttribute("color", "blue");
labelRuangan.setAttribute("align", "center");
marker.appendChild(labelRuangan);
scene.appendChild(marker);
}
</script>
</body>
</html>