-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
254 lines (215 loc) · 6.5 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.8.3/angular.min.js" integrity="sha512-KZmyTq3PLx9EZl0RHShHQuXtrvdJ+m35tuOiwlcZfs/rE7NZv29ygNA8SFCkMXTnYZQK2OX0Gm2qKGfvWEtRXA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<style>
body {
background-color: black;
color: red;
margin: 10px;
}
table:first-child td:first-child
{
text-align: right;
}
table
{
white-space: pre;
}
canvas
{
max-width: 100%;
margin: 0px auto;
display: block;
}
</style>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AstroTool</title>
</head>
<body ng-app="app" ng-controller="controller">
<table>
<tr>
<td>Latitude:</td>
<td>{{position.coords.latitude | latdeg}} ({{position.coords.latitude}})</td>
</tr>
<tr>
<td>Longitude:</td>
<td>{{position.coords.longitude | longdeg}} ({{position.coords.longitude}})</td>
</tr>
<tr>
<td>Altitude:</td>
<td>{{position.coords.altitude | number: 0}} m</td>
</tr>
<tr>
<td>Date:</td>
<td>{{ currentDate | date:'MM/dd/yyyy' : 'GMT'}} GMT ({{ currentDate | date:'MM/dd/yyyy'}})</td>
</tr>
<tr>
<td>Time:</td>
<td>{{ currentDate | date:'HH:mm:ss' : 'GMT'}} GMT ({{ currentDate | date:'HH:mm:ss'}})</td>
</tr>
<tr>
<td>Temperature:</td>
<td>{{weather.main.temp}} °C</td>
</tr>
<tr>
<td>Humidity:</td>
<td>{{weather.main.humidity}} %RH</td>
</tr>
<tr>
<td>Clouds:</td>
<td>{{weather.clouds.all}} %</td>
</tr>
</table>
<canvas id="compass" style="border: 0px solid red" width="400" height="400"></canvas>
<script>
function Compass(ctx)
{
var self = this;
var compassdir = 0;
this.draw = function()
{
var width = ctx.canvas.width;
var height = ctx.canvas.height;
var px = width / 2;
var py = height / 2;
var cf = {
scale: {
size0: width / 2 - 30 + 15, // text
size1: width / 2 - 30 + 0, // line
size2: width / 2 - 30 - 10, // line
size3: width / 2 - 30 - 10 - 20
}
};
ctx.clearRect(0, 0, width, height);
ctx.beginPath();
ctx.strokeStyle = '#500';
ctx.moveTo(px, height);
ctx.lineTo(px, 0);
ctx.moveTo(0, py);
ctx.lineTo(width, py);
ctx.closePath();
ctx.stroke();
ctx.beginPath();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = 'white';
//var offset = (compassdir + 90) / 360 * 2 * Math.PI;
var offset = compassdir;
for(var i=0; i<12; ++i)
{
var sin = Math.sin(2*Math.PI * i / 12 + offset);
var cos = Math.cos(2*Math.PI * i / 12 + offset);
var x0 = px + (cf.scale.size0) * sin;
var y0 = py - (cf.scale.size0) * cos;
var x1 = px + (cf.scale.size1) * sin;
var y1 = py - (cf.scale.size1) * cos;
var x2 = px + (cf.scale.size2) * sin;
var y2 = py - (cf.scale.size2) * cos;
var x3 = px + (cf.scale.size3) * sin;
var y3 = py - (cf.scale.size3) * cos;
ctx.font = "15px Arial";
ctx.fillText(parseInt(i*360 / 12), x0, y0);
if ((i % 3) == 0)
{
ctx.font = "35px Arial";
ctx.fillText(['N', 'E', 'S', 'W'][parseInt(i/3)], x3, y3);
}
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
}
ctx.lineWidth = 2;
ctx.strokeStyle = 'white';
ctx.closePath()
ctx.stroke();
};
let sensor = new AbsoluteOrientationSensor({ frequency: 30 });
sensor.addEventListener('reading', function(e) {
var q = e.target.quaternion;
var a = Math.atan2(2*q[0]*q[1] + 2*q[2]*q[3], 1 - 2*q[1]*q[1] - 2*q[2]*q[2]);
compassdir = a;
self.draw();
});
self.draw();
sensor.start();
/*
if (window.DeviceOrientationEvent) {
// Listen for the deviceorientation event and handle the raw data
window.addEventListener('deviceorientation', function(eventData) {
compassdir = event.webkitCompassHeading ? event.webkitCompassHeading : event.alpha;
//$scope.$apply;
self.draw();
});
}
*/
}
new Compass(document.getElementById("compass").getContext('2d'));
var app = angular.module('app', []);
function geoToAbsString(degree)
{
var geoSeconds = Math.abs(parseInt(degree * 60 * 60));
const pad = ' ';
return (pad + parseInt(geoSeconds/60/60) ).slice(-3) + "° " +
(pad + parseInt(geoSeconds/60 ) % 60).slice(-2) + "' " +
(pad + parseInt(geoSeconds ) % 60).slice(-2) + "'' ";
}
app.filter('latdeg', function()
{
return function(degree)
{
return geoToAbsString(degree) + (degree > 0 ? 'N' : 'S');
}
});
app.filter('longdeg', function()
{
return function(degree)
{
return geoToAbsString(degree) + (degree > 0 ? 'E' : 'W');
}
});
app.controller('controller', ['$scope', '$http', '$timeout', '$interval', function($scope, $http, $timeout, $interval){
$scope.position = {};
var gotGeo = false;
function updateGeo()
{
navigator.geolocation.getCurrentPosition(function(position)
{
$scope.position = position;
if (gotGeo == false)
{
gotGeo = true;
updateWeather();
}
$scope.$apply();
});
$timeout(updateGeo, 10 * 1000);
}
function updateWeather()
{
$http({
method: 'GET',
url: '//api.openweathermap.org/data/2.5/weather',
params: {
lat: $scope.position.coords.latitude,
lon: $scope.position.coords.longitude,
units: 'metric',
appid: '4f08bf0829032ef19cda55a9279aae71'
}
}).then(function(response){
$scope.weather = response.data;
console.log(response.data);
});
$timeout(updateWeather, 30 * 1000);
}
function updateTime()
{
$scope.currentDate = (new Date());
$timeout(updateTime, 0.2 * 1000);
}
updateGeo();
updateTime();
}]);
</script>
</body>
</html>