Optional zIndex for stroke symbolizers

This commit is contained in:
Tim Schaub
2013-08-26 15:27:45 -06:00
parent 04a23d0e45
commit 33cacab11c
5 changed files with 69 additions and 10 deletions
+1
View File
@@ -728,6 +728,7 @@
* color code. * color code.
* @property {number|ol.expr.Expression|undefined} opacity Stroke opacity (0-1). * @property {number|ol.expr.Expression|undefined} opacity Stroke opacity (0-1).
* @property {number|ol.expr.Expression|undefined} width Stroke width in pixels. * @property {number|ol.expr.Expression|undefined} width Stroke width in pixels.
* @property {number|ol.expr.Expression|undefined} zIndex Stack order.
*/ */
/** /**
+10 -5
View File
@@ -7,7 +7,8 @@ goog.require('ol.style.Literal');
/** /**
* @typedef {{color: (string), * @typedef {{color: (string),
* opacity: (number), * opacity: (number),
* width: (number)}} * width: (number),
* zIndex: (number|undefined)}}
*/ */
ol.style.LineLiteralOptions; ol.style.LineLiteralOptions;
@@ -36,6 +37,9 @@ ol.style.LineLiteral = function(options) {
/** @type {number} */ /** @type {number} */
this.width = options.width; this.width = options.width;
/** @type {number|undefined} */
this.zIndex = options.zIndex;
}; };
goog.inherits(ol.style.LineLiteral, ol.style.Literal); goog.inherits(ol.style.LineLiteral, ol.style.Literal);
@@ -43,8 +47,9 @@ goog.inherits(ol.style.LineLiteral, ol.style.Literal);
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.style.LineLiteral.prototype.equals = function(lineLiteral) { ol.style.LineLiteral.prototype.equals = function(other) {
return this.color == lineLiteral.color && return this.color == other.color &&
this.opacity == lineLiteral.opacity && this.opacity == other.opacity &&
this.width == lineLiteral.width; this.width == other.width &&
this.zIndex == other.zIndex;
}; };
+41 -5
View File
@@ -49,6 +49,15 @@ ol.style.Stroke = function(opt_options) {
(options.width instanceof ol.expr.Expression) ? (options.width instanceof ol.expr.Expression) ?
options.width : new ol.expr.Literal(options.width); options.width : new ol.expr.Literal(options.width);
/**
* @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.Stroke, ol.style.Symbolizer); goog.inherits(ol.style.Stroke, ol.style.Symbolizer);
@@ -79,20 +88,28 @@ ol.style.Stroke.prototype.createLiteral = function(featureOrType) {
this.width_, feature)); this.width_, feature));
goog.asserts.assert(!isNaN(width), 'width must be a number'); goog.asserts.assert(!isNaN(width), 'width 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');
}
var literal = null; var literal = null;
if (type === ol.geom.GeometryType.LINESTRING || if (type === ol.geom.GeometryType.LINESTRING ||
type === ol.geom.GeometryType.MULTILINESTRING) { type === ol.geom.GeometryType.MULTILINESTRING) {
literal = new ol.style.LineLiteral({ literal = new ol.style.LineLiteral({
color: color, color: color,
opacity: opacity, opacity: opacity,
width: width width: width,
zIndex: zIndex
}); });
} else if (type === ol.geom.GeometryType.POLYGON || } else if (type === ol.geom.GeometryType.POLYGON ||
type === ol.geom.GeometryType.MULTIPOLYGON) { type === ol.geom.GeometryType.MULTIPOLYGON) {
literal = new ol.style.PolygonLiteral({ literal = new ol.style.PolygonLiteral({
strokeColor: color, strokeColor: color,
strokeOpacity: opacity, strokeOpacity: opacity,
strokeWidth: width strokeWidth: width,
zIndex: zIndex
}); });
} }
@@ -127,6 +144,15 @@ ol.style.Stroke.prototype.getWidth = function() {
}; };
/**
* Get the stroke zIndex.
* @return {ol.expr.Expression} Stroke zIndex.
*/
ol.style.Stroke.prototype.getZIndex = function() {
return this.zIndex_;
};
/** /**
* Set the stroke color. * Set the stroke color.
* @param {ol.expr.Expression} color Stroke color. * @param {ol.expr.Expression} color Stroke color.
@@ -158,9 +184,19 @@ ol.style.Stroke.prototype.setWidth = function(width) {
/** /**
* @typedef {{color: (string), * Set the stroke zIndex.
* opacity: (number), * @param {ol.expr.Expression} zIndex Stroke zIndex.
* width: (number)}} */
ol.style.Stroke.prototype.setZIndex = function(zIndex) {
goog.asserts.assertInstanceof(zIndex, ol.expr.Expression);
this.zIndex_ = zIndex;
};
/**
* @typedef {{strokeColor: (string),
* strokeOpacity: (number),
* strokeWidth: (number)}}
*/ */
ol.style.StrokeDefaults = { ol.style.StrokeDefaults = {
color: '#696969', color: '#696969',
+7
View File
@@ -30,10 +30,17 @@ describe('ol.style.LineLiteral', function() {
color: '#BADA55', color: '#BADA55',
opacity: 0.5 opacity: 0.5
}); });
var differentZIndex = new ol.style.LineLiteral({
width: 3,
color: '#BADA55',
opacity: 1,
zIndex: 3
});
expect(literal.equals(equalLiteral)).to.be(true); expect(literal.equals(equalLiteral)).to.be(true);
expect(literal.equals(differentColor)).to.be(false); expect(literal.equals(differentColor)).to.be(false);
expect(literal.equals(differentWidth)).to.be(false); expect(literal.equals(differentWidth)).to.be(false);
expect(literal.equals(differentOpacity)).to.be(false); expect(literal.equals(differentOpacity)).to.be(false);
expect(literal.equals(differentZIndex)).to.be(false);
}); });
}); });
@@ -20,6 +20,15 @@ describe('ol.style.Stroke', function() {
expect(symbolizer).to.be.a(ol.style.Stroke); expect(symbolizer).to.be.a(ol.style.Stroke);
}); });
it('accepts zIndex', function() {
var symbolizer = new ol.style.Stroke({
opacity: ol.expr.parse('value / 100'),
width: ol.expr.parse('widthAttr'),
zIndex: 5
});
expect(symbolizer).to.be.a(ol.style.Stroke);
});
}); });
describe('#createLiteral()', function() { describe('#createLiteral()', function() {
@@ -40,6 +49,7 @@ describe('ol.style.Stroke', function() {
expect(literal).to.be.a(ol.style.LineLiteral); expect(literal).to.be.a(ol.style.LineLiteral);
expect(literal.opacity).to.be(42 / 100); expect(literal.opacity).to.be(42 / 100);
expect(literal.width).to.be(1.5); expect(literal.width).to.be(1.5);
expect(literal.zIndex).to.be(undefined);
}); });
it('applies the default values', function() { it('applies the default values', function() {