diff --git a/data/qmls/polygon_simple_nostyle.qml b/data/qmls/polygon_simple_nostyle.qml new file mode 100644 index 00000000..1af90a75 --- /dev/null +++ b/data/qmls/polygon_simple_nostyle.qml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/styles/polygon_simple_nostyle.ts b/data/styles/polygon_simple_nostyle.ts new file mode 100644 index 00000000..4dc242d9 --- /dev/null +++ b/data/styles/polygon_simple_nostyle.ts @@ -0,0 +1,16 @@ +import { Style } from 'geostyler-style'; + +const polygonSimpleNoStyle: Style = { + name: 'QGIS Style', + rules: [{ + name: 'QGIS Simple Symbol', + symbolizers: [{ + kind: 'Fill', + outlineColor: '#FF070B', + outlineWidth: 4, + outlineDasharray: [10, 2] + }] + }] +} as Style; + +export default polygonSimpleNoStyle; diff --git a/src/QGISStyleParser.spec.ts b/src/QGISStyleParser.spec.ts index c65283a4..dd94dcca 100644 --- a/src/QGISStyleParser.spec.ts +++ b/src/QGISStyleParser.spec.ts @@ -10,8 +10,10 @@ import point_label from '../data/styles/point_label'; import point_ranges from '../data/styles/point_ranges'; import point_external_graphic from '../data/styles/point_external_graphic'; import polygon_simple from '../data/styles/polygon_simple'; +import polygon_simple_nostyle from '../data/styles/polygon_simple_nostyle'; import no_symbolizer from '../data/styles/no_symbolizer'; import text_text_buffer from '../data/styles/text_text_buffer'; +import { defaults } from 'xml2js'; it('QGISStyleParser is defined', () => { expect(QGISStyleParser).toBeDefined(); @@ -78,6 +80,15 @@ describe('QMLStyleParser implements StyleParser', () => { expect(geoStylerStyle).toEqual(polygon_simple); }); }); + describe('FillSymbolizer with no style', () => { + it('can read a simple QML FillSymbol with no style', async () => { + expect.assertions(2); + const qml = fs.readFileSync('./data/qmls/polygon_simple_nostyle.qml', 'utf8'); + const { output: geoStylerStyle } = await styleParser.readStyle(qml); + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(polygon_simple_nostyle); + }); + }); describe('Filter Parsing', () => { it('can read a rule based QML PointSymbolizer', async () => { expect.assertions(2); diff --git a/src/QGISStyleParser.ts b/src/QGISStyleParser.ts index 26260fe9..778333c4 100644 --- a/src/QGISStyleParser.ts +++ b/src/QGISStyleParser.ts @@ -576,39 +576,42 @@ export class QGISStyleParser implements StyleParser { const qmlMarkerProps: any = qmlSymbolizerLayerPropsToObject(symbolizerLayer); - if (qmlMarkerProps.outline_color) { + let outlineStyle = qmlMarkerProps?.outline_style || 'solid'; + if (qmlMarkerProps.outline_color && 'no' !== outlineStyle) { fillSymbolizer.outlineColor = this.qmlColorToHex(qmlMarkerProps.outline_color); } - if (qmlMarkerProps.color) { + + let fillStyle = qmlMarkerProps?.style || 'solid'; + if (qmlMarkerProps.color && 'solid' === fillStyle) { fillSymbolizer.opacity = this.qmlColorToOpacity(qmlMarkerProps.color); fillSymbolizer.color = this.qmlColorToHex(qmlMarkerProps.color); } - if (qmlMarkerProps.outline_style) { - switch (qmlMarkerProps.outline_style) { - case 'dot': - fillSymbolizer.outlineDasharray = outlineStyleDashArrays.dot; - break; - case 'dash': - fillSymbolizer.outlineDasharray = outlineStyleDashArrays.dash; - break; - case 'dash dot': - fillSymbolizer.outlineDasharray = [ - ...outlineStyleDashArrays.dash, - ...outlineStyleDashArrays.dot - ]; - break; - case 'dash dot dot': - fillSymbolizer.outlineDasharray = [ - ...outlineStyleDashArrays.dash, - ...outlineStyleDashArrays.dot, - ...outlineStyleDashArrays.dot - ]; - break; - default: - break; - } + + switch (outlineStyle) { + case 'dot': + fillSymbolizer.outlineDasharray = outlineStyleDashArrays.dot; + break; + case 'dash': + fillSymbolizer.outlineDasharray = outlineStyleDashArrays.dash; + break; + case 'dash dot': + fillSymbolizer.outlineDasharray = [ + ...outlineStyleDashArrays.dash, + ...outlineStyleDashArrays.dot + ]; + break; + case 'dash dot dot': + fillSymbolizer.outlineDasharray = [ + ...outlineStyleDashArrays.dash, + ...outlineStyleDashArrays.dot, + ...outlineStyleDashArrays.dot + ]; + break; + default: + break; } - if (qmlMarkerProps.outline_width) { + + if (qmlMarkerProps.outline_width && 'no' !== outlineStyle) { fillSymbolizer.outlineWidth = parseFloat(qmlMarkerProps.outline_width); }