Getters and setters for text symbolizer

This commit is contained in:
Tim Schaub
2013-07-12 11:16:17 -06:00
parent 4a098aaee3
commit 8b93c5a0a0
2 changed files with 297 additions and 0 deletions

View File

@@ -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}
*/

View File

@@ -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');