Skip to content

Commit

Permalink
Rename line symbolizer opacity to strokeOpacity for consistency
Browse files Browse the repository at this point in the history
We already have strokeColor and strokeWidth.  Having strokeOpacity makes sense.
  • Loading branch information
tschaub committed Aug 5, 2013
1 parent 1cedea6 commit f210d6d
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 63 deletions.
6 changes: 3 additions & 3 deletions examples/style-rules.js
Expand Up @@ -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
})
]
}),
Expand All @@ -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
})
]
}),
Expand Down
3 changes: 2 additions & 1 deletion src/objectliterals.jsdoc
Expand Up @@ -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).
*/

/**
Expand Down
4 changes: 2 additions & 2 deletions src/ol/parser/kml.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/ol/renderer/canvas/canvasvectorrenderer.js
Expand Up @@ -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
Expand Down
83 changes: 43 additions & 40 deletions src/ol/style/line.js
Expand Up @@ -11,8 +11,8 @@ goog.require('ol.style.SymbolizerLiteral');

/**
* @typedef {{strokeColor: (string),
* strokeWidth: (number),
* opacity: (number)}}
* strokeOpacity: (number),
* strokeWidth: (number)}}
*/
ol.style.LineLiteralOptions;

Expand All @@ -32,13 +32,14 @@ ol.style.LineLiteral = function(options) {
this.strokeColor = options.strokeColor;

goog.asserts.assertNumber(
options.strokeWidth, 'strokeWidth must be a number');
options.strokeOpacity, 'strokeOpacity must be a number');
/** @type {number} */
this.strokeWidth = options.strokeWidth;
this.strokeOpacity = options.strokeOpacity;

goog.asserts.assertNumber(options.opacity, 'opacity must be a number');
goog.asserts.assertNumber(
options.strokeWidth, 'strokeWidth must be a number');
/** @type {number} */
this.opacity = options.opacity;
this.strokeWidth = options.strokeWidth;

};
goog.inherits(ol.style.LineLiteral, ol.style.SymbolizerLiteral);
Expand All @@ -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;
};


Expand All @@ -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);
Expand All @@ -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
});
};

Expand All @@ -129,20 +132,20 @@ ol.style.Line.prototype.getStrokeColor = function() {


/**
* Get the stroke width.
* @return {ol.expr.Expression} Stroke width.
* Get the stroke opacity.
* @return {ol.expr.Expression} Stroke opacity.
*/
ol.style.Line.prototype.getStrokeWidth = function() {
return this.strokeWidth_;
ol.style.Line.prototype.getStrokeOpacity = function() {
return this.strokeOpacity_;
};


/**
* Get the stroke opacity.
* @return {ol.expr.Expression} Stroke opacity.
* Get the stroke width.
* @return {ol.expr.Expression} Stroke width.
*/
ol.style.Line.prototype.getOpacity = function() {
return this.opacity_;
ol.style.Line.prototype.getStrokeWidth = function() {
return this.strokeWidth_;
};


Expand All @@ -157,22 +160,22 @@ ol.style.Line.prototype.setStrokeColor = function(strokeColor) {


/**
* Set the stroke width.
* @param {ol.expr.Expression} strokeWidth Stroke width.
* Set the stroke opacity.
* @param {ol.expr.Expression} strokeOpacity Stroke opacity.
*/
ol.style.Line.prototype.setStrokeWidth = function(strokeWidth) {
goog.asserts.assertInstanceof(strokeWidth, ol.expr.Expression);
this.strokeWidth_ = strokeWidth;
ol.style.Line.prototype.setStrokeOpacity = function(strokeOpacity) {
goog.asserts.assertInstanceof(strokeOpacity, ol.expr.Expression);
this.strokeOpacity_ = strokeOpacity;
};


/**
* Set the stroke opacity.
* @param {ol.expr.Expression} opacity Stroke opacity.
* Set the stroke width.
* @param {ol.expr.Expression} strokeWidth Stroke width.
*/
ol.style.Line.prototype.setOpacity = function(opacity) {
goog.asserts.assertInstanceof(opacity, ol.expr.Expression);
this.opacity_ = opacity;
ol.style.Line.prototype.setStrokeWidth = function(strokeWidth) {
goog.asserts.assertInstanceof(strokeWidth, ol.expr.Expression);
this.strokeWidth_ = strokeWidth;
};


Expand All @@ -181,6 +184,6 @@ ol.style.Line.prototype.setOpacity = function(opacity) {
*/
ol.style.LineDefaults = new ol.style.LineLiteral({
strokeColor: '#696969',
strokeWidth: 1.5,
opacity: 0.75
strokeOpacity: 0.75,
strokeWidth: 1.5
});
2 changes: 1 addition & 1 deletion test/spec/ol/parser/kml.test.js
Expand Up @@ -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() {
Expand Down
30 changes: 15 additions & 15 deletions test/spec/ol/style/line.test.js
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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')
});

Expand All @@ -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);
});

Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down

0 comments on commit f210d6d

Please sign in to comment.