Getters and setters for line symbolizers
This commit is contained in:
@@ -119,6 +119,63 @@ ol.style.Line.prototype.createLiteral = function(opt_feature) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the stroke color.
|
||||
* @return {ol.expr.Expression} Stroke color.
|
||||
*/
|
||||
ol.style.Line.prototype.getStrokeColor = function() {
|
||||
return this.strokeColor_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the stroke width.
|
||||
* @return {ol.expr.Expression} Stroke width.
|
||||
*/
|
||||
ol.style.Line.prototype.getStrokeWidth = function() {
|
||||
return this.strokeWidth_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
ol.style.Line.prototype.setStrokeColor = function(strokeColor) {
|
||||
goog.asserts.assertInstanceof(strokeColor, ol.expr.Expression);
|
||||
this.strokeColor_ = strokeColor;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the stroke width.
|
||||
* @param {ol.expr.Expression} strokeWidth Stroke width.
|
||||
*/
|
||||
ol.style.Line.prototype.setStrokeWidth = function(strokeWidth) {
|
||||
goog.asserts.assertInstanceof(strokeWidth, ol.expr.Expression);
|
||||
this.strokeWidth_ = 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}
|
||||
*/
|
||||
|
||||
@@ -71,9 +71,136 @@ describe('ol.style.Line', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#getStrokeColor()', function() {
|
||||
|
||||
it('returns the stroke color', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
strokeColor: '#ff0000'
|
||||
});
|
||||
|
||||
var strokeColor = symbolizer.getStrokeColor();
|
||||
expect(strokeColor).to.be.a(ol.expr.Literal);
|
||||
expect(strokeColor.getValue()).to.be('#ff0000');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getStrokeWidth()', function() {
|
||||
|
||||
it('returns the stroke width', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
strokeWidth: 10
|
||||
});
|
||||
|
||||
var strokeWidth = symbolizer.getStrokeWidth();
|
||||
expect(strokeWidth).to.be.a(ol.expr.Literal);
|
||||
expect(strokeWidth.getValue()).to.be(10);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getOpacity()', function() {
|
||||
|
||||
it('returns the stroke opacity', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
opacity: 0.123
|
||||
});
|
||||
|
||||
var opacity = symbolizer.getOpacity();
|
||||
expect(opacity).to.be.a(ol.expr.Literal);
|
||||
expect(opacity.getValue()).to.be(0.123);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setStrokeColor()', function() {
|
||||
|
||||
it('sets the stroke color', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
strokeColor: '#ff0000'
|
||||
});
|
||||
|
||||
symbolizer.setStrokeColor(new ol.expr.Literal('#0000ff'));
|
||||
|
||||
var strokeColor = symbolizer.getStrokeColor();
|
||||
expect(strokeColor).to.be.a(ol.expr.Literal);
|
||||
expect(strokeColor.getValue()).to.be('#0000ff');
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
strokeColor: '#ff0000'
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setStrokeColor('#0000ff');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setStrokeWidth()', function() {
|
||||
|
||||
it('sets the stroke width', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
strokeWidth: 10
|
||||
});
|
||||
symbolizer.setStrokeWidth(new ol.expr.Literal(20));
|
||||
|
||||
var strokeWidth = symbolizer.getStrokeWidth();
|
||||
expect(strokeWidth).to.be.a(ol.expr.Literal);
|
||||
expect(strokeWidth.getValue()).to.be(20);
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
strokeWidth: 10
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setStrokeWidth(10);
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setOpacity()', function() {
|
||||
|
||||
it('sets the stroke opacity', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
opacity: 0.123
|
||||
});
|
||||
symbolizer.setOpacity(new ol.expr.Literal(0.321));
|
||||
|
||||
var opacity = symbolizer.getOpacity();
|
||||
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
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setOpacity(0.5);
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.asserts.AssertionError');
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.style.Line');
|
||||
goog.require('ol.style.LineLiteral');
|
||||
|
||||
Reference in New Issue
Block a user