diff --git a/examples/mobile-full-screen.js b/examples/mobile-full-screen.js index 19d54c7a2d..8803e0a5fd 100644 --- a/examples/mobile-full-screen.js +++ b/examples/mobile-full-screen.js @@ -29,7 +29,7 @@ var geolocation = new ol.Geolocation({ tracking: true }); geolocation.bindTo('projection', view); -geolocation.on('position_changed', function() { +geolocation.onOnce('position_changed', function() { view.setCenter(geolocation.getPosition()); view.setResolution(2.388657133911758); }); diff --git a/src/ol/object.exports b/src/ol/object.exports index 079e2bcd67..36ddd7c276 100644 --- a/src/ol/object.exports +++ b/src/ol/object.exports @@ -3,9 +3,11 @@ @exportProperty ol.Object.prototype.get @exportProperty ol.Object.prototype.notify @exportProperty ol.Object.prototype.on +@exportProperty ol.Object.prototype.onOnce @exportProperty ol.Object.prototype.set @exportProperty ol.Object.prototype.setOptions @exportProperty ol.Object.prototype.setValues @exportProperty ol.Object.prototype.un +@exportProperty ol.Object.prototype.unByKey @exportProperty ol.Object.prototype.unbind @exportProperty ol.Object.prototype.unbindAll diff --git a/src/ol/object.js b/src/ol/object.js index 318d1a6482..6b698c773f 100644 --- a/src/ol/object.js +++ b/src/ol/object.js @@ -228,9 +228,22 @@ ol.Object.prototype.notifyInternal_ = function(key) { * @param {Function} listener The listener function. * @param {Object=} opt_scope Object is whose scope to call * the listener. + * @return {?number} Unique key for the listener. */ ol.Object.prototype.on = function(type, listener, opt_scope) { - goog.events.listen(this, type, listener, false, opt_scope); + return goog.events.listen(this, type, listener, false, opt_scope); +}; + + +/** + * @param {string} type The event type. + * @param {Function} listener The listener function. + * @param {Object=} opt_scope Object is whose scope to call + * the listener. + * @return {?number} Unique key for the listener. + */ +ol.Object.prototype.onOnce = function(type, listener, opt_scope) { + return goog.events.listenOnce(this, type, listener, false, opt_scope); }; @@ -308,6 +321,14 @@ ol.Object.prototype.un = function(type, listener, opt_scope) { }; +/** + * @param {?number} key Key. + */ +ol.Object.prototype.unByKey = function(key) { + goog.events.unlistenByKey(key); +}; + + /** * Removes all bindings. */