Optional zIndex for text symbolizers
This commit is contained in:
@@ -748,6 +748,7 @@
|
||||
* @property {number|ol.expr.Expression|undefined} fontSize Font size in pixels.
|
||||
* @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} zIndex Stack order.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,7 +9,8 @@ goog.require('ol.style.Literal');
|
||||
* fontFamily: string,
|
||||
* fontSize: number,
|
||||
* text: string,
|
||||
* opacity: number}}
|
||||
* opacity: number,
|
||||
* zIndex: (number|undefined)}}
|
||||
*/
|
||||
ol.style.TextLiteralOptions;
|
||||
|
||||
@@ -42,6 +43,9 @@ ol.style.TextLiteral = function(options) {
|
||||
/** @type {number} */
|
||||
this.opacity = options.opacity;
|
||||
|
||||
/** @type {number|undefined} */
|
||||
this.zIndex = options.zIndex;
|
||||
|
||||
};
|
||||
goog.inherits(ol.style.TextLiteral, ol.style.Literal);
|
||||
|
||||
@@ -49,9 +53,10 @@ goog.inherits(ol.style.TextLiteral, ol.style.Literal);
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.style.TextLiteral.prototype.equals = function(textLiteral) {
|
||||
return this.color == textLiteral.color &&
|
||||
this.fontFamily == textLiteral.fontFamily &&
|
||||
this.fontSize == textLiteral.fontSize &&
|
||||
this.opacity == textLiteral.opacity;
|
||||
ol.style.TextLiteral.prototype.equals = function(other) {
|
||||
return this.color == other.color &&
|
||||
this.fontFamily == other.fontFamily &&
|
||||
this.fontSize == other.fontSize &&
|
||||
this.opacity == other.opacity &&
|
||||
this.zIndex == other.zIndex;
|
||||
};
|
||||
|
||||
@@ -60,6 +60,15 @@ ol.style.Text = function(options) {
|
||||
(options.opacity instanceof ol.expr.Expression) ?
|
||||
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);
|
||||
|
||||
@@ -93,12 +102,19 @@ ol.style.Text.prototype.createLiteral = function(featureOrType) {
|
||||
var opacity = Number(ol.expr.evaluateFeature(this.opacity_, feature));
|
||||
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({
|
||||
color: color,
|
||||
fontFamily: fontFamily,
|
||||
fontSize: fontSize,
|
||||
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.
|
||||
* @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,
|
||||
* fontFamily: string,
|
||||
|
||||
@@ -54,12 +54,21 @@ describe('ol.style.TextLiteral', function() {
|
||||
text: 'Text is not compared for equality',
|
||||
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(differentLiteral1)).to.be(false);
|
||||
expect(literal.equals(differentLiteral2)).to.be(false);
|
||||
expect(literal.equals(differentLiteral3)).to.be(false);
|
||||
expect(literal.equals(differentLiteral4)).to.be(false);
|
||||
expect(literal.equals(equalLiteral2)).to.be(true);
|
||||
expect(literal.equals(differentZIndex)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -26,6 +26,18 @@ describe('ol.style.Text', function() {
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user