Optional zIndex for text symbolizers

This commit is contained in:
Tim Schaub
2013-08-26 15:50:45 -06:00
parent b9a44d2db5
commit 43c581ef5f
5 changed files with 69 additions and 7 deletions

View File

@@ -748,6 +748,7 @@
* @property {number|ol.expr.Expression|undefined} fontSize Font size in pixels. * @property {number|ol.expr.Expression|undefined} fontSize Font size in pixels.
* @property {string|ol.expr.Expression} text Text for the label. * @property {string|ol.expr.Expression} text Text for the label.
* @property {number|ol.expr.Expression|undefined} opacity Opacity (0-1). * @property {number|ol.expr.Expression|undefined} opacity Opacity (0-1).
* @property {number|ol.expr.Expression|undefined} zIndex Stack order.
*/ */
/** /**

View File

@@ -9,7 +9,8 @@ goog.require('ol.style.Literal');
* fontFamily: string, * fontFamily: string,
* fontSize: number, * fontSize: number,
* text: string, * text: string,
* opacity: number}} * opacity: number,
* zIndex: (number|undefined)}}
*/ */
ol.style.TextLiteralOptions; ol.style.TextLiteralOptions;
@@ -42,6 +43,9 @@ ol.style.TextLiteral = function(options) {
/** @type {number} */ /** @type {number} */
this.opacity = options.opacity; this.opacity = options.opacity;
/** @type {number|undefined} */
this.zIndex = options.zIndex;
}; };
goog.inherits(ol.style.TextLiteral, ol.style.Literal); goog.inherits(ol.style.TextLiteral, ol.style.Literal);
@@ -49,9 +53,10 @@ goog.inherits(ol.style.TextLiteral, ol.style.Literal);
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.style.TextLiteral.prototype.equals = function(textLiteral) { ol.style.TextLiteral.prototype.equals = function(other) {
return this.color == textLiteral.color && return this.color == other.color &&
this.fontFamily == textLiteral.fontFamily && this.fontFamily == other.fontFamily &&
this.fontSize == textLiteral.fontSize && this.fontSize == other.fontSize &&
this.opacity == textLiteral.opacity; this.opacity == other.opacity &&
this.zIndex == other.zIndex;
}; };

View File

@@ -60,6 +60,15 @@ ol.style.Text = function(options) {
(options.opacity instanceof ol.expr.Expression) ? (options.opacity instanceof ol.expr.Expression) ?
options.opacity : new ol.expr.Literal(options.opacity); options.opacity : new ol.expr.Literal(options.opacity);
/**
* @type {ol.expr.Expression}
* @private
*/
this.zIndex_ = !goog.isDefAndNotNull(options.zIndex) ?
null :
(options.zIndex instanceof ol.expr.Expression) ?
options.zIndex : new ol.expr.Literal(options.zIndex);
}; };
goog.inherits(ol.style.Text, ol.style.Symbolizer); goog.inherits(ol.style.Text, ol.style.Symbolizer);
@@ -93,12 +102,19 @@ ol.style.Text.prototype.createLiteral = function(featureOrType) {
var opacity = Number(ol.expr.evaluateFeature(this.opacity_, feature)); var opacity = Number(ol.expr.evaluateFeature(this.opacity_, feature));
goog.asserts.assert(!isNaN(opacity), 'opacity must be a number'); goog.asserts.assert(!isNaN(opacity), 'opacity must be a number');
var zIndex;
if (!goog.isNull(this.zIndex_)) {
zIndex = Number(ol.expr.evaluateFeature(this.zIndex_, feature));
goog.asserts.assert(!isNaN(zIndex), 'zIndex must be a number');
}
return new ol.style.TextLiteral({ return new ol.style.TextLiteral({
color: color, color: color,
fontFamily: fontFamily, fontFamily: fontFamily,
fontSize: fontSize, fontSize: fontSize,
text: text, text: text,
opacity: opacity opacity: opacity,
zIndex: zIndex
}); });
}; };
@@ -148,6 +164,15 @@ ol.style.Text.prototype.getText = function() {
}; };
/**
* Get the zIndex.
* @return {ol.expr.Expression} Text.
*/
ol.style.Text.prototype.getZIndex = function() {
return this.zIndex_;
};
/** /**
* Set the font color. * Set the font color.
* @param {ol.expr.Expression} color Font color. * @param {ol.expr.Expression} color Font color.
@@ -198,6 +223,16 @@ ol.style.Text.prototype.setText = function(text) {
}; };
/**
* Set the zIndex.
* @param {ol.expr.Expression} zIndex Text.
*/
ol.style.Text.prototype.setZIndex = function(zIndex) {
goog.asserts.assertInstanceof(zIndex, ol.expr.Expression);
this.zIndex_ = zIndex;
};
/** /**
* @typedef {{color: string, * @typedef {{color: string,
* fontFamily: string, * fontFamily: string,

View File

@@ -54,12 +54,21 @@ describe('ol.style.TextLiteral', function() {
text: 'Text is not compared for equality', text: 'Text is not compared for equality',
opacity: 0.5 opacity: 0.5
}); });
var differentZIndex = new ol.style.TextLiteral({
color: '#ff0000',
fontFamily: 'Arial',
fontSize: 11,
text: 'Test',
opacity: 0.5,
zIndex: 3
});
expect(literal.equals(equalLiteral)).to.be(true); expect(literal.equals(equalLiteral)).to.be(true);
expect(literal.equals(differentLiteral1)).to.be(false); expect(literal.equals(differentLiteral1)).to.be(false);
expect(literal.equals(differentLiteral2)).to.be(false); expect(literal.equals(differentLiteral2)).to.be(false);
expect(literal.equals(differentLiteral3)).to.be(false); expect(literal.equals(differentLiteral3)).to.be(false);
expect(literal.equals(differentLiteral4)).to.be(false); expect(literal.equals(differentLiteral4)).to.be(false);
expect(literal.equals(equalLiteral2)).to.be(true); expect(literal.equals(equalLiteral2)).to.be(true);
expect(literal.equals(differentZIndex)).to.be(false);
}); });
}); });

View File

@@ -26,6 +26,18 @@ describe('ol.style.Text', function() {
expect(symbolizer).to.be.a(ol.style.Text); expect(symbolizer).to.be.a(ol.style.Text);
}); });
it('accepts zIndex', function() {
var symbolizer = new ol.style.Text({
color: '#ff0000',
fontFamily: 'Arial',
fontSize: 11,
text: 'Test',
opacity: 0.6,
zIndex: 3
});
expect(symbolizer).to.be.a(ol.style.Text);
});
}); });
describe('#createLiteral()', function() { describe('#createLiteral()', function() {