Skip to content

Commit ec42caf

Browse files
committed
fix: add all line style properties to the KML reader/writer
1 parent cc0fcbb commit ec42caf

File tree

4 files changed

+1325
-1243
lines changed

4 files changed

+1325
-1243
lines changed

package.json

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"@emotion/react": "^11.11.4",
88
"@emotion/styled": "^11.11.5",
99
"@geops/geops-ui": "0.3.2",
10-
"@mui/icons-material": "^5.15.17",
11-
"@mui/material": "^5.15.17",
12-
"re-resizable": "6.9.16",
10+
"@mui/icons-material": "^5.15.20",
11+
"@mui/material": "^5.15.20",
12+
"re-resizable": "6.9.17",
1313
"react-icons": "5.2.1",
1414
"resize-observer-polyfill": "1.5.1"
1515
},
@@ -22,30 +22,31 @@
2222
"react-dom": "^18"
2323
},
2424
"devDependencies": {
25-
"@babel/preset-env": "7.24.5",
26-
"@babel/preset-react": "7.24.1",
25+
"@babel/preset-env": "7.24.7",
26+
"@babel/preset-react": "7.24.7",
2727
"@cfaester/enzyme-adapter-react-18": "0.8.0",
2828
"@commitlint/cli": "19.3.0",
2929
"@commitlint/config-conventional": "19.2.2",
3030
"@svgr/plugin-jsx": "^8.1.0",
3131
"@svgr/webpack": "8.1.0",
32-
"@testing-library/jest-dom": "6.4.5",
33-
"@testing-library/react": "15.0.7",
32+
"@testing-library/dom": "^10.1.0",
33+
"@testing-library/jest-dom": "6.4.6",
34+
"@testing-library/react": "16.0.0",
3435
"@testing-library/user-event": "14.5.2",
3536
"babel-jest": "29.7.0",
3637
"babel-loader": "9.1.3",
3738
"canvas": "2.11.2",
38-
"css-loader": "7.1.1",
39+
"css-loader": "7.1.2",
3940
"enzyme": "3.11.0",
40-
"esbuild": "^0.21.2",
41-
"esbuild-loader": "^4.1.0",
41+
"esbuild": "^0.21.5",
42+
"esbuild-loader": "^4.2.0",
4243
"eslint": "8",
4344
"eslint-config-airbnb": "19.0.4",
4445
"eslint-config-prettier": "9.1.0",
4546
"eslint-plugin-import": "2.29.1",
46-
"eslint-plugin-jsx-a11y": "^6.8.0",
47+
"eslint-plugin-jsx-a11y": "^6.9.0",
4748
"eslint-plugin-prettier": "5.1.3",
48-
"eslint-plugin-react": "7.34.1",
49+
"eslint-plugin-react": "7.34.3",
4950
"eslint-plugin-react-hooks": "4.6.2",
5051
"file-loader": "6.2.0",
5152
"fixpack": "4.0.0",
@@ -62,33 +63,33 @@
6263
"jest-transform-file": "1.1.1",
6364
"jest-transformer-svg": "^2.0.2",
6465
"jsts": "2.11.3",
65-
"lint-staged": "15.2.2",
66+
"lint-staged": "15.2.7",
6667
"mapbox-gl": "1.13.1",
67-
"maplibre-gl": "4.2.0",
68-
"mobility-toolbox-js": "2.4.1",
69-
"ol": "8.2.0",
68+
"maplibre-gl": "4.4.1",
69+
"mobility-toolbox-js": "2.4.2",
70+
"ol": "9.2.4",
7071
"postcss": "^8.4.38",
71-
"prettier": "3.2.5",
72+
"prettier": "3.3.2",
7273
"proj4": "2.11.0",
7374
"prop-types": "15.8.1",
7475
"react": "18.3.1",
7576
"react-dom": "18.3.1",
7677
"react-styleguidist": "13.1.2",
7778
"react-svg-loader": "3.0.3",
7879
"react-test-renderer": "18.3.1",
79-
"sass": "1.77.1",
80+
"sass": "1.77.6",
8081
"sass-loader": "14.2.1",
8182
"standard-version": "9.5.0",
8283
"stream-array": "1.1.2",
8384
"style-loader": "4.0.0",
84-
"stylelint": "16.5.0",
85+
"stylelint": "16.6.1",
8586
"stylelint-config-recommended-scss": "14.0.0",
8687
"stylelint-config-standard": "36.0.0",
87-
"stylelint-scss": "6.3.0",
88+
"stylelint-scss": "6.3.2",
8889
"terser-webpack-plugin": "^5.3.10",
8990
"url-loader": "4.1.1",
9091
"vinyl-fs": "4.0.0",
91-
"webpack": "^5.91.0",
92+
"webpack": "^5.92.1",
9293
"xml-beautifier": "0.5.0"
9394
},
9495
"scripts": {

src/utils/KML.js

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,17 @@ const sanitizeFeature = (feature, doNotRevert32pxScaling = false) => {
9393
const style = (Array.isArray(tmpStyles) ? tmpStyles[0] : tmpStyles).clone();
9494

9595
let stroke = style.getStroke();
96-
if (stroke && feature.get("lineDash")) {
97-
stroke.setLineDash(
96+
97+
if (feature.get("lineCap")) {
98+
stroke?.setLineCap(feature.get("lineCap"));
99+
}
100+
101+
if (feature.get("lineJoin")) {
102+
stroke?.setLineJoin(feature.get("lineJoin"));
103+
}
104+
105+
if (feature.get("lineDash")) {
106+
stroke?.setLineDash(
98107
feature
99108
.get("lineDash")
100109
.split(",")
@@ -104,6 +113,14 @@ const sanitizeFeature = (feature, doNotRevert32pxScaling = false) => {
104113
);
105114
}
106115

116+
if (feature.get("lineDashOffset")) {
117+
stroke?.setLineDashOffset(parseInt(feature.get("lineDashOffset"), 10));
118+
}
119+
120+
if (feature.get("miterLimit")) {
121+
stroke?.setMiterLimit(parseInt(feature.get("miterLimit"), 10));
122+
}
123+
107124
// The canvas draws a stroke width=1 by default if width=0, so we
108125
// remove the stroke style in that case.
109126
if (stroke && stroke.getWidth() === 0) {
@@ -478,21 +495,37 @@ const writeFeatures = (layer, featureProjection, mapResolution) => {
478495
}
479496
}
480497

481-
if (newStyle.text && newStyle.text.getBackgroundFill()) {
498+
if (newStyle.text?.getBackgroundFill()) {
482499
clone.set(
483500
"textBackgroundFillColor",
484501
asString(newStyle.text.getBackgroundFill().getColor()),
485502
);
486503
}
487504

488-
if (newStyle.text && newStyle.text.getPadding()) {
505+
if (newStyle.text?.getPadding()) {
489506
clone.set("textPadding", newStyle.text.getPadding().join());
490507
}
491508

492-
if (newStyle.stroke && newStyle.stroke.getLineDash()) {
509+
if (newStyle.stroke?.getLineCap()) {
510+
clone.set("lineCap", newStyle.stroke.getLineCap());
511+
}
512+
513+
if (newStyle.stroke?.getLineJoin()) {
514+
clone.set("lineJoin", newStyle.stroke.getLineJoin());
515+
}
516+
517+
if (newStyle.stroke?.getLineDash()) {
493518
clone.set("lineDash", newStyle.stroke.getLineDash().join(","));
494519
}
495520

521+
if (newStyle.stroke?.getLineDashOffset()) {
522+
clone.set("lineDashOffset", newStyle.stroke.getLineDashOffset());
523+
}
524+
525+
if (newStyle.stroke?.getMiterLimit()) {
526+
clone.set("miterLimit", newStyle.stroke.getMiterLimit());
527+
}
528+
496529
if (newStyle.image instanceof Circle) {
497530
newStyle.image = null;
498531
}

src/utils/KML.test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,13 @@ describe("KML", () => {
9494
</LineStyle>
9595
</Style>
9696
<ExtendedData>
97+
<Data name="lineCap"><value>butt</value></Data>
9798
<Data name="lineDash"><value>40,40</value></Data>
99+
<Data name="lineDashOffset"><value>5</value></Data>
98100
<Data name="lineEndIcon"><value>{"url":"fooarrowend.png","scale":0.35,"size":[36,58],"zIndex":1}</value></Data>
101+
<Data name="lineJoin"><value>square</value></Data>
99102
<Data name="lineStartIcon"><value>{"url":"fooarrowstart.png","scale":0.35,"size":[36,58],"zIndex":1}</value></Data>
103+
<Data name="miterLimit"><value>14</value></Data>
100104
</ExtendedData>
101105
<LineString><coordinates>0,1,0 3,5,0 40,25,0</coordinates></LineString>
102106
</Placemark>
@@ -201,7 +205,10 @@ describe("KML", () => {
201205
const styleText = style.getText();
202206
expect(styleText.getText()).toBe("bar"); // spaces are trimmed.
203207
expect(styleText.getFont()).toEqual("bold 16px arial");
204-
expect(styleText.getFill()).toEqual({ color_: [32, 52, 126, 1] });
208+
expect(styleText.getFill()).toEqual({
209+
color_: [32, 52, 126, 1],
210+
patternImage_: null,
211+
});
205212
expect(styleText.getStroke()).toEqual({
206213
color_: "rgba(100,255,255,0.2)",
207214
width_: 3,
@@ -216,6 +223,7 @@ describe("KML", () => {
216223
expect(styleText.getPadding()).toEqual([5, 6, 7, 8]);
217224
expect(styleText.getBackgroundFill()).toEqual({
218225
color_: "rgba(255,255,255,0.01)",
226+
patternImage_: null,
219227
});
220228
expect(styleText.getTextAlign()).toEqual("right");
221229
expect(styleText.getOffsetX()).toEqual(-90);

0 commit comments

Comments
 (0)