-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13_Device_Orientation.html
75 lines (66 loc) · 2.66 KB
/
13_Device_Orientation.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<link rel="stylesheet" href="https://openlayers.org/en/v5.3.0/css/ol.css" type="text/css">
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://unpkg.com/[email protected]/dist/gyronorm.complete.min.js"></script>
</head>
<body>
<!-- 기본틀로 사용하는 양식 -->
<div id="map" class="map"></div>
<p>
<div>α : <code id="alpha"></code></div>
<div>β : <code id="beta"></code></div>
<div>γ : <code id="gamma"></code></div>
</p>
<p>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e2/3D_Gyroscope.png/250px-3D_Gyroscope.png">
</p>
<script>
var view = new ol.View({
center: [0, 0],
zoom: 2
});
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map',
view: view
});
function el(id) {
return document.getElementById(id);
}
//https://github.com/dorukeker/gyronorm.js/
//웹 브라우저에서 자이로 스코프 및 가속도계 데이터에 액세스하고이를 하나의 JS 객체에 결합합니다.
//장치에 테스트 가능
var gn = new GyroNorm();
gn.init().then(function() {
gn.start(function(event) {
var center = view.getCenter();
var resolution = view.getResolution(); //초기 해상도
var alpha = toRadians(300);
var beta = toRadians(100);
var gamma = toRadians(90);
el('alpha').innerText = alpha + ' [rad]';
el('beta').innerText = beta + ' [rad]';
el('gamma').innerText = gamma + ' [rad]';
center[0] -= resolution * gamma * 25;
center[1] += resolution * beta * 25;
view.setCenter(view.constrainCenter(center));
});
});
//ol.math.toRadians 존재하지않음 노드 패키지안에만 존재하는 것 같으므로 직접 func 작성
toRadians = function (angleInDegrees) {
return angleInDegrees * Math.PI / 180;
}
</script>
</body>
</html>