@masterportal/masterportalapi 2.12.0 → 2.14.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 (50) hide show
  1. package/.eslintrc +2 -1
  2. package/CHANGELOG.md +19 -1
  3. package/example/config/portal.json +8 -1
  4. package/example/config/services.json +10 -0
  5. package/example/index.js +34 -2
  6. package/jest.config.js +1 -1
  7. package/jest.setup.js +9 -1
  8. package/package.json +63 -63
  9. package/src/layer/geojson/index.js +3 -3
  10. package/src/lib/attributeMapper.js +231 -0
  11. package/src/lib/getValueFromObjectByPath.js +73 -0
  12. package/src/lib/thousandsSeparator.js +23 -0
  13. package/src/maps/olcs/3dUtils/wmsRasterSynchronizer.js +3 -0
  14. package/src/vectorStyle/createStyle.js +259 -0
  15. package/src/vectorStyle/lib/colorConvertions.js +97 -0
  16. package/src/vectorStyle/lib/createLegendInfo.js +28 -0
  17. package/src/vectorStyle/lib/getGeometryTypeFromService.js +153 -0
  18. package/src/vectorStyle/lib/getRuleForIndex.js +62 -0
  19. package/src/vectorStyle/lib/valueOperations.js +172 -0
  20. package/src/vectorStyle/styleList.js +281 -0
  21. package/src/vectorStyle/styles/defaultStyles.js +177 -0
  22. package/src/vectorStyle/styles/point/stylePoint.js +108 -0
  23. package/src/vectorStyle/styles/point/stylePointCircle.js +29 -0
  24. package/src/vectorStyle/styles/point/stylePointIcon.js +79 -0
  25. package/src/vectorStyle/styles/point/stylePointInterval.js +124 -0
  26. package/src/vectorStyle/styles/point/stylePointNominal.js +232 -0
  27. package/src/vectorStyle/styles/point/stylePointRegularShape.js +39 -0
  28. package/src/vectorStyle/styles/polygon/polygonStyleHatch.js +160 -0
  29. package/src/vectorStyle/styles/polygon/stylePolygon.js +125 -0
  30. package/src/vectorStyle/styles/style.js +161 -0
  31. package/src/vectorStyle/styles/styleCesium.js +106 -0
  32. package/src/vectorStyle/styles/styleLine.js +51 -0
  33. package/src/vectorStyle/styles/styleText.js +143 -0
  34. package/test/lib/attributeMapper.test.js +290 -0
  35. package/test/lib/getValueFromObjectByPath.test.js +61 -0
  36. package/test/lib/thousandsSeparator.test.js +58 -0
  37. package/test/vectorStyle/createStyle.test.js +335 -0
  38. package/test/vectorStyle/lib/colorConvertions.test.js +42 -0
  39. package/test/vectorStyle/lib/getRuleForIndex.test.js +132 -0
  40. package/test/vectorStyle/lib/valueOperations.test.js +191 -0
  41. package/test/vectorStyle/styles/point/stylePoint.test.js +28 -0
  42. package/test/vectorStyle/styles/point/stylePointCircle.test.js +30 -0
  43. package/test/vectorStyle/styles/point/stylePointIcon.test.js +83 -0
  44. package/test/vectorStyle/styles/point/stylePointInterval.test.js +57 -0
  45. package/test/vectorStyle/styles/point/stylePointNominal.test.js +84 -0
  46. package/test/vectorStyle/styles/point/stylePointRegularShape.test.js +24 -0
  47. package/test/vectorStyle/styles/polygon/polygonStyleHatch.test.js +95 -0
  48. package/test/vectorStyle/styles/polygon/stylePolygon.test.js +61 -0
  49. package/test/vectorStyle/styles/styleLine.test.js +29 -0
  50. package/test/vectorStyle/styles/styleText.test.js +49 -0
@@ -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
+ });
@@ -0,0 +1,132 @@
1
+ import {getRuleForIndex, getIndexedRule, getRulesForFeature} from "../../../src/vectorStyle/lib/getRuleForIndex";
2
+ import {GeoJSON} from "ol/format.js";
3
+
4
+ describe("getRuleForIndex", function () {
5
+
6
+ const geojsonReader = new GeoJSON(),
7
+ jsonFeatures = {
8
+ "type": "FeatureCollection",
9
+ "features": [
10
+ {
11
+ "type": "Feature",
12
+ "geometry": {
13
+ "type": "Point",
14
+ "coordinates": [10.082125662581083, 53.518872973925404]
15
+ },
16
+ "properties": {
17
+ "id": "test1",
18
+ "name": "myName",
19
+ "value": 50,
20
+ "min": 10,
21
+ "max": 100,
22
+ "myObj": {
23
+ "myCascade": 10,
24
+ "myArray": [
25
+ {
26
+ "myValue": 20
27
+ }
28
+ ]
29
+ }
30
+ }
31
+ },
32
+ {
33
+ "type": "Feature",
34
+ "geometry": {
35
+ "type": "LineString",
36
+ "coordinates": [[10.082125662581083, 53.518872973925404], [11.01, 53.6]]
37
+ },
38
+ "properties": {
39
+ "id": "test2",
40
+ "value": 50,
41
+ "min": 10,
42
+ "max": 100
43
+ }
44
+ }
45
+ ]
46
+ },
47
+ rules = [
48
+ {
49
+ "conditions": {
50
+ "properties": {
51
+ "id": "test1"
52
+ },
53
+ "sequence": [1, 1]
54
+ },
55
+ "style": {
56
+ "polygonStrokeColor": [100, 0, 0, 1],
57
+ "labelField": "name"
58
+ }
59
+ },
60
+ {
61
+ "conditions": {
62
+ "properties": {
63
+ "id": "test1"
64
+ }
65
+ },
66
+ "style": {
67
+ "polygonStrokeColor": [100, 100, 0, 1]
68
+ }
69
+ },
70
+ {
71
+ "style": {
72
+ "polygonStrokeColor": [100, 100, 100, 1]
73
+ }
74
+ }
75
+ ];
76
+
77
+ let jsonObjects;
78
+
79
+
80
+ beforeAll(function () {
81
+ jsonObjects = geojsonReader.readFeatures(jsonFeatures);
82
+ });
83
+
84
+ it("should return rule with conditions but without sequence", function () {
85
+ expect(typeof getRuleForIndex(rules, 0)).toBe("object");
86
+ expect(getRuleForIndex(rules, 0)).toEqual(expect.objectContaining({style: {polygonStrokeColor: [100, 100, 0, 1]}}));
87
+ expect(Array.isArray(getRuleForIndex(rules, 0).style.polygonStrokeColor)).toBe(true);
88
+ });
89
+ it("should return rule with conditions and sequence", function () {
90
+ expect(typeof getRuleForIndex(rules, 1)).toBe("object");
91
+ expect(getRuleForIndex(rules, 1)).toEqual(expect.objectContaining({style: {labelField: "name", polygonStrokeColor: [100, 0, 0, 1]}}));
92
+ expect(Array.isArray(getRuleForIndex(rules, 1).style.polygonStrokeColor)).toBe(true);
93
+ });
94
+ it("should return fallback rule", function () {
95
+ const newArray = [];
96
+
97
+ newArray.push(rules[2]);
98
+ expect(typeof getRuleForIndex(newArray, 0)).toBe("object");
99
+ expect(getRuleForIndex(newArray, 0)).toEqual(expect.objectContaining({style: {polygonStrokeColor: [100, 100, 100, 1]}}));
100
+ expect(Array.isArray(getRuleForIndex(newArray, 0).style.polygonStrokeColor)).toBe(true);
101
+ });
102
+ it("should return null if no rule can be used", function () {
103
+ const newArray = [];
104
+
105
+ newArray.push(rules[0]);
106
+ expect(getRuleForIndex(newArray, 0)).toBe(null);
107
+ });
108
+
109
+ describe("getIndexedRule", function () {
110
+ it("should return rule with fitting sequence", function () {
111
+ expect(typeof getIndexedRule(rules, 1)).toBe("object");
112
+ expect(getIndexedRule(rules, 1)).toEqual(expect.objectContaining({style: {labelField: "name", polygonStrokeColor: [100, 0, 0, 1]}}));
113
+ expect(Array.isArray(getIndexedRule(rules, 1).style.polygonStrokeColor)).toBe(true);
114
+ });
115
+ it("should return undefined if no rule fits sequence", function () {
116
+ expect(getIndexedRule(rules, 0)).toBe(undefined);
117
+ });
118
+ });
119
+
120
+ describe("getRulesForFeature", function () {
121
+ const styleObject = {rules: rules};
122
+
123
+ it("should return correct list of rules for feature1", function () {
124
+ expect(Array.isArray(getRulesForFeature(styleObject, jsonObjects[0]))).toBe(true);
125
+ expect(getRulesForFeature(styleObject, jsonObjects[0]).length).toEqual(3);
126
+ });
127
+ it("should return correct list of rules for feature2", function () {
128
+ expect(Array.isArray(getRulesForFeature(styleObject, jsonObjects[1]))).toBe(true);
129
+ expect(getRulesForFeature(styleObject, jsonObjects[1]).length).toEqual(1);
130
+ });
131
+ });
132
+ });