Add controls to map

This commit is contained in:
Tom Payne
2012-09-28 12:52:47 +02:00
parent e7eccb302d
commit e2e983728e
4 changed files with 91 additions and 2 deletions
+47
View File
@@ -176,6 +176,25 @@ ol.Map = function(container, mapOptionsLiteral) {
this.handleBrowserEvent, false, this);
this.registerDisposable(mouseWheelHandler);
/**
* @type {ol.Collection}
* @private
*/
this.controls_ = mapOptions.controls;
this.controls_.forEach(
/**
* @param {ol.control.Control} control Control.
*/
function(control) {
control.setMap(this);
}, this);
goog.events.listen(this.controls_, ol.CollectionEventType.ADD,
this.handleControlsAdd_, false, this);
goog.events.listen(this.controls_, ol.CollectionEventType.REMOVE,
this.handleControlsRemove_, false, this);
/**
* @type {ol.renderer.Map}
* @private
@@ -280,6 +299,14 @@ ol.Map.prototype.getContainer = function() {
};
/**
* @return {ol.Collection} Controls.
*/
ol.Map.prototype.getControls = function() {
return this.controls_;
};
/**
* @param {ol.Pixel} pixel Pixel.
* @return {ol.Coordinate} Coordinate.
@@ -488,6 +515,26 @@ ol.Map.prototype.handleBrowserEvent = function(browserEvent, opt_type) {
};
/**
* @param {ol.CollectionEvent} collectionEvent Collection event.
* @private
*/
ol.Map.prototype.handleControlsAdd_ = function(collectionEvent) {
var control = /** @type {ol.control.Control} */ collectionEvent.elem;
control.setMap(this);
};
/**
* @param {ol.CollectionEvent} collectionEvent Collection event.
* @private
*/
ol.Map.prototype.handleControlsRemove_ = function(collectionEvent) {
var control = /** @type {ol.control.Control} */ collectionEvent.elem;
control.setMap(null);
};
/**
* @param {ol.MapBrowserEvent} mapBrowserEvent The event to handle.
*/