Cast to numbers for literals
There are times when we parse from XML without a schema (e.g. KML). In these cases, features attributes will always be strings. We can cast to number when creating literals from symbolizers and then assert `!isNaN` instead of asserting that they are numbers before.
This commit is contained in:
@@ -74,7 +74,7 @@ describe('ol.style.Text', function() {
|
||||
expect(literal.opacity).to.be(0.6);
|
||||
});
|
||||
|
||||
it('applies default type if none provided', function() {
|
||||
it('applies defaults if none provided', function() {
|
||||
var symbolizer = new ol.style.Text({
|
||||
text: 'Test'
|
||||
});
|
||||
@@ -88,6 +88,34 @@ describe('ol.style.Text', function() {
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getColor()', function() {
|
||||
|
||||
Reference in New Issue
Block a user