Skip to content

Commit

Permalink
Make interaction "active" an ol.Object property
Browse files Browse the repository at this point in the history
  • Loading branch information
elemoine committed Sep 29, 2014
1 parent 1a4d841 commit dede4f3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
37 changes: 27 additions & 10 deletions src/ol/interaction/interaction.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
// FIXME factor out key precondition (shift et. al)

goog.provide('ol.interaction.Interaction');
goog.provide('ol.interaction.InteractionProperty');

goog.require('goog.asserts');
goog.require('ol.MapBrowserEvent');
goog.require('ol.Observable');
goog.require('ol.Object');
goog.require('ol.animation');
goog.require('ol.easing');


/**
* @enum {string}
*/
ol.interaction.InteractionProperty = {
ACTIVE: 'active'
};



/**
* @classdesc
Expand All @@ -23,9 +32,10 @@ goog.require('ol.easing');
* vectors and so are visible on the screen.
*
* @constructor
* @extends {ol.Observable}
* @extends {ol.Object}
*/
ol.interaction.Interaction = function() {

goog.base(this);

/**
Expand All @@ -34,23 +44,25 @@ ol.interaction.Interaction = function() {
*/
this.map_ = null;

/**
* @private
* @type {boolean}
*/
this.active_ = true;
this.setActive(true);

};
goog.inherits(ol.interaction.Interaction, ol.Observable);
goog.inherits(ol.interaction.Interaction, ol.Object);


/**
* @return {boolean} `true` if the interaction is active, `false` otherwise.
* @observable
* @api
*/
ol.interaction.Interaction.prototype.getActive = function() {
return this.active_;
return /** @type {boolean} */ (
this.get(ol.interaction.InteractionProperty.ACTIVE));
};
goog.exportProperty(
ol.interaction.Interaction.prototype,
'getActive',
ol.interaction.Interaction.prototype.getActive);


/**
Expand All @@ -75,11 +87,16 @@ ol.interaction.Interaction.prototype.handleMapBrowserEvent =
/**
* Activate or deactivate the interaction.
* @param {boolean} active Active.
* @observable
* @api
*/
ol.interaction.Interaction.prototype.setActive = function(active) {
this.active_ = active;
this.set(ol.interaction.InteractionProperty.ACTIVE, active);
};
goog.exportProperty(
ol.interaction.Interaction.prototype,
'setActive',
ol.interaction.Interaction.prototype.setActive);


/**
Expand Down
10 changes: 9 additions & 1 deletion test/spec/ol/interaction/interaction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ goog.provide('ol.test.interaction.Interaction');
describe('ol.interaction.Interaction', function() {

describe('constructor', function() {
var interaction;

beforeEach(function() {
interaction = new ol.interaction.Interaction();
});

it('creates a new interaction', function() {
var interaction = new ol.interaction.Interaction();
expect(interaction).to.be.a(ol.interaction.Interaction);
expect(interaction).to.be.a(goog.events.EventTarget);
});

it('creates an active interaction', function() {
expect(interaction.getActive()).to.be(true);
});

});

describe('#getMap()', function() {
Expand Down

0 comments on commit dede4f3

Please sign in to comment.