-
-
Notifications
You must be signed in to change notification settings - Fork 35
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: Extract SLD version from SLD #696 and #925 #926
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -56,11 +56,14 @@ import { | |||||
numberExpression | ||||||
} from './Util/SldUtil'; | ||||||
|
||||||
export type SldVersion = '1.0.0' | '1.1.0'; | ||||||
const SLD_VERSIONS = ['1.0.0','1.1.0'] as const; | ||||||
|
||||||
export type SldVersion = (typeof SLD_VERSIONS)[number]; | ||||||
|
||||||
export type ConstructorParams = { | ||||||
numericFilterFields?: string[]; | ||||||
boolFilterFields?: string[]; | ||||||
/* optional for reading style (it will be guessed from sld style) and mandatory for writing */ | ||||||
sldVersion?: SldVersion; | ||||||
symbolizerUnits?: string; | ||||||
parserOptions?: X2jOptionsOptional; | ||||||
|
@@ -271,9 +274,9 @@ export class SldStyleParser implements StyleParser<string> { | |||||
|
||||||
/** | ||||||
* String indicating the SLD version to use. 1.1.0 will make use of | ||||||
* Symbology Encoding. Default ist to use SLD 1.0.0 | ||||||
* Symbology Encoding. | ||||||
*/ | ||||||
private _sldVersion: SldVersion = '1.0.0'; | ||||||
private _sldVersion: SldVersion; | ||||||
|
||||||
/** | ||||||
* Getter for _sldVersion | ||||||
|
@@ -325,6 +328,15 @@ export class SldStyleParser implements StyleParser<string> { | |||||
return new Promise<ReadStyleResult>((resolve) => { | ||||||
try { | ||||||
const sldObject = this.parser.parse(sldString); | ||||||
|
||||||
if (this._sldVersion === undefined) { | ||||||
const version = getAttribute(sldObject[0], 'version'); | ||||||
if (! SLD_VERSIONS.includes(version)) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
throw new Error(`SLD version must be ${SLD_VERSIONS.toString()}`); | ||||||
} | ||||||
this._sldVersion = version; | ||||||
} | ||||||
|
||||||
const geoStylerStyle: Style = this.sldObjectToGeoStylerStyle(sldObject); | ||||||
resolve({ | ||||||
output: geoStylerStyle | ||||||
|
@@ -1165,6 +1177,10 @@ export class SldStyleParser implements StyleParser<string> { | |||||
* @return The Promise resolving with the SLD as a string. | ||||||
*/ | ||||||
writeStyle(geoStylerStyle: Style): Promise<WriteStyleResult<string>> { | ||||||
if (this._sldVersion === undefined) { | ||||||
throw new Error('sldVersion is mandatory'); | ||||||
} | ||||||
|
||||||
return new Promise<WriteStyleResult<string>>(resolve => { | ||||||
const unsupportedProperties = this.checkForUnsupportedProperties(geoStylerStyle); | ||||||
try { | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ it('SldStyleParser is defined', () => { | |
expect(SldStyleParser).toBeDefined(); | ||
}); | ||
|
||
describe('SldStyleParser implements StyleParser', () => { | ||
describe('SldStyleParser implements StyleParser (reading)', () => { | ||
let styleParser: SldStyleParser; | ||
|
||
beforeEach(() => { | ||
|
@@ -361,6 +361,14 @@ describe('SldStyleParser implements StyleParser', () => { | |
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('SldStyleParser implements StyleParser (writing)', () => { | ||
let styleParser: SldStyleParser; | ||
|
||
beforeEach(() => { | ||
styleParser = new SldStyleParser({sldVersion: '1.0.0'}); | ||
}); | ||
|
||
describe('#writeStyle', () => { | ||
it('is defined', () => { | ||
|
@@ -924,6 +932,7 @@ describe('SldStyleParser implements StyleParser', () => { | |
|
||
it('creates the correct order in a text symbolizer', async () => { | ||
const styleParserOrder = new SldStyleParser({ | ||
sldVersion: '1.0.0', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can probably be omitted, as version 1.0.0 is set as default. |
||
builderOptions: { | ||
format: true | ||
} | ||
|
@@ -935,6 +944,7 @@ describe('SldStyleParser implements StyleParser', () => { | |
}); | ||
it('adds unsupportedProperties to the write output', async () => { | ||
const styleParserOrder = new SldStyleParser({ | ||
sldVersion: '1.0.0', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see comment above |
||
builderOptions: { | ||
format: true | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.