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

feat: add vendor-option graphic-margin #971

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
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}`);
}
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
Loading