Skip to content

Commit

Permalink
Getters and setters for polygon symbolizer
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaub committed Jul 12, 2013
1 parent 7112611 commit a0d058b
Show file tree
Hide file tree
Showing 2 changed files with 249 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/ol/style/polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
173 changes: 173 additions & 0 deletions test/spec/ol/style/polygon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

0 comments on commit a0d058b

Please sign in to comment.