From 2564bb3e585f1a08fcea2cf23ef3b79f7025f027 Mon Sep 17 00:00:00 2001 From: jonataswalker Date: Tue, 8 Mar 2016 11:12:23 -0300 Subject: [PATCH] Add alpha default value to ol.Color array form --- src/ol/color/color.js | 5 +++-- test/spec/ol/color.test.js | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ol/color/color.js b/src/ol/color/color.js index 35c362e731..183cf2339f 100644 --- a/src/ol/color/color.js +++ b/src/ol/color/color.js @@ -17,7 +17,8 @@ goog.require('ol.math'); /** * A color represented as a short array [red, green, blue, alpha]. * red, green, and blue should be integers in the range 0..255 inclusive. - * alpha should be a float in the range 0..1 inclusive. + * alpha should be a float in the range 0..1 inclusive. If no alpha value is + * given then `1` will be used. * @typedef {Array.} * @api */ @@ -293,7 +294,7 @@ ol.color.toString = function(color) { if (b != (b | 0)) { b = (b + 0.5) | 0; } - var a = color[3]; + var a = color[3] === undefined ? 1 : color[3]; return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')'; }; diff --git a/test/spec/ol/color.test.js b/test/spec/ol/color.test.js index 9f17e79981..66c1845f3c 100644 --- a/test/spec/ol/color.test.js +++ b/test/spec/ol/color.test.js @@ -129,6 +129,10 @@ describe('ol.color', function() { expect(ol.color.toString([1.2, 2.5, 3.7, 0.4])).to.be('rgba(1,3,4,0.4)'); }); + it('sets default alpha value if undefined', function() { + expect(ol.color.toString([0, 0, 0])).to.be('rgba(0,0,0,1)'); + }); + }); });