-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc.js
More file actions
103 lines (91 loc) · 3.36 KB
/
calc.js
File metadata and controls
103 lines (91 loc) · 3.36 KB
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
import LatLon from 'https://cdn.jsdelivr.net/npm/geodesy@2.2.1/latlon-spherical.min.js';
export class CalcVR {
constructor() {
this.distance = 0;
this.bearing = 0;
this.newPosition = [0, 0];
this.currentPosition = [0, 0];
this.objectSize = '0, 0, 0';
this.newDistance = 800;
}
calcDist(currentPosiArg, targetPosition) {
const current = new LatLon(currentPosiArg[0], currentPosiArg[1]);
const target = new LatLon(targetPosition[0], targetPosition[1]);
this.distance = current.distanceTo(target);
this.bearing = current.finalBearingTo(target)
this.currentPosition = currentPosiArg;
}
calcNewPosition(currentPosition, bearing, newTargetToDistance) {
const current = new LatLon(currentPosition[0], currentPosition[1]);
const calculatedlced = current.destinationPoint(newTargetToDistance, bearing);
this.newPosition = [calculatedlced.latitude, calculatedlced.longitude];
}
calcSizeDist(distance) {
if(distance <= 1000 && distance >= 500){
this.objectSize = '25 25 25';
this.newDistance = 800;
}else if(distance > 1000 && distance <= 8000) {
this.objectSize = '20 20 20';
this.newDistance = 800 + (distance/1000);
}else if(distance > 8000 && distance <= 16000) {
this.objectSize = '18 18 18';
this.newDistance = 800 + (distance/1000);
}else if(distance > 16000 && distance <= 20000) {
this.objectSize = '15 15 15';
this.newDistance = 800 + (distance/1000);
}else if(distance > 20000) {
this.objectSize = '10 10 10';
this.newDistance = 800 + (distance/1000);
}
}
}
window.onload = () => {
navigator.geolocation.getCurrentPosition(success, error, options);
};
function staticLoadPlaces() {
return [
{
name: 'Time Desk',
location: {
lat: 43.062533,
lng: 141.353638,
}
},
];
}
function renderPlaces(places, pos) {
let scene = document.querySelector('a-scene');
var crd = pos.coords;
let cal = new CalcVR();
places.forEach((place) => {
let latitude = place.location.lat;
let longitude = place.location.lng;
let name = place.name;
let modelName = place.modelName;
cal.calcDist([crd.latitude, crd.longitude], [latitude, longitude]);
console.log(`heading: ${ crd.heading }`);
cal.calcNewPosition(cal.currentPosition, cal.bearing, cal.newDistance);
cal.calcSizeDist(cal.distance);
let model = document.createElement('a-box');
model.setAttribute('material', 'color: red');
model.setAttribute('gps-entity-place', `latitude: ${cal.newPosition[0]}; longitude: ${cal.newPosition[1]};`);
model.setAttribute('scale', `${cal.objectSize}`);
model.addEventListener('loaded', () => {
window.dispatchEvent(new CustomEvent('gps-entity-place-loaded'))
});
scene.appendChild(model);
});
}
var options = {
enableHighAccuracy: true,
timeout: 50000,
maximumAge: 0
};
function success(pos) {
let places = staticLoadPlaces();
renderPlaces(places, pos);
}
function error(err) {
console.warn(`ERROR(${err.code}): ${err.message}`);
alert('Unable to capture current location.');
}