forked from CSI-IITBHU/Augnex-2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.html
357 lines (304 loc) · 11.2 KB
/
home.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Cache-control" content="public" />
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Navigation</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha256-kLaT2GOSpHechhsozzB+flnD+zUyjE2LlfWPgU04xyI=" crossorigin="" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-WBkoXOwTeyKclOHuWtc+i2uENFpDZ9YPdf5Hf+D7ewM=" crossorigin=""></script>
<script src="https://aframe.io/releases/1.4.1/aframe.min.js"></script>
<script src="https://raw.githack.com/jeromeetienne/AR.js/master/aframe/build/aframe-ar.min.js"></script>
<script src="https://unpkg.com/browse/[email protected]/dist/aframe-look-at-component.min.js"></script>
<script>
THREEx.ArToolkitContext.baseURL =
"https://raw.githack.com/jeromeetienne/ar.js/master/three.js/";
</script>
<link rel="stylesheet" href="./index.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />
<link rel="icon" href="favicon.png" type="image/gif" sizes="16x16" />
</head>
<body style="margin: 0; overflow: hidden; ">
<a-scene cursor="rayOrigin: mouse; fuse: true; fuseTimeout: 0;" raycaster="objects: [gps-new-entity-place];"
vr-mode-ui="enabled: false" embedded
arjs="sourceType: webcam; sourceWidth:1280; sourceHeight:960; displayWidth: 1280; displayHeight: 960; debugUIEnabled: false;">
<!--will be "gps-new-camera" in update version -->
<a-camera gps-new-camera='minDistance: 5' rotation-reader> </a-camera>
</a-scene>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#routes" style=" position: fixed;
bottom: 0;
width: 100vw;
left: 50%;
right: 50%;
margin-left: -50vw;
margin-right: -50vw;
">
Where do you want to go
</button>
<!-- Main modal body -->
<div id="routes" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="LargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myLargeModalLabel">Routes</h4>
<button type="button" id="close-modal-btn" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div id="main-modal-body" class="modal-body main-modal-body" style="padding:0">
<!-- Here all main locations will be appended using main_locations_array -->
</div>
</div>
</div>
</div>
<!-- Next modal body -->
<div id="next-routes" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="LargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myLargeNextModalLabel"></h4>
<button type="button" id="close-next-modal-btn" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div id="next-modal-body" class="modal-body next-modal-body" style="padding:0"></div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script src="./ar.js"></script>
<script>
// coords = current position coordinates , end = destination coords
const loadPlaces = function (coords, end) {
// console.log(end);
return loadPlaceFromAPIs(coords, end);
};
// getting places from REST APIs
// returns a set of coords from current location to destination
function loadPlaceFromAPIs(position, end) {
var endpoint = `https://api.openrouteservice.org/v2/directions/foot-walking?api_key=5b3ce3597851110001cf6248449df15745a3444cae6960e8202aa401&start=${position.longitude},${position.latitude}&end=${end.long},${end.lat}`;
return fetch(endpoint)
.then(res => {
return res.json().then(resp => {
// console.log(resp);
var data = [];
data = data.concat(resp.features["0"].geometry.coordinates);
// console.log(data);
return data;
});
})
.catch(err => {
console.error("Error with places API", err);
});
}
</script>
<script>
// var navbutton = [
// {
// name: "KR",
// lat: 23.365088,
// long: 85.253257
// }
// ];
// Data for all the locations
var main_locations_array = [
{ ind: 0, name: "Hostels"},
{ ind: 1, name: "Famous Spots"},
{ ind: 2, name: "Lecture Theatres"},
{ ind: 3, name: "Grounds"},
{ ind: 4, name: "Offices"},
{ ind: 5, name: "Main Gates"},
]
var hostels_navbutton = [
{
name: "Vishwakarma Hostel",
lat: 25.257578,
long: 82.985853
},
{
name: "Visvesvaraya Hostel",
lat: 25.263038,
long: 82.983882
},
{
name: "Aryabhatta Hostel",
lat: 25.263944,
long: 82.984399
},
{
name: "Girls Hostel",
lat: 25.261037,
long: 82.98345
},
{
name: "SC Dey",
lat: 25.260237,
long: 82.987016
}
]
var famousspots_navbutton = [
{
name: "LC",
lat: 25.260911,
long: 82.986833
},
{
name: "CCD",
lat: 25.258057,
long: 82.98686
},
{
name: "Vishwanath Temple",
lat: 25.26568,
long: 82.989624
},
{
name: "Swatantrata Bhavan",
lat: 25.260576,
long: 82.993757
},
{
name: "Guest House",
lat: 25.26014,
long: 82.9848
},
{
name: "Library",
lat: 25.261804,
long: 82.989914
},
]
var lecturetheatres_navbutton = [
{
name: "G1-G11",
lat: 25.262131,
long: 82.992954
},
{
name: "LT3",
lat: 25.260209,
long: 82.99055
},
{
name: "ABLT",
lat: 25.263182,
long: 82.988691
},
]
var grounds_navbutton = [
{
name: "ADV Ground",
lat: 25.259153,
long: 82.989267
},
]
var offices_navbutton = [
{
name: "Technex Office",
lat: 25.261372,
long: 82.986774
},
]
var maingates_navbutton = [
{
name: "Hyderabad Gate",
lat: 25.262909,
long: 82.982231
},
]
var navbutton_array = [hostels_navbutton, famousspots_navbutton, lecturetheatres_navbutton, grounds_navbutton, offices_navbutton, maingates_navbutton]
$(window).on("load", () => {
// render the model
main_locations_array.forEach(button => {
$(".main-modal-body").append(
`<button type="button" id="${button.ind}" data-toggle="modal" data-target="#next-routes" class="modal-loc-type-btn list-group-item list-group-item-action">
${button.name}
</button>`
);
});
$(`.modal-loc-type-btn`).click(function(e) {
// Getting the data of which option(button) is clicked in the main modal
var btn_index = e.target.id;
var btn_name = e.target.innerText;
// Closing the main modal
$('#routes').modal("hide");
// Removing the already existing content inside the title and body of the next modal respectively
let modal_title_removing = document.getElementById("myLargeNextModalLabel");
modal_title_removing.textContent = "";
let modal_body_removing = document.getElementById("next-modal-body");
modal_body_removing.textContent = "";
// Displaying 'btn_name' as title on the next-modal
$("#myLargeNextModalLabel").append(btn_name)
var next_modal_navbutton = navbutton_array[btn_index]
// Displaying all the choices in the body of the next-modal
next_modal_navbutton.forEach(button => {
console.log('chutiye!')
$(".next-modal-body").append(`<button
lat="${button.lat}"
long="${button.long}"
type="button"
class="list-group-item list-group-item-action"
>
${button.name}
</button>`);
});
})
// will be called when destination is selected
// ... fetch al coordinates from current coords to desti coords
// .. display markers at all those locations
function drawpath(end) {
console.log("drawpath k andar :", end)
const scene = document.querySelector("a-scene");
// get the current location coords
return navigator.geolocation.getCurrentPosition(
function (position) {
loadPlaces(position.coords, end).then(places => {
places.forEach(place => {
const latitude = place[1];
const longitude = place[0];
const icon = document.createElement("a-image");
icon.setAttribute(
"gps-new-entity-place", // will be gps-new-entity-place in latest versoion
`latitude: ${latitude + + 0.001};
longitude: ${longitude};`
);
// icon.setAttribute("name", place.properties.name);
icon.setAttribute("src", "./map-marker.png");
icon.setAttribute("look-at", "[gps-new-camera]");
icon.setAttribute("scale", "5,5,5");
// console.log(icon);
icon.addEventListener('loaded', () => {
window.dispatchEvent(new CustomEvent('gps-entity-place-loaded'))
});
scene.appendChild(icon);
});
});
},
err => alert("Error in retrieving position"), // console.error(, err),
{
enableHighAccuracy: true,
maximumAge: 0,
timeout: 27000
}
);
}
// define the click event
$(".next-modal-body").click(e => {
console.log('next modal ke button ko click kar diya')
console.log("event :", e.target)
$("#next-routes").modal("hide");
$("a-image").remove();
// console.log($(e.target).attr("lat"));
// end => coordinates of the selected destination
var end = {
lat: $(e.target).attr("lat"),
long: $(e.target).attr("long")
};
console.log(end);
drawpath(end);
});
});
</script>
</body>
</html>