@masterportal/masterportalapi 2.34.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
@@ -11,6 +11,17 @@
11
11
  ### Removed
12
12
  ### Fixed
13
13
 
14
+ ---
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
+
14
25
  ---
15
26
  ## 2.34.0 - 2024-03-04
16
27
 
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.34.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({
@@ -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
  });
@@ -402,8 +402,17 @@ describe("getSimpleGeometryStyle", function () {
402
402
  });
403
403
 
404
404
  it("should return ol point style - clustered", function () {
405
+ const geometry = jsonObjects[0].getGeometry();
406
+ let styleObject = null;
407
+
405
408
  isClustered = true;
406
- 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);
407
416
 
408
417
  expect(styleObject).toBeInstanceOf(PointStyle);
409
418
  expect(typeof styleObject).toBe("object");
@@ -470,9 +479,18 @@ describe("getMultiGeometryStyle", function () {
470
479
  expect(style[1].getStyle().getImage().getStroke().getColor()).toEqual(rules[0].style.circleStrokeColor);
471
480
  });
472
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
+
473
485
  isClustered = true;
486
+ jsonObjects[3].get = (key) => {
487
+ if (key === "features") {
488
+ return [{id: "cluster1"}, {id: "cluster2"}];
489
+ }
490
+ return geometry;
491
+ };
474
492
  rules[0].style.clusterCircleStrokeColor = [1, 2, 3, 4];
475
- const style = createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, isClustered, wfsImgPathFromConfig);
493
+ style = createStyle.getMultiGeometryStyle("MultiPoint", jsonObjects[3], rules, isClustered, wfsImgPathFromConfig);
476
494
 
477
495
  expect(style[0]).toBeInstanceOf(PointStyle);
478
496
  expect(style[1]).toBeInstanceOf(PointStyle);
@@ -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
  });