Skip to content

Commit

Permalink
Merge pull request #988 from sebastianfrey/987-fix-support-margin-sep…
Browse files Browse the repository at this point in the history
…arated-by-space

fix: support spaces as sperator for vendor-option graphic-margin
  • Loading branch information
jansule authored Feb 25, 2025
2 parents b5f983e + fe8db5b commit 4c36a74
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
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);
}
}
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

0 comments on commit 4c36a74

Please sign in to comment.