Move vector code out of the way
This commit is contained in:
@@ -1,246 +0,0 @@
|
||||
goog.provide('ol.test.style.Fill');
|
||||
|
||||
describe('ol.style.Fill', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('accepts literal values', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#BADA55'
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Fill);
|
||||
});
|
||||
|
||||
it('accepts expressions', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
opacity: ol.expr.parse('value / 100'),
|
||||
color: ol.expr.parse('fillAttr')
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Fill);
|
||||
});
|
||||
|
||||
it('accepts zIndex', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
opacity: ol.expr.parse('value / 100'),
|
||||
color: ol.expr.parse('fillAttr'),
|
||||
zIndex: 3
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Fill);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#createLiteral()', function() {
|
||||
|
||||
it('evaluates expressions with the given feature', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
opacity: ol.expr.parse('value / 100'),
|
||||
color: ol.expr.parse('fillAttr')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
value: 42,
|
||||
fillAttr: '#ff0000',
|
||||
geometry: new ol.geom.Polygon(
|
||||
[[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.fillOpacity).to.be(42 / 100);
|
||||
expect(literal.fillColor).to.be('#ff0000');
|
||||
expect(literal.zIndex).to.be(0);
|
||||
});
|
||||
|
||||
it('applies default opacity', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POLYGON);
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.fillColor).to.be('#ff0000');
|
||||
expect(literal.fillOpacity).to.be(0.4);
|
||||
});
|
||||
|
||||
it('applies default color', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
opacity: 0.8
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POLYGON);
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.fillColor).to.be('#ffffff');
|
||||
expect(literal.fillOpacity).to.be(0.8);
|
||||
});
|
||||
|
||||
it('casts opacity to number', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
opacity: ol.expr.parse('opacity'),
|
||||
color: '#ff00ff'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
opacity: '0.55',
|
||||
geometry: new ol.geom.Polygon(
|
||||
[[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.fillOpacity).to.be(0.55);
|
||||
});
|
||||
|
||||
it('handles zIndex', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
opacity: 0.8,
|
||||
zIndex: 2
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POLYGON);
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.fillColor).to.be('#ffffff');
|
||||
expect(literal.fillOpacity).to.be(0.8);
|
||||
expect(literal.zIndex).to.be(2);
|
||||
});
|
||||
|
||||
it('applies default zIndex', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
opacity: 0.8
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POLYGON);
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.zIndex).to.be(0);
|
||||
});
|
||||
|
||||
it('casts zIndex to number', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
zIndex: ol.expr.parse('zIndex'),
|
||||
color: '#ff00ff'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
zIndex: '11',
|
||||
geometry: new ol.geom.Polygon(
|
||||
[[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.zIndex).to.be(11);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getColor()', function() {
|
||||
|
||||
it('returns the fill color', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
var color = symbolizer.getColor();
|
||||
expect(color).to.be.a(ol.expr.Literal);
|
||||
expect(color.getValue()).to.be('#ff0000');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getOpacity()', function() {
|
||||
|
||||
it('returns the fill opacity', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#ffffff',
|
||||
opacity: 0.123
|
||||
});
|
||||
|
||||
var opacity = symbolizer.getOpacity();
|
||||
expect(opacity).to.be.a(ol.expr.Literal);
|
||||
expect(opacity.getValue()).to.be(0.123);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getZIndex()', function() {
|
||||
|
||||
it('returns the zIndex', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#ffffff',
|
||||
zIndex: 11
|
||||
});
|
||||
|
||||
var zIndex = symbolizer.getZIndex();
|
||||
expect(zIndex).to.be.a(ol.expr.Literal);
|
||||
expect(zIndex.getValue()).to.be(11);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setColor()', function() {
|
||||
|
||||
it('sets the fill color', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
symbolizer.setColor(new ol.expr.Literal('#0000ff'));
|
||||
|
||||
var color = symbolizer.getColor();
|
||||
expect(color).to.be.a(ol.expr.Literal);
|
||||
expect(color.getValue()).to.be('#0000ff');
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setColor('#0000ff');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setOpacity()', function() {
|
||||
|
||||
it('sets the fill opacity', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
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.Fill({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setOpacity(0.123);
|
||||
}).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.geom.GeometryType');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.PolygonLiteral');
|
||||
@@ -1,87 +0,0 @@
|
||||
goog.provide('ol.test.style.IconLiteral');
|
||||
|
||||
describe('ol.style.IconLiteral', function() {
|
||||
|
||||
describe('#equals()', function() {
|
||||
|
||||
it('identifies equal literals', function() {
|
||||
var literal = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png',
|
||||
zIndex: 0
|
||||
});
|
||||
var equalLiteral = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png',
|
||||
zIndex: 0
|
||||
});
|
||||
var differentHeight = new ol.style.IconLiteral({
|
||||
height: 11,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png',
|
||||
zIndex: 0
|
||||
});
|
||||
var differentWidth = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 2,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png',
|
||||
zIndex: 0
|
||||
});
|
||||
var differentOpacity = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 0.5,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png',
|
||||
zIndex: 0
|
||||
});
|
||||
var differentRotation = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.2,
|
||||
url: 'http://example.com/1.png',
|
||||
zIndex: 0
|
||||
});
|
||||
var differentUrl = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/2.png',
|
||||
zIndex: 0
|
||||
});
|
||||
var differentZIndex = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png',
|
||||
zIndex: 20
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).to.be(true);
|
||||
expect(literal.equals(differentHeight)).to.be(false);
|
||||
expect(literal.equals(differentWidth)).to.be(false);
|
||||
expect(literal.equals(differentOpacity)).to.be(false);
|
||||
expect(literal.equals(differentRotation)).to.be(false);
|
||||
expect(literal.equals(differentUrl)).to.be(false);
|
||||
expect(literal.equals(differentZIndex)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
goog.require('ol.style.IconLiteral');
|
||||
@@ -1,531 +0,0 @@
|
||||
goog.provide('ol.test.style.Icon');
|
||||
|
||||
describe('ol.style.Icon', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('accepts literal values', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png',
|
||||
xOffset: 10,
|
||||
yOffset: 15
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Icon);
|
||||
expect(symbolizer).to.be.a(ol.style.Point);
|
||||
});
|
||||
|
||||
it('accepts expressions', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: ol.expr.parse('10'),
|
||||
width: ol.expr.parse('20'),
|
||||
opacity: ol.expr.parse('1'),
|
||||
rotation: ol.expr.parse('0.1'),
|
||||
url: ol.expr.parse('"http://example.com/1.png"'),
|
||||
xOffset: ol.expr.parse('xOffset'),
|
||||
yOffset: ol.expr.parse('yOffset')
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Icon);
|
||||
});
|
||||
|
||||
it('accepts zIndex', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: ol.expr.parse('10'),
|
||||
width: ol.expr.parse('20'),
|
||||
opacity: ol.expr.parse('1'),
|
||||
rotation: ol.expr.parse('0.1'),
|
||||
url: ol.expr.parse('"http://example.com/1.png"'),
|
||||
zIndex: 3
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Icon);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#createLiteral()', function() {
|
||||
|
||||
it('evaluates expressions with the given feature', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: ol.expr.parse('heightAttr'),
|
||||
width: ol.expr.parse('widthAttr'),
|
||||
opacity: ol.expr.parse('opacityAttr'),
|
||||
rotation: ol.expr.parse('rotationAttr'),
|
||||
url: ol.expr.parse('urlAttr'),
|
||||
xOffset: ol.expr.parse('xOffset'),
|
||||
yOffset: ol.expr.parse('yOffset')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
heightAttr: 42,
|
||||
widthAttr: 0.42,
|
||||
opacityAttr: 0.5,
|
||||
rotationAttr: 123,
|
||||
urlAttr: 'http://example.com/1.png',
|
||||
xOffset: 20,
|
||||
yOffset: 30,
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.height).to.be(42);
|
||||
expect(literal.width).to.be(.42);
|
||||
expect(literal.opacity).to.be(0.5);
|
||||
expect(literal.rotation).to.be(123);
|
||||
expect(literal.xOffset).to.be(20);
|
||||
expect(literal.yOffset).to.be(30);
|
||||
expect(literal.url).to.be('http://example.com/1.png');
|
||||
expect(literal.zIndex).to.be(0);
|
||||
});
|
||||
|
||||
it('can be called without a feature', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: ol.expr.parse('10'),
|
||||
width: ol.expr.parse('20'),
|
||||
opacity: ol.expr.parse('1'),
|
||||
rotation: ol.expr.parse('0.1'),
|
||||
xOffset: ol.expr.parse('10'),
|
||||
yOffset: ol.expr.parse('20'),
|
||||
url: ol.expr.parse('"http://example.com/1.png"')
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.height).to.be(10);
|
||||
expect(literal.width).to.be(20);
|
||||
expect(literal.opacity).to.be(1);
|
||||
expect(literal.rotation).to.be(0.1);
|
||||
expect(literal.xOffset).to.be(10);
|
||||
expect(literal.yOffset).to.be(20);
|
||||
expect(literal.url).to.be('http://example.com/1.png');
|
||||
});
|
||||
|
||||
it('applies default opacity if none provided', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: 10,
|
||||
width: 20,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.opacity).to.be(1);
|
||||
});
|
||||
|
||||
it('applies default rotation if none provided', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: 10,
|
||||
width: 20,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.rotation).to.be(0);
|
||||
});
|
||||
|
||||
it('casts opacity to number', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
opacity: ol.expr.parse('opacity'),
|
||||
height: 10,
|
||||
width: 20,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
opacity: '0.53',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.opacity).to.be(0.53);
|
||||
});
|
||||
|
||||
it('casts width to number', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
width: ol.expr.parse('width'),
|
||||
height: 10,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
width: '42',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.width).to.be(42);
|
||||
});
|
||||
|
||||
it('casts height to number', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: ol.expr.parse('height'),
|
||||
width: 10,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
height: '42',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.height).to.be(42);
|
||||
});
|
||||
|
||||
it('applies default xOffset if none', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: 10,
|
||||
width: 20,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.xOffset).to.be(0);
|
||||
});
|
||||
|
||||
it('casts xOffset to number', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
xOffset: ol.expr.parse('xOffset'),
|
||||
width: 10,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
xOffset: '42',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.xOffset).to.be(42);
|
||||
});
|
||||
|
||||
it('applies default yOffset if none', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: 10,
|
||||
width: 20,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.yOffset).to.be(0);
|
||||
});
|
||||
|
||||
it('casts yOffset to number', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
yOffset: ol.expr.parse('yOffset'),
|
||||
width: 10,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
yOffset: '42',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.yOffset).to.be(42);
|
||||
});
|
||||
|
||||
it('handles zIndex', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: ol.expr.parse('10'),
|
||||
width: ol.expr.parse('20'),
|
||||
url: ol.expr.parse('"http://example.com/1.png"'),
|
||||
zIndex: 4
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.xOffset).to.be(0);
|
||||
expect(literal.zIndex).to.be(4);
|
||||
});
|
||||
|
||||
it('applies default zIndex if none', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: 10,
|
||||
width: 20,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.zIndex).to.be(0);
|
||||
});
|
||||
|
||||
it('casts zIndex to number', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
zIndex: ol.expr.parse('zIndex'),
|
||||
width: 10,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
zIndex: '42',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.zIndex).to.be(42);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getHeight()', function() {
|
||||
|
||||
it('returns the icon height', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
height: 20
|
||||
});
|
||||
|
||||
var height = symbolizer.getHeight();
|
||||
expect(height).to.be.a(ol.expr.Literal);
|
||||
expect(height.getValue()).to.be(20);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getOpacity()', function() {
|
||||
|
||||
it('returns the icon opacity', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
opacity: 0.123
|
||||
});
|
||||
|
||||
var opacity = symbolizer.getOpacity();
|
||||
expect(opacity).to.be.a(ol.expr.Literal);
|
||||
expect(opacity.getValue()).to.be(0.123);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getRotation()', function() {
|
||||
|
||||
it('returns the icon rotation', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
rotation: 0.123
|
||||
});
|
||||
|
||||
var rotation = symbolizer.getRotation();
|
||||
expect(rotation).to.be.a(ol.expr.Literal);
|
||||
expect(rotation.getValue()).to.be(0.123);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getUrl()', function() {
|
||||
|
||||
it('returns the url', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var url = symbolizer.getUrl();
|
||||
expect(url).to.be.a(ol.expr.Literal);
|
||||
expect(url.getValue()).to.be('http://example.com/1.png');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('#getWidth()', function() {
|
||||
|
||||
it('returns the icon width', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10
|
||||
});
|
||||
|
||||
var width = symbolizer.getWidth();
|
||||
expect(width).to.be.a(ol.expr.Literal);
|
||||
expect(width.getValue()).to.be(10);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('#setHeight()', function() {
|
||||
|
||||
it('sets the icon height', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
height: 20
|
||||
});
|
||||
symbolizer.setHeight(new ol.expr.Literal(30));
|
||||
|
||||
var height = symbolizer.getHeight();
|
||||
expect(height).to.be.a(ol.expr.Literal);
|
||||
expect(height.getValue()).to.be(30);
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
height: 20
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setHeight(30);
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setOpacity()', function() {
|
||||
|
||||
it('sets the icon opacity', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
height: 20,
|
||||
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.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
height: 20,
|
||||
opacity: 0.123
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setOpacity(0.5);
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setRotation()', function() {
|
||||
|
||||
it('sets the icon rotation', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
height: 20,
|
||||
rotation: 0.123
|
||||
});
|
||||
symbolizer.setRotation(new ol.expr.Literal(0.321));
|
||||
|
||||
var rotation = symbolizer.getRotation();
|
||||
expect(rotation).to.be.a(ol.expr.Literal);
|
||||
expect(rotation.getValue()).to.be(0.321);
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
height: 20,
|
||||
rotation: 0.123
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setRotation(0.5);
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setUrl()', function() {
|
||||
|
||||
it('sets the url', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
symbolizer.setUrl(new ol.expr.Literal('http://example.com/2.png'));
|
||||
|
||||
var url = symbolizer.getUrl();
|
||||
expect(url).to.be.a(ol.expr.Literal);
|
||||
expect(url.getValue()).to.be('http://example.com/2.png');
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setUrl('http://example.com/2.png');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setWidth()', function() {
|
||||
|
||||
it('sets the icon width', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10
|
||||
});
|
||||
|
||||
symbolizer.setWidth(new ol.expr.Literal(20));
|
||||
|
||||
var width = symbolizer.getWidth();
|
||||
expect(width).to.be.a(ol.expr.Literal);
|
||||
expect(width.getValue()).to.be(20);
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setWidth(40);
|
||||
}).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.geom.GeometryType');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.style.Icon');
|
||||
goog.require('ol.style.IconLiteral');
|
||||
goog.require('ol.style.Point');
|
||||
@@ -1,55 +0,0 @@
|
||||
goog.provide('ol.test.style.LineLiteral');
|
||||
|
||||
describe('ol.style.LineLiteral', function() {
|
||||
|
||||
describe('#equals()', function() {
|
||||
|
||||
it('identifies equal literals', function() {
|
||||
var literal = new ol.style.LineLiteral({
|
||||
width: 3,
|
||||
color: '#BADA55',
|
||||
opacity: 1,
|
||||
zIndex: 0
|
||||
});
|
||||
var equalLiteral = new ol.style.LineLiteral({
|
||||
color: '#BADA55',
|
||||
width: 3,
|
||||
opacity: 1,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentColor = new ol.style.LineLiteral({
|
||||
width: 3,
|
||||
color: '#ff0000',
|
||||
opacity: 1,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentWidth = new ol.style.LineLiteral({
|
||||
width: 3.5,
|
||||
color: '#BADA55',
|
||||
opacity: 1,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentOpacity = new ol.style.LineLiteral({
|
||||
width: 3,
|
||||
color: '#BADA55',
|
||||
opacity: 0.5,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentZIndex = new ol.style.LineLiteral({
|
||||
width: 3,
|
||||
color: '#BADA55',
|
||||
opacity: 1,
|
||||
zIndex: 3
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).to.be(true);
|
||||
expect(literal.equals(differentColor)).to.be(false);
|
||||
expect(literal.equals(differentWidth)).to.be(false);
|
||||
expect(literal.equals(differentOpacity)).to.be(false);
|
||||
expect(literal.equals(differentZIndex)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.style.LineLiteral');
|
||||
@@ -1,86 +0,0 @@
|
||||
goog.provide('ol.test.style.PolygonLiteral');
|
||||
|
||||
describe('ol.style.PolygonLiteral', function() {
|
||||
|
||||
describe('#equals()', function() {
|
||||
|
||||
it('identifies equal literals', function() {
|
||||
var literal = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3,
|
||||
zIndex: 0
|
||||
});
|
||||
var equalLiteral = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentStrokeWidth = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 5,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentStrokeColor = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#ffff00',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentStrokeOpacity = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.41,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentFillColor = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#00ffff',
|
||||
fillOpacity: 0.3,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentFillOpacity = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.31,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentZIndex = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3,
|
||||
zIndex: 2
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).to.be(true);
|
||||
expect(literal.equals(differentStrokeWidth)).to.be(false);
|
||||
expect(literal.equals(differentStrokeColor)).to.be(false);
|
||||
expect(literal.equals(differentStrokeOpacity)).to.be(false);
|
||||
expect(literal.equals(differentFillColor)).to.be(false);
|
||||
expect(literal.equals(differentFillOpacity)).to.be(false);
|
||||
expect(literal.equals(differentZIndex)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.style.PolygonLiteral');
|
||||
@@ -1,157 +0,0 @@
|
||||
goog.provide('ol.test.style.Rule');
|
||||
|
||||
describe('ol.style.Rule', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('accepts a filter option', function() {
|
||||
var rule = new ol.style.Rule({
|
||||
filter: 'foo == "bar"'
|
||||
});
|
||||
expect(rule).to.be.a(ol.style.Rule);
|
||||
});
|
||||
|
||||
it('accepts a minResolution option', function() {
|
||||
var rule = new ol.style.Rule({
|
||||
minResolution: 10
|
||||
});
|
||||
expect(rule).to.be.a(ol.style.Rule);
|
||||
});
|
||||
|
||||
it('accepts a maxResolution option', function() {
|
||||
var rule = new ol.style.Rule({
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule).to.be.a(ol.style.Rule);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#applies()', function() {
|
||||
var feature = new ol.Feature(),
|
||||
rule;
|
||||
|
||||
it('returns true for a rule without filter', function() {
|
||||
rule = new ol.style.Rule({});
|
||||
expect(rule.applies(feature, 1)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false when the filter evaluates to false', function() {
|
||||
rule = new ol.style.Rule({
|
||||
filter: new ol.expr.Literal(false)
|
||||
});
|
||||
expect(rule.applies(feature, 1)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns true when the filter evaluates to true', function() {
|
||||
rule = new ol.style.Rule({
|
||||
filter: new ol.expr.Literal(true)
|
||||
});
|
||||
expect(rule.applies(feature, 1)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false when the resolution is less than min', function() {
|
||||
rule = new ol.style.Rule({
|
||||
minResolution: 10
|
||||
});
|
||||
expect(rule.applies(feature, 9)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns true when the resolution is greater than min', function() {
|
||||
rule = new ol.style.Rule({
|
||||
minResolution: 10
|
||||
});
|
||||
expect(rule.applies(feature, 11)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns true when the resolution is equal to min', function() {
|
||||
rule = new ol.style.Rule({
|
||||
minResolution: 10
|
||||
});
|
||||
expect(rule.applies(feature, 10)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false if filter evaluates to false (with min res)', function() {
|
||||
rule = new ol.style.Rule({
|
||||
filter: new ol.expr.Literal(false),
|
||||
minResolution: 10
|
||||
});
|
||||
expect(rule.applies(feature, 11)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns true if filter evaluates to true (with min res)', function() {
|
||||
rule = new ol.style.Rule({
|
||||
filter: new ol.expr.Literal(true),
|
||||
minResolution: 10
|
||||
});
|
||||
expect(rule.applies(feature, 11)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false when the resolution is greater than max', function() {
|
||||
rule = new ol.style.Rule({
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule.applies(feature, 101)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns true when the resolution is less than max', function() {
|
||||
rule = new ol.style.Rule({
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule.applies(feature, 99)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false when the resolution is equal to max', function() {
|
||||
rule = new ol.style.Rule({
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule.applies(feature, 100)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns false if filter evaluates to false (with max res)', function() {
|
||||
rule = new ol.style.Rule({
|
||||
filter: new ol.expr.Literal(false),
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule.applies(feature, 99)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns true if filter evaluates to true (with max res)', function() {
|
||||
rule = new ol.style.Rule({
|
||||
filter: new ol.expr.Literal(true),
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule.applies(feature, 99)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns true if resolution is between min and max', function() {
|
||||
rule = new ol.style.Rule({
|
||||
minResolution: 10,
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule.applies(feature, 55)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false if resolution is greater than min and max', function() {
|
||||
rule = new ol.style.Rule({
|
||||
minResolution: 10,
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule.applies(feature, 1000)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns false if resolution is less than min and max', function() {
|
||||
rule = new ol.style.Rule({
|
||||
minResolution: 10,
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule.applies(feature, 5)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.style.Rule');
|
||||
@@ -1,113 +0,0 @@
|
||||
goog.provide('ol.test.style.ShapeLiteral');
|
||||
|
||||
describe('ol.style.ShapeLiteral', function() {
|
||||
|
||||
describe('#equals()', function() {
|
||||
|
||||
it('identifies equal literals', function() {
|
||||
var literal = new ol.style.ShapeLiteral({
|
||||
type: ol.style.ShapeType.CIRCLE,
|
||||
size: 4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.9,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.8,
|
||||
strokeWidth: 3,
|
||||
zIndex: 0
|
||||
});
|
||||
var equalLiteral = new ol.style.ShapeLiteral({
|
||||
type: ol.style.ShapeType.CIRCLE,
|
||||
size: 4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.9,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.8,
|
||||
strokeWidth: 3,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentSize = new ol.style.ShapeLiteral({
|
||||
type: ol.style.ShapeType.CIRCLE,
|
||||
size: 5,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.9,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.8,
|
||||
strokeWidth: 3,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentFillColor = new ol.style.ShapeLiteral({
|
||||
type: ol.style.ShapeType.CIRCLE,
|
||||
size: 4,
|
||||
fillColor: '#ffffff',
|
||||
fillOpacity: 0.9,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.8,
|
||||
strokeWidth: 3,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentFillOpacity = new ol.style.ShapeLiteral({
|
||||
type: ol.style.ShapeType.CIRCLE,
|
||||
size: 4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.8,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.8,
|
||||
strokeWidth: 3,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentStrokeColor = new ol.style.ShapeLiteral({
|
||||
type: ol.style.ShapeType.CIRCLE,
|
||||
size: 4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.9,
|
||||
strokeColor: '#ffffff',
|
||||
strokeOpacity: 0.8,
|
||||
strokeWidth: 3,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentStrokeOpacity = new ol.style.ShapeLiteral({
|
||||
type: ol.style.ShapeType.CIRCLE,
|
||||
size: 4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.9,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.7,
|
||||
strokeWidth: 3,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentStrokeWidth = new ol.style.ShapeLiteral({
|
||||
type: ol.style.ShapeType.CIRCLE,
|
||||
size: 4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.9,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.8,
|
||||
strokeWidth: 4,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentZIndex = new ol.style.ShapeLiteral({
|
||||
type: ol.style.ShapeType.CIRCLE,
|
||||
size: 4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.9,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.8,
|
||||
strokeWidth: 3,
|
||||
zIndex: -1
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).to.be(true);
|
||||
expect(literal.equals(differentSize)).to.be(false);
|
||||
expect(literal.equals(differentFillColor)).to.be(false);
|
||||
expect(literal.equals(differentFillOpacity)).to.be(false);
|
||||
expect(literal.equals(differentStrokeColor)).to.be(false);
|
||||
expect(literal.equals(differentStrokeOpacity)).to.be(false);
|
||||
expect(literal.equals(differentStrokeWidth)).to.be(false);
|
||||
expect(literal.equals(differentZIndex)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.style.ShapeLiteral');
|
||||
goog.require('ol.style.ShapeType');
|
||||
@@ -1,337 +0,0 @@
|
||||
goog.provide('ol.test.style.Shape');
|
||||
|
||||
describe('ol.style.Shape', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('accepts literal values', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: 4,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#ff0000'
|
||||
})
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Shape);
|
||||
expect(symbolizer).to.be.a(ol.style.Point);
|
||||
});
|
||||
|
||||
it('accepts expressions', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: ol.expr.parse('sizeAttr'),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: ol.expr.parse('color')
|
||||
})
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Shape);
|
||||
});
|
||||
|
||||
it('accepts zIndex', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: 4,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#ff0000'
|
||||
}),
|
||||
zIndex: -1
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Shape);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#createLiteral()', function() {
|
||||
|
||||
it('evaluates expressions with the given feature', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: ol.expr.parse('sizeAttr'),
|
||||
fill: new ol.style.Fill({
|
||||
opacity: ol.expr.parse('opacityAttr'),
|
||||
color: '#BADA55'
|
||||
})
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
sizeAttr: 42,
|
||||
opacityAttr: 0.4,
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.ShapeLiteral);
|
||||
expect(literal.size).to.be(42);
|
||||
expect(literal.fillOpacity).to.be(0.4);
|
||||
expect(literal.zIndex).to.be(0);
|
||||
});
|
||||
|
||||
it('can be called without a feature', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: 10,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#BADA55'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#013',
|
||||
opacity: 1,
|
||||
width: 2
|
||||
})
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.ShapeLiteral);
|
||||
expect(literal.size).to.be(10);
|
||||
expect(literal.fillColor).to.be('#BADA55');
|
||||
expect(literal.strokeColor).to.be('#013');
|
||||
expect(literal.strokeOpacity).to.be(1);
|
||||
expect(literal.strokeWidth).to.be(2);
|
||||
});
|
||||
|
||||
it('casts size to number', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: ol.expr.parse('size'),
|
||||
fill: new ol.style.Fill({
|
||||
color: '#BADA55'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#013',
|
||||
opacity: 1,
|
||||
width: 2
|
||||
})
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
size: '42',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.ShapeLiteral);
|
||||
expect(literal.size).to.be(42);
|
||||
});
|
||||
|
||||
it('casts stroke width to number', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
fill: new ol.style.Fill({
|
||||
color: '#BADA55'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#013',
|
||||
opacity: 1,
|
||||
width: ol.expr.parse('strokeWidth')
|
||||
})
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
strokeWidth: '4.2',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.ShapeLiteral);
|
||||
expect(literal.strokeWidth).to.be(4.2);
|
||||
});
|
||||
|
||||
it('casts stroke opacity to number', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
fill: new ol.style.Fill({
|
||||
color: '#BADA55'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#013',
|
||||
opacity: ol.expr.parse('strokeOpacity'),
|
||||
width: 3
|
||||
})
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
strokeOpacity: '.2',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.ShapeLiteral);
|
||||
expect(literal.strokeOpacity).to.be(0.2);
|
||||
});
|
||||
|
||||
it('casts fill opacity to number', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
fill: new ol.style.Fill({
|
||||
opacity: ol.expr.parse('fillOpacity'),
|
||||
color: '#BADA55'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#013',
|
||||
width: 3
|
||||
})
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
fillOpacity: '.42',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.ShapeLiteral);
|
||||
expect(literal.fillOpacity).to.be(0.42);
|
||||
});
|
||||
|
||||
it('handles zIndex', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#ff0000'
|
||||
}),
|
||||
zIndex: -2
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.ShapeLiteral);
|
||||
expect(literal.zIndex).to.be(-2);
|
||||
});
|
||||
|
||||
it('casts zIndex to number', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
fill: new ol.style.Fill({
|
||||
color: '#BADA55'
|
||||
}),
|
||||
zIndex: ol.expr.parse('zIndex')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
zIndex: '42',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.ShapeLiteral);
|
||||
expect(literal.zIndex).to.be(42);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getFill()', function() {
|
||||
|
||||
it('returns the fill', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
fill: new ol.style.Fill({
|
||||
color: '#ff0000'
|
||||
})
|
||||
});
|
||||
|
||||
var fill = symbolizer.getFill();
|
||||
expect(fill).to.be.a(ol.style.Fill);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getStroke()', function() {
|
||||
|
||||
it('returns the stroke', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#ff0000'
|
||||
})
|
||||
});
|
||||
|
||||
var stroke = symbolizer.getStroke();
|
||||
expect(stroke).to.be.a(ol.style.Stroke);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getType()', function() {
|
||||
|
||||
it('returns the shape type', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
stroke: new ol.style.Stroke({
|
||||
width: 1,
|
||||
opacity: 0.123
|
||||
})
|
||||
});
|
||||
|
||||
var type = symbolizer.getType();
|
||||
expect(type).to.be(ol.style.ShapeType.CIRCLE);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setFill()', function() {
|
||||
|
||||
it('sets the fill', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
stroke: new ol.style.Stroke({color: '#ff0000'})
|
||||
});
|
||||
expect(symbolizer.getFill()).to.be(null);
|
||||
|
||||
symbolizer.setFill(new ol.style.Fill({color: '#0000ff'}));
|
||||
expect(symbolizer.getFill()).to.be.a(ol.style.Fill);
|
||||
});
|
||||
|
||||
it('throws when not provided a fill', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
fill: new ol.style.Fill({color: '#ff0000'})
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setFill('#0000ff');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setStroke()', function() {
|
||||
|
||||
it('sets the stroke', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
fill: new ol.style.Fill({color: '#ff0000'})
|
||||
});
|
||||
expect(symbolizer.getStroke()).to.be(null);
|
||||
|
||||
symbolizer.setStroke(new ol.style.Stroke({color: '#0000ff'}));
|
||||
expect(symbolizer.getStroke()).to.be.a(ol.style.Stroke);
|
||||
});
|
||||
|
||||
it('throws when not provided a stroke', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
stroke: new ol.style.Stroke({color: '#ff0000'})
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setStroke('#0000ff');
|
||||
}).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({
|
||||
stroke: new ol.style.Stroke({
|
||||
width: 1,
|
||||
opacity: 0.123
|
||||
})
|
||||
});
|
||||
symbolizer.setType(ol.style.ShapeType.CIRCLE);
|
||||
|
||||
var type = symbolizer.getType();
|
||||
expect(type).to.be(ol.style.ShapeType.CIRCLE);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.asserts.AssertionError');
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.Point');
|
||||
goog.require('ol.style.Shape');
|
||||
goog.require('ol.style.ShapeLiteral');
|
||||
goog.require('ol.style.ShapeType');
|
||||
goog.require('ol.style.Stroke');
|
||||
@@ -1,202 +0,0 @@
|
||||
goog.provide('ol.test.style.Stroke');
|
||||
|
||||
describe('ol.style.Stroke', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('accepts literal values', function() {
|
||||
var symbolizer = new ol.style.Stroke({
|
||||
color: '#BADA55',
|
||||
width: 3
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Stroke);
|
||||
});
|
||||
|
||||
it('accepts expressions', function() {
|
||||
var symbolizer = new ol.style.Stroke({
|
||||
opacity: ol.expr.parse('value / 100'),
|
||||
width: ol.expr.parse('widthAttr')
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Stroke);
|
||||
});
|
||||
|
||||
it('accepts zIndex', function() {
|
||||
var symbolizer = new ol.style.Stroke({
|
||||
opacity: ol.expr.parse('value / 100'),
|
||||
width: ol.expr.parse('widthAttr'),
|
||||
zIndex: 5
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Stroke);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#createLiteral()', function() {
|
||||
|
||||
it('evaluates expressions with the given feature', function() {
|
||||
var symbolizer = new ol.style.Stroke({
|
||||
opacity: ol.expr.parse('value / 100'),
|
||||
width: ol.expr.parse('widthAttr')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
value: 42,
|
||||
widthAttr: 1.5,
|
||||
geometry: new ol.geom.LineString([[1, 2], [3, 4]])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.LineLiteral);
|
||||
expect(literal.opacity).to.be(42 / 100);
|
||||
expect(literal.width).to.be(1.5);
|
||||
expect(literal.zIndex).to.be(0);
|
||||
});
|
||||
|
||||
it('applies the default values', function() {
|
||||
var symbolizer = new ol.style.Stroke({});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.LINESTRING);
|
||||
expect(literal).to.be.a(ol.style.LineLiteral);
|
||||
expect(literal.color).to.be('#696969');
|
||||
expect(literal.opacity).to.be(0.75);
|
||||
expect(literal.width).to.be(1.5);
|
||||
expect(literal.zIndex).to.be(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getColor()', function() {
|
||||
|
||||
it('returns the stroke color', function() {
|
||||
var symbolizer = new ol.style.Stroke({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
var color = symbolizer.getColor();
|
||||
expect(color).to.be.a(ol.expr.Literal);
|
||||
expect(color.getValue()).to.be('#ff0000');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getWidth()', function() {
|
||||
|
||||
it('returns the stroke width', function() {
|
||||
var symbolizer = new ol.style.Stroke({
|
||||
width: 10
|
||||
});
|
||||
|
||||
var width = symbolizer.getWidth();
|
||||
expect(width).to.be.a(ol.expr.Literal);
|
||||
expect(width.getValue()).to.be(10);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getOpacity()', function() {
|
||||
|
||||
it('returns the stroke opacity', function() {
|
||||
var symbolizer = new ol.style.Stroke({
|
||||
opacity: 0.123
|
||||
});
|
||||
|
||||
var opacity = symbolizer.getOpacity();
|
||||
expect(opacity).to.be.a(ol.expr.Literal);
|
||||
expect(opacity.getValue()).to.be(0.123);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setColor()', function() {
|
||||
|
||||
it('sets the stroke color', function() {
|
||||
var symbolizer = new ol.style.Stroke({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
symbolizer.setColor(new ol.expr.Literal('#0000ff'));
|
||||
|
||||
var color = symbolizer.getColor();
|
||||
expect(color).to.be.a(ol.expr.Literal);
|
||||
expect(color.getValue()).to.be('#0000ff');
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Stroke({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setColor('#0000ff');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setWidth()', function() {
|
||||
|
||||
it('sets the stroke width', function() {
|
||||
var symbolizer = new ol.style.Stroke({
|
||||
width: 10
|
||||
});
|
||||
symbolizer.setWidth(new ol.expr.Literal(20));
|
||||
|
||||
var width = symbolizer.getWidth();
|
||||
expect(width).to.be.a(ol.expr.Literal);
|
||||
expect(width.getValue()).to.be(20);
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Stroke({
|
||||
width: 10
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setWidth(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.Stroke({
|
||||
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.Stroke({
|
||||
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.geom.GeometryType');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.LineLiteral');
|
||||
@@ -1,317 +0,0 @@
|
||||
goog.provide('ol.test.style.Style');
|
||||
|
||||
describe('ol.style.Style', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a style instance given rules', function() {
|
||||
var style = new ol.style.Style({
|
||||
rules: [
|
||||
new ol.style.Rule({
|
||||
filter: 'foo == "bar"',
|
||||
symbolizers: [
|
||||
new ol.style.Fill({
|
||||
color: '#ff0000'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
});
|
||||
expect(style).to.be.a(ol.style.Style);
|
||||
});
|
||||
|
||||
it('creates a style instance given only "else" symbolizers', function() {
|
||||
var style = new ol.style.Style({
|
||||
symbolizers: [
|
||||
new ol.style.Fill({
|
||||
color: '#ff0000'
|
||||
})
|
||||
]
|
||||
});
|
||||
expect(style).to.be.a(ol.style.Style);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#createLiterals()', function() {
|
||||
|
||||
it('creates symbolizer literals for a feature', function() {
|
||||
var style = new ol.style.Style({
|
||||
rules: [
|
||||
new ol.style.Rule({
|
||||
filter: 'foo == "bar"',
|
||||
symbolizers: [
|
||||
new ol.style.Shape({
|
||||
size: 4,
|
||||
fill: new ol.style.Fill({
|
||||
color: ol.expr.parse('fillColor')
|
||||
})
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
});
|
||||
var feature = new ol.Feature({
|
||||
fillColor: '#BADA55',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
feature.set('foo', 'bar');
|
||||
|
||||
var literals = style.createLiterals(feature, 1);
|
||||
expect(literals).to.have.length(1);
|
||||
expect(literals[0].fillColor).to.be('#BADA55');
|
||||
|
||||
feature.set('foo', 'baz');
|
||||
expect(style.createLiterals(feature, 1)).to.have.length(0);
|
||||
});
|
||||
|
||||
it('uses the "else" symbolizers when no rules are provided', function() {
|
||||
var style = new ol.style.Style({
|
||||
symbolizers: [
|
||||
new ol.style.Stroke({
|
||||
color: '#ff0000'
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
geometry: new ol.geom.LineString([[1, 2], [3, 4]])
|
||||
});
|
||||
|
||||
var literals = style.createLiterals(feature, 1);
|
||||
expect(literals).to.have.length(1);
|
||||
expect(literals[0].color).to.be('#ff0000');
|
||||
});
|
||||
|
||||
it('uses the "else" symbolizers when no rules apply', function() {
|
||||
var style = new ol.style.Style({
|
||||
rules: [
|
||||
new ol.style.Rule({
|
||||
filter: 'name == "match"',
|
||||
symbolizers: [
|
||||
new ol.style.Stroke({
|
||||
color: '#ff00ff'
|
||||
})
|
||||
]
|
||||
})
|
||||
],
|
||||
// these are the "else" symbolizers
|
||||
symbolizers: [
|
||||
new ol.style.Stroke({
|
||||
color: '#00ff00'
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
geometry: new ol.geom.LineString([[1, 2], [3, 4]])
|
||||
});
|
||||
|
||||
var literals = style.createLiterals(feature, 1);
|
||||
expect(literals).to.have.length(1);
|
||||
expect(literals[0].color).to.be('#00ff00');
|
||||
|
||||
feature = new ol.Feature({
|
||||
name: 'match',
|
||||
geometry: new ol.geom.LineString([[1, 2], [3, 4]])
|
||||
});
|
||||
literals = style.createLiterals(feature, 1);
|
||||
expect(literals).to.have.length(1);
|
||||
expect(literals[0].color).to.be('#ff00ff');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.style.getDefault()', function() {
|
||||
var style = ol.style.getDefault();
|
||||
|
||||
it('is a ol.style.Style instance', function() {
|
||||
expect(style).to.be.a(ol.style.Style);
|
||||
});
|
||||
|
||||
describe('#createLiterals()', function() {
|
||||
|
||||
it('returns an empty array for features without geometry', function() {
|
||||
var feature = new ol.Feature();
|
||||
expect(style.createLiterals(feature, 1))
|
||||
.to.have.length(0);
|
||||
});
|
||||
|
||||
it('returns an array with the Shape default for points', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.setGeometry(new ol.geom.Point([0, 0]));
|
||||
|
||||
var literals = style.createLiterals(feature, 1);
|
||||
expect(literals).to.have.length(1);
|
||||
|
||||
var literal = literals[0];
|
||||
expect(literal).to.be.a(ol.style.ShapeLiteral);
|
||||
expect(literal.type).to.be(ol.style.ShapeDefaults.type);
|
||||
expect(literal.fillColor).to.be(ol.style.FillDefaults.color);
|
||||
expect(literal.fillOpacity).to.be(ol.style.FillDefaults.opacity);
|
||||
expect(literal.strokeColor).to.be(ol.style.StrokeDefaults.color);
|
||||
expect(literal.strokeOpacity).to.be(ol.style.StrokeDefaults.opacity);
|
||||
expect(literal.strokeWidth).to.be(ol.style.StrokeDefaults.width);
|
||||
});
|
||||
|
||||
it('returns an array with the Line default for lines', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.setGeometry(new ol.geom.LineString([[0, 0], [1, 1]]));
|
||||
|
||||
var literals = style.createLiterals(feature, 1);
|
||||
expect(literals).to.have.length(1);
|
||||
|
||||
var literal = literals[0];
|
||||
expect(literal).to.be.a(ol.style.LineLiteral);
|
||||
expect(literal.color).to.be(ol.style.StrokeDefaults.color);
|
||||
expect(literal.opacity).to.be(ol.style.StrokeDefaults.opacity);
|
||||
expect(literal.width).to.be(ol.style.StrokeDefaults.width);
|
||||
});
|
||||
|
||||
it('returns an array with the Polygon default for polygons', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.setGeometry(new ol.geom.Polygon([[[0, 0], [1, 1], [0, 0]]]));
|
||||
|
||||
var literals = style.createLiterals(feature, 1);
|
||||
expect(literals).to.have.length(1);
|
||||
|
||||
var literal = literals[0];
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.fillColor).to.be(ol.style.FillDefaults.color);
|
||||
expect(literal.fillOpacity).to.be(ol.style.FillDefaults.opacity);
|
||||
expect(literal.strokeColor).to.be(ol.style.StrokeDefaults.color);
|
||||
expect(literal.strokeOpacity).to.be(ol.style.StrokeDefaults.opacity);
|
||||
expect(literal.strokeWidth).to.be(ol.style.StrokeDefaults.width);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#reduceLiterals_', function() {
|
||||
|
||||
it('collapses stroke or fill only literals where possible', function() {
|
||||
var literals = [
|
||||
new ol.style.PolygonLiteral({
|
||||
fillColor: '#ff0000',
|
||||
fillOpacity: 0.5,
|
||||
zIndex: 0
|
||||
}),
|
||||
new ol.style.PolygonLiteral({
|
||||
strokeColor: '#00ff00',
|
||||
strokeOpacity: 0.6,
|
||||
strokeWidth: 3,
|
||||
zIndex: 0
|
||||
})
|
||||
];
|
||||
|
||||
var reduced = ol.style.Style.reduceLiterals_(literals);
|
||||
expect(reduced).to.have.length(1);
|
||||
|
||||
var poly = reduced[0];
|
||||
expect(poly.fillColor).to.be('#ff0000');
|
||||
expect(poly.fillOpacity).to.be(0.5);
|
||||
expect(poly.strokeColor).to.be('#00ff00');
|
||||
expect(poly.strokeOpacity).to.be(0.6);
|
||||
expect(poly.strokeWidth).to.be(3);
|
||||
});
|
||||
|
||||
it('leaves complete polygon literals alone', function() {
|
||||
var literals = [
|
||||
new ol.style.PolygonLiteral({
|
||||
fillColor: '#ff0000',
|
||||
fillOpacity: 0.5,
|
||||
strokeColor: '#00ff00',
|
||||
strokeOpacity: 0.6,
|
||||
strokeWidth: 3,
|
||||
zIndex: 0
|
||||
}),
|
||||
new ol.style.PolygonLiteral({
|
||||
strokeColor: '#0000ff',
|
||||
strokeOpacity: 0.7,
|
||||
strokeWidth: 1,
|
||||
zIndex: 0
|
||||
})
|
||||
];
|
||||
|
||||
var reduced = ol.style.Style.reduceLiterals_(literals);
|
||||
expect(reduced).to.have.length(2);
|
||||
|
||||
var first = reduced[0];
|
||||
expect(first.fillColor).to.be('#ff0000');
|
||||
expect(first.fillOpacity).to.be(0.5);
|
||||
expect(first.strokeColor).to.be('#00ff00');
|
||||
expect(first.strokeOpacity).to.be(0.6);
|
||||
expect(first.strokeWidth).to.be(3);
|
||||
|
||||
var second = reduced[1];
|
||||
expect(second.fillColor).to.be(undefined);
|
||||
expect(second.fillOpacity).to.be(undefined);
|
||||
expect(second.strokeColor).to.be('#0000ff');
|
||||
expect(second.strokeOpacity).to.be(0.7);
|
||||
expect(second.strokeWidth).to.be(1);
|
||||
});
|
||||
|
||||
it('leaves other literals alone', function() {
|
||||
var literals = [
|
||||
new ol.style.PolygonLiteral({
|
||||
strokeColor: '#00ff00',
|
||||
strokeOpacity: 0.6,
|
||||
strokeWidth: 3,
|
||||
zIndex: 0
|
||||
}),
|
||||
new ol.style.PolygonLiteral({
|
||||
fillColor: '#ff0000',
|
||||
fillOpacity: 0.5,
|
||||
zIndex: 0
|
||||
}),
|
||||
new ol.style.TextLiteral({
|
||||
color: '#ffffff',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
fontWeight: 'normal',
|
||||
text: 'Test',
|
||||
opacity: 0.5,
|
||||
zIndex: 0
|
||||
})
|
||||
];
|
||||
|
||||
var reduced = ol.style.Style.reduceLiterals_(literals);
|
||||
expect(reduced).to.have.length(2);
|
||||
|
||||
var first = reduced[0];
|
||||
expect(first.fillColor).to.be('#ff0000');
|
||||
expect(first.fillOpacity).to.be(0.5);
|
||||
expect(first.strokeColor).to.be('#00ff00');
|
||||
expect(first.strokeOpacity).to.be(0.6);
|
||||
expect(first.strokeWidth).to.be(3);
|
||||
|
||||
var second = reduced[1];
|
||||
expect(second.color).to.be('#ffffff');
|
||||
expect(second.fontFamily).to.be('Arial');
|
||||
expect(second.fontSize).to.be(11);
|
||||
expect(second.text).to.be('Test');
|
||||
expect(second.opacity).to.be(0.5);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.style');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.LineLiteral');
|
||||
goog.require('ol.style.PolygonLiteral');
|
||||
goog.require('ol.style.Rule');
|
||||
goog.require('ol.style.Shape');
|
||||
goog.require('ol.style.ShapeLiteral');
|
||||
goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.StrokeDefaults');
|
||||
goog.require('ol.style.Style');
|
||||
goog.require('ol.style.TextLiteral');
|
||||
@@ -1,156 +0,0 @@
|
||||
goog.provide('ol.test.style.TextLiteral');
|
||||
|
||||
describe('ol.style.TextLiteral', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a new literal', function() {
|
||||
var literal = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
fontWeight: 'normal',
|
||||
text: 'Test',
|
||||
opacity: 0.5,
|
||||
zIndex: 0
|
||||
});
|
||||
expect(literal).to.be.a(ol.style.Literal);
|
||||
expect(literal).to.be.a(ol.style.TextLiteral);
|
||||
});
|
||||
|
||||
it('accepts stroke properties', function() {
|
||||
var literal = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
fontWeight: 'normal',
|
||||
text: 'Test',
|
||||
opacity: 0.5,
|
||||
strokeColor: '#ff0000',
|
||||
strokeWidth: 2,
|
||||
strokeOpacity: 0.5,
|
||||
zIndex: 0
|
||||
});
|
||||
expect(literal).to.be.a(ol.style.TextLiteral);
|
||||
});
|
||||
|
||||
it('throws with incomplete stroke properties', function() {
|
||||
expect(function() {
|
||||
new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
fontWeight: 'normal',
|
||||
text: 'Test',
|
||||
opacity: 0.5,
|
||||
strokeColor: '#ff0000',
|
||||
zIndex: 0
|
||||
});
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#equals()', function() {
|
||||
|
||||
it('identifies equal literals', function() {
|
||||
var literal = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
fontWeight: 'normal',
|
||||
text: 'Test',
|
||||
opacity: 0.5,
|
||||
zIndex: 0
|
||||
});
|
||||
var equalLiteral = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
fontWeight: 'normal',
|
||||
text: 'Test',
|
||||
opacity: 0.5,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentColor = new ol.style.TextLiteral({
|
||||
color: '#0000ff',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
fontWeight: 'normal',
|
||||
text: 'Test',
|
||||
opacity: 0.5,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentFontFamily = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Dingbats',
|
||||
fontSize: 11,
|
||||
fontWeight: 'normal',
|
||||
text: 'Test',
|
||||
opacity: 0.5,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentFontSize = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 12,
|
||||
fontWeight: 'normal',
|
||||
text: 'Test',
|
||||
opacity: 0.5,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentFontWeight = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
fontWeight: 'bold',
|
||||
text: 'Test',
|
||||
opacity: 0.5,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentOpacity = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
fontWeight: 'normal',
|
||||
text: 'Test',
|
||||
opacity: 0.6,
|
||||
zIndex: 0
|
||||
});
|
||||
var equalLiteral2 = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
fontWeight: 'normal',
|
||||
text: 'Text is not compared for equality',
|
||||
opacity: 0.5,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentZIndex = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
fontWeight: 'normal',
|
||||
text: 'Test',
|
||||
opacity: 0.5,
|
||||
zIndex: 3
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).to.be(true);
|
||||
expect(literal.equals(differentColor)).to.be(false);
|
||||
expect(literal.equals(differentFontFamily)).to.be(false);
|
||||
expect(literal.equals(differentFontSize)).to.be(false);
|
||||
expect(literal.equals(differentFontWeight)).to.be(false);
|
||||
expect(literal.equals(differentOpacity)).to.be(false);
|
||||
expect(literal.equals(equalLiteral2)).to.be(true);
|
||||
expect(literal.equals(differentZIndex)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.asserts.AssertionError');
|
||||
goog.require('ol.style.Literal');
|
||||
goog.require('ol.style.TextLiteral');
|
||||
@@ -1,428 +0,0 @@
|
||||
goog.provide('ol.test.style.Text');
|
||||
|
||||
describe('ol.style.Text', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('accepts literal values', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
text: 'Test',
|
||||
opacity: 0.6
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Text);
|
||||
});
|
||||
|
||||
it('accepts expressions', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
color: ol.expr.parse('"#ff0000"'),
|
||||
fontFamily: ol.expr.parse('"Arial"'),
|
||||
fontSize: ol.expr.parse('11'),
|
||||
text: ol.expr.parse('"Test"'),
|
||||
opacity: ol.expr.parse('0.6')
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Text);
|
||||
});
|
||||
|
||||
it('accepts zIndex', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
text: 'Test',
|
||||
opacity: 0.6,
|
||||
zIndex: 3
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Text);
|
||||
});
|
||||
|
||||
it('accepts stroke', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
color: '#000000',
|
||||
text: 'Test',
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#ff0000',
|
||||
width: 2,
|
||||
opacity: 0.5
|
||||
})
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Text);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#createLiteral()', function() {
|
||||
|
||||
it('evaluates expressions with the given feature', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
color: ol.expr.parse('colorAttr'),
|
||||
fontFamily: ol.expr.parse('fontFamilyAttr'),
|
||||
fontSize: ol.expr.parse('fontSizeAttr'),
|
||||
text: ol.expr.parse('textAttr'),
|
||||
opacity: ol.expr.parse('opacityAttr')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
colorAttr: '#ff0000',
|
||||
fontFamilyAttr: 'Dingbats',
|
||||
fontSizeAttr: 43,
|
||||
textAttr: 'Test',
|
||||
opacityAttr: 0.4
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.TextLiteral);
|
||||
expect(literal.color).to.be('#ff0000');
|
||||
expect(literal.fontFamily).to.be('Dingbats');
|
||||
expect(literal.fontSize).to.be(43);
|
||||
expect(literal.text).to.be('Test');
|
||||
expect(literal.opacity).to.be(0.4);
|
||||
});
|
||||
|
||||
it('can be called without a feature', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
color: ol.expr.parse('"#ff0000"'),
|
||||
fontFamily: ol.expr.parse('"Arial"'),
|
||||
fontSize: ol.expr.parse('11'),
|
||||
text: ol.expr.parse('"Test"'),
|
||||
opacity: ol.expr.parse('0.6')
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.TextLiteral);
|
||||
expect(literal.color).to.be('#ff0000');
|
||||
expect(literal.fontFamily).to.be('Arial');
|
||||
expect(literal.fontSize).to.be(11);
|
||||
expect(literal.text).to.be('Test');
|
||||
expect(literal.opacity).to.be(0.6);
|
||||
});
|
||||
|
||||
it('applies defaults if none provided', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
text: 'Test'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.TextLiteral);
|
||||
expect(literal.color).to.be('#000');
|
||||
expect(literal.fontFamily).to.be('sans-serif');
|
||||
expect(literal.fontSize).to.be(10);
|
||||
expect(literal.fontWeight).to.be('normal');
|
||||
expect(literal.text).to.be('Test');
|
||||
expect(literal.opacity).to.be(1);
|
||||
});
|
||||
|
||||
it('casts size to number', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
text: 'test',
|
||||
fontSize: ol.expr.parse('size')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
size: '42'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal.fontSize).to.be(42);
|
||||
});
|
||||
|
||||
it('casts opacity to number', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
text: 'test',
|
||||
opacity: ol.expr.parse('opacity')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
opacity: '0.42'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal.opacity).to.be(0.42);
|
||||
});
|
||||
|
||||
it('evaluates stroke expressions', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
text: 'test',
|
||||
stroke: new ol.style.Stroke({
|
||||
width: ol.expr.parse('strokeWidth')
|
||||
})
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
strokeWidth: '4.2'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal.strokeWidth).to.be(4.2);
|
||||
});
|
||||
|
||||
it('applies stroke defaults', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
text: 'test',
|
||||
stroke: new ol.style.Stroke({
|
||||
width: 2
|
||||
})
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral();
|
||||
expect(literal.strokeWidth).to.be(2);
|
||||
expect(literal.strokeColor).to.be('#696969');
|
||||
expect(literal.strokeOpacity).to.be(0.75);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getColor()', function() {
|
||||
|
||||
it('returns the text color', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
var color = symbolizer.getColor();
|
||||
expect(color).to.be.a(ol.expr.Literal);
|
||||
expect(color.getValue()).to.be('#ff0000');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('#getFontFamily()', function() {
|
||||
|
||||
it('returns the font family', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
|
||||
var fontFamily = symbolizer.getFontFamily();
|
||||
expect(fontFamily).to.be.a(ol.expr.Literal);
|
||||
expect(fontFamily.getValue()).to.be('Arial');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getFontSize()', function() {
|
||||
|
||||
it('returns the font size', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
fontSize: 42
|
||||
});
|
||||
|
||||
var fontSize = symbolizer.getFontSize();
|
||||
expect(fontSize).to.be.a(ol.expr.Literal);
|
||||
expect(fontSize.getValue()).to.be(42);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getFontWeight()', function() {
|
||||
|
||||
it('returns the font size', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
fontWeight: 'bold'
|
||||
});
|
||||
|
||||
var fontWeight = symbolizer.getFontWeight();
|
||||
expect(fontWeight).to.be.a(ol.expr.Literal);
|
||||
expect(fontWeight.getValue()).to.be('bold');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getOpacity()', function() {
|
||||
|
||||
it('returns the opacity', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
fontSize: 1,
|
||||
opacity: 0.123
|
||||
});
|
||||
|
||||
var opacity = symbolizer.getOpacity();
|
||||
expect(opacity).to.be.a(ol.expr.Literal);
|
||||
expect(opacity.getValue()).to.be(0.123);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setColor()', function() {
|
||||
|
||||
it('sets the text color', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
symbolizer.setColor(new ol.expr.Literal('#0000ff'));
|
||||
|
||||
var color = symbolizer.getColor();
|
||||
expect(color).to.be.a(ol.expr.Literal);
|
||||
expect(color.getValue()).to.be('#0000ff');
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setColor('#0000ff');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setFontFamily()', function() {
|
||||
|
||||
it('sets the font family', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
fontFamily: '#ff0000'
|
||||
});
|
||||
|
||||
symbolizer.setFontFamily(new ol.expr.Literal('#0000ff'));
|
||||
|
||||
var fontFamily = symbolizer.getFontFamily();
|
||||
expect(fontFamily).to.be.a(ol.expr.Literal);
|
||||
expect(fontFamily.getValue()).to.be('#0000ff');
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
fontFamily: '#ff0000'
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setFontFamily('#0000ff');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setFontSize()', function() {
|
||||
|
||||
it('sets the font size', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
fontSize: 10
|
||||
});
|
||||
symbolizer.setFontSize(new ol.expr.Literal(20));
|
||||
|
||||
var fontSize = symbolizer.getFontSize();
|
||||
expect(fontSize).to.be.a(ol.expr.Literal);
|
||||
expect(fontSize.getValue()).to.be(20);
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
fontSize: 10
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setFontSize(10);
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setFontWeight()', function() {
|
||||
|
||||
it('sets the font size', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
fontWeight: 'bold'
|
||||
});
|
||||
symbolizer.setFontWeight(new ol.expr.Literal('900'));
|
||||
|
||||
var fontWeight = symbolizer.getFontWeight();
|
||||
expect(fontWeight).to.be.a(ol.expr.Literal);
|
||||
expect(fontWeight.getValue()).to.be('900');
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
fontWeight: 'lighter'
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setFontWeight('bolder');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setOpacity()', function() {
|
||||
|
||||
it('sets the opacity', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
fontSize: 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.Text({
|
||||
fontSize: 1,
|
||||
opacity: 1
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setOpacity(0.5);
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setText()', function() {
|
||||
|
||||
it('sets the text', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
fontSize: 1,
|
||||
text: 'Initial Text'
|
||||
});
|
||||
symbolizer.setText(new ol.expr.Literal('New Text'));
|
||||
|
||||
var text = symbolizer.getText();
|
||||
expect(text).to.be.a(ol.expr.Literal);
|
||||
expect(text.getValue()).to.be('New Text');
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
fontSize: 1,
|
||||
text: 'Test'
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setText('Bad');
|
||||
}).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.expr.Literal');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.Text');
|
||||
goog.require('ol.style.TextLiteral');
|
||||
Reference in New Issue
Block a user