@masterportal/masterportalapi 2.19.2 → 2.21.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.
@@ -0,0 +1,123 @@
1
+ import {Draw} from "ol/interaction.js";
2
+ import Feature from "ol/Feature";
3
+ import Circle from "ol/geom/Circle";
4
+ import VectorSource from "ol/source/Vector";
5
+
6
+ import drawInteractions, {styleObject} from "../../../src/maps/interactions/drawInteractions";
7
+
8
+ describe("src/maps/interactions/drawInteractions.js", () => {
9
+ describe("transformMapUnitRadius", () => {
10
+ it("should return the input meter radius in meter ", () => {
11
+ const radius = 100,
12
+ mapProjection = {
13
+ getUnits: () => "m"
14
+ },
15
+ mapUnitRadius = drawInteractions.transformMapUnitRadius(radius, mapProjection);
16
+
17
+ expect(mapUnitRadius).toEqual(100);
18
+ });
19
+
20
+ it("should return the input degree radius in meter ", () => {
21
+ const radius = 100,
22
+ mapProjection = {
23
+ getUnits: () => "degrees"
24
+ },
25
+ mapUnitRadius = drawInteractions.transformMapUnitRadius(radius, mapProjection);
26
+
27
+ expect(mapUnitRadius).toEqual(0.0008983152841195215);
28
+ });
29
+ });
30
+
31
+ describe("drawInnerCircle", () => {
32
+ it("should set radius for circle feature", () => {
33
+ const feature = new Feature({geometry: new Circle([565826.38, 5934174.40], 10)}),
34
+ mapProjection = {
35
+ getUnits: () => "m"
36
+ },
37
+ options = {
38
+ innerRadius: 100,
39
+ interactive: false,
40
+ outerRadius: 500
41
+ };
42
+
43
+ drawInteractions.drawInnerCircle(feature, mapProjection, options);
44
+
45
+ expect(feature.getGeometry().getRadius()).toEqual(100);
46
+ });
47
+ });
48
+
49
+ describe("setStyleObject", () => {
50
+ it("should set style object", () => {
51
+ const currentLayout = {
52
+ fillColor: [55, 126, 184],
53
+ fillTransparency: 0,
54
+ strokeColor: [0, 0, 0],
55
+ strokeWidth: 1
56
+ };
57
+
58
+ drawInteractions.setStyleObject(currentLayout);
59
+
60
+ expect(styleObject).toEqual({
61
+ rules: [
62
+ {
63
+ style: {
64
+ circleFillColor: [
65
+ 55,
66
+ 126,
67
+ 184,
68
+ 1
69
+ ],
70
+ circleStrokeColor: [
71
+ 0,
72
+ 0,
73
+ 0
74
+ ],
75
+ circleStrokeWidth: 1,
76
+ lineStrokeColor: [
77
+ 0,
78
+ 0,
79
+ 0
80
+ ],
81
+ lineStrokeWidth: 1,
82
+ polygonFillColor: [
83
+ 55,
84
+ 126,
85
+ 184,
86
+ 1
87
+ ],
88
+ polygonStrokeColor: [
89
+ 0,
90
+ 0,
91
+ 0
92
+ ],
93
+ polygonStrokeWidth: 1
94
+ }
95
+ }
96
+ ]
97
+ });
98
+ });
99
+ });
100
+
101
+ describe("createDrawInteraction", () => {
102
+ it("should create a draw interaction", () => {
103
+ const source = new VectorSource(),
104
+ drawType = "pen",
105
+ drawInteraction = drawInteractions.createDrawInteraction(drawType, source);
106
+
107
+ expect(drawInteraction).not.toBeUndefined();
108
+ expect(drawInteraction).not.toBeNull();
109
+ expect(drawInteraction).toBeInstanceOf(Draw);
110
+ });
111
+
112
+ it("should return null, if drawType is not supported", () => {
113
+ const source = new VectorSource(),
114
+ drawType = "abc",
115
+ drawInteraction = drawInteractions.createDrawInteraction(drawType, source);
116
+
117
+ expect(drawInteraction).not.toBeUndefined();
118
+ expect(drawInteraction).toBeNull();
119
+ expect(drawInteraction).not.toBeInstanceOf(Draw);
120
+ });
121
+ });
122
+
123
+ });
@@ -4,7 +4,6 @@ import Polygon from "ol/geom/Polygon";
4
4
  import * as webgl from "../../src/renderer/webgl";
5
5
  import WebGLPointsLayer from "ol/layer/WebGLPoints";
6
6
  import Layer from "ol/layer/Layer";
7
- import {packColor} from "ol/renderer/webgl/shaders";
8
7
  import styleList from "../../src/vectorStyle/styleList";
9
8
 
10
9
  describe("webgl.js", () => {
@@ -108,54 +107,5 @@ describe("webgl.js", () => {
108
107
  expect($feature.styleRule).toEqual(styleRule);
109
108
  });
110
109
  });
111
- describe("getRenderFunctions", () => {
112
- it("should read the style from styleRule and pack them to single float", () => {
113
- const renderFunctions = webgl.getRenderFunctions();
114
-
115
- $feature = feature.clone();
116
- webgl.formatFeatureStyles($feature, styleObject);
117
- expect(renderFunctions.fill.attributes.color($feature)).toEqual(packColor(styleRule.style.polygonFillColor));
118
- expect(renderFunctions.fill.attributes.opacity($feature)).toEqual(styleRule.style.polygonFillColor[3]);
119
- expect(renderFunctions.stroke.attributes.color($feature)).toEqual(packColor(styleRule.style.polygonStrokeColor));
120
- expect(renderFunctions.stroke.attributes.width($feature)).toEqual(styleRule.style.polygonStrokeWidth);
121
- expect(renderFunctions.stroke.attributes.opacity($feature)).toEqual(styleRule.style.polygonStrokeColor[3]);
122
- expect(renderFunctions.point.attributes.color($feature)).toEqual(packColor(styleRule.style.circleFillColor));
123
- expect(renderFunctions.point.attributes.size($feature)).toEqual(styleRule.style.circleRadius);
124
- expect(renderFunctions.point.attributes.opacity($feature)).toEqual(styleRule.style.circleFillColor[3]);
125
- });
126
- it("should return default values if style is empty, i.e. \"default\" style", () => {
127
- const renderFunctions = webgl.getRenderFunctions();
128
-
129
- styleObject = {
130
- rules: [{
131
- style: {}
132
- }]
133
- };
134
- $feature = feature.clone();
135
- webgl.formatFeatureStyles($feature, styleObject);
136
- expect(typeof renderFunctions.fill.attributes.color($feature)).toEqual("number");
137
- expect(typeof renderFunctions.fill.attributes.opacity($feature)).toEqual("number");
138
- expect(typeof renderFunctions.stroke.attributes.color($feature)).toEqual("number");
139
- expect(typeof renderFunctions.stroke.attributes.width($feature)).toEqual("number");
140
- expect(typeof renderFunctions.stroke.attributes.opacity($feature)).toEqual("number");
141
- expect(typeof renderFunctions.point.attributes.color($feature)).toEqual("number");
142
- expect(typeof renderFunctions.point.attributes.size($feature)).toEqual("number");
143
- expect(typeof renderFunctions.point.attributes.opacity($feature)).toEqual("number");
144
- });
145
- it("should return default values if no style rule is found", () => {
146
- const renderFunctions = webgl.getRenderFunctions();
147
-
148
- $feature = feature.clone();
149
- expect(feature.styleRule).toBeUndefined();
150
- expect(typeof renderFunctions.fill.attributes.color($feature)).toEqual("number");
151
- expect(typeof renderFunctions.fill.attributes.opacity($feature)).toEqual("number");
152
- expect(typeof renderFunctions.stroke.attributes.color($feature)).toEqual("number");
153
- expect(typeof renderFunctions.stroke.attributes.width($feature)).toEqual("number");
154
- expect(typeof renderFunctions.stroke.attributes.opacity($feature)).toEqual("number");
155
- expect(typeof renderFunctions.point.attributes.color($feature)).toEqual("number");
156
- expect(typeof renderFunctions.point.attributes.size($feature)).toEqual("number");
157
- expect(typeof renderFunctions.point.attributes.opacity($feature)).toEqual("number");
158
- });
159
- });
160
110
  });
161
111
  });
@@ -27,8 +27,11 @@ describe("stylePoint", () => {
27
27
  expect(typeof stylePointClass.setSize).toBe("function");
28
28
  });
29
29
  });
30
- describe("getStyle", function () {
30
+ describe("createStyle", function () {
31
31
  it("returns an instance of openlayers style", () => {
32
+ const createdStyle = stylePointClass.createStyle();
33
+
34
+ stylePointClass.setStyle(createdStyle);
32
35
  expect(stylePointClass.getStyle()).toBeInstanceOf(Style);
33
36
  });
34
37
  it("returns an instance of openlayers circleStyle", () => {
@@ -39,6 +42,9 @@ describe("stylePoint", () => {
39
42
  legendValue: "Krankenhaus",
40
43
  imageName: "krankenhaus.png"
41
44
  };
45
+ const createdStyle = stylePointClass.createStyle();
46
+
47
+ stylePointClass.setStyle(createdStyle);
42
48
 
43
49
  expect(stylePointClass.getStyle()).toBeInstanceOf(Style);
44
50
  expect(stylePointClass.getStyle().getImage()).toBeInstanceOf(CircleStyle);
@@ -15,8 +15,11 @@ describe("stylePolygon", () => {
15
15
  isClustered = false,
16
16
  stylePolygonClass = new PolygonStyle(feature, style, isClustered);
17
17
 
18
- describe("getStyle", function () {
18
+ describe("createStyle", function () {
19
19
  it("returns an instance of openlayers style", () => {
20
+ const createdStyle = stylePolygonClass.createStyle();
21
+
22
+ stylePolygonClass.setStyle(createdStyle);
20
23
  expect(stylePolygonClass.getStyle()).toBeInstanceOf(Style);
21
24
  });
22
25
  });
@@ -0,0 +1,31 @@
1
+ import CircleStyle from "../../../src/vectorStyle/styles/styleCircle";
2
+ import {Style} from "ol/style.js";
3
+
4
+ describe("styleCircle", () => {
5
+ const feature = {
6
+ geometryName: "geom",
7
+ id: "DE.HH.UP_GESUNDHEIT_KRANKENHAEUSER_2"
8
+ },
9
+ style = {
10
+ type: "icon",
11
+ legendValue: "Krankenhaus",
12
+ imageName: "krankenhaus.png"
13
+ },
14
+ isClustered = false,
15
+ styleCircleClass = new CircleStyle(feature, style, isClustered);
16
+
17
+ describe("initialize", function () {
18
+ it("returns an instance of openlayers style", () => {
19
+ expect(typeof styleCircleClass.initialize).toBe("function");
20
+ });
21
+ });
22
+
23
+ describe("createStyle", function () {
24
+ it("returns an instance of openlayers style", () => {
25
+ const createdStyle = styleCircleClass.createStyle();
26
+
27
+ styleCircleClass.setStyle(createdStyle);
28
+ expect(styleCircleClass.getStyle()).toBeInstanceOf(Style);
29
+ });
30
+ });
31
+ });
@@ -21,8 +21,11 @@ describe("styleLine", () => {
21
21
  });
22
22
  });
23
23
 
24
- describe("getStyle", function () {
24
+ describe("createStyle", function () {
25
25
  it("returns an instance of openlayers style", () => {
26
+ const createdStyle = styleLineClass.createStyle();
27
+
28
+ styleLineClass.setStyle(createdStyle);
26
29
  expect(styleLineClass.getStyle()).toBeInstanceOf(Style);
27
30
  });
28
31
  });