Sizes in string
Razi91 opened this issue · 5 comments
Widths and sizes are parsed from XML as strings, then without casts, they are used in addictions. Those sizes should be parsed into float, before using in computing, like:
const radius = 0.5 * size;
to
const radius = 0.5 * parseFloat(size);
Same thing with styleParams.strokeWidth
in simpleStyles.js#28
With that fix, it works fine. But any idea how it would work with issue #36?
While I agree that it's nice to be explicit about when values are numeric, in your example above Javascript automatically converts size to a number when it's multiplied by a number.
Is this causing any bugs with a particular SLD?
I'm also not sure how this relates to issue #36.
ok, I used wrong example. Another: getSimpleStroke
returns param width: styleParams.strokeWidth || 1,
. It's not parsed, therefore width
might be string. This object is used to create style, and used for example in RegularShape: var size = 2 * (this.radius_ + strokeWidth) + 1;
. We have number * (number * string)
, result might be either wrong number (like `2 * (1 + "2") = 2 * "12") or NaN.
Tests are wrong:
expect(featureStyle.getStroke().getWidth()).to.equal('4');
We are expecting this value to be string. Test will pass, but style won't render correctly in OL (or at all, if there will be two floating points value).
Probably they changed something in OpenLayers, dropping parsing to number, but I think docs never said strings are allowed there.
https://github.com/Razi91/SLDReader/tree/cast-string-to-number – this branch solves the problem and fixes test, but I'm not sure if it's suitable solution. Works for me now.
That fix looks good to me. Can you make a pull request for it?
Sure, let me just fix my repository,
I've merged your fix. Thanks!