Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The map should be disposable #58

Merged
merged 7 commits into from Oct 12, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/ol/control/control.js
Expand Up @@ -49,6 +49,15 @@ ol.control.Control = function(controlOptions) {
goog.inherits(ol.control.Control, goog.Disposable);


/**
* @inheritDoc
*/
ol.control.Control.prototype.disposeInternal = function() {
goog.dom.removeNode(this.element);
goog.base(this, 'disposeInternal');
};


/**
* @return {ol.Map} Map.
*/
Expand Down
10 changes: 10 additions & 0 deletions src/ol/map.js
Expand Up @@ -290,6 +290,16 @@ ol.Map.prototype.canRotate = function() {
};


/**
*
* @inheritDoc
*/
ol.Map.prototype.disposeInternal = function() {
goog.dom.removeNode(this.viewport_);
goog.base(this, 'disposeInternal');
};


/**
* @param {ol.Extent} extent Extent.
*/
Expand Down
8 changes: 5 additions & 3 deletions src/ol/mapbrowserevent.js
Expand Up @@ -285,9 +285,11 @@ ol.MapBrowserEventHandler.prototype.disposeInternal = function() {
this.handleUp_, false, this);
goog.events.unlisten(element,
goog.events.EventType.CLICK, this.click_, false, this);
goog.asserts.assert(goog.isDef(this.dragListenerKeys_));
goog.array.forEach(this.dragListenerKeys_, goog.events.unlistenByKey);
this.dragListenerKeys_ = null;
if (!goog.isNull(this.dragListenerKeys_)) {
goog.array.forEach(this.dragListenerKeys_, goog.events.unlistenByKey);
this.dragListenerKeys_ = null;
}
goog.base(this, 'disposeInternal');
};


Expand Down
2 changes: 2 additions & 0 deletions test/ol.html
Expand Up @@ -83,6 +83,7 @@
<script type="text/javascript" src="spec/ol/tilegrid.test.js"></script>
<script type="text/javascript" src="spec/ol/tilerange.test.js"></script>
<script type="text/javascript" src="spec/ol/tileurlfunction.test.js"></script>
<script type="text/javascript" src="spec/ol/control/control.test.js"></script>

<script type="text/javascript">

Expand Down Expand Up @@ -124,5 +125,6 @@
</head>

<body>
<div id="map"></div>
</body>
</html>
27 changes: 27 additions & 0 deletions test/spec/ol/control/control.test.js
@@ -0,0 +1,27 @@
goog.require('goog.dom');
goog.require('ol.Map');
goog.require('ol.control.Control');

describe('ol.control.Control', function() {
var map, control;

beforeEach(function() {
map = new ol.Map({
target: document.getElementById('map')
});
var element = goog.dom.createDom(goog.dom.TagName.DIV);
control = new ol.control.Control({element: element});
control.setMap(map);
});

afterEach(function() {
map.dispose();
});

describe('dispose', function() {
it('removes the control element from its parent', function() {
control.dispose();
expect(goog.dom.getParentElement(control.element)).toBeNull();
});
});
});
16 changes: 16 additions & 0 deletions test/spec/ol/map.test.js
@@ -1,7 +1,23 @@
goog.require('goog.dom');
goog.require('ol.Map');

describe('ol.Map', function() {

describe('dispose', function() {
var map;

beforeEach(function() {
map = new ol.Map({
target: document.getElementById('map')
});
});

it('removes the viewport from its parent', function() {
map.dispose();
expect(goog.dom.getParentElement(map.getViewport())).toBeNull();
});
});

describe('create constraints', function() {

describe('create resolution constraint', function() {
Expand Down