Getters and setters for shape symbolizers
This commit is contained in:
@@ -226,6 +226,119 @@ ol.style.Shape.prototype.createLiteral = function(opt_feature) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the fill color.
|
||||
* @return {ol.expr.Expression} Fill color.
|
||||
*/
|
||||
ol.style.Shape.prototype.getFillColor = function() {
|
||||
return this.fillColor_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the opacity.
|
||||
* @return {ol.expr.Expression} Opacity.
|
||||
*/
|
||||
ol.style.Shape.prototype.getOpacity = function() {
|
||||
return this.opacity_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the shape size.
|
||||
* @return {ol.expr.Expression} Shape size.
|
||||
*/
|
||||
ol.style.Shape.prototype.getSize = function() {
|
||||
return this.size_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the stroke color.
|
||||
* @return {ol.expr.Expression} Stroke color.
|
||||
*/
|
||||
ol.style.Shape.prototype.getStrokeColor = function() {
|
||||
return this.strokeColor_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the stroke width.
|
||||
* @return {ol.expr.Expression} Stroke width.
|
||||
*/
|
||||
ol.style.Shape.prototype.getStrokeWidth = function() {
|
||||
return this.strokeWidth_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the shape type.
|
||||
* @return {ol.style.ShapeType} Shape type.
|
||||
*/
|
||||
ol.style.Shape.prototype.getType = function() {
|
||||
return this.type_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the fill color.
|
||||
* @param {ol.expr.Expression} fillColor Fill color.
|
||||
*/
|
||||
ol.style.Shape.prototype.setFillColor = function(fillColor) {
|
||||
goog.asserts.assertInstanceof(fillColor, ol.expr.Expression);
|
||||
this.fillColor_ = fillColor;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the opacity.
|
||||
* @param {ol.expr.Expression} opacity Opacity.
|
||||
*/
|
||||
ol.style.Shape.prototype.setOpacity = function(opacity) {
|
||||
goog.asserts.assertInstanceof(opacity, ol.expr.Expression);
|
||||
this.opacity_ = opacity;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the shape size.
|
||||
* @param {ol.expr.Expression} size Shape size.
|
||||
*/
|
||||
ol.style.Shape.prototype.setSize = function(size) {
|
||||
goog.asserts.assertInstanceof(size, ol.expr.Expression);
|
||||
this.size_ = size;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the stroke color.
|
||||
* @param {ol.expr.Expression} strokeColor Stroke color.
|
||||
*/
|
||||
ol.style.Shape.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.Shape.prototype.setStrokeWidth = function(strokeWidth) {
|
||||
goog.asserts.assertInstanceof(strokeWidth, ol.expr.Expression);
|
||||
this.strokeWidth_ = strokeWidth;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the shape type.
|
||||
* @param {ol.style.ShapeType} type Shape type.
|
||||
*/
|
||||
ol.style.Shape.prototype.setType = function(type) {
|
||||
this.type_ = type;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {ol.style.ShapeLiteral}
|
||||
*/
|
||||
|
||||
@@ -117,10 +117,210 @@ describe('ol.style.Shape', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#getFillColor()', function() {
|
||||
|
||||
it('returns the fill color', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
fillColor: '#ff0000'
|
||||
});
|
||||
|
||||
var fillColor = symbolizer.getFillColor();
|
||||
expect(fillColor).to.be.a(ol.expr.Literal);
|
||||
expect(fillColor.getValue()).to.be('#ff0000');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getStrokeColor()', function() {
|
||||
|
||||
it('returns the stroke color', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
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.Shape({
|
||||
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.Shape({
|
||||
strokeWidth: 1,
|
||||
opacity: 0.123
|
||||
});
|
||||
|
||||
var opacity = symbolizer.getOpacity();
|
||||
expect(opacity).to.be.a(ol.expr.Literal);
|
||||
expect(opacity.getValue()).to.be(0.123);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getType()', function() {
|
||||
|
||||
it('returns the shape type', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
strokeWidth: 1,
|
||||
opacity: 0.123
|
||||
});
|
||||
|
||||
var type = symbolizer.getType();
|
||||
expect(type).to.be(ol.style.ShapeType.CIRCLE);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setFillColor()', function() {
|
||||
|
||||
it('sets the fill color', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
fillColor: '#ff0000'
|
||||
});
|
||||
|
||||
symbolizer.setFillColor(new ol.expr.Literal('#0000ff'));
|
||||
|
||||
var fillColor = symbolizer.getFillColor();
|
||||
expect(fillColor).to.be.a(ol.expr.Literal);
|
||||
expect(fillColor.getValue()).to.be('#0000ff');
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
fillColor: '#ff0000'
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setFillColor('#0000ff');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setStrokeColor()', function() {
|
||||
|
||||
it('sets the stroke color', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
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.Shape({
|
||||
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.Shape({
|
||||
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.Shape({
|
||||
strokeWidth: 10
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setStrokeWidth(10);
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setType()', function() {
|
||||
|
||||
it('sets the shape type', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
strokeWidth: 1,
|
||||
opacity: 0.123
|
||||
});
|
||||
symbolizer.setType(ol.style.ShapeType.CIRCLE);
|
||||
|
||||
var type = symbolizer.getType();
|
||||
expect(type).to.be(ol.style.ShapeType.CIRCLE);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setOpacity()', function() {
|
||||
|
||||
it('sets the stroke opacity', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
strokeWidth: 1,
|
||||
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.Shape({
|
||||
strokeWidth: 1,
|
||||
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.Shape');
|
||||
goog.require('ol.style.ShapeLiteral');
|
||||
goog.require('ol.style.ShapeType');
|
||||
|
||||
Reference in New Issue
Block a user