@masterportal/masterportalapi 2.26.0 → 2.28.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 +34 -1
- package/package.json +3 -3
- package/src/layer/tileset.js +10 -5
- package/src/lib/attributeMapper.js +53 -2
- package/src/renderer/webgl.js +42 -19
- package/src/vectorStyle/lib/colorConvertions.js +3 -0
- package/src/vectorStyle/lib/getGeometryTypeFromService.js +8 -1
- package/src/vectorStyle/styleList.js +4 -3
- package/test/layer/tileset.test.js +36 -14
- package/test/lib/attributeMapper.test.js +164 -1
- package/test/renderer/webgl.test.js +23 -3
- package/test/vectorStyle/lib/colorConvertions.test.js +30 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,40 @@
|
|
|
3
3
|
|
|
4
4
|
The [Semantic Versioning](https://semver.org/spec/v2.0.0.html) is used.
|
|
5
5
|
|
|
6
|
+
### Unreleased - in development
|
|
7
|
+
## Added
|
|
8
|
+
|
|
9
|
+
## Changed
|
|
10
|
+
|
|
11
|
+
## Deprecated
|
|
12
|
+
|
|
13
|
+
## Removed
|
|
14
|
+
|
|
15
|
+
## Fixed
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
### 2.28.0 - 2023-09-27
|
|
20
|
+
## Added
|
|
21
|
+
- GfiAttributes: GFI Attributes can now be configured as HTML tags, e.g <a>, <img> or <iframe>
|
|
22
|
+
|
|
23
|
+
## Changed
|
|
24
|
+
- The following packages have been updated:
|
|
25
|
+
- dependencies:
|
|
26
|
+
- ol: 7.5.1 to 7.5.2 (This version fix a bug for vectorTiles with declutter: true)
|
|
27
|
+
## Fixed
|
|
28
|
+
- Issue Masterportal #1067 VectorStyle: if there is a ? in the services URL, no further one is added
|
|
29
|
+
- Cesium tileset: set visibility and set opacity was fixed.
|
|
30
|
+
- Webgl: set default style for feature and fix the opacity problem
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
### 2.27.0 - 2023-08-31
|
|
35
|
+
## Changed
|
|
36
|
+
- VectorStyle: 'initializeStyleList' is asynchron, waits for loading finished and returns the loaded styles.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
6
40
|
### 2.26.0 - 2023-08-23
|
|
7
41
|
## Changed
|
|
8
42
|
- The following packages have been updated:
|
|
@@ -12,7 +46,6 @@
|
|
|
12
46
|
---
|
|
13
47
|
|
|
14
48
|
## 2.25.0 - 2023-08-21
|
|
15
|
-
|
|
16
49
|
### Changed
|
|
17
50
|
- WebGL: method "afterLoading" catches MultiPoint geometries and parses them to a single point feature for proper rendering
|
|
18
51
|
- WebGL Render-Pipeline for VectorLayer of type VectorTile can be called using {"renderer": "webgl"} in config.json.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@masterportal/masterportalapi",
|
|
3
3
|
"author": "Implementierungspartnerschaft Masterportal <info@masterportal.org> (https://www.masterportal.org)",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.28.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Basic functions of the Masterportal as api",
|
|
7
7
|
"repository": {
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"core-js": "^3.32.0",
|
|
23
23
|
"dayjs": "^1.11.9",
|
|
24
|
-
"ol": "7.5.
|
|
25
|
-
"olcs": "
|
|
24
|
+
"ol": "7.5.2",
|
|
25
|
+
"olcs": "2.15.0",
|
|
26
26
|
"proj4": "^2.9.0",
|
|
27
27
|
"xml2js": "^0.6.2"
|
|
28
28
|
},
|
package/src/layer/tileset.js
CHANGED
|
@@ -63,7 +63,11 @@ Tileset.prototype.setOpacity = function (opacity) {
|
|
|
63
63
|
color = splitValues.toString();
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
this.tileset.
|
|
66
|
+
this.tileset.then(function (tileset) {
|
|
67
|
+
if (tileset) {
|
|
68
|
+
tileset.style = new Cesium.Cesium3DTileStyle({color});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
67
71
|
};
|
|
68
72
|
|
|
69
73
|
/**
|
|
@@ -80,11 +84,12 @@ Tileset.prototype.setVisible = function (value, map) {
|
|
|
80
84
|
map.getCesiumScene().primitives.add(tileset);
|
|
81
85
|
});
|
|
82
86
|
}
|
|
83
|
-
this.tileset.show = true;
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
this.tileset.show = false;
|
|
87
87
|
}
|
|
88
|
+
this.tileset.then(function (tileset) {
|
|
89
|
+
if (tileset) {
|
|
90
|
+
tileset.show = value;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
88
93
|
}
|
|
89
94
|
};
|
|
90
95
|
|
|
@@ -118,6 +118,29 @@ function getValueFromCondition (key, condition, properties) {
|
|
|
118
118
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Maps the feature properties by the given object. if the value is the wildcard '%value%' then the prepared value is taken.
|
|
123
|
+
* @param {HTML} htmltag The html tag.
|
|
124
|
+
* @param {Object} properties The properties for the htmltag.
|
|
125
|
+
* @param {String} preparedValue The prepared value.
|
|
126
|
+
* @returns {HTML} The html tag with mapped properties.
|
|
127
|
+
*/
|
|
128
|
+
function addPropertiesToHtmlTag (htmltag, properties, preparedValue) {
|
|
129
|
+
const htmltagWithproperties = htmltag;
|
|
130
|
+
|
|
131
|
+
if (properties) {
|
|
132
|
+
Object.keys(properties).forEach(prop => {
|
|
133
|
+
if (properties[prop] === "%value%") {
|
|
134
|
+
htmltagWithproperties.setAttribute(prop, preparedValue);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
htmltagWithproperties.setAttribute(prop, properties[prop]);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return htmltagWithproperties;
|
|
142
|
+
}
|
|
143
|
+
|
|
121
144
|
/**
|
|
122
145
|
* Derives the gfi value if the value is an object.
|
|
123
146
|
* @param {*} key Key of Attribute.
|
|
@@ -127,10 +150,12 @@ function getValueFromCondition (key, condition, properties) {
|
|
|
127
150
|
*/
|
|
128
151
|
function prepareValueFromObject (key, mappingObj, properties) {
|
|
129
152
|
const type = mappingObj?.type ? mappingObj.type : "string",
|
|
130
|
-
condition = mappingObj?.condition ? mappingObj.condition : null
|
|
153
|
+
condition = mappingObj?.condition ? mappingObj.condition : null,
|
|
154
|
+
serializer = new XMLSerializer();
|
|
131
155
|
let preparedValue = prepareValue(properties, key),
|
|
132
156
|
format = mappingObj?.format ? mappingObj.format : "YYYY-MM-DDTHH:mm:ss.SSSZ",
|
|
133
|
-
date
|
|
157
|
+
date,
|
|
158
|
+
htmltag;
|
|
134
159
|
|
|
135
160
|
if (condition) {
|
|
136
161
|
preparedValue = getValueFromCondition(key, condition, properties);
|
|
@@ -172,6 +197,32 @@ function prepareValueFromObject (key, mappingObj, properties) {
|
|
|
172
197
|
preparedValue = getBooleanValue(preparedValue, format);
|
|
173
198
|
break;
|
|
174
199
|
}
|
|
200
|
+
case "html": {
|
|
201
|
+
// create tag
|
|
202
|
+
if (mappingObj?.html?.tag) {
|
|
203
|
+
htmltag = document.createElement(mappingObj?.html?.tag);
|
|
204
|
+
}
|
|
205
|
+
// create innerHTML
|
|
206
|
+
if (mappingObj?.html?.innerHTML === "%value%") {
|
|
207
|
+
htmltag.innerHTML = preparedValue;
|
|
208
|
+
}
|
|
209
|
+
else if (mappingObj?.html?.innerHTML) {
|
|
210
|
+
htmltag.innerHTML = mappingObj?.html?.innerHTML;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
if (htmltag) {
|
|
215
|
+
if (mappingObj?.html?.properties) {
|
|
216
|
+
htmltag = addPropertiesToHtmlTag(htmltag, mappingObj?.html?.properties, preparedValue);
|
|
217
|
+
}
|
|
218
|
+
preparedValue = serializer.serializeToString(htmltag);
|
|
219
|
+
// remove xmlns
|
|
220
|
+
preparedValue = preparedValue.replace(/ xmlns="(.*?)"/g, "");
|
|
221
|
+
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
175
226
|
// default equals to mappingObj.type === "string"
|
|
176
227
|
default: {
|
|
177
228
|
preparedValue = String(preparedValue);
|
package/src/renderer/webgl.js
CHANGED
|
@@ -14,7 +14,7 @@ import {packColor, parseLiteralStyle} from "ol/webgl/styleparser.js";
|
|
|
14
14
|
* @see https://openlayers.org/en/latest/examples/webgl-points-layer.html
|
|
15
15
|
* @private
|
|
16
16
|
*/
|
|
17
|
-
const
|
|
17
|
+
const defaultPointStyle = {
|
|
18
18
|
symbol: {
|
|
19
19
|
symbolType: "circle",
|
|
20
20
|
size: 20,
|
|
@@ -25,6 +25,13 @@ const defaultStyle = {
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
|
|
28
|
+
defaultPolygonStyle = {
|
|
29
|
+
fillColor: "#006688",
|
|
30
|
+
strokeColor: "#006688",
|
|
31
|
+
strokeWidth: 1,
|
|
32
|
+
opacity: 1
|
|
33
|
+
},
|
|
34
|
+
|
|
28
35
|
/** @type {import('ol/style/literal.js').LiteralStyle} */
|
|
29
36
|
style = {
|
|
30
37
|
"stroke-color": ["get", "strokeColor"],
|
|
@@ -32,7 +39,7 @@ const defaultStyle = {
|
|
|
32
39
|
"fill-color": ["get", "fillColor"],
|
|
33
40
|
"opacity": ["get", "opacity", "number"],
|
|
34
41
|
"size": ["get", "circleSize", "number"],
|
|
35
|
-
symbol:
|
|
42
|
+
symbol: defaultPointStyle.symbol
|
|
36
43
|
};
|
|
37
44
|
|
|
38
45
|
/**
|
|
@@ -165,29 +172,36 @@ export function createVectorTileLayerRenderer () {
|
|
|
165
172
|
* @returns {void}
|
|
166
173
|
*/
|
|
167
174
|
export function formatFeatureStyles (feature, styleObject) {
|
|
168
|
-
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
175
|
+
let rule;
|
|
171
176
|
|
|
172
|
-
|
|
173
|
-
|
|
177
|
+
if (styleObject) {
|
|
178
|
+
// extract first matching rule only
|
|
179
|
+
rule = getRulesForFeature(styleObject, feature)[0];
|
|
180
|
+
}
|
|
174
181
|
|
|
175
|
-
|
|
176
|
-
|
|
182
|
+
if (rule?.style) {
|
|
183
|
+
feature.styleRule = rule;
|
|
177
184
|
|
|
178
|
-
|
|
179
|
-
const polygonFillColor = returnColor(rule.style.polygonFillColor, "hex"),
|
|
185
|
+
const polygonFillColor = returnColor(rule.style.polygonFillColor, "rgba"),
|
|
180
186
|
circleFillColor = returnColor(rule.style.circleFillColor, "hex"),
|
|
187
|
+
|
|
181
188
|
fillColor = polygonFillColor ? polygonFillColor : circleFillColor,
|
|
182
189
|
strokeColor = returnColor(rule.style.polygonStrokeColor || rule.style.lineStrokeColor, "hex"),
|
|
183
190
|
strokeWidth = rule.style.polygonStrokeWidth || rule.style.lineStrokeWidth,
|
|
184
191
|
size = rule.style.circleRadius;
|
|
185
192
|
|
|
186
|
-
feature.set("fillColor", fillColor
|
|
187
|
-
feature.set("strokeColor", strokeColor
|
|
188
|
-
feature.set("strokeWidth", strokeWidth
|
|
189
|
-
feature.set("opacity", fillColor ? (rule.style.polygonFillColor || rule.style.circleFillColor)[3] :
|
|
190
|
-
feature.set("circleSize", size
|
|
193
|
+
feature.set("fillColor", fillColor || defaultPolygonStyle.fillColor);
|
|
194
|
+
feature.set("strokeColor", strokeColor || defaultPolygonStyle.strokeColor);
|
|
195
|
+
feature.set("strokeWidth", strokeWidth || defaultPolygonStyle.strokeWidth);
|
|
196
|
+
feature.set("opacity", fillColor ? (rule.style.polygonFillColor || rule.style.circleFillColor)[3] : defaultPolygonStyle.opacity);
|
|
197
|
+
feature.set("circleSize", size || defaultPointStyle.symbol.size);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
feature.set("fillColor", defaultPolygonStyle.fillColor);
|
|
201
|
+
feature.set("strokeColor", defaultPolygonStyle.strokeColor);
|
|
202
|
+
feature.set("strokeWidth", defaultPolygonStyle.strokeWidth);
|
|
203
|
+
feature.set("opacity", defaultPolygonStyle.opacity);
|
|
204
|
+
feature.set("circleSize", defaultPointStyle.symbol.size);
|
|
191
205
|
}
|
|
192
206
|
}
|
|
193
207
|
|
|
@@ -217,7 +231,7 @@ export function formatFeatureData (feature, excludeTypes = ["boolean"]) {
|
|
|
217
231
|
valueIsTrue = typeof feature.get(key) === "string" && feature.get(key).toLowerCase() === "true" ? true : undefined,
|
|
218
232
|
valueIsFalse = typeof feature.get(key) === "string" && feature.get(key).toLowerCase() === "false" ? false : undefined;
|
|
219
233
|
|
|
220
|
-
if (!isNaN(parseFloat(feature.get(key))) && !excludeTypes
|
|
234
|
+
if (!isNaN(parseFloat(feature.get(key))) && !excludeTypes?.includes("number")) {
|
|
221
235
|
feature.set(key, valueAsNumber);
|
|
222
236
|
}
|
|
223
237
|
if (valueIsTrue === true && !excludeTypes.includes("boolean")) {
|
|
@@ -288,14 +302,14 @@ export function createLayer (attrs) {
|
|
|
288
302
|
* If the layer consists only of points, use WebGLPointsLayer
|
|
289
303
|
* For advanced styling options
|
|
290
304
|
* @see https://openlayers.org/en/latest/examples/webgl-points-layer.html
|
|
291
|
-
|
|
305
|
+
*/
|
|
292
306
|
if (attrs.isPointLayer) {
|
|
293
307
|
/**
|
|
294
308
|
* @deprecated
|
|
295
309
|
* @todo will be replaced in the next OL release and incorporated in the WebGLVectorLayerRenderer
|
|
296
310
|
*/
|
|
297
311
|
return new LayerConstructor({
|
|
298
|
-
style: attrs.style ||
|
|
312
|
+
style: attrs.style || defaultPointStyle,
|
|
299
313
|
disableHitDetection: false,
|
|
300
314
|
...options,
|
|
301
315
|
isPointLayer: true
|
|
@@ -323,3 +337,12 @@ export function createLayer (attrs) {
|
|
|
323
337
|
isPointLayer: false
|
|
324
338
|
});
|
|
325
339
|
}
|
|
340
|
+
|
|
341
|
+
export default {
|
|
342
|
+
afterLoading,
|
|
343
|
+
createLayer,
|
|
344
|
+
createVectorLayerRenderer,
|
|
345
|
+
formatFeatureData,
|
|
346
|
+
formatFeatureGeometry,
|
|
347
|
+
formatFeatureStyles
|
|
348
|
+
};
|
|
@@ -90,6 +90,9 @@ export function returnColor (color, dest) {
|
|
|
90
90
|
else if (src === "rgb" && dest === "hex") {
|
|
91
91
|
newColor = rgbToHex(newColor[0], newColor[1], newColor[2]);
|
|
92
92
|
}
|
|
93
|
+
else if (src === "rgb" && dest === "rgba") {
|
|
94
|
+
newColor = "rgba(" + newColor[0] + ", " + newColor[1] + ", " + newColor[2] + ", " + newColor[3] + ")";
|
|
95
|
+
}
|
|
93
96
|
|
|
94
97
|
newColor = dest === "rgb" ? normalizeRgbColor(newColor) : newColor;
|
|
95
98
|
|
|
@@ -99,7 +99,14 @@ function getGeometryTypeFromWFS (rules, wfsURL, version, featureType, styleGeome
|
|
|
99
99
|
"VERSION": version,
|
|
100
100
|
"REQUEST": "DescribeFeatureType"
|
|
101
101
|
};
|
|
102
|
-
let url = wfsURL
|
|
102
|
+
let url = wfsURL;
|
|
103
|
+
|
|
104
|
+
if (url && url.includes("?")) {
|
|
105
|
+
url += "&";
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
url += "?";
|
|
109
|
+
}
|
|
103
110
|
|
|
104
111
|
Object.keys(params).forEach(key => {
|
|
105
112
|
url += key + "=" + params[key] + "&";
|
|
@@ -214,9 +214,9 @@ function parseStyles (data) {
|
|
|
214
214
|
* @param {array} [layers] - an array with the configured layers
|
|
215
215
|
* @param {array} [tools] - an array with the configured tools
|
|
216
216
|
* @param {function} [callback] - called with services after loaded; called with false and error on error
|
|
217
|
-
* @returns {
|
|
217
|
+
* @returns {array} the list of styles
|
|
218
218
|
*/
|
|
219
|
-
function initializeStyleList (styleGetters, Config, layers, tools, callback) {
|
|
219
|
+
async function initializeStyleList (styleGetters, Config, layers, tools, callback) {
|
|
220
220
|
configuredLayers = layers;
|
|
221
221
|
configuredTools = tools;
|
|
222
222
|
|
|
@@ -230,7 +230,7 @@ function initializeStyleList (styleGetters, Config, layers, tools, callback) {
|
|
|
230
230
|
styleConf = Config.styleConf;
|
|
231
231
|
featureViaUrlLayers = Config.featureViaURL?.layers;
|
|
232
232
|
|
|
233
|
-
fetch(styleConf)
|
|
233
|
+
await fetch(styleConf)
|
|
234
234
|
.then(response => response.json())
|
|
235
235
|
.then(data => {
|
|
236
236
|
styleList = parseStyles(data);
|
|
@@ -239,6 +239,7 @@ function initializeStyleList (styleGetters, Config, layers, tools, callback) {
|
|
|
239
239
|
console.error(error);
|
|
240
240
|
callback(false, true);
|
|
241
241
|
});
|
|
242
|
+
return styleList;
|
|
242
243
|
}
|
|
243
244
|
|
|
244
245
|
/**
|
|
@@ -75,40 +75,62 @@ describe("tileset.js", function () {
|
|
|
75
75
|
});
|
|
76
76
|
});
|
|
77
77
|
describe("setOpacity", function () {
|
|
78
|
-
it("calls setOpacity sets opacity to terrain style", function () {
|
|
78
|
+
it("calls setOpacity sets opacity to terrain style", function (done) {
|
|
79
79
|
const layer = new Tileset(attr, map);
|
|
80
80
|
|
|
81
81
|
layer.setOpacity(0.5);
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
layer.tileset.then(function (tileset) {
|
|
84
|
+
if (tileset) {
|
|
85
|
+
expect(tileset.style).toEqual({color: "rgba(255, 255, 255, 0.5)"});
|
|
86
|
+
done();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
84
89
|
});
|
|
85
90
|
});
|
|
86
91
|
describe("setVisible", function () {
|
|
87
|
-
it("calls setVisible without map shall not fail", function () {
|
|
92
|
+
it("calls setVisible without map shall not fail", function (done) {
|
|
88
93
|
const layer = new Tileset(attr, map);
|
|
89
94
|
|
|
90
95
|
expect(layer.tileset.show).toEqual(undefined);
|
|
91
96
|
layer.setVisible(true);
|
|
92
97
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
layer.tileset.then(function (tileset) {
|
|
99
|
+
if (tileset) {
|
|
100
|
+
checkAttributes(layer, attr);
|
|
101
|
+
expect(layer.tileset.show).toEqual(undefined);
|
|
102
|
+
expect(cesium3DTilesetSpy).toHaveBeenCalledTimes(1);
|
|
103
|
+
done();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
96
106
|
});
|
|
97
|
-
it("sets the tileset layer visible", function () {
|
|
107
|
+
it("sets the tileset layer visible", function (done) {
|
|
98
108
|
const layer = new Tileset(attr, map);
|
|
99
109
|
|
|
100
110
|
layer.setVisible(true, map);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
111
|
+
|
|
112
|
+
layer.tileset.then(function (tileset) {
|
|
113
|
+
if (tileset) {
|
|
114
|
+
checkAttributes(layer, attr);
|
|
115
|
+
expect(tileset.show).toEqual(true);
|
|
116
|
+
expect(cesium3DTilesetSpy).toHaveBeenCalledTimes(1);
|
|
117
|
+
done();
|
|
118
|
+
}
|
|
119
|
+
});
|
|
104
120
|
});
|
|
105
|
-
it("sets the tileset layer not visible", function () {
|
|
121
|
+
it("sets the tileset layer not visible", function (done) {
|
|
106
122
|
const layer = new Tileset(attr, map);
|
|
107
123
|
|
|
108
124
|
layer.setVisible(false, map);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
125
|
+
|
|
126
|
+
layer.tileset.then(function (tileset) {
|
|
127
|
+
if (tileset) {
|
|
128
|
+
checkAttributes(layer, attr);
|
|
129
|
+
expect(tileset.show).toEqual(false);
|
|
130
|
+
expect(cesium3DTilesetSpy).toHaveBeenCalledTimes(1);
|
|
131
|
+
done();
|
|
132
|
+
}
|
|
133
|
+
});
|
|
112
134
|
});
|
|
113
135
|
});
|
|
114
136
|
describe("get", function () {
|
|
@@ -21,7 +21,8 @@ const props = {
|
|
|
21
21
|
}
|
|
22
22
|
]
|
|
23
23
|
}
|
|
24
|
-
]
|
|
24
|
+
],
|
|
25
|
+
random_url: "http://random.url.de"
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
describe("src/utils/attributeMapper.js", () => {
|
|
@@ -272,6 +273,168 @@ describe("src/utils/attributeMapper.js", () => {
|
|
|
272
273
|
int: "12345"
|
|
273
274
|
});
|
|
274
275
|
});
|
|
276
|
+
it("should map object with mapping object and type:html", () => {
|
|
277
|
+
const mappingObj = {
|
|
278
|
+
random_url: {
|
|
279
|
+
name: "url",
|
|
280
|
+
type: "html"
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
expect(mapAttributes(props, mappingObj)).toEqual({
|
|
285
|
+
url: "http://random.url.de"
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
it("should map object with mapping object and type:html and tag a", () => {
|
|
289
|
+
const mappingObj = {
|
|
290
|
+
random_url: {
|
|
291
|
+
name: "url",
|
|
292
|
+
type: "html",
|
|
293
|
+
html: {
|
|
294
|
+
tag: "a",
|
|
295
|
+
properties: {
|
|
296
|
+
href: "%value%"
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
expect(mapAttributes(props, mappingObj)).toEqual({
|
|
303
|
+
url: "<a href=\"http://random.url.de\"></a>"
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
it("should map object with mapping object and type:html and tag a", () => {
|
|
307
|
+
const mappingObj = {
|
|
308
|
+
random_url: {
|
|
309
|
+
name: "url",
|
|
310
|
+
type: "html",
|
|
311
|
+
html: {
|
|
312
|
+
tag: "a",
|
|
313
|
+
innerHTML: "%value%",
|
|
314
|
+
properties: {
|
|
315
|
+
href: "%value%"
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
expect(mapAttributes(props, mappingObj)).toEqual({
|
|
322
|
+
url: "<a href=\"http://random.url.de\">http://random.url.de</a>"
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
it("should map object with mapping object and type:html and tag a without innerHTML and properties", () => {
|
|
326
|
+
const mappingObj = {
|
|
327
|
+
random_url: {
|
|
328
|
+
name: "url",
|
|
329
|
+
type: "html",
|
|
330
|
+
html: {
|
|
331
|
+
tag: "a"
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
expect(mapAttributes(props, mappingObj)).toEqual({
|
|
337
|
+
url: "<a></a>"
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
it("should map object with mapping object and type:html and tag a and innerHTML", () => {
|
|
341
|
+
const mappingObj = {
|
|
342
|
+
random_url: {
|
|
343
|
+
name: "url",
|
|
344
|
+
type: "html",
|
|
345
|
+
html: {
|
|
346
|
+
tag: "a",
|
|
347
|
+
innerHTML: "myURL",
|
|
348
|
+
properties: {
|
|
349
|
+
href: "%value%"
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
expect(mapAttributes(props, mappingObj)).toEqual({
|
|
356
|
+
url: "<a href=\"http://random.url.de\">myURL</a>"
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
it("should map object with mapping object and type:html and tag a and properties", () => {
|
|
360
|
+
const mappingObj = {
|
|
361
|
+
random_url: {
|
|
362
|
+
name: "url",
|
|
363
|
+
type: "html",
|
|
364
|
+
html: {
|
|
365
|
+
tag: "a",
|
|
366
|
+
innerHTML: "myURL",
|
|
367
|
+
properties: {
|
|
368
|
+
href: "%value%",
|
|
369
|
+
target: "_blank"
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
expect(mapAttributes(props, mappingObj)).toEqual({
|
|
376
|
+
url: "<a href=\"http://random.url.de\" target=\"_blank\">myURL</a>"
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
it("should map object with mapping object and type:html and tag a and properties", () => {
|
|
380
|
+
const mappingObj = {
|
|
381
|
+
random_url: {
|
|
382
|
+
name: "url",
|
|
383
|
+
type: "html",
|
|
384
|
+
html: {
|
|
385
|
+
tag: "a",
|
|
386
|
+
innerHTML: "%value%",
|
|
387
|
+
properties: {
|
|
388
|
+
href: "%value%",
|
|
389
|
+
target: "_blank"
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
expect(mapAttributes(props, mappingObj)).toEqual({
|
|
396
|
+
url: "<a href=\"http://random.url.de\" target=\"_blank\">http://random.url.de</a>"
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
it("should map object with mapping object and type:html and tag img and properties", () => {
|
|
400
|
+
const mappingObj = {
|
|
401
|
+
random_url: {
|
|
402
|
+
name: "url",
|
|
403
|
+
type: "html",
|
|
404
|
+
html: {
|
|
405
|
+
tag: "img",
|
|
406
|
+
properties: {
|
|
407
|
+
src: "%value%",
|
|
408
|
+
style: "width:150px"
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
expect(mapAttributes(props, mappingObj)).toEqual({
|
|
415
|
+
url: "<img src=\"http://random.url.de\" style=\"width:150px\" />"
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
it("should map object with mapping object and type:html and tag iframe and properties", () => {
|
|
419
|
+
const mappingObj = {
|
|
420
|
+
random_url: {
|
|
421
|
+
name: "url",
|
|
422
|
+
type: "html",
|
|
423
|
+
html: {
|
|
424
|
+
tag: "iframe",
|
|
425
|
+
properties: {
|
|
426
|
+
src: "%value%",
|
|
427
|
+
foo: "bar",
|
|
428
|
+
bar: "foo"
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
expect(mapAttributes(props, mappingObj)).toEqual({
|
|
435
|
+
url: "<iframe src=\"http://random.url.de\" foo=\"bar\" bar=\"foo\"></iframe>"
|
|
436
|
+
});
|
|
437
|
+
});
|
|
275
438
|
});
|
|
276
439
|
describe("isObjectPath", () => {
|
|
277
440
|
it("should return true for \"@foobar\"", () => {
|
|
@@ -18,7 +18,7 @@ jest.mock("../../src/vectorStyle/styleList.js", () => {
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
describe("webgl.js", () => {
|
|
21
|
-
let layerParams, layerParamsVectorTile, rawLayer, rawLayerVectorTile, styleRule, styleObject;
|
|
21
|
+
let layerParams, layerParamsVectorTile, rawLayer, rawLayerVectorTile, styleRule, styleObject, defaultStyle;
|
|
22
22
|
|
|
23
23
|
beforeEach(() => {
|
|
24
24
|
layerParams = {
|
|
@@ -68,6 +68,13 @@ describe("webgl.js", () => {
|
|
|
68
68
|
styleObject = {
|
|
69
69
|
rules: [styleRule]
|
|
70
70
|
};
|
|
71
|
+
defaultStyle = {
|
|
72
|
+
fillColor: "#006688",
|
|
73
|
+
strokeColor: "#006688",
|
|
74
|
+
strokeWidth: 1,
|
|
75
|
+
opacity: 1,
|
|
76
|
+
size: 20
|
|
77
|
+
};
|
|
71
78
|
});
|
|
72
79
|
|
|
73
80
|
describe("createLayer", () => {
|
|
@@ -156,7 +163,7 @@ describe("webgl.js", () => {
|
|
|
156
163
|
it("set the necessary style attributes on the feature for literal style syntax", () => {
|
|
157
164
|
$feature = feature.clone();
|
|
158
165
|
webgl.formatFeatureStyles($feature, styleObject);
|
|
159
|
-
expect($feature.get("fillColor")).toEqual(returnColor(styleRule.style.polygonFillColor, "
|
|
166
|
+
expect($feature.get("fillColor")).toEqual(returnColor(styleRule.style.polygonFillColor, "rgba"));
|
|
160
167
|
expect($feature.get("strokeColor")).toEqual(returnColor(styleRule.style.polygonStrokeColor, "hex"));
|
|
161
168
|
expect($feature.get("strokeWidth")).toEqual(styleRule.style.polygonStrokeWidth);
|
|
162
169
|
expect($feature.get("opacity")).toEqual(styleRule.style.polygonFillColor[3]);
|
|
@@ -173,6 +180,19 @@ describe("webgl.js", () => {
|
|
|
173
180
|
expect($feature.get("opacity")).toEqual(styleRule.style.circleFillColor[3]);
|
|
174
181
|
expect($feature.get("circleSize")).toEqual(styleRule.style.circleRadius);
|
|
175
182
|
});
|
|
183
|
+
it("set the necessary style attributes on the feature with default style", () => {
|
|
184
|
+
$feature = feature.clone();
|
|
185
|
+
styleRule = null;
|
|
186
|
+
styleObject = {
|
|
187
|
+
rules: [styleRule]
|
|
188
|
+
};
|
|
189
|
+
webgl.formatFeatureStyles($feature, styleObject);
|
|
190
|
+
expect($feature.get("fillColor")).toEqual(defaultStyle.fillColor);
|
|
191
|
+
expect($feature.get("strokeColor")).toEqual(defaultStyle.strokeColor);
|
|
192
|
+
expect($feature.get("strokeWidth")).toEqual(defaultStyle.strokeWidth);
|
|
193
|
+
expect($feature.get("opacity")).toEqual(defaultStyle.opacity);
|
|
194
|
+
expect($feature.get("circleSize")).toEqual(defaultStyle.size);
|
|
195
|
+
});
|
|
176
196
|
});
|
|
177
197
|
});
|
|
178
|
-
});
|
|
198
|
+
});
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
normalizeRgbColor,
|
|
3
|
+
componentToHex,
|
|
4
|
+
rgbToHex,
|
|
5
|
+
hexToRgb,
|
|
6
|
+
returnColor
|
|
7
|
+
} from "../../../src/vectorStyle/lib/colorConvertions";
|
|
2
8
|
|
|
3
9
|
describe("normalizeRgbColor", function () {
|
|
4
10
|
it("should be extend the given array with length 3 by value 1", function () {
|
|
@@ -39,4 +45,26 @@ describe("hexToRgb", function () {
|
|
|
39
45
|
it("should return null", function () {
|
|
40
46
|
expect(hexToRgb("")).toEqual(null);
|
|
41
47
|
});
|
|
42
|
-
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("returnColor", function () {
|
|
51
|
+
it("should return the parsed rgb value", function () {
|
|
52
|
+
expect(returnColor([255, 0, 0])).toEqual([255, 0, 0]);
|
|
53
|
+
});
|
|
54
|
+
it("should return the parsed rgb value with hex format", function () {
|
|
55
|
+
expect(returnColor([255, 0, 0, 0.5], "hex")).toEqual("#ff0000");
|
|
56
|
+
});
|
|
57
|
+
it("should return the parsed rgb value with rgba format", function () {
|
|
58
|
+
expect(returnColor([255, 0, 0, 0.5], "rgba")).toEqual("rgba(255, 0, 0, 0.5)");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("should return the parsed rgb value with hex format", function () {
|
|
62
|
+
expect(returnColor("#ff0000")).toEqual("#ff0000");
|
|
63
|
+
});
|
|
64
|
+
it("should return the parsed rgb value with array in string", function () {
|
|
65
|
+
expect(returnColor("[255, 0, 0, 0.5]")).toEqual(["255", "0", "0", "0.5"]);
|
|
66
|
+
});
|
|
67
|
+
it("should return the parsed rgb value with array in string and hex format as destination format", function () {
|
|
68
|
+
expect(returnColor("[255, 0, 0, 0.5]", "hex")).toEqual("#ff0000");
|
|
69
|
+
});
|
|
70
|
+
});
|