From 711261171bc954edf0961a5bd4f86587715eb641 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 12 Jul 2013 09:41:47 -0600 Subject: [PATCH 1/7] Getters and setters for line symbolizers --- src/ol/style/line.js | 57 ++++++++++++++ test/spec/ol/style/line.test.js | 127 ++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+) diff --git a/src/ol/style/line.js b/src/ol/style/line.js index 5fc17a2e7a..2c2a963ccb 100644 --- a/src/ol/style/line.js +++ b/src/ol/style/line.js @@ -119,6 +119,63 @@ ol.style.Line.prototype.createLiteral = function(opt_feature) { }; +/** + * Get the stroke color. + * @return {ol.expr.Expression} Stroke color. + */ +ol.style.Line.prototype.getStrokeColor = function() { + return this.strokeColor_; +}; + + +/** + * Get the stroke width. + * @return {ol.expr.Expression} Stroke width. + */ +ol.style.Line.prototype.getStrokeWidth = function() { + return this.strokeWidth_; +}; + + +/** + * Get the stroke opacity. + * @return {ol.expr.Expression} Stroke opacity. + */ +ol.style.Line.prototype.getOpacity = function() { + return this.opacity_; +}; + + +/** + * Set the stroke color. + * @param {ol.expr.Expression} strokeColor Stroke color. + */ +ol.style.Line.prototype.setStrokeColor = function(strokeColor) { + goog.asserts.assertInstanceof(strokeColor, ol.expr.Expression); + this.strokeColor_ = strokeColor; +}; + + +/** + * Set the stroke width. + * @param {ol.expr.Expression} strokeWidth Stroke width. + */ +ol.style.Line.prototype.setStrokeWidth = function(strokeWidth) { + goog.asserts.assertInstanceof(strokeWidth, ol.expr.Expression); + this.strokeWidth_ = strokeWidth; +}; + + +/** + * Set the stroke opacity. + * @param {ol.expr.Expression} opacity Stroke opacity. + */ +ol.style.Line.prototype.setOpacity = function(opacity) { + goog.asserts.assertInstanceof(opacity, ol.expr.Expression); + this.opacity_ = opacity; +}; + + /** * @type {ol.style.LineLiteral} */ diff --git a/test/spec/ol/style/line.test.js b/test/spec/ol/style/line.test.js index 6022486638..dae4962301 100644 --- a/test/spec/ol/style/line.test.js +++ b/test/spec/ol/style/line.test.js @@ -71,9 +71,136 @@ describe('ol.style.Line', function() { }); + describe('#getStrokeColor()', function() { + + it('returns the stroke color', function() { + var symbolizer = new ol.style.Line({ + strokeColor: '#ff0000' + }); + + var strokeColor = symbolizer.getStrokeColor(); + expect(strokeColor).to.be.a(ol.expr.Literal); + expect(strokeColor.getValue()).to.be('#ff0000'); + }); + + }); + + describe('#getStrokeWidth()', function() { + + it('returns the stroke width', function() { + var symbolizer = new ol.style.Line({ + strokeWidth: 10 + }); + + var strokeWidth = symbolizer.getStrokeWidth(); + expect(strokeWidth).to.be.a(ol.expr.Literal); + expect(strokeWidth.getValue()).to.be(10); + }); + + }); + + describe('#getOpacity()', function() { + + it('returns the stroke opacity', function() { + var symbolizer = new ol.style.Line({ + opacity: 0.123 + }); + + var opacity = symbolizer.getOpacity(); + expect(opacity).to.be.a(ol.expr.Literal); + expect(opacity.getValue()).to.be(0.123); + }); + + }); + + describe('#setStrokeColor()', function() { + + it('sets the stroke color', function() { + var symbolizer = new ol.style.Line({ + strokeColor: '#ff0000' + }); + + symbolizer.setStrokeColor(new ol.expr.Literal('#0000ff')); + + var strokeColor = symbolizer.getStrokeColor(); + expect(strokeColor).to.be.a(ol.expr.Literal); + expect(strokeColor.getValue()).to.be('#0000ff'); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Line({ + strokeColor: '#ff0000' + }); + + expect(function() { + symbolizer.setStrokeColor('#0000ff'); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setStrokeWidth()', function() { + + it('sets the stroke width', function() { + var symbolizer = new ol.style.Line({ + strokeWidth: 10 + }); + symbolizer.setStrokeWidth(new ol.expr.Literal(20)); + + var strokeWidth = symbolizer.getStrokeWidth(); + expect(strokeWidth).to.be.a(ol.expr.Literal); + expect(strokeWidth.getValue()).to.be(20); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Line({ + strokeWidth: 10 + }); + + expect(function() { + symbolizer.setStrokeWidth(10); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setOpacity()', function() { + + it('sets the stroke opacity', function() { + var symbolizer = new ol.style.Line({ + opacity: 0.123 + }); + symbolizer.setOpacity(new ol.expr.Literal(0.321)); + + var opacity = symbolizer.getOpacity(); + expect(opacity).to.be.a(ol.expr.Literal); + expect(opacity.getValue()).to.be(0.321); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Line({ + opacity: 1 + }); + + expect(function() { + symbolizer.setOpacity(0.5); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + }); +goog.require('goog.asserts.AssertionError'); + goog.require('ol.Feature'); goog.require('ol.expr'); +goog.require('ol.expr.Literal'); goog.require('ol.style.Line'); goog.require('ol.style.LineLiteral'); From a0d058b2fa0e99d5411840a146b7205f2978e39f Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 12 Jul 2013 09:50:42 -0600 Subject: [PATCH 2/7] Getters and setters for polygon symbolizer --- src/ol/style/polygon.js | 76 +++++++++++++ test/spec/ol/style/polygon.test.js | 173 +++++++++++++++++++++++++++++ 2 files changed, 249 insertions(+) diff --git a/src/ol/style/polygon.js b/src/ol/style/polygon.js index 57fa4afb6b..bcb5ac724f 100644 --- a/src/ol/style/polygon.js +++ b/src/ol/style/polygon.js @@ -186,6 +186,82 @@ ol.style.Polygon.prototype.createLiteral = function(opt_feature) { }; +/** + * Get the fill color. + * @return {ol.expr.Expression} Fill color. + */ +ol.style.Polygon.prototype.getFillColor = function() { + return this.fillColor_; +}; + + +/** + * Get the opacity. + * @return {ol.expr.Expression} Opacity. + */ +ol.style.Polygon.prototype.getOpacity = function() { + return this.opacity_; +}; + + +/** + * Get the stroke color. + * @return {ol.expr.Expression} Stroke color. + */ +ol.style.Polygon.prototype.getStrokeColor = function() { + return this.strokeColor_; +}; + + +/** + * Get the stroke width. + * @return {ol.expr.Expression} Stroke width. + */ +ol.style.Polygon.prototype.getStrokeWidth = function() { + return this.strokeWidth_; +}; + + +/** + * Set the fill color. + * @param {ol.expr.Expression} fillColor Fill color. + */ +ol.style.Polygon.prototype.setFillColor = function(fillColor) { + goog.asserts.assertInstanceof(fillColor, ol.expr.Expression); + this.fillColor_ = fillColor; +}; + + +/** + * Set the opacity. + * @param {ol.expr.Expression} opacity Opacity. + */ +ol.style.Polygon.prototype.setOpacity = function(opacity) { + goog.asserts.assertInstanceof(opacity, ol.expr.Expression); + this.opacity_ = opacity; +}; + + +/** + * Set the stroke color. + * @param {ol.expr.Expression} strokeColor Stroke color. + */ +ol.style.Polygon.prototype.setStrokeColor = function(strokeColor) { + goog.asserts.assertInstanceof(strokeColor, ol.expr.Expression); + this.strokeColor_ = strokeColor; +}; + + +/** + * Set the stroke width. + * @param {ol.expr.Expression} strokeWidth Stroke width. + */ +ol.style.Polygon.prototype.setStrokeWidth = function(strokeWidth) { + goog.asserts.assertInstanceof(strokeWidth, ol.expr.Expression); + this.strokeWidth_ = strokeWidth; +}; + + /** * @type {ol.style.PolygonLiteral} */ diff --git a/test/spec/ol/style/polygon.test.js b/test/spec/ol/style/polygon.test.js index 6ce43ae867..d5136b7690 100644 --- a/test/spec/ol/style/polygon.test.js +++ b/test/spec/ol/style/polygon.test.js @@ -87,9 +87,182 @@ describe('ol.style.Polygon', function() { }); + describe('#getFillColor()', function() { + + it('returns the fill color', function() { + var symbolizer = new ol.style.Polygon({ + fillColor: '#ff0000' + }); + + var fillColor = symbolizer.getFillColor(); + expect(fillColor).to.be.a(ol.expr.Literal); + expect(fillColor.getValue()).to.be('#ff0000'); + }); + + }); + + + describe('#getStrokeColor()', function() { + + it('returns the stroke color', function() { + var symbolizer = new ol.style.Polygon({ + strokeColor: '#ff0000' + }); + + var strokeColor = symbolizer.getStrokeColor(); + expect(strokeColor).to.be.a(ol.expr.Literal); + expect(strokeColor.getValue()).to.be('#ff0000'); + }); + + }); + + describe('#getStrokeWidth()', function() { + + it('returns the stroke width', function() { + var symbolizer = new ol.style.Polygon({ + strokeWidth: 10 + }); + + var strokeWidth = symbolizer.getStrokeWidth(); + expect(strokeWidth).to.be.a(ol.expr.Literal); + expect(strokeWidth.getValue()).to.be(10); + }); + + }); + + describe('#getOpacity()', function() { + + it('returns the stroke opacity', function() { + var symbolizer = new ol.style.Polygon({ + strokeWidth: 1, + opacity: 0.123 + }); + + var opacity = symbolizer.getOpacity(); + expect(opacity).to.be.a(ol.expr.Literal); + expect(opacity.getValue()).to.be(0.123); + }); + + }); + + describe('#setFillColor()', function() { + + it('sets the fill color', function() { + var symbolizer = new ol.style.Polygon({ + fillColor: '#ff0000' + }); + + symbolizer.setFillColor(new ol.expr.Literal('#0000ff')); + + var fillColor = symbolizer.getFillColor(); + expect(fillColor).to.be.a(ol.expr.Literal); + expect(fillColor.getValue()).to.be('#0000ff'); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Polygon({ + fillColor: '#ff0000' + }); + + expect(function() { + symbolizer.setFillColor('#0000ff'); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setStrokeColor()', function() { + + it('sets the stroke color', function() { + var symbolizer = new ol.style.Polygon({ + strokeColor: '#ff0000' + }); + + symbolizer.setStrokeColor(new ol.expr.Literal('#0000ff')); + + var strokeColor = symbolizer.getStrokeColor(); + expect(strokeColor).to.be.a(ol.expr.Literal); + expect(strokeColor.getValue()).to.be('#0000ff'); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Polygon({ + strokeColor: '#ff0000' + }); + + expect(function() { + symbolizer.setStrokeColor('#0000ff'); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setStrokeWidth()', function() { + + it('sets the stroke width', function() { + var symbolizer = new ol.style.Polygon({ + strokeWidth: 10 + }); + symbolizer.setStrokeWidth(new ol.expr.Literal(20)); + + var strokeWidth = symbolizer.getStrokeWidth(); + expect(strokeWidth).to.be.a(ol.expr.Literal); + expect(strokeWidth.getValue()).to.be(20); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Polygon({ + strokeWidth: 10 + }); + + expect(function() { + symbolizer.setStrokeWidth(10); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setOpacity()', function() { + + it('sets the stroke opacity', function() { + var symbolizer = new ol.style.Polygon({ + strokeWidth: 1, + opacity: 0.123 + }); + symbolizer.setOpacity(new ol.expr.Literal(0.321)); + + var opacity = symbolizer.getOpacity(); + expect(opacity).to.be.a(ol.expr.Literal); + expect(opacity.getValue()).to.be(0.321); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Polygon({ + strokeWidth: 1, + opacity: 1 + }); + + expect(function() { + symbolizer.setOpacity(0.5); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + }); +goog.require('goog.asserts.AssertionError'); + goog.require('ol.Feature'); goog.require('ol.expr'); +goog.require('ol.expr.Literal'); goog.require('ol.style.Polygon'); goog.require('ol.style.PolygonLiteral'); From 2e08ccce036c203f3fd06a55f0023acd67df382b Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 12 Jul 2013 09:57:40 -0600 Subject: [PATCH 3/7] Getters and setters for shape symbolizers --- src/ol/style/shape.js | 113 +++++++++++++++++ test/spec/ol/style/shape.test.js | 200 +++++++++++++++++++++++++++++++ 2 files changed, 313 insertions(+) diff --git a/src/ol/style/shape.js b/src/ol/style/shape.js index 751cf66ab2..4df16825d6 100644 --- a/src/ol/style/shape.js +++ b/src/ol/style/shape.js @@ -226,6 +226,119 @@ ol.style.Shape.prototype.createLiteral = function(opt_feature) { }; +/** + * Get the fill color. + * @return {ol.expr.Expression} Fill color. + */ +ol.style.Shape.prototype.getFillColor = function() { + return this.fillColor_; +}; + + +/** + * Get the opacity. + * @return {ol.expr.Expression} Opacity. + */ +ol.style.Shape.prototype.getOpacity = function() { + return this.opacity_; +}; + + +/** + * Get the shape size. + * @return {ol.expr.Expression} Shape size. + */ +ol.style.Shape.prototype.getSize = function() { + return this.size_; +}; + + +/** + * Get the stroke color. + * @return {ol.expr.Expression} Stroke color. + */ +ol.style.Shape.prototype.getStrokeColor = function() { + return this.strokeColor_; +}; + + +/** + * Get the stroke width. + * @return {ol.expr.Expression} Stroke width. + */ +ol.style.Shape.prototype.getStrokeWidth = function() { + return this.strokeWidth_; +}; + + +/** + * Get the shape type. + * @return {ol.style.ShapeType} Shape type. + */ +ol.style.Shape.prototype.getType = function() { + return this.type_; +}; + + +/** + * Set the fill color. + * @param {ol.expr.Expression} fillColor Fill color. + */ +ol.style.Shape.prototype.setFillColor = function(fillColor) { + goog.asserts.assertInstanceof(fillColor, ol.expr.Expression); + this.fillColor_ = fillColor; +}; + + +/** + * Set the opacity. + * @param {ol.expr.Expression} opacity Opacity. + */ +ol.style.Shape.prototype.setOpacity = function(opacity) { + goog.asserts.assertInstanceof(opacity, ol.expr.Expression); + this.opacity_ = opacity; +}; + + +/** + * Set the shape size. + * @param {ol.expr.Expression} size Shape size. + */ +ol.style.Shape.prototype.setSize = function(size) { + goog.asserts.assertInstanceof(size, ol.expr.Expression); + this.size_ = size; +}; + + +/** + * Set the stroke color. + * @param {ol.expr.Expression} strokeColor Stroke color. + */ +ol.style.Shape.prototype.setStrokeColor = function(strokeColor) { + goog.asserts.assertInstanceof(strokeColor, ol.expr.Expression); + this.strokeColor_ = strokeColor; +}; + + +/** + * Set the stroke width. + * @param {ol.expr.Expression} strokeWidth Stroke width. + */ +ol.style.Shape.prototype.setStrokeWidth = function(strokeWidth) { + goog.asserts.assertInstanceof(strokeWidth, ol.expr.Expression); + this.strokeWidth_ = strokeWidth; +}; + + +/** + * Set the shape type. + * @param {ol.style.ShapeType} type Shape type. + */ +ol.style.Shape.prototype.setType = function(type) { + this.type_ = type; +}; + + /** * @type {ol.style.ShapeLiteral} */ diff --git a/test/spec/ol/style/shape.test.js b/test/spec/ol/style/shape.test.js index 1e629eef1b..be1fd83e8a 100644 --- a/test/spec/ol/style/shape.test.js +++ b/test/spec/ol/style/shape.test.js @@ -117,10 +117,210 @@ describe('ol.style.Shape', function() { }); + describe('#getFillColor()', function() { + + it('returns the fill color', function() { + var symbolizer = new ol.style.Shape({ + fillColor: '#ff0000' + }); + + var fillColor = symbolizer.getFillColor(); + expect(fillColor).to.be.a(ol.expr.Literal); + expect(fillColor.getValue()).to.be('#ff0000'); + }); + + }); + + describe('#getStrokeColor()', function() { + + it('returns the stroke color', function() { + var symbolizer = new ol.style.Shape({ + strokeColor: '#ff0000' + }); + + var strokeColor = symbolizer.getStrokeColor(); + expect(strokeColor).to.be.a(ol.expr.Literal); + expect(strokeColor.getValue()).to.be('#ff0000'); + }); + + }); + + describe('#getStrokeWidth()', function() { + + it('returns the stroke width', function() { + var symbolizer = new ol.style.Shape({ + strokeWidth: 10 + }); + + var strokeWidth = symbolizer.getStrokeWidth(); + expect(strokeWidth).to.be.a(ol.expr.Literal); + expect(strokeWidth.getValue()).to.be(10); + }); + + }); + + describe('#getOpacity()', function() { + + it('returns the stroke opacity', function() { + var symbolizer = new ol.style.Shape({ + strokeWidth: 1, + opacity: 0.123 + }); + + var opacity = symbolizer.getOpacity(); + expect(opacity).to.be.a(ol.expr.Literal); + expect(opacity.getValue()).to.be(0.123); + }); + + }); + + describe('#getType()', function() { + + it('returns the shape type', function() { + var symbolizer = new ol.style.Shape({ + strokeWidth: 1, + opacity: 0.123 + }); + + var type = symbolizer.getType(); + expect(type).to.be(ol.style.ShapeType.CIRCLE); + }); + + }); + + describe('#setFillColor()', function() { + + it('sets the fill color', function() { + var symbolizer = new ol.style.Shape({ + fillColor: '#ff0000' + }); + + symbolizer.setFillColor(new ol.expr.Literal('#0000ff')); + + var fillColor = symbolizer.getFillColor(); + expect(fillColor).to.be.a(ol.expr.Literal); + expect(fillColor.getValue()).to.be('#0000ff'); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Shape({ + fillColor: '#ff0000' + }); + + expect(function() { + symbolizer.setFillColor('#0000ff'); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setStrokeColor()', function() { + + it('sets the stroke color', function() { + var symbolizer = new ol.style.Shape({ + strokeColor: '#ff0000' + }); + + symbolizer.setStrokeColor(new ol.expr.Literal('#0000ff')); + + var strokeColor = symbolizer.getStrokeColor(); + expect(strokeColor).to.be.a(ol.expr.Literal); + expect(strokeColor.getValue()).to.be('#0000ff'); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Shape({ + strokeColor: '#ff0000' + }); + + expect(function() { + symbolizer.setStrokeColor('#0000ff'); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setStrokeWidth()', function() { + + it('sets the stroke width', function() { + var symbolizer = new ol.style.Shape({ + strokeWidth: 10 + }); + symbolizer.setStrokeWidth(new ol.expr.Literal(20)); + + var strokeWidth = symbolizer.getStrokeWidth(); + expect(strokeWidth).to.be.a(ol.expr.Literal); + expect(strokeWidth.getValue()).to.be(20); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Shape({ + strokeWidth: 10 + }); + + expect(function() { + symbolizer.setStrokeWidth(10); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setType()', function() { + + it('sets the shape type', function() { + var symbolizer = new ol.style.Shape({ + strokeWidth: 1, + opacity: 0.123 + }); + symbolizer.setType(ol.style.ShapeType.CIRCLE); + + var type = symbolizer.getType(); + expect(type).to.be(ol.style.ShapeType.CIRCLE); + }); + + }); + + describe('#setOpacity()', function() { + + it('sets the stroke opacity', function() { + var symbolizer = new ol.style.Shape({ + strokeWidth: 1, + opacity: 0.123 + }); + symbolizer.setOpacity(new ol.expr.Literal(0.321)); + + var opacity = symbolizer.getOpacity(); + expect(opacity).to.be.a(ol.expr.Literal); + expect(opacity.getValue()).to.be(0.321); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Shape({ + strokeWidth: 1, + opacity: 1 + }); + + expect(function() { + symbolizer.setOpacity(0.5); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); }); +goog.require('goog.asserts.AssertionError'); + goog.require('ol.Feature'); goog.require('ol.expr'); +goog.require('ol.expr.Literal'); goog.require('ol.style.Shape'); goog.require('ol.style.ShapeLiteral'); goog.require('ol.style.ShapeType'); From 88444651882aa094648449def942a44c4a2e47ca Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 12 Jul 2013 10:17:08 -0600 Subject: [PATCH 4/7] Fixing bug with IconLiteral#equals and adding tests --- src/ol/style/icon.js | 2 +- test/spec/ol/style/icon.test.js | 163 ++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 test/spec/ol/style/icon.test.js diff --git a/src/ol/style/icon.js b/src/ol/style/icon.js index 9be3af41a8..a43b904d50 100644 --- a/src/ol/style/icon.js +++ b/src/ol/style/icon.js @@ -51,7 +51,7 @@ goog.inherits(ol.style.IconLiteral, ol.style.PointLiteral); * @inheritDoc */ ol.style.IconLiteral.prototype.equals = function(iconLiteral) { - return this.url == iconLiteral.type && + return this.url == iconLiteral.url && this.width == iconLiteral.width && this.height == iconLiteral.height && this.opacity == iconLiteral.opacity && diff --git a/test/spec/ol/style/icon.test.js b/test/spec/ol/style/icon.test.js new file mode 100644 index 0000000000..2f41fa4805 --- /dev/null +++ b/test/spec/ol/style/icon.test.js @@ -0,0 +1,163 @@ +goog.provide('ol.test.style.Icon'); + +describe('ol.style.IconLiteral', function() { + + describe('#equals()', function() { + + it('identifies equal literals', function() { + var literal = new ol.style.IconLiteral({ + height: 10, + width: 20, + opacity: 1, + rotation: 0.1, + url: 'http://example.com/1.png' + }); + var equalLiteral = new ol.style.IconLiteral({ + height: 10, + width: 20, + opacity: 1, + rotation: 0.1, + url: 'http://example.com/1.png' + }); + var differentLiteral1 = new ol.style.IconLiteral({ + height: 11, + width: 20, + opacity: 1, + rotation: 0.1, + url: 'http://example.com/1.png' + }); + var differentLiteral2 = new ol.style.IconLiteral({ + height: 10, + width: 2, + opacity: 1, + rotation: 0.1, + url: 'http://example.com/1.png' + }); + var differentLiteral3 = new ol.style.IconLiteral({ + height: 10, + width: 20, + opacity: 0.5, + rotation: 0.1, + url: 'http://example.com/1.png' + }); + var differentLiteral4 = new ol.style.IconLiteral({ + height: 10, + width: 20, + opacity: 1, + rotation: 0.2, + url: 'http://example.com/1.png' + }); + var differentLiteral5 = new ol.style.IconLiteral({ + height: 10, + width: 20, + opacity: 1, + rotation: 0.1, + url: 'http://example.com/2.png' + }); + expect(literal.equals(equalLiteral)).to.be(true); + expect(literal.equals(differentLiteral1)).to.be(false); + expect(literal.equals(differentLiteral2)).to.be(false); + expect(literal.equals(differentLiteral3)).to.be(false); + expect(literal.equals(differentLiteral4)).to.be(false); + expect(literal.equals(differentLiteral5)).to.be(false); + }); + + }); + +}); + +describe('ol.style.Icon', function() { + + describe('constructor', function() { + + it('accepts literal values', function() { + var symbolizer = new ol.style.Icon({ + height: 10, + width: 20, + opacity: 1, + rotation: 0.1, + url: 'http://example.com/1.png' + }); + expect(symbolizer).to.be.a(ol.style.Icon); + }); + + it('accepts expressions', function() { + var symbolizer = new ol.style.Icon({ + height: ol.expr.parse('10'), + width: ol.expr.parse('20'), + opacity: ol.expr.parse('1'), + rotation: ol.expr.parse('0.1'), + url: ol.expr.parse('"http://example.com/1.png"') + }); + expect(symbolizer).to.be.a(ol.style.Icon); + }); + + }); + + describe('#createLiteral()', function() { + + it('evaluates expressions with the given feature', function() { + var symbolizer = new ol.style.Icon({ + height: ol.expr.parse('heightAttr'), + width: ol.expr.parse('widthAttr'), + opacity: ol.expr.parse('opacityAttr'), + rotation: ol.expr.parse('rotationAttr'), + url: ol.expr.parse('urlAttr') + }); + + var feature = new ol.Feature({ + heightAttr: 42, + widthAttr: 0.42, + opacityAttr: 0.5, + rotationAttr: 123, + urlAttr: 'http://example.com/1.png' + }); + + var literal = symbolizer.createLiteral(feature); + expect(literal).to.be.a(ol.style.IconLiteral); + expect(literal.height).to.be(42); + expect(literal.width).to.be(.42); + expect(literal.opacity).to.be(0.5); + expect(literal.rotation).to.be(123); + expect(literal.url).to.be('http://example.com/1.png'); + }); + + it('can be called without a feature', function() { + var symbolizer = new ol.style.Icon({ + height: ol.expr.parse('10'), + width: ol.expr.parse('20'), + opacity: ol.expr.parse('1'), + rotation: ol.expr.parse('0.1'), + url: ol.expr.parse('"http://example.com/1.png"') + }); + + var literal = symbolizer.createLiteral(); + expect(literal).to.be.a(ol.style.IconLiteral); + expect(literal.height).to.be(10); + expect(literal.width).to.be(20); + expect(literal.opacity).to.be(1); + expect(literal.rotation).to.be(0.1); + expect(literal.url).to.be('http://example.com/1.png'); + }); + + it('applies default type if none provided', function() { + var symbolizer = new ol.style.Icon({ + height: ol.expr.parse('10'), + width: ol.expr.parse('20'), + url: ol.expr.parse('"http://example.com/1.png"') + }); + + var literal = symbolizer.createLiteral(); + expect(literal).to.be.a(ol.style.IconLiteral); + expect(literal.opacity).to.be(1); + expect(literal.rotation).to.be(0); + }); + + }); +}); + + +goog.require('ol.Feature'); +goog.require('ol.expr'); +goog.require('ol.style.Icon'); +goog.require('ol.style.IconLiteral'); From 0e879223893a26ecce981451741aa1f3b3d297c3 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 12 Jul 2013 10:42:59 -0600 Subject: [PATCH 5/7] Getters and setters for icon symbolizer --- src/ol/style/icon.js | 95 +++++++++++++ test/spec/ol/style/icon.test.js | 238 ++++++++++++++++++++++++++++++++ 2 files changed, 333 insertions(+) diff --git a/src/ol/style/icon.js b/src/ol/style/icon.js index a43b904d50..200517d373 100644 --- a/src/ol/style/icon.js +++ b/src/ol/style/icon.js @@ -153,6 +153,101 @@ ol.style.Icon.prototype.createLiteral = function(opt_feature) { }; +/** + * Get the height. + * @return {ol.expr.Expression} Icon height. + */ +ol.style.Icon.prototype.getHeight = function() { + return this.height_; +}; + + +/** + * Get the opacity. + * @return {ol.expr.Expression} Opacity. + */ +ol.style.Icon.prototype.getOpacity = function() { + return this.opacity_; +}; + + +/** + * Get the rotation. + * @return {ol.expr.Expression} Icon rotation. + */ +ol.style.Icon.prototype.getRotation = function() { + return this.rotation_; +}; + + +/** + * Get the url. + * @return {ol.expr.Expression} Icon url. + */ +ol.style.Icon.prototype.getUrl = function() { + return this.url_; +}; + + +/** + * Get the width. + * @return {ol.expr.Expression} Icon width. + */ +ol.style.Icon.prototype.getWidth = function() { + return this.width_; +}; + + +/** + * Set the height. + * @param {ol.expr.Expression} height Icon height. + */ +ol.style.Icon.prototype.setHeight = function(height) { + goog.asserts.assertInstanceof(height, ol.expr.Expression); + this.height_ = height; +}; + + +/** + * Set the opacity. + * @param {ol.expr.Expression} opacity Opacity. + */ +ol.style.Icon.prototype.setOpacity = function(opacity) { + goog.asserts.assertInstanceof(opacity, ol.expr.Expression); + this.opacity_ = opacity; +}; + + +/** + * Set the rotation. + * @param {ol.expr.Expression} rotation Icon rotation. + */ +ol.style.Icon.prototype.setRotation = function(rotation) { + goog.asserts.assertInstanceof(rotation, ol.expr.Expression); + this.rotation_ = rotation; +}; + + +/** + * Set the url. + * @param {ol.expr.Expression} url Icon url. + */ +ol.style.Icon.prototype.setUrl = function(url) { + goog.asserts.assertInstanceof(url, ol.expr.Expression); + this.url_ = url; +}; + + +/** + * Set the width. + * @param {ol.expr.Expression} width Icon width. + */ +ol.style.Icon.prototype.setWidth = function(width) { + goog.asserts.assertInstanceof(width, ol.expr.Expression); + this.width_ = width; +}; + + /** * @type {ol.style.IconLiteral} */ diff --git a/test/spec/ol/style/icon.test.js b/test/spec/ol/style/icon.test.js index 2f41fa4805..a697f53b47 100644 --- a/test/spec/ol/style/icon.test.js +++ b/test/spec/ol/style/icon.test.js @@ -154,10 +154,248 @@ describe('ol.style.Icon', function() { }); }); + + describe('#getHeight()', function() { + + it('returns the icon height', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + height: 20 + }); + + var height = symbolizer.getHeight(); + expect(height).to.be.a(ol.expr.Literal); + expect(height.getValue()).to.be(20); + }); + + }); + + describe('#getOpacity()', function() { + + it('returns the icon opacity', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + opacity: 0.123 + }); + + var opacity = symbolizer.getOpacity(); + expect(opacity).to.be.a(ol.expr.Literal); + expect(opacity.getValue()).to.be(0.123); + }); + + }); + + describe('#getRotation()', function() { + + it('returns the icon rotation', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + rotation: 0.123 + }); + + var rotation = symbolizer.getRotation(); + expect(rotation).to.be.a(ol.expr.Literal); + expect(rotation.getValue()).to.be(0.123); + }); + + }); + + describe('#getUrl()', function() { + + it('returns the url', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png' + }); + + var url = symbolizer.getUrl(); + expect(url).to.be.a(ol.expr.Literal); + expect(url.getValue()).to.be('http://example.com/1.png'); + }); + + }); + + + describe('#getWidth()', function() { + + it('returns the icon width', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10 + }); + + var width = symbolizer.getWidth(); + expect(width).to.be.a(ol.expr.Literal); + expect(width.getValue()).to.be(10); + }); + + }); + + + describe('#setHeight()', function() { + + it('sets the icon height', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + height: 20 + }); + symbolizer.setHeight(new ol.expr.Literal(30)); + + var height = symbolizer.getHeight(); + expect(height).to.be.a(ol.expr.Literal); + expect(height.getValue()).to.be(30); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + height: 20 + }); + + expect(function() { + symbolizer.setHeight(30); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setOpacity()', function() { + + it('sets the icon opacity', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + height: 20, + opacity: 0.123 + }); + symbolizer.setOpacity(new ol.expr.Literal(0.321)); + + var opacity = symbolizer.getOpacity(); + expect(opacity).to.be.a(ol.expr.Literal); + expect(opacity.getValue()).to.be(0.321); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + height: 20, + opacity: 0.123 + }); + + expect(function() { + symbolizer.setOpacity(0.5); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setRotation()', function() { + + it('sets the icon rotation', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + height: 20, + rotation: 0.123 + }); + symbolizer.setRotation(new ol.expr.Literal(0.321)); + + var rotation = symbolizer.getRotation(); + expect(rotation).to.be.a(ol.expr.Literal); + expect(rotation.getValue()).to.be(0.321); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + height: 20, + rotation: 0.123 + }); + + expect(function() { + symbolizer.setRotation(0.5); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setUrl()', function() { + + it('sets the url', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png' + }); + + symbolizer.setUrl(new ol.expr.Literal('http://example.com/2.png')); + + var url = symbolizer.getUrl(); + expect(url).to.be.a(ol.expr.Literal); + expect(url.getValue()).to.be('http://example.com/2.png'); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png' + }); + + expect(function() { + symbolizer.setUrl('http://example.com/2.png'); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setWidth()', function() { + + it('sets the icon width', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10 + }); + + symbolizer.setWidth(new ol.expr.Literal(20)); + + var width = symbolizer.getWidth(); + expect(width).to.be.a(ol.expr.Literal); + expect(width.getValue()).to.be(20); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10 + }); + + expect(function() { + symbolizer.setWidth(40); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + }); +goog.require('goog.asserts.AssertionError'); + goog.require('ol.Feature'); goog.require('ol.expr'); +goog.require('ol.expr.Literal'); goog.require('ol.style.Icon'); goog.require('ol.style.IconLiteral'); From 4a098aaee35f10ecc24eb7948381d7988f18ffd3 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 12 Jul 2013 10:59:52 -0600 Subject: [PATCH 6/7] Adding tests for text symbolizer --- test/spec/ol/style/text.test.js | 165 ++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 test/spec/ol/style/text.test.js diff --git a/test/spec/ol/style/text.test.js b/test/spec/ol/style/text.test.js new file mode 100644 index 0000000000..3e9ab4f47b --- /dev/null +++ b/test/spec/ol/style/text.test.js @@ -0,0 +1,165 @@ +goog.provide('ol.test.style.Text'); + +describe('ol.style.TextLiteral', function() { + + describe('#equals()', function() { + + it('identifies equal literals', function() { + var literal = new ol.style.TextLiteral({ + color: '#ff0000', + fontFamily: 'Arial', + fontSize: 11, + text: 'Test', + opacity: 0.5 + }); + var equalLiteral = new ol.style.TextLiteral({ + color: '#ff0000', + fontFamily: 'Arial', + fontSize: 11, + text: 'Test', + opacity: 0.5 + }); + var differentLiteral1 = new ol.style.TextLiteral({ + color: '#0000ff', + fontFamily: 'Arial', + fontSize: 11, + text: 'Test', + opacity: 0.5 + }); + var differentLiteral2 = new ol.style.TextLiteral({ + color: '#ff0000', + fontFamily: 'Dingbats', + fontSize: 11, + text: 'Test', + opacity: 0.5 + }); + var differentLiteral3 = new ol.style.TextLiteral({ + color: '#ff0000', + fontFamily: 'Arial', + fontSize: 12, + text: 'Test', + opacity: 0.5 + }); + var differentLiteral4 = new ol.style.TextLiteral({ + color: '#ff0000', + fontFamily: 'Arial', + fontSize: 11, + text: 'Test', + opacity: 0.6 + }); + var equalLiteral2 = new ol.style.TextLiteral({ + color: '#ff0000', + fontFamily: 'Arial', + fontSize: 11, + text: 'Text is not compared for equality', + opacity: 0.5 + }); + expect(literal.equals(equalLiteral)).to.be(true); + expect(literal.equals(differentLiteral1)).to.be(false); + expect(literal.equals(differentLiteral2)).to.be(false); + expect(literal.equals(differentLiteral3)).to.be(false); + expect(literal.equals(differentLiteral4)).to.be(false); + expect(literal.equals(equalLiteral2)).to.be(true); + }); + + }); + +}); + +describe('ol.style.Text', function() { + + describe('constructor', function() { + + it('accepts literal values', function() { + var symbolizer = new ol.style.Text({ + color: '#ff0000', + fontFamily: 'Arial', + fontSize: 11, + text: 'Test', + opacity: 0.6 + }); + expect(symbolizer).to.be.a(ol.style.Text); + }); + + it('accepts expressions', function() { + var symbolizer = new ol.style.Text({ + color: ol.expr.parse('"#ff0000"'), + fontFamily: ol.expr.parse('"Arial"'), + fontSize: ol.expr.parse('11'), + text: ol.expr.parse('"Test"'), + opacity: ol.expr.parse('0.6') + }); + expect(symbolizer).to.be.a(ol.style.Text); + }); + + }); + + describe('#createLiteral()', function() { + + it('evaluates expressions with the given feature', function() { + var symbolizer = new ol.style.Text({ + color: ol.expr.parse('colorAttr'), + fontFamily: ol.expr.parse('fontFamilyAttr'), + fontSize: ol.expr.parse('fontSizeAttr'), + text: ol.expr.parse('textAttr'), + opacity: ol.expr.parse('opacityAttr') + }); + + var feature = new ol.Feature({ + colorAttr: '#ff0000', + fontFamilyAttr: 'Dingbats', + fontSizeAttr: 43, + textAttr: 'Test', + opacityAttr: 0.4 + }); + + var literal = symbolizer.createLiteral(feature); + expect(literal).to.be.a(ol.style.TextLiteral); + expect(literal.color).to.be('#ff0000'); + expect(literal.fontFamily).to.be('Dingbats'); + expect(literal.fontSize).to.be(43); + expect(literal.text).to.be('Test'); + expect(literal.opacity).to.be(0.4); + }); + + it('can be called without a feature', function() { + var symbolizer = new ol.style.Text({ + color: ol.expr.parse('"#ff0000"'), + fontFamily: ol.expr.parse('"Arial"'), + fontSize: ol.expr.parse('11'), + text: ol.expr.parse('"Test"'), + opacity: ol.expr.parse('0.6') + }); + + var literal = symbolizer.createLiteral(); + expect(literal).to.be.a(ol.style.TextLiteral); + expect(literal.color).to.be('#ff0000'); + expect(literal.fontFamily).to.be('Arial'); + expect(literal.fontSize).to.be(11); + expect(literal.text).to.be('Test'); + expect(literal.opacity).to.be(0.6); + }); + + it('applies default type if none provided', function() { + var symbolizer = new ol.style.Text({ + text: 'Test' + }); + + var literal = symbolizer.createLiteral(); + expect(literal).to.be.a(ol.style.TextLiteral); + expect(literal.color).to.be('#000'); + expect(literal.fontFamily).to.be('sans-serif'); + expect(literal.fontSize).to.be(10); + expect(literal.text).to.be('Test'); + expect(literal.opacity).to.be(1); + }); + + }); + +}); + +goog.require('ol.Feature'); +goog.require('ol.expr'); +goog.require('ol.expr.Literal'); +goog.require('ol.style.Text'); +goog.require('ol.style.TextLiteral'); From 8b93c5a0a0d3c651f03a6511b823ade108b41d77 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 12 Jul 2013 11:16:17 -0600 Subject: [PATCH 7/7] Getters and setters for text symbolizer --- src/ol/style/text.js | 95 +++++++++++++++ test/spec/ol/style/text.test.js | 202 ++++++++++++++++++++++++++++++++ 2 files changed, 297 insertions(+) diff --git a/src/ol/style/text.js b/src/ol/style/text.js index a1862bc776..e4fd413446 100644 --- a/src/ol/style/text.js +++ b/src/ol/style/text.js @@ -148,6 +148,101 @@ ol.style.Text.prototype.createLiteral = function(opt_feature) { }; +/** + * Get the font color. + * @return {ol.expr.Expression} Font color. + */ +ol.style.Text.prototype.getColor = function() { + return this.color_; +}; + + +/** + * Get the font family. + * @return {ol.expr.Expression} Font family. + */ +ol.style.Text.prototype.getFontFamily = function() { + return this.fontFamily_; +}; + + +/** + * Get the font size. + * @return {ol.expr.Expression} Font size. + */ +ol.style.Text.prototype.getFontSize = function() { + return this.fontSize_; +}; + + +/** + * Get the opacity. + * @return {ol.expr.Expression} Opacity. + */ +ol.style.Text.prototype.getOpacity = function() { + return this.opacity_; +}; + + +/** + * Get the text. + * @return {ol.expr.Expression} Text. + */ +ol.style.Text.prototype.getText = function() { + return this.text_; +}; + + +/** + * Set the font color. + * @param {ol.expr.Expression} color Font color. + */ +ol.style.Text.prototype.setColor = function(color) { + goog.asserts.assertInstanceof(color, ol.expr.Expression); + this.color_ = color; +}; + + +/** + * Set the font family. + * @param {ol.expr.Expression} fontFamily Font family. + */ +ol.style.Text.prototype.setFontFamily = function(fontFamily) { + goog.asserts.assertInstanceof(fontFamily, ol.expr.Expression); + this.fontFamily_ = fontFamily; +}; + + +/** + * Set the font size. + * @param {ol.expr.Expression} fontSize Font size. + */ +ol.style.Text.prototype.setFontSize = function(fontSize) { + goog.asserts.assertInstanceof(fontSize, ol.expr.Expression); + this.fontSize_ = fontSize; +}; + + +/** + * Set the opacity. + * @param {ol.expr.Expression} opacity Opacity. + */ +ol.style.Text.prototype.setOpacity = function(opacity) { + goog.asserts.assertInstanceof(opacity, ol.expr.Expression); + this.opacity_ = opacity; +}; + + +/** + * Set the text. + * @param {ol.expr.Expression} text Text. + */ +ol.style.Text.prototype.setText = function(text) { + goog.asserts.assertInstanceof(text, ol.expr.Expression); + this.text_ = text; +}; + + /** * @type {ol.style.TextLiteral} */ diff --git a/test/spec/ol/style/text.test.js b/test/spec/ol/style/text.test.js index 3e9ab4f47b..6c8efce73f 100644 --- a/test/spec/ol/style/text.test.js +++ b/test/spec/ol/style/text.test.js @@ -156,10 +156,212 @@ describe('ol.style.Text', function() { }); + describe('#getColor()', function() { + + it('returns the text color', function() { + var symbolizer = new ol.style.Text({ + color: '#ff0000' + }); + + var color = symbolizer.getColor(); + expect(color).to.be.a(ol.expr.Literal); + expect(color.getValue()).to.be('#ff0000'); + }); + + }); + + + describe('#getFontFamily()', function() { + + it('returns the font family', function() { + var symbolizer = new ol.style.Text({ + fontFamily: 'Arial' + }); + + var fontFamily = symbolizer.getFontFamily(); + expect(fontFamily).to.be.a(ol.expr.Literal); + expect(fontFamily.getValue()).to.be('Arial'); + }); + + }); + + describe('#getFontSize()', function() { + + it('returns the font size', function() { + var symbolizer = new ol.style.Text({ + fontSize: 42 + }); + + var fontSize = symbolizer.getFontSize(); + expect(fontSize).to.be.a(ol.expr.Literal); + expect(fontSize.getValue()).to.be(42); + }); + + }); + + describe('#getOpacity()', function() { + + it('returns the opacity', function() { + var symbolizer = new ol.style.Text({ + fontSize: 1, + opacity: 0.123 + }); + + var opacity = symbolizer.getOpacity(); + expect(opacity).to.be.a(ol.expr.Literal); + expect(opacity.getValue()).to.be(0.123); + }); + + }); + + describe('#setColor()', function() { + + it('sets the text color', function() { + var symbolizer = new ol.style.Text({ + color: '#ff0000' + }); + + symbolizer.setColor(new ol.expr.Literal('#0000ff')); + + var color = symbolizer.getColor(); + expect(color).to.be.a(ol.expr.Literal); + expect(color.getValue()).to.be('#0000ff'); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Text({ + color: '#ff0000' + }); + + expect(function() { + symbolizer.setColor('#0000ff'); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setFontFamily()', function() { + + it('sets the font family', function() { + var symbolizer = new ol.style.Text({ + fontFamily: '#ff0000' + }); + + symbolizer.setFontFamily(new ol.expr.Literal('#0000ff')); + + var fontFamily = symbolizer.getFontFamily(); + expect(fontFamily).to.be.a(ol.expr.Literal); + expect(fontFamily.getValue()).to.be('#0000ff'); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Text({ + fontFamily: '#ff0000' + }); + + expect(function() { + symbolizer.setFontFamily('#0000ff'); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setFontSize()', function() { + + it('sets the font size', function() { + var symbolizer = new ol.style.Text({ + fontSize: 10 + }); + symbolizer.setFontSize(new ol.expr.Literal(20)); + + var fontSize = symbolizer.getFontSize(); + expect(fontSize).to.be.a(ol.expr.Literal); + expect(fontSize.getValue()).to.be(20); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Text({ + fontSize: 10 + }); + + expect(function() { + symbolizer.setFontSize(10); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setOpacity()', function() { + + it('sets the opacity', function() { + var symbolizer = new ol.style.Text({ + fontSize: 1, + opacity: 0.123 + }); + symbolizer.setOpacity(new ol.expr.Literal(0.321)); + + var opacity = symbolizer.getOpacity(); + expect(opacity).to.be.a(ol.expr.Literal); + expect(opacity.getValue()).to.be(0.321); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Text({ + fontSize: 1, + opacity: 1 + }); + + expect(function() { + symbolizer.setOpacity(0.5); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setText()', function() { + + it('sets the text', function() { + var symbolizer = new ol.style.Text({ + fontSize: 1, + text: 'Initial Text' + }); + symbolizer.setText(new ol.expr.Literal('New Text')); + + var text = symbolizer.getText(); + expect(text).to.be.a(ol.expr.Literal); + expect(text.getValue()).to.be('New Text'); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Text({ + fontSize: 1, + text: 'Test' + }); + + expect(function() { + symbolizer.setText('Bad'); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + }); +goog.require('goog.asserts.AssertionError'); + goog.require('ol.Feature'); goog.require('ol.expr'); goog.require('ol.expr.Literal'); +goog.require('ol.expr.Literal'); goog.require('ol.style.Text'); goog.require('ol.style.TextLiteral');