@masterportal/masterportalapi 2.33.0 → 2.35.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.
package/CHANGELOG.md CHANGED
@@ -13,6 +13,23 @@
13
13
 
14
14
  ---
15
15
 
16
+ ## 2.35.0 - 2024-04-02
17
+
18
+ ### Added
19
+ - WMS: Support for using CQL filters by attribute added.
20
+
21
+ ### Fixed
22
+ - Issue Masterportal #1127: fixed styling of clustered and not clustered circles.
23
+ - WFST parsing featureType wfs.js with attribute required true by default.
24
+
25
+ ---
26
+ ## 2.34.0 - 2024-03-04
27
+
28
+ ### Changed
29
+ - stylePointCircle.js now has a zIndex of -1 to put unclustered Labels above clustered ones.
30
+
31
+ ---
32
+
16
33
  ## 2.33.0 - 2024-02-07
17
34
 
18
35
  ### Changed
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@masterportal/masterportalapi",
3
3
  "author": "Implementierungspartnerschaft Masterportal <info@masterportal.org> (https://www.masterportal.org)",
4
- "version": "2.33.0",
4
+ "version": "2.35.0",
5
5
  "license": "MIT",
6
6
  "description": "Basic functions of the Masterportal as api",
7
7
  "repository": {
package/src/layer/wfs.js CHANGED
@@ -447,7 +447,7 @@ function parseDescribeFeatureTypeResponse (responseData, featureType) {
447
447
  key: "",
448
448
  value: null,
449
449
  type: "string",
450
- required: false
450
+ required: true
451
451
  }));
452
452
  }
453
453
  return [];
package/src/layer/wms.js CHANGED
@@ -55,6 +55,7 @@ export function addOptionalParams (params, rawLayer) {
55
55
  * @param {boolean} rawLayer.singleTile - whether only one tile shall be requested that fills the whole view
56
56
  * @param {boolean} rawLayer.STYLES - styles of the layer, if available
57
57
  * @param {(string|number)} rawLayer.tilesize - if singleTile is true, this is the requested tilesize
58
+ * @param {string} rawLayer.cqlFilter - CQL filter
58
59
  * @returns {object} maps query parameter names to values
59
60
  */
60
61
  export function makeParams (rawLayer) {
@@ -66,7 +67,8 @@ export function makeParams (rawLayer) {
66
67
  LAYERS: rawLayer.layers,
67
68
  VERSION: rawLayer.version,
68
69
  TRANSPARENT: rawLayer.transparent,
69
- SINGLETILE: rawLayer.singleTile
70
+ SINGLETILE: rawLayer.singleTile,
71
+ CQL_FILTER: rawLayer.cqlFilter
70
72
  }, rawLayer.singleTile ? {} : {WIDTH: rawLayer.tilesize, HEIGHT: rawLayer.tilesize});
71
73
 
72
74
  params = addOptionalParams(params, rawLayer);
@@ -90,6 +92,7 @@ async function defaultTileLoadFunction (imageTile, src) {
90
92
  * @param {function} [rawLayer.olAttribution] - optional function that takes a module:ol/Map~FrameState and returns a string or an array of strings representing source attributions
91
93
  * @param {string|number} [rawLayer.tilesize] - optional needed to create the tileGrid
92
94
  * @param {string|"anonymous"} [rawLayer.crossOrigin] - optional needed for CORS requests of image data, to enable canvas export
95
+ * @param {string} [rawLayer.cqlFilter] - optional CQL filter to add to the request
93
96
  * @param {object} options - optional resolutions and origin to create the TileGrid
94
97
  * @param {Array} [options.resolutions] - optional resolutions to create the TileGrid, must be in descending order
95
98
  * @param {Array} [options.origin] - optional origin to create the TileGrid
@@ -61,7 +61,7 @@ class PointStyle extends StyleClass {
61
61
  return createIconStyle(this.attributes, this.feature, isClustered);
62
62
  }
63
63
  else if (type === "circle") {
64
- return createCircleStyle(this.attributes, isClustered);
64
+ return createCircleStyle(this.attributes, this.feature, isClustered);
65
65
  }
66
66
  else if (type === "nominal") {
67
67
  return isClustered ? createIconStyle(this.attributes, this.feature, isClustered) : createNominalPointStyle(this.attributes, this.feature, defaultStyle.point.imageName);
@@ -5,14 +5,16 @@ import {returnColor} from "../../lib/colorConvertions";
5
5
  * Creates pointStyle as circle.
6
6
  * all features get same circle.
7
7
  * @param {Object} attributes - The attributes from the circle
8
+ * @param {Object} feature - The feature
8
9
  * @param {Boolean} isClustered - true if features are clustered
9
10
  * @returns {ol/style} - The created style.
10
11
  */
11
- export function createCircleStyle (attributes, isClustered) {
12
- const radius = isClustered ? parseFloat(attributes.clusterCircleRadius, 10) : parseFloat(attributes.circleRadius, 10),
13
- fillcolor = isClustered ? returnColor(attributes.clusterCircleFillColor, "rgb") : returnColor(attributes.circleFillColor, "rgb"),
14
- strokecolor = isClustered ? returnColor(attributes.clusterCircleStrokeColor, "rgb") : returnColor(attributes.circleStrokeColor, "rgb"),
15
- strokewidth = isClustered ? parseFloat(attributes.clusterCircleStrokeWidth, 10) : parseFloat(attributes.circleStrokeWidth, 10);
12
+ export function createCircleStyle (attributes, feature, isClustered) {
13
+ const showCluster = isClustered && feature.get("features")?.length > 1,
14
+ radius = showCluster ? parseFloat(attributes.clusterCircleRadius, 10) : parseFloat(attributes.circleRadius, 10),
15
+ fillcolor = showCluster ? returnColor(attributes.clusterCircleFillColor, "rgb") : returnColor(attributes.circleFillColor, "rgb"),
16
+ strokecolor = showCluster ? returnColor(attributes.clusterCircleStrokeColor, "rgb") : returnColor(attributes.circleStrokeColor, "rgb"),
17
+ strokewidth = showCluster ? parseFloat(attributes.clusterCircleStrokeWidth, 10) : parseFloat(attributes.circleStrokeWidth, 10);
16
18
 
17
19
  return new Style({
18
20
  image: new CircleStyle({
@@ -24,6 +26,7 @@ export function createCircleStyle (attributes, isClustered) {
24
26
  color: strokecolor,
25
27
  width: strokewidth
26
28
  })
27
- })
29
+ }),
30
+ zIndex: -1
28
31
  });
29
32
  }
@@ -25,7 +25,8 @@ describe("wms.js", function () {
25
25
  LAYERS: "b",
26
26
  VERSION: "c",
27
27
  TRANSPARENT: "d",
28
- SINGLETILE: "e"
28
+ SINGLETILE: "e",
29
+ CQL_FILTER: "f"
29
30
  };
30
31
  });
31
32
 
@@ -38,6 +39,7 @@ describe("wms.js", function () {
38
39
  expect(extendedParams.VERSION).toEqual("c");
39
40
  expect(extendedParams.TRANSPARENT).toEqual("d");
40
41
  expect(extendedParams.SINGLETILE).toEqual("e");
42
+ expect(extendedParams.CQL_FILTER).toEqual("f");
41
43
  expect(extendedParams.TIME).toEqual("The time");
42
44
  expect(extendedParams.STYLES).not.toBeDefined();
43
45
  });
@@ -50,6 +52,7 @@ describe("wms.js", function () {
50
52
  expect(extendedParams.VERSION).toEqual("c");
51
53
  expect(extendedParams.TRANSPARENT).toEqual("d");
52
54
  expect(extendedParams.SINGLETILE).toEqual("e");
55
+ expect(extendedParams.CQL_FILTER).toEqual("f");
53
56
  expect(extendedParams.STYLES).toEqual("The style");
54
57
  expect(extendedParams.TIME).not.toBeDefined();
55
58
  });
@@ -5,76 +5,14 @@ import PolygonStyle from "../../src/vectorStyle/styles/polygon/stylePolygon";
5
5
  import {Style, Stroke, Fill} from "ol/style.js";
6
6
  import {GeoJSON} from "ol/format.js";
7
7
 
8
+ let rules,
9
+ jsonObjects,
10
+ multiLineStringRules,
11
+ multiPolygonRules,
12
+ isClustered;
13
+
8
14
  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
- }],
15
+ defaultStrokeColor = [0, 0, 0, 1],
78
16
  geojsonReader = new GeoJSON(),
79
17
  jsonFeatures = {
80
18
  "type": "FeatureCollection",
@@ -221,8 +159,6 @@ const wfsImgPathFromConfig = "/path/to/wfs/images",
221
159
  null;
222
160
  });
223
161
 
224
- let jsonObjects;
225
-
226
162
 
227
163
  beforeAll(function () {
228
164
  jsonObjects = geojsonReader.readFeatures(jsonFeatures);
@@ -231,10 +167,82 @@ afterAll(() => {
231
167
  warn.mockReset();
232
168
  });
233
169
 
170
+ beforeEach(() => {
171
+ isClustered = false;
172
+ rules = [
173
+ {
174
+ conditions: {
175
+ properties: {
176
+ id: "test1"
177
+ }
178
+ },
179
+ style: {
180
+ legendValue: "legendValueText",
181
+ circleStrokeColor: [255, 0, 0, 1],
182
+ type: "circle",
183
+ lineStrokeColor: [100, 0, 0, 1],
184
+ polygonStrokeColor: [100, 100, 0, 1]
185
+ }
186
+ },
187
+ {
188
+ style: {
189
+ legendValue: "LineStringLegend",
190
+ lineStrokeColor: [255, 0, 0, 1]
191
+ }
192
+ },
193
+ {
194
+ style: {
195
+ legendValue: "PolygonLegend",
196
+ polygonStrokeColor: [255, 0, 0, 255]
197
+ }
198
+ },
199
+ {
200
+ conditions: {
201
+ properties: {
202
+ value: [0, 50, "@min", "@max"]
203
+ }
204
+ },
205
+ style: {
206
+ legendValue: "legendValueText",
207
+ circleStrokeColor: [255, 0, 0, 1]
208
+ }
209
+ },
210
+ {
211
+ style: {
212
+ legendValue: "legendValueText",
213
+ circleStrokeColor: [255, 255, 255, 1]
214
+ }
215
+ }
216
+ ];
217
+ multiLineStringRules = [{
218
+ style: {
219
+ legendValue: "legendValueText",
220
+ lineStrokeColor: [255, 255, 255, 1]
221
+ }
222
+ },
223
+ {
224
+ style: {
225
+ legendValue: "legendValueText",
226
+ lineStrokeColor: [255, 0, 0, 1]
227
+ }
228
+ }];
229
+ multiPolygonRules = [{
230
+ style: {
231
+ legendValue: "legendValueText",
232
+ polygonStrokeColor: [100, 100, 0, 1]
233
+ }
234
+ },
235
+ {
236
+ style: {
237
+ legendValue: "legendValueText",
238
+ polygonStrokeColor: [255, 0, 0, 1]
239
+ }
240
+ }];
241
+ });
242
+
234
243
  describe("createStyle", () => {
235
244
  it("should return the correct style for a feature", () => {
236
245
  const styleObject = {styleId: "myStyle", rules: [{style: {type: "Point"}}]},
237
- isClustered = false,
238
246
  style = createStyle.createStyle(styleObject, jsonObjects[0], isClustered, wfsImgPathFromConfig);
239
247
 
240
248
  expect(style).toBeInstanceOf(Style);
@@ -254,7 +262,6 @@ describe("createStyle", () => {
254
262
  }
255
263
  }],
256
264
  styleObject = {styleId: "styleId", styleMultiGeomOnlyWithRule: true, rules: stylingRules},
257
- isClustered = false,
258
265
  multiLineStringFeature = jsonObjects[4],
259
266
  style = createStyle.createStyle(styleObject, multiLineStringFeature, isClustered, wfsImgPathFromConfig);
260
267
 
@@ -287,7 +294,6 @@ describe("createStyle", () => {
287
294
  }
288
295
  }],
289
296
  styleObject = {styleId: "styleId", styleMultiGeomOnlyWithRule: true, rules: stylingRules},
290
- isClustered = false,
291
297
  multiPolygonFeature = jsonObjects[5],
292
298
  style = createStyle.createStyle(styleObject, multiPolygonFeature, isClustered, wfsImgPathFromConfig);
293
299
 
@@ -320,7 +326,6 @@ describe("createStyle", () => {
320
326
  }
321
327
  }],
322
328
  styleObject = {styleId: "styleId", styleMultiGeomOnlyWithRule: true, rules: stylingRules},
323
- isClustered = false,
324
329
  geometryCollectionFeature = jsonObjects[6],
325
330
  style = createStyle.createStyle(styleObject, geometryCollectionFeature, isClustered, wfsImgPathFromConfig);
326
331
 
@@ -353,7 +358,6 @@ describe("createStyle", () => {
353
358
  }
354
359
  }],
355
360
  styleObject = {styleId: "styleId", styleMultiGeomOnlyWithRule: true, rules: stylingRules},
356
- isClustered = false,
357
361
  multiPointFeature = jsonObjects[3],
358
362
  style = createStyle.createStyle(styleObject, multiPointFeature, isClustered, wfsImgPathFromConfig);
359
363
 
@@ -367,8 +371,6 @@ describe("createStyle", () => {
367
371
  });
368
372
 
369
373
  describe("getSimpleGeometryStyle", function () {
370
- let isClustered = false;
371
-
372
374
  it("should return ol point style - not clustered", function () {
373
375
  const styleObject = createStyle.getSimpleGeometryStyle("Point", jsonObjects[0], rules[0], isClustered, wfsImgPathFromConfig);
374
376
 
@@ -400,12 +402,21 @@ describe("getSimpleGeometryStyle", function () {
400
402
  });
401
403
 
402
404
  it("should return ol point style - clustered", function () {
405
+ const geometry = jsonObjects[0].getGeometry();
406
+ let styleObject = null;
407
+
403
408
  isClustered = true;
404
- const styleObject = createStyle.getSimpleGeometryStyle("Point", jsonObjects[0], rules[0], isClustered, wfsImgPathFromConfig);
409
+ jsonObjects[0].get = (key) => {
410
+ if (key === "features") {
411
+ return [{id: "cluster1"}, {id: "cluster2"}];
412
+ }
413
+ return geometry;
414
+ };
415
+ styleObject = createStyle.getSimpleGeometryStyle("Point", jsonObjects[0], rules[0], isClustered, wfsImgPathFromConfig);
405
416
 
406
417
  expect(styleObject).toBeInstanceOf(PointStyle);
407
418
  expect(typeof styleObject).toBe("object");
408
- expect(styleObject.getStyle().getImage().getStroke().getColor()).toEqual([0, 0, 0, 1]);
419
+ expect(styleObject.getStyle().getImage().getStroke().getColor()).toEqual(defaultStrokeColor);
409
420
  expect(styleObject.getLegendInfos()[0].styleObject.circleStrokeColor).toEqual([255, 0, 0, 1]);
410
421
  });
411
422
  it("should return ol linestring style - clustered", function () {
@@ -435,51 +446,166 @@ describe("getSimpleGeometryStyle", function () {
435
446
 
436
447
  describe("getMultiGeometryStyle", function () {
437
448
  it("should return style array for multipoint", function () {
438
- expect(Array.isArray(createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, wfsImgPathFromConfig))).toBe(true);
439
- expect(createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, wfsImgPathFromConfig).length).toEqual(2);
449
+ const style = createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, isClustered, wfsImgPathFromConfig);
450
+
451
+ expect(Array.isArray(style)).toBe(true);
452
+ expect(style.length).toEqual(2);
453
+ });
454
+ it("should include ol point style - use defaultStyle for stroke color", function () {
455
+ delete rules[0].style.circleStrokeColor;
456
+ const style = createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, isClustered, wfsImgPathFromConfig);
457
+
458
+ expect(style[0]).toBeInstanceOf(PointStyle);
459
+ expect(style[1]).toBeInstanceOf(PointStyle);
460
+ expect(style[0].getStyle().getImage().getStroke().getColor()).toEqual(defaultStrokeColor);
461
+ expect(style[1].getStyle().getImage().getStroke().getColor()).toEqual(defaultStrokeColor);
462
+ });
463
+ it("should include ol point style - is clustered and use defaultStyle for stroke color", function () {
464
+ isClustered = true;
465
+ delete rules[0].style.circleStrokeColor;
466
+ const style = createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, isClustered, wfsImgPathFromConfig);
467
+
468
+ expect(style[0]).toBeInstanceOf(PointStyle);
469
+ expect(style[1]).toBeInstanceOf(PointStyle);
470
+ expect(style[0].getStyle().getImage().getStroke().getColor()).toEqual(defaultStrokeColor);
471
+ expect(style[1].getStyle().getImage().getStroke().getColor()).toEqual(defaultStrokeColor);
440
472
  });
441
- it("should include ol point style", function () {
442
- expect(createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, wfsImgPathFromConfig)[0]).toBeInstanceOf(PointStyle);
443
- expect(typeof createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, wfsImgPathFromConfig)[0]).toBe("object");
444
- expect(Array.isArray(createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, wfsImgPathFromConfig)[0].getStyle().getImage().getStroke().getColor())).toBe(true);
445
- expect(createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, wfsImgPathFromConfig)[0].getStyle().getImage().getStroke().getColor()).toEqual([0, 0, 0, 1]);
473
+ it("should include ol point style- use rules for stroke color", function () {
474
+ const style = createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, isClustered, wfsImgPathFromConfig);
475
+
476
+ expect(style[0]).toBeInstanceOf(PointStyle);
477
+ expect(style[1]).toBeInstanceOf(PointStyle);
478
+ expect(style[0].getStyle().getImage().getStroke().getColor()).toEqual(rules[0].style.circleStrokeColor);
479
+ expect(style[1].getStyle().getImage().getStroke().getColor()).toEqual(rules[0].style.circleStrokeColor);
480
+ });
481
+ it("should include ol point style- is clustered and use rules for stroke color", function () {
482
+ const geometry = jsonObjects[3].getGeometry();
483
+ let style = null;
484
+
485
+ isClustered = true;
486
+ jsonObjects[3].get = (key) => {
487
+ if (key === "features") {
488
+ return [{id: "cluster1"}, {id: "cluster2"}];
489
+ }
490
+ return geometry;
491
+ };
492
+ rules[0].style.clusterCircleStrokeColor = [1, 2, 3, 4];
493
+ style = createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, isClustered, wfsImgPathFromConfig);
494
+
495
+ expect(style[0]).toBeInstanceOf(PointStyle);
496
+ expect(style[1]).toBeInstanceOf(PointStyle);
497
+ expect(style[0].getStyle().getImage().getStroke().getColor()).toEqual(rules[0].style.clusterCircleStrokeColor);
498
+ expect(style[1].getStyle().getImage().getStroke().getColor()).toEqual(rules[0].style.clusterCircleStrokeColor);
446
499
  });
447
500
  it("should return style array for MultiLineString", function () {
448
- expect(Array.isArray(createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], multiLineStringRules, wfsImgPathFromConfig))).toBe(true);
449
- expect(createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], multiLineStringRules, wfsImgPathFromConfig).length).toEqual(2);
501
+ const style = createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], multiLineStringRules, isClustered, wfsImgPathFromConfig);
502
+
503
+ expect(Array.isArray(style)).toBe(true);
504
+ expect(style.length).toEqual(2);
450
505
  });
451
- it("should include ol stroke style", function () {
452
- expect(createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], multiLineStringRules, wfsImgPathFromConfig)[0]).toBeInstanceOf(LineStringStyle);
453
- expect(createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], multiLineStringRules, wfsImgPathFromConfig)[0].getStyle().getStroke()).toBeInstanceOf(Stroke);
454
- expect(Array.isArray(createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], multiLineStringRules, wfsImgPathFromConfig)[0].getStyle().getStroke().getColor())).toBe(true);
455
- expect(createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], multiLineStringRules, wfsImgPathFromConfig)[0].getStyle().getStroke().getColor()).toEqual([255, 255, 255, 1]);
506
+ it("MultiLineString: should include ol line style - use defaultStyle for stroke color", function () {
507
+ delete multiLineStringRules[0].style.lineStrokeColor;
508
+ delete multiLineStringRules[1].style.lineStrokeColor;
509
+ const style = createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], multiLineStringRules, isClustered, wfsImgPathFromConfig);
510
+
511
+ expect(style[0]).toBeInstanceOf(LineStringStyle);
512
+ expect(style[1]).toBeInstanceOf(LineStringStyle);
513
+ expect(style[0].getStyle().getStroke()).toBeInstanceOf(Stroke);
514
+ expect(style[1].getStyle().getStroke()).toBeInstanceOf(Stroke);
515
+ expect(style[0].getStyle().getStroke().getColor()).toEqual(defaultStrokeColor);
516
+ expect(style[1].getStyle().getStroke().getColor()).toEqual(defaultStrokeColor);
517
+ });
518
+ it("MultiLineString: should include ol line style - use rules for stroke color", function () {
519
+ const style = createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], multiLineStringRules, isClustered, wfsImgPathFromConfig);
520
+
521
+ expect(style[0]).toBeInstanceOf(LineStringStyle);
522
+ expect(style[1]).toBeInstanceOf(LineStringStyle);
523
+ expect(style[0].getStyle().getStroke()).toBeInstanceOf(Stroke);
524
+ expect(style[1].getStyle().getStroke()).toBeInstanceOf(Stroke);
525
+ expect(style[0].getStyle().getStroke().getColor()).toEqual(multiLineStringRules[0].style.lineStrokeColor);
526
+ expect(style[1].getStyle().getStroke().getColor()).toEqual(multiLineStringRules[0].style.lineStrokeColor);
456
527
  });
457
528
  it("should return style array for MultiPolygon", function () {
458
- expect(Array.isArray(createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, wfsImgPathFromConfig))).toBe(true);
459
- expect(createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, wfsImgPathFromConfig).length).toEqual(2);
529
+ const style = createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, isClustered, wfsImgPathFromConfig);
530
+
531
+ expect(Array.isArray(style)).toBe(true);
532
+ expect(style.length).toEqual(2);
460
533
  });
461
- it("should include ol polygon style", function () {
462
- expect(createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, wfsImgPathFromConfig)[0]).toBeInstanceOf(PolygonStyle);
463
- expect(createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, wfsImgPathFromConfig)[0].getStyle().getStroke()).toBeInstanceOf(Stroke);
464
- expect(createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, wfsImgPathFromConfig)[0].getStyle().getFill()).toBeInstanceOf(Fill);
465
- expect(Array.isArray(createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, wfsImgPathFromConfig)[0].getStyle().getStroke().getColor())).toBe(true);
466
- expect(createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, wfsImgPathFromConfig)[0].getStyle().getStroke().getColor()).toEqual([100, 100, 0, 1]);
534
+ it("should include ol polygon style - use defaultStyle for stroke color", function () {
535
+ delete multiPolygonRules[0].style.polygonStrokeColor;
536
+ delete multiPolygonRules[1].style.polygonStrokeColor;
537
+ const style = createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, isClustered, wfsImgPathFromConfig);
538
+
539
+ expect(style[0]).toBeInstanceOf(PolygonStyle);
540
+ expect(style[0].getStyle().getStroke()).toBeInstanceOf(Stroke);
541
+ expect(style[0].getStyle().getFill()).toBeInstanceOf(Fill);
542
+ expect(style[0].getStyle().getStroke().getColor()).toEqual(defaultStrokeColor);
543
+ expect(style[1].getStyle().getStroke()).toBeInstanceOf(Stroke);
544
+ expect(style[1].getStyle().getFill()).toBeInstanceOf(Fill);
545
+ expect(style[1].getStyle().getStroke().getColor()).toEqual(defaultStrokeColor);
546
+ });
547
+ it("should include ol polygon style - use rules for stroke color", function () {
548
+ const style = createStyle.getMultiGeometryStyle("MultiPolygon", jsonObjects[5], multiPolygonRules, isClustered, wfsImgPathFromConfig);
549
+
550
+ expect(style[0]).toBeInstanceOf(PolygonStyle);
551
+ expect(style[0].getStyle().getStroke()).toBeInstanceOf(Stroke);
552
+ expect(style[0].getStyle().getFill()).toBeInstanceOf(Fill);
553
+ expect(style[0].getStyle().getStroke().getColor()).toEqual(multiPolygonRules[0].style.polygonStrokeColor);
554
+ expect(style[1].getStyle().getStroke()).toBeInstanceOf(Stroke);
555
+ expect(style[1].getStyle().getFill()).toBeInstanceOf(Fill);
556
+ expect(style[1].getStyle().getStroke().getColor()).toEqual(multiPolygonRules[0].style.polygonStrokeColor);
467
557
  });
468
558
  it("should return style array for GeometryCollection", function () {
469
- expect(Array.isArray(createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], rules, wfsImgPathFromConfig))).toBe(true);
470
- expect(createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], rules, wfsImgPathFromConfig).length).toEqual(2);
559
+ const style = createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], rules, isClustered, wfsImgPathFromConfig);
560
+
561
+ expect(Array.isArray(style)).toBe(true);
562
+ expect(style.length).toEqual(2);
471
563
  });
472
- it("should include ol line and point style", function () {
473
- expect(createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], rules, wfsImgPathFromConfig)[0]).toBeInstanceOf(PointStyle);
474
- expect(createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], multiLineStringRules, wfsImgPathFromConfig)[1]).toBeInstanceOf(LineStringStyle);
475
- expect(createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], rules, wfsImgPathFromConfig)[0].getStyle().getImage().getStroke()).toBeInstanceOf(Stroke);
476
- expect(Array.isArray(createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], rules, wfsImgPathFromConfig)[0].getStyle().getImage().getStroke().getColor())).toBe(true);
477
- expect(createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], rules, wfsImgPathFromConfig)[0].getStyle().getImage().getStroke().getColor()).toEqual([0, 0, 0, 1]);
478
- expect(createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], multiLineStringRules, wfsImgPathFromConfig)[1].getStyle().getStroke()).toBeInstanceOf(Stroke);
564
+ it("should include ol line and point style - use defaultStyle for stroke color", function () {
565
+ delete rules[0].style.circleStrokeColor;
566
+ delete rules[0].style.lineStrokeColor;
567
+ delete multiLineStringRules[0].style.lineStrokeColor;
568
+ const style = createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], rules, isClustered, wfsImgPathFromConfig),
569
+ multiLineStyle = createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], multiLineStringRules, isClustered, wfsImgPathFromConfig);
570
+
571
+ expect(style[0]).toBeInstanceOf(PointStyle);
572
+ expect(style[0].getStyle().getImage().getStroke()).toBeInstanceOf(Stroke);
573
+ expect(style[0].getStyle().getImage().getStroke().getColor()).toEqual(defaultStrokeColor);
574
+ expect(style[1]).toBeInstanceOf(LineStringStyle);
575
+ expect(style[1].getStyle().getStroke()).toBeInstanceOf(Stroke);
576
+ expect(style[1].getStyle().getStroke().getColor()).toEqual(defaultStrokeColor);
577
+
578
+ expect(multiLineStyle[0]).toBeInstanceOf(PointStyle);
579
+ expect(multiLineStyle[0].getStyle().getImage().getStroke().getColor()).toEqual(defaultStrokeColor);
580
+ expect(multiLineStyle[1]).toBeInstanceOf(LineStringStyle);
581
+ expect(multiLineStyle[1].getStyle().getStroke()).toBeInstanceOf(Stroke);
582
+ expect(multiLineStyle[1].getStyle().getStroke().getColor()).toEqual(defaultStrokeColor);
583
+ });
584
+ it("should include ol line and point style - use rules for stroke color", function () {
585
+ const style = createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], rules, isClustered, wfsImgPathFromConfig),
586
+ multiLineStyle = createStyle.getMultiGeometryStyle("GeometryCollection", jsonObjects[6], multiLineStringRules, isClustered, wfsImgPathFromConfig);
587
+
588
+ expect(style[0]).toBeInstanceOf(PointStyle);
589
+ expect(style[0].getStyle().getImage().getStroke()).toBeInstanceOf(Stroke);
590
+ expect(style[0].getStyle().getImage().getStroke().getColor()).toEqual(rules[0].style.circleStrokeColor);
591
+ expect(style[1]).toBeInstanceOf(LineStringStyle);
592
+ expect(style[1].getStyle().getStroke()).toBeInstanceOf(Stroke);
593
+ expect(style[1].getStyle().getStroke().getColor()).toEqual(rules[0].style.lineStrokeColor);
594
+
595
+ expect(multiLineStyle[0]).toBeInstanceOf(PointStyle);
596
+ // multiLineStringRules[0].style.circleStrokeColor is not defined --> use defaultStrokeColor
597
+ expect(multiLineStyle[0].getStyle().getImage().getStroke().getColor()).toEqual(defaultStrokeColor);
598
+ expect(multiLineStyle[1]).toBeInstanceOf(LineStringStyle);
599
+ expect(multiLineStyle[1].getStyle().getStroke()).toBeInstanceOf(Stroke);
600
+ expect(multiLineStyle[1].getStyle().getStroke().getColor()).toEqual(multiLineStringRules[0].style.lineStrokeColor);
479
601
  });
480
- it("features with more geometries than rules (rules: 1, geometries: 2) should have style for all geometries - styleMultiGeomOnlyWithRule=false", function () {
481
- expect(Array.isArray(createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], rulesWithOneEntry, wfsImgPathFromConfig))).toBe(true);
482
- expect(createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], rulesWithOneEntry, wfsImgPathFromConfig).length).toEqual(2);
602
+ it("features with more geometries than rules (rules: 1, geometries: 2) should have style for all geometries - 'styleMultiGeomOnlyWithRule' is not set", function () {
603
+ const style = createStyle.getMultiGeometryStyle("MultiLineString", jsonObjects[4], rulesWithOneEntry, isClustered, wfsImgPathFromConfig);
604
+
605
+ expect(Array.isArray(style)).toBe(true);
606
+ expect(style.length).toEqual(2);
607
+ expect(style[0].getStyle().getStroke().getColor()).toEqual(rulesWithOneEntry[0].style.lineStrokeColor);
608
+ expect(style[1].getStyle()).toEqual(null);
483
609
  });
484
610
  });
485
611
 
@@ -494,12 +620,22 @@ describe("isMultiGeometry", function () {
494
620
  });
495
621
 
496
622
  describe("getGeometryStyle", function () {
497
- it("should return ol style with correct settings", function () {
498
- expect(createStyle.getGeometryStyle(jsonObjects[0], rules, wfsImgPathFromConfig)).toBeInstanceOf(PointStyle);
499
- expect(Array.isArray(createStyle.getGeometryStyle(jsonObjects[0], rules, wfsImgPathFromConfig).getStyle().getImage().getStroke().getColor())).toBe(true);
500
- expect(createStyle.getGeometryStyle(jsonObjects[0], rules, wfsImgPathFromConfig).getStyle().getImage().getStroke().getColor()).toEqual([0, 0, 0, 1]);
623
+ it("should return point style with correct settings", function () {
624
+ const style = createStyle.getGeometryStyle(jsonObjects[0], rules, isClustered, wfsImgPathFromConfig);
625
+
626
+ expect(style).toBeInstanceOf(PointStyle);
627
+ expect(Array.isArray(style.getStyle().getImage().getStroke().getColor())).toBe(true);
628
+ expect(style.getStyle().getImage().getStroke().getColor()).toEqual(rules[0].style.circleStrokeColor);
629
+ });
630
+ it("should return 'MultiPoint' style with correct settings", function () {
631
+ const style = createStyle.getGeometryStyle(jsonObjects[3], rules, isClustered, wfsImgPathFromConfig);
632
+
633
+ expect(Array.isArray(style)).toBe(true);
634
+ expect(style.length).toEqual(2);
635
+ expect(style[0].getStyle().getImage().getStroke().getColor()).toEqual(rules[0].style.circleStrokeColor);
636
+ expect(style[1].getStyle().getImage().getStroke().getColor()).toEqual(rules[0].style.circleStrokeColor);
501
637
  });
502
638
  it("should return null as style if no rule is found", function () {
503
- expect(createStyle.getGeometryStyle(jsonObjects[0], [], wfsImgPathFromConfig).getStyle()).toBe(null);
639
+ expect(createStyle.getGeometryStyle(jsonObjects[0], [], isClustered, wfsImgPathFromConfig).getStyle()).toBe(null);
504
640
  });
505
641
  });
@@ -7,24 +7,61 @@ describe("stylePointCircle.js", () => {
7
7
  circleRadius: 15,
8
8
  circleFillColor: [10, 200, 100, 0.5],
9
9
  circleStrokeColor: [10, 200, 100, 0.5],
10
- circleStrokeWidth: 1
11
- },
12
- clusterAttributes = {
10
+ circleStrokeWidth: 1,
13
11
  clusterCircleRadius: 20,
14
12
  clusterCircleFillColor: [10, 200, 100, 0.5],
15
13
  clusterCircleStrokeColor: [10, 200, 100, 0.5],
16
14
  clusterCircleStrokeWidth: 1
15
+ },
16
+ feature = {
17
+ getProperties: () => {
18
+ return {
19
+ name: "singleFeature",
20
+ id: "123"
21
+ };
22
+ },
23
+ get: () => {
24
+ return [];
25
+ }
26
+ },
27
+ clusteredFeature = {
28
+ get: () => {
29
+ return [
30
+ {
31
+ name: "singleFeature1",
32
+ id: "123"
33
+ },
34
+ {
35
+ name: "singleFeature2",
36
+ id: "456"
37
+ }
38
+ ];
39
+ }
17
40
  };
18
41
 
19
42
  it("should create circle style", () => {
20
- expect(stylePointCircle.createCircleStyle(attributes, false)).toBeInstanceOf(Style);
21
- expect(stylePointCircle.createCircleStyle(attributes, false).getImage()).toBeInstanceOf(Circle);
22
- expect(stylePointCircle.createCircleStyle(attributes, false).getImage().getRadius()).toEqual(15);
43
+ const style = stylePointCircle.createCircleStyle(attributes, feature, false);
44
+
45
+ expect(style).toBeInstanceOf(Style);
46
+ expect(style.getImage()).toBeInstanceOf(Circle);
47
+ expect(style.getImage().getRadius()).toEqual(15);
48
+ expect(style.getImage().getFill().getColor()).toEqual(attributes.circleFillColor);
23
49
  });
24
50
  it("should create circle cluster style", () => {
25
- expect(stylePointCircle.createCircleStyle(clusterAttributes, true)).toBeInstanceOf(Style);
26
- expect(stylePointCircle.createCircleStyle(clusterAttributes, true).getImage()).toBeInstanceOf(Circle);
27
- expect(stylePointCircle.createCircleStyle(clusterAttributes, true).getImage().getRadius()).toEqual(20);
51
+ const style = stylePointCircle.createCircleStyle(attributes, clusteredFeature, true);
52
+
53
+ expect(style).toBeInstanceOf(Style);
54
+ expect(style.getImage()).toBeInstanceOf(Circle);
55
+ expect(style.getImage().getRadius()).toEqual(20);
56
+ expect(style.getImage().getFill().getColor()).toEqual(attributes.clusterCircleFillColor);
57
+ });
58
+ it("should create circle not cluster style - respects feature.get('features')", () => {
59
+ const style = stylePointCircle.createCircleStyle(attributes, feature, true);
60
+
61
+ expect(style).toBeInstanceOf(Style);
62
+ expect(style.getImage()).toBeInstanceOf(Circle);
63
+ expect(style.getImage().getRadius()).toEqual(15);
64
+ expect(style.getImage().getFill().getColor()).toEqual(attributes.circleFillColor);
28
65
  });
29
66
  });
30
67
  });