The map now has a collection of controls
This commit is contained in:
@@ -247,6 +247,12 @@ ol.Map = function(options) {
|
||||
this.handleBrowserEvent, false, this);
|
||||
this.registerDisposable(mouseWheelHandler);
|
||||
|
||||
/**
|
||||
* @type {ol.Collection}
|
||||
* @private
|
||||
*/
|
||||
this.controls_ = optionsInternal.controls;
|
||||
|
||||
/**
|
||||
* @type {ol.Collection}
|
||||
* @private
|
||||
@@ -320,15 +326,13 @@ ol.Map = function(options) {
|
||||
// is "defined" already.
|
||||
this.setValues(optionsInternal.values);
|
||||
|
||||
if (goog.isDef(optionsInternal.controls)) {
|
||||
goog.array.forEach(optionsInternal.controls,
|
||||
/**
|
||||
* @param {ol.control.Control} control Control.
|
||||
*/
|
||||
function(control) {
|
||||
control.setMap(this);
|
||||
}, this);
|
||||
}
|
||||
this.controls_.forEach(
|
||||
/**
|
||||
* @param {ol.control.Control} control Control.
|
||||
*/
|
||||
function(control) {
|
||||
control.setMap(this);
|
||||
}, this);
|
||||
|
||||
};
|
||||
goog.inherits(ol.Map, ol.Object);
|
||||
@@ -434,6 +438,14 @@ ol.Map.prototype.getCoordinateFromPixel = function(pixel) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.Collection} Controls.
|
||||
*/
|
||||
ol.Map.prototype.getControls = function() {
|
||||
return this.controls_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get feature information for a pixel on the map.
|
||||
*
|
||||
@@ -997,7 +1009,7 @@ ol.Map.prototype.withFrozenRendering = function(f, opt_obj) {
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{controls: Array.<ol.control.Control>,
|
||||
* @typedef {{controls: ol.Collection,
|
||||
* interactions: ol.Collection,
|
||||
* rendererConstructor:
|
||||
* function(new: ol.renderer.Map, Element, ol.Map),
|
||||
@@ -1074,8 +1086,17 @@ ol.Map.createOptionsInternal = function(options) {
|
||||
}
|
||||
}
|
||||
|
||||
var controls = goog.isDef(options.controls) ?
|
||||
options.controls : ol.control.defaults();
|
||||
var controls;
|
||||
if (goog.isDef(options.controls)) {
|
||||
if (goog.isArray(options.controls)) {
|
||||
controls = new ol.Collection(goog.array.clone(options.controls));
|
||||
} else {
|
||||
goog.asserts.assertInstanceof(options.controls, ol.Collection);
|
||||
controls = options.controls;
|
||||
}
|
||||
} else {
|
||||
controls = ol.control.defaults();
|
||||
}
|
||||
|
||||
var interactions = goog.isDef(options.interactions) ?
|
||||
options.interactions : ol.interaction.defaults();
|
||||
|
||||
Reference in New Issue
Block a user