Skip to content

Commit c09f787

Browse files
authored
Fix #3685 print support for dashed stroke (#3686)
* Fix #139 print support for dashed stroke * fix lint error
1 parent c461d1b commit c09f787

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

web/client/utils/AnnotationsUtils.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const LocaleUtils = require('./LocaleUtils');
1111
const {extraMarkers} = require('./MarkerUtils');
1212
const {geometryFunctions, fetchStyle, hashAndStringify} = require('./VectorStyleUtils');
1313
const {set} = require('./ImmutableUtils');
14-
const {values, isNil, slice, head, castArray, last, isArray, findIndex} = require('lodash');
14+
const {values, isNil, slice, head, castArray, last, isArray, findIndex, isString} = require('lodash');
1515
const uuid = require('uuid');
1616
const turfCenter = require('@turf/center').default;
1717
const assign = require('object-assign');
@@ -96,9 +96,14 @@ const getStylesObject = ({type = "Point", features = []} = {}) => {
9696
};
9797
const getProperties = (props = {}, messages = {}) => ({title: LocaleUtils.getMessageById(messages, "annotations.defaulttitle") !== "annotations.defaulttitle" ? LocaleUtils.getMessageById(messages, "annotations.defaulttitle") : "Default title", id: uuidv1(), ...props});
9898

99+
const getDashArrayFromStyle = dashArray => {
100+
return isString(dashArray) && dashArray || isArray(dashArray) && dashArray.join(" ");
101+
};
102+
99103
const annStyleToOlStyle = (type, tempStyle, label = "") => {
100104
let style = tempStyle && tempStyle[type] ? tempStyle[type] : tempStyle;
101105
const s = style;
106+
const dashArray = s.dashArray ? getDashArrayFromStyle(s.dashArray) : "";
102107
switch (type) {
103108
case "MultiPolygon":
104109
case "Polygon":
@@ -108,14 +113,16 @@ const annStyleToOlStyle = (type, tempStyle, label = "") => {
108113
"strokeOpacity": s.opacity,
109114
"strokeWidth": s.weight,
110115
"fillColor": rgbaTorgb(s.fillColor),
111-
"fillOpacity": s.fillOpacity
116+
"fillOpacity": s.fillOpacity,
117+
"strokeDashStyle": dashArray
112118
};
113119
case "LineString":
114120
case "MultiLineString":
115121
return {
116122
"strokeColor": rgbaTorgb(s.color),
117123
"strokeOpacity": s.opacity,
118-
"strokeWidth": s.weight
124+
"strokeWidth": s.weight,
125+
"strokeDashStyle": dashArray
119126
};
120127
case "Text":
121128
return {
@@ -133,7 +140,8 @@ const annStyleToOlStyle = (type, tempStyle, label = "") => {
133140
"stroke": true,
134141
"strokeColor": rgbaTorgb(s.color),
135142
"strokeOpacity": s.opacity,
136-
"strokeWidth": s.weight
143+
"strokeWidth": s.weight,
144+
"strokeDashStyle": dashArray
137145
};
138146
case "Point":
139147
case "MultiPoint": {
@@ -177,6 +185,7 @@ const annStyleToOlStyle = (type, tempStyle, label = "") => {
177185
"strokeColor": "#FF0000",
178186
"pointRadius": 5,
179187
"strokeOpacity": 1,
188+
"strokeDashStyle": dashArray,
180189
"strokeWidth": 1
181190
};
182191
}
@@ -565,7 +574,8 @@ const AnnotationsUtils = {
565574
isCompletePolygon: (coords = [[[]]]) => {
566575
const validCoords = coords[0].filter(AnnotationsUtils.validateCoordsArray);
567576
return validCoords.length > 3 && head(validCoords)[0] === last(validCoords)[0] && head(validCoords)[1] === last(validCoords)[1];
568-
}
577+
},
578+
getDashArrayFromStyle
569579
};
570580

571581
module.exports = AnnotationsUtils;

web/client/utils/__tests__/AnnotationsUtils-test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const {getAvailableStyler, getRelativeStyler, convertGeoJSONToInternalModel,
1919
getStartEndPointsForLinestring,
2020
createGeometryFromGeomFunction,
2121
updateAllStyles,
22-
fromLineStringToGeodesicLineString, isCompletePolygon
22+
fromLineStringToGeodesicLineString, isCompletePolygon,
23+
getDashArrayFromStyle
2324
} = require('../AnnotationsUtils');
2425

2526
const featureCollection = {
@@ -374,6 +375,23 @@ describe('Test the AnnotationsUtils', () => {
374375
expect(ft.properties).toExist();
375376
expect(ft.properties.ms_style).toExist();
376377
});
378+
it('fromAnnotationToGeoJson with a LineString with dashArray', () => {
379+
const f = {
380+
type: "Feature",
381+
geometry: {
382+
type: "LineString",
383+
coordinates: [[0, 0], [1, 1], [3, 3], [5, 5]]
384+
},
385+
style: {
386+
dashArray: [1, 3]
387+
}
388+
};
389+
const ft = fromAnnotationToGeoJson(f);
390+
expect(ft.type).toBe("Feature");
391+
expect(ft.properties).toExist();
392+
expect(ft.properties.ms_style).toExist();
393+
expect(ft.properties.ms_style.strokeDashStyle).toEqual("1 3");
394+
});
377395
it('flattenGeometryCollection', () => {
378396
const fts = flattenGeometryCollection(feature);
379397
expect(fts).toExist();
@@ -739,4 +757,10 @@ describe('Test the AnnotationsUtils', () => {
739757
expect(isCompletePolygon(polygonCoords3)).toBe(true);
740758
expect(isCompletePolygon(polygonCoords4)).toBe(false);
741759
});
760+
it('test getDashArrayFromStyle', () => {
761+
// default
762+
expect(getDashArrayFromStyle()).toEqual("");
763+
expect(getDashArrayFromStyle("3 4 5")).toEqual("3 4 5");
764+
expect(getDashArrayFromStyle(["3", "4", "5"])).toEqual("3 4 5");
765+
});
742766
});

0 commit comments

Comments
 (0)