Skip to content

Commit

Permalink
Merge pull request #365 from IGNF/style-fill-color
Browse files Browse the repository at this point in the history
Ignore fill color property when style = no
  • Loading branch information
jansule authored Sep 13, 2022
2 parents a35d964 + 8c45e69 commit ae52033
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 27 deletions.
23 changes: 23 additions & 0 deletions data/qmls/polygon_simple_nostyle.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis>
<renderer-v2 type="RuleRenderer">
<rules key="renderer_rules">
<rule key="renderer_rule_0" symbol="0" label="QGIS Simple Symbol"/>
</rules>
<symbols>
<symbol type="fill" name="0">
<layer class="SimpleFill">
<prop k="color" v="75,255,126,128"/>
<prop k="offset_map_unit_scale" v="3x:0,0,0,0,0,0"/>
<prop k="offset_unit" v="Pixel"/>
<prop k="outline_style" v="dash"/>
<prop k="outline_width" v="4"/>
<prop k="outline_width_map_unit_scale" v="3x:0,0,0,0,0,0"/>
<prop k="outline_width_unit" v="Pixel"/>
<prop k="outline_color" v="255,7,11,128"/>
<prop k="style" v="no"/>
</layer>
</symbol>
</symbols>
</renderer-v2>
</qgis>
16 changes: 16 additions & 0 deletions data/styles/polygon_simple_nostyle.ts
Original file line number Diff line number Diff line change
@@ -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;
11 changes: 11 additions & 0 deletions src/QGISStyleParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
57 changes: 30 additions & 27 deletions src/QGISStyleParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit ae52033

Please sign in to comment.