summaryrefslogtreecommitdiff
path: root/misc/openlayers/examples/accelerometer.html
blob: 07215192cac32a06a4fb8de250011e1a82dc031b (plain)
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
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <title>OpenLayers Accelerometer Usage</title>
    <link rel="stylesheet" href="../theme/default/style.css" type="text/css">
    <link rel="stylesheet" href="style.css" type="text/css">
    <script type="text/javascript" src="browser.js"></script>

    <style type="text/css">
        .olControlAttribution {
            bottom: 5px;
        }
    </style>
    <script type="text/javascript">
        function init() {
            if (isEventSupported('deviceorientation', window) || isEventSupported('mozorientation', window) || isEventSupported('devicemotion', window)) {
                if (window.DeviceOrientationEvent) {
                    window.addEventListener("deviceorientation", function (event) {
                        document.getElementById('resultDeviceOrientation').innerHTML = '';
                        if (typeof(event.alpha) != 'undefined') {
                            document.getElementById('resultDeviceOrientation').innerHTML = document.getElementById('resultDeviceOrientation').innerHTML + "Alpha: " + event.alpha + "<br>";
                            document.getElementById('resultDeviceOrientation').innerHTML = document.getElementById('resultDeviceOrientation').innerHTML + "Beta: " + event.beta + "<br>";
                            document.getElementById('resultDeviceOrientation').innerHTML = document.getElementById('resultDeviceOrientation').innerHTML + "Gamma: " + event.gamma + "<br>";
                        }
                        if (typeof(event.absolute) != 'undefined') {
                            document.getElementById('resultDeviceOrientation').innerHTML = document.getElementById('resultDeviceOrientation').innerHTML + "Gamma: " + event.absolute + "<br>";
                        }
                        if (typeof(event.compassCalibrate) != 'undefined') {
                            document.getElementById('resultDeviceOrientation').innerHTML = document.getElementById('resultDeviceOrientation').innerHTML + "Gamma: " + event.compassCalibrated + "<br>";
                        }
                    }, true);
                }
                if (window.DeviceMotionEvent) {
                    window.addEventListener('devicemotion', function (event) {
                        document.getElementById('resultDeviceMotion').innerHTML = '';
                        if (typeof(event.accelerationIncludingGravity) != 'undefined') {
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "accelerationIncludingGravity.x: " + event.accelerationIncludingGravity.x + "<br>";
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "accelerationIncludingGravity.y: " + event.accelerationIncludingGravity.y + "<br>";
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "accelerationIncludingGravity.z: " + event.accelerationIncludingGravity.z + "<br>";
                        }
                        if (typeof(event.acceleration) != 'undefined') {
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "acceleration.x: " + event.acceleration.x + "<br>";
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "acceleration.y: " + event.acceleration.y + "<br>";
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "acceleration.z: " + event.acceleration.z + "<br>";
                        }
                        if (typeof(event.rotationRate) != 'undefined') {
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "rotationRate.alpha: " + event.rotationRate.alpha + "<br>";
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "rotationRate.beta: " + event.rotationRate.beta + "<br>";
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "rotationRate.gamma: " + event.rotationRate.gamma + "<br>";
                        }
                    }, true);
                }
                if (window.MozOrientation) {
                    window.addEventListener("MozOrientation", function (orientation) {
                        document.getElementById('resultMozOrientation').innerHTML = "orientation.x: " + orientation.x + "<br>";
                        document.getElementById('resultMozOrientation').innerHTML = document.getElementById('resultMozOrientation').innerHTML + "orientation.y: " + orientation.y + "<br>";
                        document.getElementById('resultMozOrientation').innerHTML = document.getElementById('resultMozOrientation').innerHTML + "orientation.z: " + orientation.z + "<br>";
                    }, true);
                }
            } else {
                alert("Unfortunately, your brower doesn't support the orientation usage");
            }

        }
    </script>
</head>
<body onload="init()">
<h1 id="title">Accelerometer</h1>

<p id="shortdesc">
    The goal of this script is to demonstrate the usage of accelerometer.
</p>
<p>
  The orientation specification can be found <a href="http://dev.w3.org/geo/api/spec-source-orientation.html">here</a>.
</p>

<div id="tags">
  browser, vendor, mobile, orientation 
</div>  

<h1>Device motion</h1>

<div id="resultDeviceMotion">

</div>
<h1>Device orientation</h1>

<div id="resultDeviceOrientation">

</div>
<h1>MOZ orientation</h1>

<div id="resultMozOrientation">

</div>
</body>
</html>