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

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