@masterportal/masterportalapi 2.21.0 → 2.23.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 CHANGED
@@ -3,13 +3,33 @@
3
3
 
4
4
  The [Semantic Versioning](https://semver.org/spec/v2.0.0.html) is used.
5
5
 
6
- ## 2.21.0 - 2023-07-20
6
+ ## 2.23.0 - 2023-08-02
7
+ ### Added
8
+ - VectorStyle: Add Styling rules for Geoemtries of type `Circle`.
9
+ - Add Styling and zIndex to draw interactions and improve the draw behavior.
10
+ - Add select and modify interactions for editing ol features.
11
+
12
+ ### Fixed
13
+ - The legend for wfs is now created again via the Describefeaturetype.
14
+
15
+ ---
16
+
17
+ ## 2.22.0 - 2023-07-25
7
18
  ### Added
8
19
  - VectorStyle: Add Styling rules for Geoemtries of type `Circle`.
9
20
  - Add Styling and zIndex to draw interactions and improve the draw behavior.
10
21
 
11
22
  ### Changed
12
23
  - Changed peerDependency from cesium 1.106.0 to @cesium/engine 2.4.1.
24
+ - WFS:
25
+ - Migrated writeTransaction and sendTransaction from masterportal the masterportalAPI.
26
+ - Exports in src/layer/wfs.js changed to export default {} to provide ES-Syntax.
27
+ ### Deprecated
28
+
29
+ ### Removed
30
+
31
+ ### Fixed
32
+ - WFS: fixed a bug that prevented parsing GeoServer responses.
13
33
 
14
34
  ---
15
35
 
package/package.json CHANGED
@@ -1,64 +1,65 @@
1
- {
2
- "name": "@masterportal/masterportalapi",
3
- "author": "Implementierungspartnerschaft Masterportal <info@masterportal.org> (https://www.masterportal.org)",
4
- "version": "2.21.0",
5
- "license": "MIT",
6
- "description": "Basic functions of the Masterportal as api",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://bitbucket.org/geowerkstatt-hamburg/masterportalapi.git"
10
- },
11
- "main": "src/index.js",
12
- "scripts": {
13
- "test": "jest .test.js --config ./jest.config.js --collectCoverage",
14
- "test:trace": "node --trace-warnings node_modules/jest/bin/jest.js .test.js --config ./jest.config.js",
15
- "test:watch": "jest .test.js --config ./jest.config.js --watch",
16
- "example": "parcel example/index.html",
17
- "generate-jsdoc": "jsdoc ./src -r -d ./docs/ -R ./README.md -c jsdoc.json",
18
- "prePushHook": "eslint --max-warnings 0 \"./**/*.js\" && npm run test",
19
- "prepare": "husky install"
20
- },
21
- "dependencies": {
22
- "core-js": "^3.30.2",
23
- "dayjs": "^1.11.7",
24
- "ol": "7.4.0",
25
- "olcs": "^2.14.0",
26
- "proj4": "^2.9.0",
27
- "xml2js": "^0.5.0"
28
- },
29
- "devDependencies": {
30
- "@babel/core": "^7.21.8",
31
- "@babel/plugin-transform-modules-commonjs": "^7.21.5",
32
- "@parcel/transformer-sass": "^2.8.3",
33
- "buffer": "^5.7.1",
34
- "canvas": "^2.11.2",
35
- "eslint": "^8.40.0",
36
- "events": "^3.3.0",
37
- "husky": "^8.0.3",
38
- "jest": "^29.5.0",
39
- "jest-canvas-mock": "^2.5.0",
40
- "jest-environment-jsdom": "^29.5.0",
41
- "jsdoc": "^4.0.2",
42
- "parcel": "^2.8.3",
43
- "process": "^0.11.10",
44
- "sass": "^1.62.1",
45
- "stream-browserify": "^3.0.0",
46
- "timers-browserify": "^2.0.12",
47
- "use-resize-observer": "^9.1.0"
48
- },
49
- "peerDependencies": {
50
- "@cesium/engine": "^2.4.1"
51
- },
52
- "engines": {
53
- "node": "^16.13.2 || ^18.12.0",
54
- "npm": "^8.1.2 || ^9.3.1"
55
- },
56
- "homepage": "https://bitbucket.org/geowerkstatt-hamburg/masterportalapi#readme",
57
- "directories": {
58
- "example": "example",
59
- "test": "test"
60
- },
61
- "bugs": {
62
- "url": "https://bitbucket.org/geowerkstatt-hamburg/masterportalapi/issues"
63
- }
64
- }
1
+ {
2
+ "name": "@masterportal/masterportalapi",
3
+ "author": "Implementierungspartnerschaft Masterportal <info@masterportal.org> (https://www.masterportal.org)",
4
+ "version": "2.23.0",
5
+ "license": "MIT",
6
+ "description": "Basic functions of the Masterportal as api",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://bitbucket.org/geowerkstatt-hamburg/masterportalapi.git"
10
+ },
11
+ "main": "src/index.js",
12
+ "scripts": {
13
+ "test": "jest .test.js --config ./jest.config.js --collectCoverage",
14
+ "test:trace": "node --trace-warnings node_modules/jest/bin/jest.js .test.js --config ./jest.config.js",
15
+ "test:watch": "jest .test.js --config ./jest.config.js --watch",
16
+ "example": "parcel example/index.html",
17
+ "generate-jsdoc": "jsdoc ./src -r -d ./docs/ -R ./README.md -c jsdoc.json",
18
+ "prePushHook": "eslint --max-warnings 0 \"./**/*.js\" && npm run test",
19
+ "prepare": "husky install"
20
+ },
21
+ "dependencies": {
22
+ "core-js": "^3.30.2",
23
+ "dayjs": "^1.11.7",
24
+ "ol": "7.4.0",
25
+ "olcs": "^2.14.0",
26
+ "proj4": "^2.9.0",
27
+ "xml2js": "^0.5.0"
28
+ },
29
+ "devDependencies": {
30
+ "@babel/core": "^7.21.8",
31
+ "@babel/plugin-transform-modules-commonjs": "^7.21.5",
32
+ "@parcel/transformer-sass": "^2.8.3",
33
+ "buffer": "^5.7.1",
34
+ "canvas": "^2.11.2",
35
+ "eslint": "^8.40.0",
36
+ "events": "^3.3.0",
37
+ "husky": "^8.0.3",
38
+ "jest": "^29.5.0",
39
+ "jest-canvas-mock": "^2.5.0",
40
+ "jest-environment-jsdom": "^29.5.0",
41
+ "jest-fetch-mock": "^3.0.3",
42
+ "jsdoc": "^4.0.2",
43
+ "parcel": "^2.8.3",
44
+ "process": "^0.11.10",
45
+ "sass": "^1.62.1",
46
+ "stream-browserify": "^3.0.0",
47
+ "timers-browserify": "^2.0.12",
48
+ "use-resize-observer": "^9.1.0"
49
+ },
50
+ "peerDependencies": {
51
+ "@cesium/engine": "^2.4.1"
52
+ },
53
+ "engines": {
54
+ "node": "^16.13.2 || ^18.12.0",
55
+ "npm": "^8.1.2 || ^9.3.1"
56
+ },
57
+ "homepage": "https://bitbucket.org/geowerkstatt-hamburg/masterportalapi#readme",
58
+ "directories": {
59
+ "example": "example",
60
+ "test": "test"
61
+ },
62
+ "bugs": {
63
+ "url": "https://bitbucket.org/geowerkstatt-hamburg/masterportalapi/issues"
64
+ }
65
+ }
package/src/index.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import {createMapView} from "./maps/mapView";
2
2
  import crs from "./crs";
3
- import drawInteractions from "./maps/interactions/drawInteractions";
4
3
  import rawLayerList from "./rawLayerList";
5
4
  import * as wms from "./layer/wms";
6
5
  import wmts from "./layer/wmts";
7
- import * as wfs from "./layer/wfs";
6
+ import wfs from "./layer/wfs";
8
7
  import * as geojson from "./layer/geojson";
9
8
  import * as vectorBase from "./layer/vectorBase";
10
9
  import * as vectorTile from "./layer/vectorTile";
@@ -37,6 +36,5 @@ export {
37
36
  ping,
38
37
  search,
39
38
  crs,
40
- drawInteractions,
41
39
  webgl
42
40
  };
package/src/layer/wfs.js CHANGED
@@ -154,7 +154,7 @@ function createUrl (rawLayer, version, projection, bboxParam) {
154
154
  * {@link https://openlayers.org/en/latest/apidoc/module-ol_source_Vector-VectorSource.html failure/success see}
155
155
  * @returns {(ol.source.VectorSource|ol.source.Cluster)} VectorSource or Cluster, depending on whether clusterDistance is set.
156
156
  */
157
- export function createLayerSource (rawLayer, options = {}) {
157
+ function createLayerSource (rawLayer, options = {}) {
158
158
  if (!options.loadingStrategy) {
159
159
  options.loadingStrategy = bbox;
160
160
  }
@@ -175,10 +175,15 @@ export function createLayerSource (rawLayer, options = {}) {
175
175
  }
176
176
  else {
177
177
  const bboxParam = options.loadingStrategy === bbox ? `&bbox=${extent.join(",")},${projection.getCode()}` : "";
178
- let url = createUrl(rawLayer, version, projection, bboxParam);
178
+ let url = createUrl(rawLayer, version, projection, bboxParam),
179
+ params = {};
179
180
 
180
181
  if (options.loadingParams) {
181
182
  for (const key in options.loadingParams) {
183
+ if (key === "xhrParameters") {
184
+ params = options.loadingParams.xhrParameters;
185
+ continue;
186
+ }
182
187
  const option = Array.isArray(options.loadingParams[key]) ? options.loadingParams[key].join(",") : options.loadingParams[key];
183
188
 
184
189
  if (option !== undefined && key === "bbox") {
@@ -189,7 +194,7 @@ export function createLayerSource (rawLayer, options = {}) {
189
194
  }
190
195
  }
191
196
  }
192
- loadWFS(url, {}, source, {onErrorFn: onError, success, failure}, options);
197
+ loadWFS(url, params, source, {onErrorFn: onError, success, failure}, options);
193
198
  }
194
199
  }
195
200
  format.featureType = rawLayer.featureType;
@@ -224,7 +229,7 @@ export function createLayerSource (rawLayer, options = {}) {
224
229
  * @param {options} [optionalParams.options] - additional options
225
230
  * @returns {ol.Layer} Layer that can be added to map.
226
231
  */
227
- export function createLayer (rawLayer = {}, {layerParams = {}, options = {}} = {}) {
232
+ function createLayer (rawLayer = {}, {layerParams = {}, options = {}} = {}) {
228
233
  let layer, source;
229
234
 
230
235
  // use WebGL render pipeline, if specified
@@ -260,13 +265,227 @@ export function createLayer (rawLayer = {}, {layerParams = {}, options = {}} = {
260
265
  return layer;
261
266
  }
262
267
 
268
+ /**
269
+ * Writes a wfs transaction including the given feature for given layer
270
+ * inserting, updated or deleting the feature depending on the given selectedInteraction.
271
+ *
272
+ * @param {ol/Feature} feature Feature to be inserted, updated or deleted.
273
+ * @param {Object} transactionOptions Information about the layer to be manipulated.
274
+ * @param {string} transactionMethod Which transaction to perform. Possible values are: "insert"|"delete"|"selectedUpdate"
275
+ * @param {string} srsName EPSG code currently used by the map.
276
+ * @returns {string} WFS Transaction as an XML Node as String.
277
+ */
278
+
279
+ function writeTransactionBody (feature, transactionOptions, transactionMethod, version = "1.1.0") {
280
+ const transactionPosition = {
281
+ insert: 0,
282
+ selectedUpdate: 1,
283
+ delete: 2
284
+ },
285
+ transaction = [[], [], []];
286
+
287
+ if (transactionMethod !== "insert" && transactionMethod !== "delete" && transactionMethod !== "selectedUpdate") {
288
+ throw new Error("transactionMethod has to be \"insert\", \"selectedUpdate\" or \"delete\".");
289
+ }
290
+
291
+ transaction[transactionPosition[transactionMethod]].push(feature);
292
+ return new XMLSerializer()
293
+ .serializeToString(new WFS({version})
294
+ .writeTransaction(...transaction, transactionOptions));
295
+ }
296
+
297
+ /**
298
+ * Checks if it is an unknown or special error and returns the code and the error message
299
+ *
300
+ * @param {Object} xmlDocument with the error
301
+ * @returns {Object} the code and the specific or unknown error looking like this {code, message}
302
+ */
303
+ function getExceptionFromTransactionResponse (xmlDocument) {
304
+ const response = {code: null, message: "genericFailedTransaction"},
305
+ exception = xmlDocument.getElementsByTagName(`${xmlDocument.getElementsByTagName("Exception").length === 0 ? "ows:" : ""}Exception`)[0],
306
+ exceptionText = exception.getElementsByTagName(`${xmlDocument.getElementsByTagName("ExceptionText").length === 0 ? "ows:" : ""}ExceptionText`)[0];
307
+
308
+ if (exceptionText !== undefined) {
309
+ response.message = exceptionText.textContent;
310
+ console.error("WfsTransaction: An error occurred when sending the transaction to the service.", exceptionText.textContent);
311
+ }
312
+ else {
313
+ response.message = "WfsTransaction: An unkown error occurred when sending the transaction to the service.";
314
+ console.error(response.message);
315
+ }
316
+ if (exception?.attributes.getNamedItem("code") || exception?.attributes.getNamedItem("exceptionCode")) {
317
+ response.code = exception.attributes.getNamedItem(`${exception?.attributes.getNamedItem("code") ? "c" : "exceptionC"}ode`).textContent;
318
+ }
319
+
320
+ return response;
321
+ }
322
+
323
+
324
+ /**
325
+ * Sends a transaction to the service and returns the feature.
326
+ *
327
+ * @param {string} srsName of the coordinate reference system
328
+ * @param {ol/Feature} feature Feature to by inserted / updated / deleted.
329
+ * @param {string} url of the wfs-t service
330
+ * @param {Object} layer the configured representation of the layer in the Masterportal
331
+ * @param {string} transactionMethod which transaction to perform. Possible values are: "insert"|"delete"|"selectedUpdate"
332
+ * @returns {ol/Feature} the given feature
333
+ * @throws {Error} error if occurs
334
+ */
335
+ async function sendTransaction (srsName, feature, url, layer, transactionMethod) {
336
+ let exception,
337
+ response,
338
+ xmlDocument = null,
339
+ transactionSummary = null,
340
+ data = null;
341
+
342
+ const {featureNS, featurePrefix, featureType, version} = layer;
343
+
344
+ try {
345
+ response = await fetch(url, {
346
+ method: "POST",
347
+ headers: {"Content-Type": "text/xml"},
348
+ credentials: layer.isSecured ? "include" : "omit",
349
+ body: writeTransactionBody(feature,
350
+ {featureNS, featurePrefix, featureType, version, srsName},
351
+ transactionMethod,
352
+ version),
353
+ responseType: "text"
354
+ });
355
+
356
+ data = await response.text();
357
+
358
+ xmlDocument = new DOMParser().parseFromString(data, "text/xml");
359
+ transactionSummary = xmlDocument.getElementsByTagName("wfs:TransactionSummary");
360
+
361
+ // NOTE: WFS-T services respond errors with the transaction as an XML response, even though it's the http code indicates different...
362
+ if (transactionSummary.length === 0) {
363
+ exception = getExceptionFromTransactionResponse(xmlDocument);
364
+ throw new Error(exception.code ? exception.code + ": " + exception.message : exception.message);
365
+ }
366
+ }
367
+ catch (e) {
368
+ console.error(e);
369
+ throw e;
370
+ }
371
+
372
+ return feature;
373
+ }
374
+
375
+ /**
376
+ * Parses the response of a DescribeFeatureType request
377
+ * and prepares its values for later use as an input value for the user.
378
+ *
379
+ * @param {string} responseData XML response data
380
+ * @param {string} featureType Name of the feature type of the service.
381
+ * @returns {Array} If an <element> with a name of the featureType is present, an array of prepared feature properties; else an empty Array.
382
+ */
383
+ function parseDescribeFeatureTypeResponse (responseData, featureType) {
384
+
385
+ const parsedResponse = new DOMParser().parseFromString(responseData, "application/xml");
386
+
387
+ let prefix = "",
388
+ foundElement = null;
389
+
390
+ if (parsedResponse.getElementsByTagName("xsd:element").length > 0) {
391
+ prefix = "xsd:";
392
+ }
393
+ else if (parsedResponse.getElementsByTagName("xs:element").length > 0) {
394
+ prefix = "xs";
395
+ }
396
+
397
+ // Check if featureType applies to the response
398
+ foundElement = Object.values(parsedResponse.getElementsByTagName(prefix + "element")).find(element => element.getAttribute("name") === featureType);
399
+
400
+ if (foundElement) {
401
+ let sequenceElements;
402
+
403
+ if (foundElement.hasChildNodes()) {
404
+ sequenceElements = Object.values(foundElement.getElementsByTagName(prefix + "sequence"));
405
+ }
406
+ else {
407
+ sequenceElements = Object.values(parsedResponse.getElementsByTagName(prefix + "sequence"));
408
+ }
409
+
410
+ const elements = [];
411
+
412
+ sequenceElements.forEach(sequenceElement => {
413
+ elements.push(...Object.values(sequenceElement.getElementsByTagName(prefix + "element")));
414
+ });
415
+
416
+ return elements.map(el => Object.values(el.attributes).reduce((obj, att) => {
417
+ if (att.localName === "minOccurs") {
418
+ obj.required = att.value === "1";
419
+ }
420
+ else if (att.localName === "type") {
421
+ if (att.value.trim().startsWith("gml")) {
422
+ obj.type = "geometry";
423
+ }
424
+ else {
425
+ let value = att.value;
426
+
427
+ if (prefix.length > 0) {
428
+ value = value.replace(prefix, "");
429
+ }
430
+
431
+ switch (value) {
432
+ case "long":
433
+ obj.type = "integer";
434
+ break;
435
+ default:
436
+ obj.type = value;
437
+ }
438
+ }
439
+ }
440
+ else if (att.localName === "name") {
441
+ obj.label = obj.key = att.value;
442
+ }
443
+ return obj;
444
+ }, {
445
+ label: "",
446
+ key: "",
447
+ value: null,
448
+ type: "string",
449
+ required: false
450
+ }));
451
+ }
452
+ return [];
453
+ }
454
+
455
+ /**
456
+ * Requests the possible properties of a feature and further values;
457
+ * for more {@see FeatureProperty}.
458
+ *
459
+ * @param {string} url from the WFS-T
460
+ * @param {string} version of the WFS-T
461
+ * @param {string} featureType Name of the FeatureType according to the capabilities document
462
+ * @param {boolean} isSecured Whether the layer is secured by BasicAuth and should include or omit the credentials prompt
463
+ * @returns {Promise<Array>} If the request is successful, an array of prepared feature properties.
464
+ */
465
+ async function receivePossibleProperties (url, version, featureType, isSecured) {
466
+ const baseUrl = `${url}?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=${version}&TYPENAME=${featureType}`;
467
+ let response;
468
+
469
+ try {
470
+ response = await fetch(baseUrl, {
471
+ responseType: "text/xml",
472
+ credentials: isSecured ? "include" : "omit"
473
+ });
474
+ return parseDescribeFeatureTypeResponse(await response.text(), featureType);
475
+ }
476
+ catch (e) {
477
+ console.error(e);
478
+ throw e;
479
+ }
480
+ }
481
+
263
482
  /**
264
483
  * Load the features manually.
265
484
  * @param {Object} layerAttributes raw layer attributes.
266
485
  * @param {module:ol/vector/Source} layerSource - the source of the layer
267
486
  * @returns {void}
268
487
  */
269
- export function loadFeaturesManually (layerAttributes, layerSource) {
488
+ function loadFeaturesManually (layerAttributes, layerSource) {
270
489
  const getUrl = createUrl(layerAttributes, layerAttributes.version, {getCode: () => layerAttributes.crs}, "");
271
490
 
272
491
  fetch(getUrl, layerSource)
@@ -278,3 +497,5 @@ export function loadFeaturesManually (layerAttributes, layerSource) {
278
497
  console.error(error);
279
498
  });
280
499
  }
500
+
501
+ export default {createLayerSource, createLayer, sendTransaction, receivePossibleProperties, parseDescribeFeatureTypeResponse, writeTransactionBody, loadFeaturesManually};
@@ -0,0 +1,18 @@
1
+ import {Modify} from "ol/interaction.js";
2
+
3
+ /**
4
+ * Create the modify interaction.
5
+ * @param {ol/source} source The vector layer source containing the features to be modified.
6
+ * @returns {ol/interaction/Modify} The modify interaction.
7
+ */
8
+ function createModifyInteraction (source) {
9
+ const modifyInteraction = new Modify({
10
+ source: source
11
+ });
12
+
13
+ return modifyInteraction;
14
+ }
15
+
16
+ export default {
17
+ createModifyInteraction
18
+ };
@@ -0,0 +1,35 @@
1
+ import {Select} from "ol/interaction.js";
2
+
3
+ /**
4
+ * Remove the selected feature.
5
+ * @param {ol/interaction/Select} selectInteraction The select interaction.
6
+ * @param {ol/source} source The vector layer source containing the features to be selected.
7
+ * @returns {void}
8
+ */
9
+ function removeSelectedFeature (selectInteraction, source) {
10
+ selectInteraction.on("select", event => {
11
+ source.removeFeature(event.selected[0]);
12
+ event.target.getFeatures().clear();
13
+ });
14
+ }
15
+
16
+ /**
17
+ * Create the select interaction.
18
+ * @param {ol/layer|ol/layer[]} layers The vector layers for select features.
19
+ * @param {ol/events/condition} [condition] The ol condition. Default from ol is "singleClick".
20
+ * @returns {ol/interaction/Select} The select interaction.
21
+ */
22
+ function createSelectInteraction (layers, condition) {
23
+ const selectInteraction = new Select({
24
+ condition: condition,
25
+ layers: Array.isArray(layers) ? layers : [layers],
26
+ hitTolerance: 10
27
+ });
28
+
29
+ return selectInteraction;
30
+ }
31
+
32
+ export default {
33
+ createSelectInteraction,
34
+ removeSelectedFeature
35
+ };
@@ -6,7 +6,7 @@ import defaults from "../../defaults";
6
6
  import * as wms from "../../layer/wms";
7
7
  import wmts from "../../layer/wmts";
8
8
  import * as geojson from "../../layer/geojson";
9
- import * as wfs from "../../layer/wfs";
9
+ import wfs from "../../layer/wfs";
10
10
  import * as vectorBase from "../../layer/vectorBase";
11
11
  import * as vectortile from "../../layer/vectorTile";
12
12
  import * as oaf from "../../layer/oaf";
@@ -1,4 +1,5 @@
1
1
  import createStyle from "../createStyle";
2
+
2
3
  /**
3
4
  * Creates the style objects for the layer
4
5
  * @param {object[]} rules styling rules from the styleObject
@@ -8,22 +9,29 @@ import createStyle from "../createStyle";
8
9
  */
9
10
  export function createLegendInfo (rules, geometryType, wfsImgPath) {
10
11
  let styleObject,
11
- simpleGeom;
12
+ simpleGeom,
13
+ legendInfos = [];
12
14
 
13
15
  geometryType.forEach(geom => rules.forEach(rule => {
14
16
  if (geom === "MultiSurface") {
15
17
  simpleGeom = "Polygon";
16
18
  styleObject = createStyle.getSimpleGeometryStyle(simpleGeom, "", rule, false, wfsImgPath);
17
- return styleObject;
19
+ legendInfos = legendInfos.concat(styleObject.legendInfos);
18
20
  }
19
21
  else if (geom.includes("Multi")) {
20
22
  simpleGeom = geom.replace("Multi", "");
21
23
  styleObject = createStyle.getMultiGeometryStyle(simpleGeom, "", rule, false, wfsImgPath);
22
- return styleObject;
23
- }
24
24
 
25
- simpleGeom = geom;
26
- styleObject = createStyle.getSimpleGeometryStyle(simpleGeom, "", rule, false, wfsImgPath);
27
- return styleObject;
25
+ styleObject.forEach(singleStyleObject => {
26
+ legendInfos = legendInfos.concat(singleStyleObject.legendInfos);
27
+ });
28
+ }
29
+ else {
30
+ simpleGeom = geom;
31
+ styleObject = createStyle.getSimpleGeometryStyle(simpleGeom, "", rule, false, wfsImgPath);
32
+ legendInfos = legendInfos.concat(styleObject.legendInfos);
33
+ }
28
34
  }));
29
- }
35
+
36
+ return legendInfos;
37
+ }
@@ -7,15 +7,15 @@ import {createLegendInfo} from "./createLegendInfo";
7
7
  * @returns {object[]} subElements of the xml element
8
8
  */
9
9
  function getSubelementsFromXMLOtherStructure (xml, featureType) {
10
- const elements = xml ? Array.from(xml.getElementsByTagName("element")) : [];
10
+ const elements = xml ? Array.from(xml.getElementsByTagNameNS("*", "element")) : [];
11
11
  let subElements = [];
12
12
 
13
13
  elements.forEach(element => {
14
14
  if (element.getAttribute("name") === featureType) {
15
15
  const sibling = element.nextElementSibling;
16
16
 
17
- if (sibling && sibling.tagName === "complexType" && sibling.hasAttribute("name")) {
18
- subElements = Array.from(sibling.getElementsByTagName("element"));
17
+ if (sibling && sibling.tagName.endsWith("complexType") && sibling.hasAttribute("name")) {
18
+ subElements = Array.from(sibling.getElementsByTagNameNS("*", "element"));
19
19
  }
20
20
  }
21
21
  });
@@ -29,7 +29,8 @@ function getSubelementsFromXMLOtherStructure (xml, featureType) {
29
29
  * @returns {object[]} subElements of the xml element
30
30
  */
31
31
  function getSubelementsFromXML (xml, featureType) {
32
- const elements = xml ? Array.from(xml.getElementsByTagName("element")) : [];
32
+ const elements = xml ? Array.from(xml.getElementsByTagNameNS("*", "element")) : [];
33
+
33
34
  let subElements = [],
34
35
  featureTypeWithoutNamespace = featureType;
35
36
 
@@ -39,9 +40,10 @@ function getSubelementsFromXML (xml, featureType) {
39
40
 
40
41
  elements.forEach(element => {
41
42
  if (element.getAttribute("name") === featureTypeWithoutNamespace) {
42
- subElements = Array.from(element.getElementsByTagName("element"));
43
+ subElements = Array.from(element.getElementsByTagNameNS("*", "element"));
43
44
  }
44
45
  });
46
+
45
47
  if (subElements.length === 0) {
46
48
  subElements = getSubelementsFromXMLOtherStructure(xml, featureTypeWithoutNamespace);
47
49
  }
@@ -105,7 +107,7 @@ function getGeometryTypeFromWFS (rules, wfsURL, version, featureType, styleGeome
105
107
  url = url.slice(0, -1);
106
108
 
107
109
 
108
- fetch(url, {
110
+ return fetch(url, {
109
111
  method: "get",
110
112
  withCredentials: isSecured,
111
113
  responseType: "text"
@@ -115,7 +117,7 @@ function getGeometryTypeFromWFS (rules, wfsURL, version, featureType, styleGeome
115
117
  const subElements = getSubelementsFromXML(responseXML, featureType),
116
118
  geometryTypes = getTypeAttributesFromSubelements(subElements, styleGeometryType);
117
119
 
118
- createLegendInfo(rules, geometryTypes, wfsImgPath);
120
+ return createLegendInfo(rules, geometryTypes, wfsImgPath);
119
121
  }).catch(error => {
120
122
  return callback(error);
121
123
  });
@@ -152,4 +154,4 @@ function getGeometryTypeFromOAF (rules, oafURL, collection, wfsImgPath, callback
152
154
  export default {
153
155
  getGeometryTypeFromWFS,
154
156
  getGeometryTypeFromOAF
155
- };
157
+ };