From 69872c99d27cc063dc88bc2a9ead3f64359778a2 Mon Sep 17 00:00:00 2001 From: Paul Spencer Date: Sat, 7 Sep 2013 21:48:49 -0400 Subject: [PATCH 1/3] Detect iOS compass heading iOS webkit does not provide an absolute alpha, instead it provides webkitCompassHeading. --- src/ol/deviceorientation.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ol/deviceorientation.js b/src/ol/deviceorientation.js index 3b86d5bba4..c10584091a 100644 --- a/src/ol/deviceorientation.js +++ b/src/ol/deviceorientation.js @@ -122,6 +122,9 @@ ol.DeviceOrientation.prototype.orientationChange_ = function(browserEvent) { // event.absolute is undefined in iOS. if (goog.isBoolean(event.absolute) && event.absolute) { this.set(ol.DeviceOrientationProperty.HEADING, alpha); + } else if (goog.isDefAndNotNull(event.webkitCompassHeading)) { + var heading = goog.math.toRadians(event.webkitCompassHeading); + this.set(ol.DeviceOrientationProperty.HEADING, heading); } } if (goog.isDefAndNotNull(event.beta)) { From 4bae5e755a70595b16a07d34193ea0d1bbb1e48a Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Sat, 7 Sep 2013 10:10:31 +0200 Subject: [PATCH 2/3] Rename externs/html5.js to externs/closure-compiler.js Add add a fix for issues: * https://code.google.com/p/closure-compiler/issues/detail?id=1084 * https://code.google.com/p/closure-compiler/issues/detail?id=1088 --- build.py | 2 +- buildcfg/base.json | 2 +- buildcfg/ol-all.json | 2 +- buildcfg/ol-simple.json | 2 +- buildcfg/ol-whitespace.json | 2 +- buildcfg/ol.json | 2 +- externs/closure-compiler.js | 38 +++++++++++++++++++++++++++++++++++++ externs/html5.js | 17 ----------------- 8 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 externs/closure-compiler.js delete mode 100644 externs/html5.js diff --git a/build.py b/build.py index ca6130a78a..e8ecd57fe4 100755 --- a/build.py +++ b/build.py @@ -316,7 +316,7 @@ def examples_star_json(name, match): '../externs/oli.js', '../externs/proj4js.js', '../externs/tilejson.js', - '../externs/html5.js', + '../externs/closure-compiler.js', ], }) with open(t.name, 'w') as f: diff --git a/buildcfg/base.json b/buildcfg/base.json index 6b645e49e7..4a0fc293c1 100644 --- a/buildcfg/base.json +++ b/buildcfg/base.json @@ -46,7 +46,7 @@ "../externs/oli.js", "../externs/proj4js.js", "../externs/tilejson.js", - "../externs/html5.js" + "../externs/closure-compiler.js" ], "level": "VERBOSE", diff --git a/buildcfg/ol-all.json b/buildcfg/ol-all.json index a808f0f797..b3a6cfd3de 100644 --- a/buildcfg/ol-all.json +++ b/buildcfg/ol-all.json @@ -11,7 +11,7 @@ "../externs/oli.js", "../externs/proj4js.js", "../externs/tilejson.js", - "../externs/html5.js" + "../externs/closure-compiler.js" ], "inherits": "base.json", diff --git a/buildcfg/ol-simple.json b/buildcfg/ol-simple.json index d7e50b1552..93192f4484 100644 --- a/buildcfg/ol-simple.json +++ b/buildcfg/ol-simple.json @@ -20,7 +20,7 @@ "../externs/oli.js", "../externs/proj4js.js", "../externs/tilejson.js", - "../externs/html5.js" + "../externs/closure-compiler.js" ], "inherits": "ol.json", diff --git a/buildcfg/ol-whitespace.json b/buildcfg/ol-whitespace.json index 4364a2769d..fb956da2fd 100644 --- a/buildcfg/ol-whitespace.json +++ b/buildcfg/ol-whitespace.json @@ -21,7 +21,7 @@ "../externs/oli.js", "../externs/proj4js.js", "../externs/tilejson.js", - "../externs/html5.js" + "../externs/closure-compiler.js" ], "inherits": "ol.json", diff --git a/buildcfg/ol.json b/buildcfg/ol.json index c64d3fbf0d..7bfc960045 100644 --- a/buildcfg/ol.json +++ b/buildcfg/ol.json @@ -21,7 +21,7 @@ "../externs/oli.js", "../externs/proj4js.js", "../externs/tilejson.js", - "../externs/html5.js" + "../externs/closure-compiler.js" ], "inherits": "base.json", diff --git a/externs/closure-compiler.js b/externs/closure-compiler.js new file mode 100644 index 0000000000..7632dd8368 --- /dev/null +++ b/externs/closure-compiler.js @@ -0,0 +1,38 @@ +/** + * @fileoverview Definitions for externs that are either missing or incorrect + * in the current release version of the closure compiler we use. + * + * The entries must be removed once they are available/correct in the + * version we use. + * + * @externs + */ + +// @see https://code.google.com/p/closure-compiler/issues/detail?id=1060 + +/** @type {Date} */ +HTMLInputElement.prototype.valueAsDate; + +/** @type {number} */ +HTMLInputElement.prototype.valueAsNumber; + + +// @see https://code.google.com/p/closure-compiler/issues/detail?id=1084 + +/** @type {?number} */ +DeviceRotationRate.prototype.alpha; + +/** @type {?number} */ +DeviceRotationRate.prototype.beta; + +/** @type {?number} */ +DeviceRotationRate.prototype.gamma; + + +// @see https://code.google.com/p/closure-compiler/issues/detail?id=1088 + +/** @type {?number} */ +DeviceOrientationEvent.prototype.webkitCompassAccuracy; + +/** @type {?number} */ +DeviceOrientationEvent.prototype.webkitCompassHeading; diff --git a/externs/html5.js b/externs/html5.js deleted file mode 100644 index bc8a63ad2f..0000000000 --- a/externs/html5.js +++ /dev/null @@ -1,17 +0,0 @@ -/** - * @fileoverview Definitions for extensions over the W3C's DOM3 specification - * in HTML5 which are not yet available with the current release version of - * the closure compiler we use. - * @see http://dev.w3.org/html5/spec/Overview.html - * @externs - */ - -// See issue https://code.google.com/p/closure-compiler/issues/detail?id=1060 -// FIXME: this should be remove when the next closure compiler release is out -// with valueAsDate and valueAsNumber externs. - -/** @type {Date} */ -HTMLInputElement.prototype.valueAsDate; - -/** @type {number} */ -HTMLInputElement.prototype.valueAsNumber; From 4117a5df2d5ddcc4614dad2180c42318d5836113 Mon Sep 17 00:00:00 2001 From: Paul Spencer Date: Mon, 9 Sep 2013 08:05:37 -0400 Subject: [PATCH 3/3] check iOS compass calibration via webkitCompassAccuracy Ensure that webkitCompassAccuracy is not -1 as this indicates that the compass has not been calibrated and its values cannot be trusted. --- src/ol/deviceorientation.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ol/deviceorientation.js b/src/ol/deviceorientation.js index c10584091a..a9660d1119 100644 --- a/src/ol/deviceorientation.js +++ b/src/ol/deviceorientation.js @@ -122,7 +122,9 @@ ol.DeviceOrientation.prototype.orientationChange_ = function(browserEvent) { // event.absolute is undefined in iOS. if (goog.isBoolean(event.absolute) && event.absolute) { this.set(ol.DeviceOrientationProperty.HEADING, alpha); - } else if (goog.isDefAndNotNull(event.webkitCompassHeading)) { + } else if (goog.isDefAndNotNull(event.webkitCompassHeading) && + goog.isDefAndNotNull(event.webkitCompassAccuracy) && + event.webkitCompassAccuracy != -1) { var heading = goog.math.toRadians(event.webkitCompassHeading); this.set(ol.DeviceOrientationProperty.HEADING, heading); }