Line literal color instead of strokeColor etc.

This commit is contained in:
Tim Schaub
2013-08-15 09:55:10 -04:00
parent a5991aee03
commit 6078fe7b02
9 changed files with 58 additions and 46 deletions
+3 -3
View File
@@ -668,10 +668,10 @@ ol.parser.KML = function(opt_options) {
var literal = obj.symbolizer.createLiteral( var literal = obj.symbolizer.createLiteral(
ol.geom.GeometryType.LINESTRING); ol.geom.GeometryType.LINESTRING);
this.writeNode('color', { this.writeNode('color', {
color: literal.strokeColor.substring(1), color: literal.color.substring(1),
opacity: literal.strokeOpacity opacity: literal.opacity
}, null, node); }, null, node);
this.writeNode('width', literal.strokeWidth, null, node); this.writeNode('width', literal.width, null, node);
return node; return node;
}, },
'color': function(colorObj) { 'color': function(colorObj) {
@@ -153,9 +153,9 @@ 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.strokeOpacity; context.globalAlpha = symbolizer.opacity;
context.strokeStyle = symbolizer.strokeColor; context.strokeStyle = symbolizer.color;
context.lineWidth = symbolizer.strokeWidth; context.lineWidth = symbolizer.width;
context.lineCap = 'round'; // TODO: accept this as a symbolizer property context.lineCap = 'round'; // TODO: accept this as a symbolizer property
context.lineJoin = 'round'; // TODO: accept this as a symbolizer property context.lineJoin = 'round'; // TODO: accept this as a symbolizer property
strokeSize = context.lineWidth * this.inverseScale_; strokeSize = context.lineWidth * this.inverseScale_;
+12 -12
View File
@@ -5,9 +5,9 @@ goog.require('ol.style.Literal');
/** /**
* @typedef {{strokeColor: (string), * @typedef {{color: (string),
* strokeOpacity: (number), * opacity: (number),
* strokeWidth: (number)}} * width: (number)}}
*/ */
ol.style.LineLiteralOptions; ol.style.LineLiteralOptions;
@@ -22,19 +22,19 @@ ol.style.LineLiteral = function(options) {
goog.base(this); goog.base(this);
goog.asserts.assertString( goog.asserts.assertString(
options.strokeColor, 'strokeColor must be a string'); options.color, 'color must be a string');
/** @type {string} */ /** @type {string} */
this.strokeColor = options.strokeColor; this.color = options.color;
goog.asserts.assertNumber( goog.asserts.assertNumber(
options.strokeOpacity, 'strokeOpacity must be a number'); options.opacity, 'opacity must be a number');
/** @type {number} */ /** @type {number} */
this.strokeOpacity = options.strokeOpacity; this.opacity = options.opacity;
goog.asserts.assertNumber( goog.asserts.assertNumber(
options.strokeWidth, 'strokeWidth must be a number'); options.width, 'width must be a number');
/** @type {number} */ /** @type {number} */
this.strokeWidth = options.strokeWidth; this.width = options.width;
}; };
goog.inherits(ol.style.LineLiteral, ol.style.Literal); goog.inherits(ol.style.LineLiteral, ol.style.Literal);
@@ -44,7 +44,7 @@ goog.inherits(ol.style.LineLiteral, ol.style.Literal);
* @inheritDoc * @inheritDoc
*/ */
ol.style.LineLiteral.prototype.equals = function(lineLiteral) { ol.style.LineLiteral.prototype.equals = function(lineLiteral) {
return this.strokeColor == lineLiteral.strokeColor && return this.color == lineLiteral.color &&
this.strokeOpacity == lineLiteral.strokeOpacity && this.opacity == lineLiteral.opacity &&
this.strokeWidth == lineLiteral.strokeWidth; this.width == lineLiteral.width;
}; };
+3 -3
View File
@@ -82,9 +82,9 @@ ol.style.Stroke.prototype.createLiteral = function(featureOrType) {
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({
strokeColor: color, color: color,
strokeOpacity: opacity, opacity: opacity,
strokeWidth: width width: width
}); });
} else if (type === ol.geom.GeometryType.POLYGON || } else if (type === ol.geom.GeometryType.POLYGON ||
type === ol.geom.GeometryType.MULTIPOLYGON) { type === ol.geom.GeometryType.MULTIPOLYGON) {
+3 -3
View File
@@ -137,9 +137,9 @@ describe('ol.layer.Vector', function() {
var groups = layer.groupFeaturesBySymbolizerLiteral(features); var groups = layer.groupFeaturesBySymbolizerLiteral(features);
expect(groups.length).to.be(2); expect(groups.length).to.be(2);
expect(groups[0][0].length).to.be(1); expect(groups[0][0].length).to.be(1);
expect(groups[0][1].strokeColor).to.be('#BADA55'); expect(groups[0][1].color).to.be('#BADA55');
expect(groups[1][0].length).to.be(2); expect(groups[1][0].length).to.be(2);
expect(groups[1][1].strokeColor).to.be('#013'); expect(groups[1][1].color).to.be('#013');
}); });
it('groups equal symbolizers also when defined on features', function() { it('groups equal symbolizers also when defined on features', function() {
@@ -167,7 +167,7 @@ describe('ol.layer.Vector', function() {
var groups = layer.groupFeaturesBySymbolizerLiteral(features); var groups = layer.groupFeaturesBySymbolizerLiteral(features);
expect(groups).to.have.length(3); expect(groups).to.have.length(3);
expect(groups[2][0].length).to.be(2); expect(groups[2][0].length).to.be(2);
expect(groups[2][1].strokeWidth).to.be(3); expect(groups[2][1].width).to.be(3);
}); });
+3 -3
View File
@@ -189,9 +189,9 @@ describe('ol.parser.KML', function() {
var literal = stroke.createLiteral(ol.geom.GeometryType.LINESTRING); var literal = stroke.createLiteral(ol.geom.GeometryType.LINESTRING);
expect(literal).to.be.a(ol.style.LineLiteral); expect(literal).to.be.a(ol.style.LineLiteral);
expect(literal.strokeColor).to.eql('#ff0000'); expect(literal.color).to.eql('#ff0000');
expect(literal.strokeOpacity).to.eql(0.5294117647058824); expect(literal.opacity).to.eql(0.5294117647058824);
expect(literal.strokeWidth).to.eql(10); expect(literal.width).to.eql(10);
}); });
it('reads PolyStyle fill', function() { it('reads PolyStyle fill', function() {
+23 -11
View File
@@ -6,22 +6,34 @@ describe('ol.style.LineLiteral', function() {
it('identifies equal literals', function() { it('identifies equal literals', function() {
var literal = new ol.style.LineLiteral({ var literal = new ol.style.LineLiteral({
strokeWidth: 3, width: 3,
strokeColor: '#BADA55', color: '#BADA55',
strokeOpacity: 1 opacity: 1
}); });
var equalLiteral = new ol.style.LineLiteral({ var equalLiteral = new ol.style.LineLiteral({
strokeColor: '#BADA55', color: '#BADA55',
strokeWidth: 3, width: 3,
strokeOpacity: 1 opacity: 1
}); });
var differentLiteral = new ol.style.LineLiteral({ var differentColor = new ol.style.LineLiteral({
strokeColor: '#013', width: 3,
strokeWidth: 3, color: '#ff0000',
strokeOpacity: 1 opacity: 1
});
var differentWidth = new ol.style.LineLiteral({
width: 3.5,
color: '#BADA55',
opacity: 1
});
var differentOpacity = new ol.style.LineLiteral({
width: 3,
color: '#BADA55',
opacity: 0.5
}); });
expect(literal.equals(equalLiteral)).to.be(true); expect(literal.equals(equalLiteral)).to.be(true);
expect(literal.equals(differentLiteral)).to.be(false); expect(literal.equals(differentColor)).to.be(false);
expect(literal.equals(differentWidth)).to.be(false);
expect(literal.equals(differentOpacity)).to.be(false);
}); });
}); });
+5 -5
View File
@@ -38,8 +38,8 @@ describe('ol.style.Stroke', 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.strokeOpacity).to.be(42 / 100); expect(literal.opacity).to.be(42 / 100);
expect(literal.strokeWidth).to.be(1.5); expect(literal.width).to.be(1.5);
}); });
it('applies the default values', function() { it('applies the default values', function() {
@@ -47,9 +47,9 @@ describe('ol.style.Stroke', function() {
var literal = symbolizer.createLiteral(ol.geom.GeometryType.LINESTRING); var literal = symbolizer.createLiteral(ol.geom.GeometryType.LINESTRING);
expect(literal).to.be.a(ol.style.LineLiteral); expect(literal).to.be.a(ol.style.LineLiteral);
expect(literal.strokeColor).to.be('#696969'); expect(literal.color).to.be('#696969');
expect(literal.strokeOpacity).to.be(0.75); expect(literal.opacity).to.be(0.75);
expect(literal.strokeWidth).to.be(1.5); expect(literal.width).to.be(1.5);
}); });
}); });
+3 -3
View File
@@ -65,9 +65,9 @@ describe('ol.style.Style', function() {
var literal = literals[0]; var literal = literals[0];
expect(literal).to.be.a(ol.style.LineLiteral); expect(literal).to.be.a(ol.style.LineLiteral);
expect(literal.strokeColor).to.be(ol.style.StrokeDefaults.color); expect(literal.color).to.be(ol.style.StrokeDefaults.color);
expect(literal.strokeOpacity).to.be(ol.style.StrokeDefaults.opacity); expect(literal.opacity).to.be(ol.style.StrokeDefaults.opacity);
expect(literal.strokeWidth).to.be(ol.style.StrokeDefaults.width); expect(literal.width).to.be(ol.style.StrokeDefaults.width);
}); });
it('returns an array with the Polygon default for polygons', function() { it('returns an array with the Polygon default for polygons', function() {