@masterportal/masterportalapi 2.12.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 +19 -1
- 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 +63 -63
- package/src/layer/geojson/index.js +3 -3
- package/src/lib/attributeMapper.js +231 -0
- package/src/lib/getValueFromObjectByPath.js +73 -0
- package/src/lib/thousandsSeparator.js +23 -0
- package/src/maps/olcs/3dUtils/wmsRasterSynchronizer.js +3 -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,108 @@
|
|
|
1
|
+
import StyleClass from "../style";
|
|
2
|
+
import {createIconStyle} from "./stylePointIcon";
|
|
3
|
+
import {createCircleStyle} from "./stylePointCircle";
|
|
4
|
+
import {createRegularShapeStyle} from "./stylePointRegularShape";
|
|
5
|
+
import {createIntervalPointStyle} from "./stylePointInterval";
|
|
6
|
+
import {createNominalPointStyle} from "./stylePointNominal";
|
|
7
|
+
import {Style} from "ol/style.js";
|
|
8
|
+
import defaultStyle from "../defaultStyles";
|
|
9
|
+
|
|
10
|
+
class PointStyle extends StyleClass {
|
|
11
|
+
/**
|
|
12
|
+
* @description Class to create ol.style.Style
|
|
13
|
+
* @constructor
|
|
14
|
+
* @class PointStyle
|
|
15
|
+
* @extends StyleClass
|
|
16
|
+
* @memberof VectorStyle.Style
|
|
17
|
+
*/
|
|
18
|
+
constructor () {
|
|
19
|
+
super();
|
|
20
|
+
this.attributes = {...defaultStyle.point};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* This function initializes the Linestring Object by setting or overwriting some attributes.
|
|
25
|
+
* @param {ol/feature} feature Feature to be styled.
|
|
26
|
+
* @param {object} styles styling properties to overwrite defaults
|
|
27
|
+
* @param {Boolean} isClustered Flag to show if feature is clustered.
|
|
28
|
+
* @param {Boolean} wfsImgPathFromConfig image Path of the wfs.
|
|
29
|
+
* @returns {void}
|
|
30
|
+
*/
|
|
31
|
+
initialize (feature, styles, isClustered, wfsImgPathFromConfig) {
|
|
32
|
+
if (wfsImgPathFromConfig !== undefined) {
|
|
33
|
+
this.setImagePath(wfsImgPathFromConfig);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
console.warn("wfsImgPath at Config.js is not defined");
|
|
37
|
+
}
|
|
38
|
+
this.setFeature(feature);
|
|
39
|
+
this.setIsClustered(isClustered);
|
|
40
|
+
this.overwriteStyling(styles);
|
|
41
|
+
this.setStyle(this.getStyle());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* This function returns a style for each feature.
|
|
46
|
+
* @returns {ol/style} - The created style.
|
|
47
|
+
*/
|
|
48
|
+
getStyle () {
|
|
49
|
+
const type = this.attributes.type.toLowerCase(),
|
|
50
|
+
isClustered = this.isClustered;
|
|
51
|
+
|
|
52
|
+
if (type === "icon") {
|
|
53
|
+
return createIconStyle(this.attributes, this.feature, isClustered);
|
|
54
|
+
}
|
|
55
|
+
else if (type === "circle") {
|
|
56
|
+
return createCircleStyle(this.attributes, isClustered);
|
|
57
|
+
}
|
|
58
|
+
else if (type === "nominal") {
|
|
59
|
+
return isClustered ? createIconStyle(this.attributes, this.feature, isClustered) : createNominalPointStyle(this.attributes, this.feature, defaultStyle.point.imageName);
|
|
60
|
+
}
|
|
61
|
+
else if (type === "interval") {
|
|
62
|
+
return createIntervalPointStyle(this.feature, this.attributes);
|
|
63
|
+
}
|
|
64
|
+
else if (type === "regularshape") {
|
|
65
|
+
return createRegularShapeStyle(this.attributes);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return new Style();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Setter for circleSegmentsBackgroundColor
|
|
73
|
+
* @param {Number[]} value Color
|
|
74
|
+
* @returns {void}
|
|
75
|
+
*/
|
|
76
|
+
setCircleSegmentsBackgroundColor (value) {
|
|
77
|
+
this.attributes.circleSegmentsBackgroundColor = value;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Setter for size.
|
|
82
|
+
* @param {*} value Size
|
|
83
|
+
* @returns {void}
|
|
84
|
+
*/
|
|
85
|
+
setSize (value) {
|
|
86
|
+
this.size = value;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Getter for size.
|
|
91
|
+
* @param {*} size Size
|
|
92
|
+
* @returns {void}
|
|
93
|
+
*/
|
|
94
|
+
getSize () {
|
|
95
|
+
return this.size;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Setter for imagePath.
|
|
100
|
+
* @param {String} value Image path.
|
|
101
|
+
* @returns {void}
|
|
102
|
+
*/
|
|
103
|
+
setImagePath (value) {
|
|
104
|
+
this.attributes.imagePath = value;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export default PointStyle;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {Circle as CircleStyle, Fill, Stroke, Style} from "ol/style.js";
|
|
2
|
+
import {returnColor} from "../../lib/colorConvertions";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates pointStyle as circle.
|
|
6
|
+
* all features get same circle.
|
|
7
|
+
* @param {Object} attributes - The attributes from the circle
|
|
8
|
+
* @param {Boolean} isClustered - true if features are clustered
|
|
9
|
+
* @returns {ol/style} - The created style.
|
|
10
|
+
*/
|
|
11
|
+
export function createCircleStyle (attributes, isClustered) {
|
|
12
|
+
const radius = isClustered ? parseFloat(attributes.clusterCircleRadius, 10) : parseFloat(attributes.circleRadius, 10),
|
|
13
|
+
fillcolor = isClustered ? returnColor(attributes.clusterCircleFillColor, "rgb") : returnColor(attributes.circleFillColor, "rgb"),
|
|
14
|
+
strokecolor = isClustered ? returnColor(attributes.clusterCircleStrokeColor, "rgb") : returnColor(attributes.circleStrokeColor, "rgb"),
|
|
15
|
+
strokewidth = isClustered ? parseFloat(attributes.clusterCircleStrokeWidth, 10) : parseFloat(attributes.circleStrokeWidth, 10);
|
|
16
|
+
|
|
17
|
+
return new Style({
|
|
18
|
+
image: new CircleStyle({
|
|
19
|
+
radius: radius,
|
|
20
|
+
fill: new Fill({
|
|
21
|
+
color: fillcolor
|
|
22
|
+
}),
|
|
23
|
+
stroke: new Stroke({
|
|
24
|
+
color: strokecolor,
|
|
25
|
+
width: strokewidth
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {Style, Icon} from "ol/style.js";
|
|
2
|
+
import {prepareValue, isObjectPath} from "../../../lib/attributeMapper";
|
|
3
|
+
import PointStyle from "./stylePoint";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns the rotation value and its corresponding value according to style.json.
|
|
7
|
+
* @param {Object} rotation - The rotation object from the style.json
|
|
8
|
+
* @param {Object} featureValues - The values object from the feature
|
|
9
|
+
* @returns {number} - The rotation value in degrees or radiants.
|
|
10
|
+
*/
|
|
11
|
+
export function getRotationValue (rotation, featureValues) {
|
|
12
|
+
if (typeof rotation === "object") {
|
|
13
|
+
const {value, isDegree} = rotation;
|
|
14
|
+
|
|
15
|
+
if (isObjectPath(value) && featureValues !== undefined) {
|
|
16
|
+
const rotationValueFromService = parseInt(prepareValue(featureValues, value), 10);
|
|
17
|
+
|
|
18
|
+
return isDegree ? rotationValueFromService * Math.PI / 180 : rotationValueFromService;
|
|
19
|
+
}
|
|
20
|
+
return isDegree ? parseInt(value, 10) * Math.PI / 180 : parseInt(value, 10);
|
|
21
|
+
}
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Creates pointStyle as icon.
|
|
27
|
+
* All features get same image.
|
|
28
|
+
* @see {@link https://community.cesium.com/t/cors-and-billboard-image/3920/2} crossOrigin: "anonymous", is necessary for the 3D mode.
|
|
29
|
+
* @param {Object} attributes - The attributes from the icon
|
|
30
|
+
* @param {Object} feature - The feature
|
|
31
|
+
* @param {Boolean} isClustered - true if features are clustered
|
|
32
|
+
* @returns {ol/style} - The created style.
|
|
33
|
+
*/
|
|
34
|
+
export function createIconStyle (attributes, feature, isClustered) {
|
|
35
|
+
const showCluster = isClustered && feature.get("features")?.length > 1,
|
|
36
|
+
|
|
37
|
+
height = showCluster ? attributes.clusterImageHeight : attributes.imageHeight,
|
|
38
|
+
imageName = showCluster ? attributes.clusterImageName : attributes.imageName,
|
|
39
|
+
imageOffsetX = showCluster ? attributes.clusterImageOffsetY : attributes.imageOffsetX,
|
|
40
|
+
imageOffsetY = showCluster ? attributes.clusterImageOffsetX : attributes.imageOffsetY,
|
|
41
|
+
scale = showCluster ? attributes.clusterImageScale : attributes.imageScale,
|
|
42
|
+
src = imageName.indexOf("/") === -1 ? attributes.imagePath + imageName : imageName,
|
|
43
|
+
width = showCluster ? attributes.clusterImageWidth : attributes.imageWidth,
|
|
44
|
+
iconOptions = {
|
|
45
|
+
crossOrigin: "anonymous",
|
|
46
|
+
src: src.startsWith("<svg") ? "data:image/svg+xml;charset=utf-8," + encodeURIComponent(src) : src,
|
|
47
|
+
scale,
|
|
48
|
+
anchor: [parseFloat(imageOffsetX), parseFloat(imageOffsetY)],
|
|
49
|
+
imgSize: src.indexOf(".svg") > -1 ? [width, height] : ""
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
if (!showCluster) {
|
|
53
|
+
iconOptions.anchorXUnits = attributes.imageOffsetXUnit;
|
|
54
|
+
iconOptions.anchorYUnits = attributes.imageOffsetYUnit;
|
|
55
|
+
iconOptions.rotation = getRotationValue(attributes.rotation, feature.getProperties());
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return new Style({
|
|
59
|
+
image: new Icon(iconOptions)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* create Style for SVG
|
|
65
|
+
* @param {String} svgPath - contains the params to be draw
|
|
66
|
+
* @see {@link https://community.cesium.com/t/cors-and-billboard-image/3920/2} crossOrigin: "anonymous", is necessary for the 3D mode.
|
|
67
|
+
* @return {ol.Style} style
|
|
68
|
+
*/
|
|
69
|
+
export function createSVGStyle (svgPath) {
|
|
70
|
+
const size = PointStyle.prototype.getSize();
|
|
71
|
+
|
|
72
|
+
return new Style({
|
|
73
|
+
image: new Icon({
|
|
74
|
+
crossOrigin: "anonymous",
|
|
75
|
+
src: "data:image/svg+xml;charset=utf-8," + encodeURIComponent(svgPath),
|
|
76
|
+
imgSize: [size, size]
|
|
77
|
+
})
|
|
78
|
+
});
|
|
79
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {createSVGStyle} from "./stylePointIcon";
|
|
2
|
+
import PointStyle from "./stylePoint";
|
|
3
|
+
import {returnColor} from "../../lib/colorConvertions";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Calculate size for intervalscaled circle bar
|
|
7
|
+
* @param {number} stateValue - value from feature
|
|
8
|
+
* @param {number} circleBarScalingFactor - factor is multiplied by the stateValue
|
|
9
|
+
* @param {number} circleBarLineStroke - stroke from bar
|
|
10
|
+
* @param {number} circleBarRadius - radius from point
|
|
11
|
+
* @return {number} size - size of the section to be drawn
|
|
12
|
+
*/
|
|
13
|
+
export function calculateSizeIntervalCircleBar (stateValue, circleBarScalingFactor, circleBarLineStroke, circleBarRadius) {
|
|
14
|
+
let size = circleBarRadius * 2;
|
|
15
|
+
|
|
16
|
+
if (((stateValue * circleBarScalingFactor) + circleBarLineStroke) >= size) {
|
|
17
|
+
size = size + (stateValue * circleBarScalingFactor) + circleBarLineStroke;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return size;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Calculate the length for the bar
|
|
25
|
+
* @param {number} size - size of the section to be drawn
|
|
26
|
+
* @param {number} circleBarRadius - radius from point
|
|
27
|
+
* @param {number} stateValue - value from feature
|
|
28
|
+
* @param {number} circleBarScalingFactor - factor is multiplied by the stateValue
|
|
29
|
+
* @return {number} barLength
|
|
30
|
+
*/
|
|
31
|
+
export function calculateLengthIntervalCircleBar (size, circleBarRadius, stateValue, circleBarScalingFactor) {
|
|
32
|
+
let barLength;
|
|
33
|
+
|
|
34
|
+
if (stateValue >= 0) {
|
|
35
|
+
barLength = (size / 2) - circleBarRadius - (stateValue * circleBarScalingFactor);
|
|
36
|
+
}
|
|
37
|
+
else if (stateValue < 0) {
|
|
38
|
+
barLength = (size / 2) + circleBarRadius - (stateValue * circleBarScalingFactor);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
barLength = 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return barLength;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Create SVG for intervalscaled circle bars
|
|
49
|
+
* @param {number} size - size of the section to be drawn
|
|
50
|
+
* @param {number} barLength - length from bar
|
|
51
|
+
* @param {String} circleBarCircleFillColor - fill color from circle
|
|
52
|
+
* @param {String} circleBarCircleStrokeColor - stroke color from circle
|
|
53
|
+
* @param {number} circleBarCircleStrokeWidth - stroke width from circle
|
|
54
|
+
* @param {String} circleBarLineStrokeColor - stroke color from bar
|
|
55
|
+
* @param {number} circleBarLineStroke - stroke from bar
|
|
56
|
+
* @param {number} circleBarRadius - radius from point
|
|
57
|
+
* @return {String} svg
|
|
58
|
+
*/
|
|
59
|
+
// eslint-disable-next-line max-params
|
|
60
|
+
export function createSvgIntervalCircleBar (size, barLength, circleBarCircleFillColor, circleBarCircleStrokeColor, circleBarCircleStrokeWidth, circleBarLineStrokeColor, circleBarLineStroke, circleBarRadius) {
|
|
61
|
+
let svg = "<svg width='" + size + "'" +
|
|
62
|
+
" height='" + size + "'" +
|
|
63
|
+
" xmlns='http://www.w3.org/2000/svg'" +
|
|
64
|
+
" xmlns:xlink='http://www.w3.org/1999/xlink'>";
|
|
65
|
+
|
|
66
|
+
// draw bar
|
|
67
|
+
svg = svg + "<line x1='" + (size / 2) + "'" +
|
|
68
|
+
" y1='" + (size / 2) + "'" +
|
|
69
|
+
" x2='" + (size / 2) + "'" +
|
|
70
|
+
" y2='" + barLength + "'" +
|
|
71
|
+
" stroke='" + circleBarLineStrokeColor + "'" +
|
|
72
|
+
" stroke-width='" + circleBarLineStroke + "' />";
|
|
73
|
+
|
|
74
|
+
// draw circle
|
|
75
|
+
svg = svg + "<circle cx='" + (size / 2) + "'" +
|
|
76
|
+
" cy='" + (size / 2) + "'" +
|
|
77
|
+
" r='" + circleBarRadius + "'" +
|
|
78
|
+
" stroke='" + circleBarCircleStrokeColor + "'" +
|
|
79
|
+
" stroke-width='" + circleBarCircleStrokeWidth + "'" +
|
|
80
|
+
" fill='" + circleBarCircleFillColor + "' />";
|
|
81
|
+
svg = svg + "</svg>";
|
|
82
|
+
|
|
83
|
+
return svg;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Create interval circle bar
|
|
88
|
+
* @param {ol.Feature} feature - contains features to draw
|
|
89
|
+
* @param {ol.Feature} attributes - The attributes of the feature
|
|
90
|
+
* @return {String} svg
|
|
91
|
+
*/
|
|
92
|
+
export function createIntervalCircleBar (feature, attributes) {
|
|
93
|
+
const circleBarScalingFactor = parseFloat(attributes.circleBarScalingFactor),
|
|
94
|
+
circleBarRadius = parseFloat(attributes.circleBarRadius, 10),
|
|
95
|
+
circleBarLineStroke = parseFloat(attributes.circleBarLineStroke, 10),
|
|
96
|
+
circleBarCircleFillColor = returnColor(attributes.circleBarCircleFillColor, "hex"),
|
|
97
|
+
circleBarCircleStrokeColor = returnColor(attributes.circleBarCircleStrokeColor, "hex"),
|
|
98
|
+
circleBarCircleStrokeWidth = attributes.circleBarCircleStrokeWidth,
|
|
99
|
+
circleBarLineStrokeColor = returnColor(attributes.circleBarLineStrokeColor, "hex"),
|
|
100
|
+
featureProperties = feature.getProperties(),
|
|
101
|
+
preparedField = PointStyle.prototype.prepareField(featureProperties, attributes.scalingAttribute),
|
|
102
|
+
scalingAttribute = preparedField === "undefined" ? undefined : preparedField,
|
|
103
|
+
stateValue = scalingAttribute !== undefined && scalingAttribute.indexOf(" ") !== -1 ? scalingAttribute.split(" ")[0] : scalingAttribute,
|
|
104
|
+
size = calculateSizeIntervalCircleBar(stateValue, circleBarScalingFactor, circleBarLineStroke, circleBarRadius),
|
|
105
|
+
barLength = calculateLengthIntervalCircleBar(size, circleBarRadius, stateValue, circleBarScalingFactor);
|
|
106
|
+
|
|
107
|
+
PointStyle.prototype.setSize(size);
|
|
108
|
+
|
|
109
|
+
// create svg
|
|
110
|
+
return createSvgIntervalCircleBar(size, barLength, circleBarCircleFillColor, circleBarCircleStrokeColor, circleBarCircleStrokeWidth, circleBarLineStrokeColor, circleBarLineStroke, circleBarRadius);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* create interval scaled advanced style for pointFeatures
|
|
115
|
+
* @param {ol.Feature} feature - The feature
|
|
116
|
+
* @param {ol.Feature} attributes - The attributes of the feature
|
|
117
|
+
* @return {ol.Style} style
|
|
118
|
+
*/
|
|
119
|
+
export function createIntervalPointStyle (feature, attributes) {
|
|
120
|
+
const styleScalingShape = attributes.scalingShape.toUpperCase(),
|
|
121
|
+
svgPath = styleScalingShape === "CIRCLE_BAR" ? createIntervalCircleBar(feature, attributes) : "";
|
|
122
|
+
|
|
123
|
+
return createSVGStyle(svgPath);
|
|
124
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import {createIconStyle, createSVGStyle} from "./stylePointIcon";
|
|
2
|
+
import PointStyle from "./stylePoint";
|
|
3
|
+
import {returnColor} from "../../lib/colorConvertions";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create SVG for nominalscaled circle segments
|
|
7
|
+
* @param {number} size - size of the section to be drawn
|
|
8
|
+
* @param {number} circleSegmentsRadius - radius from circlesegment
|
|
9
|
+
* @param {String} circleSegmentsBackgroundColor - backgroundcolor from circlesegment
|
|
10
|
+
* @param {number} circleSegmentsStrokeWidth - strokewidth from circlesegment
|
|
11
|
+
* @param {String} circleSegmentsFillOpacity - opacity from circlesegment
|
|
12
|
+
* @return {String} svg
|
|
13
|
+
*/
|
|
14
|
+
export function createSvgNominalCircleSegments (size, circleSegmentsRadius, circleSegmentsBackgroundColor, circleSegmentsStrokeWidth, circleSegmentsFillOpacity) {
|
|
15
|
+
const halfSize = size / 2;
|
|
16
|
+
let svg = "<svg width='" + size + "'" +
|
|
17
|
+
" height='" + size + "'" +
|
|
18
|
+
" xmlns='http://www.w3.org/2000/svg'" +
|
|
19
|
+
" xmlns:xlink='http://www.w3.org/1999/xlink'>";
|
|
20
|
+
|
|
21
|
+
svg = svg + "<circle cx='" + halfSize + "'" +
|
|
22
|
+
" cy='" + halfSize + "'" +
|
|
23
|
+
" r='" + circleSegmentsRadius + "'" +
|
|
24
|
+
" stroke='" + circleSegmentsBackgroundColor + "'" +
|
|
25
|
+
" stroke-width='" + circleSegmentsStrokeWidth + "'" +
|
|
26
|
+
" fill='" + circleSegmentsBackgroundColor + "'" +
|
|
27
|
+
" fill-opacity='" + circleSegmentsFillOpacity + "'/>";
|
|
28
|
+
|
|
29
|
+
return svg;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Fills the object with values
|
|
34
|
+
* @param {object} scalingAttributesAsObject - object with possible attributes as keys and values = 0
|
|
35
|
+
* @param {string} scalingAttribute - actual states from feature
|
|
36
|
+
* @return {Object} scalingObject - contains the states
|
|
37
|
+
*/
|
|
38
|
+
export function fillScalingAttributes (scalingAttributesAsObject, scalingAttribute) {
|
|
39
|
+
const scalingObject = scalingAttributesAsObject === undefined || Object.keys(scalingAttributesAsObject).length === 0
|
|
40
|
+
? {empty: 0} : scalingAttributesAsObject;
|
|
41
|
+
let states = scalingAttribute;
|
|
42
|
+
|
|
43
|
+
if (states === undefined) {
|
|
44
|
+
return scalingObject;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
states = states.split(" | ");
|
|
48
|
+
|
|
49
|
+
states.forEach(function (state) {
|
|
50
|
+
if (Object.prototype.hasOwnProperty.call(scalingObject, state)) {
|
|
51
|
+
scalingObject[state] = scalingObject[state] + 1;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
scalingObject.empty = scalingObject.empty + 1;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return scalingObject;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Convert scalingAttributes to object
|
|
63
|
+
* @param {object} scalingValues - contains attribute with color
|
|
64
|
+
* @return {object} scalingAttribute with value 0
|
|
65
|
+
*/
|
|
66
|
+
export function getScalingAttributesAsObject (scalingValues) {
|
|
67
|
+
const obj = {};
|
|
68
|
+
let key;
|
|
69
|
+
|
|
70
|
+
if (scalingValues !== undefined) {
|
|
71
|
+
for (key in scalingValues) {
|
|
72
|
+
obj[key] = 0;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
obj.empty = 0;
|
|
77
|
+
|
|
78
|
+
return obj;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Create circle segments
|
|
83
|
+
* @param {number} startAngelDegree - start with circle segment
|
|
84
|
+
* @param {number} endAngelDegree - finish with circle segment
|
|
85
|
+
* @param {number} circleRadius - radius from circle
|
|
86
|
+
* @param {number} size - size of the window to be draw
|
|
87
|
+
* @param {number} gap - gap between segments
|
|
88
|
+
* @return {String} all circle segments
|
|
89
|
+
*/
|
|
90
|
+
export function calculateCircleSegment (startAngelDegree, endAngelDegree, circleRadius, size, gap) {
|
|
91
|
+
const rad = Math.PI / 180,
|
|
92
|
+
xy = size / 2,
|
|
93
|
+
isCircle = startAngelDegree === 0 && endAngelDegree === 360,
|
|
94
|
+
endAngelDegreeActual = isCircle ? endAngelDegree / 2 : endAngelDegree,
|
|
95
|
+
gapActual = isCircle ? 0 : gap,
|
|
96
|
+
// convert angle from degree to radiant
|
|
97
|
+
startAngleRad = (startAngelDegree + (gapActual / 2)) * rad,
|
|
98
|
+
endAngleRad = (endAngelDegreeActual - (gapActual / 2)) * rad,
|
|
99
|
+
xStart = xy + (Math.cos(startAngleRad) * circleRadius),
|
|
100
|
+
yStart = xy - (Math.sin(startAngleRad) * circleRadius),
|
|
101
|
+
xEnd = xy + (Math.cos(endAngleRad) * circleRadius),
|
|
102
|
+
yEnd = xy - (Math.sin(endAngleRad) * circleRadius);
|
|
103
|
+
|
|
104
|
+
if (isCircle) {
|
|
105
|
+
return [
|
|
106
|
+
"M", xStart, yStart,
|
|
107
|
+
"A", circleRadius, circleRadius, 0, 0, 0, xEnd, yEnd,
|
|
108
|
+
"A", circleRadius, circleRadius, 0, 0, 0, xStart, yStart
|
|
109
|
+
].join(" ");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return [
|
|
113
|
+
"M", xStart, yStart,
|
|
114
|
+
"A", circleRadius, circleRadius, 0, 0, 0, xEnd, yEnd
|
|
115
|
+
].join(" ");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Extends the SVG with given tags
|
|
120
|
+
* @param {String} svg - String with svg tags
|
|
121
|
+
* @param {number} circleSegmentsStrokeWidth strokewidth from circlesegment
|
|
122
|
+
* @param {String} strokeColor - strokecolor from circlesegment
|
|
123
|
+
* @param {String} d - circle segment
|
|
124
|
+
* @return {String} extended svg
|
|
125
|
+
*/
|
|
126
|
+
export function extendsSvgNominalCircleSegments (svg, circleSegmentsStrokeWidth, strokeColor, d) {
|
|
127
|
+
return svg + "<path" +
|
|
128
|
+
" fill='none'" +
|
|
129
|
+
" stroke-width='" + circleSegmentsStrokeWidth + "'" +
|
|
130
|
+
" stroke='" + strokeColor + "'" +
|
|
131
|
+
" d='" + d + "'/>";
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Create a svg with colored circle segments by nominal scaling
|
|
136
|
+
* @param {ol.Feature} feature - feature to be drawn
|
|
137
|
+
* @param {Object} attributes - The attributes from the nominal circle segment
|
|
138
|
+
* @return {String} svg with colored circle segments
|
|
139
|
+
*/
|
|
140
|
+
export function createNominalCircleSegments (feature, attributes) {
|
|
141
|
+
const circleSegmentsRadius = parseFloat(attributes.circleSegmentsRadius, 10),
|
|
142
|
+
circleSegmentsStrokeWidth = parseFloat(attributes.circleSegmentsStrokeWidth, 10),
|
|
143
|
+
circleSegBCArray = attributes.circleSegmentsBackgroundColor,
|
|
144
|
+
circleSegmentsFillOpacity = Array.isArray(circleSegBCArray) && circleSegBCArray[circleSegBCArray.length - 1],
|
|
145
|
+
circleSegmentsBackgroundColor = returnColor(attributes.circleSegmentsBackgroundColor, "hex"),
|
|
146
|
+
scalingValueDefaultColor = returnColor(attributes.scalingValueDefaultColor, "hex"),
|
|
147
|
+
scalingValues = attributes.scalingValues,
|
|
148
|
+
scalingAttributesAsObject = getScalingAttributesAsObject(scalingValues),
|
|
149
|
+
scalingAttribute = feature.get(attributes.scalingAttribute),
|
|
150
|
+
scalingObject = fillScalingAttributes(scalingAttributesAsObject, scalingAttribute),
|
|
151
|
+
totalSegments = Object.values(scalingObject).reduce(function (memo, num) {
|
|
152
|
+
return memo + num;
|
|
153
|
+
}, 0),
|
|
154
|
+
degreeSegment = totalSegments >= 0 ? 360 / totalSegments : 360,
|
|
155
|
+
gap = parseFloat(attributes.circleSegmentsGap, 10);
|
|
156
|
+
let size = 10,
|
|
157
|
+
startAngelDegree = 0,
|
|
158
|
+
endAngelDegree = degreeSegment,
|
|
159
|
+
svg,
|
|
160
|
+
d,
|
|
161
|
+
strokeColor,
|
|
162
|
+
i,
|
|
163
|
+
key,
|
|
164
|
+
value;
|
|
165
|
+
|
|
166
|
+
// calculate size
|
|
167
|
+
if (((circleSegmentsRadius + circleSegmentsStrokeWidth) * 2) >= size) {
|
|
168
|
+
size = size + ((circleSegmentsRadius + circleSegmentsStrokeWidth) * 2);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// is required for the display in the Internet Explorer,
|
|
172
|
+
// because in addition to the SVG and the size must be specified
|
|
173
|
+
PointStyle.prototype.setSize(size);
|
|
174
|
+
|
|
175
|
+
svg = createSvgNominalCircleSegments(size, circleSegmentsRadius, circleSegmentsBackgroundColor, circleSegmentsStrokeWidth, circleSegmentsFillOpacity);
|
|
176
|
+
|
|
177
|
+
for (key in scalingObject) {
|
|
178
|
+
value = scalingObject[key];
|
|
179
|
+
if (scalingValues !== undefined && (key !== "empty")) {
|
|
180
|
+
strokeColor = returnColor(scalingValues[key], "hex");
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
strokeColor = scalingValueDefaultColor;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// create segments
|
|
187
|
+
for (i = 0; i < value; i++) {
|
|
188
|
+
|
|
189
|
+
d = calculateCircleSegment(startAngelDegree, endAngelDegree, circleSegmentsRadius, size, gap);
|
|
190
|
+
|
|
191
|
+
svg = extendsSvgNominalCircleSegments(svg, circleSegmentsStrokeWidth, strokeColor, d);
|
|
192
|
+
|
|
193
|
+
// set degree for next circular segment
|
|
194
|
+
startAngelDegree = startAngelDegree + degreeSegment;
|
|
195
|
+
endAngelDegree = endAngelDegree + degreeSegment;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
svg = svg + "</svg>";
|
|
200
|
+
|
|
201
|
+
return svg;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* create nominal scaled advanced style for pointFeatures
|
|
206
|
+
* @param {Object} attributes - The attributes from the nominal point
|
|
207
|
+
* @param {Object} feature - the feature to be drawn
|
|
208
|
+
* @param {Object} defaultImageName - The image name from the default style
|
|
209
|
+
* @return {ol.Style} style
|
|
210
|
+
*/
|
|
211
|
+
export function createNominalPointStyle (attributes, feature, defaultImageName) {
|
|
212
|
+
const workingFeature = Array.isArray(feature.get("features")) ? feature.get("features")[0] : feature,
|
|
213
|
+
styleScalingShape = attributes.scalingShape.toUpperCase(),
|
|
214
|
+
imageName = attributes.imageName;
|
|
215
|
+
|
|
216
|
+
let svgPath,
|
|
217
|
+
style,
|
|
218
|
+
imageStyle;
|
|
219
|
+
|
|
220
|
+
if (styleScalingShape === "CIRCLESEGMENTS") {
|
|
221
|
+
svgPath = createNominalCircleSegments(workingFeature, attributes);
|
|
222
|
+
style = createSVGStyle(svgPath, 5);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// create style from svg and image
|
|
226
|
+
if (imageName !== defaultImageName) {
|
|
227
|
+
imageStyle = createIconStyle(attributes, feature);
|
|
228
|
+
style = [style, imageStyle];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return style;
|
|
232
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {RegularShape, Fill, Stroke, Style} from "ol/style.js";
|
|
2
|
+
import {returnColor} from "../../lib/colorConvertions";
|
|
3
|
+
import {getRotationValue} from "../point/stylePointIcon";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates RegularShape Style.
|
|
7
|
+
* all features get same shape styöe.
|
|
8
|
+
* @param {Object} attributes - The attributes from the circle
|
|
9
|
+
* @returns {ol/style} - The created RegularShape style.
|
|
10
|
+
*/
|
|
11
|
+
export function createRegularShapeStyle (attributes) {
|
|
12
|
+
const radius = parseFloat(attributes.rsRadius, 10),
|
|
13
|
+
radius2 = parseFloat(attributes.rsRadius2, 10),
|
|
14
|
+
points = parseFloat(attributes.rsPoints, 10),
|
|
15
|
+
angle = parseFloat(attributes.rsAngle, 10),
|
|
16
|
+
rotation = getRotationValue(attributes.rotation),
|
|
17
|
+
scale = attributes.rsScale,
|
|
18
|
+
fillcolor = returnColor(attributes.rsFillColor, "rgb"),
|
|
19
|
+
strokecolor = returnColor(attributes.rsStrokeColor, "rgb"),
|
|
20
|
+
strokewidth = parseFloat(attributes.rsStrokeWidth, 10);
|
|
21
|
+
|
|
22
|
+
return new Style({
|
|
23
|
+
image: new RegularShape({
|
|
24
|
+
radius: radius,
|
|
25
|
+
radius2: radius2,
|
|
26
|
+
points: points,
|
|
27
|
+
scale: scale,
|
|
28
|
+
rotation: rotation,
|
|
29
|
+
angle: angle,
|
|
30
|
+
fill: new Fill({
|
|
31
|
+
color: fillcolor
|
|
32
|
+
}),
|
|
33
|
+
stroke: new Stroke({
|
|
34
|
+
color: strokecolor,
|
|
35
|
+
width: strokewidth
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
}
|