Merge pull request #1173 from tschaub/map-interaction

Give interactions a reference to their map.
This commit is contained in:
Tim Schaub
2013-11-01 15:30:19 -07:00
4 changed files with 162 additions and 0 deletions
@@ -0,0 +1,50 @@
goog.provide('ol.test.interaction.Interaction');
describe('ol.interaction.Interaction', function() {
describe('constructor', function() {
it('creates a new interaction', function() {
var interaction = new ol.interaction.Interaction();
expect(interaction).to.be.a(ol.interaction.Interaction);
});
});
describe('#getMap()', function() {
it('retrieves the associated map', function() {
var map = new ol.Map({});
var interaction = new ol.interaction.Interaction();
interaction.setMap(map);
expect(interaction.getMap()).to.be(map);
});
it('returns null if no map', function() {
var interaction = new ol.interaction.Interaction();
expect(interaction.getMap()).to.be(null);
});
});
describe('#setMap()', function() {
it('allows a map to be set', function() {
var map = new ol.Map({});
var interaction = new ol.interaction.Interaction();
interaction.setMap(map);
expect(interaction.getMap()).to.be(map);
});
it('accepts null', function() {
var interaction = new ol.interaction.Interaction();
interaction.setMap(null);
expect(interaction.getMap()).to.be(null);
});
});
});
goog.require('ol.Map');
goog.require('ol.interaction.Interaction');
+47
View File
@@ -51,6 +51,52 @@ describe('ol.RendererHints', function() {
describe('ol.Map', function() {
describe('contstructor', function() {
it('creates a new map', function() {
var map = new ol.Map({});
expect(map).to.be.a(ol.Map);
});
it('creates a set of default interactions', function() {
var map = new ol.Map({});
var interactions = map.getInteractions();
var length = interactions.getLength();
expect(length).to.be.greaterThan(0);
for (var i = 0; i < length; ++i) {
expect(interactions.getAt(i).getMap()).to.be(map);
}
});
});
describe('#addInteraction()', function() {
it('adds an interaction to the map', function() {
var map = new ol.Map({});
var interaction = new ol.interaction.Interaction();
var before = map.getInteractions().getLength();
map.addInteraction(interaction);
var after = map.getInteractions().getLength();
expect(after).to.be(before + 1);
expect(interaction.getMap()).to.be(map);
});
});
describe('#removeInteraction()', function() {
it('removes an interaction from the map', function() {
var map = new ol.Map({});
var interaction = new ol.interaction.Interaction();
var before = map.getInteractions().getLength();
map.addInteraction(interaction);
map.removeInteraction(interaction);
expect(map.getInteractions().getLength()).to.be(before);
expect(interaction.getMap()).to.be(null);
});
});
describe('dispose', function() {
var map;
@@ -128,5 +174,6 @@ goog.require('ol.Map');
goog.require('ol.RendererHint');
goog.require('ol.RendererHints');
goog.require('ol.interaction');
goog.require('ol.interaction.Interaction');
goog.require('ol.interaction.DoubleClickZoom');
goog.require('ol.interaction.MouseWheelZoom');