Skip to content

fix: dashed line conversion #579

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

Merged
merged 1 commit into from
Dec 16, 2024
Merged
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
1 change: 1 addition & 0 deletions data/qmls/line_simple.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<Option name="line_width" value="3" type="QString"/>
<Option name="line_width_unit" value="Pixel" type="QString"/>
<Option name="customdash" value="12;12" type="QString"/>
<Option name="use_custom_dash" value="1" type="QString"/>
</Option>
</layer>
</symbol>
Expand Down
1 change: 1 addition & 0 deletions data/qmls_old/line_simple.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<prop k="line_width" v="3"/>
<prop k="line_width_unit" v="Pixel"/>
<prop k="customdash" v="12;12"/>
<prop k="use_custom_dash" v="1"/>
</layer>
</symbol>
</symbols>
Expand Down
52 changes: 24 additions & 28 deletions src/QGISStyleParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,15 @@ type QmlRange = {
};
};

export const outlineStyleDashArrays = {
dot: [2, 2],
dash: [10, 2]
const dot = [2, 2];
const dash = [10, 2];

const lineStyleDashArrays: { [key: string]: number[] | undefined } = {
solid: undefined,
dot: dot,
dash: dash,
'dash dot': [...dash, ...dot],
'dash dot dot': [...dash, ...dot, ...dot]
};

const AnchorMap = {
Expand Down Expand Up @@ -609,8 +615,16 @@ export class QGISStyleParser implements StyleParser {
if (qmlMarkerProps.joinstyle) {
lineSymbolizer.join = qmlMarkerProps.joinstyle;
}
if (qmlMarkerProps.customdash) {
lineSymbolizer.dasharray = qmlMarkerProps.customdash.split(';').map(parseFloat);
if (!qmlMarkerProps.use_custom_dash || qmlMarkerProps.use_custom_dash === '0') {
const lineStyle = qmlMarkerProps?.line_style || 'solid';
const lineDashArray = lineStyleDashArrays[lineStyle as string];
if (lineDashArray) {
lineSymbolizer.dasharray = lineDashArray;
}
} else {
if (qmlMarkerProps.customdash) {
lineSymbolizer.dasharray = qmlMarkerProps.customdash.split(';').map(parseFloat);
}
}
if (qmlMarkerProps.offset) {
lineSymbolizer.perpendicularOffset = parseFloat(qmlMarkerProps.offset);
Expand Down Expand Up @@ -640,7 +654,7 @@ export class QGISStyleParser implements StyleParser {

const qmlMarkerProps: any = qmlSymbolizerLayerPropsToObject(symbolizerLayer);

let outlineStyle = qmlMarkerProps?.outline_style || 'solid';
const outlineStyle = qmlMarkerProps?.outline_style || 'solid';
if (qmlMarkerProps.outline_color && 'no' !== outlineStyle) {
fillSymbolizer.outlineColor = this.qmlColorToHex(qmlMarkerProps.outline_color);
}
Expand All @@ -651,28 +665,9 @@ export class QGISStyleParser implements StyleParser {
fillSymbolizer.color = this.qmlColorToHex(qmlMarkerProps.color);
}

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;
const outlineDashArray = lineStyleDashArrays[outlineStyle];
if (outlineDashArray) {
fillSymbolizer.outlineDasharray = outlineDashArray;
}

if (qmlMarkerProps.outline_width && 'no' !== outlineStyle) {
Expand Down Expand Up @@ -854,6 +849,7 @@ export class QGISStyleParser implements StyleParser {
};
if (symbolizer.dasharray) {
qmlProps.customdash = symbolizer.dasharray.join(';');
qmlProps.use_custom_dash = '1';
}

return {
Expand Down
Loading