@masterportal/masterportalapi 2.13.0 → 2.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/.eslintrc +2 -1
  2. package/CHANGELOG.md +16 -7
  3. package/example/config/localGeoJSONPoints.js +2106 -0
  4. package/example/config/portal.json +47 -1
  5. package/example/config/services.json +20 -0
  6. package/example/index.js +50 -7
  7. package/jest.config.js +1 -1
  8. package/jest.setup.js +9 -1
  9. package/package.json +64 -62
  10. package/src/index.js +3 -1
  11. package/src/layer/geojson/index.js +55 -4
  12. package/src/layer/oaf.js +35 -5
  13. package/src/layer/vectorBase.js +20 -1
  14. package/src/layer/wfs.js +38 -7
  15. package/src/lib/attributeMapper.js +231 -0
  16. package/src/lib/getValueFromObjectByPath.js +73 -0
  17. package/src/lib/thousandsSeparator.js +23 -0
  18. package/src/maps/ol/olMap.js +4 -3
  19. package/src/renderer/webgl.js +250 -0
  20. package/src/vectorStyle/createStyle.js +259 -0
  21. package/src/vectorStyle/lib/colorConvertions.js +97 -0
  22. package/src/vectorStyle/lib/createLegendInfo.js +28 -0
  23. package/src/vectorStyle/lib/getGeometryTypeFromService.js +153 -0
  24. package/src/vectorStyle/lib/getRuleForIndex.js +62 -0
  25. package/src/vectorStyle/lib/valueOperations.js +172 -0
  26. package/src/vectorStyle/styleList.js +281 -0
  27. package/src/vectorStyle/styles/defaultStyles.js +177 -0
  28. package/src/vectorStyle/styles/point/stylePoint.js +108 -0
  29. package/src/vectorStyle/styles/point/stylePointCircle.js +29 -0
  30. package/src/vectorStyle/styles/point/stylePointIcon.js +79 -0
  31. package/src/vectorStyle/styles/point/stylePointInterval.js +124 -0
  32. package/src/vectorStyle/styles/point/stylePointNominal.js +232 -0
  33. package/src/vectorStyle/styles/point/stylePointRegularShape.js +39 -0
  34. package/src/vectorStyle/styles/polygon/polygonStyleHatch.js +160 -0
  35. package/src/vectorStyle/styles/polygon/stylePolygon.js +125 -0
  36. package/src/vectorStyle/styles/style.js +161 -0
  37. package/src/vectorStyle/styles/styleCesium.js +106 -0
  38. package/src/vectorStyle/styles/styleLine.js +51 -0
  39. package/src/vectorStyle/styles/styleText.js +143 -0
  40. package/test/layer/geojson/index.test.js +23 -0
  41. package/test/layer/oaf.test.js +30 -0
  42. package/test/layer/vectorBase.test.js +27 -7
  43. package/test/layer/wfs.test.js +30 -0
  44. package/test/lib/attributeMapper.test.js +290 -0
  45. package/test/lib/getValueFromObjectByPath.test.js +61 -0
  46. package/test/lib/thousandsSeparator.test.js +58 -0
  47. package/test/renderer/webgl.test.js +161 -0
  48. package/test/vectorStyle/createStyle.test.js +335 -0
  49. package/test/vectorStyle/lib/colorConvertions.test.js +42 -0
  50. package/test/vectorStyle/lib/getRuleForIndex.test.js +132 -0
  51. package/test/vectorStyle/lib/valueOperations.test.js +191 -0
  52. package/test/vectorStyle/styles/point/stylePoint.test.js +28 -0
  53. package/test/vectorStyle/styles/point/stylePointCircle.test.js +30 -0
  54. package/test/vectorStyle/styles/point/stylePointIcon.test.js +83 -0
  55. package/test/vectorStyle/styles/point/stylePointInterval.test.js +57 -0
  56. package/test/vectorStyle/styles/point/stylePointNominal.test.js +84 -0
  57. package/test/vectorStyle/styles/point/stylePointRegularShape.test.js +24 -0
  58. package/test/vectorStyle/styles/polygon/polygonStyleHatch.test.js +95 -0
  59. package/test/vectorStyle/styles/polygon/stylePolygon.test.js +61 -0
  60. package/test/vectorStyle/styles/styleLine.test.js +29 -0
  61. package/test/vectorStyle/styles/styleText.test.js +49 -0
@@ -0,0 +1,61 @@
1
+ import {getValueFromObjectByPath, getPathPartsFromPath} from "../../src/lib/getValueFromObjectByPath";
2
+
3
+ describe("src/utils/getValueFromObjectByPath.js", () => {
4
+ describe("getPathPartsFromPath", () => {
5
+ it("should walk through the given string, collecting all parts seperated by a dot", () => {
6
+ const path = "first.second.third",
7
+ expected = ["first", "second", "third"];
8
+
9
+ expect(getPathPartsFromPath(path)).toEqual(expected);
10
+ });
11
+ it("should ignore escaped dots on the way, removing escape signs", () => {
12
+ const path = "first.sec\\.ond.third",
13
+ expected = ["first", "sec.ond", "third"];
14
+
15
+ expect(getPathPartsFromPath(path)).toEqual(expected);
16
+ });
17
+ it("should be able to escape escape signs", () => {
18
+ const path = "first.sec\\\\ond.third",
19
+ expected = ["first", "sec\\ond", "third"];
20
+
21
+ expect(getPathPartsFromPath(path)).toEqual(expected);
22
+ });
23
+ });
24
+ describe("getValueFromObjectByPath", () => {
25
+ it("should return undefined if anything but an object or array is given as first param", () => {
26
+ expect(getValueFromObjectByPath(undefined, "")).toBe(undefined);
27
+ expect(getValueFromObjectByPath(null, "")).toBe(undefined);
28
+ expect(getValueFromObjectByPath("string", "")).toBe(undefined);
29
+ expect(getValueFromObjectByPath(1234, "")).toBe(undefined);
30
+ expect(getValueFromObjectByPath(true, "")).toBe(undefined);
31
+ expect(getValueFromObjectByPath(false, "")).toBe(undefined);
32
+ });
33
+ it("should return undefined if anything but a string is given as second param", () => {
34
+ expect(getValueFromObjectByPath({}, undefined)).toBe(undefined);
35
+ expect(getValueFromObjectByPath({}, null)).toBe(undefined);
36
+ expect(getValueFromObjectByPath({}, 1234)).toBe(undefined);
37
+ expect(getValueFromObjectByPath({}, true)).toBe(undefined);
38
+ expect(getValueFromObjectByPath({}, false)).toBe(undefined);
39
+ expect(getValueFromObjectByPath({}, {})).toBe(undefined);
40
+ expect(getValueFromObjectByPath({}, [])).toBe(undefined);
41
+ });
42
+ it("should return undefined if the given depthBarrier is reached during walkthrough", () => {
43
+ expect(getValueFromObjectByPath({test: {test: 1}}, "@test.test", "@", ".", 1)).toBe(undefined);
44
+ });
45
+ it("should return undefined if the given path can't be followed through the given object", () => {
46
+ expect(getValueFromObjectByPath({}, "@test")).toBe(undefined);
47
+ expect(getValueFromObjectByPath({test: null}, "@test.test")).toBe(undefined);
48
+ });
49
+ it("should return the found value if the given path was successfully followed through the object", () => {
50
+ expect(getValueFromObjectByPath({test: 1}, "@test")).toEqual(1);
51
+ expect(getValueFromObjectByPath({test: {test: 1}}, "@test")).toEqual({test: 1});
52
+ expect(getValueFromObjectByPath({test: {test: {test: 1}}}, "@test.test")).toEqual({test: 1});
53
+ });
54
+ it("should be able to handle a path without prefix when no prefix is given", () => {
55
+ expect(getValueFromObjectByPath({test: 1}, "test", false)).toEqual(1);
56
+ });
57
+ it("should be able to handle a path with a complex prefix", () => {
58
+ expect(getValueFromObjectByPath({test: 1}, "1234test", "1234")).toEqual(1);
59
+ });
60
+ });
61
+ });
@@ -0,0 +1,58 @@
1
+ import thousandsSeparator from "../../src/lib/thousandsSeparator";
2
+
3
+ describe("src/utils/thousandsSeparator.js", () => {
4
+ it("should return an empty string if the given param is not a number nor a string", () => {
5
+ expect(typeof thousandsSeparator(undefined)).toBe("string");
6
+ expect(thousandsSeparator(undefined)).toEqual("");
7
+ expect(typeof thousandsSeparator(null)).toBe("string");
8
+ expect(thousandsSeparator(null)).toEqual("");
9
+ expect(typeof thousandsSeparator([])).toBe("string");
10
+ expect(thousandsSeparator([])).toEqual("");
11
+ expect(typeof thousandsSeparator({})).toBe("string");
12
+ expect(thousandsSeparator({})).toEqual("");
13
+ expect(typeof thousandsSeparator(false)).toBe("string");
14
+ expect(thousandsSeparator(false)).toEqual("");
15
+ expect(typeof thousandsSeparator(true)).toBe("string");
16
+ expect(thousandsSeparator(true)).toEqual("");
17
+ });
18
+ it("should convert a number into a string", () => {
19
+ expect(typeof thousandsSeparator(1)).toBe("string");
20
+ });
21
+ it("should convert a negative number into a string", () => {
22
+ expect(typeof thousandsSeparator(-1)).toBe("string");
23
+ });
24
+ it("should return a string if a string was given", () => {
25
+ expect(typeof thousandsSeparator("1")).toBe("string");
26
+ });
27
+ it("should add the given letter(s) as thousands separator", () => {
28
+ expect(thousandsSeparator(1000, "delimAbs")).toEqual("1delimAbs000");
29
+ });
30
+ it("should add the given letter(s) as decimal point for positive value", () => {
31
+ expect(thousandsSeparator(1000.1, "delimAbs", "delimDec")).toEqual("1delimAbs000delimDec1");
32
+ });
33
+ it("should create a number in german format by default for positive value", () => {
34
+ expect(thousandsSeparator(1000.1)).toEqual("1.000,1");
35
+ });
36
+ it("should be able to add a higher number of thousands separators", () => {
37
+ expect(thousandsSeparator(1123456789.123456)).toEqual("1.123.456.789,123456");
38
+ });
39
+ it("should be able to add a higher number of thousands separators if a string was given", () => {
40
+ expect(thousandsSeparator("1123456789.123456")).toEqual("1.123.456.789,123456");
41
+ });
42
+ it("should add the given letter(s) as thousands seperator", () => {
43
+ expect(thousandsSeparator(-1000, "delimAbs")).toEqual("-1delimAbs000");
44
+ });
45
+ it("should add the given letter(s) as decimal point for negative value", () => {
46
+ expect(thousandsSeparator(-1000.1, "delimAbs", "delimDec")).toEqual("-1delimAbs000delimDec1");
47
+ });
48
+ it("should create a number in german format by default for negative value", () => {
49
+ expect(thousandsSeparator(-1000.1)).toEqual("-1.000,1");
50
+ });
51
+ it("should be able to add a higher number of thousands seperators", () => {
52
+ expect(thousandsSeparator(-1123456789.123456)).toEqual("-1.123.456.789,123456");
53
+ });
54
+ it("should be able to add a higher number of thousands seperators if a string was given", () => {
55
+ expect(thousandsSeparator("-1123456789.123456")).toEqual("-1.123.456.789,123456");
56
+ });
57
+ });
58
+
@@ -0,0 +1,161 @@
1
+ import VectorSource from "ol/source/Vector.js";
2
+ import Feature from "ol/Feature";
3
+ import Polygon from "ol/geom/Polygon";
4
+ import * as webgl from "../../src/renderer/webgl";
5
+ import WebGLPointsLayer from "ol/layer/WebGLPoints";
6
+ import Layer from "ol/layer/Layer";
7
+ import {packColor} from "ol/renderer/webgl/shaders";
8
+ import styleList from "../../src/vectorStyle/styleList";
9
+
10
+ describe("webgl.js", () => {
11
+ let layerParams, rawLayer, styleRule, styleObject;
12
+
13
+ beforeEach(() => {
14
+ layerParams = {
15
+ name: "webglTestLayer",
16
+ id: "123",
17
+ typ: "WFS",
18
+ renderer: "webgl",
19
+ styleId: "123"
20
+ };
21
+ rawLayer = {
22
+ url: "https://url.de",
23
+ name: "wfsSourceLayer",
24
+ id: "123",
25
+ typ: "WFS",
26
+ version: "2.0.0",
27
+ featureNS: "http://www.deegree.org/app",
28
+ featureType: "krankenhaeuser_hh",
29
+ outputFormat: "XML"
30
+ };
31
+ styleRule = {style: {
32
+ polygonFillColor: [255, 0, 0, 0.5],
33
+ polygonStrokeColor: [0, 255, 0, 0.5],
34
+ polygonStrokeWidth: 2,
35
+ circleFillColor: [0, 0, 255, 0.5],
36
+ circleRadius: 6
37
+ }};
38
+ styleObject = {
39
+ rules: [styleRule]
40
+ };
41
+
42
+ jest.spyOn(styleList, "returnStyleObject").mockImplementation(() => styleObject);
43
+ });
44
+
45
+ afterEach(() => {
46
+ jest.restoreAllMocks();
47
+ });
48
+
49
+ describe("createLayer", () => {
50
+ const source = new VectorSource();
51
+
52
+ it("should return a WebGLPointsLayer", () => {
53
+ layerParams.isPointLayer = true;
54
+ const webglLayer = webgl.createLayer({...rawLayer, ...layerParams, source});
55
+
56
+ expect(webglLayer).toBeInstanceOf(WebGLPointsLayer);
57
+ expect(webglLayer.get("isPointLayer")).toBeTruthy();
58
+ });
59
+ it("should return a custom Layer", () => {
60
+ layerParams.isPointLayer = false;
61
+ const webglLayer = webgl.createLayer({...rawLayer, ...layerParams, source});
62
+
63
+ expect(webglLayer).toBeInstanceOf(Layer);
64
+ expect(webglLayer).not.toBeInstanceOf(WebGLPointsLayer);
65
+ expect(webglLayer.get("isPointLayer")).toBeFalsy();
66
+ });
67
+ });
68
+ describe("private format and style functions", () => {
69
+ const
70
+ feature = new Feature({
71
+ geometry: new Polygon([
72
+ [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 0, 0]]
73
+ ], "XYZ"),
74
+ apple: "42",
75
+ pear: "true",
76
+ pumpkin: "false"
77
+ });
78
+ let $feature;
79
+
80
+ describe("formatFeatureGeometry", () => {
81
+ it("should remove any Z components from the geometry", () => {
82
+ $feature = feature.clone();
83
+ webgl.formatFeatureGeometry($feature);
84
+ /* eslint-disable-next-line max-nested-callbacks */
85
+ expect($feature.getGeometry().getCoordinates()[0].every(coord => coord.length === 2)).toBeTruthy();
86
+ });
87
+ });
88
+ describe("formatFeatureData", () => {
89
+ it("should not format excluded formats 'number' and 'boolean", () => {
90
+ $feature = feature.clone();
91
+ webgl.formatFeatureData($feature, ["number", "boolean"]);
92
+ expect(typeof $feature.get("apple")).toEqual("string");
93
+ expect(typeof $feature.get("pear")).toEqual("string");
94
+ expect(typeof $feature.get("pumpkin")).toEqual("string");
95
+ });
96
+ it("should format numbers and booleans", () => {
97
+ $feature = feature.clone();
98
+ webgl.formatFeatureData($feature, []);
99
+ expect(typeof $feature.get("apple")).toEqual("number");
100
+ expect(typeof $feature.get("pear")).toEqual("boolean");
101
+ expect(typeof $feature.get("pumpkin")).toEqual("boolean");
102
+ });
103
+ });
104
+ describe("formatFeatureStyles", () => {
105
+ it("bind the styling rule from the styleObject to each feature", () => {
106
+ $feature = feature.clone();
107
+ webgl.formatFeatureStyles($feature, styleObject);
108
+ expect($feature.styleRule).toEqual(styleRule);
109
+ });
110
+ });
111
+ describe("getRenderFunctions", () => {
112
+ it("should read the style from styleRule and pack them to single float", () => {
113
+ const renderFunctions = webgl.getRenderFunctions();
114
+
115
+ $feature = feature.clone();
116
+ webgl.formatFeatureStyles($feature, styleObject);
117
+ expect(renderFunctions.fill.attributes.color($feature)).toEqual(packColor(styleRule.style.polygonFillColor));
118
+ expect(renderFunctions.fill.attributes.opacity($feature)).toEqual(styleRule.style.polygonFillColor[3]);
119
+ expect(renderFunctions.stroke.attributes.color($feature)).toEqual(packColor(styleRule.style.polygonStrokeColor));
120
+ expect(renderFunctions.stroke.attributes.width($feature)).toEqual(styleRule.style.polygonStrokeWidth);
121
+ expect(renderFunctions.stroke.attributes.opacity($feature)).toEqual(styleRule.style.polygonStrokeColor[3]);
122
+ expect(renderFunctions.point.attributes.color($feature)).toEqual(packColor(styleRule.style.circleFillColor));
123
+ expect(renderFunctions.point.attributes.size($feature)).toEqual(styleRule.style.circleRadius);
124
+ expect(renderFunctions.point.attributes.opacity($feature)).toEqual(styleRule.style.circleFillColor[3]);
125
+ });
126
+ it("should return default values if style is empty, i.e. \"default\" style", () => {
127
+ const renderFunctions = webgl.getRenderFunctions();
128
+
129
+ styleObject = {
130
+ rules: [{
131
+ style: {}
132
+ }]
133
+ };
134
+ $feature = feature.clone();
135
+ webgl.formatFeatureStyles($feature, styleObject);
136
+ expect(typeof renderFunctions.fill.attributes.color($feature)).toEqual("number");
137
+ expect(typeof renderFunctions.fill.attributes.opacity($feature)).toEqual("number");
138
+ expect(typeof renderFunctions.stroke.attributes.color($feature)).toEqual("number");
139
+ expect(typeof renderFunctions.stroke.attributes.width($feature)).toEqual("number");
140
+ expect(typeof renderFunctions.stroke.attributes.opacity($feature)).toEqual("number");
141
+ expect(typeof renderFunctions.point.attributes.color($feature)).toEqual("number");
142
+ expect(typeof renderFunctions.point.attributes.size($feature)).toEqual("number");
143
+ expect(typeof renderFunctions.point.attributes.opacity($feature)).toEqual("number");
144
+ });
145
+ it("should return default values if no style rule is found", () => {
146
+ const renderFunctions = webgl.getRenderFunctions();
147
+
148
+ $feature = feature.clone();
149
+ expect(feature.styleRule).toBeUndefined();
150
+ expect(typeof renderFunctions.fill.attributes.color($feature)).toEqual("number");
151
+ expect(typeof renderFunctions.fill.attributes.opacity($feature)).toEqual("number");
152
+ expect(typeof renderFunctions.stroke.attributes.color($feature)).toEqual("number");
153
+ expect(typeof renderFunctions.stroke.attributes.width($feature)).toEqual("number");
154
+ expect(typeof renderFunctions.stroke.attributes.opacity($feature)).toEqual("number");
155
+ expect(typeof renderFunctions.point.attributes.color($feature)).toEqual("number");
156
+ expect(typeof renderFunctions.point.attributes.size($feature)).toEqual("number");
157
+ expect(typeof renderFunctions.point.attributes.opacity($feature)).toEqual("number");
158
+ });
159
+ });
160
+ });
161
+ });
@@ -0,0 +1,335 @@
1
+ import createStyle from "../../src/vectorStyle/createStyle";
2
+ import PointStyle from "../../src/vectorStyle/styles/point/stylePoint";
3
+ import LineStringStyle from "../../src/vectorStyle/styles/styleLine";
4
+ import PolygonStyle from "../../src/vectorStyle/styles/polygon/stylePolygon";
5
+ import {Style, Stroke, Fill} from "ol/style.js";
6
+ import {GeoJSON} from "ol/format.js";
7
+
8
+ const wfsImgPathFromConfig = "/path/to/wfs/images",
9
+ rules = [
10
+ {
11
+ conditions: {
12
+ properties: {
13
+ id: "test1"
14
+ }
15
+ },
16
+ style: {
17
+ legendValue: "legendValueText",
18
+ circleStrokeColor: [255, 0, 0, 1],
19
+ type: "circle",
20
+ lineStrokeColor: [100, 0, 0, 1],
21
+ polygonStrokeColor: [100, 100, 0, 1]
22
+ }
23
+ },
24
+ {
25
+ style: {
26
+ legendValue: "LineStringLegend",
27
+ lineStrokeColor: [255, 0, 0, 1]
28
+ }
29
+ },
30
+ {
31
+ style: {
32
+ legendValue: "PolygonLegend",
33
+ polygonStrokeColor: [255, 0, 0, 255]
34
+ }
35
+ },
36
+ {
37
+ conditions: {
38
+ properties: {
39
+ value: [0, 50, "@min", "@max"]
40
+ }
41
+ },
42
+ style: {
43
+ legendValue: "legendValueText",
44
+ circleStrokeColor: [255, 0, 0, 1]
45
+ }
46
+ },
47
+ {
48
+ style: {
49
+ legendValue: "legendValueText",
50
+ circleStrokeColor: [255, 255, 255, 1]
51
+ }
52
+ }
53
+ ],
54
+ multiLineStringRules = [{
55
+ style: {
56
+ legendValue: "legendValueText",
57
+ lineStrokeColor: [255, 255, 255, 1]
58
+ }
59
+ },
60
+ {
61
+ style: {
62
+ legendValue: "legendValueText",
63
+ lineStrokeColor: [255, 0, 0, 1]
64
+ }
65
+ }],
66
+ multiPolygonRules = [{
67
+ style: {
68
+ legendValue: "legendValueText",
69
+ polygonStrokeColor: [100, 100, 0, 1]
70
+ }
71
+ },
72
+ {
73
+ style: {
74
+ legendValue: "legendValueText",
75
+ polygonStrokeColor: [255, 0, 0, 1]
76
+ }
77
+ }],
78
+ geojsonReader = new GeoJSON(),
79
+ jsonFeatures = {
80
+ "type": "FeatureCollection",
81
+ "features": [
82
+ {
83
+ "type": "Feature",
84
+ "geometry": {
85
+ "type": "Point",
86
+ "coordinates": [10.082125662581083, 53.518872973925404]
87
+ },
88
+ "properties": {
89
+ "id": "test1",
90
+ "name": "myName",
91
+ "value": 50,
92
+ "min": 10,
93
+ "max": 100,
94
+ "myObj": {
95
+ "myCascade": 10,
96
+ "myArray": [
97
+ {
98
+ "myValue": 20
99
+ }
100
+ ]
101
+ }
102
+ }
103
+ },
104
+ {
105
+ "type": "Feature",
106
+ "geometry": {
107
+ "type": "LineString",
108
+ "coordinates": [[10.082125662581083, 53.518872973925404], [11.01, 53.6]]
109
+ },
110
+ "properties": {
111
+ "id": "test2",
112
+ "value": 50,
113
+ "min": 10,
114
+ "max": 100
115
+ }
116
+ },
117
+ {
118
+ "type": "Feature",
119
+ "geometry": {
120
+ "type": "Polygon",
121
+ "coordinates": [[10.082125662581083, 53.518872973925404], [11.01, 53.6], [11.5, 54.0]]
122
+ },
123
+ "properties": {
124
+ "id": "test1",
125
+ "value": 50,
126
+ "min": 10,
127
+ "max": 100
128
+ }
129
+ },
130
+ {
131
+ "type": "Feature",
132
+ "geometry": {
133
+ "type": "MultiPoint",
134
+ "coordinates": [[11.01, 53.6], [11.5, 54.0]]
135
+ },
136
+ "properties": {
137
+ "id": "test1",
138
+ "value": 50,
139
+ "min": 10,
140
+ "max": 100
141
+ }
142
+ },
143
+ {
144
+ "type": "Feature",
145
+ "geometry": {
146
+ "type": "MultiLineString",
147
+ "coordinates": [
148
+ [[10, 10], [20, 20], [10, 40]],
149
+ [[40, 40], [30, 30], [40, 20], [30, 10]]
150
+ ]
151
+ },
152
+ "properties": {
153
+ "id": "test1",
154
+ "value": 50,
155
+ "min": 10,
156
+ "max": 100
157
+ }
158
+ },
159
+ {
160
+ "type": "Feature",
161
+ "geometry": {
162
+ "type": "MultiPolygon",
163
+ "coordinates": [
164
+ [
165
+ [[30, 20], [45, 40], [10, 40], [30, 20]]
166
+ ],
167
+ [
168
+ [[15, 5], [40, 10], [10, 20], [5, 10], [15, 5]]
169
+ ]
170
+ ]
171
+ },
172
+ "properties": {
173
+ "id": "test1",
174
+ "value": 50,
175
+ "min": 10,
176
+ "max": 100
177
+ }
178
+ },
179
+ {
180
+ "type": "Feature",
181
+ "geometry": {
182
+ "type": "GeometryCollection",
183
+ "geometries": [
184
+ {
185
+ "type": "Point",
186
+ "coordinates": [100.0, 0.0]
187
+ },
188
+ {
189
+ "type": "LineString",
190
+ "coordinates": [
191
+ [101.0, 0.0], [102.0, 1.0]
192
+ ]
193
+ }
194
+ ]
195
+ },
196
+ "properties": {
197
+ "@test": "test",
198
+ "id": "test1",
199
+ "value": 50,
200
+ "min": 10,
201
+ "max": 100
202
+ }
203
+ }
204
+ ]
205
+ },
206
+ rulesWithOneEntry = [
207
+ {
208
+ "conditions": {
209
+ "sequence": [0, 0],
210
+ "properties": {
211
+ "@Datastreams.0.Observations.0.result": [81, 101]}},
212
+ "style": {
213
+ "legendValue": "legendValueText",
214
+ "lineStrokeColor": [37, 52, 148, 1],
215
+ "lineStrokeDash": [20, 20, 5, 2000],
216
+ "lineStrokeDashOffset": 20,
217
+ "lineStrokeWidth": 5,
218
+ "labelField": ""}}
219
+ ],
220
+ warn = jest.spyOn(console, "warn").mockImplementation(() => {
221
+ null;
222
+ });
223
+
224
+ let jsonObjects;
225
+
226
+
227
+ beforeAll(function () {
228
+ jsonObjects = geojsonReader.readFeatures(jsonFeatures);
229
+ });
230
+ afterAll(() => {
231
+ warn.mockReset();
232
+ });
233
+
234
+ describe("createStyle", () => {
235
+ it("should return the correct style for a feature", () => {
236
+ const styleObject = {styleId: "myStyle", rules: [{style: {type: "Point"}}]},
237
+ isClustered = false,
238
+ style = createStyle.createStyle(styleObject, jsonObjects[0], isClustered, wfsImgPathFromConfig);
239
+
240
+ expect(style).toBeInstanceOf(Style);
241
+ });
242
+ });
243
+
244
+ describe("getSimpleGeometryStyle", function () {
245
+ it("should return ol point style", function () {
246
+ expect(createStyle.getSimpleGeometryStyle("Point", jsonObjects[0], rules[0], wfsImgPathFromConfig)).toBeInstanceOf(PointStyle);
247
+ expect(typeof createStyle.getSimpleGeometryStyle("Point", jsonObjects[0], rules[0], wfsImgPathFromConfig).getStyle().getImage().getStroke().getColor()).toBe("object");
248
+ expect(createStyle.getSimpleGeometryStyle("Point", jsonObjects[0], rules[0], wfsImgPathFromConfig).getStyle().getImage().getStroke().getColor()).toEqual([0, 0, 0, 1]);
249
+ });
250
+ it("should return ol linestring style", function () {
251
+ expect(createStyle.getSimpleGeometryStyle("LineString", jsonObjects[1], rules[1], wfsImgPathFromConfig)).toBeInstanceOf(LineStringStyle);
252
+ expect(typeof createStyle.getSimpleGeometryStyle("LineString", jsonObjects[1], rules[1], wfsImgPathFromConfig).getStyle().getStroke().getColor()).toBe("object");
253
+ expect(createStyle.getSimpleGeometryStyle("LineString", jsonObjects[1], rules[1], wfsImgPathFromConfig).getStyle().getStroke().getColor()).toEqual([255, 0, 0, 1]);
254
+ });
255
+ it("should return ol polygon style", function () {
256
+ expect(createStyle.getSimpleGeometryStyle("Polygon", jsonObjects[2], rules[2], wfsImgPathFromConfig)).toBeInstanceOf(PolygonStyle);
257
+ expect(typeof createStyle.getSimpleGeometryStyle("Polygon", jsonObjects[2], rules[2], wfsImgPathFromConfig).getStyle().getStroke().getColor()).toBe("object");
258
+ expect(createStyle.getSimpleGeometryStyle("Polygon", jsonObjects[2], rules[2], wfsImgPathFromConfig).getStyle().getStroke().getColor()).toEqual([255, 0, 0, 255]);
259
+ });
260
+ it("should return ol default style", function () {
261
+ expect(createStyle.getSimpleGeometryStyle("not exist", jsonObjects[0], null, wfsImgPathFromConfig)).toBeInstanceOf(Style);
262
+ });
263
+ });
264
+
265
+ describe("getMultiGeometryStyle", function () {
266
+ it("should return style array for multipoint", function () {
267
+ expect(Array.isArray(createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, wfsImgPathFromConfig))).toBe(true);
268
+ expect(createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, wfsImgPathFromConfig).length).toEqual(2);
269
+ });
270
+ it("should include ol point style", function () {
271
+ expect(createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, wfsImgPathFromConfig)[0]).toBeInstanceOf(PointStyle);
272
+ expect(typeof createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, wfsImgPathFromConfig)[0]).toBe("object");
273
+ expect(Array.isArray(createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, wfsImgPathFromConfig)[0].getStyle().getImage().getStroke().getColor())).toBe(true);
274
+ expect(createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, wfsImgPathFromConfig)[0].getStyle().getImage().getStroke().getColor()).toEqual([0, 0, 0, 1]);
275
+ });
276
+ it("should return style array for MultiLineString", function () {
277
+ expect(Array.isArray(createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], multiLineStringRules, wfsImgPathFromConfig))).toBe(true);
278
+ expect(createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], multiLineStringRules, wfsImgPathFromConfig).length).toEqual(2);
279
+ });
280
+ it("should include ol stroke style", function () {
281
+ expect(createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], multiLineStringRules, wfsImgPathFromConfig)[0]).toBeInstanceOf(LineStringStyle);
282
+ expect(createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], multiLineStringRules, wfsImgPathFromConfig)[0].getStyle().getStroke()).toBeInstanceOf(Stroke);
283
+ expect(Array.isArray(createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], multiLineStringRules, wfsImgPathFromConfig)[0].getStyle().getStroke().getColor())).toBe(true);
284
+ expect(createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], multiLineStringRules, wfsImgPathFromConfig)[0].getStyle().getStroke().getColor()).toEqual([255, 255, 255, 1]);
285
+ });
286
+ it("should return style array for MultiPolygon", function () {
287
+ expect(Array.isArray(createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, wfsImgPathFromConfig))).toBe(true);
288
+ expect(createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, wfsImgPathFromConfig).length).toEqual(2);
289
+ });
290
+ it("should include ol polygon style", function () {
291
+ expect(createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, wfsImgPathFromConfig)[0]).toBeInstanceOf(PolygonStyle);
292
+ expect(createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, wfsImgPathFromConfig)[0].getStyle().getStroke()).toBeInstanceOf(Stroke);
293
+ expect(createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, wfsImgPathFromConfig)[0].getStyle().getFill()).toBeInstanceOf(Fill);
294
+ expect(Array.isArray(createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, wfsImgPathFromConfig)[0].getStyle().getStroke().getColor())).toBe(true);
295
+ expect(createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, wfsImgPathFromConfig)[0].getStyle().getStroke().getColor()).toEqual([100, 100, 0, 1]);
296
+ });
297
+ it("should return style array for GeometryCollection", function () {
298
+ expect(Array.isArray(createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], rules, wfsImgPathFromConfig))).toBe(true);
299
+ expect(createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], rules, wfsImgPathFromConfig).length).toEqual(2);
300
+ });
301
+ it("should include ol line and point style", function () {
302
+ expect(createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], rules, wfsImgPathFromConfig)[0]).toBeInstanceOf(PointStyle);
303
+ expect(createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], multiLineStringRules, wfsImgPathFromConfig)[1]).toBeInstanceOf(LineStringStyle);
304
+ expect(createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], rules, wfsImgPathFromConfig)[0].getStyle().getImage().getStroke()).toBeInstanceOf(Stroke);
305
+ expect(Array.isArray(createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], rules, wfsImgPathFromConfig)[0].getStyle().getImage().getStroke().getColor())).toBe(true);
306
+ expect(createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], rules, wfsImgPathFromConfig)[0].getStyle().getImage().getStroke().getColor()).toEqual([0, 0, 0, 1]);
307
+ expect(createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], multiLineStringRules, wfsImgPathFromConfig)[1].getStyle().getStroke()).toBeInstanceOf(Stroke);
308
+ });
309
+ it("features with more geometries than rules (rules: 1, geometries: 2) should have style for all geometries - styleMultiGeomOnlyWithRule=false", function () {
310
+ expect(Array.isArray(createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], rulesWithOneEntry, wfsImgPathFromConfig))).toBe(true);
311
+ expect(createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], rulesWithOneEntry, wfsImgPathFromConfig).length).toEqual(2);
312
+ });
313
+ });
314
+
315
+ describe("isMultiGeometry", function () {
316
+ it("should return true with multi geometries", function () {
317
+ expect(createStyle.isMultiGeometry("MultiPoint")).toBe(true);
318
+ expect(createStyle.isMultiGeometry("MultiLineString")).toBe(true);
319
+ expect(createStyle.isMultiGeometry("MultiPolygon")).toBe(true);
320
+ expect(createStyle.isMultiGeometry("GeometryCollection")).toBe(true);
321
+ expect(createStyle.isMultiGeometry("Point")).toBe(false);
322
+ });
323
+ });
324
+
325
+ describe("getGeometryStyle", function () {
326
+ it("should return ol style with correct settings", function () {
327
+ expect(createStyle.getGeometryStyle(jsonObjects[0], rules, wfsImgPathFromConfig)).toBeInstanceOf(PointStyle);
328
+ expect(Array.isArray(createStyle.getGeometryStyle(jsonObjects[0], rules, wfsImgPathFromConfig).getStyle().getImage().getStroke().getColor())).toBe(true);
329
+ expect(createStyle.getGeometryStyle(jsonObjects[0], rules, wfsImgPathFromConfig).getStyle().getImage().getStroke().getColor()).toEqual([0, 0, 0, 1]);
330
+ });
331
+ it("should return default style if no rule is found", function () {
332
+ expect(Array.isArray(createStyle.getGeometryStyle(jsonObjects[0], [], wfsImgPathFromConfig).getStyle().getImage().getStroke().getColor())).toBe(true);
333
+ expect(createStyle.getGeometryStyle(jsonObjects[0], [], wfsImgPathFromConfig).getStyle().getImage().getStroke().getColor()).toEqual([0, 0, 0, 1]);
334
+ });
335
+ });
@@ -0,0 +1,42 @@
1
+ import {normalizeRgbColor, componentToHex, rgbToHex, hexToRgb} from "../../../src/vectorStyle/lib/colorConvertions";
2
+
3
+ describe("normalizeRgbColor", function () {
4
+ it("should be extend the given array with length 3 by value 1", function () {
5
+ expect(Array.isArray(normalizeRgbColor([255, 255, 255]))).toBe(true);
6
+ expect(normalizeRgbColor([255, 255, 255])).toEqual([255, 255, 255, 1]);
7
+ });
8
+ it("should be extend the given array with length 2 by value 1, 1", function () {
9
+ expect(Array.isArray(normalizeRgbColor([255, 255]))).toBe(true);
10
+ expect(normalizeRgbColor([255, 255])).toEqual([255, 255, 1, 1]);
11
+ });
12
+ it("should be return the input value, which is an array with length 4", function () {
13
+ expect(Array.isArray(normalizeRgbColor([0, 0, 0, 0]))).toBe(true);
14
+ expect(normalizeRgbColor([0, 0, 0, 0])).toEqual([0, 0, 0, 0]);
15
+ });
16
+ it("should be return the input value, which is an array with length > 4", function () {
17
+ expect(Array.isArray(normalizeRgbColor([1, 2, 3, 4, 5]))).toBe(true);
18
+ expect(normalizeRgbColor([1, 2, 3, 4, 5])).toEqual([1, 2, 3, 4]);
19
+ });
20
+ });
21
+
22
+ describe("componentToHex", function () {
23
+ it("should return the parsed 16 digits value", function () {
24
+ expect(componentToHex(2)).toEqual("02");
25
+ expect(componentToHex(213)).toEqual("d5");
26
+ });
27
+ });
28
+
29
+ describe("rgbToHex", function () {
30
+ it("should return the parsed hex value", function () {
31
+ expect(rgbToHex(2, 213, 33)).toEqual("#02d521");
32
+ });
33
+ });
34
+
35
+ describe("hexToRgb", function () {
36
+ it("should return the parsed rgb value", function () {
37
+ expect(hexToRgb("#020521")).toEqual([2, 5, 21]);
38
+ });
39
+ it("should return null", function () {
40
+ expect(hexToRgb("")).toEqual(null);
41
+ });
42
+ });