Merge pull request #3179 from fredj/disallow-undefined
Disallow undefined values for ol.layer.Base
This commit is contained in:
+32
-37
@@ -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
|
* @observable
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.layer.Base.prototype.getBrightness = function() {
|
ol.layer.Base.prototype.getBrightness = function() {
|
||||||
return /** @type {number|undefined} */ (
|
return /** @type {number} */ (this.get(ol.layer.LayerProperty.BRIGHTNESS));
|
||||||
this.get(ol.layer.LayerProperty.BRIGHTNESS));
|
|
||||||
};
|
};
|
||||||
goog.exportProperty(
|
goog.exportProperty(
|
||||||
ol.layer.Base.prototype,
|
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
|
* @observable
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.layer.Base.prototype.getContrast = function() {
|
ol.layer.Base.prototype.getContrast = function() {
|
||||||
return /** @type {number|undefined} */ (
|
return /** @type {number} */ (this.get(ol.layer.LayerProperty.CONTRAST));
|
||||||
this.get(ol.layer.LayerProperty.CONTRAST));
|
|
||||||
};
|
};
|
||||||
goog.exportProperty(
|
goog.exportProperty(
|
||||||
ol.layer.Base.prototype,
|
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
|
* @observable
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.layer.Base.prototype.getHue = function() {
|
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(
|
goog.exportProperty(
|
||||||
ol.layer.Base.prototype,
|
ol.layer.Base.prototype,
|
||||||
@@ -146,16 +144,16 @@ ol.layer.Base.prototype.getLayerState = function() {
|
|||||||
var minResolution = this.getMinResolution();
|
var minResolution = this.getMinResolution();
|
||||||
return {
|
return {
|
||||||
layer: /** @type {ol.layer.Layer} */ (this),
|
layer: /** @type {ol.layer.Layer} */ (this),
|
||||||
brightness: goog.isDef(brightness) ? goog.math.clamp(brightness, -1, 1) : 0,
|
brightness: goog.math.clamp(brightness, -1, 1),
|
||||||
contrast: goog.isDef(contrast) ? Math.max(contrast, 0) : 1,
|
contrast: Math.max(contrast, 0),
|
||||||
hue: goog.isDef(hue) ? hue : 0,
|
hue: hue,
|
||||||
opacity: goog.isDef(opacity) ? goog.math.clamp(opacity, 0, 1) : 1,
|
opacity: goog.math.clamp(opacity, 0, 1),
|
||||||
saturation: goog.isDef(saturation) ? Math.max(saturation, 0) : 1,
|
saturation: Math.max(saturation, 0),
|
||||||
sourceState: sourceState,
|
sourceState: sourceState,
|
||||||
visible: goog.isDef(visible) ? !!visible : true,
|
visible: visible,
|
||||||
extent: extent,
|
extent: extent,
|
||||||
maxResolution: goog.isDef(maxResolution) ? maxResolution : Infinity,
|
maxResolution: maxResolution,
|
||||||
minResolution: goog.isDef(minResolution) ? Math.max(minResolution, 0) : 0
|
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
|
* @observable
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
ol.layer.Base.prototype.getMaxResolution = function() {
|
ol.layer.Base.prototype.getMaxResolution = function() {
|
||||||
return /** @type {number|undefined} */ (
|
return /** @type {number} */ (
|
||||||
this.get(ol.layer.LayerProperty.MAX_RESOLUTION));
|
this.get(ol.layer.LayerProperty.MAX_RESOLUTION));
|
||||||
};
|
};
|
||||||
goog.exportProperty(
|
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
|
* @observable
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
ol.layer.Base.prototype.getMinResolution = function() {
|
ol.layer.Base.prototype.getMinResolution = function() {
|
||||||
return /** @type {number|undefined} */ (
|
return /** @type {number} */ (
|
||||||
this.get(ol.layer.LayerProperty.MIN_RESOLUTION));
|
this.get(ol.layer.LayerProperty.MIN_RESOLUTION));
|
||||||
};
|
};
|
||||||
goog.exportProperty(
|
goog.exportProperty(
|
||||||
@@ -222,13 +220,12 @@ goog.exportProperty(
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {number|undefined} The opacity of the layer.
|
* @return {number} The opacity of the layer.
|
||||||
* @observable
|
* @observable
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
ol.layer.Base.prototype.getOpacity = function() {
|
ol.layer.Base.prototype.getOpacity = function() {
|
||||||
return /** @type {number|undefined} */ (
|
return /** @type {number} */ (this.get(ol.layer.LayerProperty.OPACITY));
|
||||||
this.get(ol.layer.LayerProperty.OPACITY));
|
|
||||||
};
|
};
|
||||||
goog.exportProperty(
|
goog.exportProperty(
|
||||||
ol.layer.Base.prototype,
|
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
|
* @observable
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.layer.Base.prototype.getSaturation = function() {
|
ol.layer.Base.prototype.getSaturation = function() {
|
||||||
return /** @type {number|undefined} */ (
|
return /** @type {number} */ (this.get(ol.layer.LayerProperty.SATURATION));
|
||||||
this.get(ol.layer.LayerProperty.SATURATION));
|
|
||||||
};
|
};
|
||||||
goog.exportProperty(
|
goog.exportProperty(
|
||||||
ol.layer.Base.prototype,
|
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
|
* @observable
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
ol.layer.Base.prototype.getVisible = function() {
|
ol.layer.Base.prototype.getVisible = function() {
|
||||||
return /** @type {boolean|undefined} */ (
|
return /** @type {boolean} */ (this.get(ol.layer.LayerProperty.VISIBLE));
|
||||||
this.get(ol.layer.LayerProperty.VISIBLE));
|
|
||||||
};
|
};
|
||||||
goog.exportProperty(
|
goog.exportProperty(
|
||||||
ol.layer.Base.prototype,
|
ol.layer.Base.prototype,
|
||||||
@@ -290,7 +285,7 @@ goog.exportProperty(
|
|||||||
* [2] https://github.com/WebKit/webkit/commit/8f4765e569
|
* [2] https://github.com/WebKit/webkit/commit/8f4765e569
|
||||||
* [3] https://www.w3.org/Bugs/Public/show_bug.cgi?id=15647
|
* [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
|
* @observable
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -308,7 +303,7 @@ goog.exportProperty(
|
|||||||
* grey. A value of 1 will leave the contrast unchanged. Other values are
|
* grey. A value of 1 will leave the contrast unchanged. Other values are
|
||||||
* linear multipliers on the effect (and values over 1 are permitted).
|
* 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
|
* @observable
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -324,7 +319,7 @@ goog.exportProperty(
|
|||||||
/**
|
/**
|
||||||
* Apply a hue-rotation to the layer. A value of 0 will leave the hue
|
* Apply a hue-rotation to the layer. A value of 0 will leave the hue
|
||||||
* unchanged. Other values are radians around the color circle.
|
* 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
|
* @observable
|
||||||
* @api
|
* @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
|
* @observable
|
||||||
* @api stable
|
* @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
|
* @observable
|
||||||
* @api stable
|
* @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
|
* @observable
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
@@ -401,7 +396,7 @@ goog.exportProperty(
|
|||||||
* values are linear multipliers of the effect (and values over 1 are
|
* values are linear multipliers of the effect (and values over 1 are
|
||||||
* permitted).
|
* permitted).
|
||||||
*
|
*
|
||||||
* @param {number|undefined} saturation The saturation of the layer.
|
* @param {number} saturation The saturation of the layer.
|
||||||
* @observable
|
* @observable
|
||||||
* @api
|
* @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
|
* @observable
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -46,6 +46,14 @@ describe('ol.layer.Layer', function() {
|
|||||||
expect(layer.getVisible()).to.be(true);
|
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() {
|
it('provides default layerState', function() {
|
||||||
expect(layer.getLayerState()).to.eql({
|
expect(layer.getLayerState()).to.eql({
|
||||||
layer: layer,
|
layer: layer,
|
||||||
|
|||||||
Reference in New Issue
Block a user