Rename line symbolizer opacity to strokeOpacity for consistency

We already have strokeColor and strokeWidth.  Having strokeOpacity makes sense.
This commit is contained in:
Tim Schaub
2013-07-30 16:32:42 -06:00
parent 1cedea6606
commit f210d6d0e1
7 changed files with 68 additions and 64 deletions

View File

@@ -21,7 +21,7 @@ var style = new ol.style.Style({rules: [
new ol.style.Line({
strokeColor: ol.expr.parse('color'),
strokeWidth: 4,
opacity: 1
strokeOpacity: 1
})
]
}),
@@ -31,12 +31,12 @@ var style = new ol.style.Style({rules: [
new ol.style.Line({
strokeColor: '#013',
strokeWidth: 4,
opacity: 1
strokeOpacity: 1
}),
new ol.style.Line({
strokeColor: ol.expr.parse('color'),
strokeWidth: 2,
opacity: 1
strokeOpacity: 1
})
]
}),

View File

@@ -580,9 +580,10 @@
* @typedef {Object} ol.style.LineOptions
* @property {string|ol.expr.Expression|undefined} strokeColor Stroke
* color as hex color code.
* @property {number|ol.expr.Expression|undefined} strokeOpacity Stroke
* opacity (0-1).
* @property {number|ol.expr.Expression|undefined} strokeWidth Stroke
* width in pixels.
* @property {number|ol.expr.Expression|undefined} opacity Opacity (0-1).
*/
/**

View File

@@ -342,7 +342,7 @@ ol.parser.KML = function(opt_options) {
this.readChildNodes(node, symbolizer);
if (symbolizer.color) {
symbolizer.strokeColor = symbolizer.color.color;
symbolizer.opacity = symbolizer.color.opacity;
symbolizer.strokeOpacity = symbolizer.color.opacity;
}
if (symbolizer.width) {
symbolizer.strokeWidth = parseFloat(symbolizer.width);
@@ -657,7 +657,7 @@ ol.parser.KML = function(opt_options) {
symbolizer : symbolizer.createLiteral();
this.writeNode('color', {
color: literal.strokeColor.substring(1),
opacity: literal.opacity
opacity: literal.strokeOpacity
}, null, node);
this.writeNode('width', literal.strokeWidth, null, node);
return node;

View File

@@ -153,7 +153,7 @@ ol.renderer.canvas.VectorRenderer.prototype.renderLineStringFeatures_ =
i, ii, feature, id, currentSize, geometry, components, j, jj, line, dim,
k, kk, vec, strokeSize;
context.globalAlpha = symbolizer.opacity;
context.globalAlpha = symbolizer.strokeOpacity;
context.strokeStyle = symbolizer.strokeColor;
context.lineWidth = symbolizer.strokeWidth;
context.lineCap = 'round'; // TODO: accept this as a symbolizer property

View File

@@ -11,8 +11,8 @@ goog.require('ol.style.SymbolizerLiteral');
/**
* @typedef {{strokeColor: (string),
* strokeWidth: (number),
* opacity: (number)}}
* strokeOpacity: (number),
* strokeWidth: (number)}}
*/
ol.style.LineLiteralOptions;
@@ -31,15 +31,16 @@ ol.style.LineLiteral = function(options) {
/** @type {string} */
this.strokeColor = options.strokeColor;
goog.asserts.assertNumber(
options.strokeOpacity, 'strokeOpacity must be a number');
/** @type {number} */
this.strokeOpacity = options.strokeOpacity;
goog.asserts.assertNumber(
options.strokeWidth, 'strokeWidth must be a number');
/** @type {number} */
this.strokeWidth = options.strokeWidth;
goog.asserts.assertNumber(options.opacity, 'opacity must be a number');
/** @type {number} */
this.opacity = options.opacity;
};
goog.inherits(ol.style.LineLiteral, ol.style.SymbolizerLiteral);
@@ -49,8 +50,8 @@ goog.inherits(ol.style.LineLiteral, ol.style.SymbolizerLiteral);
*/
ol.style.LineLiteral.prototype.equals = function(lineLiteral) {
return this.strokeColor == lineLiteral.strokeColor &&
this.strokeWidth == lineLiteral.strokeWidth &&
this.opacity == lineLiteral.opacity;
this.strokeOpacity == lineLiteral.strokeOpacity &&
this.strokeWidth == lineLiteral.strokeWidth;
};
@@ -76,19 +77,19 @@ ol.style.Line = function(options) {
* @type {ol.expr.Expression}
* @private
*/
this.strokeWidth_ = !goog.isDef(options.strokeWidth) ?
new ol.expr.Literal(ol.style.LineDefaults.strokeWidth) :
(options.strokeWidth instanceof ol.expr.Expression) ?
options.strokeWidth : new ol.expr.Literal(options.strokeWidth);
this.strokeOpacity_ = !goog.isDef(options.strokeOpacity) ?
new ol.expr.Literal(ol.style.LineDefaults.strokeOpacity) :
(options.strokeOpacity instanceof ol.expr.Expression) ?
options.strokeOpacity : new ol.expr.Literal(options.strokeOpacity);
/**
* @type {ol.expr.Expression}
* @private
*/
this.opacity_ = !goog.isDef(options.opacity) ?
new ol.expr.Literal(ol.style.LineDefaults.opacity) :
(options.opacity instanceof ol.expr.Expression) ?
options.opacity : new ol.expr.Literal(options.opacity);
this.strokeWidth_ = !goog.isDef(options.strokeWidth) ?
new ol.expr.Literal(ol.style.LineDefaults.strokeWidth) :
(options.strokeWidth instanceof ol.expr.Expression) ?
options.strokeWidth : new ol.expr.Literal(options.strokeWidth);
};
goog.inherits(ol.style.Line, ol.style.Symbolizer);
@@ -104,17 +105,19 @@ ol.style.Line.prototype.createLiteral = function(opt_feature) {
this.strokeColor_, opt_feature);
goog.asserts.assertString(strokeColor, 'strokeColor must be a string');
var strokeOpacity = ol.expr.evaluateFeature(
this.strokeOpacity_, opt_feature);
goog.asserts.assertNumber(strokeOpacity, 'strokeOpacity must be a number');
var strokeWidth = ol.expr.evaluateFeature(
this.strokeWidth_, opt_feature);
goog.asserts.assertNumber(strokeWidth, 'strokeWidth must be a number');
var opacity = ol.expr.evaluateFeature(this.opacity_, opt_feature);
goog.asserts.assertNumber(opacity, 'opacity must be a number');
return new ol.style.LineLiteral({
strokeColor: strokeColor,
strokeWidth: strokeWidth,
opacity: opacity
strokeOpacity: strokeOpacity,
strokeWidth: strokeWidth
});
};
@@ -128,6 +131,15 @@ ol.style.Line.prototype.getStrokeColor = function() {
};
/**
* Get the stroke opacity.
* @return {ol.expr.Expression} Stroke opacity.
*/
ol.style.Line.prototype.getStrokeOpacity = function() {
return this.strokeOpacity_;
};
/**
* Get the stroke width.
* @return {ol.expr.Expression} Stroke width.
@@ -137,15 +149,6 @@ ol.style.Line.prototype.getStrokeWidth = function() {
};
/**
* Get the stroke opacity.
* @return {ol.expr.Expression} Stroke opacity.
*/
ol.style.Line.prototype.getOpacity = function() {
return this.opacity_;
};
/**
* Set the stroke color.
* @param {ol.expr.Expression} strokeColor Stroke color.
@@ -156,6 +159,16 @@ ol.style.Line.prototype.setStrokeColor = function(strokeColor) {
};
/**
* Set the stroke opacity.
* @param {ol.expr.Expression} strokeOpacity Stroke opacity.
*/
ol.style.Line.prototype.setStrokeOpacity = function(strokeOpacity) {
goog.asserts.assertInstanceof(strokeOpacity, ol.expr.Expression);
this.strokeOpacity_ = strokeOpacity;
};
/**
* Set the stroke width.
* @param {ol.expr.Expression} strokeWidth Stroke width.
@@ -166,21 +179,11 @@ ol.style.Line.prototype.setStrokeWidth = function(strokeWidth) {
};
/**
* Set the stroke opacity.
* @param {ol.expr.Expression} opacity Stroke opacity.
*/
ol.style.Line.prototype.setOpacity = function(opacity) {
goog.asserts.assertInstanceof(opacity, ol.expr.Expression);
this.opacity_ = opacity;
};
/**
* @type {ol.style.LineLiteral}
*/
ol.style.LineDefaults = new ol.style.LineLiteral({
strokeColor: '#696969',
strokeWidth: 1.5,
opacity: 0.75
strokeOpacity: 0.75,
strokeWidth: 1.5
});

View File

@@ -182,7 +182,7 @@ describe('ol.parser.kml', function() {
var symbolizer = obj.features[0].getSymbolizerLiterals()[0];
expect(symbolizer instanceof ol.style.LineLiteral).to.be.ok();
expect(symbolizer.strokeColor).to.eql('#ff0000');
expect(symbolizer.opacity).to.eql(0.5294117647058824);
expect(symbolizer.strokeOpacity).to.eql(0.5294117647058824);
expect(symbolizer.strokeWidth).to.eql(10);
});
it('Test style fill (read / write)', function() {

View File

@@ -8,17 +8,17 @@ describe('ol.style.LineLiteral', function() {
var literal = new ol.style.LineLiteral({
strokeWidth: 3,
strokeColor: '#BADA55',
opacity: 1
strokeOpacity: 1
});
var equalLiteral = new ol.style.LineLiteral({
strokeColor: '#BADA55',
strokeWidth: 3,
opacity: 1
strokeOpacity: 1
});
var differentLiteral = new ol.style.LineLiteral({
strokeColor: '#013',
strokeWidth: 3,
opacity: 1
strokeOpacity: 1
});
expect(literal.equals(equalLiteral)).to.be(true);
expect(literal.equals(differentLiteral)).to.be(false);
@@ -42,7 +42,7 @@ describe('ol.style.Line', function() {
it('accepts expressions', function() {
var symbolizer = new ol.style.Line({
opacity: ol.expr.parse('value / 100'),
strokeOpacity: ol.expr.parse('value / 100'),
strokeWidth: ol.expr.parse('widthAttr')
});
expect(symbolizer).to.be.a(ol.style.Line);
@@ -54,7 +54,7 @@ describe('ol.style.Line', function() {
it('evaluates expressions with the given feature', function() {
var symbolizer = new ol.style.Line({
opacity: ol.expr.parse('value / 100'),
strokeOpacity: ol.expr.parse('value / 100'),
strokeWidth: ol.expr.parse('widthAttr')
});
@@ -65,7 +65,7 @@ describe('ol.style.Line', function() {
var literal = symbolizer.createLiteral(feature);
expect(literal).to.be.a(ol.style.LineLiteral);
expect(literal.opacity).to.be(42 / 100);
expect(literal.strokeOpacity).to.be(42 / 100);
expect(literal.strokeWidth).to.be(1.5);
});
@@ -99,14 +99,14 @@ describe('ol.style.Line', function() {
});
describe('#getOpacity()', function() {
describe('#getStrokeOpacity()', function() {
it('returns the stroke opacity', function() {
var symbolizer = new ol.style.Line({
opacity: 0.123
strokeOpacity: 0.123
});
var opacity = symbolizer.getOpacity();
var opacity = symbolizer.getStrokeOpacity();
expect(opacity).to.be.a(ol.expr.Literal);
expect(opacity.getValue()).to.be(0.123);
});
@@ -168,26 +168,26 @@ describe('ol.style.Line', function() {
});
describe('#setOpacity()', function() {
describe('#setStrokeOpacity()', function() {
it('sets the stroke opacity', function() {
var symbolizer = new ol.style.Line({
opacity: 0.123
strokeOpacity: 0.123
});
symbolizer.setOpacity(new ol.expr.Literal(0.321));
symbolizer.setStrokeOpacity(new ol.expr.Literal(0.321));
var opacity = symbolizer.getOpacity();
var opacity = symbolizer.getStrokeOpacity();
expect(opacity).to.be.a(ol.expr.Literal);
expect(opacity.getValue()).to.be(0.321);
});
it('throws when not provided an expression', function() {
var symbolizer = new ol.style.Line({
opacity: 1
strokeOpacity: 1
});
expect(function() {
symbolizer.setOpacity(0.5);
symbolizer.setStrokeOpacity(0.5);
}).throwException(function(err) {
expect(err).to.be.a(goog.asserts.AssertionError);
});