Skip to content

Commit

Permalink
Merge branch 'master' of github.com:geostyler/geostyler-qgis-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVolland committed Jun 7, 2021
2 parents 1d959d7 + ebbe37c commit 2d1ec68
Show file tree
Hide file tree
Showing 10 changed files with 4,270 additions and 1,636 deletions.
1 change: 1 addition & 0 deletions data/qmls/line_simple.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<prop k="joinstyle" v="round"/>
<prop k="capstyle" v="square"/>
<prop k="line_width" v="3"/>
<prop k="line_width_unit" v="Pixel"/>
<prop k="customdash" v="12;12"/>
</layer>
</symbol>
Expand Down
5 changes: 1 addition & 4 deletions data/qmls/no_symbolizer.qml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis>
<renderer-v2 type="RuleRenderer">
<rules key="renderer_rules"/>
<symbols/>
</renderer-v2>
<renderer-v2 type="nullSymbol"/>
</qgis>
5 changes: 1 addition & 4 deletions data/qmls/point_label.qml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis>
<renderer-v2 type="RuleRenderer">
<rules key="renderer_rules"/>
<symbols/>
</renderer-v2>
<renderer-v2 type="nullSymbol"/>
<labeling type="rule-based">
<rules key="labeling_rules">
<rule key="labeling_rule_0" filter="value > 0.1">
Expand Down
2 changes: 1 addition & 1 deletion data/qmls/polygon_simple.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<prop k="outline_width_map_unit_scale" v="3x:0,0,0,0,0,0"/>
<prop k="outline_width_unit" v="Pixel"/>
<prop k="customdash" v="10;2"/>
<prop k="outline_color" v="255,7,11,255"/>
<prop k="outline_color" v="255,7,11,128"/>
</layer>
</symbol>
</symbols>
Expand Down
15 changes: 15 additions & 0 deletions data/qmls/text_text_buffer.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis>
<renderer-v2 type="nullSymbol"/>
<labeling type="rule-based">
<rules key="labeling_rules">
<rule key="labeling_rule_0">
<settings>
<text-style fontSize="10.6135611907387" fontLetterSpacing="0" multilineHeight="1" textColor="0,0,0,255" fontFamily="DejaVuSans" fieldName="Sample label"/>
<placement predefinedPositionOrder="TR,TL,BR,BL,R,L,TSR,BSR" xOffset="0" yOffset="0" rotationAngle="0"/>
<text-buffer bufferSize="0.7938257993384785" bufferColor="250,250,250,255" bufferDraw="1" bufferSizeUnits="Pixel" bufferSizeMapUnitScale="3x:0,0,0,0,0,0"/>
</settings>
</rule>
</rules>
</labeling>
</qgis>
24 changes: 24 additions & 0 deletions data/styles/text_text_buffer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Style } from 'geostyler-style';

const labelSample: Style = {
name: 'roads_oneways',
rules: [
{
name: '',
scaleDenominator: { max: 1000 },
symbolizers: [
{
kind: 'Text',
label: 'Sample label',
padding: 0,
font: ['DejaVuSans'],
size: 10.6135611907387,
haloColor: '#fafafa',
haloWidth: 0.7938257993384785
}
]
}
]
} as Style;

export default labelSample;
5,776 changes: 4,173 additions & 1,603 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
"homepage": "https://github.com/geostyler/geostyler-qgis-parser#readme",
"dependencies": {
"@babel/core": "^7.10.2",
"@types/jest": "^25.2.3",
"@types/jest": "^26.0.23",
"@types/lodash": "^4.14.155",
"@types/node": "^14.0.11",
"@types/xml2js": "^0.4.5",
"color": "^3.1.2",
"geostyler-cql-parser": "^1.0.0",
"geostyler-style": "^3.0.0",
"geostyler-style": "^4.0.2",
"lodash": "^4.17.15",
"xml2js": "^0.4.23",
"xmldom": "^0.5.0"
"xmldom": "^0.6.0"
},
"scripts": {
"build:browser": "webpack --config browser-build.config.js",
Expand Down
10 changes: 10 additions & 0 deletions src/QGISStyleParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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 no_symbolizer from '../data/styles/no_symbolizer';
import text_text_buffer from '../data/styles/text_text_buffer';

it('QGISStyleParser is defined', () => {
expect(QGISStyleParser).toBeDefined();
Expand Down Expand Up @@ -163,6 +164,15 @@ describe('QMLStyleParser implements StyleParser', () => {
expect(qgisStyle).toEqual(qml.trim());
});
});
it('can write QML with text-buffer', async () => {
expect.assertions(2);
const qml = fs.readFileSync('./data/qmls/text_text_buffer.qml', 'utf8');
return styleParser.writeStyle(text_text_buffer)
.then((qgisStyle: string) => {
expect(qgisStyle).toBeDefined();
expect(qgisStyle).toEqual(qml.trim());
});
});
});
describe('LineSymbolizer', () => {
it('can write a simple QML LineSymbol', async () => {
Expand Down
62 changes: 41 additions & 21 deletions src/QGISStyleParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,8 @@ export class QGISStyleParser implements StyleParser {
offset_unit: 'Pixel',
joinstyle: symbolizer.join,
capstyle: symbolizer.cap,
line_width: symbolizer.width
line_width: symbolizer.width,
line_width_unit: 'Pixel'
};
if (symbolizer.dasharray) {
qmlProps.customdash = symbolizer.dasharray.join(';');
Expand All @@ -783,16 +784,19 @@ export class QGISStyleParser implements StyleParser {
}

getQmlFillSymbolFromSymbolizer(symbolizer: FillSymbolizer): any {
const fillOpacity = symbolizer.fillOpacity !== undefined ? symbolizer.fillOpacity : symbolizer.opacity;
const outlineOpacity = symbolizer.outlineOpacity !== undefined ? symbolizer.outlineOpacity : symbolizer.opacity;

const qmlProps = {
color: this.qmlColorFromHexAndOpacity(symbolizer.color, symbolizer.opacity),
color: this.qmlColorFromHexAndOpacity(symbolizer.color, fillOpacity),
offset_map_unit_scale: '3x:0,0,0,0,0,0',
offset_unit: 'Pixel',
outline_style: symbolizer.outlineDasharray ? 'dash' : 'solid',
outline_width: symbolizer.outlineWidth || '0',
outline_width_map_unit_scale: '3x:0,0,0,0,0,0',
outline_width_unit: 'Pixel',
customdash: symbolizer.outlineDasharray ? symbolizer.outlineDasharray.join(';') : undefined,
outline_color: this.qmlColorFromHexAndOpacity(symbolizer.outlineColor, 1)
outline_color: this.qmlColorFromHexAndOpacity(symbolizer.outlineColor, outlineOpacity)
};

return {
Expand Down Expand Up @@ -901,25 +905,38 @@ export class QGISStyleParser implements StyleParser {
const type: string = 'RuleRenderer';
const rules: any[] = [];
const symbols: any[] = this.getQmlSymbolsFromStyle(geoStylerStyle, rules);
return {
qgis: {
$: {},
'renderer-v2': [{
$: {
type
},
rules: [{
if (rules.length > 0 || symbols.length > 0) {
return {
qgis: {
$: {},
'renderer-v2': [{
$: {
key: 'renderer_rules'
type
},
rule: rules
}],
symbols: [{
symbol: symbols
rules: [{
$: {
key: 'renderer_rules'
},
rule: rules
}],
symbols: [{
symbol: symbols
}]
}]
}]
}
};
}
};
} else {
return {
qgis: {
$: {},
'renderer-v2': [{
$: {
type: 'nullSymbol'
}
}]
}
};
}
}

convertTextSymbolizerRule(qmlRuleList: any[], rule: Rule) {
Expand Down Expand Up @@ -960,10 +977,13 @@ export class QGISStyleParser implements StyleParser {
};

if (textSymbolizer.haloColor) {
textRule.settings['text-buffer'] = [{
textRule.settings[0]['text-buffer'] = [{
$: {
bufferSize: textSymbolizer.haloWidth || `0`,
bufferColor: this.qmlColorFromHexAndOpacity(textSymbolizer.haloColor, 1)
bufferColor: this.qmlColorFromHexAndOpacity(textSymbolizer.haloColor, 1),
bufferDraw: 1,
bufferSizeUnits: 'Pixel',
bufferSizeMapUnitScale: '3x:0,0,0,0,0,0'
}
}];
}
Expand Down

0 comments on commit 2d1ec68

Please sign in to comment.