Add 'heading' property to ol.DeviceOrientation

This commit is contained in:
Frederic Junod
2013-04-16 11:40:10 +02:00
parent c431cc7f63
commit 15e5242611
3 changed files with 22 additions and 3 deletions
+20 -3
View File
@@ -1,4 +1,3 @@
// FIXME: event.absolute
goog.provide('ol.DeviceOrientation');
goog.provide('ol.DeviceOrientationProperty');
@@ -14,6 +13,7 @@ ol.DeviceOrientationProperty = {
ALPHA: 'alpha',
BETA: 'beta',
GAMMA: 'gamma',
HEADING: 'heading',
TRACKING: 'tracking'
};
@@ -67,8 +67,12 @@ ol.DeviceOrientation.prototype.orientationChange_ = function(browserEvent) {
var event = /** @type {DeviceOrientationEvent} */
(browserEvent.getBrowserEvent());
if (goog.isDefAndNotNull(event.alpha)) {
this.set(ol.DeviceOrientationProperty.ALPHA,
goog.math.toRadians(event.alpha));
var alpha = goog.math.toRadians(event.alpha);
this.set(ol.DeviceOrientationProperty.ALPHA, alpha);
// event.absolute is undefined in iOS.
if (goog.isBoolean(event.absolute) && event.absolute) {
this.set(ol.DeviceOrientationProperty.HEADING, alpha);
}
}
if (goog.isDefAndNotNull(event.beta)) {
this.set(ol.DeviceOrientationProperty.BETA,
@@ -120,6 +124,19 @@ goog.exportProperty(
ol.DeviceOrientation.prototype.getGamma);
/**
* @return {number|undefined} heading.
*/
ol.DeviceOrientation.prototype.getHeading = function() {
return /** @type {number} */ (
this.get(ol.DeviceOrientationProperty.HEADING));
};
goog.exportProperty(
ol.DeviceOrientation.prototype,
'getHeading',
ol.DeviceOrientation.prototype.getHeading);
/**
* @return {boolean|undefined} tracking.
*/