From 2e08ccce036c203f3fd06a55f0023acd67df382b Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 12 Jul 2013 09:57:40 -0600 Subject: [PATCH] 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');