@masterportal/masterportalapi 2.13.0 → 2.15.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 +16 -7
- package/example/config/localGeoJSONPoints.js +2106 -0
- package/example/config/portal.json +47 -1
- package/example/config/services.json +20 -0
- package/example/index.js +50 -7
- package/jest.config.js +1 -1
- package/jest.setup.js +9 -1
- package/package.json +64 -62
- package/src/index.js +3 -1
- package/src/layer/geojson/index.js +55 -4
- package/src/layer/oaf.js +35 -5
- package/src/layer/vectorBase.js +20 -1
- package/src/layer/wfs.js +38 -7
- package/src/lib/attributeMapper.js +231 -0
- package/src/lib/getValueFromObjectByPath.js +73 -0
- package/src/lib/thousandsSeparator.js +23 -0
- package/src/maps/ol/olMap.js +4 -3
- package/src/renderer/webgl.js +250 -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/layer/geojson/index.test.js +23 -0
- package/test/layer/oaf.test.js +30 -0
- package/test/layer/vectorBase.test.js +27 -7
- package/test/layer/wfs.test.js +30 -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/renderer/webgl.test.js +161 -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,160 @@
|
|
|
1
|
+
// pattern library – default draw instructions as described in style.json.md
|
|
2
|
+
const diagonal = {
|
|
3
|
+
draw: [
|
|
4
|
+
{type: "line", parameters: [[1, -0.5], [-0.5, 1]]},
|
|
5
|
+
{type: "line", parameters: [[1.5, 0], [0, 1.5]]}
|
|
6
|
+
]
|
|
7
|
+
},
|
|
8
|
+
zigLine = {
|
|
9
|
+
draw: [
|
|
10
|
+
{type: "line", parameters: [[0, -0.25], [0.75, 0.5], [0, 1.25]]}
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
namedHatches = {
|
|
14
|
+
diagonal,
|
|
15
|
+
"zig-line": zigLine,
|
|
16
|
+
"diagonal-right": {...diagonal, rotate: 90},
|
|
17
|
+
"zig-line-horizontal": {...zigLine, rotate: 90},
|
|
18
|
+
rectangle: {
|
|
19
|
+
draw: [
|
|
20
|
+
{type: "rect", parameters: [
|
|
21
|
+
[0.125, 0.125, 0.25, 0.25],
|
|
22
|
+
[0.625, 0.625, 0.25, 0.25]
|
|
23
|
+
]}
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
triangle: {
|
|
27
|
+
draw: [
|
|
28
|
+
{type: "line", parameters: [
|
|
29
|
+
[0.25, 0], [0.5, 0.5], [0, 0.5], [0.25, 0]
|
|
30
|
+
]},
|
|
31
|
+
{type: "line", parameters: [
|
|
32
|
+
[0.75, 0.5], [1, 1], [0.5, 1], [0.75, 0.5]
|
|
33
|
+
]}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
diamond: {
|
|
37
|
+
draw: [
|
|
38
|
+
{type: "line", parameters: [
|
|
39
|
+
[0.25, 0], [0.5, 0.25], [0.25, 0.5], [0, 0.25], [0.25, 0]
|
|
40
|
+
]},
|
|
41
|
+
{type: "line", parameters: [
|
|
42
|
+
[0.75, 0.5], [1, 0.75], [0.75, 1], [0.5, 0.75], [0.75, 0.5]
|
|
43
|
+
]}
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
circle: {
|
|
47
|
+
draw: [
|
|
48
|
+
{type: "arc", parameters: [
|
|
49
|
+
0.25, 0.25,
|
|
50
|
+
({size, lineWidth}) => (size - (2 * lineWidth)) / 4
|
|
51
|
+
]},
|
|
52
|
+
{type: "arc", parameters: [
|
|
53
|
+
0.75, 0.75,
|
|
54
|
+
({size, lineWidth}) => (size - (2 * lineWidth)) / 4
|
|
55
|
+
]}
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Determines the absolute position of a relative segment coordinate.
|
|
62
|
+
* @param {Number} size side length of context
|
|
63
|
+
* @returns {Function} gets absolute position in context (x or y)
|
|
64
|
+
*/
|
|
65
|
+
function makeCalculateAbsolutePosition (size) {
|
|
66
|
+
return relativePosition => relativePosition * size;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Draws a singular draw instruction to context, i.e., a single line, rect, or arc.
|
|
71
|
+
* @param {CanvasRenderingContext2D} context draw context
|
|
72
|
+
* @param {Number} size side length of context
|
|
73
|
+
* @param {Object} segment draw segment, i.e. a singular draw instruction
|
|
74
|
+
* @param {('rect'|'line'|'arc')} segment.type what kind of segment it is
|
|
75
|
+
* @param {Array} segment.parameters type-specific parameters, see style.json.md
|
|
76
|
+
* @returns {void} side-effect on context
|
|
77
|
+
*/
|
|
78
|
+
function drawSegment (context, size, {type, parameters}) {
|
|
79
|
+
const calculateAbsolutePosition = makeCalculateAbsolutePosition(size);
|
|
80
|
+
|
|
81
|
+
context.beginPath();
|
|
82
|
+
|
|
83
|
+
if (type === "rect") {
|
|
84
|
+
parameters.forEach(rect => context.rect(...rect.map(calculateAbsolutePosition)));
|
|
85
|
+
}
|
|
86
|
+
else if (type === "line") {
|
|
87
|
+
const [start, ...waypoints] = parameters;
|
|
88
|
+
|
|
89
|
+
context.moveTo(...start.map(calculateAbsolutePosition));
|
|
90
|
+
waypoints.forEach(waypoint => context.lineTo(...waypoint.map(calculateAbsolutePosition)));
|
|
91
|
+
}
|
|
92
|
+
else if (type === "arc") {
|
|
93
|
+
const [
|
|
94
|
+
x, y, getRadiusOrRadius, startAngle, endAngle, counterclockwise
|
|
95
|
+
] = parameters,
|
|
96
|
+
radius = typeof getRadiusOrRadius === "function"
|
|
97
|
+
? getRadiusOrRadius({size, lineWidth: context.lineWidth})
|
|
98
|
+
: getRadiusOrRadius;
|
|
99
|
+
|
|
100
|
+
context.arc(makeCalculateAbsolutePosition(size)(x),
|
|
101
|
+
makeCalculateAbsolutePosition(size)(y),
|
|
102
|
+
radius,
|
|
103
|
+
// default to full circle
|
|
104
|
+
startAngle || 0,
|
|
105
|
+
endAngle || 2 * Math.PI,
|
|
106
|
+
counterclockwise || false);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
console.error(`polygonStyleHatches: Unknown segment type "${type}". Skipping segment.`);
|
|
110
|
+
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
context.stroke();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Rotates a given context of side length "size" by "degrees" around its center.
|
|
120
|
+
* Normally, rotation would happen based on the top left corner.
|
|
121
|
+
* @param {CanvasRenderingContext2D} context draw context
|
|
122
|
+
* @param {Number} size side length of context
|
|
123
|
+
* @param {Number} [degrees=90] degrees to rotate context by
|
|
124
|
+
* @returns {void} side-effect on context
|
|
125
|
+
*/
|
|
126
|
+
function rotateContextCenter (context, size, degrees = 90) {
|
|
127
|
+
const halfSize = 0.5 * size;
|
|
128
|
+
|
|
129
|
+
context.translate(halfSize, halfSize);
|
|
130
|
+
context.rotate(degrees * (Math.PI / 180));
|
|
131
|
+
context.translate(-halfSize, -halfSize);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Draws a hatch pattern to the context element.
|
|
136
|
+
* @param {CanvasRenderingContext2D} context draw context
|
|
137
|
+
* @param {Number} size side length of context
|
|
138
|
+
* @param {(("diagonal"|"zig-line"|"diagonal-right"|"zig-line-horizontal"|"rectangle"|"triangle"|"diamond"|"circle")|Object)} pattern Name of pattern library object, or draw instructions as described in style.json.md
|
|
139
|
+
* @returns {void} side-effect on context
|
|
140
|
+
*/
|
|
141
|
+
export function drawHatch (context, size, pattern) {
|
|
142
|
+
const hatchDefinition = typeof pattern === "string"
|
|
143
|
+
? namedHatches[pattern]
|
|
144
|
+
: pattern;
|
|
145
|
+
|
|
146
|
+
if (hatchDefinition) {
|
|
147
|
+
const {draw, rotate} = hatchDefinition;
|
|
148
|
+
|
|
149
|
+
if (draw) {
|
|
150
|
+
draw.forEach(segment => drawSegment(context, size, segment));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (rotate) {
|
|
154
|
+
rotateContextCenter(context, size, rotate);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
console.error(`polygonStyleHatches: Unknown polygon style "${pattern}". Skipping hatching.`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import StyleClass from "../style";
|
|
2
|
+
import {Style, Fill, Stroke} from "ol/style.js";
|
|
3
|
+
import defaultStyle from "../defaultStyles";
|
|
4
|
+
import {drawHatch} from "./polygonStyleHatch";
|
|
5
|
+
import {returnColor} from "../../lib/colorConvertions";
|
|
6
|
+
|
|
7
|
+
class PolygonStyle extends StyleClass {
|
|
8
|
+
/**
|
|
9
|
+
* @description Class to create ol.style.Style
|
|
10
|
+
* @constructor
|
|
11
|
+
* @class PolygonStyle
|
|
12
|
+
* @extends StyleClass
|
|
13
|
+
* @memberof VectorStyle.Style
|
|
14
|
+
*/
|
|
15
|
+
constructor () {
|
|
16
|
+
super();
|
|
17
|
+
this.attributes = {...defaultStyle.polygon};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This function initializes the stylePolygon Object by setting or overwriting some attributes.
|
|
22
|
+
* @param {ol/feature} feature Feature to be styled.
|
|
23
|
+
* @param {object} styles styling properties to overwrite defaults
|
|
24
|
+
* @param {Boolean} isClustered Flag to show if feature is clustered.
|
|
25
|
+
* @returns {void}
|
|
26
|
+
*/
|
|
27
|
+
initialize (feature, styles, isClustered) {
|
|
28
|
+
this.setFeature(feature);
|
|
29
|
+
this.setIsClustered(isClustered);
|
|
30
|
+
this.overwriteStyling(styles);
|
|
31
|
+
this.setStyle(this.getStyle());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* This function returns a style for each feature.
|
|
36
|
+
* @returns {ol/style} - The created style.
|
|
37
|
+
*/
|
|
38
|
+
getStyle () {
|
|
39
|
+
const polygonFillColor = this.attributes.polygonFillColor,
|
|
40
|
+
polygonFillHatch = this.attributes.polygonFillHatch;
|
|
41
|
+
|
|
42
|
+
return new Style({
|
|
43
|
+
stroke: new Stroke({
|
|
44
|
+
lineCap: this.attributes.polygonStrokeCap,
|
|
45
|
+
lineJoin: this.attributes.polygonStrokeJoin,
|
|
46
|
+
lineDash: this.attributes.polygonStrokeDash,
|
|
47
|
+
lineDashOffset: this.attributes.polygonStrokeDashOffset,
|
|
48
|
+
miterLimit: this.attributes.polygonStrokeMiterLimit,
|
|
49
|
+
color: this.attributes.polygonStrokeColor,
|
|
50
|
+
width: this.attributes.polygonStrokeWidth
|
|
51
|
+
}),
|
|
52
|
+
fill: new Fill({color:
|
|
53
|
+
polygonFillHatch
|
|
54
|
+
? this.getPolygonFillHatch(polygonFillHatch)
|
|
55
|
+
.getContext("2d")
|
|
56
|
+
.fillStyle
|
|
57
|
+
: polygonFillColor
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Generates a polygon fill pattern.
|
|
64
|
+
* @param {object} params parameters as defined in style.json.md#Polygon.polygonFillHatch
|
|
65
|
+
* @returns {HTMLCanvasElement} contains polygon fill pattern
|
|
66
|
+
*/
|
|
67
|
+
getPolygonFillHatch ({
|
|
68
|
+
pattern = "diagonal",
|
|
69
|
+
size = 30,
|
|
70
|
+
lineWidth = 10,
|
|
71
|
+
backgroundColor = [0, 0, 0, 1],
|
|
72
|
+
patternColor = [255, 255, 255, 1]
|
|
73
|
+
}) {
|
|
74
|
+
const canvas = document.createElement("canvas"),
|
|
75
|
+
context = canvas.getContext("2d");
|
|
76
|
+
|
|
77
|
+
canvas.width = size;
|
|
78
|
+
canvas.height = size;
|
|
79
|
+
|
|
80
|
+
context.fillStyle = `rgba(${backgroundColor.join(",")})`;
|
|
81
|
+
context.fillRect(0, 0, canvas.width, canvas.height);
|
|
82
|
+
|
|
83
|
+
context.lineWidth = lineWidth;
|
|
84
|
+
context.strokeStyle = `rgba(${patternColor.join(",")})`;
|
|
85
|
+
|
|
86
|
+
drawHatch(context, size, pattern);
|
|
87
|
+
|
|
88
|
+
context.fillStyle = context.createPattern(canvas, "repeat");
|
|
89
|
+
|
|
90
|
+
return canvas;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getPolygonFillHatchLegendDataUrl (style) {
|
|
94
|
+
const originalCanvas = this.getPolygonFillHatch(style.polygonFillHatch),
|
|
95
|
+
strokeColor = returnColor(style.polygonStrokeColor, "hex"),
|
|
96
|
+
strokeWidth = parseInt(style.polygonStrokeWidth, 10),
|
|
97
|
+
strokeOpacity = style.polygonStrokeColor[3].toString() || 0,
|
|
98
|
+
legendCanvas = document.createElement("canvas"),
|
|
99
|
+
legendContext = legendCanvas.getContext("2d"),
|
|
100
|
+
halfStroke = strokeWidth / 2,
|
|
101
|
+
doubleStroke = strokeWidth * 2;
|
|
102
|
+
|
|
103
|
+
legendCanvas.width = originalCanvas.width + doubleStroke;
|
|
104
|
+
legendCanvas.height = originalCanvas.height + doubleStroke;
|
|
105
|
+
|
|
106
|
+
legendContext.drawImage(originalCanvas,
|
|
107
|
+
strokeWidth,
|
|
108
|
+
strokeWidth);
|
|
109
|
+
|
|
110
|
+
legendContext.lineCap = "round";
|
|
111
|
+
legendContext.lineJoin = "round";
|
|
112
|
+
legendContext.strokeStyle = strokeColor;
|
|
113
|
+
legendContext.lineWidth = strokeWidth;
|
|
114
|
+
legendContext.globalAlpha = strokeOpacity;
|
|
115
|
+
|
|
116
|
+
legendContext.strokeRect(halfStroke,
|
|
117
|
+
halfStroke,
|
|
118
|
+
legendCanvas.width - strokeWidth,
|
|
119
|
+
legendCanvas.height - strokeWidth);
|
|
120
|
+
|
|
121
|
+
return legendCanvas.toDataURL();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export default PolygonStyle;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import {getValueFromObjectByPath} from "../../lib/getValueFromObjectByPath";
|
|
2
|
+
|
|
3
|
+
class StyleClass {
|
|
4
|
+
/**
|
|
5
|
+
* @param {ol/feature} feature Feature to be styled.
|
|
6
|
+
* @param {object} style styling properties to overwrite defaults
|
|
7
|
+
* @param {Boolean} isClustered Flag to show if feature is clustered.
|
|
8
|
+
* @constructor
|
|
9
|
+
*/
|
|
10
|
+
constructor (feature, style, isClustered) {
|
|
11
|
+
this.feature = feature;
|
|
12
|
+
this.style = style;
|
|
13
|
+
this.isClustered = isClustered;
|
|
14
|
+
this.attributes = {};
|
|
15
|
+
this.legendInfos = [];
|
|
16
|
+
this.styleMultiGeomOnlyWithRule = false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* setter for feature
|
|
21
|
+
* @param {ol/feature} value the feature to set
|
|
22
|
+
* @returns {void}
|
|
23
|
+
*/
|
|
24
|
+
setFeature (value) {
|
|
25
|
+
this.feature = value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Setter for style.
|
|
30
|
+
* @param {object} value the style to set
|
|
31
|
+
* @returns {void}
|
|
32
|
+
*/
|
|
33
|
+
setStyle (value) {
|
|
34
|
+
this.style = value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* setter for styles
|
|
39
|
+
* @param {object} styles styles
|
|
40
|
+
* @returns {void}
|
|
41
|
+
*/
|
|
42
|
+
overwriteStyling (styles) {
|
|
43
|
+
// check if styles object is defined
|
|
44
|
+
// if not, use defaults instead
|
|
45
|
+
if (styles) {
|
|
46
|
+
Object.keys(styles).forEach(element => {
|
|
47
|
+
const value = styles[element];
|
|
48
|
+
|
|
49
|
+
this.attributes[element] = value;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* setter for isClustered
|
|
56
|
+
* @param {Boolean} value isClustered
|
|
57
|
+
* @returns {void}
|
|
58
|
+
*/
|
|
59
|
+
setIsClustered (value) {
|
|
60
|
+
this.isClustered = value;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* returns the legend info
|
|
65
|
+
* @returns {object[]} legend objects
|
|
66
|
+
*/
|
|
67
|
+
getLegendInfos () {
|
|
68
|
+
return this.legendInfos;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Returns an id created from geometryType and conditions using encodeURIComponent.
|
|
73
|
+
* @param {string} geometryType features geometry type
|
|
74
|
+
* @param {object} rule a rule description
|
|
75
|
+
* @returns {string} id
|
|
76
|
+
*/
|
|
77
|
+
createLegendId (geometryType, rule) {
|
|
78
|
+
const properties = rule?.conditions ? rule.conditions : null;
|
|
79
|
+
|
|
80
|
+
return encodeURIComponent(geometryType + JSON.stringify(properties));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns the label or null examining some attributes. Giving precedence to "legendValue". Otherwhile creates a string out of rules conditions.
|
|
85
|
+
* @param {Object} rule conditions
|
|
86
|
+
* @param {vectorStyle/style} styleObject a vector style needed in
|
|
87
|
+
* @returns {String | null} label for styleObject
|
|
88
|
+
*/
|
|
89
|
+
createLegendLabel (rule, styleObject) {
|
|
90
|
+
if (styleObject?.attributes?.legendValue) {
|
|
91
|
+
return styleObject.attributes.legendValue.toString();
|
|
92
|
+
}
|
|
93
|
+
else if (rule?.conditions) {
|
|
94
|
+
let label = "";
|
|
95
|
+
|
|
96
|
+
if (rule.conditions?.properties) {
|
|
97
|
+
label = Object.values(rule.conditions.properties).join(", ");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (rule.conditions?.sequence
|
|
101
|
+
&& Array.isArray(rule.conditions.sequence)
|
|
102
|
+
&& rule.conditions.sequence.every(element => typeof element === "number")
|
|
103
|
+
&& rule.conditions.sequence.length === 2
|
|
104
|
+
&& rule.conditions.sequence[1] >= rule.conditions.sequence[0]) {
|
|
105
|
+
label = label + " (" + rule.conditions.sequence.join("-") + ")";
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return label;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Adds a unique legendInfo for each id to vectorStyle model to be used for legend descriptions.
|
|
116
|
+
* @param {string} geometryType features geometry type needed in legend model
|
|
117
|
+
* @param {vectorStyle/style} styleObject a vector style needed in
|
|
118
|
+
* @param {Object} rule conditions
|
|
119
|
+
* @returns {void}
|
|
120
|
+
*/
|
|
121
|
+
addLegendInfo (geometryType, styleObject, rule) {
|
|
122
|
+
const {legendInfos} = styleObject,
|
|
123
|
+
id = this.createLegendId(geometryType, rule),
|
|
124
|
+
hasLegendInfo = legendInfos.some(legend => {
|
|
125
|
+
return legend.id === id;
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
if (!hasLegendInfo) {
|
|
129
|
+
this.legendInfos.push({
|
|
130
|
+
"id": id,
|
|
131
|
+
"geometryType": geometryType,
|
|
132
|
+
"styleObject": styleObject.attributes.type === "NOMINAL" ? {attributes: styleObject.attributes, style: styleObject.style} : styleObject.attributes,
|
|
133
|
+
"label": this.createLegendLabel(rule, styleObject)
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Returns the value of the given field. Also considers that the field can be an object path.
|
|
140
|
+
* @param {Object} featureProperties Feature properties.
|
|
141
|
+
* @param {String} field Field to get value.
|
|
142
|
+
* @returns {*} - Value from given field.
|
|
143
|
+
*/
|
|
144
|
+
prepareField (featureProperties, field) {
|
|
145
|
+
const isPath = field.startsWith("@");
|
|
146
|
+
let value = field;
|
|
147
|
+
|
|
148
|
+
if (isPath) {
|
|
149
|
+
value = getValueFromObjectByPath(featureProperties, value);
|
|
150
|
+
if (typeof value === "undefined") {
|
|
151
|
+
value = "undefined";
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
value = Object.prototype.hasOwnProperty.call(featureProperties, field) ? featureProperties[field] : "undefined";
|
|
156
|
+
}
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export default StyleClass;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import StyleClass from "./style";
|
|
2
|
+
import defaultStyle from "./defaultStyles";
|
|
3
|
+
class CesiumStyle extends StyleClass {
|
|
4
|
+
/**
|
|
5
|
+
* @description Class to create ol.style.Style
|
|
6
|
+
* @constructor
|
|
7
|
+
* @class CesiumStyleMode
|
|
8
|
+
* @extends StyleClass
|
|
9
|
+
* @memberof VectorStyle.Style
|
|
10
|
+
*/
|
|
11
|
+
constructor () {
|
|
12
|
+
super();
|
|
13
|
+
this.attributes = {...defaultStyle.point};
|
|
14
|
+
this.conditions = [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This function initializes the Linestring Object by setting or overwriting some attributes.
|
|
19
|
+
* @param {ol/feature} rule styling rule of the feature.
|
|
20
|
+
* @returns {void}
|
|
21
|
+
*/
|
|
22
|
+
initialize (rule) {
|
|
23
|
+
this.overwriteStyling(rule.style);
|
|
24
|
+
this.setConditions(rule.conditions);
|
|
25
|
+
this.setStyle(this.getStyle());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* This function returns a style for each feature.
|
|
30
|
+
* @returns {ol/style} - The created style.
|
|
31
|
+
*/
|
|
32
|
+
getStyle () {
|
|
33
|
+
return this.createCondition(this.get("conditions"), this.get("style"));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates the cesium tile style conditions.
|
|
38
|
+
* @param {Object} conditions Condition.
|
|
39
|
+
* @param {Object} style Style.
|
|
40
|
+
* @returns {*} - Condition for cesium 3d tile style.
|
|
41
|
+
*/
|
|
42
|
+
createCondition (conditions, style) {
|
|
43
|
+
const {color} = style,
|
|
44
|
+
condition = [];
|
|
45
|
+
let ruleCondition;
|
|
46
|
+
|
|
47
|
+
if (conditions && Object.keys(conditions).length > 0) {
|
|
48
|
+
Object.keys(conditions).forEach(key => {
|
|
49
|
+
const value = conditions[key];
|
|
50
|
+
|
|
51
|
+
condition.push([key, value]);
|
|
52
|
+
});
|
|
53
|
+
ruleCondition = [this.createCesiumConditionForRule(condition), color];
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
ruleCondition = ["true", color];
|
|
57
|
+
}
|
|
58
|
+
return ruleCondition;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Creates a cesium condition.
|
|
63
|
+
* @param {*} conditions Conditions.
|
|
64
|
+
* @returns {String[]} - Cesium condition for rule.
|
|
65
|
+
*/
|
|
66
|
+
createCesiumConditionForRule (conditions) {
|
|
67
|
+
let cesiumCondition = [],
|
|
68
|
+
singleCondition = "";
|
|
69
|
+
|
|
70
|
+
conditions.forEach(condition => {
|
|
71
|
+
const cesiumKey = "${" + condition[0] + "}";
|
|
72
|
+
let value = condition[1],
|
|
73
|
+
minValue,
|
|
74
|
+
maxValue;
|
|
75
|
+
|
|
76
|
+
if (Array.isArray(value)) {
|
|
77
|
+
minValue = value[0];
|
|
78
|
+
maxValue = value[1];
|
|
79
|
+
singleCondition = "(" + cesiumKey + " > " + minValue + " && " + cesiumKey + " <= " + maxValue + ")";
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
if (typeof value === "string") {
|
|
83
|
+
value = "'" + value + "'";
|
|
84
|
+
}
|
|
85
|
+
singleCondition = "(" + cesiumKey + " === " + value + ")";
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
cesiumCondition.push(singleCondition);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
cesiumCondition = "(" + cesiumCondition.join(" && ") + ")";
|
|
92
|
+
|
|
93
|
+
return cesiumCondition;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Setter for attribute "conditions"
|
|
98
|
+
* @param {*} conditions conditions
|
|
99
|
+
* @returns {void}
|
|
100
|
+
*/
|
|
101
|
+
setConditions (conditions) {
|
|
102
|
+
this.attributes.conditions = conditions;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export default CesiumStyle;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import StyleClass from "./style";
|
|
2
|
+
import {Style, Stroke} from "ol/style.js";
|
|
3
|
+
import defaultStyle from "./defaultStyles";
|
|
4
|
+
|
|
5
|
+
class LineStringStyle extends StyleClass {
|
|
6
|
+
/**
|
|
7
|
+
* @description Class to create ol.style.Style
|
|
8
|
+
* @constructor
|
|
9
|
+
* @class LineStringStyle
|
|
10
|
+
* @extends StyleClass
|
|
11
|
+
* @memberof VectorStyle.Style
|
|
12
|
+
*/
|
|
13
|
+
constructor () {
|
|
14
|
+
super();
|
|
15
|
+
this.attributes = {...defaultStyle.line};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This function initializes the Linestring Object by setting or overwriting some attributes.
|
|
20
|
+
* @param {ol/feature} feature Feature to be styled.
|
|
21
|
+
* @param {object} styles styling properties to overwrite defaults
|
|
22
|
+
* @param {Boolean} isClustered Flag to show if feature is clustered.
|
|
23
|
+
* @returns {void}
|
|
24
|
+
*/
|
|
25
|
+
initialize (feature, styles, isClustered) {
|
|
26
|
+
this.setFeature(feature);
|
|
27
|
+
this.setIsClustered(isClustered);
|
|
28
|
+
this.overwriteStyling(styles);
|
|
29
|
+
this.setStyle(this.getStyle());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* This function returns a style for each feature.
|
|
34
|
+
* @returns {ol/style/Style} - The created style.
|
|
35
|
+
*/
|
|
36
|
+
getStyle () {
|
|
37
|
+
return new Style({
|
|
38
|
+
stroke: new Stroke({
|
|
39
|
+
lineCap: this.attributes.lineStrokeCap,
|
|
40
|
+
lineJoin: this.attributes.lineStrokeJoin,
|
|
41
|
+
lineDash: this.attributes.lineStrokeDash,
|
|
42
|
+
lineDashOffset: this.attributes.lineStrokeDashOffset,
|
|
43
|
+
miterLimit: this.attributes.lineStrokeMiterLimit,
|
|
44
|
+
color: this.attributes.lineStrokeColor,
|
|
45
|
+
width: this.attributes.lineStrokeWidth
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default LineStringStyle;
|