From 7de6cb4fd414056443e3d1d0299da4e6e70fc5a3 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 16 Feb 2013 20:19:38 +0100 Subject: [PATCH] Add remaining geolocation properties --- src/ol/geolocation.js | 97 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 16 deletions(-) diff --git a/src/ol/geolocation.js b/src/ol/geolocation.js index b75aaaf38c..e9271bebde 100644 --- a/src/ol/geolocation.js +++ b/src/ol/geolocation.js @@ -15,8 +15,12 @@ goog.require('ol.Projection'); */ ol.GeolocationProperty = { ACCURACY: 'accuracy', + ALTITUDE: 'altitude', + ALTITUDE_ACCURACY: 'altitudeAccuracy', + HEADING: 'heading', POSITION: 'position', - PROJECTION: 'projection' + PROJECTION: 'projection', + SPEED: 'speed' }; @@ -92,10 +96,19 @@ ol.Geolocation.isSupported = 'geolocation' in navigator; */ ol.Geolocation.prototype.positionChange_ = function(position) { var coords = position.coords; + this.set(ol.GeolocationProperty.ACCURACY, coords.accuracy); + this.set(ol.GeolocationProperty.ALTITUDE, + goog.isNull(coords.altitude) ? undefined : coords.altitude); + this.set(ol.GeolocationProperty.ALTITUDE_ACCURACY, + goog.isNull(coords.altitudeAccuracy) ? + undefined : coords.altitudeAccuracy); + this.set(ol.GeolocationProperty.HEADING, + goog.isNull(coords.heading) ? undefined : coords.heading); this.position_ = new ol.Coordinate(coords.longitude, coords.latitude); this.set(ol.GeolocationProperty.POSITION, this.transformCoords_(this.position_)); - this.set(ol.GeolocationProperty.ACCURACY, coords.accuracy); + this.set(ol.GeolocationProperty.SPEED, + goog.isNull(coords.speed) ? undefined : coords.speed); }; @@ -107,20 +120,6 @@ ol.Geolocation.prototype.positionError_ = function(error) { }; -/** - * The position of the device. - * @return {ol.Coordinate|undefined} position. - */ -ol.Geolocation.prototype.getPosition = function() { - return /** @type {ol.Coordinate} */ ( - this.get(ol.GeolocationProperty.POSITION)); -}; -goog.exportProperty( - ol.Geolocation.prototype, - 'getPosition', - ol.Geolocation.prototype.getPosition); - - /** * The accuracy of the position in meters. * @return {number|undefined} accuracy. @@ -135,6 +134,59 @@ goog.exportProperty( ol.Geolocation.prototype.getAccuracy); +/** + * @return {number|undefined} Altitude. + */ +ol.Geolocation.prototype.getAltitude = function() { + return /** @type {number|undefined} */ ( + this.get(ol.GeolocationProperty.ALTITUDE)); +}; +goog.exportProperty( + ol.Geolocation.prototype, + 'getAltitude', + ol.Geolocation.prototype.getAltitude); + + +/** + * @return {number|undefined} Altitude accuracy. + */ +ol.Geolocation.prototype.getAltitudeAccuracy = function() { + return /** @type {number|undefined} */ ( + this.get(ol.GeolocationProperty.ALTITUDE_ACCURACY)); +}; +goog.exportProperty( + ol.Geolocation.prototype, + 'getAltitudeAccuracy', + ol.Geolocation.prototype.getAltitudeAccuracy); + + +/** + * @return {number|undefined} Heading. + */ +ol.Geolocation.prototype.getHeading = function() { + return /** @type {number|undefined} */ ( + this.get(ol.GeolocationProperty.HEADING)); +}; +goog.exportProperty( + ol.Geolocation.prototype, + 'getHeading', + ol.Geolocation.prototype.getHeading); + + +/** + * The position of the device. + * @return {ol.Coordinate|undefined} position. + */ +ol.Geolocation.prototype.getPosition = function() { + return /** @type {ol.Coordinate} */ ( + this.get(ol.GeolocationProperty.POSITION)); +}; +goog.exportProperty( + ol.Geolocation.prototype, + 'getPosition', + ol.Geolocation.prototype.getPosition); + + /** * @return {ol.Projection|undefined} projection. */ @@ -148,6 +200,19 @@ goog.exportProperty( ol.Geolocation.prototype.getProjection); +/** + * @return {number|undefined} Speed. + */ +ol.Geolocation.prototype.getSpeed = function() { + return /** @type {number|undefined} */ ( + this.get(ol.GeolocationProperty.SPEED)); +}; +goog.exportProperty( + ol.Geolocation.prototype, + 'getSpeed', + ol.Geolocation.prototype.getSpeed); + + /** * @param {ol.Projection} projection Projection. */