Merge pull request #912 from tschaub/seperate-fill-stroke
Separate fill and stroke symbolizers. Allow styles with no rules (and also support "else" symbolizers).
This commit is contained in:
@@ -106,9 +106,9 @@ describe('ol.layer.Vector', function() {
|
||||
rules: [
|
||||
new ol.style.Rule({
|
||||
symbolizers: [
|
||||
new ol.style.Line({
|
||||
strokeWidth: 2,
|
||||
strokeColor: ol.expr.parse('colorProperty'),
|
||||
new ol.style.Stroke({
|
||||
width: 2,
|
||||
color: ol.expr.parse('colorProperty'),
|
||||
opacity: 1
|
||||
})
|
||||
]
|
||||
@@ -137,20 +137,20 @@ describe('ol.layer.Vector', function() {
|
||||
var groups = layer.groupFeaturesBySymbolizerLiteral(features);
|
||||
expect(groups.length).to.be(2);
|
||||
expect(groups[0][0].length).to.be(1);
|
||||
expect(groups[0][1].strokeColor).to.be('#BADA55');
|
||||
expect(groups[0][1].color).to.be('#BADA55');
|
||||
expect(groups[1][0].length).to.be(2);
|
||||
expect(groups[1][1].strokeColor).to.be('#013');
|
||||
expect(groups[1][1].color).to.be('#013');
|
||||
});
|
||||
|
||||
it('groups equal symbolizers also when defined on features', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
strokeWidth: 3,
|
||||
strokeColor: ol.expr.parse('colorProperty'),
|
||||
var symbolizer = new ol.style.Stroke({
|
||||
width: 3,
|
||||
color: ol.expr.parse('colorProperty'),
|
||||
opacity: 1
|
||||
});
|
||||
var anotherSymbolizer = new ol.style.Line({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#BADA55',
|
||||
var anotherSymbolizer = new ol.style.Stroke({
|
||||
width: 3,
|
||||
color: '#BADA55',
|
||||
opacity: 1
|
||||
});
|
||||
var featureWithSymbolizers = new ol.Feature({
|
||||
@@ -165,9 +165,9 @@ describe('ol.layer.Vector', function() {
|
||||
features.push(featureWithSymbolizers, anotherFeatureWithSymbolizers);
|
||||
|
||||
var groups = layer.groupFeaturesBySymbolizerLiteral(features);
|
||||
expect(groups.length).to.be(3);
|
||||
expect(groups).to.have.length(3);
|
||||
expect(groups[2][0].length).to.be(2);
|
||||
expect(groups[2][1].strokeWidth).to.be(3);
|
||||
expect(groups[2][1].width).to.be(3);
|
||||
|
||||
});
|
||||
|
||||
@@ -188,6 +188,6 @@ goog.require('ol.geom.Point');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.source.Vector');
|
||||
goog.require('ol.style.Line');
|
||||
goog.require('ol.style.Rule');
|
||||
goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.Style');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
goog.provide('ol.test.parser.kml');
|
||||
goog.provide('ol.test.parser.KML');
|
||||
|
||||
describe('ol.parser.kml', function() {
|
||||
describe('ol.parser.KML', function() {
|
||||
|
||||
var parser = new ol.parser.KML();
|
||||
|
||||
@@ -165,8 +165,9 @@ describe('ol.parser.kml', function() {
|
||||
expect(obj.features[0].get('description')).to.eql('Full of text.');
|
||||
expect(obj.features[0].get('name')).to.eql('Pezinok');
|
||||
});
|
||||
it('Test line style (read / write)', function() {
|
||||
var test_style = '<kml xmlns="http://www.opengis.net/kml/2.2" ' +
|
||||
|
||||
it('handles line style (read / write)', function() {
|
||||
var kml = '<kml xmlns="http://www.opengis.net/kml/2.2" ' +
|
||||
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
|
||||
'xsi:schemaLocation="http://www.opengis.net/kml/2.2 ' +
|
||||
'http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd"> ' +
|
||||
@@ -175,16 +176,24 @@ describe('ol.parser.kml', function() {
|
||||
'<coordinates> -112,36 -113,37 </coordinates> </LineString>' +
|
||||
'</Placemark></Document></kml>';
|
||||
var p = new ol.parser.KML({extractStyles: true});
|
||||
var obj = p.read(test_style);
|
||||
var obj = p.read(kml);
|
||||
var output = p.write(obj);
|
||||
expect(goog.dom.xml.loadXml(test_style)).to.xmleql(
|
||||
expect(goog.dom.xml.loadXml(kml)).to.xmleql(
|
||||
goog.dom.xml.loadXml(output));
|
||||
var symbolizer = obj.features[0].getSymbolizerLiterals()[0];
|
||||
expect(symbolizer instanceof ol.style.LineLiteral).to.be.ok();
|
||||
expect(symbolizer.strokeColor).to.eql('#ff0000');
|
||||
expect(symbolizer.strokeOpacity).to.eql(0.5294117647058824);
|
||||
expect(symbolizer.strokeWidth).to.eql(10);
|
||||
|
||||
var symbolizers = obj.features[0].getSymbolizers();
|
||||
expect(symbolizers).to.have.length(1);
|
||||
|
||||
var stroke = symbolizers[0];
|
||||
expect(stroke).to.be.a(ol.style.Stroke);
|
||||
|
||||
var literal = stroke.createLiteral(ol.geom.GeometryType.LINESTRING);
|
||||
expect(literal).to.be.a(ol.style.LineLiteral);
|
||||
expect(literal.color).to.eql('#ff0000');
|
||||
expect(literal.opacity).to.eql(0.5294117647058824);
|
||||
expect(literal.width).to.eql(10);
|
||||
});
|
||||
|
||||
it('reads PolyStyle fill', function() {
|
||||
var kml = '<kml xmlns="http://www.opengis.net/kml/2.2">' +
|
||||
'<Document><Placemark> <Style> <PolyStyle> <fill>1</fill> ' +
|
||||
@@ -203,11 +212,34 @@ describe('ol.parser.kml', function() {
|
||||
'</outerBoundaryIs></Polygon></Placemark></Document></kml>';
|
||||
var p = new ol.parser.KML({extractStyles: true});
|
||||
var obj = p.read(kml);
|
||||
var symbolizer1 = obj.features[0].getSymbolizerLiterals()[0];
|
||||
var symbolizer2 = obj.features[1].getSymbolizerLiterals()[0];
|
||||
expect(symbolizer1.strokeColor).to.be('#ff0000');
|
||||
expect(symbolizer2.fillOpacity).to.be(undefined);
|
||||
|
||||
var symbolizers = obj.features[0].getSymbolizers();
|
||||
expect(symbolizers).to.have.length(2);
|
||||
expect(symbolizers[0]).to.be.a(ol.style.Fill);
|
||||
expect(symbolizers[1]).to.be.a(ol.style.Stroke);
|
||||
|
||||
var literals = ol.style.Style.createLiterals(
|
||||
symbolizers, ol.geom.GeometryType.POLYGON);
|
||||
expect(literals).to.have.length(1);
|
||||
|
||||
var literal = literals[0];
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.fillColor).to.be('#ff0000');
|
||||
expect(literal.strokeColor).to.be('#ff0000');
|
||||
|
||||
symbolizers = obj.features[1].getSymbolizers();
|
||||
expect(symbolizers).to.have.length(1);
|
||||
expect(symbolizers[0]).to.be.a(ol.style.Stroke);
|
||||
|
||||
var literals = ol.style.Style.createLiterals(
|
||||
symbolizers, ol.geom.GeometryType.POLYGON);
|
||||
expect(literals).to.have.length(1);
|
||||
|
||||
literal = literals[0];
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.fillColor).to.be(undefined);
|
||||
});
|
||||
|
||||
it('writes PolyStyle fill and outline', function() {
|
||||
var kml = '<kml xmlns="http://www.opengis.net/kml/2.2" ' +
|
||||
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
|
||||
@@ -226,18 +258,28 @@ describe('ol.parser.kml', function() {
|
||||
expect(goog.dom.xml.loadXml(kml)).to.xmleql(
|
||||
goog.dom.xml.loadXml(output));
|
||||
});
|
||||
it('Test iconStyle (read / write)', function(done) {
|
||||
|
||||
it('handles iconStyle (read / write)', function(done) {
|
||||
var url = 'spec/ol/parser/kml/iconstyle.kml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.KML({extractStyles: true});
|
||||
var obj = p.read(xml);
|
||||
var output = p.write(obj);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
var symbolizer = obj.features[0].getSymbolizerLiterals()[0];
|
||||
|
||||
var symbolizers = obj.features[0].getSymbolizers();
|
||||
expect(symbolizers).to.have.length(1);
|
||||
|
||||
var symbolizer = symbolizers[0];
|
||||
expect(symbolizer).to.be.a(ol.style.Icon);
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
|
||||
var url = 'http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png';
|
||||
expect(symbolizer.url).to.eql(url);
|
||||
expect(symbolizer.width).to.eql(32);
|
||||
expect(symbolizer.height).to.eql(32);
|
||||
expect(literal.url).to.eql(url);
|
||||
expect(literal.width).to.eql(32);
|
||||
expect(literal.height).to.eql(32);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -295,6 +337,7 @@ goog.require('goog.array');
|
||||
goog.require('goog.dom.xml');
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.GeometryCollection');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
@@ -302,4 +345,10 @@ goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.parser.KML');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.Icon');
|
||||
goog.require('ol.style.IconLiteral');
|
||||
goog.require('ol.style.LineLiteral');
|
||||
goog.require('ol.style.PolygonLiteral');
|
||||
goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.Style');
|
||||
|
||||
164
test/spec/ol/style/fillsymbolizer.test.js
Normal file
164
test/spec/ol/style/fillsymbolizer.test.js
Normal file
@@ -0,0 +1,164 @@
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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('#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');
|
||||
71
test/spec/ol/style/iconliteral.test.js
Normal file
71
test/spec/ol/style/iconliteral.test.js
Normal file
@@ -0,0 +1,71 @@
|
||||
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'
|
||||
});
|
||||
var equalLiteral = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
var differentLiteral1 = new ol.style.IconLiteral({
|
||||
height: 11,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
var differentLiteral2 = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 2,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
var differentLiteral3 = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 0.5,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
var differentLiteral4 = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.2,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
var differentLiteral5 = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/2.png'
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).to.be(true);
|
||||
expect(literal.equals(differentLiteral1)).to.be(false);
|
||||
expect(literal.equals(differentLiteral2)).to.be(false);
|
||||
expect(literal.equals(differentLiteral3)).to.be(false);
|
||||
expect(literal.equals(differentLiteral4)).to.be(false);
|
||||
expect(literal.equals(differentLiteral5)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
goog.require('ol.style.IconLiteral');
|
||||
@@ -1,71 +1,5 @@
|
||||
goog.provide('ol.test.style.Icon');
|
||||
|
||||
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'
|
||||
});
|
||||
var equalLiteral = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
var differentLiteral1 = new ol.style.IconLiteral({
|
||||
height: 11,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
var differentLiteral2 = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 2,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
var differentLiteral3 = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 0.5,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
var differentLiteral4 = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.2,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
var differentLiteral5 = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/2.png'
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).to.be(true);
|
||||
expect(literal.equals(differentLiteral1)).to.be(false);
|
||||
expect(literal.equals(differentLiteral2)).to.be(false);
|
||||
expect(literal.equals(differentLiteral3)).to.be(false);
|
||||
expect(literal.equals(differentLiteral4)).to.be(false);
|
||||
expect(literal.equals(differentLiteral5)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.style.Icon', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
@@ -110,7 +44,8 @@ describe('ol.style.Icon', function() {
|
||||
widthAttr: 0.42,
|
||||
opacityAttr: 0.5,
|
||||
rotationAttr: 123,
|
||||
urlAttr: 'http://example.com/1.png'
|
||||
urlAttr: 'http://example.com/1.png',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
@@ -131,7 +66,7 @@ describe('ol.style.Icon', function() {
|
||||
url: ol.expr.parse('"http://example.com/1.png"')
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral();
|
||||
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);
|
||||
@@ -147,7 +82,7 @@ describe('ol.style.Icon', function() {
|
||||
url: ol.expr.parse('"http://example.com/1.png"')
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral();
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.opacity).to.be(1);
|
||||
expect(literal.rotation).to.be(0);
|
||||
@@ -397,5 +332,7 @@ 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');
|
||||
@@ -1,206 +0,0 @@
|
||||
goog.provide('ol.test.style.Line');
|
||||
|
||||
describe('ol.style.LineLiteral', function() {
|
||||
|
||||
describe('#equals()', function() {
|
||||
|
||||
it('identifies equal literals', function() {
|
||||
var literal = new ol.style.LineLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#BADA55',
|
||||
strokeOpacity: 1
|
||||
});
|
||||
var equalLiteral = new ol.style.LineLiteral({
|
||||
strokeColor: '#BADA55',
|
||||
strokeWidth: 3,
|
||||
strokeOpacity: 1
|
||||
});
|
||||
var differentLiteral = new ol.style.LineLiteral({
|
||||
strokeColor: '#013',
|
||||
strokeWidth: 3,
|
||||
strokeOpacity: 1
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).to.be(true);
|
||||
expect(literal.equals(differentLiteral)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.style.Line', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('accepts literal values', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
strokeColor: '#BADA55',
|
||||
strokeWidth: 3
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Line);
|
||||
});
|
||||
|
||||
it('accepts expressions', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
strokeOpacity: ol.expr.parse('value / 100'),
|
||||
strokeWidth: ol.expr.parse('widthAttr')
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Line);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#createLiteral()', function() {
|
||||
|
||||
it('evaluates expressions with the given feature', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
strokeOpacity: ol.expr.parse('value / 100'),
|
||||
strokeWidth: ol.expr.parse('widthAttr')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
value: 42,
|
||||
widthAttr: 1.5
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.LineLiteral);
|
||||
expect(literal.strokeOpacity).to.be(42 / 100);
|
||||
expect(literal.strokeWidth).to.be(1.5);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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('#getStrokeOpacity()', function() {
|
||||
|
||||
it('returns the stroke opacity', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
strokeOpacity: 0.123
|
||||
});
|
||||
|
||||
var opacity = symbolizer.getStrokeOpacity();
|
||||
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('#setStrokeOpacity()', function() {
|
||||
|
||||
it('sets the stroke opacity', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
strokeOpacity: 0.123
|
||||
});
|
||||
symbolizer.setStrokeOpacity(new ol.expr.Literal(0.321));
|
||||
|
||||
var opacity = symbolizer.getStrokeOpacity();
|
||||
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({
|
||||
strokeOpacity: 1
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setStrokeOpacity(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');
|
||||
43
test/spec/ol/style/lineliteral.test.js
Normal file
43
test/spec/ol/style/lineliteral.test.js
Normal file
@@ -0,0 +1,43 @@
|
||||
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
|
||||
});
|
||||
var equalLiteral = new ol.style.LineLiteral({
|
||||
color: '#BADA55',
|
||||
width: 3,
|
||||
opacity: 1
|
||||
});
|
||||
var differentColor = new ol.style.LineLiteral({
|
||||
width: 3,
|
||||
color: '#ff0000',
|
||||
opacity: 1
|
||||
});
|
||||
var differentWidth = new ol.style.LineLiteral({
|
||||
width: 3.5,
|
||||
color: '#BADA55',
|
||||
opacity: 1
|
||||
});
|
||||
var differentOpacity = new ol.style.LineLiteral({
|
||||
width: 3,
|
||||
color: '#BADA55',
|
||||
opacity: 0.5
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).to.be(true);
|
||||
expect(literal.equals(differentColor)).to.be(false);
|
||||
expect(literal.equals(differentWidth)).to.be(false);
|
||||
expect(literal.equals(differentOpacity)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.style.LineLiteral');
|
||||
@@ -1,317 +0,0 @@
|
||||
goog.provide('ol.test.style.Polygon');
|
||||
|
||||
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
|
||||
});
|
||||
var equalLiteral = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3
|
||||
});
|
||||
var differentStrokeWidth = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 5,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3
|
||||
});
|
||||
var differentStrokeColor = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#ffff00',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3
|
||||
});
|
||||
var differentStrokeOpacity = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.41,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3
|
||||
});
|
||||
var differentFillColor = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#00ffff',
|
||||
fillOpacity: 0.3
|
||||
});
|
||||
var differentFillOpacity = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.31
|
||||
});
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.style.Polygon', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('accepts literal values', function() {
|
||||
var symbolizer = new ol.style.Polygon({
|
||||
fillColor: '#BADA55',
|
||||
strokeWidth: 3
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Polygon);
|
||||
});
|
||||
|
||||
it('accepts expressions', function() {
|
||||
var symbolizer = new ol.style.Polygon({
|
||||
fillOpacity: ol.expr.parse('value / 100'),
|
||||
fillColor: ol.expr.parse('fillAttr')
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Polygon);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#createLiteral()', function() {
|
||||
|
||||
it('evaluates expressions with the given feature', function() {
|
||||
var symbolizer = new ol.style.Polygon({
|
||||
fillOpacity: ol.expr.parse('value / 100'),
|
||||
fillColor: ol.expr.parse('fillAttr')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
value: 42,
|
||||
fillAttr: '#ff0000'
|
||||
});
|
||||
|
||||
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.strokeColor).to.be(undefined);
|
||||
});
|
||||
|
||||
it('applies default strokeWidth if only strokeColor is given', function() {
|
||||
var symbolizer = new ol.style.Polygon({
|
||||
strokeColor: '#ff0000'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral();
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.strokeColor).to.be('#ff0000');
|
||||
expect(literal.strokeWidth).to.be(1.5);
|
||||
expect(literal.fillColor).to.be(undefined);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getFillColor()', function() {
|
||||
|
||||
it('returns the fill color', function() {
|
||||
var symbolizer = new ol.style.Polygon({
|
||||
fillColor: '#ff0000'
|
||||
});
|
||||
|
||||
var fillColor = symbolizer.getFillColor();
|
||||
expect(fillColor).to.be.a(ol.expr.Literal);
|
||||
expect(fillColor.getValue()).to.be('#ff0000');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getFillOpacity()', function() {
|
||||
|
||||
it('returns the fill opacity', function() {
|
||||
var symbolizer = new ol.style.Polygon({
|
||||
fillColor: '#ffffff',
|
||||
fillOpacity: 0.123
|
||||
});
|
||||
|
||||
var opacity = symbolizer.getFillOpacity();
|
||||
expect(opacity).to.be.a(ol.expr.Literal);
|
||||
expect(opacity.getValue()).to.be(0.123);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getStrokeColor()', function() {
|
||||
|
||||
it('returns the stroke color', function() {
|
||||
var symbolizer = new ol.style.Polygon({
|
||||
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.Polygon({
|
||||
strokeWidth: 10
|
||||
});
|
||||
|
||||
var strokeWidth = symbolizer.getStrokeWidth();
|
||||
expect(strokeWidth).to.be.a(ol.expr.Literal);
|
||||
expect(strokeWidth.getValue()).to.be(10);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getStrokeOpacity()', function() {
|
||||
|
||||
it('returns the stroke opacity', function() {
|
||||
var symbolizer = new ol.style.Polygon({
|
||||
strokeWidth: 1,
|
||||
strokeOpacity: 0.123
|
||||
});
|
||||
|
||||
var opacity = symbolizer.getStrokeOpacity();
|
||||
expect(opacity).to.be.a(ol.expr.Literal);
|
||||
expect(opacity.getValue()).to.be(0.123);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setFillColor()', function() {
|
||||
|
||||
it('sets the fill color', function() {
|
||||
var symbolizer = new ol.style.Polygon({
|
||||
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.Polygon({
|
||||
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.Polygon({
|
||||
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.Polygon({
|
||||
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.Polygon({
|
||||
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.Polygon({
|
||||
strokeWidth: 10
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setStrokeWidth(10);
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setStrokeOpacity()', function() {
|
||||
|
||||
it('sets the stroke opacity', function() {
|
||||
var symbolizer = new ol.style.Polygon({
|
||||
strokeWidth: 1,
|
||||
strokeOpacity: 0.123
|
||||
});
|
||||
symbolizer.setStrokeOpacity(new ol.expr.Literal(0.321));
|
||||
|
||||
var opacity = symbolizer.getStrokeOpacity();
|
||||
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.Polygon({
|
||||
strokeWidth: 1,
|
||||
strokeOpacity: 1
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setStrokeOpacity(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.Polygon');
|
||||
goog.require('ol.style.PolygonLiteral');
|
||||
70
test/spec/ol/style/polygonliteral.test.js
Normal file
70
test/spec/ol/style/polygonliteral.test.js
Normal file
@@ -0,0 +1,70 @@
|
||||
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
|
||||
});
|
||||
var equalLiteral = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3
|
||||
});
|
||||
var differentStrokeWidth = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 5,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3
|
||||
});
|
||||
var differentStrokeColor = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#ffff00',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3
|
||||
});
|
||||
var differentStrokeOpacity = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.41,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3
|
||||
});
|
||||
var differentFillColor = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#00ffff',
|
||||
fillOpacity: 0.3
|
||||
});
|
||||
var differentFillOpacity = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.31
|
||||
});
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.style.PolygonLiteral');
|
||||
@@ -1,424 +0,0 @@
|
||||
goog.provide('ol.test.style.Shape');
|
||||
|
||||
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
|
||||
});
|
||||
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
|
||||
});
|
||||
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
|
||||
});
|
||||
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
|
||||
});
|
||||
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
|
||||
});
|
||||
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
|
||||
});
|
||||
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
|
||||
});
|
||||
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
|
||||
});
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.style.Shape', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('accepts literal values', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: 4,
|
||||
fillColor: '#BADA55'
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Shape);
|
||||
});
|
||||
|
||||
it('accepts expressions', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: ol.expr.parse('sizeAttr'),
|
||||
strokeColor: ol.expr.parse('color')
|
||||
});
|
||||
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'),
|
||||
fillOpacity: ol.expr.parse('opacityAttr'),
|
||||
fillColor: '#BADA55'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
sizeAttr: 42,
|
||||
opacityAttr: 0.4
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
it('can be called without a feature', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: 10,
|
||||
fillColor: '#BADA55',
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 1,
|
||||
strokeWidth: 2
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral();
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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('#getFillOpacity()', function() {
|
||||
|
||||
it('returns the fill opacity', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
fillOpacity: 0.123
|
||||
});
|
||||
|
||||
var opacity = symbolizer.getFillOpacity();
|
||||
expect(opacity).to.be.a(ol.expr.Literal);
|
||||
expect(opacity.getValue()).to.be(0.123);
|
||||
});
|
||||
|
||||
it('returns the default if none provided', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
fillColor: '#ffffff'
|
||||
});
|
||||
|
||||
var opacity = symbolizer.getFillOpacity();
|
||||
expect(opacity).to.be.a(ol.expr.Literal);
|
||||
expect(opacity.getValue()).to.be(0.4);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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('#getStrokeOpacity()', function() {
|
||||
|
||||
it('returns the stroke opacity', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
strokeWidth: 1,
|
||||
strokeOpacity: 0.123
|
||||
});
|
||||
|
||||
var opacity = symbolizer.getStrokeOpacity();
|
||||
expect(opacity).to.be.a(ol.expr.Literal);
|
||||
expect(opacity.getValue()).to.be(0.123);
|
||||
});
|
||||
|
||||
it('returns the default if none provided', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
strokeWidth: 1
|
||||
});
|
||||
|
||||
var opacity = symbolizer.getStrokeOpacity();
|
||||
expect(opacity).to.be.a(ol.expr.Literal);
|
||||
expect(opacity.getValue()).to.be(0.8);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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('#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('#setFillOpacity()', function() {
|
||||
|
||||
it('sets the fill opacity', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
fillOpacity: 0.5
|
||||
});
|
||||
|
||||
symbolizer.setFillOpacity(new ol.expr.Literal(0.6));
|
||||
|
||||
var fillOpacity = symbolizer.getFillOpacity();
|
||||
expect(fillOpacity).to.be.a(ol.expr.Literal);
|
||||
expect(fillOpacity.getValue()).to.be(0.6);
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
fillOpacity: 0.5
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setFillOpacity(0.4);
|
||||
}).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('#setStrokeOpacity()', function() {
|
||||
|
||||
it('sets the stroke opacity', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
strokeWidth: 1,
|
||||
strokeOpacity: 0.123
|
||||
});
|
||||
symbolizer.setStrokeOpacity(new ol.expr.Literal(0.321));
|
||||
|
||||
var opacity = symbolizer.getStrokeOpacity();
|
||||
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,
|
||||
strokeOpacity: 1
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setStrokeOpacity(0.5);
|
||||
}).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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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');
|
||||
94
test/spec/ol/style/shapeliteral.test.js
Normal file
94
test/spec/ol/style/shapeliteral.test.js
Normal file
@@ -0,0 +1,94 @@
|
||||
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
|
||||
});
|
||||
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
|
||||
});
|
||||
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
|
||||
});
|
||||
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
|
||||
});
|
||||
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
|
||||
});
|
||||
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
|
||||
});
|
||||
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
|
||||
});
|
||||
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
|
||||
});
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.style.ShapeLiteral');
|
||||
goog.require('ol.style.ShapeType');
|
||||
203
test/spec/ol/style/shapesymbolizer.test.js
Normal file
203
test/spec/ol/style/shapesymbolizer.test.js
Normal file
@@ -0,0 +1,203 @@
|
||||
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);
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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.Shape');
|
||||
goog.require('ol.style.ShapeLiteral');
|
||||
goog.require('ol.style.ShapeType');
|
||||
goog.require('ol.style.Stroke');
|
||||
191
test/spec/ol/style/strokesymbolizer.test.js
Normal file
191
test/spec/ol/style/strokesymbolizer.test.js
Normal file
@@ -0,0 +1,191 @@
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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');
|
||||
@@ -2,10 +2,40 @@ goog.provide('ol.test.style.Style');
|
||||
|
||||
describe('ol.style.Style', function() {
|
||||
|
||||
describe('#apply()', function() {
|
||||
describe('constructor', function() {
|
||||
|
||||
it('applies a style to a feature', 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({
|
||||
@@ -13,58 +43,254 @@ describe('ol.style.Style', function() {
|
||||
symbolizers: [
|
||||
new ol.style.Shape({
|
||||
size: 4,
|
||||
fillColor: '#BADA55'
|
||||
fill: new ol.style.Fill({
|
||||
color: ol.expr.parse('fillColor')
|
||||
})
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
});
|
||||
var feature = new ol.Feature();
|
||||
var feature = new ol.Feature({
|
||||
fillColor: '#BADA55',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
feature.set('foo', 'bar');
|
||||
expect(style.apply(feature).length).to.be(1);
|
||||
expect(style.apply(feature)[0].fillColor).to.be('#BADA55');
|
||||
|
||||
var literals = style.createLiterals(feature);
|
||||
expect(literals).to.have.length(1);
|
||||
expect(literals[0].fillColor).to.be('#BADA55');
|
||||
|
||||
feature.set('foo', 'baz');
|
||||
expect(style.apply(feature).length).to.be(0);
|
||||
expect(style.createLiterals(feature)).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);
|
||||
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);
|
||||
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);
|
||||
expect(literals).to.have.length(1);
|
||||
expect(literals[0].color).to.be('#ff00ff');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.style.Style.applyDefaultStyle()', function() {
|
||||
describe('ol.style.Style.defaults.createLiterals(feature)', function() {
|
||||
var feature = new ol.Feature();
|
||||
|
||||
it('returns an empty array for features without geometry', function() {
|
||||
expect(ol.style.Style.applyDefaultStyle(feature).length).to.be(0);
|
||||
expect(ol.style.Style.defaults.createLiterals(feature))
|
||||
.to.have.length(0);
|
||||
});
|
||||
|
||||
it('returns an array with the Shape default for points', function() {
|
||||
feature.setGeometry(new ol.geom.Point([0, 0]));
|
||||
var symbolizers = ol.style.Style.applyDefaultStyle(feature);
|
||||
expect(symbolizers.length).to.be(1);
|
||||
expect(symbolizers[0]).to.be.a(ol.style.ShapeLiteral);
|
||||
expect(symbolizers[0].equals(ol.style.ShapeDefaults)).to.be(true);
|
||||
|
||||
var literals = ol.style.Style.defaults.createLiterals(feature);
|
||||
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() {
|
||||
feature.setGeometry(new ol.geom.LineString([[0, 0], [1, 1]]));
|
||||
expect(ol.style.Style.applyDefaultStyle(feature)[0]
|
||||
.equals(ol.style.LineDefaults)).to.be(true);
|
||||
|
||||
var literals = ol.style.Style.defaults.createLiterals(feature);
|
||||
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() {
|
||||
feature.setGeometry(new ol.geom.Polygon([[[0, 0], [1, 1], [0, 0]]]));
|
||||
expect(ol.style.Style.applyDefaultStyle(feature)[0]
|
||||
.equals(ol.style.PolygonDefaults)).to.be(true);
|
||||
|
||||
var literals = ol.style.Style.defaults.createLiterals(feature);
|
||||
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
|
||||
}),
|
||||
new ol.style.PolygonLiteral({
|
||||
strokeColor: '#00ff00',
|
||||
strokeOpacity: 0.6,
|
||||
strokeWidth: 3
|
||||
})
|
||||
];
|
||||
|
||||
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
|
||||
}),
|
||||
new ol.style.PolygonLiteral({
|
||||
strokeColor: '#0000ff',
|
||||
strokeOpacity: 0.7,
|
||||
strokeWidth: 1
|
||||
})
|
||||
];
|
||||
|
||||
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
|
||||
}),
|
||||
new ol.style.PolygonLiteral({
|
||||
fillColor: '#ff0000',
|
||||
fillOpacity: 0.5
|
||||
}),
|
||||
new ol.style.TextLiteral({
|
||||
color: '#ffffff',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
text: 'Test',
|
||||
opacity: 0.5
|
||||
})
|
||||
];
|
||||
|
||||
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.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');
|
||||
|
||||
69
test/spec/ol/style/textliteral.test.js
Normal file
69
test/spec/ol/style/textliteral.test.js
Normal file
@@ -0,0 +1,69 @@
|
||||
goog.provide('ol.test.style.TextLiteral');
|
||||
|
||||
describe('ol.style.TextLiteral', function() {
|
||||
|
||||
describe('#equals()', function() {
|
||||
|
||||
it('identifies equal literals', function() {
|
||||
var literal = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
text: 'Test',
|
||||
opacity: 0.5
|
||||
});
|
||||
var equalLiteral = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
text: 'Test',
|
||||
opacity: 0.5
|
||||
});
|
||||
var differentLiteral1 = new ol.style.TextLiteral({
|
||||
color: '#0000ff',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
text: 'Test',
|
||||
opacity: 0.5
|
||||
});
|
||||
var differentLiteral2 = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Dingbats',
|
||||
fontSize: 11,
|
||||
text: 'Test',
|
||||
opacity: 0.5
|
||||
});
|
||||
var differentLiteral3 = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 12,
|
||||
text: 'Test',
|
||||
opacity: 0.5
|
||||
});
|
||||
var differentLiteral4 = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
text: 'Test',
|
||||
opacity: 0.6
|
||||
});
|
||||
var equalLiteral2 = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
text: 'Text is not compared for equality',
|
||||
opacity: 0.5
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).to.be(true);
|
||||
expect(literal.equals(differentLiteral1)).to.be(false);
|
||||
expect(literal.equals(differentLiteral2)).to.be(false);
|
||||
expect(literal.equals(differentLiteral3)).to.be(false);
|
||||
expect(literal.equals(differentLiteral4)).to.be(false);
|
||||
expect(literal.equals(equalLiteral2)).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.style.TextLiteral');
|
||||
@@ -1,71 +1,5 @@
|
||||
goog.provide('ol.test.style.Text');
|
||||
|
||||
describe('ol.style.TextLiteral', function() {
|
||||
|
||||
describe('#equals()', function() {
|
||||
|
||||
it('identifies equal literals', function() {
|
||||
var literal = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
text: 'Test',
|
||||
opacity: 0.5
|
||||
});
|
||||
var equalLiteral = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
text: 'Test',
|
||||
opacity: 0.5
|
||||
});
|
||||
var differentLiteral1 = new ol.style.TextLiteral({
|
||||
color: '#0000ff',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
text: 'Test',
|
||||
opacity: 0.5
|
||||
});
|
||||
var differentLiteral2 = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Dingbats',
|
||||
fontSize: 11,
|
||||
text: 'Test',
|
||||
opacity: 0.5
|
||||
});
|
||||
var differentLiteral3 = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 12,
|
||||
text: 'Test',
|
||||
opacity: 0.5
|
||||
});
|
||||
var differentLiteral4 = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
text: 'Test',
|
||||
opacity: 0.6
|
||||
});
|
||||
var equalLiteral2 = new ol.style.TextLiteral({
|
||||
color: '#ff0000',
|
||||
fontFamily: 'Arial',
|
||||
fontSize: 11,
|
||||
text: 'Text is not compared for equality',
|
||||
opacity: 0.5
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).to.be(true);
|
||||
expect(literal.equals(differentLiteral1)).to.be(false);
|
||||
expect(literal.equals(differentLiteral2)).to.be(false);
|
||||
expect(literal.equals(differentLiteral3)).to.be(false);
|
||||
expect(literal.equals(differentLiteral4)).to.be(false);
|
||||
expect(literal.equals(equalLiteral2)).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.style.Text', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
@@ -131,7 +65,7 @@ describe('ol.style.Text', function() {
|
||||
opacity: ol.expr.parse('0.6')
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral();
|
||||
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');
|
||||
@@ -145,7 +79,7 @@ describe('ol.style.Text', function() {
|
||||
text: 'Test'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral();
|
||||
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');
|
||||
@@ -363,5 +297,6 @@ 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.Text');
|
||||
goog.require('ol.style.TextLiteral');
|
||||
Reference in New Issue
Block a user