Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add ol.control.defaults

  • Loading branch information...
commit 8ae009d401603fc1215df3019251974a4a29d328 1 parent 1ae2064
@twpayne authored
View
14 src/objectliterals.exports
@@ -1,5 +1,5 @@
@exportObjectLiteral ol.MapOptions
-@exportObjectLiteralProperty ol.MapOptions.attributionControl boolean|undefined
+@exportObjectLiteralProperty ol.MapOptions.controls Array.<ol.control.Control>|undefined
@exportObjectLiteralProperty ol.MapOptions.doubleClickZoom boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.dragPan boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.interactions ol.Collection|undefined
@@ -9,16 +9,12 @@
@exportObjectLiteralProperty ol.MapOptions.mouseWheelZoom boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.renderer ol.RendererHint|undefined
@exportObjectLiteralProperty ol.MapOptions.renderers Array.<ol.RendererHint>|undefined
-@exportObjectLiteralProperty ol.MapOptions.scaleLineControl boolean|undefined
-@exportObjectLiteralProperty ol.MapOptions.scaleLineUnits ol.control.ScaleLineUnits|undefined
@exportObjectLiteralProperty ol.MapOptions.shiftDragZoom boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.target Element|string
@exportObjectLiteralProperty ol.MapOptions.touchPan boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.touchRotate boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.touchZoom boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.view ol.IView|undefined
-@exportObjectLiteralProperty ol.MapOptions.zoomControl boolean|undefined
-@exportObjectLiteralProperty ol.MapOptions.zoomDelta number|undefined
@exportObjectLiteral ol.View2DOptions
@exportObjectLiteralProperty ol.View2DOptions.center ol.Coordinate|undefined
@@ -59,6 +55,14 @@
@exportObjectLiteralProperty ol.control.AttributionOptions.map ol.Map|undefined
@exportObjectLiteralProperty ol.control.AttributionOptions.target Element|undefined
+@exportObjectLiteral ol.control.DefaultsOptions
+@exportObjectLiteralProperty ol.control.DefaultsOptions.attribution boolean|undefined
+@exportObjectLiteralProperty ol.control.DefaultsOptions.attributionOptions ol.control.AttributionOptions|undefined
+@exportObjectLiteralProperty ol.control.DefaultsOptions.scaleLine boolean|undefined
+@exportObjectLiteralProperty ol.control.DefaultsOptions.scaleLineOptions ol.control.ScaleLineOptions|undefined
+@exportObjectLiteralProperty ol.control.DefaultsOptions.zoom boolean|undefined
+@exportObjectLiteralProperty ol.control.DefaultsOptions.zoomOptions ol.control.ZoomOptions|undefined
+
@exportObjectLiteral ol.control.ScaleLineOptions
@exportObjectLiteralProperty ol.control.ScaleLineOptions.map ol.Map|undefined
@exportObjectLiteralProperty ol.control.ScaleLineOptions.minWidth number|undefined
View
1  src/ol/control/defaults.exports
@@ -0,0 +1 @@
+@exportSymbol ol.control.defaults ol.control.defaults
View
51 src/ol/control/defaults.js
@@ -0,0 +1,51 @@
+goog.provide('ol.control.defaults');
+
+goog.require('ol.control.Attribution');
+goog.require('ol.control.ScaleLine');
+goog.require('ol.control.Zoom');
+
+
+/**
+ * @param {ol.control.DefaultsOptions=} opt_options Options.
+ * @param {...ol.control.Control} var_args Further controls.
+ * @return {Array.<ol.control.Control>} Controls.
+ */
+ol.control.defaults = function(opt_options, var_args) {
+
+ var options = goog.isDef(opt_options) ? opt_options : {};
+
+ /** @type {Array.<ol.control.Control>} */
+ var controls = [];
+
+ var attributionControl = goog.isDef(options.attribution) ?
+ options.attribution : true;
+ if (attributionControl) {
+ var attributionControlOptions = goog.isDef(options.attributionOptions) ?
+ options.attributionOptions : undefined;
+ controls.push(new ol.control.Attribution(attributionControlOptions));
+ }
+
+ var scaleLineControl = goog.isDef(options.scaleLine) ?
+ options.scaleLine : false;
+ if (scaleLineControl) {
+ var scaleLineOptions = goog.isDef(options.scaleLineOptions) ?
+ options.scaleLineOptions : undefined;
+ controls.push(new ol.control.ScaleLine(scaleLineOptions));
+ }
+
+ var zoomControl = goog.isDef(options.zoom) ?
+ options.zoom : true;
+ if (zoomControl) {
+ var zoomControlOptions = goog.isDef(options.zoomControlOptions) ?
+ options.zoomControlOptions : undefined;
+ controls.push(new ol.control.Zoom(zoomControlOptions));
+ }
+
+ var i;
+ for (i = 1; i < arguments.length; ++i) {
+ controls.push(arguments[i]);
+ }
+
+ return controls;
+
+};
View
68 src/ol/map.js
@@ -43,10 +43,7 @@ goog.require('ol.Tile');
goog.require('ol.TileQueue');
goog.require('ol.View');
goog.require('ol.View2D');
-goog.require('ol.control.Attribution');
-goog.require('ol.control.Control');
-goog.require('ol.control.ScaleLine');
-goog.require('ol.control.Zoom');
+goog.require('ol.control.defaults');
goog.require('ol.interaction.DblClickZoom');
goog.require('ol.interaction.DragPan');
goog.require('ol.interaction.DragRotate');
@@ -292,15 +289,15 @@ ol.Map = function(mapOptions) {
// this gives the map an initial size
this.handleBrowserWindowResize();
- /** @type {Array.<ol.control.Control>} */
- var controls = mapOptionsInternal.controls;
- goog.array.forEach(controls,
- /**
- * @param {ol.control.Control} control Control.
- */
- function(control) {
- control.setMap(this);
- }, this);
+ if (goog.isDef(mapOptionsInternal.controls)) {
+ goog.array.forEach(mapOptionsInternal.controls,
+ /**
+ * @param {ol.control.Control} control Control.
+ */
+ function(control) {
+ control.setMap(this);
+ }, this);
+ }
};
goog.inherits(ol.Map, ol.Object);
@@ -881,10 +878,8 @@ ol.Map.createOptionsInternal = function(mapOptions) {
}
}
- /**
- * @type {Array.<ol.control.Control>}
- */
- var controls = ol.Map.createControls_(mapOptions);
+ var controls = goog.isDef(mapOptions.controls) ?
+ mapOptions.controls : ol.control.defaults();
/**
* @type {ol.Collection}
@@ -915,45 +910,6 @@ ol.Map.createOptionsInternal = function(mapOptions) {
/**
* @private
* @param {ol.MapOptions} mapOptions Map options.
- * @return {Array.<ol.control.Control>} Controls.
- */
-ol.Map.createControls_ = function(mapOptions) {
- /** @type {Array.<ol.control.Control>} */
- var controls = [];
-
- var attributionControl = goog.isDef(mapOptions.attributionControl) ?
- mapOptions.attributionControl : true;
- if (attributionControl) {
- controls.push(new ol.control.Attribution({}));
- }
-
- var scaleLineControl = goog.isDef(mapOptions.scaleLineControl) ?
- mapOptions.scaleLineControl : false;
- if (scaleLineControl) {
- var scaleLineUnits = goog.isDef(mapOptions.scaleLineUnits) ?
- mapOptions.scaleLineUnits : undefined;
- controls.push(new ol.control.ScaleLine({
- units: scaleLineUnits
- }));
- }
-
- var zoomControl = goog.isDef(mapOptions.zoomControl) ?
- mapOptions.zoomControl : true;
- if (zoomControl) {
- var zoomDelta = goog.isDef(mapOptions.zoomDelta) ?
- mapOptions.zoomDelta : 1;
- controls.push(new ol.control.Zoom({
- delta: zoomDelta
- }));
- }
-
- return controls;
-};
-
-
-/**
- * @private
- * @param {ol.MapOptions} mapOptions Map options.
* @return {ol.Collection} Interactions.
*/
ol.Map.createInteractions_ = function(mapOptions) {
Please sign in to comment.
Something went wrong with that request. Please try again.