Add controls to map
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,7 @@ goog.require('ol.Constraints');
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.ResolutionConstraint');
|
||||
goog.require('ol.RotationConstraint');
|
||||
goog.require('ol.control.Zoom');
|
||||
goog.require('ol.interaction.AltDragRotate');
|
||||
goog.require('ol.interaction.DblClickZoom');
|
||||
goog.require('ol.interaction.DragPan');
|
||||
@@ -57,6 +58,7 @@ ol.DEFAULT_RENDERER_HINTS = [
|
||||
|
||||
/**
|
||||
* @typedef {{center: (ol.Coordinate|undefined),
|
||||
* controls: (ol.Collection|undefined),
|
||||
* doubleClickZoom: (boolean|undefined),
|
||||
* dragPan: (boolean|undefined),
|
||||
* interactions: (ol.Collection|undefined),
|
||||
@@ -83,7 +85,9 @@ ol.MapOptionsLiteral;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{rendererConstructor:
|
||||
* @typedef {{controls: ol.Collection,
|
||||
* constraints: ol.Constraints,
|
||||
* rendererConstructor:
|
||||
* function(new: ol.renderer.Map, Element, ol.Map),
|
||||
* values: Object.<string, *>}}
|
||||
*/
|
||||
@@ -164,9 +168,20 @@ ol.MapOptions.create = function(mapOptionsLiteral) {
|
||||
*/
|
||||
var constraints = ol.MapOptions.createConstraints_(mapOptionsLiteral);
|
||||
|
||||
/**
|
||||
* @type {ol.Collection}
|
||||
*/
|
||||
var controls;
|
||||
if (goog.isDef(mapOptionsLiteral.controls)) {
|
||||
controls = mapOptionsLiteral.controls;
|
||||
} else {
|
||||
controls = ol.MapOptions.createControls_(mapOptionsLiteral);
|
||||
}
|
||||
|
||||
return {
|
||||
rendererConstructor: rendererConstructor,
|
||||
constraints: constraints,
|
||||
controls: controls,
|
||||
rendererConstructor: rendererConstructor,
|
||||
values: values
|
||||
};
|
||||
|
||||
@@ -207,6 +222,26 @@ ol.MapOptions.createConstraints_ = function(mapOptionsLiteral) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {ol.MapOptionsLiteral} mapOptionsLiteral Map options literal.
|
||||
* @return {ol.Collection} Controls.
|
||||
*/
|
||||
ol.MapOptions.createControls_ = function(mapOptionsLiteral) {
|
||||
|
||||
var controls = new ol.Collection();
|
||||
|
||||
var zoomDelta = goog.isDef(mapOptionsLiteral.zoomDelta) ?
|
||||
mapOptionsLiteral.zoomDelta : 4;
|
||||
controls.push(new ol.control.Zoom({
|
||||
delta: zoomDelta
|
||||
}));
|
||||
|
||||
return controls;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {ol.MapOptionsLiteral} mapOptionsLiteral Map options literal.
|
||||
|
||||
Reference in New Issue
Block a user