Skip to content

Commit

Permalink
feat: add vendor-option graphic-margin
Browse files Browse the repository at this point in the history
  • Loading branch information
ger-benjamin committed Dec 3, 2024
1 parent 0093c6b commit 2fd05bc
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 11 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"fast-xml-parser": "^4.4.1",
"geostyler-style": "^9.1.0",
"geostyler-style": "^9.2.0",
"lodash": "^4.17.21"
},
"devDependencies": {
Expand Down
66 changes: 60 additions & 6 deletions src/SldStyleParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export type ConstructorParams = {
boolFilterFields?: string[];
/* optional for reading style (it will be guessed from sld style) and mandatory for writing */
sldVersion?: SldVersion;
withVendorOption?: boolean;
symbolizerUnits?: string;
parserOptions?: ParserOptions;
builderOptions?: XmlBuilderOptions;
Expand Down Expand Up @@ -275,6 +276,7 @@ export class SldStyleParser implements StyleParser<string> {
preserveOrder: true,
trimValues: true
});

this.builder = new XMLBuilder({
...opts?.builderOptions,
// Fixed attributes
Expand All @@ -283,10 +285,16 @@ export class SldStyleParser implements StyleParser<string> {
suppressEmptyNode: true,
preserveOrder: true
});

if (opts?.sldVersion) {
this.sldVersion = opts?.sldVersion;
}

this.withVendorOption = true; // FIXME !
if (opts?.withVendorOption !== undefined) {
this.withVendorOption = opts.withVendorOption;
}

if (opts?.locale) {
this.locale = opts.locale;
}
Expand Down Expand Up @@ -386,6 +394,26 @@ export class SldStyleParser implements StyleParser<string> {
this._sldVersion = sldVersion;
}

/**
* Indicates whether additional GeoServer vendorOption should be included in
* sld write operations. Set to `false` by default.
*/
private _withVendorOption = false;

/**
* Getter for _withVendorOption
*/
get withVendorOption(): boolean {
return this._withVendorOption;
}

/**
* Setter for _withVendorOption
*/
set withVendorOption(withVendorOption: boolean) {
this._withVendorOption = withVendorOption;
}


/**
* String indicating the SLD version used in reading mode
Expand Down Expand Up @@ -1865,6 +1893,31 @@ export class SldStyleParser implements StyleParser<string> {
}];
}

/**
* FIXME
*/
pushVendorOption(elementArray: any[], name: string, text: string) {
if (this.withVendorOption) {
elementArray.push(this.createVendorOption(name, text));
}
}

/**
* FIXME
* @return <VendorOption name="name">text</VendorOption>
*/
createVendorOption(name: string, text: string) {
const VendorOption = this.getTagName('VendorOption');
return {
[VendorOption]: [{
'#text': text,
}],
':@': {
'@_name': name,
}
};
}

/**
* Get the SLD Object (readable with fast-xml-parser) from a geostyler-style IconSymbolizer.
*
Expand Down Expand Up @@ -2454,16 +2507,17 @@ export class SldStyleParser implements StyleParser<string> {

const polygonSymbolizer: any = [];
if (fillCssParameters.length > 0 || graphicFill) {
if (!Array.isArray(polygonSymbolizer?.[0]?.[Fill])) {
polygonSymbolizer[0] = { [Fill]: [] };
const fillArray: any[] = [];
const graphicFillPadding = fillSymbolizer.graphicFillPadding;
if (graphicFillPadding) {
this.pushVendorOption(polygonSymbolizer, 'graphic-margin', graphicFillPadding);

Check failure on line 2513 in src/SldStyleParser.ts

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Argument of type '[number | GeoStylerNumberFunction, number | GeoStylerNumberFunction, number | GeoStylerNumberFunction, number | GeoStylerNumberFunction]' is not assignable to parameter of type 'string'.

Check failure on line 2513 in src/SldStyleParser.ts

View workflow job for this annotation

GitHub Actions / build (22.x, ubuntu-latest)

Argument of type '[number | GeoStylerNumberFunction, number | GeoStylerNumberFunction, number | GeoStylerNumberFunction, number | GeoStylerNumberFunction]' is not assignable to parameter of type 'string'.
}
polygonSymbolizer.push({ [Fill]: fillArray });
if (fillCssParameters.length > 0) {
polygonSymbolizer[0][Fill].push(...fillCssParameters);
fillArray.push(...fillCssParameters);
}
if (graphicFill) {
polygonSymbolizer[0][Fill].push({
GraphicFill: graphicFill
});
fillArray.push({ GraphicFill: graphicFill });
}
}

Expand Down

0 comments on commit 2fd05bc

Please sign in to comment.