Merge pull request #58 from elemoine/dispose
The map should be disposable
This commit is contained in:
@@ -49,6 +49,15 @@ ol.control.Control = function(controlOptions) {
|
|||||||
goog.inherits(ol.control.Control, goog.Disposable);
|
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.
|
* @return {ol.Map} Map.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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.
|
* @param {ol.Extent} extent Extent.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -285,9 +285,11 @@ ol.MapBrowserEventHandler.prototype.disposeInternal = function() {
|
|||||||
this.handleUp_, false, this);
|
this.handleUp_, false, this);
|
||||||
goog.events.unlisten(element,
|
goog.events.unlisten(element,
|
||||||
goog.events.EventType.CLICK, this.click_, false, this);
|
goog.events.EventType.CLICK, this.click_, false, this);
|
||||||
goog.asserts.assert(goog.isDef(this.dragListenerKeys_));
|
if (!goog.isNull(this.dragListenerKeys_)) {
|
||||||
goog.array.forEach(this.dragListenerKeys_, goog.events.unlistenByKey);
|
goog.array.forEach(this.dragListenerKeys_, goog.events.unlistenByKey);
|
||||||
this.dragListenerKeys_ = null;
|
this.dragListenerKeys_ = null;
|
||||||
|
}
|
||||||
|
goog.base(this, 'disposeInternal');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,7 @@
|
|||||||
<script type="text/javascript" src="spec/ol/tilegrid.test.js"></script>
|
<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/tilerange.test.js"></script>
|
||||||
<script type="text/javascript" src="spec/ol/tileurlfunction.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">
|
<script type="text/javascript">
|
||||||
|
|
||||||
@@ -124,5 +125,6 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<div id="map"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,7 +1,23 @@
|
|||||||
|
goog.require('goog.dom');
|
||||||
goog.require('ol.Map');
|
goog.require('ol.Map');
|
||||||
|
|
||||||
describe('ol.Map', function() {
|
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 constraints', function() {
|
||||||
|
|
||||||
describe('create resolution constraint', function() {
|
describe('create resolution constraint', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user