Add controls to map
This commit is contained in:
@@ -12,6 +12,7 @@ ol.MapExport = function(container, mapOptionsExtern) {
|
|||||||
|
|
||||||
goog.base(this, container, {
|
goog.base(this, container, {
|
||||||
center: mapOptionsExtern.center,
|
center: mapOptionsExtern.center,
|
||||||
|
controls: mapOptionsExtern.controls,
|
||||||
doubleClickZoom: mapOptionsExtern.doubleClickZoom,
|
doubleClickZoom: mapOptionsExtern.doubleClickZoom,
|
||||||
dragPan: mapOptionsExtern.dragPan,
|
dragPan: mapOptionsExtern.dragPan,
|
||||||
interactions: mapOptionsExtern.interactions,
|
interactions: mapOptionsExtern.interactions,
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ olx.MapOptionsExtern = function() {};
|
|||||||
olx.MapOptionsExtern.prototype.center;
|
olx.MapOptionsExtern.prototype.center;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {ol.Collection|undefined}
|
||||||
|
*/
|
||||||
|
olx.MapOptionsExtern.prototype.controls;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {boolean|undefined}
|
* @type {boolean|undefined}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -176,6 +176,25 @@ ol.Map = function(container, mapOptionsLiteral) {
|
|||||||
this.handleBrowserEvent, false, this);
|
this.handleBrowserEvent, false, this);
|
||||||
this.registerDisposable(mouseWheelHandler);
|
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}
|
* @type {ol.renderer.Map}
|
||||||
* @private
|
* @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.
|
* @param {ol.Pixel} pixel Pixel.
|
||||||
* @return {ol.Coordinate} Coordinate.
|
* @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.
|
* @param {ol.MapBrowserEvent} mapBrowserEvent The event to handle.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+37
-2
@@ -11,6 +11,7 @@ goog.require('ol.Constraints');
|
|||||||
goog.require('ol.Projection');
|
goog.require('ol.Projection');
|
||||||
goog.require('ol.ResolutionConstraint');
|
goog.require('ol.ResolutionConstraint');
|
||||||
goog.require('ol.RotationConstraint');
|
goog.require('ol.RotationConstraint');
|
||||||
|
goog.require('ol.control.Zoom');
|
||||||
goog.require('ol.interaction.AltDragRotate');
|
goog.require('ol.interaction.AltDragRotate');
|
||||||
goog.require('ol.interaction.DblClickZoom');
|
goog.require('ol.interaction.DblClickZoom');
|
||||||
goog.require('ol.interaction.DragPan');
|
goog.require('ol.interaction.DragPan');
|
||||||
@@ -57,6 +58,7 @@ ol.DEFAULT_RENDERER_HINTS = [
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{center: (ol.Coordinate|undefined),
|
* @typedef {{center: (ol.Coordinate|undefined),
|
||||||
|
* controls: (ol.Collection|undefined),
|
||||||
* doubleClickZoom: (boolean|undefined),
|
* doubleClickZoom: (boolean|undefined),
|
||||||
* dragPan: (boolean|undefined),
|
* dragPan: (boolean|undefined),
|
||||||
* interactions: (ol.Collection|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),
|
* function(new: ol.renderer.Map, Element, ol.Map),
|
||||||
* values: Object.<string, *>}}
|
* values: Object.<string, *>}}
|
||||||
*/
|
*/
|
||||||
@@ -164,9 +168,20 @@ ol.MapOptions.create = function(mapOptionsLiteral) {
|
|||||||
*/
|
*/
|
||||||
var constraints = ol.MapOptions.createConstraints_(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 {
|
return {
|
||||||
rendererConstructor: rendererConstructor,
|
|
||||||
constraints: constraints,
|
constraints: constraints,
|
||||||
|
controls: controls,
|
||||||
|
rendererConstructor: rendererConstructor,
|
||||||
values: values
|
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
|
* @private
|
||||||
* @param {ol.MapOptionsLiteral} mapOptionsLiteral Map options literal.
|
* @param {ol.MapOptionsLiteral} mapOptionsLiteral Map options literal.
|
||||||
|
|||||||
Reference in New Issue
Block a user