Add stroke properties to text symbolizer literal

This commit is contained in:
Tim Schaub
2013-10-07 15:43:17 -06:00
parent aca022df6e
commit 5e86ffcca5
2 changed files with 87 additions and 0 deletions

View File

@@ -10,6 +10,9 @@ goog.require('ol.style.Literal');
* fontSize: number,
* text: string,
* opacity: number,
* strokeColor: (string|undefined),
* strokeOpacity: (number|undefined),
* strokeWidth: (number|undefined),
* zIndex: number}}
*/
ol.style.TextLiteralOptions;
@@ -43,6 +46,37 @@ ol.style.TextLiteral = function(options) {
/** @type {number} */
this.opacity = options.opacity;
/** @type {string|undefined} */
this.strokeColor = options.strokeColor;
if (goog.isDef(this.strokeColor)) {
goog.asserts.assertString(
this.strokeColor, 'strokeColor must be a string');
}
/** @type {number|undefined} */
this.strokeOpacity = options.strokeOpacity;
if (goog.isDef(this.strokeOpacity)) {
goog.asserts.assertNumber(
this.strokeOpacity, 'strokeOpacity must be a number');
}
/** @type {number|undefined} */
this.strokeWidth = options.strokeWidth;
if (goog.isDef(this.strokeWidth)) {
goog.asserts.assertNumber(
this.strokeWidth, 'strokeWidth must be a number');
}
// if any stroke property is defined, all must be defined
var strokeDef = goog.isDef(this.strokeColor) &&
goog.isDef(this.strokeOpacity) &&
goog.isDef(this.strokeWidth);
var strokeUndef = !goog.isDef(this.strokeColor) &&
!goog.isDef(this.strokeOpacity) &&
!goog.isDef(this.strokeWidth);
goog.asserts.assert(strokeDef || strokeUndef,
'If any stroke property is defined, all must be defined');
goog.asserts.assertNumber(options.zIndex, 'zIndex must be a number');
/** @type {number} */
this.zIndex = options.zIndex;
@@ -59,5 +93,8 @@ ol.style.TextLiteral.prototype.equals = function(other) {
this.fontFamily == other.fontFamily &&
this.fontSize == other.fontSize &&
this.opacity == other.opacity &&
this.strokeColor == other.strokeColor &&
this.strokeOpacity == other.strokeOpacity &&
this.strokeWidth == other.strokeWidth &&
this.zIndex == other.zIndex;
};

View File

@@ -2,6 +2,54 @@ goog.provide('ol.test.style.TextLiteral');
describe('ol.style.TextLiteral', function() {
describe('constructor', function() {
it('creates a new literal', function() {
var literal = new ol.style.TextLiteral({
color: '#ff0000',
fontFamily: 'Arial',
fontSize: 11,
text: 'Test',
opacity: 0.5,
zIndex: 0
});
expect(literal).to.be.a(ol.style.Literal);
expect(literal).to.be.a(ol.style.TextLiteral);
});
it('accepts stroke properties', function() {
var literal = new ol.style.TextLiteral({
color: '#ff0000',
fontFamily: 'Arial',
fontSize: 11,
text: 'Test',
opacity: 0.5,
strokeColor: '#ff0000',
strokeWidth: 2,
strokeOpacity: 0.5,
zIndex: 0
});
expect(literal).to.be.a(ol.style.TextLiteral);
});
it('throws with incomplete stroke properties', function() {
expect(function() {
new ol.style.TextLiteral({
color: '#ff0000',
fontFamily: 'Arial',
fontSize: 11,
text: 'Test',
opacity: 0.5,
strokeColor: '#ff0000',
zIndex: 0
});
}).throwException(function(err) {
expect(err).to.be.a(goog.asserts.AssertionError);
});
});
});
describe('#equals()', function() {
it('identifies equal literals', function() {
@@ -82,4 +130,6 @@ describe('ol.style.TextLiteral', function() {
});
goog.require('goog.asserts.AssertionError');
goog.require('ol.style.Literal');
goog.require('ol.style.TextLiteral');