@masterportal/masterportalapi 2.15.1 → 2.16.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
@@ -3,6 +3,40 @@
3
3
 
4
4
  The [Semantic Versioning](https://semver.org/spec/v2.0.0.html) is used.
5
5
 
6
+ ## 2.16.0 - 2023-03-28
7
+ ### Added
8
+ - Added support for `npm` version ^9.1.3.
9
+
10
+ ### Changed
11
+ - The following packages have been updated:
12
+ - dependencies:
13
+ - core-js: 3.27.1 to 3.29.1
14
+ - ol: 7.2.2 to 7.3.0
15
+ - proj4: 2.8.1 to 2.9.0
16
+ - devDependencies:
17
+ - @babel/core: 7.20.12 to 7.21.3
18
+ - @babel/plugin-transform-modules-commonjs: 7.20.11 to 7.21.2
19
+ - eslint: 8.31.0 to 8.36.0
20
+ - jest: 29.3.1 to 29.5.0
21
+ - jest-environment-jsdom: 29.3.1 to 29.5.0
22
+ - jsdoc: 4.0.0 to 4.0.2
23
+ - sass: 1.57.1 to 1.59.3
24
+
25
+ ### Fixed
26
+ - Issue Masterportal.#870: Features with `null` style were shown with default style. However, the default style is only supposed to be used for fallbacks; `null` style features must explicitly be invisible. This has been resolved.
27
+ - Style of legend is now always not clustered.
28
+
29
+ ---
30
+
31
+ ## 2.15.2 - 2023-03-14
32
+ ### Changed
33
+ - Update parameters for getGeometryTypeFromService.getGeometryTypeFromWFS and getGeometryTypeFromService.getGeometryTypeFromOAF to pass wfsImgPath.
34
+
35
+ ### Fixed
36
+ - Fix imports in createLegendInfo.js
37
+
38
+ ---
39
+
6
40
  ## 2.15.1 - 2023-03-09
7
41
  ### Fixed
8
42
  - The `labelField` attribute is now evaluated correctly for a text style.
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.15.1",
4
+ "version": "2.16.0",
5
5
  "license": "MIT",
6
6
  "description": "Basic functions of the Masterportal as api",
7
7
  "repository": {
@@ -19,28 +19,28 @@
19
19
  "prepare": "husky install"
20
20
  },
21
21
  "dependencies": {
22
- "core-js": "^3.27.1",
23
- "ol": "7.2.2",
22
+ "core-js": "^3.29.1",
23
+ "ol": "7.3.0",
24
24
  "olcs": "^2.13.1",
25
- "proj4": "^2.8.1",
25
+ "proj4": "^2.9.0",
26
26
  "xml2js": "^0.4.23"
27
27
  },
28
28
  "devDependencies": {
29
- "@babel/core": "^7.20.12",
30
- "@babel/plugin-transform-modules-commonjs": "^7.20.11",
29
+ "@babel/core": "^7.21.3",
30
+ "@babel/plugin-transform-modules-commonjs": "^7.21.2",
31
31
  "@parcel/transformer-sass": "^2.6.0",
32
32
  "buffer": "^6.0.3",
33
33
  "canvas": "^2.11.0",
34
- "eslint": "^8.31.0",
34
+ "eslint": "^8.36.0",
35
35
  "events": "^3.3.0",
36
36
  "husky": "^8.0.3",
37
- "jest": "^29.3.1",
37
+ "jest": "^29.5.0",
38
38
  "jest-canvas-mock": "^2.4.0",
39
- "jest-environment-jsdom": "^29.3.1",
40
- "jsdoc": "^4.0.0",
39
+ "jest-environment-jsdom": "^29.5.0",
40
+ "jsdoc": "^4.0.2",
41
41
  "parcel": "^2.6.0",
42
42
  "process": "^0.11.10",
43
- "sass": "^1.57.1",
43
+ "sass": "^1.59.3",
44
44
  "stream-browserify": "^3.0.0",
45
45
  "timers-browserify": "^2.0.12",
46
46
  "use-resize-observer": "^9.1.0"
@@ -50,7 +50,7 @@
50
50
  },
51
51
  "engines": {
52
52
  "node": "^16.13.2 || ^18.12.0",
53
- "npm": "^8.1.2"
53
+ "npm": "^8.1.2 || ^9.3.1"
54
54
  },
55
55
  "homepage": "https://bitbucket.org/geowerkstatt-hamburg/masterportalapi#readme",
56
56
  "directories": {
@@ -32,7 +32,8 @@ function getSimpleGeometryStyle (geometryType, feature, rule, isClustered, wfsIm
32
32
  const style = rule?.style,
33
33
  legendValue = style ? style.legendValue : null,
34
34
  alreadyExisitingStyle = uniqueStyles.find(element => element.featureStyle === style && element.geometryType === geometryType);
35
- let styleObject;
35
+ let styleObject,
36
+ styleObjectForLegend = null;
36
37
 
37
38
  feature.legendValue = legendValue ? legendValue : null;
38
39
 
@@ -41,12 +42,21 @@ function getSimpleGeometryStyle (geometryType, feature, rule, isClustered, wfsIm
41
42
  }
42
43
  else if (geometryType === "Point") {
43
44
  styleObject = new PointStyle(feature, style, isClustered);
45
+ if (isClustered) {
46
+ styleObjectForLegend = new PointStyle(feature, style, false);
47
+ }
44
48
  }
45
49
  else if (geometryType === "LineString") {
46
50
  styleObject = new LineStringStyle(feature, style, isClustered);
51
+ if (isClustered) {
52
+ styleObjectForLegend = new LineStringStyle(feature, style, false);
53
+ }
47
54
  }
48
55
  else if (geometryType === "Polygon") {
49
56
  styleObject = new PolygonStyle(feature, style, isClustered);
57
+ if (isClustered) {
58
+ styleObjectForLegend = new PolygonStyle(feature, style, false);
59
+ }
50
60
  }
51
61
  else if (geometryType === "Cesium") {
52
62
  styleObject = new CesiumStyle(rule);
@@ -63,9 +73,14 @@ function getSimpleGeometryStyle (geometryType, feature, rule, isClustered, wfsIm
63
73
  console.warn("Geometry type not implemented: " + geometryType + " default style ist used for feature " + feature);
64
74
  return new Style();
65
75
  }
76
+
77
+ if (styleObjectForLegend !== null) {
78
+ styleObjectForLegend.initialize(feature, style, false, wfsImgPathFromConfig);
79
+ styleObjectForLegend.legendValue = legendValue;
80
+ }
66
81
  uniqueStyles.push({featureStyle: style, featureStyleObject: styleObject, geometryType});
67
82
  styleObject.initialize(feature, style, isClustered, wfsImgPathFromConfig);
68
- styleObject.addLegendInfo(geometryType, styleObject, rule);
83
+ styleObject.addLegendInfo(geometryType, styleObjectForLegend === null ? styleObject : styleObjectForLegend, rule);
69
84
  styleObject.legendValue = legendValue;
70
85
  return styleObject;
71
86
  }
@@ -1,28 +1,29 @@
1
- import {getSimpleGeometryStyle, getMultiGeometryStyle} from "../createStyle";
1
+ import createStyle from "../createStyle";
2
2
  /**
3
3
  * Creates the style objects for the layer
4
4
  * @param {object[]} rules styling rules from the styleObject
5
5
  * @param {string[]} geometryType Array of geometry types
6
+ * @param {String} wfsImgPath path to wfsImg from Config
6
7
  * @returns {void}
7
8
  */
8
- export function createLegendInfo (rules, geometryType) {
9
+ export function createLegendInfo (rules, geometryType, wfsImgPath) {
9
10
  let styleObject,
10
11
  simpleGeom;
11
12
 
12
13
  geometryType.forEach(geom => rules.forEach(rule => {
13
14
  if (geom === "MultiSurface") {
14
15
  simpleGeom = "Polygon";
15
- styleObject = getSimpleGeometryStyle(simpleGeom, "", rule, false);
16
+ styleObject = createStyle.getSimpleGeometryStyle(simpleGeom, "", rule, false, wfsImgPath);
16
17
  return styleObject;
17
18
  }
18
19
  else if (geom.includes("Multi")) {
19
20
  simpleGeom = geom.replace("Multi", "");
20
- styleObject = getMultiGeometryStyle(simpleGeom, "", rule, false);
21
+ styleObject = createStyle.getMultiGeometryStyle(simpleGeom, "", rule, false, wfsImgPath);
21
22
  return styleObject;
22
23
  }
23
24
 
24
25
  simpleGeom = geom;
25
- styleObject = getSimpleGeometryStyle(simpleGeom, "", rule, false);
26
+ styleObject = createStyle.getSimpleGeometryStyle(simpleGeom, "", rule, false, wfsImgPath);
26
27
  return styleObject;
27
28
  }));
28
29
  }
@@ -86,11 +86,12 @@ function getTypeAttributesFromSubelements (subElements = [], styleGeometryType =
86
86
  * @param {string} featureType wfs feature type from layer
87
87
  * @param {string[] | string} styleGeometryType The configured geometry type of the layer
88
88
  * @param {boolean} isSecured true if wfs is secured
89
+ * @param {String} wfsImgPath path to wfsImg from Config
89
90
  * @param {function} [callback] - called with services after loaded; called with false and error on error
90
91
  * @returns {void}
91
92
  */
92
93
  // eslint-disable-next-line max-params
93
- function getGeometryTypeFromWFS (rules, wfsURL, version, featureType, styleGeometryType, isSecured, callback) {
94
+ function getGeometryTypeFromWFS (rules, wfsURL, version, featureType, styleGeometryType, isSecured, wfsImgPath, callback) {
94
95
  const params = {
95
96
  "SERVICE": "WFS",
96
97
  "VERSION": version,
@@ -114,7 +115,7 @@ function getGeometryTypeFromWFS (rules, wfsURL, version, featureType, styleGeome
114
115
  const subElements = getSubelementsFromXML(responseXML, featureType),
115
116
  geometryTypes = getTypeAttributesFromSubelements(subElements, styleGeometryType);
116
117
 
117
- createLegendInfo(rules, geometryTypes);
118
+ createLegendInfo(rules, geometryTypes, wfsImgPath);
118
119
  }).catch(error => {
119
120
  return callback(error);
120
121
  });
@@ -125,10 +126,11 @@ function getGeometryTypeFromWFS (rules, wfsURL, version, featureType, styleGeome
125
126
  * @param {object[]} rules styling rules from the styleObject
126
127
  * @param {string} oafURL url from layer
127
128
  * @param {String} collection the collection name to fetch geometry type for
129
+ * @param {String} wfsImgPath path to wfsImg from Config
128
130
  * @param {function} [callback] - called with services after loaded; called with false and error on error
129
131
  * @returns {void}
130
132
  */
131
- function getGeometryTypeFromOAF (rules, oafURL, collection, callback) {
133
+ function getGeometryTypeFromOAF (rules, oafURL, collection, wfsImgPath, callback) {
132
134
  const url = oafURL + "/collections/" + collection + "/items?limit=1";
133
135
 
134
136
  fetch(url, {
@@ -140,7 +142,7 @@ function getGeometryTypeFromOAF (rules, oafURL, collection, callback) {
140
142
  const geometryType = response.data?.features[0]?.geometry?.type;
141
143
 
142
144
  if (geometryType) {
143
- createLegendInfo(rules, [geometryType]);
145
+ createLegendInfo(rules, [geometryType], wfsImgPath);
144
146
  }
145
147
  }).catch(error => {
146
148
  return callback(error);
@@ -46,6 +46,10 @@ class PointStyle extends StyleClass {
46
46
  * @returns {ol/style} - The created style.
47
47
  */
48
48
  getStyle () {
49
+ if (this.nullStyle) {
50
+ return null;
51
+ }
52
+
49
53
  const isClustered = this.isClustered;
50
54
  let type = this.attributes.type.toLowerCase();
51
55
 
@@ -52,7 +52,7 @@ export function createIconStyle (attributes, feature, isClustered) {
52
52
  if (!showCluster) {
53
53
  iconOptions.anchorXUnits = attributes.imageOffsetXUnit;
54
54
  iconOptions.anchorYUnits = attributes.imageOffsetYUnit;
55
- iconOptions.rotation = getRotationValue(attributes.rotation, feature.getProperties());
55
+ iconOptions.rotation = feature ? getRotationValue(attributes.rotation, feature.getProperties()) : 0;
56
56
  }
57
57
 
58
58
  return new Style({
@@ -36,6 +36,10 @@ class PolygonStyle extends StyleClass {
36
36
  * @returns {ol/style} - The created style.
37
37
  */
38
38
  getStyle () {
39
+ if (this.nullStyle) {
40
+ return null;
41
+ }
42
+
39
43
  const polygonFillColor = this.attributes.polygonFillColor,
40
44
  polygonFillHatch = this.attributes.polygonFillHatch;
41
45
 
@@ -14,6 +14,7 @@ class StyleClass {
14
14
  this.attributes = {};
15
15
  this.legendInfos = [];
16
16
  this.styleMultiGeomOnlyWithRule = false;
17
+ this.nullStyle = false;
17
18
  }
18
19
 
19
20
  /**
@@ -43,12 +44,16 @@ class StyleClass {
43
44
  // check if styles object is defined
44
45
  // if not, use defaults instead
45
46
  if (styles) {
47
+ this.nullStyle = false;
46
48
  Object.keys(styles).forEach(element => {
47
49
  const value = styles[element];
48
50
 
49
51
  this.attributes[element] = value;
50
52
  });
51
53
  }
54
+ else {
55
+ this.nullStyle = true;
56
+ }
52
57
  }
53
58
 
54
59
  /**
@@ -34,6 +34,10 @@ class LineStringStyle extends StyleClass {
34
34
  * @returns {ol/style/Style} - The created style.
35
35
  */
36
36
  getStyle () {
37
+ if (this.nullStyle) {
38
+ return null;
39
+ }
40
+
37
41
  return new Style({
38
42
  stroke: new Stroke({
39
43
  lineCap: this.attributes.lineStrokeCap,
@@ -36,6 +36,10 @@ class TextStyle extends StyleClass {
36
36
  * @returns {ol/style} - The created style.
37
37
  */
38
38
  getStyle () {
39
+ if (this.nullStyle) {
40
+ return null;
41
+ }
42
+
39
43
  const isClustered = this.isClustered,
40
44
  feature = this.feature,
41
45
  labelField = this.attributes.labelField;
@@ -242,23 +242,69 @@ describe("createStyle", () => {
242
242
  });
243
243
 
244
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]);
245
+ let isClustered = false;
246
+
247
+ it("should return ol point style - not clustered", function () {
248
+ const styleObject = createStyle.getSimpleGeometryStyle("Point", jsonObjects[0], rules[0], isClustered, wfsImgPathFromConfig);
249
+
250
+ expect(styleObject).toBeInstanceOf(PointStyle);
251
+ expect(typeof styleObject.getStyle().getImage().getStroke().getColor()).toBe("object");
252
+ expect(styleObject.getStyle().getImage().getStroke().getColor()).toEqual([255, 0, 0, 1]);
253
+ expect(styleObject.getLegendInfos()[0].styleObject.circleStrokeColor).toEqual([255, 0, 0, 1]);
254
+ });
255
+ it("should return ol linestring style - not clustered", function () {
256
+ const styleObject = createStyle.getSimpleGeometryStyle("LineString", jsonObjects[1], rules[1], isClustered, wfsImgPathFromConfig);
257
+
258
+ expect(styleObject).toBeInstanceOf(LineStringStyle);
259
+ expect(typeof styleObject.getStyle().getStroke().getColor()).toBe("object");
260
+ expect(styleObject.getStyle().getStroke().getColor()).toEqual([255, 0, 0, 1]);
261
+ expect(styleObject.getLegendInfos()[0].styleObject.lineStrokeColor).toEqual([255, 0, 0, 1]);
262
+ });
263
+ it("should return ol polygon style - not clustered", function () {
264
+ const styleObject = createStyle.getSimpleGeometryStyle("Polygon", jsonObjects[2], rules[2], isClustered, wfsImgPathFromConfig);
265
+
266
+ expect(styleObject).toBeInstanceOf(PolygonStyle);
267
+ expect(typeof styleObject.getStyle().getStroke().getColor()).toBe("object");
268
+ expect(styleObject.getStyle().getStroke().getColor()).toEqual([255, 0, 0, 255]);
269
+ expect(styleObject.getStyle().getFill().getColor()).toEqual([10, 200, 100, 0.5]);
270
+ expect(styleObject.getLegendInfos()[0].styleObject.polygonStrokeColor).toEqual([255, 0, 0, 255]);
271
+ expect(styleObject.getLegendInfos()[0].styleObject.polygonFillColor).toEqual([10, 200, 100, 0.5]);
249
272
  });
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]);
273
+ it("should return ol default style - not clustered", function () {
274
+ expect(createStyle.getSimpleGeometryStyle("not exist", jsonObjects[0], null, isClustered, wfsImgPathFromConfig)).toBeInstanceOf(Style);
254
275
  });
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]);
276
+
277
+ it("should return ol point style - clustered", function () {
278
+ isClustered = true;
279
+ const styleObject = createStyle.getSimpleGeometryStyle("Point", jsonObjects[0], rules[0], isClustered, wfsImgPathFromConfig);
280
+
281
+ expect(styleObject).toBeInstanceOf(PointStyle);
282
+ expect(typeof styleObject).toBe("object");
283
+ expect(styleObject.getStyle().getImage().getStroke().getColor()).toEqual([0, 0, 0, 1]);
284
+ expect(styleObject.getLegendInfos()[0].styleObject.circleStrokeColor).toEqual([255, 0, 0, 1]);
285
+ });
286
+ it("should return ol linestring style - clustered", function () {
287
+ isClustered = true;
288
+ const styleObject = createStyle.getSimpleGeometryStyle("LineString", jsonObjects[1], rules[1], isClustered, wfsImgPathFromConfig);
289
+
290
+ expect(styleObject).toBeInstanceOf(LineStringStyle);
291
+ expect(typeof styleObject.getStyle().getStroke().getColor()).toBe("object");
292
+ expect(styleObject.getStyle().getStroke().getColor()).toEqual([255, 0, 0, 1]);
293
+ expect(styleObject.getLegendInfos()[0].styleObject.lineStrokeColor).toEqual([255, 0, 0, 1]);
294
+ });
295
+ it("should return ol polygon style - clustered", function () {
296
+ isClustered = true;
297
+ const styleObject = createStyle.getSimpleGeometryStyle("Polygon", jsonObjects[2], rules[2], isClustered, wfsImgPathFromConfig);
298
+
299
+ expect(styleObject).toBeInstanceOf(PolygonStyle);
300
+ expect(typeof styleObject.getStyle().getStroke().getColor()).toBe("object");
301
+ expect(styleObject.getStyle().getStroke().getColor()).toEqual([255, 0, 0, 255]);
302
+ expect(styleObject.getLegendInfos()[0].styleObject.polygonStrokeColor).toEqual([255, 0, 0, 255]);
303
+ expect(styleObject.getLegendInfos()[0].styleObject.polygonFillColor).toEqual([10, 200, 100, 0.5]);
259
304
  });
260
- it("should return ol default style", function () {
261
- expect(createStyle.getSimpleGeometryStyle("not exist", jsonObjects[0], null, wfsImgPathFromConfig)).toBeInstanceOf(Style);
305
+ it("should return ol default style - clustered", function () {
306
+ isClustered = true;
307
+ expect(createStyle.getSimpleGeometryStyle("not exist", jsonObjects[0], null, isClustered, wfsImgPathFromConfig)).toBeInstanceOf(Style);
262
308
  });
263
309
  });
264
310
 
@@ -328,8 +374,7 @@ describe("getGeometryStyle", function () {
328
374
  expect(Array.isArray(createStyle.getGeometryStyle(jsonObjects[0], rules, wfsImgPathFromConfig).getStyle().getImage().getStroke().getColor())).toBe(true);
329
375
  expect(createStyle.getGeometryStyle(jsonObjects[0], rules, wfsImgPathFromConfig).getStyle().getImage().getStroke().getColor()).toEqual([0, 0, 0, 1]);
330
376
  });
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]);
377
+ it("should return null as style if no rule is found", function () {
378
+ expect(createStyle.getGeometryStyle(jsonObjects[0], [], wfsImgPathFromConfig).getStyle()).toBe(null);
334
379
  });
335
380
  });