Rename line symbolizer opacity to strokeOpacity for consistency
We already have strokeColor and strokeWidth. Having strokeOpacity makes sense.
This commit is contained in:
@@ -21,7 +21,7 @@ var style = new ol.style.Style({rules: [
|
|||||||
new ol.style.Line({
|
new ol.style.Line({
|
||||||
strokeColor: ol.expr.parse('color'),
|
strokeColor: ol.expr.parse('color'),
|
||||||
strokeWidth: 4,
|
strokeWidth: 4,
|
||||||
opacity: 1
|
strokeOpacity: 1
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
@@ -31,12 +31,12 @@ var style = new ol.style.Style({rules: [
|
|||||||
new ol.style.Line({
|
new ol.style.Line({
|
||||||
strokeColor: '#013',
|
strokeColor: '#013',
|
||||||
strokeWidth: 4,
|
strokeWidth: 4,
|
||||||
opacity: 1
|
strokeOpacity: 1
|
||||||
}),
|
}),
|
||||||
new ol.style.Line({
|
new ol.style.Line({
|
||||||
strokeColor: ol.expr.parse('color'),
|
strokeColor: ol.expr.parse('color'),
|
||||||
strokeWidth: 2,
|
strokeWidth: 2,
|
||||||
opacity: 1
|
strokeOpacity: 1
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -580,9 +580,10 @@
|
|||||||
* @typedef {Object} ol.style.LineOptions
|
* @typedef {Object} ol.style.LineOptions
|
||||||
* @property {string|ol.expr.Expression|undefined} strokeColor Stroke
|
* @property {string|ol.expr.Expression|undefined} strokeColor Stroke
|
||||||
* color as hex color code.
|
* color as hex color code.
|
||||||
|
* @property {number|ol.expr.Expression|undefined} strokeOpacity Stroke
|
||||||
|
* opacity (0-1).
|
||||||
* @property {number|ol.expr.Expression|undefined} strokeWidth Stroke
|
* @property {number|ol.expr.Expression|undefined} strokeWidth Stroke
|
||||||
* width in pixels.
|
* width in pixels.
|
||||||
* @property {number|ol.expr.Expression|undefined} opacity Opacity (0-1).
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -342,7 +342,7 @@ ol.parser.KML = function(opt_options) {
|
|||||||
this.readChildNodes(node, symbolizer);
|
this.readChildNodes(node, symbolizer);
|
||||||
if (symbolizer.color) {
|
if (symbolizer.color) {
|
||||||
symbolizer.strokeColor = symbolizer.color.color;
|
symbolizer.strokeColor = symbolizer.color.color;
|
||||||
symbolizer.opacity = symbolizer.color.opacity;
|
symbolizer.strokeOpacity = symbolizer.color.opacity;
|
||||||
}
|
}
|
||||||
if (symbolizer.width) {
|
if (symbolizer.width) {
|
||||||
symbolizer.strokeWidth = parseFloat(symbolizer.width);
|
symbolizer.strokeWidth = parseFloat(symbolizer.width);
|
||||||
@@ -657,7 +657,7 @@ ol.parser.KML = function(opt_options) {
|
|||||||
symbolizer : symbolizer.createLiteral();
|
symbolizer : symbolizer.createLiteral();
|
||||||
this.writeNode('color', {
|
this.writeNode('color', {
|
||||||
color: literal.strokeColor.substring(1),
|
color: literal.strokeColor.substring(1),
|
||||||
opacity: literal.opacity
|
opacity: literal.strokeOpacity
|
||||||
}, null, node);
|
}, null, node);
|
||||||
this.writeNode('width', literal.strokeWidth, null, node);
|
this.writeNode('width', literal.strokeWidth, null, node);
|
||||||
return node;
|
return node;
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ ol.renderer.canvas.VectorRenderer.prototype.renderLineStringFeatures_ =
|
|||||||
i, ii, feature, id, currentSize, geometry, components, j, jj, line, dim,
|
i, ii, feature, id, currentSize, geometry, components, j, jj, line, dim,
|
||||||
k, kk, vec, strokeSize;
|
k, kk, vec, strokeSize;
|
||||||
|
|
||||||
context.globalAlpha = symbolizer.opacity;
|
context.globalAlpha = symbolizer.strokeOpacity;
|
||||||
context.strokeStyle = symbolizer.strokeColor;
|
context.strokeStyle = symbolizer.strokeColor;
|
||||||
context.lineWidth = symbolizer.strokeWidth;
|
context.lineWidth = symbolizer.strokeWidth;
|
||||||
context.lineCap = 'round'; // TODO: accept this as a symbolizer property
|
context.lineCap = 'round'; // TODO: accept this as a symbolizer property
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ goog.require('ol.style.SymbolizerLiteral');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{strokeColor: (string),
|
* @typedef {{strokeColor: (string),
|
||||||
* strokeWidth: (number),
|
* strokeOpacity: (number),
|
||||||
* opacity: (number)}}
|
* strokeWidth: (number)}}
|
||||||
*/
|
*/
|
||||||
ol.style.LineLiteralOptions;
|
ol.style.LineLiteralOptions;
|
||||||
|
|
||||||
@@ -31,15 +31,16 @@ ol.style.LineLiteral = function(options) {
|
|||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
this.strokeColor = options.strokeColor;
|
this.strokeColor = options.strokeColor;
|
||||||
|
|
||||||
|
goog.asserts.assertNumber(
|
||||||
|
options.strokeOpacity, 'strokeOpacity must be a number');
|
||||||
|
/** @type {number} */
|
||||||
|
this.strokeOpacity = options.strokeOpacity;
|
||||||
|
|
||||||
goog.asserts.assertNumber(
|
goog.asserts.assertNumber(
|
||||||
options.strokeWidth, 'strokeWidth must be a number');
|
options.strokeWidth, 'strokeWidth must be a number');
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
this.strokeWidth = options.strokeWidth;
|
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);
|
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) {
|
ol.style.LineLiteral.prototype.equals = function(lineLiteral) {
|
||||||
return this.strokeColor == lineLiteral.strokeColor &&
|
return this.strokeColor == lineLiteral.strokeColor &&
|
||||||
this.strokeWidth == lineLiteral.strokeWidth &&
|
this.strokeOpacity == lineLiteral.strokeOpacity &&
|
||||||
this.opacity == lineLiteral.opacity;
|
this.strokeWidth == lineLiteral.strokeWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -76,19 +77,19 @@ ol.style.Line = function(options) {
|
|||||||
* @type {ol.expr.Expression}
|
* @type {ol.expr.Expression}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.strokeWidth_ = !goog.isDef(options.strokeWidth) ?
|
this.strokeOpacity_ = !goog.isDef(options.strokeOpacity) ?
|
||||||
new ol.expr.Literal(ol.style.LineDefaults.strokeWidth) :
|
new ol.expr.Literal(ol.style.LineDefaults.strokeOpacity) :
|
||||||
(options.strokeWidth instanceof ol.expr.Expression) ?
|
(options.strokeOpacity instanceof ol.expr.Expression) ?
|
||||||
options.strokeWidth : new ol.expr.Literal(options.strokeWidth);
|
options.strokeOpacity : new ol.expr.Literal(options.strokeOpacity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {ol.expr.Expression}
|
* @type {ol.expr.Expression}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.opacity_ = !goog.isDef(options.opacity) ?
|
this.strokeWidth_ = !goog.isDef(options.strokeWidth) ?
|
||||||
new ol.expr.Literal(ol.style.LineDefaults.opacity) :
|
new ol.expr.Literal(ol.style.LineDefaults.strokeWidth) :
|
||||||
(options.opacity instanceof ol.expr.Expression) ?
|
(options.strokeWidth instanceof ol.expr.Expression) ?
|
||||||
options.opacity : new ol.expr.Literal(options.opacity);
|
options.strokeWidth : new ol.expr.Literal(options.strokeWidth);
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.style.Line, ol.style.Symbolizer);
|
goog.inherits(ol.style.Line, ol.style.Symbolizer);
|
||||||
@@ -104,17 +105,19 @@ ol.style.Line.prototype.createLiteral = function(opt_feature) {
|
|||||||
this.strokeColor_, opt_feature);
|
this.strokeColor_, opt_feature);
|
||||||
goog.asserts.assertString(strokeColor, 'strokeColor must be a string');
|
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(
|
var strokeWidth = ol.expr.evaluateFeature(
|
||||||
this.strokeWidth_, opt_feature);
|
this.strokeWidth_, opt_feature);
|
||||||
goog.asserts.assertNumber(strokeWidth, 'strokeWidth must be a number');
|
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({
|
return new ol.style.LineLiteral({
|
||||||
strokeColor: strokeColor,
|
strokeColor: strokeColor,
|
||||||
strokeWidth: strokeWidth,
|
strokeOpacity: strokeOpacity,
|
||||||
opacity: opacity
|
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.
|
* Get the stroke width.
|
||||||
* @return {ol.expr.Expression} 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.
|
* Set the stroke color.
|
||||||
* @param {ol.expr.Expression} strokeColor 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.
|
* Set the stroke width.
|
||||||
* @param {ol.expr.Expression} strokeWidth 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}
|
* @type {ol.style.LineLiteral}
|
||||||
*/
|
*/
|
||||||
ol.style.LineDefaults = new ol.style.LineLiteral({
|
ol.style.LineDefaults = new ol.style.LineLiteral({
|
||||||
strokeColor: '#696969',
|
strokeColor: '#696969',
|
||||||
strokeWidth: 1.5,
|
strokeOpacity: 0.75,
|
||||||
opacity: 0.75
|
strokeWidth: 1.5
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ describe('ol.parser.kml', function() {
|
|||||||
var symbolizer = obj.features[0].getSymbolizerLiterals()[0];
|
var symbolizer = obj.features[0].getSymbolizerLiterals()[0];
|
||||||
expect(symbolizer instanceof ol.style.LineLiteral).to.be.ok();
|
expect(symbolizer instanceof ol.style.LineLiteral).to.be.ok();
|
||||||
expect(symbolizer.strokeColor).to.eql('#ff0000');
|
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);
|
expect(symbolizer.strokeWidth).to.eql(10);
|
||||||
});
|
});
|
||||||
it('Test style fill (read / write)', function() {
|
it('Test style fill (read / write)', function() {
|
||||||
|
|||||||
@@ -8,17 +8,17 @@ describe('ol.style.LineLiteral', function() {
|
|||||||
var literal = new ol.style.LineLiteral({
|
var literal = new ol.style.LineLiteral({
|
||||||
strokeWidth: 3,
|
strokeWidth: 3,
|
||||||
strokeColor: '#BADA55',
|
strokeColor: '#BADA55',
|
||||||
opacity: 1
|
strokeOpacity: 1
|
||||||
});
|
});
|
||||||
var equalLiteral = new ol.style.LineLiteral({
|
var equalLiteral = new ol.style.LineLiteral({
|
||||||
strokeColor: '#BADA55',
|
strokeColor: '#BADA55',
|
||||||
strokeWidth: 3,
|
strokeWidth: 3,
|
||||||
opacity: 1
|
strokeOpacity: 1
|
||||||
});
|
});
|
||||||
var differentLiteral = new ol.style.LineLiteral({
|
var differentLiteral = new ol.style.LineLiteral({
|
||||||
strokeColor: '#013',
|
strokeColor: '#013',
|
||||||
strokeWidth: 3,
|
strokeWidth: 3,
|
||||||
opacity: 1
|
strokeOpacity: 1
|
||||||
});
|
});
|
||||||
expect(literal.equals(equalLiteral)).to.be(true);
|
expect(literal.equals(equalLiteral)).to.be(true);
|
||||||
expect(literal.equals(differentLiteral)).to.be(false);
|
expect(literal.equals(differentLiteral)).to.be(false);
|
||||||
@@ -42,7 +42,7 @@ describe('ol.style.Line', function() {
|
|||||||
|
|
||||||
it('accepts expressions', function() {
|
it('accepts expressions', function() {
|
||||||
var symbolizer = new ol.style.Line({
|
var symbolizer = new ol.style.Line({
|
||||||
opacity: ol.expr.parse('value / 100'),
|
strokeOpacity: ol.expr.parse('value / 100'),
|
||||||
strokeWidth: ol.expr.parse('widthAttr')
|
strokeWidth: ol.expr.parse('widthAttr')
|
||||||
});
|
});
|
||||||
expect(symbolizer).to.be.a(ol.style.Line);
|
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() {
|
it('evaluates expressions with the given feature', function() {
|
||||||
var symbolizer = new ol.style.Line({
|
var symbolizer = new ol.style.Line({
|
||||||
opacity: ol.expr.parse('value / 100'),
|
strokeOpacity: ol.expr.parse('value / 100'),
|
||||||
strokeWidth: ol.expr.parse('widthAttr')
|
strokeWidth: ol.expr.parse('widthAttr')
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ describe('ol.style.Line', function() {
|
|||||||
|
|
||||||
var literal = symbolizer.createLiteral(feature);
|
var literal = symbolizer.createLiteral(feature);
|
||||||
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.strokeOpacity).to.be(42 / 100);
|
||||||
expect(literal.strokeWidth).to.be(1.5);
|
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() {
|
it('returns the stroke opacity', function() {
|
||||||
var symbolizer = new ol.style.Line({
|
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).to.be.a(ol.expr.Literal);
|
||||||
expect(opacity.getValue()).to.be(0.123);
|
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() {
|
it('sets the stroke opacity', function() {
|
||||||
var symbolizer = new ol.style.Line({
|
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).to.be.a(ol.expr.Literal);
|
||||||
expect(opacity.getValue()).to.be(0.321);
|
expect(opacity.getValue()).to.be(0.321);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws when not provided an expression', function() {
|
it('throws when not provided an expression', function() {
|
||||||
var symbolizer = new ol.style.Line({
|
var symbolizer = new ol.style.Line({
|
||||||
opacity: 1
|
strokeOpacity: 1
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
symbolizer.setOpacity(0.5);
|
symbolizer.setStrokeOpacity(0.5);
|
||||||
}).throwException(function(err) {
|
}).throwException(function(err) {
|
||||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user