From be7228f78ebbe128b30bdef1c9f509c41e3e177c Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 20 Apr 2013 16:44:16 +0200 Subject: [PATCH] Add options to ol.Geolocation constructor --- src/objectliterals.jsdoc | 7 +++++++ src/ol/geolocation.js | 18 +++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index efd75780ced..1c9b194871a 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -1,3 +1,10 @@ +/** + * @typedef {Object} ol.GeolocationOptions + * @property {boolean|undefined} tracking Tracking. + * @property {GeolocationPositionOptions|undefined} trackingOptions Tracking options. + * @property {ol.ProjectionLike} projection Projection. + */ + /** * Object literal with config options for the map. * @typedef {Object} ol.MapOptions diff --git a/src/ol/geolocation.js b/src/ol/geolocation.js index 81bdc95d1bd..c16a88d8665 100644 --- a/src/ol/geolocation.js +++ b/src/ol/geolocation.js @@ -33,11 +33,14 @@ ol.GeolocationProperty = { /** * @constructor * @extends {ol.Object} + * @param {ol.GeolocationOptions=} opt_options Options. */ -ol.Geolocation = function() { +ol.Geolocation = function(opt_options) { goog.base(this); + var options = goog.isDef(opt_options) ? opt_options : {}; + /** * The unprojected (EPSG:4326) device position. * @private @@ -51,14 +54,23 @@ ol.Geolocation = function() { */ this.watchId_ = undefined; - this.setTracking(false); - goog.events.listen( this, ol.Object.getChangedEventType(ol.GeolocationProperty.PROJECTION), this.handleProjectionChanged_, false, this); goog.events.listen( this, ol.Object.getChangedEventType(ol.GeolocationProperty.TRACKING), this.handleTrackingChanged_, false, this); + + if (goog.isDef(options.projection)) { + this.setProjection(ol.projection.get(options.projection)); + } + if (goog.isDef(options.trackingOptions)) { + this.setTrackingOptions(options.trackingOptions); + } + if (goog.isDef(options.tracking)) { + this.setTracking(options.tracking); + } + }; goog.inherits(ol.Geolocation, ol.Object);