@masterportal/masterportalapi 2.38.0 → 2.40.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,21 +3,61 @@
3
3
 
4
4
  The [Semantic Versioning](https://semver.org/spec/v2.0.0.html) is used.
5
5
 
6
+ ## Unreleased - in development
7
+ ### __Breaking Changes__
8
+
9
+ ### Added
10
+
11
+ ### Changed
12
+
13
+ ### Deprecated
14
+
15
+ ### Removed
16
+
17
+ ### Fixed
18
+
19
+ ---
20
+
21
+ ## 2.40.0 - 2024-07-17
22
+
23
+ ### Added
24
+ - vectorStyle: enables support for additional polygon highlighting, including default styles.
25
+
26
+ ### Changed
27
+ - Replace `XMLHttpRequest` with `fetch` in `initializeLayerList`
28
+
29
+ ### Fixed
30
+ - OAF-Layer: bbox and bboxCrs are respected when building url.
31
+ - OAF-Layer: prevent url to not use more than one questionmark.
32
+
33
+ ---
34
+
35
+ ## 2.39.0 - 2024-06-18
36
+
37
+ ### Changed
38
+ - peerDependencies:
39
+ - @cesium/engine: 6.2.0 to 9.2.0
40
+
41
+ ---
42
+
6
43
  ## 2.38.0 - 2024-06-04
7
44
 
8
45
  ### Added
9
46
  - Added support for Node LTS version ^20.12.2 and npm Version ^10.5.0.
47
+ - OAF, GeoJSON: added function loadFeaturesManually.
10
48
 
11
49
  ### Changed
12
50
  - The following packages have been updated:
13
51
  - dependencies:
14
52
  - ol: 9.1.0 to 9.2.4
15
53
  - olcs: 2.19.3 to 2.20.0
54
+ - Exports in src/layer/oaf.js changed to export default {} to provide ES-Syntax.
16
55
 
17
56
  ### Fixed
18
57
  - The mitigation for issue 666 in ol-cesium since version 2.37.0 is removed
19
58
  - Webgl: vectorTiles were not displayed.
20
59
  - WMS-Layer: special loadFunction is only used if layer's attribute `isSecured` is true.
60
+ - Issue#1170: checkProperty was not negated, although it should be, so that styling-rules can be properly excluded.
21
61
 
22
62
  ---
23
63
 
@@ -105,7 +105,8 @@
105
105
  "url": "https://api.hamburg.de/datasets/v1/schulen",
106
106
  "collection": "staatliche_schulen",
107
107
  "typ": "OAF",
108
- "crs": "http://www.opengis.net/def/crs/EPSG/0/25832"
108
+ "crs": "http://www.opengis.net/def/crs/EPSG/0/25832",
109
+ "bboxCrs": "http://www.opengis.net/def/crs/EPSG/0/25832"
109
110
  },
110
111
  {
111
112
  "id": "8712",
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.38.0",
4
+ "version": "2.40.0",
5
5
  "license": "MIT",
6
6
  "description": "Basic functions of the Masterportal as api",
7
7
  "repository": {
@@ -56,7 +56,7 @@
56
56
  "util": "^0.12.5"
57
57
  },
58
58
  "peerDependencies": {
59
- "@cesium/engine": "^6.2.0"
59
+ "@cesium/engine": "^9.2.0"
60
60
  },
61
61
  "engines": {
62
62
  "node": "^16.13.2 || ^18.12.0 || ^20.12.2",
package/src/index.js CHANGED
@@ -6,7 +6,7 @@ import wmts from "./layer/wmts";
6
6
  import wfs from "./layer/wfs";
7
7
  import * as geojson from "./layer/geojson";
8
8
  import * as vectorTile from "./layer/vectorTile";
9
- import * as oaf from "./layer/oaf";
9
+ import oaf from "./layer/oaf";
10
10
  import * as terrain from "./layer/terrain";
11
11
  import * as entities from "./layer/entities";
12
12
  import * as webgl from "./renderer/webgl";
@@ -167,3 +167,28 @@ export function showFeaturesById (layer, featureIdList) {
167
167
  hideAllFeatures(layer);
168
168
  setFeatureStyle(features, undefined);
169
169
  }
170
+
171
+ /**
172
+ * Load the features manually.
173
+ * @param {Object} layerAttributes raw layer attributes.
174
+ * @param {module:ol/vector/Source} layerSource - the source of the layer
175
+ * @returns {void}
176
+ */
177
+ export function loadFeaturesManually (layerAttributes, layerSource) {
178
+ const getUrl = layerAttributes.url;
179
+
180
+ fetch(getUrl, layerSource)
181
+ .then(response => response.text())
182
+ .then(responseString => {
183
+ const features = layerSource.getFormat().readFeatures(responseString);
184
+
185
+ layerSource.addFeatures(features);
186
+ layerSource.dispatchEvent({
187
+ type: "featuresloadend",
188
+ features: layerSource.getFeatures()
189
+ });
190
+ })
191
+ .catch(error => {
192
+ console.error(error);
193
+ });
194
+ }
package/src/layer/oaf.js CHANGED
@@ -3,7 +3,6 @@ import {bbox} from "ol/loadingstrategy.js";
3
3
  import GeoJSON from "ol/format/GeoJSON.js";
4
4
  import {createVectorSource, createClusterVectorSource} from "./vector";
5
5
  import {onError, onLoad} from "../lib/wfsUtil";
6
- import {getParamsUrl} from "../lib/oafUtil";
7
6
  import * as webgl from "../renderer/webgl";
8
7
 
9
8
  /**
@@ -110,20 +109,75 @@ function loadSource (url, source, {onErrorFn, success, failure}, options, collec
110
109
  });
111
110
  }
112
111
 
112
+ /**
113
+ * Creates the url for OAF request.
114
+ * @param {rawLayer} rawLayer layer specification as in services.json
115
+ * @param {object} loadingParams added as params to url
116
+ * @param {number[]} [extent] the current viewport extent
117
+ * @returns {string} the url
118
+ */
119
+ export function createUrl (rawLayer, loadingParams) {
120
+ const bboxParam = loadingParams?.bbox || rawLayer.bbox,
121
+ rawUrl = rawLayer.url;
122
+ let bboxValue = typeof bboxParam === "string" && bboxParam.length ? bboxParam : null,
123
+ url = null;
124
+
125
+ url = new URL(rawUrl);
126
+ if (typeof rawLayer.collection === "string") {
127
+ if (!url.pathname.endsWith("/")) {
128
+ url.pathname += "/collections/" + rawLayer.collection + "/items";
129
+ }
130
+ else {
131
+ url.pathname = "collections/" + rawLayer.collection + "/items";
132
+ }
133
+
134
+ }
135
+ if (typeof rawLayer.limit === "number") {
136
+ url.searchParams.set("limit", rawLayer.limit);
137
+ }
138
+ if (Array.isArray(bboxParam) && bboxParam.length === 4) {
139
+ bboxValue = bboxParam.join(",");
140
+ }
141
+ if (bboxValue) {
142
+ url.searchParams.set("bbox", bboxParam);
143
+ if (typeof rawLayer.bboxCrs === "string" && rawLayer.bboxCrs !== "") {
144
+ url.searchParams.set("bbox-crs", rawLayer.bboxCrs);
145
+ }
146
+ }
147
+ if (typeof rawLayer.crs === "string") {
148
+ url.searchParams.set("crs", rawLayer.crs);
149
+ }
150
+ if (typeof rawLayer.datetime === "string" && rawLayer.datetime !== "") {
151
+ url.searchParams.set("datetime", rawLayer.datetime);
152
+ }
153
+ if (typeof rawLayer.params === "object" && Object.keys(rawLayer.params).length) {
154
+ Object.entries(rawLayer.params).forEach(([key, value]) => {
155
+ url.searchParams.set(key, value);
156
+ });
157
+ }
158
+
159
+ return url;
160
+ }
161
+
113
162
  /**
114
163
  * Creates an ol/source element for the rawLayer by using a loader.
115
164
  * The 'featuresloadend' and 'featuresloaderror' events will be fired by using success and failure callbacks of the loader.
116
165
  * @param {rawLayer} rawLayer layer specification as in services.json
117
166
  * @param {options} [options] additional options
118
- * @param {String} url the parsed url
119
167
  * {@link https://openlayers.org/en/latest/apidoc/module-ol_source_Vector-VectorSource.html failure/success see}
120
168
  * @returns {(ol.source.VectorSource|ol.source.Cluster)} VectorSource or Cluster, depending on whether clusterDistance is set.
121
169
  */
122
- function getLayerSource (rawLayer, options, url) {
170
+ function getLayerSource (rawLayer, options) {
123
171
  const format = new GeoJSON();
124
172
  let source = null;
125
173
 
126
- function loader (extent, resolution, projection, success, failure) {
174
+ function loader (extent, _, __, success, failure) {
175
+ const bboxParam = options.loadingStrategy === bbox ? extent : options.loadingParams.bbox,
176
+ url = createUrl(rawLayer, {
177
+ ...options.loadingParams,
178
+ bbox: bboxParam
179
+ });
180
+
127
181
  loadSource(url, source, {onErrorFn: onError, success, failure}, options);
128
182
  }
129
183
  source = createVectorSource(loader, options.loadingStrategy, format);
@@ -138,36 +192,6 @@ function getLayerSource (rawLayer, options, url) {
138
192
  return source;
139
193
  }
140
194
 
141
- /**
142
- * Creates the url for OAF request.
143
- * @param {rawLayer} rawLayer layer specification as in services.json
144
- * @returns {string} the url
145
- */
146
- function createUrl (rawLayer) {
147
- let url = rawLayer.url,
148
- appendingString;
149
- const crsDefault = "";
150
-
151
- url += typeof rawLayer.collection === "string" ? "/collections/" + rawLayer.collection + "/items?" : "";
152
- url += typeof rawLayer.limit === "number" ? "limit=" + rawLayer.limit + "&" : "";
153
- if (Array.isArray(rawLayer.bbox) && rawLayer.bbox.length === 4) {
154
- appendingString = "";
155
-
156
- rawLayer.bbox.forEach((bboxEntry, i) => {
157
- appendingString += i !== rawLayer.bbox.length - 1 ? bboxEntry + "," : bboxEntry;
158
- });
159
- url += "bbox=" + appendingString + "&";
160
- }
161
- url += typeof rawLayer.bboxCrs === "string" && rawLayer.bboxCrs !== "" ? "bbox-crs=" + encodeURIComponent(rawLayer.bboxCrs) + "&" : "";
162
- if (rawLayer.crs !== false) {
163
- url += "crs=" + encodeURIComponent(typeof rawLayer.crs === "string" && rawLayer.crs !== "" ? rawLayer.crs : crsDefault) + "&";
164
- }
165
- url += typeof rawLayer.datetime === "string" && rawLayer.datetime !== "" ? "datetime=" + rawLayer.datetime + "&" : "";
166
- url += getParamsUrl(rawLayer.params);
167
-
168
- return url;
169
- }
170
-
171
195
  /**
172
196
  * Creates an ol/source element for the rawLayer by OAF (XML or Geojson)
173
197
  * @param {rawLayer} rawLayer layer specification as in services.json
@@ -178,13 +202,11 @@ function createUrl (rawLayer) {
178
202
  * {@link https://openlayers.org/en/latest/apidoc/module-ol_source_Vector-VectorSource.html failure/success see}
179
203
  * @returns {(ol.source.VectorSource|ol.source.Cluster)} VectorSource or Cluster, depending on whether clusterDistance is set.
180
204
  */
181
- export function createLayerSource (rawLayer, options = {}) {
205
+ function createLayerSource (rawLayer, options = {}) {
182
206
  if (!options.loadingStrategy) {
183
207
  options.loadingStrategy = bbox;
184
208
  }
185
-
186
- const url = createUrl(rawLayer),
187
- source = getLayerSource(rawLayer, options, url);
209
+ const source = getLayerSource(rawLayer, options);
188
210
 
189
211
  if (rawLayer.renderer === "webgl") {
190
212
  source.once("featuresloadend", event => {
@@ -203,7 +225,7 @@ export function createLayerSource (rawLayer, options = {}) {
203
225
  * @param {options} [optionalParams.options] - additional options
204
226
  * @returns {ol.Layer} Layer that can be added to map.
205
227
  */
206
- export function createLayer (rawLayer = {}, {layerParams = {}, options = {}} = {}) {
228
+ function createLayer (rawLayer = {}, {layerParams = {}, options = {}} = {}) {
207
229
  let layer, source;
208
230
 
209
231
  // use WebGL render pipeline, if specified
@@ -239,3 +261,26 @@ export function createLayer (rawLayer = {}, {layerParams = {}, options = {}} = {
239
261
  }
240
262
  return layer;
241
263
  }
264
+
265
+ /**
266
+ * Load the features manually.
267
+ * @param {Object} layerAttributes raw layer attributes.
268
+ * @param {module:ol/vector/Source} layerSource - the source of the layer
269
+ * @returns {void}
270
+ */
271
+ function loadFeaturesManually (layerAttributes, layerSource) {
272
+ const getUrl = createUrl(layerAttributes, layerAttributes.version, {getCode: () => layerAttributes.crs}, "");
273
+
274
+ fetch(getUrl, layerSource)
275
+ .then(response => {
276
+ return response.text();
277
+ })
278
+ .then(responseString => {
279
+ layerSource.addFeatures(layerSource.getFormat().readFeatures(responseString));
280
+ })
281
+ .catch(error => {
282
+ console.error(error);
283
+ });
284
+ }
285
+
286
+ export default {createLayer, createLayerSource, createUrl, loadFeaturesManually};
@@ -8,7 +8,7 @@ import wmts from "../../layer/wmts";
8
8
  import * as geojson from "../../layer/geojson";
9
9
  import wfs from "../../layer/wfs";
10
10
  import * as vectortile from "../../layer/vectorTile";
11
- import * as oaf from "../../layer/oaf";
11
+ import oaf from "../../layer/oaf";
12
12
  import {createMapView} from "../../maps/mapView";
13
13
  import rawLayerList from "../../rawLayerList";
14
14
  import crs from "../../crs";
@@ -26,28 +26,25 @@ function initializeLayerList (layerConf = defaults.layerConf, callback) {
26
26
  }
27
27
 
28
28
  // case: parameter is URL
29
- const Http = new XMLHttpRequest();
30
-
31
- Http.open("GET", layerConf);
32
- Http.timeout = 10000;
33
- Http.send();
34
- Http.onload = function () {
35
- try {
36
- layerList = JSON.parse(Http.responseText);
37
- }
38
- catch (error) {
39
- console.error("An error occured when parsing the response after loading '" + layerConf + "':", error);
40
- return callback(false, error);
41
- }
42
- if (typeof callback === "function") {
43
- return callback(layerList);
44
- }
45
- return true;
46
- };
47
- Http.onerror = function (e) {
48
- console.error("An error occured when trying to fetch services from '" + layerConf + "':", e);
49
- callback(false, e);
50
- };
29
+ fetch(layerConf, {method: "GET", timeout: 10000})
30
+ .then((response) => {
31
+ response.json()
32
+ .then((json) => {
33
+ layerList = json;
34
+ if (typeof callback === "function") {
35
+ return callback(layerList);
36
+ }
37
+ return true;
38
+ })
39
+ .catch((error) => {
40
+ console.error("An error occured when parsing the response after loading '" + layerConf + "':", error);
41
+ return callback(false, error);
42
+ });
43
+ })
44
+ .catch((error) => {
45
+ console.error("An error occured when trying to fetch services from '" + layerConf + "':", error);
46
+ callback(false, error);
47
+ });
51
48
  }
52
49
 
53
50
  /**
@@ -152,7 +152,7 @@ export function checkProperties (feature, rule) {
152
152
 
153
153
  key = properties[i].attrName;
154
154
 
155
- if (checkProperty(featureProperties, key, value)) {
155
+ if (!checkProperty(featureProperties, key, value)) {
156
156
  return false;
157
157
  }
158
158
  }
@@ -14,6 +14,7 @@ let styleList,
14
14
  configuredTools,
15
15
  mapMarkerPointStyleId,
16
16
  mapMarkerPolygonStyleId,
17
+ additionalPolygonStyleId,
17
18
  highlightFeaturesPointStyleId,
18
19
  highlightFeaturesPolygonStyleId,
19
20
  highlightFeaturesLineStyleId,
@@ -140,6 +141,23 @@ function getStyleIdForMapMarkerPolygon () {
140
141
  return styleId;
141
142
  }
142
143
 
144
+ /**
145
+ * Gets the style id for an additional MapMarker.
146
+ * If the additionalPolygonStyleId exists, return it; otherwise, returns the default styleId.
147
+ * @returns {String} - The styleId of the additional MapMarker
148
+ */
149
+ function getStyleIdForAdditionalMapMarkerPolygon () {
150
+ let styleId;
151
+
152
+ if (additionalPolygonStyleId) {
153
+ styleId = additionalPolygonStyleId;
154
+ }
155
+ else {
156
+ styleId = "defaultAdditionalMapMarkerPolygon";
157
+ }
158
+ return styleId;
159
+ }
160
+
143
161
  /**
144
162
  * gets style id from HighlightFeatures
145
163
  * @returns {String} - Style id of highlightFeatures.
@@ -186,6 +204,7 @@ function parseStyles (data) {
186
204
  dataWithDefaultValue.push({styleId: "default", rules: [{style: {}}]},
187
205
  defaultStyle.defaultMapMarkerPoint,
188
206
  defaultStyle.defaultMapMarkerPolygon,
207
+ defaultStyle.defaultAdditionalMapMarkerPolygon,
189
208
  defaultStyle.defaultHighlightFeaturesPoint,
190
209
  defaultStyle.defaultHighlightFeaturesPolygon,
191
210
  defaultStyle.defaultHighlightFeaturesLine);
@@ -193,6 +212,7 @@ function parseStyles (data) {
193
212
  styleIds.push(getStyleIdsFromLayers(),
194
213
  getStyleIdForMapMarkerPoint(),
195
214
  getStyleIdForMapMarkerPolygon(),
215
+ getStyleIdForAdditionalMapMarkerPolygon(),
196
216
  getStyleIdForHighlightFeaturesPoint(),
197
217
  getStyleIdForHighlightFeaturesPolygon(),
198
218
  getStyleIdForHighlightFeaturesLine(),
@@ -222,6 +242,7 @@ async function initializeStyleList (styleGetters, Config, layers, tools, callbac
222
242
 
223
243
  mapMarkerPointStyleId = styleGetters.mapMarkerPointStyleId;
224
244
  mapMarkerPolygonStyleId = styleGetters.mapMarkerPolygonStyleId;
245
+ additionalPolygonStyleId = styleGetters.additionalPolygonStyleId;
225
246
  highlightFeaturesPointStyleId = styleGetters.highlightFeaturesPointStyleId;
226
247
  highlightFeaturesPolygonStyleId = styleGetters.highlightFeaturesPolygonStyleId;
227
248
  highlightFeaturesLineStyleId = styleGetters.highlightFeaturesLineStyleId;
@@ -137,6 +137,17 @@ const defaultColors = {
137
137
  }
138
138
  }]
139
139
  },
140
+ defaultAdditionalMapMarkerPolygon: {
141
+ styleId: "defaultAdditionalMapMarkerPolygon",
142
+ rules: [{
143
+ style: {
144
+ polygonStrokeColor: [255, 255, 0, 1],
145
+ polygonStrokeWidth: 4,
146
+ polygonFillColor: [255, 255, 0, 0.3],
147
+ polygonStrokeDash: [8]
148
+ }
149
+ }]
150
+ },
140
151
  defaultHighlightFeaturesPoint: {
141
152
  styleId: "defaultHighlightFeaturesPoint",
142
153
  rules: [{
@@ -167,4 +167,34 @@ describe("geojson/index", function () {
167
167
  expect(features[1].getStyle()()).toBeNull();
168
168
  });
169
169
  });
170
+ describe("loadFeaturesManually", function () {
171
+ it("loadFeaturesManually shall call fetch", function () {
172
+ console.error = jest.fn();
173
+ global.fetch = jest.fn().mockImplementationOnce(() => {
174
+ return new Promise((resolve) => {
175
+ resolve({
176
+ ok: true,
177
+ status: 200,
178
+ json: () => {
179
+ return [];
180
+ }
181
+ });
182
+ });
183
+ });
184
+
185
+ const layerParams = {
186
+ id: "id",
187
+ url: "url",
188
+ featureNS: "http://www.deegree.org/app",
189
+ featureType: "krankenhaeuser_hh",
190
+ version: "1.0.0"
191
+ },
192
+ options = {},
193
+ layer = geojson.createLayer(layerParams, {options});
194
+
195
+ geojson.loadFeaturesManually(layerParams, layer.getSource());
196
+
197
+ expect(global.fetch.mock.calls.length).toBe(1);
198
+ });
199
+ });
170
200
  });
@@ -5,7 +5,7 @@ import {Style, Icon} from "ol/style.js";
5
5
  import map from "../../src/maps/map.js";
6
6
  import defaults from "../../src/defaults";
7
7
  import GeoJSON from "ol/format/GeoJSON.js";
8
- import * as oaf from "../../src/layer/oaf";
8
+ import oaf from "../../src/layer/oaf";
9
9
  import {featureCollection} from "./resources/oafFeatures";
10
10
  import * as webgl from "../../src/renderer/webgl.js";
11
11
 
@@ -38,7 +38,7 @@ describe("oaf.js", function () {
38
38
  const attr = {
39
39
  "id": "id",
40
40
  "name": "Schulen",
41
- "url": "https://url.de",
41
+ "url": "https://url",
42
42
  "collection": "staatliche_schulen",
43
43
  "typ": "OAF",
44
44
  "bbox": "",
@@ -137,7 +137,7 @@ describe("oaf.js", function () {
137
137
  console.error = consoleError;
138
138
  });
139
139
  it("creates a GeoJSON VectorSource", function () {
140
- global.fetch = jest.fn().mockImplementationOnce(() => {
140
+ global.fetch = jest.fn().mockImplementation(() => {
141
141
  return new Promise((resolve) => {
142
142
  resolve({
143
143
  ok: true,
@@ -153,7 +153,7 @@ describe("oaf.js", function () {
153
153
  const rawLayer = {
154
154
  id: "id",
155
155
  name: "Schulen",
156
- url: "https://url.de",
156
+ url: "https://url",
157
157
  collection: "staatliche_schulen",
158
158
  typ: "OAF",
159
159
  limit: 10,
@@ -167,7 +167,7 @@ describe("oaf.js", function () {
167
167
  expect(layer.getSource().getFormat()).toBeInstanceOf(GeoJSON);
168
168
  });
169
169
  it("creates a VectorSource and onLoadingError is called", function () {
170
- global.fetch = jest.fn().mockImplementationOnce(() => {
170
+ global.fetch = jest.fn().mockImplementation(() => {
171
171
  return new Promise((resolve) => {
172
172
  resolve({
173
173
  ok: false,
@@ -184,7 +184,7 @@ describe("oaf.js", function () {
184
184
  const rawLayer = {
185
185
  id: "id",
186
186
  name: "Schulen",
187
- url: "https://url.de",
187
+ url: "https://url",
188
188
  collection: "staatliche_schulen",
189
189
  typ: "OAF",
190
190
  limit: 10,
@@ -206,7 +206,7 @@ describe("oaf.js", function () {
206
206
  });
207
207
  });
208
208
  it("creates a clustered VectorSource and beforeLoading, afterLoading and featuresFilter are called", function () {
209
- global.fetch = jest.fn().mockImplementationOnce(() => {
209
+ global.fetch = jest.fn().mockImplementation(() => {
210
210
  return new Promise((resolve) => {
211
211
  resolve({
212
212
  ok: true,
@@ -223,7 +223,7 @@ describe("oaf.js", function () {
223
223
  rawLayer = {
224
224
  id: "id",
225
225
  name: "Schulen",
226
- url: "https://url.de",
226
+ url: "https://url",
227
227
  collection: "staatliche_schulen",
228
228
  typ: "OAF",
229
229
  limit: 10,
@@ -259,7 +259,7 @@ describe("oaf.js", function () {
259
259
  });
260
260
  it("creates a vectorSource with an additional listener, when renderer is \"webgl\"", () => {
261
261
  const
262
- url = "https://url.de",
262
+ url = "https://url",
263
263
  rawLayer = {
264
264
  id: "id",
265
265
  url: url,
@@ -287,4 +287,114 @@ describe("oaf.js", function () {
287
287
  expect(webgl.afterLoading).toHaveBeenCalledWith(features, layerParams.styleId, layerParams.excludeTypesFromParsing, layerParams.isPointLayer);
288
288
  });
289
289
  });
290
+ describe("loadFeaturesManually", function () {
291
+ it("loadFeaturesManually shall call fetch", function () {
292
+ console.error = jest.fn();
293
+ global.fetch = jest.fn().mockImplementation(() => {
294
+ return new Promise((resolve) => {
295
+ resolve({
296
+ ok: true,
297
+ status: 200,
298
+ json: () => {
299
+ return featureCollection;
300
+ }
301
+ });
302
+ });
303
+ });
304
+
305
+ const rawLayer = {
306
+ id: "id",
307
+ url: "https://url",
308
+ featureNS: "http://www.deegree.org/app",
309
+ featureType: "krankenhaeuser_hh",
310
+ version: "1.0.0"
311
+ },
312
+ options = {},
313
+ layer = oaf.createLayer(rawLayer, {options});
314
+
315
+ oaf.loadFeaturesManually(rawLayer, layer.getSource());
316
+
317
+ expect(global.fetch.mock.calls.length).toBe(1);
318
+ });
319
+ });
320
+ describe("createUrl", () => {
321
+ it("should append bbox, collection, limit, datetime, bboxCrs, and crs, as provided in rawLayer", () => {
322
+ const rawLayer = {
323
+ id: "id",
324
+ name: "Schulen",
325
+ url: "https://url.de",
326
+ collection: "staatliche_schulen",
327
+ typ: "OAF",
328
+ limit: 10,
329
+ bbox: [0, 0, 10, 10],
330
+ bboxCrs: "EPSG:4326",
331
+ datetime: "123",
332
+ crs: "EPSG:25832"
333
+ },
334
+ loadingParams = undefined,
335
+ createdUrl = oaf.createUrl(rawLayer, loadingParams);
336
+
337
+ expect(createdUrl.origin).toEqual(rawLayer.url);
338
+ expect(createdUrl.pathname).toEqual("/collections/" + rawLayer.collection + "/items");
339
+ expect(createdUrl.searchParams.get("limit")).toEqual("10");
340
+ expect(createdUrl.searchParams.get("bbox")).toEqual("0,0,10,10");
341
+ expect(createdUrl.searchParams.get("bbox-crs")).toEqual(rawLayer.bboxCrs);
342
+ expect(createdUrl.searchParams.get("crs")).toEqual(rawLayer.crs);
343
+ expect(createdUrl.searchParams.get("datetime")).toEqual(rawLayer.datetime);
344
+ });
345
+ it("should append the bbox, if provided as string in rawLayer", () => {
346
+ const rawLayer = {
347
+ id: "id",
348
+ name: "Schulen",
349
+ url: "https://url.de",
350
+ collection: "staatliche_schulen",
351
+ typ: "OAF",
352
+ bbox: "0,0,10,10",
353
+ bboxCrs: "EPSG:4326"
354
+ },
355
+ loadingParams = undefined,
356
+ createdUrl = oaf.createUrl(rawLayer, loadingParams);
357
+
358
+ expect(createdUrl.origin).toEqual(rawLayer.url);
359
+ expect(createdUrl.pathname).toEqual("/collections/" + rawLayer.collection + "/items");
360
+ expect(createdUrl.searchParams.get("bbox")).toEqual("0,0,10,10");
361
+ expect(createdUrl.searchParams.get("bbox-crs")).toEqual(rawLayer.bboxCrs);
362
+ });
363
+ it("should append the bbox, if provided as string in loadingParams", () => {
364
+ const rawLayer = {
365
+ id: "id",
366
+ name: "Schulen",
367
+ url: "https://mapservice.regensburg.de/cgi-bin/mapserv?map=wfs.map",
368
+ collection: "staatliche_schulen",
369
+ typ: "OAF"
370
+ },
371
+ loadingParams = {bbox: "0,0,10,10"},
372
+ createdUrl = oaf.createUrl(rawLayer, loadingParams);
373
+
374
+ expect(createdUrl.origin).toEqual("https://mapservice.regensburg.de");
375
+ expect(createdUrl.pathname).toEqual("/cgi-bin/mapserv/collections/" + rawLayer.collection + "/items");
376
+ expect(createdUrl.searchParams.get("map")).toEqual("wfs.map");
377
+ expect(createdUrl.searchParams.get("bbox")).toEqual("0,0,10,10");
378
+ });
379
+ it("should append additional key:value filters, if provided as in rawLayer.params", () => {
380
+ const rawLayer = {
381
+ id: "id",
382
+ name: "Schulen",
383
+ url: "https://url/",
384
+ collection: "staatliche_schulen",
385
+ typ: "OAF",
386
+ params: {
387
+ kapitelbezeichnung: "Gymnasien",
388
+ anzahl_schueler: ">1000"
389
+ }
390
+ },
391
+ loadingParams = undefined,
392
+ createdUrl = oaf.createUrl(rawLayer, loadingParams);
393
+
394
+ expect(createdUrl.origin).toEqual("https://url");
395
+ expect(createdUrl.pathname).toEqual("/collections/" + rawLayer.collection + "/items");
396
+ expect(createdUrl.searchParams.get("kapitelbezeichnung")).toEqual("Gymnasien");
397
+ expect(createdUrl.searchParams.get("anzahl_schueler")).toEqual(">1000");
398
+ });
399
+ });
290
400
  });
@@ -152,7 +152,7 @@ describe("wfs.js", function () {
152
152
  });
153
153
 
154
154
  it("creates a VectorSource and beforeLoading, afterLoading and featuresFilter are called", function () {
155
- global.fetch = jest.fn().mockImplementationOnce(() => {
155
+ global.fetch = jest.fn().mockImplementation(() => {
156
156
  return new Promise((resolve) => {
157
157
  resolve({
158
158
  ok: true,
@@ -202,7 +202,7 @@ describe("wfs.js", function () {
202
202
  });
203
203
  });
204
204
  it("creates a VectorSource with doNotLoadInitially", function () {
205
- global.fetch = jest.fn().mockImplementationOnce(() => {
205
+ global.fetch = jest.fn().mockImplementation(() => {
206
206
  return new Promise((resolve) => {
207
207
  resolve({
208
208
  ok: true,
@@ -255,7 +255,7 @@ describe("wfs.js", function () {
255
255
  it("creates a VectorSource with wfsFilter", function () {
256
256
  let secondFetchCalled = false;
257
257
 
258
- global.fetch = jest.fn().mockImplementationOnce(() => {
258
+ global.fetch = jest.fn().mockImplementation(() => {
259
259
  return new Promise((resolve) => {
260
260
  resolve({
261
261
  ok: true,
@@ -265,7 +265,7 @@ describe("wfs.js", function () {
265
265
  }
266
266
  });
267
267
  });
268
- }).mockImplementationOnce(() => {
268
+ }).mockImplementation(() => {
269
269
  return new Promise((resolve) => {
270
270
  resolve({
271
271
  ok: true,
@@ -317,7 +317,7 @@ describe("wfs.js", function () {
317
317
  });
318
318
  });
319
319
  it("creates a VectorSource and onLoadingError is called", function () {
320
- global.fetch = jest.fn().mockImplementationOnce(() => {
320
+ global.fetch = jest.fn().mockImplementation(() => {
321
321
  // NOTE: fetch only rejects if a network error occurs, which do not apply to 4xx or 5xx http codes.
322
322
  return new Promise((resolve) => {
323
323
  resolve({
@@ -360,7 +360,7 @@ describe("wfs.js", function () {
360
360
  });
361
361
  });
362
362
  it("creates a clustered VectorSource and beforeLoading, afterLoading and featuresFilter are called", function () {
363
- global.fetch = jest.fn().mockImplementationOnce(() => {
363
+ global.fetch = jest.fn().mockImplementation(() => {
364
364
  return new Promise((resolve) => {
365
365
  resolve({
366
366
  ok: true,
@@ -442,7 +442,7 @@ describe("wfs.js", function () {
442
442
  expect(webgl.afterLoading).toHaveBeenCalledWith(features, layerParams.styleId, layerParams.excludeTypesFromParsing, layerParams.isPointLayer);
443
443
  });
444
444
  it("creates a vectorSource with credentials: include as params", () => {
445
- global.fetch = jest.fn().mockImplementationOnce(() => {
445
+ global.fetch = jest.fn().mockImplementation(() => {
446
446
  // NOTE: fetch only rejects if a network error occurs, which do not apply to 4xx or 5xx http codes.
447
447
  return new Promise((resolve) => {
448
448
  resolve({
@@ -1068,7 +1068,7 @@ describe("wfs.js", function () {
1068
1068
  });
1069
1069
 
1070
1070
  it("load features manually", async function () {
1071
- global.fetch = jest.fn().mockImplementationOnce(() => {
1071
+ global.fetch = jest.fn().mockImplementation(() => {
1072
1072
  return new Promise((resolve) => {
1073
1073
  resolve({
1074
1074
  ok: true,
@@ -33,7 +33,7 @@ jest.mock("../../src/searchAddress/searchGazetteer", () => {
33
33
 
34
34
  import {searchGazetteer as mockedSearchGazetteer} from "../../src/searchAddress/searchGazetteer";
35
35
 
36
- describe.only("searchAddress", function () {
36
+ describe("searchAddress", function () {
37
37
  describe("search", function () {
38
38
  it("rejects if missing configuration of what to search for", function (done) {
39
39
  search("Pflugacker", {}).catch(e => {
@@ -1,22 +0,0 @@
1
- /**
2
- * Parsing the params object in to string for url
3
- * @param {Object} params the paramters in object
4
- * @returns {String} The url parameters in string format
5
- */
6
- function getParamsUrl (params) {
7
- if (!params || typeof params !== "object" || params.constructor !== Object || !Object.keys(params).length) {
8
- return "";
9
- }
10
-
11
- let paramsUrl = "";
12
-
13
- Object.entries(params).forEach(([key, value]) => {
14
- paramsUrl += "&" + key + "=" + value;
15
- });
16
-
17
- return paramsUrl;
18
- }
19
-
20
- export {
21
- getParamsUrl
22
- };
@@ -1,24 +0,0 @@
1
- import {getParamsUrl} from "../../src/lib/oafUtil";
2
-
3
- describe("oafUtil.js", function () {
4
- describe("getParamsUrl", function () {
5
- const params = {
6
- "anzahl_schueler": ">1000",
7
- "bezirk": "Bergedorf"
8
- };
9
-
10
- it("should return the parsed paramsUrl", function () {
11
- expect(getParamsUrl(params)).toEqual("&anzahl_schueler=>1000&bezirk=Bergedorf");
12
- });
13
-
14
- it("should return an empty string", function () {
15
- expect(getParamsUrl("string")).toEqual("");
16
- expect(getParamsUrl(0)).toEqual("");
17
- expect(getParamsUrl(null)).toEqual("");
18
- expect(getParamsUrl(undefined)).toEqual("");
19
- expect(getParamsUrl(true)).toEqual("");
20
- expect(getParamsUrl([])).toEqual("");
21
- expect(getParamsUrl({})).toEqual("");
22
- });
23
- });
24
- });