@masterportal/masterportalapi 2.23.0 → 2.25.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.
@@ -1,13 +1,24 @@
1
1
  import VectorSource from "ol/source/Vector.js";
2
+ import VectorTileSource from "ol/source/VectorTile";
3
+ import VectorTile from "ol/layer/VectorTile.js";
2
4
  import Feature from "ol/Feature";
3
5
  import Polygon from "ol/geom/Polygon";
6
+ import MultiPoint from "ol/geom/MultiPoint";
4
7
  import * as webgl from "../../src/renderer/webgl";
5
8
  import WebGLPointsLayer from "ol/layer/WebGLPoints";
6
9
  import Layer from "ol/layer/Layer";
7
- import styleList from "../../src/vectorStyle/styleList";
10
+ import {returnColor} from "../../src/vectorStyle/lib/colorConvertions";
11
+
12
+ jest.mock("../../src/vectorStyle/styleList.js", () => {
13
+ const
14
+ original = jest.requireActual("../../src/vectorStyle/styleList.js");
15
+
16
+ original.returnStyleObject = jest.fn(() => "xyz");
17
+ return original;
18
+ });
8
19
 
9
20
  describe("webgl.js", () => {
10
- let layerParams, rawLayer, styleRule, styleObject;
21
+ let layerParams, layerParamsVectorTile, rawLayer, rawLayerVectorTile, styleRule, styleObject;
11
22
 
12
23
  beforeEach(() => {
13
24
  layerParams = {
@@ -27,6 +38,26 @@ describe("webgl.js", () => {
27
38
  featureType: "krankenhaeuser_hh",
28
39
  outputFormat: "XML"
29
40
  };
41
+ rawLayerVectorTile = {
42
+ id: "4000",
43
+ name: "XPLAN",
44
+ url: "https://xplanung.ldproxy.devops.diplanung.de/rest/services/xplansyn/tiles/WebMercatorQuad/{z}/{y}/{x}?f=mvt",
45
+ typ: "VectorTile",
46
+ epsg: "EPSG:3857",
47
+ tileSize: 512,
48
+ extent: [
49
+ 902186.674876469653,
50
+ 7054472.60470921732,
51
+ 1161598.35425907862,
52
+ 7175683.41171819717
53
+ ]
54
+ };
55
+ layerParamsVectorTile = {
56
+ id: "4000",
57
+ renderer: "webgl",
58
+ styleId: "4000",
59
+ visibility: true
60
+ };
30
61
  styleRule = {style: {
31
62
  polygonFillColor: [255, 0, 0, 0.5],
32
63
  polygonStrokeColor: [0, 255, 0, 0.5],
@@ -37,16 +68,10 @@ describe("webgl.js", () => {
37
68
  styleObject = {
38
69
  rules: [styleRule]
39
70
  };
40
-
41
- jest.spyOn(styleList, "returnStyleObject").mockImplementation(() => styleObject);
42
- });
43
-
44
- afterEach(() => {
45
- jest.restoreAllMocks();
46
71
  });
47
72
 
48
73
  describe("createLayer", () => {
49
- const source = new VectorSource();
74
+ let source = new VectorSource();
50
75
 
51
76
  it("should return a WebGLPointsLayer", () => {
52
77
  layerParams.isPointLayer = true;
@@ -63,6 +88,28 @@ describe("webgl.js", () => {
63
88
  expect(webglLayer).not.toBeInstanceOf(WebGLPointsLayer);
64
89
  expect(webglLayer.get("isPointLayer")).toBeFalsy();
65
90
  });
91
+ it("vectorTile: should return a VectorTile layer", () => {
92
+ source = new VectorTileSource({...rawLayerVectorTile, ...layerParamsVectorTile});
93
+ layerParams.isPointLayer = false;
94
+ const webglLayer = webgl.createLayer({...rawLayerVectorTile, ...layerParamsVectorTile, source});
95
+
96
+ expect(webglLayer).toBeInstanceOf(Layer);
97
+ expect(webglLayer).toBeInstanceOf(VectorTile);
98
+ expect(webglLayer).not.toBeInstanceOf(WebGLPointsLayer);
99
+ expect(webglLayer.get("isPointLayer")).toBeFalsy();
100
+ });
101
+ });
102
+ describe("afterLoading", () => {
103
+ const feature = new Feature({
104
+ geometry: new MultiPoint([
105
+ [[0, 0, 0], [1, 0, 0], [1, 1, 0]]
106
+ ], "XYZ")
107
+ });
108
+
109
+ it("should extract single points from MultiPoint geometries, if isPointLayer", () => {
110
+ webgl.afterLoading([feature], layerParams.styleId, null, true);
111
+ expect(feature.getGeometry().getType()).toEqual("Point");
112
+ });
66
113
  });
67
114
  describe("private format and style functions", () => {
68
115
  const
@@ -106,6 +153,26 @@ describe("webgl.js", () => {
106
153
  webgl.formatFeatureStyles($feature, styleObject);
107
154
  expect($feature.styleRule).toEqual(styleRule);
108
155
  });
156
+ it("set the necessary style attributes on the feature for literal style syntax", () => {
157
+ $feature = feature.clone();
158
+ webgl.formatFeatureStyles($feature, styleObject);
159
+ expect($feature.get("fillColor")).toEqual(returnColor(styleRule.style.polygonFillColor, "hex"));
160
+ expect($feature.get("strokeColor")).toEqual(returnColor(styleRule.style.polygonStrokeColor, "hex"));
161
+ expect($feature.get("strokeWidth")).toEqual(styleRule.style.polygonStrokeWidth);
162
+ expect($feature.get("opacity")).toEqual(styleRule.style.polygonFillColor[3]);
163
+ expect($feature.get("circleSize")).toEqual(styleRule.style.circleRadius);
164
+ });
165
+ it("circle: bind the styling rule from the styleObject to each feature", () => {
166
+ styleRule.style.polygonFillColor = undefined;
167
+ styleRule.style.polygonStrokeColor = undefined;
168
+ styleRule.style.polygonStrokeWidth = undefined;
169
+ $feature = feature.clone();
170
+ webgl.formatFeatureStyles($feature, styleObject);
171
+ expect($feature.styleRule).toEqual(styleRule);
172
+ expect($feature.get("fillColor")).toEqual(returnColor(styleRule.style.circleFillColor, "hex"));
173
+ expect($feature.get("opacity")).toEqual(styleRule.style.circleFillColor[3]);
174
+ expect($feature.get("circleSize")).toEqual(styleRule.style.circleRadius);
175
+ });
109
176
  });
110
177
  });
111
178
  });
@@ -1,83 +0,0 @@
1
- import Feature from "ol/Feature";
2
- import Point from "ol/geom/Point";
3
- import Polygon from "ol/geom/Polygon";
4
- import VectorLayer from "ol/layer/Vector";
5
- import VectorSource from "ol/source/Vector.js";
6
- import * as vectorBase from "../../src/layer/vectorBase";
7
- import * as webgl from "../../src/renderer/webgl.js";
8
-
9
- jest.mock("../../src/renderer/webgl.js", () => {
10
- const original = jest.requireActual("../../src/renderer/webgl.js");
11
-
12
- original.afterLoading = jest.fn();
13
- return original;
14
- });
15
-
16
- describe("vectorBase.js", function () {
17
-
18
- describe("createLayerSource", function () {
19
- it("creates a layerSource with features", function () {
20
- const attr = {
21
- features: [
22
- new Feature({geometry: new Polygon([[[565086.1948534324, 5934664.461947621], [565657.6945448224, 5934738.54524095], [565625.9445619675, 5934357.545446689], [565234.3614400891, 5934346.962119071], [565086.1948534324, 5934664.461947621]]])}),
23
- new Feature({geometry: new Point([565826.38, 5934174.40])})
24
- ]
25
- },
26
- source = vectorBase.createLayerSource(attr);
27
-
28
- expect(source).toBeInstanceOf(VectorSource);
29
- });
30
-
31
- it("creates a layerSource without features", function () {
32
- const source = vectorBase.createLayerSource({});
33
-
34
- expect(source).toBeInstanceOf(VectorSource);
35
- });
36
- it("creates a vectorSource with an additional listener, when renderer is \"webgl\"", () => {
37
- vectorBase.createLayerSource({renderer: "webgl"});
38
-
39
- expect(webgl.afterLoading).toHaveBeenCalled();
40
- });
41
- });
42
-
43
- describe("createLayer", function () {
44
- const attr = {
45
- name: "Albus Percival Wulfric Brian Dumbledore",
46
- typ: "VectorBase",
47
- gfiAttributes: "ignore",
48
- id: "Rawenclaw_01"
49
- };
50
-
51
- it("creates a vector Base Layer", function () {
52
- const layer = vectorBase.createLayer(attr);
53
-
54
- expect(layer).toBeInstanceOf(VectorLayer);
55
- expect(layer.get("name")).toEqual("Albus Percival Wulfric Brian Dumbledore");
56
- expect(layer.get("typ")).toEqual("VectorBase");
57
- expect(layer.get("id")).toEqual("Rawenclaw_01");
58
- });
59
- it("creates a WebGLLayer, with param renderer \"webgl\"", function () {
60
- const layer = vectorBase.createLayer({...attr, renderer: "webgl"});
61
-
62
- expect(layer.constructor.name).toEqual("LocalWebGLLayer");
63
- expect(layer.getSource()).toBeInstanceOf(VectorSource);
64
- });
65
- });
66
-
67
- describe("updateSource", function () {
68
- it("updateSource will fetch layer again", function () {
69
- const layer = vectorBase.createLayer({id: "id"}),
70
- layerGetSourceMock = jest.fn(() => {
71
- return {
72
- clear: () => this,
73
- addFeatures: () => this
74
- };
75
- });
76
-
77
- layer.getSource = layerGetSourceMock;
78
- vectorBase.updateSource(layer);
79
- expect(layerGetSourceMock.mock.calls.length).toBe(2);
80
- });
81
- });
82
-
83
- });