Add addControl and removeControl methods to ol.Map

This commit is contained in:
Éric Lemoine
2013-06-04 07:09:25 +02:00
parent b85520f504
commit be86b83b67
2 changed files with 28 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
@exportClass ol.Map ol.MapOptions
@exportProperty ol.Map.prototype.addControl
@exportProperty ol.Map.prototype.addLayer
@exportProperty ol.Map.prototype.addPreRenderFunction
@exportProperty ol.Map.prototype.addPreRenderFunctions
@@ -6,6 +7,7 @@
@exportProperty ol.Map.prototype.getFeatures
@exportProperty ol.Map.prototype.getInteractions
@exportProperty ol.Map.prototype.getRenderer
@exportProperty ol.Map.prototype.removeControl
@exportProperty ol.Map.prototype.removeLayer
@exportProperty ol.Map.prototype.updateSize

View File

@@ -338,6 +338,18 @@ ol.Map = function(options) {
goog.inherits(ol.Map, ol.Object);
/**
* Add the given control to the map.
* @param {ol.control.Control} control Control.
*/
ol.Map.prototype.addControl = function(control) {
var controls = this.getControls();
goog.asserts.assert(goog.isDef(controls));
controls.push(control);
control.setMap(this);
};
/**
* Adds the given layer to the top of this map.
* @param {ol.layer.Layer} layer Layer.
@@ -809,6 +821,20 @@ ol.Map.prototype.requestRenderFrame = function() {
};
/**
* Remove the given control from the map.
* @param {ol.control.Control} control Control.
* @return {ol.control.Control|undefined} The removed control of undefined
* if the control was not found.
*/
ol.Map.prototype.removeControl = function(control) {
var controls = this.getControls();
goog.asserts.assert(goog.isDef(controls));
control.setMap(null);
return /** @type {ol.control.Control|undefined} */ (controls.remove(control));
};
/**
* Removes the given layer from the map.
* @param {ol.layer.Layer} layer Layer.