@masterportal/masterportalapi 2.13.0 → 2.14.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/.eslintrc +2 -1
- package/CHANGELOG.md +10 -7
- package/example/config/portal.json +8 -1
- package/example/config/services.json +10 -0
- package/example/index.js +34 -2
- package/jest.config.js +1 -1
- package/jest.setup.js +9 -1
- package/package.json +4 -3
- package/src/lib/attributeMapper.js +231 -0
- package/src/lib/getValueFromObjectByPath.js +73 -0
- package/src/lib/thousandsSeparator.js +23 -0
- package/src/vectorStyle/createStyle.js +259 -0
- package/src/vectorStyle/lib/colorConvertions.js +97 -0
- package/src/vectorStyle/lib/createLegendInfo.js +28 -0
- package/src/vectorStyle/lib/getGeometryTypeFromService.js +153 -0
- package/src/vectorStyle/lib/getRuleForIndex.js +62 -0
- package/src/vectorStyle/lib/valueOperations.js +172 -0
- package/src/vectorStyle/styleList.js +281 -0
- package/src/vectorStyle/styles/defaultStyles.js +177 -0
- package/src/vectorStyle/styles/point/stylePoint.js +108 -0
- package/src/vectorStyle/styles/point/stylePointCircle.js +29 -0
- package/src/vectorStyle/styles/point/stylePointIcon.js +79 -0
- package/src/vectorStyle/styles/point/stylePointInterval.js +124 -0
- package/src/vectorStyle/styles/point/stylePointNominal.js +232 -0
- package/src/vectorStyle/styles/point/stylePointRegularShape.js +39 -0
- package/src/vectorStyle/styles/polygon/polygonStyleHatch.js +160 -0
- package/src/vectorStyle/styles/polygon/stylePolygon.js +125 -0
- package/src/vectorStyle/styles/style.js +161 -0
- package/src/vectorStyle/styles/styleCesium.js +106 -0
- package/src/vectorStyle/styles/styleLine.js +51 -0
- package/src/vectorStyle/styles/styleText.js +143 -0
- package/test/lib/attributeMapper.test.js +290 -0
- package/test/lib/getValueFromObjectByPath.test.js +61 -0
- package/test/lib/thousandsSeparator.test.js +58 -0
- package/test/vectorStyle/createStyle.test.js +335 -0
- package/test/vectorStyle/lib/colorConvertions.test.js +42 -0
- package/test/vectorStyle/lib/getRuleForIndex.test.js +132 -0
- package/test/vectorStyle/lib/valueOperations.test.js +191 -0
- package/test/vectorStyle/styles/point/stylePoint.test.js +28 -0
- package/test/vectorStyle/styles/point/stylePointCircle.test.js +30 -0
- package/test/vectorStyle/styles/point/stylePointIcon.test.js +83 -0
- package/test/vectorStyle/styles/point/stylePointInterval.test.js +57 -0
- package/test/vectorStyle/styles/point/stylePointNominal.test.js +84 -0
- package/test/vectorStyle/styles/point/stylePointRegularShape.test.js +24 -0
- package/test/vectorStyle/styles/polygon/polygonStyleHatch.test.js +95 -0
- package/test/vectorStyle/styles/polygon/stylePolygon.test.js +61 -0
- package/test/vectorStyle/styles/styleLine.test.js +29 -0
- package/test/vectorStyle/styles/styleText.test.js +49 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import {getValueWithoutComma, getReferenceValue, compareValues, checkProperty, checkProperties} from "../../../src/vectorStyle/lib/valueOperations";
|
|
2
|
+
import {GeoJSON} from "ol/format.js";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const geojsonReader = new GeoJSON(),
|
|
6
|
+
jsonFeatures = {
|
|
7
|
+
"type": "FeatureCollection",
|
|
8
|
+
"features": [
|
|
9
|
+
{
|
|
10
|
+
"type": "Feature",
|
|
11
|
+
"geometry": {
|
|
12
|
+
"type": "Point",
|
|
13
|
+
"coordinates": [10.082125662581083, 53.518872973925404]
|
|
14
|
+
},
|
|
15
|
+
"properties": {
|
|
16
|
+
"id": "test1",
|
|
17
|
+
"name": "myName",
|
|
18
|
+
"value": 50,
|
|
19
|
+
"min": 10,
|
|
20
|
+
"max": 100,
|
|
21
|
+
"myObj": {
|
|
22
|
+
"myCascade": 10,
|
|
23
|
+
"myArray": [
|
|
24
|
+
{
|
|
25
|
+
"myValue": 20
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "Feature",
|
|
33
|
+
"geometry": {
|
|
34
|
+
"type": "LineString",
|
|
35
|
+
"coordinates": [[10.082125662581083, 53.518872973925404], [11.01, 53.6]]
|
|
36
|
+
},
|
|
37
|
+
"properties": {
|
|
38
|
+
"id": "test2",
|
|
39
|
+
"value": 50,
|
|
40
|
+
"min": 10,
|
|
41
|
+
"max": 100
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
rules = [
|
|
47
|
+
{
|
|
48
|
+
"conditions": {
|
|
49
|
+
"properties": {
|
|
50
|
+
"id": "test1"
|
|
51
|
+
},
|
|
52
|
+
"sequence": [1, 1]
|
|
53
|
+
},
|
|
54
|
+
"style": {
|
|
55
|
+
"polygonStrokeColor": [100, 0, 0, 1],
|
|
56
|
+
"labelField": "name"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"conditions": {
|
|
61
|
+
"properties": {
|
|
62
|
+
"id": "test1"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"style": {
|
|
66
|
+
"polygonStrokeColor": [100, 100, 0, 1]
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"style": {
|
|
71
|
+
"polygonStrokeColor": [100, 100, 100, 1]
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
let jsonObjects;
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
beforeAll(function () {
|
|
80
|
+
jsonObjects = geojsonReader.readFeatures(jsonFeatures);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
describe("getValueWithoutComma", function () {
|
|
85
|
+
it("should return original value", function () {
|
|
86
|
+
expect(getValueWithoutComma("22")).toEqual("22");
|
|
87
|
+
expect(getValueWithoutComma("test")).toEqual("test");
|
|
88
|
+
});
|
|
89
|
+
it("should return the value without comma", function () {
|
|
90
|
+
expect(getValueWithoutComma("22,6")).toEqual(22.6);
|
|
91
|
+
expect(getValueWithoutComma("22,667")).toEqual(22.667);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("getReferenceValue", function () {
|
|
96
|
+
it("should return plain reference value", function () {
|
|
97
|
+
expect(getReferenceValue(jsonObjects[0].getProperties(), "test1")).toEqual("test1");
|
|
98
|
+
});
|
|
99
|
+
it("should return reference value in object path", function () {
|
|
100
|
+
expect(getReferenceValue(jsonObjects[0].getProperties(), "@id")).toEqual("test1");
|
|
101
|
+
});
|
|
102
|
+
it("should return array of reference values", function () {
|
|
103
|
+
expect(Array.isArray(getReferenceValue(jsonObjects[0].getProperties(), [0, 50]))).toBe(true);
|
|
104
|
+
expect(getReferenceValue(jsonObjects[0].getProperties(), [0, 50])).toEqual([0, 50]);
|
|
105
|
+
});
|
|
106
|
+
it("should return array of reference values in object path", function () {
|
|
107
|
+
expect(Array.isArray(getReferenceValue(jsonObjects[0].getProperties(), ["@min", "@max"]))).toBe(true);
|
|
108
|
+
expect(getReferenceValue(jsonObjects[0].getProperties(), ["@min", "@max"])).toEqual([10, 100]);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe("compareValues", function () {
|
|
113
|
+
it("should return true if values are the same", function () {
|
|
114
|
+
expect(compareValues("test", "test")).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
it("should return true if boolean values are same", function () {
|
|
117
|
+
expect(compareValues(true, true)).toBe(true);
|
|
118
|
+
});
|
|
119
|
+
it("should return false if boolean values are different", function () {
|
|
120
|
+
expect(compareValues(true, false)).toBe(false);
|
|
121
|
+
});
|
|
122
|
+
it("should return true if values are the same but of different type", function () {
|
|
123
|
+
expect(compareValues("20", 20)).toBe(true);
|
|
124
|
+
expect(compareValues("20.0", 20)).toBe(true);
|
|
125
|
+
});
|
|
126
|
+
it("should return false if values cannot be parsed to same type", function () {
|
|
127
|
+
expect(compareValues("abc", 20)).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
it("should return false if reference value is an invalid array", function () {
|
|
130
|
+
expect(compareValues(1, [0])).toBe(false);
|
|
131
|
+
expect(compareValues(1, [0, 1, 2])).toBe(false);
|
|
132
|
+
expect(compareValues(1, [0, 1, 2, 4, 5])).toBe(false);
|
|
133
|
+
expect(compareValues(1, ["0", 1])).toBe(false);
|
|
134
|
+
expect(compareValues(1, ["0", 1, 2, 3])).toBe(false);
|
|
135
|
+
});
|
|
136
|
+
it("should return false if feature value cannot be parsed to float and reference value is an array", function () {
|
|
137
|
+
expect(compareValues("abc", [0, 1, 2, 3])).toBe(false);
|
|
138
|
+
});
|
|
139
|
+
it("should return true if feature value is in range of reference values", function () {
|
|
140
|
+
expect(compareValues(20, [20, 25])).toBe(true);
|
|
141
|
+
expect(compareValues(21, [20, 25])).toBe(true);
|
|
142
|
+
});
|
|
143
|
+
it("should return false if feature value is not in range of reference values", function () {
|
|
144
|
+
expect(compareValues(19, [20, 25])).toBe(false);
|
|
145
|
+
expect(compareValues(25, [20, 25])).toBe(false);
|
|
146
|
+
});
|
|
147
|
+
it("should return true if feature value is in range of reference values defined by range", function () {
|
|
148
|
+
expect(compareValues(15, [0, 50, 10, 100])).toBe(true);
|
|
149
|
+
});
|
|
150
|
+
it("should return false if feature value is not in range of reference values defined by range", function () {
|
|
151
|
+
expect(compareValues(9, [0, 50, 10, 100])).toBe(false);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe("checkProperty", function () {
|
|
156
|
+
it("should return true for fitting property", function () {
|
|
157
|
+
expect(checkProperty(jsonObjects[0].getProperties(), "id", "test1")).toBe(true);
|
|
158
|
+
});
|
|
159
|
+
it("should return false for non-fitting property", function () {
|
|
160
|
+
expect(checkProperty(jsonObjects[0].getProperties(), "id", "invalidId")).toBe(false);
|
|
161
|
+
});
|
|
162
|
+
it("should return false for invalid key / value", function () {
|
|
163
|
+
expect(checkProperty(jsonObjects[0].getProperties(), null, "test1")).toBe(false);
|
|
164
|
+
expect(checkProperty(jsonObjects[0].getProperties(), "id", null)).toBe(false);
|
|
165
|
+
expect(checkProperty(jsonObjects[0].getProperties(), "id", [0])).toBe(false);
|
|
166
|
+
expect(checkProperty(jsonObjects[0].getProperties(), "id", [0, 1, 2])).toBe(false);
|
|
167
|
+
});
|
|
168
|
+
it("should return true for a clustered feature", function () {
|
|
169
|
+
const clusterFeatureProperties = {
|
|
170
|
+
features: [jsonObjects[0]],
|
|
171
|
+
geometry: jsonObjects[0].getGeometry()
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
expect(checkProperty(clusterFeatureProperties, "id", "test1")).toBe(true);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe("checkProperties", function () {
|
|
179
|
+
it("should return true for rule that fits all properties even with sequences", function () {
|
|
180
|
+
expect(checkProperties(jsonObjects[0], rules[0])).toBe(true);
|
|
181
|
+
});
|
|
182
|
+
it("should return true for rule that fits all properties without sequences", function () {
|
|
183
|
+
expect(checkProperties(jsonObjects[0], rules[1])).toBe(true);
|
|
184
|
+
});
|
|
185
|
+
it("should return true for rule that has no properties", function () {
|
|
186
|
+
expect(checkProperties(jsonObjects[0], rules[2])).toBe(true);
|
|
187
|
+
});
|
|
188
|
+
it("should return false for rule that has not fitting properties", function () {
|
|
189
|
+
expect(checkProperties(jsonObjects[1], rules[1])).toBe(false);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import PointStyle from "../../../../src/vectorStyle/styles/point/stylePoint";
|
|
2
|
+
import {Style} from "ol/style.js";
|
|
3
|
+
|
|
4
|
+
describe("stylePoint", () => {
|
|
5
|
+
const feature = {
|
|
6
|
+
geometryName: "geom",
|
|
7
|
+
id: "DE.HH.UP_GESUNDHEIT_KRANKENHAEUSER_2"
|
|
8
|
+
},
|
|
9
|
+
style = {
|
|
10
|
+
type: "icon",
|
|
11
|
+
clusterType: "icon",
|
|
12
|
+
legendValue: "Krankenhaus",
|
|
13
|
+
imageName: "krankenhaus.png"
|
|
14
|
+
},
|
|
15
|
+
isClustered = false,
|
|
16
|
+
stylePointClass = new PointStyle(feature, style, isClustered);
|
|
17
|
+
|
|
18
|
+
describe("setSize", function () {
|
|
19
|
+
it("defines setSize()", () => {
|
|
20
|
+
expect(typeof stylePointClass.setSize).toBe("function");
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
describe("getStyle", function () {
|
|
24
|
+
it("returns an instance of openlayers style", () => {
|
|
25
|
+
expect(stylePointClass.getStyle()).toBeInstanceOf(Style);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as stylePointCircle from "../../../../src/vectorStyle/styles/point/stylePointCircle";
|
|
2
|
+
import {Style, Circle} from "ol/style.js";
|
|
3
|
+
|
|
4
|
+
describe("stylePointCircle.js", () => {
|
|
5
|
+
describe("createCircleStyle", () => {
|
|
6
|
+
const attributes = {
|
|
7
|
+
circleRadius: 15,
|
|
8
|
+
circleFillColor: [10, 200, 100, 0.5],
|
|
9
|
+
circleStrokeColor: [10, 200, 100, 0.5],
|
|
10
|
+
circleStrokeWidth: 1
|
|
11
|
+
},
|
|
12
|
+
clusterAttributes = {
|
|
13
|
+
clusterCircleRadius: 20,
|
|
14
|
+
clusterCircleFillColor: [10, 200, 100, 0.5],
|
|
15
|
+
clusterCircleStrokeColor: [10, 200, 100, 0.5],
|
|
16
|
+
clusterCircleStrokeWidth: 1
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
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);
|
|
23
|
+
});
|
|
24
|
+
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);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as stylePointIcon from "../../../../src/vectorStyle/styles/point/stylePointIcon";
|
|
2
|
+
import {Style, Icon} from "ol/style.js";
|
|
3
|
+
|
|
4
|
+
describe("stylePointIcon.js", () => {
|
|
5
|
+
describe("getRotationValue", function () {
|
|
6
|
+
it("should return correct rotation value", function () {
|
|
7
|
+
expect(stylePointIcon.getRotationValue({isDegree: true, value: "90"})).toEqual(1.5707963267948966);
|
|
8
|
+
expect(stylePointIcon.getRotationValue({isDegree: false, value: "10"})).toEqual(10);
|
|
9
|
+
expect(stylePointIcon.getRotationValue()).toEqual(0);
|
|
10
|
+
});
|
|
11
|
+
it("should return correct rotation value from an object path", function () {
|
|
12
|
+
const featureValues = {
|
|
13
|
+
geometryName: "geom",
|
|
14
|
+
id: "DE.HH.UP_GESUNDHEIT_KRANKENHAEUSER_2",
|
|
15
|
+
angle: 45
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
expect(stylePointIcon.getRotationValue({isDegree: false, value: "@angle"}, featureValues)).toEqual(45);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe("createIconStyle", () => {
|
|
22
|
+
const attributes = {
|
|
23
|
+
imagePath: "/imagePath",
|
|
24
|
+
imageName: "bild.svg",
|
|
25
|
+
imageWidth: 10,
|
|
26
|
+
imageHeight: 20,
|
|
27
|
+
imageScale: 1,
|
|
28
|
+
imageOffsetX: 0,
|
|
29
|
+
imageOffsetY: 0,
|
|
30
|
+
imageOffsetXUnit: "px",
|
|
31
|
+
imageOffsetYUnit: "px",
|
|
32
|
+
rotation: 0
|
|
33
|
+
},
|
|
34
|
+
clusterAttributes = {
|
|
35
|
+
clusterImageName: "bild.svg",
|
|
36
|
+
clusterImageWidth: 10,
|
|
37
|
+
clusterImagePath: "/imagePath",
|
|
38
|
+
clusterImageHeight: 20,
|
|
39
|
+
clusterImageScale: 1
|
|
40
|
+
},
|
|
41
|
+
feature = {
|
|
42
|
+
getProperties: () => {
|
|
43
|
+
return {
|
|
44
|
+
name: "singleFeature",
|
|
45
|
+
id: "123"
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
clusteredFeature = {
|
|
50
|
+
get: () => {
|
|
51
|
+
return [
|
|
52
|
+
{
|
|
53
|
+
name: "singleFeature1",
|
|
54
|
+
id: "123"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "singleFeature2",
|
|
58
|
+
id: "456"
|
|
59
|
+
}
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
it("should create icon point style", () => {
|
|
65
|
+
expect(stylePointIcon.createIconStyle(attributes, feature, false)).toBeInstanceOf(Style);
|
|
66
|
+
expect(stylePointIcon.createIconStyle(clusterAttributes, clusteredFeature, true)).toBeInstanceOf(Style);
|
|
67
|
+
expect(stylePointIcon.createIconStyle(attributes, feature, false).getImage()).toBeInstanceOf(Icon);
|
|
68
|
+
expect(stylePointIcon.createIconStyle(attributes, feature, false).getImage().getScale()).toEqual(1);
|
|
69
|
+
});
|
|
70
|
+
it("should create cluster icon point style", () => {
|
|
71
|
+
expect(stylePointIcon.createIconStyle(clusterAttributes, clusteredFeature, true)).toBeInstanceOf(Style);
|
|
72
|
+
expect(stylePointIcon.createIconStyle(clusterAttributes, clusteredFeature, true).getImage()).toBeInstanceOf(Icon);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("createSVGStyle", function () {
|
|
77
|
+
it("should create icon point style", function () {
|
|
78
|
+
expect(stylePointIcon.createSVGStyle("test")).toBeInstanceOf(Style);
|
|
79
|
+
expect(stylePointIcon.createSVGStyle("test").getImage()).toBeInstanceOf(Icon);
|
|
80
|
+
expect(stylePointIcon.createSVGStyle("test").getImage().getSrc()).toEqual("data:image/svg+xml;charset=utf-8,test");
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as stylePointInterval from "../../../../src/vectorStyle/styles/point/stylePointInterval";
|
|
2
|
+
|
|
3
|
+
describe("stylePointInterval.js", () => {
|
|
4
|
+
describe("calculateSizeIntervalCircleBar", function () {
|
|
5
|
+
it("should be 10 at large circleBarRadius and small values input", function () {
|
|
6
|
+
expect(typeof stylePointInterval.calculateSizeIntervalCircleBar(5, 1, 3, 5)).toBe("number");
|
|
7
|
+
expect(stylePointInterval.calculateSizeIntervalCircleBar(5, 1, 3, 5)).toEqual(10);
|
|
8
|
+
});
|
|
9
|
+
it("should be 20 at large circleBarRadius and large values input", function () {
|
|
10
|
+
expect(typeof stylePointInterval.calculateSizeIntervalCircleBar(5, 2, 10, 5)).toBe("number");
|
|
11
|
+
expect(stylePointInterval.calculateSizeIntervalCircleBar(5, 2, 10, 5)).toEqual(30);
|
|
12
|
+
});
|
|
13
|
+
it("should be 10 at large circleBarRadius and stateValue is NaN input", function () {
|
|
14
|
+
expect(typeof stylePointInterval.calculateSizeIntervalCircleBar(NaN, 2, 10, 5)).toBe("number");
|
|
15
|
+
expect(stylePointInterval.calculateSizeIntervalCircleBar(NaN, 2, 10, 5)).toEqual(10);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
describe("calculateLengthIntervalCircleBar", function () {
|
|
19
|
+
it("should be 1 for positive stateValue input", function () {
|
|
20
|
+
expect(typeof stylePointInterval.calculateLengthIntervalCircleBar(10, 1, 3, 1)).toBe("number");
|
|
21
|
+
expect(stylePointInterval.calculateLengthIntervalCircleBar(10, 1, 3, 1)).toEqual(1);
|
|
22
|
+
});
|
|
23
|
+
it("should be 12 fop negative stateValue input", function () {
|
|
24
|
+
expect(typeof stylePointInterval.calculateLengthIntervalCircleBar(10, 2, -1, 5)).toBe("number");
|
|
25
|
+
expect(stylePointInterval.calculateLengthIntervalCircleBar(10, 2, -1, 5)).toEqual(12);
|
|
26
|
+
});
|
|
27
|
+
it("should be 0 for stateValue is NaN input", function () {
|
|
28
|
+
expect(typeof stylePointInterval.calculateLengthIntervalCircleBar(10, 2, NaN, 5)).toBe("number");
|
|
29
|
+
expect(stylePointInterval.calculateLengthIntervalCircleBar(10, 2, NaN, 5)).toEqual(0);
|
|
30
|
+
});
|
|
31
|
+
it("should be 0 for stateValue is undefined input", function () {
|
|
32
|
+
expect(typeof stylePointInterval.calculateLengthIntervalCircleBar(10, 2, undefined, 5)).toBe("number");
|
|
33
|
+
expect(stylePointInterval.calculateLengthIntervalCircleBar(10, 2, undefined, 5)).toEqual(0);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
describe("createIntervalCircleBar", function () {
|
|
37
|
+
const attributes = {
|
|
38
|
+
circleBarScalingFactor: 1,
|
|
39
|
+
circleBarRadius: 10,
|
|
40
|
+
circleBarLineStroke: [10, 200, 100, 0.5],
|
|
41
|
+
circleBarCircleFillColor: [10, 200, 100, 0.5],
|
|
42
|
+
circleBarCircleStrokeColor: [10, 200, 100, 0.5],
|
|
43
|
+
circleBarCircleStrokeWidth: 1,
|
|
44
|
+
circleBarLineStrokeColor: [10, 200, 100, 0.5],
|
|
45
|
+
scalingAttribute: ""
|
|
46
|
+
},
|
|
47
|
+
feature = {
|
|
48
|
+
getProperties: () => {
|
|
49
|
+
return {id: 1, name: "test"};
|
|
50
|
+
}};
|
|
51
|
+
|
|
52
|
+
it("should be an svg by default values input", function () {
|
|
53
|
+
expect(stylePointInterval.createIntervalCircleBar(feature, attributes))
|
|
54
|
+
.toEqual("<svg width='20' height='20' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'><line x1='10' y1='10' x2='10' y2='0' stroke='#0ac864' stroke-width='10' /><circle cx='10' cy='10' r='10' stroke='#0ac864' stroke-width='1' fill='#0ac864' /></svg>");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as stylePointNominal from "../../../../src/vectorStyle/styles/point/stylePointNominal";
|
|
2
|
+
|
|
3
|
+
describe("stylePointNominal.js", () => {
|
|
4
|
+
describe("fillScalingAttributes", function () {
|
|
5
|
+
it("should return an object with empty = 0 for undefined input", function () {
|
|
6
|
+
expect(typeof stylePointNominal.fillScalingAttributes(undefined, undefined)).toBe("object");
|
|
7
|
+
expect(stylePointNominal.fillScalingAttributes(undefined, undefined)).toEqual({"empty": 0});
|
|
8
|
+
});
|
|
9
|
+
it("should return an object with empty = 0 for empty input", function () {
|
|
10
|
+
expect(typeof stylePointNominal.fillScalingAttributes({})).toBe("object");
|
|
11
|
+
expect(stylePointNominal.fillScalingAttributes({empty: 0})).toEqual({"empty": 0});
|
|
12
|
+
});
|
|
13
|
+
it("should return an object with empty = 1 for object with empty: 0 and false string input", function () {
|
|
14
|
+
expect(typeof stylePointNominal.fillScalingAttributes({empty: 0}, "test")).toBe("object");
|
|
15
|
+
expect(stylePointNominal.fillScalingAttributes({empty: 0}, "test")).toEqual({"empty": 1});
|
|
16
|
+
});
|
|
17
|
+
it("should return an object with empty = 0 for undefined input two", function () {
|
|
18
|
+
const scalingAttributesAsObject = {
|
|
19
|
+
available: 0,
|
|
20
|
+
charging: 0,
|
|
21
|
+
outoforder: 0,
|
|
22
|
+
empty: 0
|
|
23
|
+
},
|
|
24
|
+
scalingAttribute = "available";
|
|
25
|
+
|
|
26
|
+
expect(typeof stylePointNominal.fillScalingAttributes(scalingAttributesAsObject, scalingAttribute)).toBe("object");
|
|
27
|
+
expect(stylePointNominal.fillScalingAttributes(scalingAttributesAsObject, scalingAttribute))
|
|
28
|
+
.toEqual({"available": 2, "charging": 0, "outoforder": 0, "empty": 0});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("getScalingAttributesAsObject", function () {
|
|
33
|
+
it("should return an object with empty = 0 for undefined input", function () {
|
|
34
|
+
expect(typeof stylePointNominal.getScalingAttributesAsObject(undefined)).toBe("object");
|
|
35
|
+
expect(stylePointNominal.getScalingAttributesAsObject(undefined)).toEqual({"empty": 0});
|
|
36
|
+
});
|
|
37
|
+
it("should return an object with empty = 0 for empty input", function () {
|
|
38
|
+
expect(typeof stylePointNominal.getScalingAttributesAsObject({})).toBe("object");
|
|
39
|
+
expect(stylePointNominal.getScalingAttributesAsObject({})).toEqual({"empty": 0});
|
|
40
|
+
});
|
|
41
|
+
it("should return an object with available = 0 and empty = 0 for correct input", function () {
|
|
42
|
+
expect(typeof stylePointNominal.getScalingAttributesAsObject({available: [0, 220, 0, 0]})).toBe("object");
|
|
43
|
+
expect(stylePointNominal.getScalingAttributesAsObject({available: [0, 220, 0, 0]})).toEqual({available: 0, "empty": 0});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("calculateCircleSegment", function () {
|
|
48
|
+
it("should return a string that contains a circlesegment as svg-string for data of a semicircle input", function () {
|
|
49
|
+
const startAngelDegree = 0,
|
|
50
|
+
endAngelDegree = 180,
|
|
51
|
+
circleRadius = 21,
|
|
52
|
+
size = 58,
|
|
53
|
+
gap = 10;
|
|
54
|
+
|
|
55
|
+
expect(typeof stylePointNominal.calculateCircleSegment(startAngelDegree, endAngelDegree, circleRadius, size, gap)).toBe("string");
|
|
56
|
+
expect(stylePointNominal.calculateCircleSegment(startAngelDegree, endAngelDegree, circleRadius, size, gap))
|
|
57
|
+
.toEqual("M 49.920088659926655 27.16972940229918 A 21 21 0 0 0 8.079911340073345 27.16972940229918");
|
|
58
|
+
|
|
59
|
+
expect(typeof stylePointNominal.calculateCircleSegment(0, 360, circleRadius, size, gap)).toBe("string");
|
|
60
|
+
expect(stylePointNominal.calculateCircleSegment(0, 360, circleRadius, size, gap))
|
|
61
|
+
.toEqual("M 50 29 A 21 21 0 0 0 8 28.999999999999996 A 21 21 0 0 0 50 29");
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe("createNominalCircleSegments", function () {
|
|
66
|
+
const attributes = {
|
|
67
|
+
circleSegmentsRadius: 1,
|
|
68
|
+
circleSegmentsStrokeWidth: 10,
|
|
69
|
+
circleSegmentsBackgroundColor: [10, 200, 100, 0.5],
|
|
70
|
+
scalingValueDefaultColor: [10, 200, 100, 0.5],
|
|
71
|
+
circleSegmentsGap: 10,
|
|
72
|
+
scalingValues: 1
|
|
73
|
+
},
|
|
74
|
+
feature = {
|
|
75
|
+
get: () => {
|
|
76
|
+
return undefined;
|
|
77
|
+
}};
|
|
78
|
+
|
|
79
|
+
it("should be an svg by default values input", function () {
|
|
80
|
+
expect(stylePointNominal.createNominalCircleSegments(feature, attributes))
|
|
81
|
+
.toEqual("<svg width='32' height='32' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'><circle cx='16' cy='16' r='1' stroke='#0ac864' stroke-width='10' fill='#0ac864' fill-opacity='0.5'/></svg>");
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {createRegularShapeStyle} from "../../../../src/vectorStyle/styles/point/stylePointRegularShape";
|
|
2
|
+
import {Style, RegularShape} from "ol/style.js";
|
|
3
|
+
|
|
4
|
+
describe("createRegularShapeStyle", function () {
|
|
5
|
+
it("should create RegularShape style", function () {
|
|
6
|
+
const attributes = {
|
|
7
|
+
rsRadius: 10,
|
|
8
|
+
rsRadius2: 10,
|
|
9
|
+
rsPoints: 3,
|
|
10
|
+
rsAngle: 10,
|
|
11
|
+
rotation: 0,
|
|
12
|
+
rsScale: 1,
|
|
13
|
+
rsFillColor: [10, 200, 100, 0.5],
|
|
14
|
+
rsStrokeColor: [10, 200, 100],
|
|
15
|
+
rsStrokeWidth: 5
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
expect(createRegularShapeStyle(attributes)).toBeInstanceOf(Style);
|
|
19
|
+
expect(createRegularShapeStyle(attributes).getImage()).toBeInstanceOf(RegularShape);
|
|
20
|
+
expect(createRegularShapeStyle(attributes).getImage().getRadius()).toEqual(10);
|
|
21
|
+
expect(createRegularShapeStyle(attributes).getImage().getPoints()).toEqual(3);
|
|
22
|
+
expect(createRegularShapeStyle(attributes).getImage().getAngle()).toEqual(10);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {drawHatch} from "../../../../src/vectorStyle/styles/polygon/polygonStyleHatch";
|
|
2
|
+
|
|
3
|
+
describe("polygonStyleHatches", function () {
|
|
4
|
+
describe("drawHatch", function () {
|
|
5
|
+
let context = null;
|
|
6
|
+
|
|
7
|
+
beforeEach(function () {
|
|
8
|
+
context = {
|
|
9
|
+
stroke: jest.fn(),
|
|
10
|
+
translate: jest.fn(),
|
|
11
|
+
rotate: jest.fn(),
|
|
12
|
+
beginPath: jest.fn(),
|
|
13
|
+
rect: jest.fn(),
|
|
14
|
+
moveTo: jest.fn(),
|
|
15
|
+
lineTo: jest.fn(),
|
|
16
|
+
arc: jest.fn(),
|
|
17
|
+
lineWidth: 50
|
|
18
|
+
};
|
|
19
|
+
jest.spyOn(context, "translate");
|
|
20
|
+
jest.spyOn(context, "rotate");
|
|
21
|
+
jest.spyOn(context, "beginPath");
|
|
22
|
+
jest.spyOn(context, "rect");
|
|
23
|
+
jest.spyOn(context, "moveTo");
|
|
24
|
+
jest.spyOn(context, "lineTo");
|
|
25
|
+
jest.spyOn(context, "arc");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should draw patterns from known names to the context object", function () {
|
|
29
|
+
drawHatch(context, 100, "zig-line-horizontal");
|
|
30
|
+
|
|
31
|
+
expect(context.stroke).toHaveBeenCalledTimes(1);
|
|
32
|
+
expect(context.translate).toHaveBeenCalledTimes(2);
|
|
33
|
+
context.translate(50, 50);
|
|
34
|
+
expect(context.translate).toHaveBeenCalledWith(50, 50);
|
|
35
|
+
context.translate(-50, -50);
|
|
36
|
+
expect(context.translate).toHaveBeenCalledWith(-50, -50);
|
|
37
|
+
expect(context.rotate).toHaveBeenCalledTimes(1);
|
|
38
|
+
expect(context.rotate).toHaveBeenCalledWith(1.5707963267948966);
|
|
39
|
+
expect(context.beginPath).toHaveBeenCalledTimes(1);
|
|
40
|
+
expect(context.rect).toHaveBeenCalledTimes(0);
|
|
41
|
+
expect(context.moveTo).toHaveBeenCalledTimes(1);
|
|
42
|
+
expect(context.moveTo).toHaveBeenCalledWith(0, -25);
|
|
43
|
+
expect(context.lineTo).toHaveBeenCalledTimes(2);
|
|
44
|
+
expect(context.lineTo).toHaveBeenCalledWith(75, 50);
|
|
45
|
+
expect(context.lineTo).toHaveBeenCalledWith(0, 125);
|
|
46
|
+
expect(context.arc).toHaveBeenCalledTimes(0);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should draw patterns from custom definitions to the context object", function () {
|
|
50
|
+
drawHatch(context, 100, {
|
|
51
|
+
"draw": [
|
|
52
|
+
{
|
|
53
|
+
"type": "arc",
|
|
54
|
+
"parameters": [
|
|
55
|
+
0.5, 0.5, 7.5, -4.14, 1.14
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"type": "arc",
|
|
60
|
+
"parameters": [
|
|
61
|
+
0.55, 0.5, 7.5, -2, 1.14
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"type": "line",
|
|
66
|
+
"parameters": [
|
|
67
|
+
[0.66, 0.75],
|
|
68
|
+
[1, 0.75]
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"type": "rect",
|
|
73
|
+
"parameters": [
|
|
74
|
+
[0, 0, 1, 1]
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
expect(context.stroke).toHaveBeenCalledTimes(4);
|
|
81
|
+
expect(context.translate).toHaveBeenCalledTimes(0);
|
|
82
|
+
expect(context.rotate).toHaveBeenCalledTimes(0);
|
|
83
|
+
expect(context.beginPath).toHaveBeenCalledTimes(4);
|
|
84
|
+
expect(context.rect).toHaveBeenCalledTimes(1);
|
|
85
|
+
expect(context.rect).toHaveBeenCalledWith(0, 0, 100, 100);
|
|
86
|
+
expect(context.moveTo).toHaveBeenCalledTimes(1);
|
|
87
|
+
expect(context.moveTo).toHaveBeenCalledWith(66, 75);
|
|
88
|
+
expect(context.lineTo).toHaveBeenCalledTimes(1);
|
|
89
|
+
expect(context.lineTo).toHaveBeenCalledWith(100, 75);
|
|
90
|
+
expect(context.arc).toHaveBeenCalledTimes(2);
|
|
91
|
+
expect(context.arc).toHaveBeenCalledWith(50, 50, 7.5, -4.14, 1.14, false);
|
|
92
|
+
expect(context.arc).toHaveBeenCalledWith(55.00000000000001, 50, 7.5, -2, 1.14, false);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import PolygonStyle from "../../../../src/vectorStyle/styles/polygon/stylePolygon";
|
|
2
|
+
import {Style} from "ol/style.js";
|
|
3
|
+
|
|
4
|
+
describe("stylePolygon", () => {
|
|
5
|
+
const feature = {
|
|
6
|
+
geometryName: "geom",
|
|
7
|
+
id: "DE.HH.UP_GESUNDHEIT_KRANKENHAEUSER_2"
|
|
8
|
+
},
|
|
9
|
+
style = {
|
|
10
|
+
type: "icon",
|
|
11
|
+
clusterType: "icon",
|
|
12
|
+
legendValue: "Krankenhaus",
|
|
13
|
+
imageName: "krankenhaus.png"
|
|
14
|
+
},
|
|
15
|
+
isClustered = false,
|
|
16
|
+
stylePolygonClass = new PolygonStyle(feature, style, isClustered);
|
|
17
|
+
|
|
18
|
+
describe("getStyle", function () {
|
|
19
|
+
it("returns an instance of openlayers style", () => {
|
|
20
|
+
expect(stylePolygonClass.getStyle()).toBeInstanceOf(Style);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe("getPolygonFillHatch", () => {
|
|
25
|
+
it("should generate a polygon fill pattern with the given parameters", () => {
|
|
26
|
+
const params = {
|
|
27
|
+
pattern: "diagonal",
|
|
28
|
+
size: 30,
|
|
29
|
+
lineWidth: 10,
|
|
30
|
+
backgroundColor: [0, 0, 0, 1],
|
|
31
|
+
patternColor: [255, 255, 255, 1]
|
|
32
|
+
},
|
|
33
|
+
canvas = stylePolygonClass.getPolygonFillHatch(params);
|
|
34
|
+
|
|
35
|
+
expect(canvas).toBeInstanceOf(HTMLCanvasElement);
|
|
36
|
+
expect(canvas.width).toEqual(30);
|
|
37
|
+
expect(canvas.height).toEqual(30);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
describe("getPolygonFillHatchLegendDataUrl", () => {
|
|
43
|
+
it("should generate a legend data URL for the given style", () => {
|
|
44
|
+
const HatchStyle = {
|
|
45
|
+
polygonFillHatch: {
|
|
46
|
+
pattern: "diagonal",
|
|
47
|
+
size: 30,
|
|
48
|
+
lineWidth: 10,
|
|
49
|
+
backgroundColor: [0, 0, 0, 1],
|
|
50
|
+
patternColor: [255, 255, 255, 1]
|
|
51
|
+
},
|
|
52
|
+
polygonStrokeColor: [0, 0, 0, 1],
|
|
53
|
+
polygonStrokeWidth: "2"
|
|
54
|
+
},
|
|
55
|
+
dataUrl = stylePolygonClass.getPolygonFillHatchLegendDataUrl(HatchStyle);
|
|
56
|
+
|
|
57
|
+
expect(dataUrl).toMatch(/^data:image\/png;base64,/);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
});
|