Merge branch 'master' of github.com:keith24/Compass

master
Keith Irwin 2020-03-29 22:11:51 -05:00
commit 7809c0a5ec
No known key found for this signature in database
GPG Key ID: 7A2D6993A44010AA
29 changed files with 75 additions and 68 deletions

0
.gitignore vendored Normal file → Executable file
View File

0
LICENSE.md Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

47
coordinates.js Executable file
View File

@ -0,0 +1,47 @@
'use strict'
/* global navigator $ */
// Set units based on browser locale
const metric = !(window.navigator.language=='en-US'||window.navigator.language=='my')
// Check for GPS capability
if (!navigator.geolocation) $('#no-gps').show()
// Start tracking
else navigator.geolocation.watchPosition(
// Got location callbackw
function(pos) {
let lat = pos.coords.latitude.toFixed(4)
let lon = pos.coords.longitude.toFixed(4)
$('#lat').text(
(lat.substring(0,1)=='-')? // Negative values are South
lat.substring(1)+' S' : lat+' N'
)
$('#lon').text(
(lon.substring(0,1)=='-')? // Negative values are East
lon.substring(1)+' W' : lon+' E'
)
// Get altitude
if (pos.coords.altitude) {
$('#alt').show().text(
(metric)? // Convert to feet if needed
pos.coords.altitude.toFixed(1)+' m':
(pos.coords.altitude*3.28084).toFixed(1)+' ft'
)
}
else $('#alt').hide()
},
// Got error
function() {
$('.coord').hide()
$('#no-gps').show()
},
// Options
{ enableHighAccuracy:true }
)

21
direction.js Normal file
View File

@ -0,0 +1,21 @@
'use strict'
/* global $ window */
window.addEventListener('deviceorientation', function(e){
// No orientation data
if(!e) $('#no-dir').show()
// Set orientation
else {
$('#no-dir').hide()
const rot = 'rotate('+e.alpha.toString().substring(0,5)+'deg)'
$('#rose').css({
'-ms-transform': rot,
'-webkit-transform': rot,
'transform': rot
})
}
}, true)

0
icons/apple-touch-icon-114x114.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

0
icons/apple-touch-icon-120x120.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

0
icons/apple-touch-icon-144x144.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

0
icons/apple-touch-icon-152x152.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

0
icons/apple-touch-icon-57x57.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

0
icons/apple-touch-icon-60x60.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

0
icons/apple-touch-icon-72x72.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

0
icons/apple-touch-icon-76x76.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

0
icons/favicon-128.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

0
icons/favicon-16x16.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 693 B

After

Width:  |  Height:  |  Size: 693 B

0
icons/favicon-196x196.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

0
icons/favicon-32x32.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

0
icons/favicon-96x96.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

0
icons/favicon.ico Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

0
icons/mstile-144x144.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

0
icons/mstile-150x150.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

0
icons/mstile-310x150.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 64 KiB

0
icons/mstile-310x310.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 125 KiB

After

Width:  |  Height:  |  Size: 125 KiB

0
icons/mstile-70x70.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

10
index.html Normal file → Executable file
View File

@ -47,8 +47,8 @@
<header>
<div class='error' id='no-gps'>No GPS data available. </div>
<div class='coord' id='lat'>0.00000 N</div>
<div class='coord' id='lon'>0.00000 E</div>
<div class='coord' id='lat'>0.0000 N</div>
<div class='coord' id='lon'>0.0000 W</div>
<div class='coord' id='alt'></div>
@ -58,7 +58,6 @@
<noscript>You need javascript to use this. </noscript>
<div class='error' id='no-dir'>No direction available. Try this on a smartphone with an internal compass.</div>
<div class='error' id='rotated'>Note: the compass may be 90&deg; off when used in landscape mode.</div>
<img id='rose' src="rose.svg">
@ -66,11 +65,12 @@
<footer>
<div id='about'><a href="https://github.com/keith24/Compass/blob/master/README.md">About</a></div>
<div id='by'>by <a href="https://keithirwin.us/">Keith Irwin</a></div>
<div id='by'>by <a href="https://www.keithirwin.us/">Keith Irwin</a></div>
</footer>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="script.js"></script>
<script src="coordinates.js"></script>
<script src="direction.js"></script>
</body>

0
manifest.webmanifest → manifest.json Normal file → Executable file
View File

0
rose.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

View File

@ -1,61 +0,0 @@
'use strict';
/* global navigator $ */
// Set units based on browser locale
const metric = !(window.navigator.language=='en-US'||window.navigator.language=='my');
// Track GPS location
if (!navigator.geolocation){ $('#no-gps').show(); }
else { navigator.geolocation.watchPosition(
// Got location
function(pos) {
let lat = pos.coords.latitude.toFixed(4);
let lon = pos.coords.longitude.toFixed(4);
$('#lat').text((lat.substring(0,1)=='-')? lat.substring(1)+' S' : lat+' N');
$('#lon').text((lon.substring(0,1)=='-')? lon.substring(1)+' E' : lon+' W');
// Get altitude
if (pos.coords.altitude){
var alt = (metric)? pos.coords.altitude.toFixed(1)+' m':(pos.coords.altitude*0.3048).toFixed(1)+' ft';
$('#alt').show().text(alt);
}
else {
$('#alt').hide();
}
},
// Got error
function() {
$('.coord').hide();
$('#rotated').hide();
$('#no-gps').show();
},
// Options
{ enableHighAccuracy:true }
);
}
// Set compass orientation
function setRose(e) {
// No orientation data
if(!e.absolute) {
$('#rotated').hide();
$('#no-dir').show();
}
// Set orientation
else {
var rot = 'rotate('+e.alpha.toString().substring(0,5)+'deg)';
$('#rose').css({
'-ms-transform': rot,
'-webkit-transform': rot,
'transform': rot
});
}
}
window.addEventListener("deviceorientation", setRose, true);

4
style.css Normal file → Executable file
View File

@ -38,7 +38,7 @@ header, main, footer, .error, noscript {
}
@media (orientation:portrait) {
.error#rotated { display: none; }
/*.error#rotated { display: none; }*/
header, main, footer {
width: 90vw;
padding: 5vw;
@ -66,7 +66,7 @@ header, main, footer, .error, noscript {
}
}
@media (orientation:landscape) {
.error#rotated { display: block; }
/*.error#rotated { display: block; }*/
header, main, footer {
height: 90vh;
padding: 5vh;