Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support spaces as sperator for vendor-option graphic-margin #988

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions data/slds/geoserver/pattern_polygon_alternative_margin.sld
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
<NamedLayer>

<Name>Pattern polygon</Name>

<UserStyle>
<Name>pattern_polygon</Name>
<Title>Pattern polygon</Title>
<Abstract>Polygon with spaced purple circle symbols</Abstract>
<FeatureTypeStyle>
<Rule>
<Name>Polygon with spaced purple circle symbols</Name>
<Abstract>Polygon with spaced purple circle symbols</Abstract>
<PolygonSymbolizer>
<VendorOption name="graphic-margin">4 6 2 3</VendorOption>
<Fill>
<GraphicFill>
<Graphic>
<Mark>
<WellKnownName>circle</WellKnownName>
<Fill>
<CssParameter name="fill">#880088</CssParameter>
</Fill>
</Mark>
<Size>6</Size>
</Graphic>
</GraphicFill>
</Fill>
</PolygonSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
6 changes: 6 additions & 0 deletions src/SldStyleParser.geoserver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ describe('SldStyleParser implements StyleParser', () => {
expect(geoStylerStyle).toBeDefined();
expect(geoStylerStyle).toEqual(pattern_polygon);
});
it('can read the geoserver pattern_polygon_alternative_margin.sld', async () => {
const sld = fs.readFileSync('./data/slds/geoserver/pattern_polygon_alternative_margin.sld', 'utf8');
const { output: geoStylerStyle } = await styleParser.readStyle(sld);
expect(geoStylerStyle).toBeDefined();
expect(geoStylerStyle).toEqual(pattern_polygon);
});
});

describe('#writeStyle', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/SldStyleParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ export class SldStyleParser implements StyleParser<string> {
if (this.withGeoServerVendorOption) {
const graphicFillPadding = getVendorOptionValue(sldSymbolizer, 'graphic-margin');
if (!isNil(graphicFillPadding)) {
fillSymbolizer.graphicFillPadding = graphicFillPadding.split(',').map(numberExpression);
fillSymbolizer.graphicFillPadding = graphicFillPadding.split(/[,\s]/).map(numberExpression);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch @sebastianfrey! Turns out GeoServer actually expects only spaces and no commas (validating the style does not show any errors, applying it however does). Could you adjust this accordingly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jansule Adopted the write path for the graphic-margin prop. Is this the change you were looking for?

}
}
if (!isNil(color)) {
Expand Down Expand Up @@ -2559,7 +2559,7 @@ export class SldStyleParser implements StyleParser<string> {
const fillArray: any[] = [];
const graphicFillPadding = fillSymbolizer.graphicFillPadding;
if (graphicFillPadding) {
this.pushGeoServerVendorOption(polygonSymbolizer, 'graphic-margin', `${graphicFillPadding}`);
this.pushGeoServerVendorOption(polygonSymbolizer, 'graphic-margin', graphicFillPadding.join(' '));
}
polygonSymbolizer.push({ [Fill]: fillArray });
if (fillCssParameters.length > 0) {
Expand Down