Merge pull request #3179 from fredj/disallow-undefined

Disallow undefined values for ol.layer.Base
This commit is contained in:
Frédéric Junod
2015-02-02 09:10:36 +01:00
2 changed files with 40 additions and 37 deletions

View File

@@ -87,13 +87,12 @@ goog.inherits(ol.layer.Base, ol.Object);
/**
* @return {number|undefined} The brightness of the layer.
* @return {number} The brightness of the layer.
* @observable
* @api
*/
ol.layer.Base.prototype.getBrightness = function() {
return /** @type {number|undefined} */ (
this.get(ol.layer.LayerProperty.BRIGHTNESS));
return /** @type {number} */ (this.get(ol.layer.LayerProperty.BRIGHTNESS));
};
goog.exportProperty(
ol.layer.Base.prototype,
@@ -102,13 +101,12 @@ goog.exportProperty(
/**
* @return {number|undefined} The contrast of the layer.
* @return {number} The contrast of the layer.
* @observable
* @api
*/
ol.layer.Base.prototype.getContrast = function() {
return /** @type {number|undefined} */ (
this.get(ol.layer.LayerProperty.CONTRAST));
return /** @type {number} */ (this.get(ol.layer.LayerProperty.CONTRAST));
};
goog.exportProperty(
ol.layer.Base.prototype,
@@ -117,12 +115,12 @@ goog.exportProperty(
/**
* @return {number|undefined} The hue of the layer.
* @return {number} The hue of the layer.
* @observable
* @api
*/
ol.layer.Base.prototype.getHue = function() {
return /** @type {number|undefined} */ (this.get(ol.layer.LayerProperty.HUE));
return /** @type {number} */ (this.get(ol.layer.LayerProperty.HUE));
};
goog.exportProperty(
ol.layer.Base.prototype,
@@ -146,16 +144,16 @@ ol.layer.Base.prototype.getLayerState = function() {
var minResolution = this.getMinResolution();
return {
layer: /** @type {ol.layer.Layer} */ (this),
brightness: goog.isDef(brightness) ? goog.math.clamp(brightness, -1, 1) : 0,
contrast: goog.isDef(contrast) ? Math.max(contrast, 0) : 1,
hue: goog.isDef(hue) ? hue : 0,
opacity: goog.isDef(opacity) ? goog.math.clamp(opacity, 0, 1) : 1,
saturation: goog.isDef(saturation) ? Math.max(saturation, 0) : 1,
brightness: goog.math.clamp(brightness, -1, 1),
contrast: Math.max(contrast, 0),
hue: hue,
opacity: goog.math.clamp(opacity, 0, 1),
saturation: Math.max(saturation, 0),
sourceState: sourceState,
visible: goog.isDef(visible) ? !!visible : true,
visible: visible,
extent: extent,
maxResolution: goog.isDef(maxResolution) ? maxResolution : Infinity,
minResolution: goog.isDef(minResolution) ? Math.max(minResolution, 0) : 0
maxResolution: maxResolution,
minResolution: Math.max(minResolution, 0)
};
};
@@ -192,12 +190,12 @@ goog.exportProperty(
/**
* @return {number|undefined} The maximum resolution of the layer.
* @return {number} The maximum resolution of the layer.
* @observable
* @api stable
*/
ol.layer.Base.prototype.getMaxResolution = function() {
return /** @type {number|undefined} */ (
return /** @type {number} */ (
this.get(ol.layer.LayerProperty.MAX_RESOLUTION));
};
goog.exportProperty(
@@ -207,12 +205,12 @@ goog.exportProperty(
/**
* @return {number|undefined} The minimum resolution of the layer.
* @return {number} The minimum resolution of the layer.
* @observable
* @api stable
*/
ol.layer.Base.prototype.getMinResolution = function() {
return /** @type {number|undefined} */ (
return /** @type {number} */ (
this.get(ol.layer.LayerProperty.MIN_RESOLUTION));
};
goog.exportProperty(
@@ -222,13 +220,12 @@ goog.exportProperty(
/**
* @return {number|undefined} The opacity of the layer.
* @return {number} The opacity of the layer.
* @observable
* @api stable
*/
ol.layer.Base.prototype.getOpacity = function() {
return /** @type {number|undefined} */ (
this.get(ol.layer.LayerProperty.OPACITY));
return /** @type {number} */ (this.get(ol.layer.LayerProperty.OPACITY));
};
goog.exportProperty(
ol.layer.Base.prototype,
@@ -237,13 +234,12 @@ goog.exportProperty(
/**
* @return {number|undefined} The saturation of the layer.
* @return {number} The saturation of the layer.
* @observable
* @api
*/
ol.layer.Base.prototype.getSaturation = function() {
return /** @type {number|undefined} */ (
this.get(ol.layer.LayerProperty.SATURATION));
return /** @type {number} */ (this.get(ol.layer.LayerProperty.SATURATION));
};
goog.exportProperty(
ol.layer.Base.prototype,
@@ -258,13 +254,12 @@ ol.layer.Base.prototype.getSourceState = goog.abstractMethod;
/**
* @return {boolean|undefined} The visiblity of the layer.
* @return {boolean} The visibility of the layer.
* @observable
* @api stable
*/
ol.layer.Base.prototype.getVisible = function() {
return /** @type {boolean|undefined} */ (
this.get(ol.layer.LayerProperty.VISIBLE));
return /** @type {boolean} */ (this.get(ol.layer.LayerProperty.VISIBLE));
};
goog.exportProperty(
ol.layer.Base.prototype,
@@ -290,7 +285,7 @@ goog.exportProperty(
* [2] https://github.com/WebKit/webkit/commit/8f4765e569
* [3] https://www.w3.org/Bugs/Public/show_bug.cgi?id=15647
*
* @param {number|undefined} brightness The brightness of the layer.
* @param {number} brightness The brightness of the layer.
* @observable
* @api
*/
@@ -308,7 +303,7 @@ goog.exportProperty(
* grey. A value of 1 will leave the contrast unchanged. Other values are
* linear multipliers on the effect (and values over 1 are permitted).
*
* @param {number|undefined} contrast The contrast of the layer.
* @param {number} contrast The contrast of the layer.
* @observable
* @api
*/
@@ -324,7 +319,7 @@ goog.exportProperty(
/**
* Apply a hue-rotation to the layer. A value of 0 will leave the hue
* unchanged. Other values are radians around the color circle.
* @param {number|undefined} hue The hue of the layer.
* @param {number} hue The hue of the layer.
* @observable
* @api
*/
@@ -354,7 +349,7 @@ goog.exportProperty(
/**
* @param {number|undefined} maxResolution The maximum resolution of the layer.
* @param {number} maxResolution The maximum resolution of the layer.
* @observable
* @api stable
*/
@@ -368,7 +363,7 @@ goog.exportProperty(
/**
* @param {number|undefined} minResolution The minimum resolution of the layer.
* @param {number} minResolution The minimum resolution of the layer.
* @observable
* @api stable
*/
@@ -382,7 +377,7 @@ goog.exportProperty(
/**
* @param {number|undefined} opacity The opacity of the layer.
* @param {number} opacity The opacity of the layer.
* @observable
* @api stable
*/
@@ -401,7 +396,7 @@ goog.exportProperty(
* values are linear multipliers of the effect (and values over 1 are
* permitted).
*
* @param {number|undefined} saturation The saturation of the layer.
* @param {number} saturation The saturation of the layer.
* @observable
* @api
*/
@@ -415,7 +410,7 @@ goog.exportProperty(
/**
* @param {boolean|undefined} visible The visiblity of the layer.
* @param {boolean} visible The visibility of the layer.
* @observable
* @api stable
*/

View File

@@ -46,6 +46,14 @@ describe('ol.layer.Layer', function() {
expect(layer.getVisible()).to.be(true);
});
it('provides default max resolution', function() {
expect(layer.getMaxResolution()).to.be(Infinity);
});
it('provides default min resolution', function() {
expect(layer.getMinResolution()).to.be(0);
});
it('provides default layerState', function() {
expect(layer.getLayerState()).to.eql({
layer: layer,