Add 'heading' property to ol.DeviceOrientation
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
<p>α : <code id="alpha"></code></p>
|
||||
<p>β : <code id="beta"></code></p>
|
||||
<p>γ : <code id="gamma"></code></p>
|
||||
<p>heading : <code id="heading"></code></p>
|
||||
<p id="shortdesc">Listen to DeviceOrientation events</p>
|
||||
<div id="docs">
|
||||
<p>See the <a href="device-orientation.js" target="_blank">device-orientation.js source</a> to see how this is done.</p>
|
||||
|
||||
@@ -29,4 +29,5 @@ deviceOrientation.on('changed', function() {
|
||||
document.getElementById('alpha').innerHTML = deviceOrientation.getAlpha();
|
||||
document.getElementById('beta').innerHTML = deviceOrientation.getBeta();
|
||||
document.getElementById('gamma').innerHTML = deviceOrientation.getGamma();
|
||||
document.getElementById('heading').innerHTML = deviceOrientation.getHeading();
|
||||
});
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user