Add stroke properties to text symbolizer literal
This commit is contained in:
@@ -10,6 +10,9 @@ goog.require('ol.style.Literal');
|
|||||||
* fontSize: number,
|
* fontSize: number,
|
||||||
* text: string,
|
* text: string,
|
||||||
* opacity: number,
|
* opacity: number,
|
||||||
|
* strokeColor: (string|undefined),
|
||||||
|
* strokeOpacity: (number|undefined),
|
||||||
|
* strokeWidth: (number|undefined),
|
||||||
* zIndex: number}}
|
* zIndex: number}}
|
||||||
*/
|
*/
|
||||||
ol.style.TextLiteralOptions;
|
ol.style.TextLiteralOptions;
|
||||||
@@ -43,6 +46,37 @@ ol.style.TextLiteral = function(options) {
|
|||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
this.opacity = options.opacity;
|
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');
|
goog.asserts.assertNumber(options.zIndex, 'zIndex must be a number');
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
this.zIndex = options.zIndex;
|
this.zIndex = options.zIndex;
|
||||||
@@ -59,5 +93,8 @@ ol.style.TextLiteral.prototype.equals = function(other) {
|
|||||||
this.fontFamily == other.fontFamily &&
|
this.fontFamily == other.fontFamily &&
|
||||||
this.fontSize == other.fontSize &&
|
this.fontSize == other.fontSize &&
|
||||||
this.opacity == other.opacity &&
|
this.opacity == other.opacity &&
|
||||||
|
this.strokeColor == other.strokeColor &&
|
||||||
|
this.strokeOpacity == other.strokeOpacity &&
|
||||||
|
this.strokeWidth == other.strokeWidth &&
|
||||||
this.zIndex == other.zIndex;
|
this.zIndex == other.zIndex;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,54 @@ goog.provide('ol.test.style.TextLiteral');
|
|||||||
|
|
||||||
describe('ol.style.TextLiteral', function() {
|
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() {
|
describe('#equals()', function() {
|
||||||
|
|
||||||
it('identifies equal literals', 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');
|
goog.require('ol.style.TextLiteral');
|
||||||
|
|||||||
Reference in New Issue
Block a user