@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.
- package/CHANGELOG.md +28 -0
- package/example/config/services.json +42 -21
- package/example/index.js +111 -97
- package/jest.setup.js +15 -0
- package/package.json +3 -3
- package/src/index.js +2 -0
- package/src/layer/wfs.js +29 -3
- package/src/maps/interactions/drawInteractions.js +214 -0
- package/src/maps/ol/olMap.js +2 -2
- package/src/renderer/webgl.js +35 -77
- package/src/vectorStyle/createStyle.js +14 -12
- package/src/vectorStyle/styles/point/stylePoint.js +2 -2
- package/src/vectorStyle/styles/polygon/stylePolygon.js +2 -2
- package/src/vectorStyle/styles/style.js +8 -0
- package/src/vectorStyle/styles/styleCesium.js +2 -2
- package/src/vectorStyle/styles/styleCircle.js +61 -0
- package/src/vectorStyle/styles/styleLine.js +2 -2
- package/src/vectorStyle/styles/styleText.js +2 -2
- package/test/layer/wfs.test.js +52 -0
- package/test/maps/interactions/drawInteractions.test.js +123 -0
- package/test/renderer/webgl.test.js +0 -50
- package/test/vectorStyle/styles/point/stylePoint.test.js +7 -1
- package/test/vectorStyle/styles/polygon/stylePolygon.test.js +4 -1
- package/test/vectorStyle/styles/styleCircle.test.js +31 -0
- package/test/vectorStyle/styles/styleLine.test.js +4 -1
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import {createBox} from "ol/interaction/Draw.js";
|
|
2
|
+
import {Draw} from "ol/interaction.js";
|
|
3
|
+
|
|
4
|
+
import createStyle from "../../vectorStyle/createStyle";
|
|
5
|
+
|
|
6
|
+
const earthRadius = 6378137,
|
|
7
|
+
roh = 180 / Math.PI,
|
|
8
|
+
mappingDrawTypes = {
|
|
9
|
+
box: {
|
|
10
|
+
type: "Circle",
|
|
11
|
+
options: {
|
|
12
|
+
geometryFunction: createBox()
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
circle: {
|
|
16
|
+
type: "Circle"
|
|
17
|
+
},
|
|
18
|
+
doubleCircle: {
|
|
19
|
+
type: "Circle"
|
|
20
|
+
},
|
|
21
|
+
line: {
|
|
22
|
+
type: "LineString"
|
|
23
|
+
},
|
|
24
|
+
pen: {
|
|
25
|
+
type: "LineString",
|
|
26
|
+
options: {
|
|
27
|
+
freehand: true
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
point: {
|
|
31
|
+
type: "Point"
|
|
32
|
+
},
|
|
33
|
+
polygon: {
|
|
34
|
+
type: "Polygon"
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
let styleObject = null,
|
|
38
|
+
styleObjectOuterCircle = null,
|
|
39
|
+
zIndex = 0;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Transform the radius to map projection unit.
|
|
43
|
+
* @param {Number} radius The radius.
|
|
44
|
+
* @param {Object} mapProjection The map projection.
|
|
45
|
+
* @returns {Number} The transformed radius.
|
|
46
|
+
*/
|
|
47
|
+
function transformMapUnitRadius (radius, mapProjection) {
|
|
48
|
+
const unit = mapProjection.getUnits();
|
|
49
|
+
let mapUnitRadius;
|
|
50
|
+
|
|
51
|
+
if (unit === "m") {
|
|
52
|
+
mapUnitRadius = radius;
|
|
53
|
+
}
|
|
54
|
+
else if (unit === "degrees") {
|
|
55
|
+
mapUnitRadius = radius * roh / earthRadius;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return mapUnitRadius;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Create a feature for the outer circle of draw type: double circle.
|
|
63
|
+
* @param {ol/feature} feature The ol feature.
|
|
64
|
+
* @param {Object} mapProjection The map projection.
|
|
65
|
+
* @param {ol/source} source The vector layer source for draw features.
|
|
66
|
+
* @param {Object} [options={}] The options for drawing features.
|
|
67
|
+
* @param {Number} [options.innerRadius] The radius for the inner circle.
|
|
68
|
+
* @param {Number} [options.outerRadius] The radius for the outer circle.
|
|
69
|
+
* @returns {void}
|
|
70
|
+
*/
|
|
71
|
+
function drawOuterCircle (feature, mapProjection, source, options = {}) {
|
|
72
|
+
const innerCircleFeature = feature.clone(),
|
|
73
|
+
mapUnitInnerRadius = transformMapUnitRadius(options.innerRadius, mapProjection),
|
|
74
|
+
mapUnitOuterRadius = transformMapUnitRadius(options.outerRadius, mapProjection),
|
|
75
|
+
innerStyle = createStyle.createStyle(styleObject, innerCircleFeature, false),
|
|
76
|
+
outerStyle = createStyle.createStyle(styleObjectOuterCircle, feature, false);
|
|
77
|
+
|
|
78
|
+
outerStyle.setZIndex(zIndex++);
|
|
79
|
+
feature.setStyle(outerStyle);
|
|
80
|
+
feature.getGeometry().setRadius(mapUnitOuterRadius);
|
|
81
|
+
|
|
82
|
+
innerStyle.setZIndex(zIndex++);
|
|
83
|
+
innerCircleFeature.setStyle(innerStyle);
|
|
84
|
+
innerCircleFeature.getGeometry().setRadius(mapUnitInnerRadius);
|
|
85
|
+
|
|
86
|
+
source.addFeature(innerCircleFeature);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Create a feature for the (inner) circle of draw type: circle or double circle.
|
|
91
|
+
* @param {ol/feature} feature The ol feature.vb
|
|
92
|
+
* @param {Object} mapProjection The map projection.
|
|
93
|
+
* @param {Object} [options={}] The options for drawing features.
|
|
94
|
+
* @param {Number} [options.innerRadius] The radius for the (inner) circle.
|
|
95
|
+
* @returns {void}
|
|
96
|
+
*/
|
|
97
|
+
function drawInnerCircle (feature, mapProjection, options = {}) {
|
|
98
|
+
const mapUnitInnerRadius = transformMapUnitRadius(options.innerRadius, mapProjection);
|
|
99
|
+
|
|
100
|
+
feature.getGeometry().setRadius(mapUnitInnerRadius);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Create features for non-interactive circle or double circle.
|
|
105
|
+
* @param {ol/interaction/Draw} drawInteraction The draw interaction.
|
|
106
|
+
* @param {String} drawType The current draw type.
|
|
107
|
+
* @param {Object} mapProjection The map projection.
|
|
108
|
+
* @param {ol/source} source The vector layer source for draw features.
|
|
109
|
+
* @param {Object} [options={}] The options for drawing features.
|
|
110
|
+
* @param {Number} [options.innerRadius] The radius for the inner circle.
|
|
111
|
+
* @param {Boolean} [options.interactive] Circle is drawn interactively or not.
|
|
112
|
+
* @param {Number} [options.outerRadius] The radius for the outer circle.
|
|
113
|
+
* @returns {void}
|
|
114
|
+
*/
|
|
115
|
+
function drawCircle (drawInteraction, drawType, mapProjection, source, options = {}) {
|
|
116
|
+
if ((drawType === "doubleCircle" || options.interactive === false) && options.innerRadius > 0) {
|
|
117
|
+
drawInteraction.on("drawstart", event => {
|
|
118
|
+
if (drawType === "circle") {
|
|
119
|
+
drawInnerCircle(event.feature, mapProjection, options);
|
|
120
|
+
}
|
|
121
|
+
else if (drawType === "doubleCircle" && options.outerRadius > 0) {
|
|
122
|
+
drawOuterCircle(event.feature, mapProjection, source, options);
|
|
123
|
+
}
|
|
124
|
+
drawInteraction.finishDrawing();
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Creates a styleObject from vectorStyling from layout.
|
|
131
|
+
* @param {Object} currentLayout The current layout.
|
|
132
|
+
* @param {Boolean} [outerCircle=false] Indicates if the styling is for the outer circle.
|
|
133
|
+
* @returns {void}
|
|
134
|
+
*/
|
|
135
|
+
function setStyleObject (currentLayout, outerCircle = false) {
|
|
136
|
+
const fillOpacity = 1 - (currentLayout.fillTransparency / 100),
|
|
137
|
+
fillColorRgba = [...currentLayout.fillColor, fillOpacity],
|
|
138
|
+
style = {
|
|
139
|
+
rules: [
|
|
140
|
+
{
|
|
141
|
+
style: {
|
|
142
|
+
circleFillColor: fillColorRgba,
|
|
143
|
+
circleStrokeColor: currentLayout.strokeColor,
|
|
144
|
+
circleStrokeWidth: currentLayout.strokeWidth,
|
|
145
|
+
lineStrokeColor: currentLayout.strokeColor,
|
|
146
|
+
lineStrokeWidth: currentLayout.strokeWidth,
|
|
147
|
+
polygonFillColor: fillColorRgba,
|
|
148
|
+
polygonStrokeColor: currentLayout.strokeColor,
|
|
149
|
+
polygonStrokeWidth: currentLayout.strokeWidth
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
if (outerCircle === true) {
|
|
156
|
+
styleObjectOuterCircle = style;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
styleObject = style;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Sets the style to overlay and feature.
|
|
165
|
+
* @param {ol/interaction/Draw} drawInteraction The draw interaction.
|
|
166
|
+
* @returns {void}
|
|
167
|
+
*/
|
|
168
|
+
function setStyleToDrawInteraction (drawInteraction) {
|
|
169
|
+
drawInteraction.on("drawstart", event => {
|
|
170
|
+
const style = createStyle.createStyle(styleObject, event.feature, false);
|
|
171
|
+
|
|
172
|
+
style.setZIndex(zIndex++);
|
|
173
|
+
drawInteraction.getOverlay().setStyle(style);
|
|
174
|
+
event.feature.setStyle(style);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Create the draw interaction.
|
|
180
|
+
* @param {String} drawType The current draw type.
|
|
181
|
+
* @param {ol/source} source The vector layer source for draw features.
|
|
182
|
+
* @returns {ol/interaction/Draw|null} The draw interaction.
|
|
183
|
+
*/
|
|
184
|
+
function createDrawInteraction (drawType, source) {
|
|
185
|
+
let drawInteraction = null;
|
|
186
|
+
|
|
187
|
+
if (typeof mappingDrawTypes[drawType] === "object") {
|
|
188
|
+
const options = mappingDrawTypes[drawType].options || {};
|
|
189
|
+
|
|
190
|
+
drawInteraction = new Draw({
|
|
191
|
+
freehand: options.freehand,
|
|
192
|
+
geometryFunction: options.geometryFunction,
|
|
193
|
+
source: source,
|
|
194
|
+
type: mappingDrawTypes[drawType].type
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
if (styleObject !== null && drawType !== "doubleCircle") {
|
|
198
|
+
setStyleToDrawInteraction(drawInteraction);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return drawInteraction;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export {styleObject};
|
|
206
|
+
|
|
207
|
+
export default {
|
|
208
|
+
createDrawInteraction,
|
|
209
|
+
drawCircle,
|
|
210
|
+
drawInnerCircle,
|
|
211
|
+
drawOuterCircle,
|
|
212
|
+
setStyleObject,
|
|
213
|
+
transformMapUnitRadius
|
|
214
|
+
};
|
package/src/maps/ol/olMap.js
CHANGED
|
@@ -4,7 +4,7 @@ import setBackgroundImage from "../../lib/setBackgroundImage";
|
|
|
4
4
|
import getInitialLayers from "../../lib/getInitialLayers";
|
|
5
5
|
import defaults from "../../defaults";
|
|
6
6
|
import * as wms from "../../layer/wms";
|
|
7
|
-
import
|
|
7
|
+
import wmts from "../../layer/wmts";
|
|
8
8
|
import * as geojson from "../../layer/geojson";
|
|
9
9
|
import * as wfs from "../../layer/wfs";
|
|
10
10
|
import * as vectorBase from "../../layer/vectorBase";
|
|
@@ -23,7 +23,7 @@ let mapIdCounter = 0;
|
|
|
23
23
|
*/
|
|
24
24
|
const layerBuilderMap = {
|
|
25
25
|
wms,
|
|
26
|
-
wmts,
|
|
26
|
+
"wmts": wmts,
|
|
27
27
|
wfs,
|
|
28
28
|
geojson,
|
|
29
29
|
vectorBase,
|
package/src/renderer/webgl.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import WebGLPointsLayer from "ol/layer/WebGLPoints";
|
|
2
2
|
import WebGLVectorLayerRenderer from "ol/renderer/webgl/VectorLayer";
|
|
3
3
|
import VectorLayer from "ol/layer/Layer";
|
|
4
|
-
import {packColor} from "ol/renderer/webgl/shaders";
|
|
5
4
|
import styleList from "../vectorStyle/styleList";
|
|
6
5
|
import {getRulesForFeature} from "../vectorStyle/lib/getRuleForIndex";
|
|
6
|
+
import {returnColor} from "../vectorStyle/lib/colorConvertions";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The default style for OpenLayers WebGLPoints class
|
|
@@ -11,82 +11,24 @@ import {getRulesForFeature} from "../vectorStyle/lib/getRuleForIndex";
|
|
|
11
11
|
* @private
|
|
12
12
|
*/
|
|
13
13
|
const defaultStyle = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* parses the styling rules for the renderer
|
|
26
|
-
* @static
|
|
27
|
-
* @private
|
|
28
|
-
* @returns {Object} the style options object with conditional functions
|
|
29
|
-
*/
|
|
30
|
-
export function getRenderFunctions () {
|
|
31
|
-
return {
|
|
32
|
-
/**
|
|
33
|
-
* Used for polygon fills
|
|
34
|
-
* Reads the relevant properties from the Masterportal style object
|
|
35
|
-
* @see https://bitbucket.org/geowerkstatt-hamburg/masterportal/src/dev/doc/style.json.md
|
|
36
|
-
*/
|
|
37
|
-
fill: {
|
|
38
|
-
attributes: {
|
|
39
|
-
color: (feature) => {
|
|
40
|
-
return packColor(feature.styleRule?.style.polygonFillColor || "#006688");
|
|
41
|
-
},
|
|
42
|
-
opacity: (feature) => {
|
|
43
|
-
return typeof feature.styleRule?.style.polygonFillColor?.[3] === "number" ?
|
|
44
|
-
feature.styleRule.style.polygonFillColor[3] : 1;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
stroke: {
|
|
49
|
-
/**
|
|
50
|
-
* Used for polygon edges and lineStrings
|
|
51
|
-
* Reads the relevant properties from the Masterportal style object
|
|
52
|
-
* @see https://bitbucket.org/geowerkstatt-hamburg/masterportal/src/dev/doc/style.json.md
|
|
53
|
-
*/
|
|
54
|
-
attributes: {
|
|
55
|
-
color: (feature) => {
|
|
56
|
-
return packColor(feature.styleRule?.style.polygonStrokeColor || "#006688");
|
|
57
|
-
},
|
|
58
|
-
width: (feature) => {
|
|
59
|
-
return feature.styleRule?.style.polygonStrokeWidth || 1;
|
|
60
|
-
},
|
|
61
|
-
opacity: (feature) => {
|
|
62
|
-
return typeof feature.styleRule?.style.polygonStrokeColor?.[3] === "number" ?
|
|
63
|
-
feature.styleRule.style.polygonStrokeColor[3] : 1;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
point: {
|
|
68
|
-
/**
|
|
69
|
-
* As of now, the generic VectorLayerRenderer only supports points rendered as quads
|
|
70
|
-
* available attributes: color, size, opacity
|
|
71
|
-
* Due to that, we use WebGLPoints Layer Class for point geom types
|
|
72
|
-
* Reads the relevant properties from the Masterportal style object
|
|
73
|
-
* @see https://bitbucket.org/geowerkstatt-hamburg/masterportal/src/dev/doc/style.json.md
|
|
74
|
-
*/
|
|
75
|
-
attributes: {
|
|
76
|
-
color: (feature) => {
|
|
77
|
-
return packColor(feature.styleRule?.style.circleFillColor || "#006688");
|
|
78
|
-
},
|
|
79
|
-
size: (feature) => {
|
|
80
|
-
return feature.styleRule?.style.circleRadius || 20;
|
|
81
|
-
},
|
|
82
|
-
opacity: (feature) => {
|
|
83
|
-
return typeof feature.styleRule?.style.circleFillColor?.[3] === "number" ?
|
|
84
|
-
feature.styleRule.style.circleFillColor[3] : 1;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
14
|
+
symbol: {
|
|
15
|
+
symbolType: "circle",
|
|
16
|
+
size: 20,
|
|
17
|
+
color: "#006688",
|
|
18
|
+
rotateWithView: false,
|
|
19
|
+
offset: [0, 0],
|
|
20
|
+
opacity: 0.6
|
|
87
21
|
}
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
/** @type {import('ol/style/literal.js').LiteralStyle} */
|
|
25
|
+
style = {
|
|
26
|
+
"stroke-color": ["get", "STROKECOLOR"],
|
|
27
|
+
"stroke-width": ["get", "STROKEWIDTH", "number"],
|
|
28
|
+
"fill-color": ["get", "FILLCOLOR"],
|
|
29
|
+
"opacity": ["get", "OPACITY", "number"],
|
|
30
|
+
"size": ["get", "CIRCLESIZE", "number"]
|
|
88
31
|
};
|
|
89
|
-
}
|
|
90
32
|
|
|
91
33
|
/**
|
|
92
34
|
* Creates a layer object to extend from.
|
|
@@ -109,7 +51,9 @@ export function createVectorLayerRenderer () {
|
|
|
109
51
|
* @experimental
|
|
110
52
|
*/
|
|
111
53
|
createRenderer () {
|
|
112
|
-
return new WebGLVectorLayerRenderer(this,
|
|
54
|
+
return new WebGLVectorLayerRenderer(this, {
|
|
55
|
+
style
|
|
56
|
+
});
|
|
113
57
|
}
|
|
114
58
|
}
|
|
115
59
|
|
|
@@ -132,9 +76,23 @@ export function formatFeatureStyles (feature, styleObject) {
|
|
|
132
76
|
// extract first matching rule only
|
|
133
77
|
const rule = getRulesForFeature(styleObject, feature)[0];
|
|
134
78
|
|
|
135
|
-
// don't set on properties to avoid GFI issues
|
|
136
79
|
// undefined if no match
|
|
137
80
|
feature.styleRule = rule;
|
|
81
|
+
|
|
82
|
+
if (rule && rule.style) {
|
|
83
|
+
const polygonFillColor = returnColor(rule.style.polygonFillColor, "hex"),
|
|
84
|
+
circleFillColor = returnColor(rule.style.circleFillColor, "hex"),
|
|
85
|
+
fillColor = polygonFillColor ? polygonFillColor : circleFillColor,
|
|
86
|
+
strokeColor = returnColor(rule.style.polygonStrokeColor || rule.style.lineStrokeColor, "hex"),
|
|
87
|
+
strokeWidth = rule.style.polygonStrokeWidth || rule.style.lineStrokeWidth,
|
|
88
|
+
size = rule.style.circleRadius;
|
|
89
|
+
|
|
90
|
+
feature.set("FILLCOLOR", fillColor ? fillColor : "#006688");
|
|
91
|
+
feature.set("STROKECOLOR", strokeColor ? strokeColor : "#006688");
|
|
92
|
+
feature.set("STROKEWIDTH", strokeWidth ? strokeWidth : 1);
|
|
93
|
+
feature.set("OPACITY", fillColor ? (rule.style.polygonFillColor || rule.style.circleFillColor)[3] : 1);
|
|
94
|
+
feature.set("CIRCLESIZE", size ? size : 20);
|
|
95
|
+
}
|
|
138
96
|
}
|
|
139
97
|
|
|
140
98
|
/**
|
|
@@ -3,11 +3,11 @@ import PointStyle from "./styles/point/stylePoint";
|
|
|
3
3
|
import TextStyle from "./styles/styleText";
|
|
4
4
|
import PolygonStyle from "./styles/polygon/stylePolygon";
|
|
5
5
|
import LineStringStyle from "./styles/styleLine";
|
|
6
|
+
import CircleStyle from "./styles/styleCircle";
|
|
6
7
|
import CesiumStyle from "./styles/styleCesium";
|
|
7
8
|
import {getRuleForIndex, getRulesForFeature} from "./lib/getRuleForIndex";
|
|
8
9
|
|
|
9
|
-
const legendsOfAllStyles = []
|
|
10
|
-
uniqueStyles = [];
|
|
10
|
+
const legendsOfAllStyles = [];
|
|
11
11
|
let legendInformationLength = 0;
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -30,17 +30,13 @@ function isMultiGeometry (geometryType) {
|
|
|
30
30
|
*/
|
|
31
31
|
function getSimpleGeometryStyle (geometryType, feature, rule, isClustered, wfsImgPathFromConfig) {
|
|
32
32
|
const style = rule?.style,
|
|
33
|
-
legendValue = style ? style.legendValue : null
|
|
34
|
-
alreadyExisitingStyle = uniqueStyles.find(element => element.featureStyle === style && element.geometryType === geometryType);
|
|
33
|
+
legendValue = style ? style.legendValue : null;
|
|
35
34
|
let styleObject,
|
|
36
35
|
styleObjectForLegend = null;
|
|
37
36
|
|
|
38
37
|
feature.legendValue = legendValue ? legendValue : null;
|
|
39
38
|
|
|
40
|
-
if (
|
|
41
|
-
styleObject = alreadyExisitingStyle.featureStyleObject;
|
|
42
|
-
}
|
|
43
|
-
else if (geometryType === "Point") {
|
|
39
|
+
if (geometryType === "Point") {
|
|
44
40
|
styleObject = new PointStyle(feature, style, isClustered);
|
|
45
41
|
if (isClustered) {
|
|
46
42
|
styleObjectForLegend = new PointStyle(feature, style, false);
|
|
@@ -65,7 +61,13 @@ function getSimpleGeometryStyle (geometryType, feature, rule, isClustered, wfsIm
|
|
|
65
61
|
styleObject.legendValue = legendValue;
|
|
66
62
|
return styleObject;
|
|
67
63
|
}
|
|
68
|
-
else if (geometryType === "
|
|
64
|
+
else if (geometryType === "Circle") {
|
|
65
|
+
styleObject = new CircleStyle(feature, style, isClustered);
|
|
66
|
+
if (isClustered) {
|
|
67
|
+
styleObjectForLegend = new CircleStyle(feature, style, false);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (geometryType === "LinearRing") {
|
|
69
71
|
console.warn("Geometry type not implemented: " + geometryType + " default style ist used for feature " + feature);
|
|
70
72
|
return new Style();
|
|
71
73
|
}
|
|
@@ -78,7 +80,6 @@ function getSimpleGeometryStyle (geometryType, feature, rule, isClustered, wfsIm
|
|
|
78
80
|
styleObjectForLegend.initialize(feature, style, false, wfsImgPathFromConfig);
|
|
79
81
|
styleObjectForLegend.legendValue = legendValue;
|
|
80
82
|
}
|
|
81
|
-
uniqueStyles.push({featureStyle: style, featureStyleObject: styleObject, geometryType});
|
|
82
83
|
styleObject.initialize(feature, style, isClustered, wfsImgPathFromConfig);
|
|
83
84
|
styleObject.addLegendInfo(geometryType, styleObjectForLegend === null ? styleObject : styleObjectForLegend, rule);
|
|
84
85
|
styleObject.legendValue = legendValue;
|
|
@@ -122,6 +123,7 @@ function getMultiGeometryStyle (geometryType, feature, rules, isClustered, wfsIm
|
|
|
122
123
|
console.warn("Multi encapsulated multiGeometries are not supported.");
|
|
123
124
|
}
|
|
124
125
|
else if (!simpleStyle.styleMultiGeomOnlyWithRule || rule) {
|
|
126
|
+
simpleStyle.getStyle()?.setGeometry(geometry);
|
|
125
127
|
olStyle.push(simpleStyle);
|
|
126
128
|
}
|
|
127
129
|
});
|
|
@@ -136,7 +138,7 @@ function getMultiGeometryStyle (geometryType, feature, rules, isClustered, wfsIm
|
|
|
136
138
|
else {
|
|
137
139
|
const simpleStyle = getSimpleGeometryStyle(geometryType, feature, rules, isClustered, wfsImgPathFromConfig);
|
|
138
140
|
|
|
139
|
-
simpleStyle.getStyle()
|
|
141
|
+
simpleStyle.getStyle()?.setGeometry(geometryType);
|
|
140
142
|
olStyle.push(simpleStyle);
|
|
141
143
|
}
|
|
142
144
|
return olStyle;
|
|
@@ -251,7 +253,7 @@ function createStyle (styleObject, feature, isClustered, wfsImgPathFromConfig) {
|
|
|
251
253
|
captureLegendFromFeature(styleObject.styleId, legendInformation);
|
|
252
254
|
}
|
|
253
255
|
// label style is optional and depends on some fields
|
|
254
|
-
if (isClustered || hasLabelField) {
|
|
256
|
+
if (styleObjectGeometry !== null && (isClustered || hasLabelField)) {
|
|
255
257
|
if (Array.isArray(styleObjectGeometry)) {
|
|
256
258
|
styleObjectGeometry[0].setText(getLabelStyle(feature, style, isClustered));
|
|
257
259
|
}
|
|
@@ -38,14 +38,14 @@ class PointStyle extends StyleClass {
|
|
|
38
38
|
this.setFeature(feature);
|
|
39
39
|
this.setIsClustered(isClustered);
|
|
40
40
|
this.overwriteStyling(styles);
|
|
41
|
-
this.setStyle(this.
|
|
41
|
+
this.setStyle(this.createStyle());
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* This function returns a style for each feature.
|
|
46
46
|
* @returns {ol/style} - The created style.
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
createStyle () {
|
|
49
49
|
if (this.nullStyle) {
|
|
50
50
|
return null;
|
|
51
51
|
}
|
|
@@ -28,14 +28,14 @@ class PolygonStyle extends StyleClass {
|
|
|
28
28
|
this.setFeature(feature);
|
|
29
29
|
this.setIsClustered(isClustered);
|
|
30
30
|
this.overwriteStyling(styles);
|
|
31
|
-
this.setStyle(this.
|
|
31
|
+
this.setStyle(this.createStyle());
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* This function returns a style for each feature.
|
|
36
36
|
* @returns {ol/style} - The created style.
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
createStyle () {
|
|
39
39
|
if (this.nullStyle) {
|
|
40
40
|
return null;
|
|
41
41
|
}
|
|
@@ -22,14 +22,14 @@ class CesiumStyle extends StyleClass {
|
|
|
22
22
|
initialize (rule) {
|
|
23
23
|
this.overwriteStyling(rule.style);
|
|
24
24
|
this.setConditions(rule.conditions);
|
|
25
|
-
this.setStyle(this.
|
|
25
|
+
this.setStyle(this.createStyle());
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* This function returns a style for each feature.
|
|
30
30
|
* @returns {ol/style} - The created style.
|
|
31
31
|
*/
|
|
32
|
-
|
|
32
|
+
createStyle () {
|
|
33
33
|
return this.createCondition(this.get("conditions"), this.get("style"));
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import StyleClass from "./style";
|
|
2
|
+
import {Circle, Fill, Stroke, Style} from "ol/style.js";
|
|
3
|
+
import defaultStyle from "./defaultStyles";
|
|
4
|
+
|
|
5
|
+
class CircleStyle extends StyleClass {
|
|
6
|
+
/**
|
|
7
|
+
* @description Class to create ol.style.Style
|
|
8
|
+
* @constructor
|
|
9
|
+
* @class CircleStyle
|
|
10
|
+
* @extends StyleClass
|
|
11
|
+
* @memberof VectorStyle.Style
|
|
12
|
+
*/
|
|
13
|
+
constructor () {
|
|
14
|
+
super();
|
|
15
|
+
this.attributes = {...defaultStyle.circle};
|
|
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.createStyle());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* This function returns a style for each feature.
|
|
34
|
+
* @returns {ol/style/Style} - The created style.
|
|
35
|
+
*/
|
|
36
|
+
createStyle () {
|
|
37
|
+
if (this.nullStyle) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const fill = new Fill({
|
|
42
|
+
color: this.attributes.circleFillColor
|
|
43
|
+
}),
|
|
44
|
+
stroke = new Stroke({
|
|
45
|
+
color: this.attributes.circleStrokeColor,
|
|
46
|
+
width: this.attributes.circleStrokeWidth
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return new Style({
|
|
50
|
+
image: new Circle({
|
|
51
|
+
fill: fill,
|
|
52
|
+
stroke: stroke,
|
|
53
|
+
radius: 0
|
|
54
|
+
}),
|
|
55
|
+
fill: fill,
|
|
56
|
+
stroke: stroke
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default CircleStyle;
|
|
@@ -26,14 +26,14 @@ class LineStringStyle extends StyleClass {
|
|
|
26
26
|
this.setFeature(feature);
|
|
27
27
|
this.setIsClustered(isClustered);
|
|
28
28
|
this.overwriteStyling(styles);
|
|
29
|
-
this.setStyle(this.
|
|
29
|
+
this.setStyle(this.createStyle());
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* This function returns a style for each feature.
|
|
34
34
|
* @returns {ol/style/Style} - The created style.
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
createStyle () {
|
|
37
37
|
if (this.nullStyle) {
|
|
38
38
|
return null;
|
|
39
39
|
}
|
|
@@ -28,14 +28,14 @@ class TextStyle extends StyleClass {
|
|
|
28
28
|
this.setFeature(feature);
|
|
29
29
|
this.setIsClustered(isClustered);
|
|
30
30
|
this.overwriteStyling(styles);
|
|
31
|
-
this.setStyle(this.
|
|
31
|
+
this.setStyle(this.createStyle());
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* This function returns a style for each feature.
|
|
36
36
|
* @returns {ol/style} - The created style.
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
createStyle () {
|
|
39
39
|
if (this.nullStyle) {
|
|
40
40
|
return null;
|
|
41
41
|
}
|
package/test/layer/wfs.test.js
CHANGED
|
@@ -414,5 +414,57 @@ describe("wfs.js", function () {
|
|
|
414
414
|
expect(webgl.afterLoading).toHaveBeenCalled();
|
|
415
415
|
});
|
|
416
416
|
});
|
|
417
|
+
describe("loadFeaturesManually", function () {
|
|
418
|
+
const consoleError = console.error;
|
|
419
|
+
let tick;
|
|
420
|
+
|
|
421
|
+
beforeEach(() => {
|
|
422
|
+
tick = () => {
|
|
423
|
+
return new Promise(resolve => {
|
|
424
|
+
setTimeout(resolve, 0);
|
|
425
|
+
});
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
if (global.fetch) {
|
|
429
|
+
global.fetch.mockClear();
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
// to reset show error on load in console
|
|
433
|
+
afterEach(() => {
|
|
434
|
+
console.error = consoleError;
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
it("load features manually", async function () {
|
|
438
|
+
global.fetch = jest.fn().mockImplementationOnce(() => {
|
|
439
|
+
return new Promise((resolve) => {
|
|
440
|
+
resolve({
|
|
441
|
+
ok: true,
|
|
442
|
+
status: 200,
|
|
443
|
+
text: () => {
|
|
444
|
+
return featureCollection;
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
const format = new WFS(),
|
|
451
|
+
source = new VectorSource({
|
|
452
|
+
format: format,
|
|
453
|
+
url: "https://url.de",
|
|
454
|
+
version: "1.1.0",
|
|
455
|
+
featureType: "krankenhaeuser_hh",
|
|
456
|
+
featureNS: "http://www.deegree.org/app"
|
|
457
|
+
}),
|
|
458
|
+
layerAttributes = {
|
|
459
|
+
crs: "EPSG:25832",
|
|
460
|
+
version: "1.1.0",
|
|
461
|
+
url: "https://url.de"
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
wfs.loadFeaturesManually(layerAttributes, source);
|
|
465
|
+
await tick();
|
|
466
|
+
expect(source.getFeatures()).toHaveLength(1);
|
|
467
|
+
});
|
|
468
|
+
});
|
|
417
469
|
});
|
|
418
470
|
|