@masterportal/masterportalapi 2.44.0 → 2.45.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
@@ -18,6 +18,22 @@
18
18
 
19
19
  ---
20
20
 
21
+ ## 2.45.0 - 2025-01-28
22
+
23
+ ### Added
24
+ - vectorStyle:
25
+ - extended 3d example by tileset styling
26
+
27
+ ### Changed
28
+ - vectorStyle:
29
+ - renamed configured style type="Cesium" to type="cesium"
30
+
31
+ ### Fixed
32
+ - vectorStyle:
33
+ - fixed styling for type "cesium"
34
+
35
+ ---
36
+
21
37
  ## 2.44.0 - 2025-01-22
22
38
 
23
39
  ### Added
@@ -62,6 +62,16 @@
62
62
  "circle-rotate-with-view": true,
63
63
  "circle-opacity": 0.8
64
64
  }
65
+ },
66
+ {
67
+ "id": "4002",
68
+ "name": "Gebäude LoD2",
69
+ "url": "https://daten-hamburg.de/gdi3d/datasource-data/LoD2",
70
+ "typ": "TileSet3D",
71
+ "styleId": "3DTileSetStyle",
72
+ "cesium3DTilesetOptions": {
73
+ "maximumScreenSpaceError": 6
74
+ }
65
75
  }
66
76
  ],
67
77
  "cesiumLib":"https://geoportal-hamburg.de/mastercode/cesium/latest/Cesium.js",
@@ -58,6 +58,7 @@
58
58
  "name": "Gebäude LoD2",
59
59
  "url": "https://daten-hamburg.de/gdi3d/datasource-data/LoD2",
60
60
  "typ": "TileSet3D",
61
+ "styleId": "3DTileSetStyle",
61
62
  "cesium3DTilesetOptions": {
62
63
  "maximumScreenSpaceError": 6
63
64
  }
package/example/index.js CHANGED
@@ -235,6 +235,23 @@ window.mpapi.search("Mümmelmannsberg 72", {
235
235
 
236
236
 
237
237
  // Add 3D functionality to the example:
238
+ // ---------------------------------------
239
+ // example style tileset by vectorstyling using style_v3.json
240
+ function getTilesetStyle (styleId) {
241
+ const styleObject = styleList.returnStyleObject(styleId);
242
+
243
+ if (styleObject !== undefined) {
244
+ const createdStyle = createStyle.createStyle(styleObject, undefined, false, config.wfsImgPath),
245
+ options = {
246
+ color: {
247
+ conditions: createdStyle
248
+ }
249
+ };
250
+
251
+ return new Cesium.Cesium3DTileStyle(options);
252
+ }
253
+ return undefined;
254
+ }
238
255
 
239
256
  // add a click-listener to button, that creates a 3D-map on click
240
257
  document.getElementById("enable").addEventListener("click", function () {
@@ -275,11 +292,14 @@ document.getElementById("enable").addEventListener("click", function () {
275
292
 
276
293
  window.mpapi.map = map3D;
277
294
  tilesetLayer = new mpapi.Tileset(rawLayerTileset, window.mpapi.map);
295
+ tilesetLayer.tileset?.then(tileset => {
296
+ tileset.style = getTilesetStyle(rawLayerTileset.styleId);
297
+ });
278
298
  tilesetLayer.setVisible(true, window.mpapi.map);
279
299
 
280
300
  // entities are 2 simple buildings in the park 'planten und blomen' near Tiergartenstraße
281
301
  mpapi.entities.createLayer(rawLayerEntities, window.mpapi.map);
282
- // mpapi.entities.setVisible(true, rawLayerEntities, window.mpapi.map);
302
+ mpapi.entities.setVisible(true, rawLayerEntities, window.mpapi.map);
283
303
 
284
304
  mpapi.terrain.createLayer(rawLayerTerrain, window.mpapi.map);
285
305
  mpapi.terrain.setVisible(true, rawLayerTerrain, window.mpapi.map);
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.44.0",
4
+ "version": "2.45.0",
5
5
  "license": "MIT",
6
6
  "description": "Basic functions of the Masterportal as api",
7
7
  "repository": {
@@ -16,7 +16,7 @@ let legendInformationLength = 0;
16
16
  * @returns {Boolean} is geometrytype a multiGeometry
17
17
  */
18
18
  function isMultiGeometry (geometryType) {
19
- return geometryType === "MultiPoint" || geometryType === "MultiLineString" || geometryType === "MultiPolygon" || geometryType === "GeometryCollection" || geometryType === "Cesium";
19
+ return geometryType === "MultiPoint" || geometryType === "MultiLineString" || geometryType === "MultiPolygon" || geometryType === "GeometryCollection" || geometryType === "cesium";
20
20
  }
21
21
 
22
22
  /**
@@ -34,7 +34,9 @@ function getSimpleGeometryStyle (geometryType, feature, rule, isClustered, wfsIm
34
34
  let styleObject,
35
35
  styleObjectForLegend = null;
36
36
 
37
- feature.legendValue = legendValue ? legendValue : null;
37
+ if (feature) {
38
+ feature.legendValue = legendValue ? legendValue : null;
39
+ }
38
40
 
39
41
  if (geometryType === "Point") {
40
42
  styleObject = new PointStyle(feature, style, isClustered);
@@ -54,10 +56,10 @@ function getSimpleGeometryStyle (geometryType, feature, rule, isClustered, wfsIm
54
56
  styleObjectForLegend = new PolygonStyle(feature, style, false);
55
57
  }
56
58
  }
57
- else if (geometryType === "Cesium") {
59
+ else if (geometryType === "cesium") {
58
60
  styleObject = new CesiumStyle(rule);
59
61
  styleObject.initialize(rule);
60
- styleObject.addLegendInfo("Cesium", styleObject, rule);
62
+ styleObject.addLegendInfo("cesium", styleObject, rule);
61
63
  styleObject.legendValue = legendValue;
62
64
  return styleObject;
63
65
  }
@@ -128,7 +130,7 @@ function getMultiGeometryStyle (geometryType, feature, rules, isClustered, wfsIm
128
130
  }
129
131
  });
130
132
  }
131
- else if (geometryType === "Cesium") {
133
+ else if (geometryType === "cesium") {
132
134
  rules.forEach(rule => {
133
135
  const simpleStyle = getSimpleGeometryStyle(geometryType, feature, rule, isClustered, wfsImgPathFromConfig);
134
136
 
@@ -153,7 +155,7 @@ function getMultiGeometryStyle (geometryType, feature, rules, isClustered, wfsIm
153
155
  * @returns {ol/style/Style} style is always returned
154
156
  */
155
157
  function getGeometryStyle (feature, rules, isClustered, wfsImgPathFromConfig) {
156
- const geometryType = feature ? feature.getGeometry().getType() : "Cesium";
158
+ const geometryType = feature ? feature.getGeometry().getType() : "cesium";
157
159
 
158
160
  // For simple geometries the first styling rule is used.
159
161
  // That algorithm implements an OR statement between multiple valid conditions giving precedence to its order in the style.json.
@@ -7,7 +7,7 @@ import {checkProperties} from "../lib/valueOperations";
7
7
  */
8
8
  export function getRulesForFeature (styleObject, feature) {
9
9
  styleObject.rules.forEach(rule => {
10
- if (typeof feature.get("rotation") !== "undefined") {
10
+ if (typeof feature?.get("rotation") !== "undefined") {
11
11
  rule.style.rotation = feature.get("rotation");
12
12
  }
13
13
  });
@@ -140,7 +140,7 @@ export function checkProperty (featureProperties, key, value) {
140
140
  * @returns {Boolean} true if all properties are satisfied
141
141
  */
142
142
  export function checkProperties (feature, rule) {
143
- if (rule?.conditions?.properties) {
143
+ if (rule?.conditions?.properties && feature) {
144
144
  const featureProperties = feature.getProperties(),
145
145
  properties = rule.conditions.properties;
146
146
  let key,
@@ -30,7 +30,7 @@ class CesiumStyle extends StyleClass {
30
30
  * @returns {ol/style} - The created style.
31
31
  */
32
32
  createStyle () {
33
- return this.createCondition(this.get("conditions"), this.get("style"));
33
+ return this.createCondition(this.attributes.conditions, this.style);
34
34
  }
35
35
 
36
36
  /**
@@ -40,7 +40,7 @@ class CesiumStyle extends StyleClass {
40
40
  * @returns {*} - Condition for cesium 3d tile style.
41
41
  */
42
42
  createCondition (conditions, style) {
43
- const {color} = style,
43
+ const color = style?.color || this.attributes.color,
44
44
  condition = [];
45
45
  let ruleCondition;
46
46
 
@@ -1,6 +1,7 @@
1
1
  import createStyle from "../../src/vectorStyle/createStyle";
2
2
  import PointStyle from "../../src/vectorStyle/styles/point/stylePoint";
3
3
  import LineStringStyle from "../../src/vectorStyle/styles/styleLine";
4
+ import CesiumStyle from "../../src/vectorStyle/styles/styleCesium";
4
5
  import PolygonStyle from "../../src/vectorStyle/styles/polygon/stylePolygon";
5
6
  import {Style, Stroke, Fill} from "ol/style.js";
6
7
  import {GeoJSON} from "ol/format.js";
@@ -9,6 +10,7 @@ let rules,
9
10
  jsonObjects,
10
11
  multiLineStringRules,
11
12
  multiPolygonRules,
13
+ cesiumRules,
12
14
  isClustered;
13
15
 
14
16
  const wfsImgPathFromConfig = "/path/to/wfs/images",
@@ -238,6 +240,12 @@ beforeEach(() => {
238
240
  polygonStrokeColor: [255, 0, 0, 1]
239
241
  }
240
242
  }];
243
+ cesiumRules = [{
244
+ style: {
245
+ type: "cesium",
246
+ color: "rgba(50, 154, 26, 0.8)"
247
+ }
248
+ }];
241
249
  });
242
250
 
243
251
  describe("createStyle", () => {
@@ -442,6 +450,13 @@ describe("getSimpleGeometryStyle", function () {
442
450
  isClustered = true;
443
451
  expect(createStyle.getSimpleGeometryStyle("not exist", jsonObjects[0], null, isClustered, wfsImgPathFromConfig)).toBeInstanceOf(Style);
444
452
  });
453
+ it("should create Cesium style", function () {
454
+ isClustered = true;
455
+ const tilesetStyle = createStyle.getSimpleGeometryStyle("cesium", undefined, cesiumRules[0], false, wfsImgPathFromConfig);
456
+
457
+ expect(tilesetStyle).toBeInstanceOf(CesiumStyle);
458
+ expect(tilesetStyle.attributes.color).toEqual(cesiumRules[0].style.color);
459
+ });
445
460
  });
446
461
 
447
462
  describe("getMultiGeometryStyle", function () {
@@ -128,5 +128,9 @@ describe("getRuleForIndex", function () {
128
128
  expect(Array.isArray(getRulesForFeature(styleObject, jsonObjects[1]))).toBe(true);
129
129
  expect(getRulesForFeature(styleObject, jsonObjects[1]).length).toEqual(1);
130
130
  });
131
+ it("should not fail if feature is undefined - is the case for type=Cesium", function () {
132
+ expect(Array.isArray(getRulesForFeature(styleObject, undefined))).toBe(true);
133
+ expect(getRulesForFeature(styleObject, jsonObjects[1]).length).toEqual(1);
134
+ });
131
135
  });
132
136
  });
@@ -185,7 +185,7 @@ describe("checkProperties", function () {
185
185
  it("should return true for rule that has no properties", function () {
186
186
  expect(checkProperties(jsonObjects[0], rules[2])).toBe(true);
187
187
  });
188
- it("should return false for rule that has not fitting properties", function () {
189
- expect(checkProperties(jsonObjects[1], rules[1])).toBe(false);
188
+ it("should do nothing if feature is undefined", function () {
189
+ expect(checkProperties(undefined, rules[1])).toBe(true);
190
190
  });
191
191
  });
@@ -0,0 +1,120 @@
1
+ import CesiumStyle from "../../../src/vectorStyle/styles/styleCesium";
2
+ import StyleClass from "../../../src/vectorStyle/styles/style";
3
+
4
+ describe("styleCesium", () => {
5
+ const expectedStyle = ["((${attributes.Dachform} === 'Flachdach'))", "rgba(50, 154, 26, 0.8)"];
6
+ let rule,
7
+ styleCesiumClass;
8
+
9
+ beforeEach(() => {
10
+ rule = {
11
+ conditions: {
12
+ "attributes.Dachform": "Flachdach"
13
+ },
14
+ style: {
15
+ type: "cesium",
16
+ color: "rgba(50, 154, 26, 0.8)"
17
+ }
18
+ };
19
+
20
+ });
21
+
22
+ describe("initialize", function () {
23
+ it("shall call 3 functions for initialization", () => {
24
+ const setConditionsSpy = jest.spyOn(CesiumStyle.prototype, "setConditions"),
25
+ overwriteStylingSpy = jest.spyOn(StyleClass.prototype, "overwriteStyling"),
26
+ setStyleSpy = jest.spyOn(StyleClass.prototype, "setStyle");
27
+
28
+ styleCesiumClass = new CesiumStyle();
29
+ styleCesiumClass.initialize(rule);
30
+ expect(setConditionsSpy).toHaveBeenCalledTimes(1);
31
+ expect(overwriteStylingSpy).toHaveBeenCalledTimes(1);
32
+ expect(setStyleSpy).toHaveBeenCalledTimes(1);
33
+ });
34
+ });
35
+
36
+
37
+ describe("createStyle", function () {
38
+ it("shall call createCondition and create expected style", () => {
39
+ const createConditionSpy = jest.spyOn(CesiumStyle.prototype, "createCondition"),
40
+ createdStyle = styleCesiumClass.createStyle();
41
+
42
+ styleCesiumClass = new CesiumStyle();
43
+ expect(createConditionSpy).toHaveBeenCalledTimes(1);
44
+ expect(createConditionSpy).toHaveBeenCalledWith(rule.conditions, expectedStyle);
45
+ expect(createdStyle).toEqual(expectedStyle);
46
+ });
47
+ });
48
+
49
+ describe("createCondition", function () {
50
+ it("createCondition with conditions and no style", () => {
51
+ let condition = null;
52
+
53
+ styleCesiumClass = new CesiumStyle();
54
+ styleCesiumClass.initialize(rule);
55
+ condition = styleCesiumClass.createCondition(rule.conditions);
56
+
57
+ expect(condition).toEqual(expectedStyle);
58
+ });
59
+
60
+ it("createCondition with no conditions and no style", () => {
61
+ let condition = null;
62
+
63
+ styleCesiumClass = new CesiumStyle();
64
+ delete rule.conditions;
65
+ styleCesiumClass.initialize(rule);
66
+ condition = styleCesiumClass.createCondition(undefined);
67
+
68
+ expect(condition).toEqual(["true", "rgba(50, 154, 26, 0.8)"]);
69
+ });
70
+
71
+
72
+ it("createCondition no conditions but with style", () => {
73
+ let condition = null;
74
+ const style = {
75
+ color: "rgba(150, 154, 26, 0.8)"
76
+ };
77
+
78
+ styleCesiumClass = new CesiumStyle();
79
+ delete rule.conditions;
80
+ styleCesiumClass.initialize(rule);
81
+ condition = styleCesiumClass.createCondition(undefined, style);
82
+
83
+ expect(condition).toEqual(["true", "rgba(150, 154, 26, 0.8)"]);
84
+ });
85
+ });
86
+
87
+ describe("createCesiumConditionForRule", function () {
88
+ it("createCesiumConditionForRule with an equals condition", () => {
89
+ let condition = null;
90
+
91
+ styleCesiumClass = new CesiumStyle();
92
+ styleCesiumClass.initialize(rule);
93
+ condition = styleCesiumClass.createCesiumConditionForRule([["attributes.Dachform", "Flachdach"]]);
94
+
95
+ expect(condition).toEqual("((${attributes.Dachform} === 'Flachdach'))");
96
+ });
97
+
98
+ it("createCesiumConditionForRule with 2 equals conditions", () => {
99
+ let condition = null;
100
+
101
+ styleCesiumClass = new CesiumStyle();
102
+ styleCesiumClass.initialize(rule);
103
+ condition = styleCesiumClass.createCesiumConditionForRule([["attributes.Dachform", "Flachdach"], ["foo", "bar"]]);
104
+
105
+ expect(condition).toEqual("((${attributes.Dachform} === 'Flachdach') && (${foo} === 'bar'))");
106
+ });
107
+
108
+ it("createCesiumConditionForRule with a >, <= condition", () => {
109
+ let condition = null;
110
+
111
+ styleCesiumClass = new CesiumStyle();
112
+ styleCesiumClass.initialize(rule);
113
+ condition = styleCesiumClass.createCesiumConditionForRule([["attributes.height", [10, 20]]]);
114
+
115
+ expect(condition).toEqual("((${attributes.height} > 10 && ${attributes.height} <= 20))");
116
+ });
117
+
118
+
119
+ });
120
+ });