From e76f853e86cab0aeda68b2c1fe21e3c7550bc4ca Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Wed, 29 Mar 2017 03:38:32 -0400 Subject: [PATCH 01/14] Added c9 to gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 443f401..26a89c7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# c9 +.c9 +c9d + # Linux *~ .Trash-* From 13dcbc400774031e22e301719671bc559e0dd888 Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Wed, 29 Mar 2017 03:41:31 -0400 Subject: [PATCH 02/14] Fixed indentation --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 264a654..e210183 100644 --- a/index.html +++ b/index.html @@ -3,8 +3,8 @@ Compass - - + + From fc0fb8858d2530e4a0b6e5a709345bc1a1ce8b16 Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Wed, 29 Mar 2017 03:45:56 -0400 Subject: [PATCH 03/14] Restored lost edits --- index.html | 19 ++++++++++++------- script.js | 49 ++++++++++++++++++++++++++++++++++++++++--------- style.css | 53 ++++++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 96 insertions(+), 25 deletions(-) diff --git a/index.html b/index.html index e210183..cd4a626 100644 --- a/index.html +++ b/index.html @@ -3,8 +3,8 @@ Compass - - + + @@ -42,10 +42,13 @@
-
No GPS data available.
-
-
+
No GPS data available.
+
0.00000 N
+
0.00000 E
+ +
0.0 m
+
No altitude data available.
@@ -53,17 +56,19 @@
No direction available. Try this on a smartphone with an internal compass.
+
Note: the compass may be 90° off when used in landscape mode.
+ diff --git a/script.js b/script.js index 015a38a..a842fbc 100644 --- a/script.js +++ b/script.js @@ -1,12 +1,19 @@ window.addEventListener("deviceorientation", setRose, true); +const metric = !(window.navigator.language=='en-US'||window.navigator.language=='my'); +var elevator; +function gmapsCB(){ + elevator = new google.maps.ElevationService; +} + if (!navigator.geolocation){ $('#no-gps').show(); } else { navigator.geolocation.watchPosition( // success function(pos) { - var lat = pos.coords.latitude.toFixed(5); - var lon = pos.coords.longitude.toFixed(5); + setAltitude(pos.coords.latitude, pos.coords.longitude); + var lat = pos.coords.latitude.toFixed(4); + var lon = pos.coords.longitude.toFixed(4); lat = (lat.substring(0,1)=='-')? lat.substring(1)+' S' : lat+' N'; lon = (lon.substring(0,1)=='-')? lon.substring(1)+' E' : lon+' W'; $('#lat').text(lat); @@ -15,6 +22,7 @@ else { // error function() { $('.coord').hide(); + $('#rotated').hide(); $('#no-gps').show(); }, // options @@ -22,21 +30,44 @@ else { ); } +function setAltitude(lat,lon) { + if (typeof elevator != 'undefined') { + elevator.getElevationForLocations({ + 'locations': [ new google.maps.LatLng(lat,lon) ] + }, function(res) { + console.log(res); + if (res[0].elevation){ + $('#no-alt').hide(); + var alt = res[0].elevation; + // Convert + if (metric) { + alt = alt.toFixed(1)+' m'; + } else { + alt = (alt*0.3048).toFixed(1)+' ft'; + } + // Set element text + $('#alt').text(alt); + } else { + // Show error + if (res.status && res.status!='OK') { + $('#no-alt').text('No altitude data available: '+res.status+'. '); + } + $('#no-alt').show(); + } + }); + } +} + function setRose(e) { - - // No orientation data - if(!e.absolute) { + if(!e.absolute) { // No orientation data + $('#rotated').hide(); $('#no-dir').show(); } else { - - // Rotate rose var rot = 'rotate('+e.alpha.toString().substring(0,5)+'deg)'; $('#rose').css({ '-ms-transform': rot, '-webkit-transform': rot, 'transform': rot }); - } - } diff --git a/style.css b/style.css index 91d6983..3f69099 100644 --- a/style.css +++ b/style.css @@ -6,7 +6,12 @@ body { color: #EEE; } +header, main, footer, .error, noscript { + position: absolute; +} + .error, noscript { + z-index: 10; color: #F22; font-size: 22px; text-align: center; @@ -18,7 +23,7 @@ body { } .coord { - height: 50%; + height: 33%; text-align: center; font-size: 44px; font-family: monospace; @@ -31,23 +36,26 @@ body { } @media (orientation:portrait) { - header, main, footer, .error, noscript { - position: absolute; - } header, main, footer { + .error#rotated { display: none; } + header, main, footer { width: 90vw; padding: 5vw; } .error, noscript { width: 82vw; } header { - height: calc(60vh - 60vw); + height: calc(65vh - 60vw); top: 0; } main { height: 90vw; - top: calc(60vh - 50vw); + top: calc(65vh - 50vw); } footer { - height: calc(40vh - 60vw); + height: calc(35vh - 60vw); bottom: 0; + } #about { + float: left; + } #by { + float: right; } main .error { top: 50%; @@ -56,10 +64,37 @@ body { } } @media (orientation:landscape) { - + .error#rotated { display: block; } + header, main, footer { + height: 90vh; + padding: 5vh; + } .error, noscript { + width: 82vh;/**/ + } + header { + width: calc(65vw - 60vh); + left: 0; + } main { + width: 90vh; + left: calc(65vw - 50vh); + } footer { + text-align: right; + width: calc(35vw - 60vh); + right: 0; + } #by { + position: absolute; + bottom: 5vh; + right: 5vh; + } + main .error { + top: 50%; + transform: translateY(-50%); + padding: 35vh 4vh; + } } -#error { display: none; } + +error { display: none; } a { color: inherit; From 224efc8c41ed790a1d2b5b97288e7468bcfafe33 Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Wed, 29 Mar 2017 03:48:34 -0400 Subject: [PATCH 04/14] Fixed indentation --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index cd4a626..42f0278 100644 --- a/index.html +++ b/index.html @@ -3,8 +3,8 @@ Compass - - + + From d78ae3c45a98a4f1db169167c6f88a4e4c6c02b0 Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Wed, 29 Mar 2017 08:02:16 -0400 Subject: [PATCH 05/14] Minor fixes --- index.html | 8 ++++-- script.js | 80 ++++++++++++++++++++++++++++++++++-------------------- style.css | 2 ++ 3 files changed, 59 insertions(+), 31 deletions(-) diff --git a/index.html b/index.html index 42f0278..adda6bc 100644 --- a/index.html +++ b/index.html @@ -1,4 +1,5 @@ + @@ -39,6 +40,8 @@ + +
@@ -46,7 +49,7 @@
No GPS data available.
0.00000 N
0.00000 E
- +
0.0 m
No altitude data available.
@@ -70,6 +73,7 @@ - + + diff --git a/script.js b/script.js index a842fbc..d8f74b9 100644 --- a/script.js +++ b/script.js @@ -1,15 +1,14 @@ -window.addEventListener("deviceorientation", setRose, true); +'use strict'; +/* global navigator google $ */ + +// Set units based on browser locale const metric = !(window.navigator.language=='en-US'||window.navigator.language=='my'); -var elevator; -function gmapsCB(){ - elevator = new google.maps.ElevationService; -} - +// Track GPS location if (!navigator.geolocation){ $('#no-gps').show(); } -else { - navigator.geolocation.watchPosition( - // success +else { navigator.geolocation.watchPosition( + + // Got location function(pos) { setAltitude(pos.coords.latitude, pos.coords.longitude); var lat = pos.coords.latitude.toFixed(4); @@ -18,51 +17,72 @@ else { lon = (lon.substring(0,1)=='-')? lon.substring(1)+' E' : lon+' W'; $('#lat').text(lat); $('#lon').text(lon); - }, - // error + }, + + // Got error function() { $('.coord').hide(); $('#rotated').hide(); $('#no-gps').show(); }, - // options + + // Options { enableHighAccuracy:true } + ); } +// Set altitude function setAltitude(lat,lon) { - if (typeof elevator != 'undefined') { + + // Create elevator + if (typeof elevator == 'undefined') { + var elevator = new google.maps.ElevationService; + } + + // Query API + else { elevator.getElevationForLocations({ 'locations': [ new google.maps.LatLng(lat,lon) ] }, function(res) { - console.log(res); - if (res[0].elevation){ - $('#no-alt').hide(); - var alt = res[0].elevation; - // Convert - if (metric) { - alt = alt.toFixed(1)+' m'; - } else { - alt = (alt*0.3048).toFixed(1)+' ft'; - } - // Set element text - $('#alt').text(alt); - } else { - // Show error + + // Show error + if (!res[0].elevation) { if (res.status && res.status!='OK') { $('#no-alt').text('No altitude data available: '+res.status+'. '); } $('#no-alt').show(); } + + // Successfully got altitude + else { + $('#no-alt').hide(); + var alt = res[0].elevation; + + // Convert + if (metric) { alt=alt.toFixed(1)+' m'; } + else { alt=(alt*0.3048).toFixed(1)+' ft'; } + + // Set element text + $('#alt').text(alt); + + } + }); } } +// Set compass orientation function setRose(e) { - if(!e.absolute) { // No orientation data + + // No orientation data + if(!e.absolute) { $('#rotated').hide(); $('#no-dir').show(); - } else { + } + + // Set orientation + else { var rot = 'rotate('+e.alpha.toString().substring(0,5)+'deg)'; $('#rose').css({ '-ms-transform': rot, @@ -70,4 +90,6 @@ function setRose(e) { 'transform': rot }); } + } +window.addEventListener("deviceorientation", setRose, true); \ No newline at end of file diff --git a/style.css b/style.css index 3f69099..35a25c4 100644 --- a/style.css +++ b/style.css @@ -32,6 +32,8 @@ header, main, footer, .error, noscript { #rose { width: 100%; -webkit-transition-duration: 2s; + -moz-transition-duration: 2s; + -o-transition-duration: 2s; transition-duration: .2s; } From 4a60f87a131ab9872f69dc83ff405572b7d7b140 Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Mon, 7 Aug 2017 08:41:37 -0400 Subject: [PATCH 06/14] Removed unused callback --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index adda6bc..5e42897 100644 --- a/index.html +++ b/index.html @@ -71,7 +71,7 @@ - + From b78f6513de3aaec2686685a979005d725e8d62b0 Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Mon, 7 Aug 2017 11:15:51 -0400 Subject: [PATCH 07/14] Use native altutude data --- index.html | 4 +--- script.js | 62 ++++++++++++------------------------------------------ 2 files changed, 15 insertions(+), 51 deletions(-) diff --git a/index.html b/index.html index 5e42897..c65c88b 100644 --- a/index.html +++ b/index.html @@ -50,8 +50,7 @@
0.00000 N
0.00000 E
-
0.0 m
-
No altitude data available.
+
@@ -71,7 +70,6 @@ - diff --git a/script.js b/script.js index d8f74b9..50ecb4e 100644 --- a/script.js +++ b/script.js @@ -1,5 +1,5 @@ 'use strict'; -/* global navigator google $ */ +/* global navigator $ */ // Set units based on browser locale const metric = !(window.navigator.language=='en-US'||window.navigator.language=='my'); @@ -10,13 +10,19 @@ else { navigator.geolocation.watchPosition( // Got location function(pos) { - setAltitude(pos.coords.latitude, pos.coords.longitude); - var lat = pos.coords.latitude.toFixed(4); - var lon = pos.coords.longitude.toFixed(4); - lat = (lat.substring(0,1)=='-')? lat.substring(1)+' S' : lat+' N'; - lon = (lon.substring(0,1)=='-')? lon.substring(1)+' E' : lon+' W'; - $('#lat').text(lat); - $('#lon').text(lon); + 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 @@ -32,46 +38,6 @@ else { navigator.geolocation.watchPosition( ); } -// Set altitude -function setAltitude(lat,lon) { - - // Create elevator - if (typeof elevator == 'undefined') { - var elevator = new google.maps.ElevationService; - } - - // Query API - else { - elevator.getElevationForLocations({ - 'locations': [ new google.maps.LatLng(lat,lon) ] - }, function(res) { - - // Show error - if (!res[0].elevation) { - if (res.status && res.status!='OK') { - $('#no-alt').text('No altitude data available: '+res.status+'. '); - } - $('#no-alt').show(); - } - - // Successfully got altitude - else { - $('#no-alt').hide(); - var alt = res[0].elevation; - - // Convert - if (metric) { alt=alt.toFixed(1)+' m'; } - else { alt=(alt*0.3048).toFixed(1)+' ft'; } - - // Set element text - $('#alt').text(alt); - - } - - }); - } -} - // Set compass orientation function setRose(e) { From d18dbcef88e23e785b7428c3799b6865a6237419 Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Mon, 7 Aug 2017 11:16:28 -0400 Subject: [PATCH 08/14] Updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a0f9b6a..d270bee 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Compass is a web app written in plain HTML/CSS/JS. It uses [DeviceOrientationEv ## Instructions -Open [compass.keithirwin.us](https://compass.keithirwin.us/) on a smartphone with a compass. Hold the phone level and it should show your direction. +Open [compass.fyi](https://compass.fyi/) on a smartphone with a compass. Hold the phone level and it should show your direction. ### Is this accurate? From 98cba6ad7e502eb9b4fe043f4012a9ba9c675db3 Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Thu, 30 Aug 2018 02:54:55 +0000 Subject: [PATCH 09/14] Many small updates, added gyronym logic --- .gitignore | 0 LICENSE.md | 0 README.md | 0 gyronorm.complete.min.js | 5 +++ icons/apple-touch-icon-114x114.png | Bin icons/apple-touch-icon-120x120.png | Bin icons/apple-touch-icon-144x144.png | Bin icons/apple-touch-icon-152x152.png | Bin icons/apple-touch-icon-57x57.png | Bin icons/apple-touch-icon-60x60.png | Bin icons/apple-touch-icon-72x72.png | Bin icons/apple-touch-icon-76x76.png | Bin icons/favicon-128.png | Bin icons/favicon-16x16.png | Bin icons/favicon-196x196.png | Bin icons/favicon-32x32.png | Bin icons/favicon-96x96.png | Bin icons/favicon.ico | Bin icons/mstile-144x144.png | Bin icons/mstile-150x150.png | Bin icons/mstile-310x150.png | Bin icons/mstile-310x310.png | Bin icons/mstile-70x70.png | Bin index.html | 1 + manifest.webmanifest => manifest.json | 0 rose.svg | 0 script.js | 42 +++++++++++++++----------- style.css | 0 28 files changed, 30 insertions(+), 18 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 LICENSE.md mode change 100644 => 100755 README.md create mode 100644 gyronorm.complete.min.js mode change 100644 => 100755 icons/apple-touch-icon-114x114.png mode change 100644 => 100755 icons/apple-touch-icon-120x120.png mode change 100644 => 100755 icons/apple-touch-icon-144x144.png mode change 100644 => 100755 icons/apple-touch-icon-152x152.png mode change 100644 => 100755 icons/apple-touch-icon-57x57.png mode change 100644 => 100755 icons/apple-touch-icon-60x60.png mode change 100644 => 100755 icons/apple-touch-icon-72x72.png mode change 100644 => 100755 icons/apple-touch-icon-76x76.png mode change 100644 => 100755 icons/favicon-128.png mode change 100644 => 100755 icons/favicon-16x16.png mode change 100644 => 100755 icons/favicon-196x196.png mode change 100644 => 100755 icons/favicon-32x32.png mode change 100644 => 100755 icons/favicon-96x96.png mode change 100644 => 100755 icons/favicon.ico mode change 100644 => 100755 icons/mstile-144x144.png mode change 100644 => 100755 icons/mstile-150x150.png mode change 100644 => 100755 icons/mstile-310x150.png mode change 100644 => 100755 icons/mstile-310x310.png mode change 100644 => 100755 icons/mstile-70x70.png mode change 100644 => 100755 index.html rename manifest.webmanifest => manifest.json (100%) mode change 100644 => 100755 mode change 100644 => 100755 rose.svg mode change 100644 => 100755 script.js mode change 100644 => 100755 style.css diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/LICENSE.md b/LICENSE.md old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/gyronorm.complete.min.js b/gyronorm.complete.min.js new file mode 100644 index 0000000..f8f7f77 --- /dev/null +++ b/gyronorm.complete.min.js @@ -0,0 +1,5 @@ +/*! Full Tilt v0.5.3 / http://github.com/richtr/Full-Tilt */ +!function(a){function b(a){return a=+a,0===a||isNaN(a)?a:a>0?1:-1}function c(a){var b=new Promise(function(b,c){var d=function(e){setTimeout(function(){a&&a.data?b():e>=20?c():d(++e)},50)};d(0)});return b}function d(){o=n?(a.screen.orientation.angle||0)*j:(a.orientation||0)*j}function e(a){l.orientation.data=a;for(var b in l.orientation.callbacks)l.orientation.callbacks[b].call(this)}function f(a){l.motion.data=a;for(var b in l.motion.callbacks)l.motion.callbacks[b].call(this)}if(void 0===a.FULLTILT||null===a.FULLTILT){var g=Math.PI,h=g/2,i=2*g,j=g/180,k=180/g,l={orientation:{active:!1,callbacks:[],data:void 0},motion:{active:!1,callbacks:[],data:void 0}},m=!1,n=a.screen&&a.screen.orientation&&void 0!==a.screen.orientation.angle&&null!==a.screen.orientation.angle?!0:!1,o=(n?a.screen.orientation.angle:a.orientation||0)*j,p=h,q=g,r=i/3,s=-h,t={};t.version="0.5.3",t.getDeviceOrientation=function(a){var b=new Promise(function(b,d){var e=new t.DeviceOrientation(a);e.start();var f=new c(l.orientation);f.then(function(){e._alphaAvailable=l.orientation.data.alpha&&null!==l.orientation.data.alpha,e._betaAvailable=l.orientation.data.beta&&null!==l.orientation.data.beta,e._gammaAvailable=l.orientation.data.gamma&&null!==l.orientation.data.gamma,b(e)})["catch"](function(){e.stop(),d("DeviceOrientation is not supported")})});return b},t.getDeviceMotion=function(a){var b=new Promise(function(b,d){var e=new t.DeviceMotion(a);e.start();var f=new c(l.motion);f.then(function(){e._accelerationXAvailable=l.motion.data.acceleration&&l.motion.data.acceleration.x,e._accelerationYAvailable=l.motion.data.acceleration&&l.motion.data.acceleration.y,e._accelerationZAvailable=l.motion.data.acceleration&&l.motion.data.acceleration.z,e._accelerationIncludingGravityXAvailable=l.motion.data.accelerationIncludingGravity&&l.motion.data.accelerationIncludingGravity.x,e._accelerationIncludingGravityYAvailable=l.motion.data.accelerationIncludingGravity&&l.motion.data.accelerationIncludingGravity.y,e._accelerationIncludingGravityZAvailable=l.motion.data.accelerationIncludingGravity&&l.motion.data.accelerationIncludingGravity.z,e._rotationRateAlphaAvailable=l.motion.data.rotationRate&&l.motion.data.rotationRate.alpha,e._rotationRateBetaAvailable=l.motion.data.rotationRate&&l.motion.data.rotationRate.beta,e._rotationRateGammaAvailable=l.motion.data.rotationRate&&l.motion.data.rotationRate.gamma,b(e)})["catch"](function(){e.stop(),d("DeviceMotion is not supported")})});return b},t.Quaternion=function(a,c,d,e){var f;this.set=function(a,b,c,d){this.x=a||0,this.y=b||0,this.z=c||0,this.w=d||1},this.copy=function(a){this.x=a.x,this.y=a.y,this.z=a.z,this.w=a.w},this.setFromEuler=function(){var a,b,c,d,e,f,g,h,i,k,l,m;return function(n){return n=n||{},c=(n.alpha||0)*j,a=(n.beta||0)*j,b=(n.gamma||0)*j,f=c/2,d=a/2,e=b/2,g=Math.cos(d),h=Math.cos(e),i=Math.cos(f),k=Math.sin(d),l=Math.sin(e),m=Math.sin(f),this.set(k*h*i-g*l*m,g*l*i+k*h*m,g*h*m+k*l*i,g*h*i-k*l*m),this.normalize(),this}}(),this.setFromRotationMatrix=function(){var a;return function(c){return a=c.elements,this.set(.5*Math.sqrt(1+a[0]-a[4]-a[8])*b(a[7]-a[5]),.5*Math.sqrt(1-a[0]+a[4]-a[8])*b(a[2]-a[6]),.5*Math.sqrt(1-a[0]-a[4]+a[8])*b(a[3]-a[1]),.5*Math.sqrt(1+a[0]+a[4]+a[8])),this}}(),this.multiply=function(a){return f=t.Quaternion.prototype.multiplyQuaternions(this,a),this.copy(f),this},this.rotateX=function(a){return f=t.Quaternion.prototype.rotateByAxisAngle(this,[1,0,0],a),this.copy(f),this},this.rotateY=function(a){return f=t.Quaternion.prototype.rotateByAxisAngle(this,[0,1,0],a),this.copy(f),this},this.rotateZ=function(a){return f=t.Quaternion.prototype.rotateByAxisAngle(this,[0,0,1],a),this.copy(f),this},this.normalize=function(){return t.Quaternion.prototype.normalize(this)},this.set(a,c,d,e)},t.Quaternion.prototype={constructor:t.Quaternion,multiplyQuaternions:function(){var a=new t.Quaternion;return function(b,c){var d=b.x,e=b.y,f=b.z,g=b.w,h=c.x,i=c.y,j=c.z,k=c.w;return a.set(d*k+g*h+e*j-f*i,e*k+g*i+f*h-d*j,f*k+g*j+d*i-e*h,g*k-d*h-e*i-f*j),a}}(),normalize:function(a){var b=Math.sqrt(a.x*a.x+a.y*a.y+a.z*a.z+a.w*a.w);return 0===b?(a.x=0,a.y=0,a.z=0,a.w=1):(b=1/b,a.x*=b,a.y*=b,a.z*=b,a.w*=b),a},rotateByAxisAngle:function(){var a,b,c=new t.Quaternion,d=new t.Quaternion;return function(e,f,g){return a=(g||0)/2,b=Math.sin(a),d.set((f[0]||0)*b,(f[1]||0)*b,(f[2]||0)*b,Math.cos(a)),c=t.Quaternion.prototype.multiplyQuaternions(e,d),t.Quaternion.prototype.normalize(c)}}()},t.RotationMatrix=function(a,b,c,d,e,f,g,h,i){var k;this.elements=new Float32Array(9),this.identity=function(){return this.set(1,0,0,0,1,0,0,0,1),this},this.set=function(a,b,c,d,e,f,g,h,i){this.elements[0]=a||1,this.elements[1]=b||0,this.elements[2]=c||0,this.elements[3]=d||0,this.elements[4]=e||1,this.elements[5]=f||0,this.elements[6]=g||0,this.elements[7]=h||0,this.elements[8]=i||1},this.copy=function(a){this.elements[0]=a.elements[0],this.elements[1]=a.elements[1],this.elements[2]=a.elements[2],this.elements[3]=a.elements[3],this.elements[4]=a.elements[4],this.elements[5]=a.elements[5],this.elements[6]=a.elements[6],this.elements[7]=a.elements[7],this.elements[8]=a.elements[8]},this.setFromEuler=function(){var a,b,c,d,e,f,g,h,i;return function(k){return k=k||{},c=(k.alpha||0)*j,a=(k.beta||0)*j,b=(k.gamma||0)*j,d=Math.cos(a),e=Math.cos(b),f=Math.cos(c),g=Math.sin(a),h=Math.sin(b),i=Math.sin(c),this.set(f*e-i*g*h,-d*i,e*i*g+f*h,e*i+f*g*h,f*d,i*h-f*e*g,-d*h,g,d*e),this.normalize(),this}}(),this.setFromQuaternion=function(){var a,b,c,d;return function(e){return a=e.w*e.w,b=e.x*e.x,c=e.y*e.y,d=e.z*e.z,this.set(a+b-c-d,2*(e.x*e.y-e.w*e.z),2*(e.x*e.z+e.w*e.y),2*(e.x*e.y+e.w*e.z),a-b+c-d,2*(e.y*e.z-e.w*e.x),2*(e.x*e.z-e.w*e.y),2*(e.y*e.z+e.w*e.x),a-b-c+d),this}}(),this.multiply=function(a){return k=t.RotationMatrix.prototype.multiplyMatrices(this,a),this.copy(k),this},this.rotateX=function(a){return k=t.RotationMatrix.prototype.rotateByAxisAngle(this,[1,0,0],a),this.copy(k),this},this.rotateY=function(a){return k=t.RotationMatrix.prototype.rotateByAxisAngle(this,[0,1,0],a),this.copy(k),this},this.rotateZ=function(a){return k=t.RotationMatrix.prototype.rotateByAxisAngle(this,[0,0,1],a),this.copy(k),this},this.normalize=function(){return t.RotationMatrix.prototype.normalize(this)},this.set(a,b,c,d,e,f,g,h,i)},t.RotationMatrix.prototype={constructor:t.RotationMatrix,multiplyMatrices:function(){var a,b,c=new t.RotationMatrix;return function(d,e){return a=d.elements,b=e.elements,c.set(a[0]*b[0]+a[1]*b[3]+a[2]*b[6],a[0]*b[1]+a[1]*b[4]+a[2]*b[7],a[0]*b[2]+a[1]*b[5]+a[2]*b[8],a[3]*b[0]+a[4]*b[3]+a[5]*b[6],a[3]*b[1]+a[4]*b[4]+a[5]*b[7],a[3]*b[2]+a[4]*b[5]+a[5]*b[8],a[6]*b[0]+a[7]*b[3]+a[8]*b[6],a[6]*b[1]+a[7]*b[4]+a[8]*b[7],a[6]*b[2]+a[7]*b[5]+a[8]*b[8]),c}}(),normalize:function(a){var b=a.elements,c=b[0]*b[4]*b[8]-b[0]*b[5]*b[7]-b[1]*b[3]*b[8]+b[1]*b[5]*b[6]+b[2]*b[3]*b[7]-b[2]*b[4]*b[6];return b[0]/=c,b[1]/=c,b[2]/=c,b[3]/=c,b[4]/=c,b[5]/=c,b[6]/=c,b[7]/=c,b[8]/=c,a.elements=b,a},rotateByAxisAngle:function(){var a,b,c=new t.RotationMatrix,d=new t.RotationMatrix,e=!1;return function(f,g,h){return d.identity(),e=!1,a=Math.sin(h),b=Math.cos(h),1===g[0]&&0===g[1]&&0===g[2]?(e=!0,d.elements[4]=b,d.elements[5]=-a,d.elements[7]=a,d.elements[8]=b):1===g[1]&&0===g[0]&&0===g[2]?(e=!0,d.elements[0]=b,d.elements[2]=a,d.elements[6]=-a,d.elements[8]=b):1===g[2]&&0===g[0]&&0===g[1]&&(e=!0,d.elements[0]=b,d.elements[1]=-a,d.elements[3]=a,d.elements[4]=b),e?(c=t.RotationMatrix.prototype.multiplyMatrices(f,d),c=t.RotationMatrix.prototype.normalize(c)):c=f,c}}()},t.Euler=function(a,b,c){this.set=function(a,b,c){this.alpha=a||0,this.beta=b||0,this.gamma=c||0},this.copy=function(a){this.alpha=a.alpha,this.beta=a.beta,this.gamma=a.gamma},this.setFromRotationMatrix=function(){var a,b,c,d;return function(e){a=e.elements,a[8]>0?(b=Math.atan2(-a[1],a[4]),c=Math.asin(a[7]),d=Math.atan2(-a[6],a[8])):a[8]<0?(b=Math.atan2(a[1],-a[4]),c=-Math.asin(a[7]),c+=c>=0?-g:g,d=Math.atan2(a[6],-a[8])):a[6]>0?(b=Math.atan2(-a[1],a[4]),c=Math.asin(a[7]),d=-h):a[6]<0?(b=Math.atan2(a[1],-a[4]),c=-Math.asin(a[7]),c+=c>=0?-g:g,d=-h):(b=Math.atan2(a[3],a[0]),c=a[7]>0?h:-h,d=0),0>b&&(b+=i),b*=k,c*=k,d*=k,this.set(b,c,d)}}(),this.setFromQuaternion=function(){var a,b,c;return function(d){var e=d.w*d.w,f=d.x*d.x,j=d.y*d.y,l=d.z*d.z,m=e+f+j+l,n=d.w*d.x+d.y*d.z,o=1e-6;if(n>(.5-o)*m)a=2*Math.atan2(d.y,d.w),b=h,c=0;else if((-.5+o)*m>n)a=-2*Math.atan2(d.y,d.w),b=-h,c=0;else{var p=e-f+j-l,q=2*(d.w*d.z-d.x*d.y),r=e-f-j+l,s=2*(d.w*d.y-d.x*d.z);r>0?(a=Math.atan2(q,p),b=Math.asin(2*n/m),c=Math.atan2(s,r)):(a=Math.atan2(-q,-p),b=-Math.asin(2*n/m),b+=0>b?g:-g,c=Math.atan2(-s,-r))}0>a&&(a+=i),a*=k,b*=k,c*=k,this.set(a,b,c)}}(),this.rotateX=function(a){return t.Euler.prototype.rotateByAxisAngle(this,[1,0,0],a),this},this.rotateY=function(a){return t.Euler.prototype.rotateByAxisAngle(this,[0,1,0],a),this},this.rotateZ=function(a){return t.Euler.prototype.rotateByAxisAngle(this,[0,0,1],a),this},this.set(a,b,c)},t.Euler.prototype={constructor:t.Euler,rotateByAxisAngle:function(){var a=new t.RotationMatrix;return function(b,c,d){return a.setFromEuler(b),a=t.RotationMatrix.prototype.rotateByAxisAngle(a,c,d),b.setFromRotationMatrix(a),b}}()},t.DeviceOrientation=function(b){this.options=b||{};var c=0,d=200,e=0,f=10;if(this.alphaOffsetScreen=0,this.alphaOffsetDevice=void 0,"game"===this.options.type){var g=function(b){return null!==b.alpha&&(this.alphaOffsetDevice=new t.Euler(b.alpha,0,0),this.alphaOffsetDevice.rotateZ(-o),++e>=f)?void a.removeEventListener("deviceorientation",g,!1):void(++c>=d&&a.removeEventListener("deviceorientation",g,!1))}.bind(this);a.addEventListener("deviceorientation",g,!1)}else if("world"===this.options.type){var h=function(b){return b.absolute!==!0&&void 0!==b.webkitCompassAccuracy&&null!==b.webkitCompassAccuracy&&+b.webkitCompassAccuracy>=0&&+b.webkitCompassAccuracy<50&&(this.alphaOffsetDevice=new t.Euler(b.webkitCompassHeading,0,0),this.alphaOffsetDevice.rotateZ(o),this.alphaOffsetScreen=o,++e>=f)?void a.removeEventListener("deviceorientation",h,!1):void(++c>=d&&a.removeEventListener("deviceorientation",h,!1))}.bind(this);a.addEventListener("deviceorientation",h,!1)}},t.DeviceOrientation.prototype={constructor:t.DeviceOrientation,start:function(b){b&&"[object Function]"==Object.prototype.toString.call(b)&&l.orientation.callbacks.push(b),m||(n?a.screen.orientation.addEventListener("change",d,!1):a.addEventListener("orientationchange",d,!1)),l.orientation.active||(a.addEventListener("deviceorientation",e,!1),l.orientation.active=!0)},stop:function(){l.orientation.active&&(a.removeEventListener("deviceorientation",e,!1),l.orientation.active=!1)},listen:function(a){this.start(a)},getFixedFrameQuaternion:function(){var a=new t.Euler,b=new t.RotationMatrix,c=new t.Quaternion;return function(){var d=l.orientation.data||{alpha:0,beta:0,gamma:0},e=d.alpha;return this.alphaOffsetDevice&&(b.setFromEuler(this.alphaOffsetDevice),b.rotateZ(-this.alphaOffsetScreen),a.setFromRotationMatrix(b),a.alpha<0&&(a.alpha+=360),a.alpha%=360,e-=a.alpha),a.set(e,d.beta,d.gamma),c.setFromEuler(a),c}}(),getScreenAdjustedQuaternion:function(){var a;return function(){return a=this.getFixedFrameQuaternion(),a.rotateZ(-o),a}}(),getFixedFrameMatrix:function(){var a=new t.Euler,b=new t.RotationMatrix;return function(){var c=l.orientation.data||{alpha:0,beta:0,gamma:0},d=c.alpha;return this.alphaOffsetDevice&&(b.setFromEuler(this.alphaOffsetDevice),b.rotateZ(-this.alphaOffsetScreen),a.setFromRotationMatrix(b),a.alpha<0&&(a.alpha+=360),a.alpha%=360,d-=a.alpha),a.set(d,c.beta,c.gamma),b.setFromEuler(a),b}}(),getScreenAdjustedMatrix:function(){var a;return function(){return a=this.getFixedFrameMatrix(),a.rotateZ(-o),a}}(),getFixedFrameEuler:function(){var a,b=new t.Euler;return function(){return a=this.getFixedFrameMatrix(),b.setFromRotationMatrix(a),b}}(),getScreenAdjustedEuler:function(){var a,b=new t.Euler;return function(){return a=this.getScreenAdjustedMatrix(),b.setFromRotationMatrix(a),b}}(),isAbsolute:function(){return l.orientation.data&&l.orientation.data.absolute===!0?!0:!1},getLastRawEventData:function(){return l.orientation.data||{}},_alphaAvailable:!1,_betaAvailable:!1,_gammaAvailable:!1,isAvailable:function(a){switch(a){case this.ALPHA:return this._alphaAvailable;case this.BETA:return this._betaAvailable;case this.GAMMA:return this._gammaAvailable}},ALPHA:"alpha",BETA:"beta",GAMMA:"gamma"},t.DeviceMotion=function(a){this.options=a||{}},t.DeviceMotion.prototype={constructor:t.DeviceMotion,start:function(b){b&&"[object Function]"==Object.prototype.toString.call(b)&&l.motion.callbacks.push(b),m||(n?a.screen.orientation.addEventListener("change",d,!1):a.addEventListener("orientationchange",d,!1)),l.motion.active||(a.addEventListener("devicemotion",f,!1),l.motion.active=!0)},stop:function(){l.motion.active&&(a.removeEventListener("devicemotion",f,!1),l.motion.active=!1)},listen:function(a){this.start(a)},getScreenAdjustedAcceleration:function(){var a=l.motion.data&&l.motion.data.acceleration?l.motion.data.acceleration:{x:0,y:0,z:0},b={};switch(o){case p:b.x=-a.y,b.y=a.x;break;case q:b.x=-a.x,b.y=-a.y;break;case r:case s:b.x=a.y,b.y=-a.x;break;default:b.x=a.x,b.y=a.y}return b.z=a.z,b},getScreenAdjustedAccelerationIncludingGravity:function(){var a=l.motion.data&&l.motion.data.accelerationIncludingGravity?l.motion.data.accelerationIncludingGravity:{x:0,y:0,z:0},b={};switch(o){case p:b.x=-a.y,b.y=a.x;break;case q:b.x=-a.x,b.y=-a.y;break;case r:case s:b.x=a.y,b.y=-a.x;break;default:b.x=a.x,b.y=a.y}return b.z=a.z,b},getScreenAdjustedRotationRate:function(){var a=l.motion.data&&l.motion.data.rotationRate?l.motion.data.rotationRate:{alpha:0,beta:0,gamma:0},b={};switch(o){case p:b.beta=-a.gamma,b.gamma=a.beta;break;case q:b.beta=-a.beta,b.gamma=-a.gamma;break;case r:case s:b.beta=a.gamma,b.gamma=-a.beta;break;default:b.beta=a.beta,b.gamma=a.gamma}return b.alpha=a.alpha,b},getLastRawEventData:function(){return l.motion.data||{}},_accelerationXAvailable:!1,_accelerationYAvailable:!1,_accelerationZAvailable:!1,_accelerationIncludingGravityXAvailable:!1,_accelerationIncludingGravityYAvailable:!1,_accelerationIncludingGravityZAvailable:!1,_rotationRateAlphaAvailable:!1,_rotationRateBetaAvailable:!1,_rotationRateGammaAvailable:!1,isAvailable:function(a){switch(a){case this.ACCELERATION_X:return this._accelerationXAvailable;case this.ACCELERATION_Y:return this._accelerationYAvailable;case this.ACCELERATION_Z:return this._accelerationZAvailable;case this.ACCELERATION_INCLUDING_GRAVITY_X:return this._accelerationIncludingGravityXAvailable;case this.ACCELERATION_INCLUDING_GRAVITY_Y:return this._accelerationIncludingGravityYAvailable;case this.ACCELERATION_INCLUDING_GRAVITY_Z:return this._accelerationIncludingGravityZAvailable;case this.ROTATION_RATE_ALPHA:return this._rotationRateAlphaAvailable;case this.ROTATION_RATE_BETA:return this._rotationRateBetaAvailable;case this.ROTATION_RATE_GAMMA:return this._rotationRateGammaAvailable}},ACCELERATION_X:"accelerationX",ACCELERATION_Y:"accelerationY",ACCELERATION_Z:"accelerationZ",ACCELERATION_INCLUDING_GRAVITY_X:"accelerationIncludingGravityX",ACCELERATION_INCLUDING_GRAVITY_Y:"accelerationIncludingGravityY",ACCELERATION_INCLUDING_GRAVITY_Z:"accelerationIncludingGravityZ",ROTATION_RATE_ALPHA:"rotationRateAlpha",ROTATION_RATE_BETA:"rotationRateBeta",ROTATION_RATE_GAMMA:"rotationRateGamma"},a.FULLTILT=t}}(window); + +/* gyronorm.js v2.0.6 - https://github.com/dorukeker/gyronorm.git*/ +!function(a,b){var c={GyroNorm:b()};"function"==typeof define&&define.amd?define(function(){return c}):"object"==typeof module&&module.exports?module.exports=c:a.GyroNorm=c.GyroNorm}(this,function(){function a(a){return Math.round(a*Math.pow(10,t))/Math.pow(10,t)}function b(){var b={};b=v?o.getScreenAdjustedEuler():o.getFixedFrameEuler();var c=p.getScreenAdjustedAcceleration(),e=p.getScreenAdjustedAccelerationIncludingGravity(),f=p.getScreenAdjustedRotationRate(),g=0;s===d?(g=b.alpha-k,g=0>g?360-Math.abs(g):g):g=b.alpha;var h={"do":{alpha:a(g),beta:a(b.beta),gamma:a(b.gamma),absolute:o.isAbsolute()},dm:{x:a(c.x),y:a(c.y),z:a(c.z),gx:a(e.x),gy:a(e.y),gz:a(e.z),alpha:a(f.alpha),beta:a(f.beta),gamma:a(f.gamma)}};return r&&(h.dm.gx*=l,h.dm.gy*=l,h.dm.gz*=l),h}function c(a){u&&("string"==typeof a&&(a={message:a,code:0}),u(a))}var d="game",e="world",f="deviceorientation",g="acceleration",h="accelerationinludinggravity",i="rotationrate",j=null,k=0,l=0,m=!1,n=!1,o=null,p=null,q=50,r=!0,s=d,t=2,u=null,v=!1,w=function(a){};return w.GAME=d,w.WORLD=e,w.DEVICE_ORIENTATION=f,w.ACCELERATION=g,w.ACCELERATION_INCLUDING_GRAVITY=h,w.ROTATION_RATE=i,w.prototype.init=function(a){a&&a.frequency&&(q=a.frequency),a&&a.gravityNormalized&&(r=a.gravityNormalized),a&&a.orientationBase&&(s=a.orientationBase),a&&"number"==typeof a.decimalCount&&a.decimalCount>=0&&(t=parseInt(a.decimalCount)),a&&a.logger&&(u=a.logger),a&&a.screenAdjusted&&(v=a.screenAdjusted);var b=new FULLTILT.getDeviceOrientation({type:s}).then(function(a){o=a}),c=(new FULLTILT.getDeviceMotion).then(function(a){p=a,l=p.getScreenAdjustedAccelerationIncludingGravity().z>0?-1:1});return Promise.all([b,c]).then(function(){n=!0})},w.prototype.end=function(){try{n=!1,this.stop(),p.stop(),o.stop()}catch(a){c(a)}},w.prototype.start=function(a){return n?(j=setInterval(function(){a(b())},q),void(m=!0)):void c({message:'GyroNorm is not initialized yet. First call the "init()" function.',code:1})},w.prototype.stop=function(){j&&(clearInterval(j),m=!1)},w.prototype.normalizeGravity=function(a){r=a?!0:!1},w.prototype.setHeadDirection=function(){return v||s===e?!1:(k=o.getFixedFrameEuler().alpha,!0)},w.prototype.startLogging=function(a){a&&(u=a)},w.prototype.stopLogging=function(){u=null},w.prototype.isAvailable=function(a){var b=o.getScreenAdjustedEuler(),c=p.getScreenAdjustedAcceleration(),d=p.getScreenAdjustedAccelerationIncludingGravity(),e=p.getScreenAdjustedRotationRate();switch(a){case f:return b.alpha&&null!==b.alpha&&b.beta&&null!==b.beta&&b.gamma&&null!==b.gamma;case g:return c&&c.x&&c.y&&c.z;case h:return d&&d.x&&d.y&&d.z;case i:return e&&e.alpha&&e.beta&&e.gamma;default:return{deviceOrientationAvailable:b.alpha&&null!==b.alpha&&b.beta&&null!==b.beta&&b.gamma&&null!==b.gamma,accelerationAvailable:c&&c.x&&c.y&&c.z,accelerationIncludingGravityAvailable:d&&d.x&&d.y&&d.z,rotationRateAvailable:e&&e.alpha&&e.beta&&e.gamma}}},w.prototype.isRunning=function(){return m},w}); diff --git a/icons/apple-touch-icon-114x114.png b/icons/apple-touch-icon-114x114.png old mode 100644 new mode 100755 diff --git a/icons/apple-touch-icon-120x120.png b/icons/apple-touch-icon-120x120.png old mode 100644 new mode 100755 diff --git a/icons/apple-touch-icon-144x144.png b/icons/apple-touch-icon-144x144.png old mode 100644 new mode 100755 diff --git a/icons/apple-touch-icon-152x152.png b/icons/apple-touch-icon-152x152.png old mode 100644 new mode 100755 diff --git a/icons/apple-touch-icon-57x57.png b/icons/apple-touch-icon-57x57.png old mode 100644 new mode 100755 diff --git a/icons/apple-touch-icon-60x60.png b/icons/apple-touch-icon-60x60.png old mode 100644 new mode 100755 diff --git a/icons/apple-touch-icon-72x72.png b/icons/apple-touch-icon-72x72.png old mode 100644 new mode 100755 diff --git a/icons/apple-touch-icon-76x76.png b/icons/apple-touch-icon-76x76.png old mode 100644 new mode 100755 diff --git a/icons/favicon-128.png b/icons/favicon-128.png old mode 100644 new mode 100755 diff --git a/icons/favicon-16x16.png b/icons/favicon-16x16.png old mode 100644 new mode 100755 diff --git a/icons/favicon-196x196.png b/icons/favicon-196x196.png old mode 100644 new mode 100755 diff --git a/icons/favicon-32x32.png b/icons/favicon-32x32.png old mode 100644 new mode 100755 diff --git a/icons/favicon-96x96.png b/icons/favicon-96x96.png old mode 100644 new mode 100755 diff --git a/icons/favicon.ico b/icons/favicon.ico old mode 100644 new mode 100755 diff --git a/icons/mstile-144x144.png b/icons/mstile-144x144.png old mode 100644 new mode 100755 diff --git a/icons/mstile-150x150.png b/icons/mstile-150x150.png old mode 100644 new mode 100755 diff --git a/icons/mstile-310x150.png b/icons/mstile-310x150.png old mode 100644 new mode 100755 diff --git a/icons/mstile-310x310.png b/icons/mstile-310x310.png old mode 100644 new mode 100755 diff --git a/icons/mstile-70x70.png b/icons/mstile-70x70.png old mode 100644 new mode 100755 diff --git a/index.html b/index.html old mode 100644 new mode 100755 index c65c88b..0e22e24 --- a/index.html +++ b/index.html @@ -69,6 +69,7 @@ + diff --git a/manifest.webmanifest b/manifest.json old mode 100644 new mode 100755 similarity index 100% rename from manifest.webmanifest rename to manifest.json diff --git a/rose.svg b/rose.svg old mode 100644 new mode 100755 diff --git a/script.js b/script.js old mode 100644 new mode 100755 index 50ecb4e..716eac6 --- a/script.js +++ b/script.js @@ -1,5 +1,5 @@ 'use strict'; -/* global navigator $ */ +/* global navigator $ GyroNorm */ // Set units based on browser locale const metric = !(window.navigator.language=='en-US'||window.navigator.language=='my'); @@ -39,23 +39,29 @@ else { navigator.geolocation.watchPosition( } // Set compass orientation -function setRose(e) { +var gn = new GyroNorm() + +gn.init().then(function(){ + gn.start(function(data){ - // 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 - }); - } + // No orientation data + if (!data.do.absolute) { + $('#rotated').hide(); + $('#no-dir').show(); + } + + // Set orientation + else { + const rot = 'rotate('+data.do.alpha.toString().substring(0,5)+'deg)'; + $('#rose').css({ + '-ms-transform': rot, + '-webkit-transform': rot, + 'transform': rot + }) + } + + }) + +}) -} window.addEventListener("deviceorientation", setRose, true); \ No newline at end of file diff --git a/style.css b/style.css old mode 100644 new mode 100755 From 527caa8ae5f274833eeef148477c8b512e536179 Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Thu, 30 Aug 2018 18:01:11 +0000 Subject: [PATCH 10/14] Fixed compass gyro at last --- script.js => coordinates.js | 36 +++++------------------------------- direction.js | 34 ++++++++++++++++++++++++++++++++++ index.html | 3 ++- 3 files changed, 41 insertions(+), 32 deletions(-) rename script.js => coordinates.js (61%) create mode 100644 direction.js diff --git a/script.js b/coordinates.js similarity index 61% rename from script.js rename to coordinates.js index 716eac6..2a17a0b 100755 --- a/script.js +++ b/coordinates.js @@ -1,10 +1,12 @@ -'use strict'; -/* global navigator $ GyroNorm */ +'use strict' +/* global navigator $ */ + +alert('coordinates loaded') // Set units based on browser locale const metric = !(window.navigator.language=='en-US'||window.navigator.language=='my'); -// Track GPS location +// Track location if (!navigator.geolocation){ $('#no-gps').show(); } else { navigator.geolocation.watchPosition( @@ -37,31 +39,3 @@ else { navigator.geolocation.watchPosition( ); } - -// Set compass orientation -var gn = new GyroNorm() - -gn.init().then(function(){ - gn.start(function(data){ - - // No orientation data - if (!data.do.absolute) { - $('#rotated').hide(); - $('#no-dir').show(); - } - - // Set orientation - else { - const rot = 'rotate('+data.do.alpha.toString().substring(0,5)+'deg)'; - $('#rose').css({ - '-ms-transform': rot, - '-webkit-transform': rot, - 'transform': rot - }) - } - - }) - -}) - -window.addEventListener("deviceorientation", setRose, true); \ No newline at end of file diff --git a/direction.js b/direction.js new file mode 100644 index 0000000..bce5d92 --- /dev/null +++ b/direction.js @@ -0,0 +1,34 @@ +'use strict' +/* global $ GyroNorm */ + +alert('direction loaded') + + +// Set compass orientation +var gn = new GyroNorm() + +gn.init().then(function(){ + gn.start(function(data){ + + console.log(data.do.alpha) + // No orientation data + // if (!data.do.absolute) { + // $('#rotated').hide() + // $('#no-dir').show() + // } + + // Set orientation + // else { + const rot = 'rotate('+data.do.alpha.toString().substring(0,5)+'deg)' + $('#rose').css({ + '-ms-transform': rot, + '-webkit-transform': rot, + 'transform': rot + }) + // } + + }) + +}) + +//window.addEventListener("deviceorientation", setRose, true) diff --git a/index.html b/index.html index 0e22e24..175c899 100755 --- a/index.html +++ b/index.html @@ -71,7 +71,8 @@ - + + From 9460e41bb7d6f55d9cf7cca1b4df471fc205395a Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Thu, 30 Aug 2018 18:09:41 +0000 Subject: [PATCH 11/14] Removed debugging --- coordinates.js | 2 -- direction.js | 2 -- 2 files changed, 4 deletions(-) diff --git a/coordinates.js b/coordinates.js index 2a17a0b..bc7b40a 100755 --- a/coordinates.js +++ b/coordinates.js @@ -1,8 +1,6 @@ 'use strict' /* global navigator $ */ -alert('coordinates loaded') - // Set units based on browser locale const metric = !(window.navigator.language=='en-US'||window.navigator.language=='my'); diff --git a/direction.js b/direction.js index bce5d92..1b04bad 100644 --- a/direction.js +++ b/direction.js @@ -1,8 +1,6 @@ 'use strict' /* global $ GyroNorm */ -alert('direction loaded') - // Set compass orientation var gn = new GyroNorm() From c14553940e470c4d8b75a70b3aee7660c983292c Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Thu, 30 Aug 2018 18:52:14 +0000 Subject: [PATCH 12/14] Removed GyroNorm for compass use, updated styles --- coordinates.js | 73 ++++++++++++++++++++++------------------ direction.js | 41 +++++++++------------- gyronorm.complete.min.js | 5 --- index.html | 10 +++--- 4 files changed, 59 insertions(+), 70 deletions(-) delete mode 100644 gyronorm.complete.min.js diff --git a/coordinates.js b/coordinates.js index bc7b40a..a12e287 100755 --- a/coordinates.js +++ b/coordinates.js @@ -1,39 +1,46 @@ 'use strict' /* global navigator $ */ -// Set units based on browser locale -const metric = !(window.navigator.language=='en-US'||window.navigator.language=='my'); -// Track location -if (!navigator.geolocation){ $('#no-gps').show(); } -else { navigator.geolocation.watchPosition( +// 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 - 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 location callback + 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)+' E' : lon+' W' + ) - // Got error - function() { - $('.coord').hide(); - $('#rotated').hide(); - $('#no-gps').show(); - }, - - // Options - { enableHighAccuracy:true } - - ); -} + // Get altitude + if (pos.coords.altitude) + $('#alt').show().text( + (metric)? // Convert to feet if needed + pos.coords.altitude.toFixed(1)+' m': + (pos.coords.altitude*0.3048).toFixed(1)+' ft' + ) + else $('#alt').hide() + }, + + // Got error + function() { + $('.coord').hide() + $('#no-gps').show() + }, + + // Options + { enableHighAccuracy:true } + +) diff --git a/direction.js b/direction.js index 1b04bad..d55ba75 100644 --- a/direction.js +++ b/direction.js @@ -1,32 +1,21 @@ 'use strict' -/* global $ GyroNorm */ +/* global $ window */ -// Set compass orientation -var gn = new GyroNorm() - -gn.init().then(function(){ - gn.start(function(data){ +window.addEventListener('deviceorientation', function(e){ - console.log(data.do.alpha) - // No orientation data - // if (!data.do.absolute) { - // $('#rotated').hide() - // $('#no-dir').show() - // } - - // Set orientation - // else { - const rot = 'rotate('+data.do.alpha.toString().substring(0,5)+'deg)' - $('#rose').css({ - '-ms-transform': rot, - '-webkit-transform': rot, - 'transform': rot - }) - // } + // 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 + }) + } -}) - -//window.addEventListener("deviceorientation", setRose, true) +}, true) diff --git a/gyronorm.complete.min.js b/gyronorm.complete.min.js deleted file mode 100644 index f8f7f77..0000000 --- a/gyronorm.complete.min.js +++ /dev/null @@ -1,5 +0,0 @@ -/*! Full Tilt v0.5.3 / http://github.com/richtr/Full-Tilt */ -!function(a){function b(a){return a=+a,0===a||isNaN(a)?a:a>0?1:-1}function c(a){var b=new Promise(function(b,c){var d=function(e){setTimeout(function(){a&&a.data?b():e>=20?c():d(++e)},50)};d(0)});return b}function d(){o=n?(a.screen.orientation.angle||0)*j:(a.orientation||0)*j}function e(a){l.orientation.data=a;for(var b in l.orientation.callbacks)l.orientation.callbacks[b].call(this)}function f(a){l.motion.data=a;for(var b in l.motion.callbacks)l.motion.callbacks[b].call(this)}if(void 0===a.FULLTILT||null===a.FULLTILT){var g=Math.PI,h=g/2,i=2*g,j=g/180,k=180/g,l={orientation:{active:!1,callbacks:[],data:void 0},motion:{active:!1,callbacks:[],data:void 0}},m=!1,n=a.screen&&a.screen.orientation&&void 0!==a.screen.orientation.angle&&null!==a.screen.orientation.angle?!0:!1,o=(n?a.screen.orientation.angle:a.orientation||0)*j,p=h,q=g,r=i/3,s=-h,t={};t.version="0.5.3",t.getDeviceOrientation=function(a){var b=new Promise(function(b,d){var e=new t.DeviceOrientation(a);e.start();var f=new c(l.orientation);f.then(function(){e._alphaAvailable=l.orientation.data.alpha&&null!==l.orientation.data.alpha,e._betaAvailable=l.orientation.data.beta&&null!==l.orientation.data.beta,e._gammaAvailable=l.orientation.data.gamma&&null!==l.orientation.data.gamma,b(e)})["catch"](function(){e.stop(),d("DeviceOrientation is not supported")})});return b},t.getDeviceMotion=function(a){var b=new Promise(function(b,d){var e=new t.DeviceMotion(a);e.start();var f=new c(l.motion);f.then(function(){e._accelerationXAvailable=l.motion.data.acceleration&&l.motion.data.acceleration.x,e._accelerationYAvailable=l.motion.data.acceleration&&l.motion.data.acceleration.y,e._accelerationZAvailable=l.motion.data.acceleration&&l.motion.data.acceleration.z,e._accelerationIncludingGravityXAvailable=l.motion.data.accelerationIncludingGravity&&l.motion.data.accelerationIncludingGravity.x,e._accelerationIncludingGravityYAvailable=l.motion.data.accelerationIncludingGravity&&l.motion.data.accelerationIncludingGravity.y,e._accelerationIncludingGravityZAvailable=l.motion.data.accelerationIncludingGravity&&l.motion.data.accelerationIncludingGravity.z,e._rotationRateAlphaAvailable=l.motion.data.rotationRate&&l.motion.data.rotationRate.alpha,e._rotationRateBetaAvailable=l.motion.data.rotationRate&&l.motion.data.rotationRate.beta,e._rotationRateGammaAvailable=l.motion.data.rotationRate&&l.motion.data.rotationRate.gamma,b(e)})["catch"](function(){e.stop(),d("DeviceMotion is not supported")})});return b},t.Quaternion=function(a,c,d,e){var f;this.set=function(a,b,c,d){this.x=a||0,this.y=b||0,this.z=c||0,this.w=d||1},this.copy=function(a){this.x=a.x,this.y=a.y,this.z=a.z,this.w=a.w},this.setFromEuler=function(){var a,b,c,d,e,f,g,h,i,k,l,m;return function(n){return n=n||{},c=(n.alpha||0)*j,a=(n.beta||0)*j,b=(n.gamma||0)*j,f=c/2,d=a/2,e=b/2,g=Math.cos(d),h=Math.cos(e),i=Math.cos(f),k=Math.sin(d),l=Math.sin(e),m=Math.sin(f),this.set(k*h*i-g*l*m,g*l*i+k*h*m,g*h*m+k*l*i,g*h*i-k*l*m),this.normalize(),this}}(),this.setFromRotationMatrix=function(){var a;return function(c){return a=c.elements,this.set(.5*Math.sqrt(1+a[0]-a[4]-a[8])*b(a[7]-a[5]),.5*Math.sqrt(1-a[0]+a[4]-a[8])*b(a[2]-a[6]),.5*Math.sqrt(1-a[0]-a[4]+a[8])*b(a[3]-a[1]),.5*Math.sqrt(1+a[0]+a[4]+a[8])),this}}(),this.multiply=function(a){return f=t.Quaternion.prototype.multiplyQuaternions(this,a),this.copy(f),this},this.rotateX=function(a){return f=t.Quaternion.prototype.rotateByAxisAngle(this,[1,0,0],a),this.copy(f),this},this.rotateY=function(a){return f=t.Quaternion.prototype.rotateByAxisAngle(this,[0,1,0],a),this.copy(f),this},this.rotateZ=function(a){return f=t.Quaternion.prototype.rotateByAxisAngle(this,[0,0,1],a),this.copy(f),this},this.normalize=function(){return t.Quaternion.prototype.normalize(this)},this.set(a,c,d,e)},t.Quaternion.prototype={constructor:t.Quaternion,multiplyQuaternions:function(){var a=new t.Quaternion;return function(b,c){var d=b.x,e=b.y,f=b.z,g=b.w,h=c.x,i=c.y,j=c.z,k=c.w;return a.set(d*k+g*h+e*j-f*i,e*k+g*i+f*h-d*j,f*k+g*j+d*i-e*h,g*k-d*h-e*i-f*j),a}}(),normalize:function(a){var b=Math.sqrt(a.x*a.x+a.y*a.y+a.z*a.z+a.w*a.w);return 0===b?(a.x=0,a.y=0,a.z=0,a.w=1):(b=1/b,a.x*=b,a.y*=b,a.z*=b,a.w*=b),a},rotateByAxisAngle:function(){var a,b,c=new t.Quaternion,d=new t.Quaternion;return function(e,f,g){return a=(g||0)/2,b=Math.sin(a),d.set((f[0]||0)*b,(f[1]||0)*b,(f[2]||0)*b,Math.cos(a)),c=t.Quaternion.prototype.multiplyQuaternions(e,d),t.Quaternion.prototype.normalize(c)}}()},t.RotationMatrix=function(a,b,c,d,e,f,g,h,i){var k;this.elements=new Float32Array(9),this.identity=function(){return this.set(1,0,0,0,1,0,0,0,1),this},this.set=function(a,b,c,d,e,f,g,h,i){this.elements[0]=a||1,this.elements[1]=b||0,this.elements[2]=c||0,this.elements[3]=d||0,this.elements[4]=e||1,this.elements[5]=f||0,this.elements[6]=g||0,this.elements[7]=h||0,this.elements[8]=i||1},this.copy=function(a){this.elements[0]=a.elements[0],this.elements[1]=a.elements[1],this.elements[2]=a.elements[2],this.elements[3]=a.elements[3],this.elements[4]=a.elements[4],this.elements[5]=a.elements[5],this.elements[6]=a.elements[6],this.elements[7]=a.elements[7],this.elements[8]=a.elements[8]},this.setFromEuler=function(){var a,b,c,d,e,f,g,h,i;return function(k){return k=k||{},c=(k.alpha||0)*j,a=(k.beta||0)*j,b=(k.gamma||0)*j,d=Math.cos(a),e=Math.cos(b),f=Math.cos(c),g=Math.sin(a),h=Math.sin(b),i=Math.sin(c),this.set(f*e-i*g*h,-d*i,e*i*g+f*h,e*i+f*g*h,f*d,i*h-f*e*g,-d*h,g,d*e),this.normalize(),this}}(),this.setFromQuaternion=function(){var a,b,c,d;return function(e){return a=e.w*e.w,b=e.x*e.x,c=e.y*e.y,d=e.z*e.z,this.set(a+b-c-d,2*(e.x*e.y-e.w*e.z),2*(e.x*e.z+e.w*e.y),2*(e.x*e.y+e.w*e.z),a-b+c-d,2*(e.y*e.z-e.w*e.x),2*(e.x*e.z-e.w*e.y),2*(e.y*e.z+e.w*e.x),a-b-c+d),this}}(),this.multiply=function(a){return k=t.RotationMatrix.prototype.multiplyMatrices(this,a),this.copy(k),this},this.rotateX=function(a){return k=t.RotationMatrix.prototype.rotateByAxisAngle(this,[1,0,0],a),this.copy(k),this},this.rotateY=function(a){return k=t.RotationMatrix.prototype.rotateByAxisAngle(this,[0,1,0],a),this.copy(k),this},this.rotateZ=function(a){return k=t.RotationMatrix.prototype.rotateByAxisAngle(this,[0,0,1],a),this.copy(k),this},this.normalize=function(){return t.RotationMatrix.prototype.normalize(this)},this.set(a,b,c,d,e,f,g,h,i)},t.RotationMatrix.prototype={constructor:t.RotationMatrix,multiplyMatrices:function(){var a,b,c=new t.RotationMatrix;return function(d,e){return a=d.elements,b=e.elements,c.set(a[0]*b[0]+a[1]*b[3]+a[2]*b[6],a[0]*b[1]+a[1]*b[4]+a[2]*b[7],a[0]*b[2]+a[1]*b[5]+a[2]*b[8],a[3]*b[0]+a[4]*b[3]+a[5]*b[6],a[3]*b[1]+a[4]*b[4]+a[5]*b[7],a[3]*b[2]+a[4]*b[5]+a[5]*b[8],a[6]*b[0]+a[7]*b[3]+a[8]*b[6],a[6]*b[1]+a[7]*b[4]+a[8]*b[7],a[6]*b[2]+a[7]*b[5]+a[8]*b[8]),c}}(),normalize:function(a){var b=a.elements,c=b[0]*b[4]*b[8]-b[0]*b[5]*b[7]-b[1]*b[3]*b[8]+b[1]*b[5]*b[6]+b[2]*b[3]*b[7]-b[2]*b[4]*b[6];return b[0]/=c,b[1]/=c,b[2]/=c,b[3]/=c,b[4]/=c,b[5]/=c,b[6]/=c,b[7]/=c,b[8]/=c,a.elements=b,a},rotateByAxisAngle:function(){var a,b,c=new t.RotationMatrix,d=new t.RotationMatrix,e=!1;return function(f,g,h){return d.identity(),e=!1,a=Math.sin(h),b=Math.cos(h),1===g[0]&&0===g[1]&&0===g[2]?(e=!0,d.elements[4]=b,d.elements[5]=-a,d.elements[7]=a,d.elements[8]=b):1===g[1]&&0===g[0]&&0===g[2]?(e=!0,d.elements[0]=b,d.elements[2]=a,d.elements[6]=-a,d.elements[8]=b):1===g[2]&&0===g[0]&&0===g[1]&&(e=!0,d.elements[0]=b,d.elements[1]=-a,d.elements[3]=a,d.elements[4]=b),e?(c=t.RotationMatrix.prototype.multiplyMatrices(f,d),c=t.RotationMatrix.prototype.normalize(c)):c=f,c}}()},t.Euler=function(a,b,c){this.set=function(a,b,c){this.alpha=a||0,this.beta=b||0,this.gamma=c||0},this.copy=function(a){this.alpha=a.alpha,this.beta=a.beta,this.gamma=a.gamma},this.setFromRotationMatrix=function(){var a,b,c,d;return function(e){a=e.elements,a[8]>0?(b=Math.atan2(-a[1],a[4]),c=Math.asin(a[7]),d=Math.atan2(-a[6],a[8])):a[8]<0?(b=Math.atan2(a[1],-a[4]),c=-Math.asin(a[7]),c+=c>=0?-g:g,d=Math.atan2(a[6],-a[8])):a[6]>0?(b=Math.atan2(-a[1],a[4]),c=Math.asin(a[7]),d=-h):a[6]<0?(b=Math.atan2(a[1],-a[4]),c=-Math.asin(a[7]),c+=c>=0?-g:g,d=-h):(b=Math.atan2(a[3],a[0]),c=a[7]>0?h:-h,d=0),0>b&&(b+=i),b*=k,c*=k,d*=k,this.set(b,c,d)}}(),this.setFromQuaternion=function(){var a,b,c;return function(d){var e=d.w*d.w,f=d.x*d.x,j=d.y*d.y,l=d.z*d.z,m=e+f+j+l,n=d.w*d.x+d.y*d.z,o=1e-6;if(n>(.5-o)*m)a=2*Math.atan2(d.y,d.w),b=h,c=0;else if((-.5+o)*m>n)a=-2*Math.atan2(d.y,d.w),b=-h,c=0;else{var p=e-f+j-l,q=2*(d.w*d.z-d.x*d.y),r=e-f-j+l,s=2*(d.w*d.y-d.x*d.z);r>0?(a=Math.atan2(q,p),b=Math.asin(2*n/m),c=Math.atan2(s,r)):(a=Math.atan2(-q,-p),b=-Math.asin(2*n/m),b+=0>b?g:-g,c=Math.atan2(-s,-r))}0>a&&(a+=i),a*=k,b*=k,c*=k,this.set(a,b,c)}}(),this.rotateX=function(a){return t.Euler.prototype.rotateByAxisAngle(this,[1,0,0],a),this},this.rotateY=function(a){return t.Euler.prototype.rotateByAxisAngle(this,[0,1,0],a),this},this.rotateZ=function(a){return t.Euler.prototype.rotateByAxisAngle(this,[0,0,1],a),this},this.set(a,b,c)},t.Euler.prototype={constructor:t.Euler,rotateByAxisAngle:function(){var a=new t.RotationMatrix;return function(b,c,d){return a.setFromEuler(b),a=t.RotationMatrix.prototype.rotateByAxisAngle(a,c,d),b.setFromRotationMatrix(a),b}}()},t.DeviceOrientation=function(b){this.options=b||{};var c=0,d=200,e=0,f=10;if(this.alphaOffsetScreen=0,this.alphaOffsetDevice=void 0,"game"===this.options.type){var g=function(b){return null!==b.alpha&&(this.alphaOffsetDevice=new t.Euler(b.alpha,0,0),this.alphaOffsetDevice.rotateZ(-o),++e>=f)?void a.removeEventListener("deviceorientation",g,!1):void(++c>=d&&a.removeEventListener("deviceorientation",g,!1))}.bind(this);a.addEventListener("deviceorientation",g,!1)}else if("world"===this.options.type){var h=function(b){return b.absolute!==!0&&void 0!==b.webkitCompassAccuracy&&null!==b.webkitCompassAccuracy&&+b.webkitCompassAccuracy>=0&&+b.webkitCompassAccuracy<50&&(this.alphaOffsetDevice=new t.Euler(b.webkitCompassHeading,0,0),this.alphaOffsetDevice.rotateZ(o),this.alphaOffsetScreen=o,++e>=f)?void a.removeEventListener("deviceorientation",h,!1):void(++c>=d&&a.removeEventListener("deviceorientation",h,!1))}.bind(this);a.addEventListener("deviceorientation",h,!1)}},t.DeviceOrientation.prototype={constructor:t.DeviceOrientation,start:function(b){b&&"[object Function]"==Object.prototype.toString.call(b)&&l.orientation.callbacks.push(b),m||(n?a.screen.orientation.addEventListener("change",d,!1):a.addEventListener("orientationchange",d,!1)),l.orientation.active||(a.addEventListener("deviceorientation",e,!1),l.orientation.active=!0)},stop:function(){l.orientation.active&&(a.removeEventListener("deviceorientation",e,!1),l.orientation.active=!1)},listen:function(a){this.start(a)},getFixedFrameQuaternion:function(){var a=new t.Euler,b=new t.RotationMatrix,c=new t.Quaternion;return function(){var d=l.orientation.data||{alpha:0,beta:0,gamma:0},e=d.alpha;return this.alphaOffsetDevice&&(b.setFromEuler(this.alphaOffsetDevice),b.rotateZ(-this.alphaOffsetScreen),a.setFromRotationMatrix(b),a.alpha<0&&(a.alpha+=360),a.alpha%=360,e-=a.alpha),a.set(e,d.beta,d.gamma),c.setFromEuler(a),c}}(),getScreenAdjustedQuaternion:function(){var a;return function(){return a=this.getFixedFrameQuaternion(),a.rotateZ(-o),a}}(),getFixedFrameMatrix:function(){var a=new t.Euler,b=new t.RotationMatrix;return function(){var c=l.orientation.data||{alpha:0,beta:0,gamma:0},d=c.alpha;return this.alphaOffsetDevice&&(b.setFromEuler(this.alphaOffsetDevice),b.rotateZ(-this.alphaOffsetScreen),a.setFromRotationMatrix(b),a.alpha<0&&(a.alpha+=360),a.alpha%=360,d-=a.alpha),a.set(d,c.beta,c.gamma),b.setFromEuler(a),b}}(),getScreenAdjustedMatrix:function(){var a;return function(){return a=this.getFixedFrameMatrix(),a.rotateZ(-o),a}}(),getFixedFrameEuler:function(){var a,b=new t.Euler;return function(){return a=this.getFixedFrameMatrix(),b.setFromRotationMatrix(a),b}}(),getScreenAdjustedEuler:function(){var a,b=new t.Euler;return function(){return a=this.getScreenAdjustedMatrix(),b.setFromRotationMatrix(a),b}}(),isAbsolute:function(){return l.orientation.data&&l.orientation.data.absolute===!0?!0:!1},getLastRawEventData:function(){return l.orientation.data||{}},_alphaAvailable:!1,_betaAvailable:!1,_gammaAvailable:!1,isAvailable:function(a){switch(a){case this.ALPHA:return this._alphaAvailable;case this.BETA:return this._betaAvailable;case this.GAMMA:return this._gammaAvailable}},ALPHA:"alpha",BETA:"beta",GAMMA:"gamma"},t.DeviceMotion=function(a){this.options=a||{}},t.DeviceMotion.prototype={constructor:t.DeviceMotion,start:function(b){b&&"[object Function]"==Object.prototype.toString.call(b)&&l.motion.callbacks.push(b),m||(n?a.screen.orientation.addEventListener("change",d,!1):a.addEventListener("orientationchange",d,!1)),l.motion.active||(a.addEventListener("devicemotion",f,!1),l.motion.active=!0)},stop:function(){l.motion.active&&(a.removeEventListener("devicemotion",f,!1),l.motion.active=!1)},listen:function(a){this.start(a)},getScreenAdjustedAcceleration:function(){var a=l.motion.data&&l.motion.data.acceleration?l.motion.data.acceleration:{x:0,y:0,z:0},b={};switch(o){case p:b.x=-a.y,b.y=a.x;break;case q:b.x=-a.x,b.y=-a.y;break;case r:case s:b.x=a.y,b.y=-a.x;break;default:b.x=a.x,b.y=a.y}return b.z=a.z,b},getScreenAdjustedAccelerationIncludingGravity:function(){var a=l.motion.data&&l.motion.data.accelerationIncludingGravity?l.motion.data.accelerationIncludingGravity:{x:0,y:0,z:0},b={};switch(o){case p:b.x=-a.y,b.y=a.x;break;case q:b.x=-a.x,b.y=-a.y;break;case r:case s:b.x=a.y,b.y=-a.x;break;default:b.x=a.x,b.y=a.y}return b.z=a.z,b},getScreenAdjustedRotationRate:function(){var a=l.motion.data&&l.motion.data.rotationRate?l.motion.data.rotationRate:{alpha:0,beta:0,gamma:0},b={};switch(o){case p:b.beta=-a.gamma,b.gamma=a.beta;break;case q:b.beta=-a.beta,b.gamma=-a.gamma;break;case r:case s:b.beta=a.gamma,b.gamma=-a.beta;break;default:b.beta=a.beta,b.gamma=a.gamma}return b.alpha=a.alpha,b},getLastRawEventData:function(){return l.motion.data||{}},_accelerationXAvailable:!1,_accelerationYAvailable:!1,_accelerationZAvailable:!1,_accelerationIncludingGravityXAvailable:!1,_accelerationIncludingGravityYAvailable:!1,_accelerationIncludingGravityZAvailable:!1,_rotationRateAlphaAvailable:!1,_rotationRateBetaAvailable:!1,_rotationRateGammaAvailable:!1,isAvailable:function(a){switch(a){case this.ACCELERATION_X:return this._accelerationXAvailable;case this.ACCELERATION_Y:return this._accelerationYAvailable;case this.ACCELERATION_Z:return this._accelerationZAvailable;case this.ACCELERATION_INCLUDING_GRAVITY_X:return this._accelerationIncludingGravityXAvailable;case this.ACCELERATION_INCLUDING_GRAVITY_Y:return this._accelerationIncludingGravityYAvailable;case this.ACCELERATION_INCLUDING_GRAVITY_Z:return this._accelerationIncludingGravityZAvailable;case this.ROTATION_RATE_ALPHA:return this._rotationRateAlphaAvailable;case this.ROTATION_RATE_BETA:return this._rotationRateBetaAvailable;case this.ROTATION_RATE_GAMMA:return this._rotationRateGammaAvailable}},ACCELERATION_X:"accelerationX",ACCELERATION_Y:"accelerationY",ACCELERATION_Z:"accelerationZ",ACCELERATION_INCLUDING_GRAVITY_X:"accelerationIncludingGravityX",ACCELERATION_INCLUDING_GRAVITY_Y:"accelerationIncludingGravityY",ACCELERATION_INCLUDING_GRAVITY_Z:"accelerationIncludingGravityZ",ROTATION_RATE_ALPHA:"rotationRateAlpha",ROTATION_RATE_BETA:"rotationRateBeta",ROTATION_RATE_GAMMA:"rotationRateGamma"},a.FULLTILT=t}}(window); - -/* gyronorm.js v2.0.6 - https://github.com/dorukeker/gyronorm.git*/ -!function(a,b){var c={GyroNorm:b()};"function"==typeof define&&define.amd?define(function(){return c}):"object"==typeof module&&module.exports?module.exports=c:a.GyroNorm=c.GyroNorm}(this,function(){function a(a){return Math.round(a*Math.pow(10,t))/Math.pow(10,t)}function b(){var b={};b=v?o.getScreenAdjustedEuler():o.getFixedFrameEuler();var c=p.getScreenAdjustedAcceleration(),e=p.getScreenAdjustedAccelerationIncludingGravity(),f=p.getScreenAdjustedRotationRate(),g=0;s===d?(g=b.alpha-k,g=0>g?360-Math.abs(g):g):g=b.alpha;var h={"do":{alpha:a(g),beta:a(b.beta),gamma:a(b.gamma),absolute:o.isAbsolute()},dm:{x:a(c.x),y:a(c.y),z:a(c.z),gx:a(e.x),gy:a(e.y),gz:a(e.z),alpha:a(f.alpha),beta:a(f.beta),gamma:a(f.gamma)}};return r&&(h.dm.gx*=l,h.dm.gy*=l,h.dm.gz*=l),h}function c(a){u&&("string"==typeof a&&(a={message:a,code:0}),u(a))}var d="game",e="world",f="deviceorientation",g="acceleration",h="accelerationinludinggravity",i="rotationrate",j=null,k=0,l=0,m=!1,n=!1,o=null,p=null,q=50,r=!0,s=d,t=2,u=null,v=!1,w=function(a){};return w.GAME=d,w.WORLD=e,w.DEVICE_ORIENTATION=f,w.ACCELERATION=g,w.ACCELERATION_INCLUDING_GRAVITY=h,w.ROTATION_RATE=i,w.prototype.init=function(a){a&&a.frequency&&(q=a.frequency),a&&a.gravityNormalized&&(r=a.gravityNormalized),a&&a.orientationBase&&(s=a.orientationBase),a&&"number"==typeof a.decimalCount&&a.decimalCount>=0&&(t=parseInt(a.decimalCount)),a&&a.logger&&(u=a.logger),a&&a.screenAdjusted&&(v=a.screenAdjusted);var b=new FULLTILT.getDeviceOrientation({type:s}).then(function(a){o=a}),c=(new FULLTILT.getDeviceMotion).then(function(a){p=a,l=p.getScreenAdjustedAccelerationIncludingGravity().z>0?-1:1});return Promise.all([b,c]).then(function(){n=!0})},w.prototype.end=function(){try{n=!1,this.stop(),p.stop(),o.stop()}catch(a){c(a)}},w.prototype.start=function(a){return n?(j=setInterval(function(){a(b())},q),void(m=!0)):void c({message:'GyroNorm is not initialized yet. First call the "init()" function.',code:1})},w.prototype.stop=function(){j&&(clearInterval(j),m=!1)},w.prototype.normalizeGravity=function(a){r=a?!0:!1},w.prototype.setHeadDirection=function(){return v||s===e?!1:(k=o.getFixedFrameEuler().alpha,!0)},w.prototype.startLogging=function(a){a&&(u=a)},w.prototype.stopLogging=function(){u=null},w.prototype.isAvailable=function(a){var b=o.getScreenAdjustedEuler(),c=p.getScreenAdjustedAcceleration(),d=p.getScreenAdjustedAccelerationIncludingGravity(),e=p.getScreenAdjustedRotationRate();switch(a){case f:return b.alpha&&null!==b.alpha&&b.beta&&null!==b.beta&&b.gamma&&null!==b.gamma;case g:return c&&c.x&&c.y&&c.z;case h:return d&&d.x&&d.y&&d.z;case i:return e&&e.alpha&&e.beta&&e.gamma;default:return{deviceOrientationAvailable:b.alpha&&null!==b.alpha&&b.beta&&null!==b.beta&&b.gamma&&null!==b.gamma,accelerationAvailable:c&&c.x&&c.y&&c.z,accelerationIncludingGravityAvailable:d&&d.x&&d.y&&d.z,rotationRateAvailable:e&&e.alpha&&e.beta&&e.gamma}}},w.prototype.isRunning=function(){return m},w}); diff --git a/index.html b/index.html index 4a16506..a0f8beb 100755 --- a/index.html +++ b/index.html @@ -47,9 +47,9 @@
No GPS data available.
-
0.00000 N
-
0.00000 E
-
No altitude data available.
+
0.0000 N
+
0.0000 W
+
@@ -58,7 +58,6 @@
No direction available. Try this on a smartphone with an internal compass.
-
Note: the compass may be 90° off when used in landscape mode.
@@ -66,10 +65,9 @@ - From c10ee9e06122b7a7624289770045bb8f996ac97a Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Thu, 4 Oct 2018 00:30:08 +0000 Subject: [PATCH 13/14] Fixed E/W and altitude conversionFixed comment spelling error --- coordinates.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/coordinates.js b/coordinates.js index a12e287..ea2a162 100755 --- a/coordinates.js +++ b/coordinates.js @@ -11,7 +11,7 @@ if (!navigator.geolocation) $('#no-gps').show() // Start tracking else navigator.geolocation.watchPosition( - // Got location callback + // Got location callbackw function(pos) { let lat = pos.coords.latitude.toFixed(4) let lon = pos.coords.longitude.toFixed(4) @@ -21,16 +21,17 @@ else navigator.geolocation.watchPosition( ) $('#lon').text( (lon.substring(0,1)=='-')? // Negative values are East - lon.substring(1)+' E' : lon+' W' + lon.substring(1)+' W' : lon+' E' ) - // Get altitude - if (pos.coords.altitude) + // Get altitude + if (pos.coords.altitude) { $('#alt').show().text( (metric)? // Convert to feet if needed pos.coords.altitude.toFixed(1)+' m': - (pos.coords.altitude*0.3048).toFixed(1)+' ft' + (pos.coords.altitude*3.28084).toFixed(1)+' ft' ) + } else $('#alt').hide() }, From 0eba5427e658bb0c127c6189a1d4dbacc5c0d9b4 Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Thu, 4 Oct 2018 00:30:47 +0000 Subject: [PATCH 14/14] Removed rotation error (for now) --- style.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/style.css b/style.css index 35a25c4..01af430 100755 --- a/style.css +++ b/style.css @@ -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;