@geogirafe/lib-geoportal 1.3.0-dev.3053452205 → 1.3.0-dev.3060317043

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.
Files changed (86) hide show
  1. package/LICENSE +1 -0
  2. package/assets/i18n/de.json +33 -3
  3. package/assets/i18n/en.json +32 -2
  4. package/assets/i18n/fr.json +34 -4
  5. package/assets/i18n/it.json +36 -6
  6. package/assets/icons/edit.svg +1 -1
  7. package/assets/icons/lock.svg +1 -0
  8. package/components/cross-section/cross-section-settings/component.js +1 -1
  9. package/components/edit/component.d.ts +52 -36
  10. package/components/edit/component.js +340 -292
  11. package/components/edit/editcomponentstate.d.ts +1 -0
  12. package/components/edit/editcomponentstate.js +1 -0
  13. package/components/edit/editform/component.d.ts +34 -4
  14. package/components/edit/editform/component.js +224 -37
  15. package/components/edit/editform/style.css +51 -16
  16. package/components/edit/geometryedithelper.d.ts +47 -0
  17. package/components/edit/geometryedithelper.js +324 -0
  18. package/components/edit/style.css +71 -28
  19. package/components/main.d.ts +1 -1
  20. package/components/main.js +1 -1
  21. package/components/print/component.d.ts +1 -1
  22. package/components/treeview/tools/treeviewelement.d.ts +1 -0
  23. package/components/treeview/tools/treeviewelement.js +22 -0
  24. package/components/treeview/treeviewitem/component.js +7 -1
  25. package/models/gmf.d.ts +18 -2
  26. package/models/gmf.js +3 -1
  27. package/models/layers/editablelayer.d.ts +7 -0
  28. package/models/layers/editablelayer.js +7 -0
  29. package/models/layers/layerwms.d.ts +1 -2
  30. package/models/layers/layerwms.js +4 -8
  31. package/models/main.d.ts +9 -4
  32. package/models/main.js +6 -2
  33. package/models/oapiflayer.d.ts +25 -0
  34. package/models/oapiflayer.js +36 -0
  35. package/models/oapiftypes.d.ts +71 -0
  36. package/models/oapiftypes.js +29 -0
  37. package/models/serverogc.d.ts +5 -3
  38. package/models/serverogc.js +19 -6
  39. package/models/serverogcapi.d.ts +2 -0
  40. package/models/serverogcapi.js +2 -0
  41. package/models/serverogcapifeatures.d.ts +5 -62
  42. package/models/serverogcapifeatures.js +8 -4
  43. package/package.json +1 -1
  44. package/templates/index.html +1 -0
  45. package/templates/public/about.json +1 -1
  46. package/tools/app/geogirafeapp.js +2 -2
  47. package/tools/drawing/olDrawing.js +2 -22
  48. package/tools/drawing/shapeConstraints.d.ts +2 -1
  49. package/tools/drawing/shapeConstraints.js +18 -2
  50. package/tools/main.d.ts +7 -5
  51. package/tools/main.js +7 -5
  52. package/tools/ogcapi/ogcapiclient.d.ts +7 -3
  53. package/tools/ogcapi/ogcapiclient.js +49 -4
  54. package/tools/ogcapi/ogcapiconformance.d.ts +2 -2
  55. package/tools/ogcapi/ogcapiconformance.js +7 -13
  56. package/tools/ogcapi/ogcapifeaturesclient.d.ts +65 -30
  57. package/tools/ogcapi/ogcapifeaturesclient.js +265 -139
  58. package/tools/ogcapi/ogcapifeaturesclientgeorama.d.ts +0 -5
  59. package/tools/ogcapi/ogcapifeaturesclientgeorama.js +0 -11
  60. package/tools/ogcapi/ogcapifeaturesclientqgis.d.ts +8 -0
  61. package/tools/ogcapi/ogcapifeaturesclientqgis.js +13 -0
  62. package/tools/ogcapi/ogcapifeaturesmanager.d.ts +61 -8
  63. package/tools/ogcapi/ogcapifeaturesmanager.js +179 -30
  64. package/tools/ogcapi/ogcapifeaturesschema.d.ts +31 -13
  65. package/tools/ogcapi/ogcapifeaturesschema.js +69 -39
  66. package/tools/ogcapi/ogcapifeaturesschemaproperty.d.ts +44 -0
  67. package/tools/ogcapi/ogcapifeaturesschemaproperty.js +137 -0
  68. package/tools/ogcapi/ogcapifeaturesschemavalidator.d.ts +22 -0
  69. package/tools/ogcapi/ogcapifeaturesschemavalidator.js +121 -0
  70. package/tools/state/state.d.ts +6 -0
  71. package/tools/state/state.js +4 -0
  72. package/tools/themes/themesmanager.d.ts +10 -3
  73. package/tools/themes/themesmanager.js +29 -9
  74. package/tools/time/layertimeformatter.d.ts +0 -5
  75. package/tools/time/layertimeformatter.js +10 -19
  76. package/tools/utils/dateutils.d.ts +40 -0
  77. package/tools/utils/dateutils.js +111 -0
  78. package/tools/utils/utils.d.ts +4 -0
  79. package/tools/utils/utils.js +12 -0
  80. package/tools/wfs/wfsmanager.js +3 -0
  81. package/tools/wms/wmsclient.d.ts +1 -0
  82. package/tools/wms/wmsclient.js +4 -0
  83. package/tools/ogcapi/demolayers.d.ts +0 -1
  84. package/tools/ogcapi/demolayers.js +0 -99
  85. package/tools/ogcapi/ogcapifeaturesclientgmf.d.ts +0 -13
  86. package/tools/ogcapi/ogcapifeaturesclientgmf.js +0 -30
@@ -2,34 +2,52 @@ import { GeoJSON } from 'ol/format.js';
2
2
  import OgcApiClient from './ogcapiclient.js';
3
3
  import ServerOgcApiFeatures from '../../models/serverogcapifeatures.js';
4
4
  import { transformExtent } from 'ol/proj.js';
5
- import { OgcApiDefaultEncoding } from '../../models/serverogcapi.js';
5
+ import { OgcApiDefaultEncoding, OgcApiGeoJsonEncoding, OgcApiSchemaEncoding } from '../../models/serverogcapi.js';
6
6
  import { serverConformsTo } from './ogcapiconformance.js';
7
7
  import { reprojectGeometry } from '../utils/olutils.js';
8
- // Default coordinate reference system used by OAPIF and GeoJson: WGS84 in lon / lat
9
- const default_crs = 'EPSG:4326';
8
+ import { EditingOperations } from '../../models/oapiftypes.js';
9
+ // Is used to combine CRS definitions for horizontal and vertical systems
10
+ const compoundCrsUri = 'www.opengis.net/def/crs-compound';
10
11
  /**
11
- * Class representing an OGC API Features (OAPIF) client that interacts with a server implementing
12
- * the OGC API - Features standard. This class provides functionality to fetch, manage, and
12
+ * Class representing an OGC API Features (OAPIF) client. This client provides functionality to fetch, manage, and
13
13
  * manipulate collections and their spatial data from the server.
14
14
  *
15
15
  * Extends `OgcApiClient<ServerOgcApiFeatures>`: Provides base client functionalities.
16
16
  */
17
17
  export default class OgcApiFeaturesClient extends OgcApiClient {
18
+ // Default coordinate reference system used by OAPIF and GeoJson is OGC:CRS84, with order lon / lat or east / north,
19
+ // corresponding to OpenLayers/Proj4 code EPSG:4326.
20
+ defaultCrsCode = 'EPSG:4326';
18
21
  collections = {};
19
22
  constructor(serverConfig, opt, context) {
20
23
  super(serverConfig, opt, context.stateManager);
24
+ this.defaultPathForRelation.set('data', 'collections');
21
25
  }
22
26
  getUrl() {
23
- return this.serverOgc.urlOapif ?? '';
27
+ return this.serverOgc.services.edit?.url ?? '';
24
28
  }
25
29
  async loadDescribeServer() {
26
30
  const server = new ServerOgcApiFeatures(this.url);
31
+ await this.registerMainRelations();
27
32
  const conformance = await this.loadConformance();
28
33
  server.conformsTo = serverConformsTo(conformance);
34
+ // Register all collections with this server, note that these objects might be incomplete and miss properties
35
+ // that are available via the collection/{id} endpoint
36
+ const collections = await this.getCollections();
37
+ collections.forEach((collection) => {
38
+ server.addCollection(collection);
39
+ });
29
40
  return server;
30
41
  }
42
+ async registerMainRelations(relations) {
43
+ relations = [...(relations ?? []), 'conformance', 'data'];
44
+ await super.registerMainRelations(relations);
45
+ }
31
46
  async getCollections() {
32
- const url = `${this.url}/collections?f=json`;
47
+ const url = this.mainRelations.get('data');
48
+ if (!url) {
49
+ throw new Error("OGC API Features 'collections' end point not known");
50
+ }
33
51
  const response = await this.fetchAll(url, 'collections', this.getFetchOptions());
34
52
  if (response.length > 0 && 'collections' in response[0]) {
35
53
  return response[0]['collections'];
@@ -39,17 +57,22 @@ export default class OgcApiFeaturesClient extends OgcApiClient {
39
57
  }
40
58
  }
41
59
  /**
42
- * Retrieves a collection by its ID. If the collection is not already cached, it fetches it from the remote resource,
43
- * sanitizes its links, and stores it locally.
60
+ * Retrieves a collection by its ID. If the collection is not already cached, it is fetched, its link object is
61
+ * sanitized, and it is stored locally.
44
62
  */
45
63
  async getCollection(collectionId) {
46
64
  if (collectionId in this.collections) {
47
65
  return this.collections[collectionId];
48
66
  }
49
- const url = `${this.url}/collections/${collectionId}?f=json`;
67
+ const collectionsUrl = this.mainRelations.get('data');
68
+ if (!collectionsUrl) {
69
+ throw new Error("OGC API Features 'collections' end point not known");
70
+ }
71
+ const url = new URL(collectionsUrl);
72
+ url.pathname += `/${collectionId}`;
50
73
  const response = await fetch(url, this.getFetchOptions());
51
74
  if (!response?.ok) {
52
- throw new Error(`Failed to get collection: ${response?.status} - ${response?.statusText}`);
75
+ throw new Error(`${response?.status} - ${response?.statusText}`);
53
76
  }
54
77
  const collection = await response.json();
55
78
  // Sanitize and save to store
@@ -58,69 +81,128 @@ export default class OgcApiFeaturesClient extends OgcApiClient {
58
81
  return collection;
59
82
  }
60
83
  /**
61
- * Retrieves the schema associated with a specified collection.
84
+ * Retrieves the storage coordinate reference system for a specified collection.
85
+ * The storageCrs information is only available if the server supports part 2 of the OGC API Features specification,
86
+ * otherwise the default CRS is the only supported CRS.
62
87
  */
63
- async getSchema(collectionId) {
64
- const server = await this.getServer();
65
- if (!server.conformsTo?.ogcapi_features_simple_write) {
66
- throw new Error('OGC API Features client does not support schemas');
88
+ async getCollectionStorageCrsCode(collectionId) {
89
+ const collection = await this.getCollection(collectionId);
90
+ const storageCrsUri = collection.storageCrs;
91
+ if (storageCrsUri) {
92
+ return getEpsgCodeFromCrsUri(storageCrsUri) ?? this.defaultCrsCode;
67
93
  }
94
+ return this.defaultCrsCode;
95
+ }
96
+ /**
97
+ * Retrieves the schema (data description) associated with a specified collection.
98
+ */
99
+ async getSchema(collectionId) {
100
+ await this.checkConformanceForSchemaHandling();
68
101
  const relation = 'http://www.opengis.net/def/rel/ogc/1.0/schema'; // NOSONAR
69
- return this.getCollectionRelation(collectionId, relation, 'application/schema+json');
102
+ const url = await this.getCollectionRelationLink(collectionId, relation, OgcApiSchemaEncoding);
103
+ const response = await fetch(url, this.getFetchOptions());
104
+ if (!response?.ok) {
105
+ throw new Error(`Failed to get schema for ${collectionId}: ${response?.status} - ${response?.statusText}`);
106
+ }
107
+ return (await response.json());
70
108
  }
71
- async getQueryables(collectionId) {
72
- const server = await this.getServer();
73
- if (!server.conformsTo?.ogcapi_features_query) {
74
- throw new Error('OGC API Features client does not support querying');
109
+ /**
110
+ * Describes the layout of the geometry in the collection by analysing the collections' extent.
111
+ * If the extent has 6 entries, it's 3D geometries, otherwise it's 2D. Possible values are: 'XY' or 'XYZ'.
112
+ * Measure values (e.g. `XYZM`) aren't detected yet.
113
+ */
114
+ async getGeometryLayout(collectionId) {
115
+ const collection = await this.getCollection(collectionId);
116
+ const extent = collection.extent?.spatial?.bbox;
117
+ if (extent?.length === 4) {
118
+ return 'XY';
75
119
  }
120
+ return extent?.length === 6 ? 'XYZ' : null;
121
+ }
122
+ /**
123
+ * Checks the allowed CRUD permissions for a collection by sending an OPTIONS request to the `/items` endpoint.
124
+ * Note: Due to CORS, the `Allow` header is only accessible from JS if the server config exposes it via
125
+ * `Access-Control-Expose-Headers: Allow`.
126
+ * If the response does not contain the `Allow` header, editing is still possible, but the permissions are unknown.
127
+ */
128
+ async checkCRUDPermissions(collectionId) {
129
+ const url = await this.getCollectionRelationLink(collectionId, 'items', OgcApiGeoJsonEncoding);
130
+ try {
131
+ const response = await fetch(url, this.getFetchOptions('OPTIONS'));
132
+ const allowHeader = response?.ok ? response.headers.get('Allow') : null;
133
+ if (!allowHeader) {
134
+ return undefined;
135
+ }
136
+ const allowedMethods = new Set(allowHeader
137
+ .toUpperCase()
138
+ .split(',')
139
+ .map((method) => method.trim()));
140
+ return Object.entries(EditingOperations)
141
+ .filter(([method]) => allowedMethods.has(method))
142
+ .map(([, permission]) => permission);
143
+ }
144
+ catch {
145
+ console.warn('OPTIONS request to check editing permissions failed.');
146
+ return undefined;
147
+ }
148
+ }
149
+ /**
150
+ * Retrieves the attributes that are available for usage in queries.
151
+ */
152
+ async getQueryables(collectionId) {
153
+ await this.checkConformanceForQuerying();
76
154
  const relation = 'http://www.opengis.net/def/rel/ogc/1.0/queryables'; // NOSONAR
77
- return this.getCollectionRelation(collectionId, relation, 'application/schema+json');
155
+ const url = await this.getCollectionRelationLink(collectionId, relation, OgcApiSchemaEncoding);
156
+ const response = await fetch(url, this.getFetchOptions());
157
+ if (!response?.ok) {
158
+ throw new Error(`Failed to get queryables: ${response?.status} - ${response?.statusText}`);
159
+ }
160
+ return (await response.json());
78
161
  }
79
162
  /**
80
- * Retrieves the related resource for a specified collection and relation type (e.g. `schema`, `self`, `parent`, etc.)
163
+ * Retrieves a resource link of a specified collection, relation type (e.g. `schema`, `self`, `parent`, etc.)
164
+ * and encoding type.
81
165
  */
82
- async getCollectionRelation(collectionId, relation, encodingType = OgcApiDefaultEncoding) {
166
+ async getCollectionRelationLink(collectionId, relation, encodingType = OgcApiDefaultEncoding) {
83
167
  const collection = await this.getCollection(collectionId);
84
168
  const link = collection.links.find((link) => link.rel === relation && (!('type' in link) || link.type === encodingType))?.href;
85
169
  if (!link) {
86
- throw new Error(`OGC API collection '${collectionId}' does not support '${relation}'}`);
87
- }
88
- const response = await fetch(link, this.getFetchOptions());
89
- if (!response?.ok) {
90
- throw new Error(`Failed to get ${relation}: ${response?.status} - ${response?.statusText}`);
91
- }
92
- if (encodingType.includes('json')) {
93
- return await response.json();
94
- }
95
- else {
96
- return response;
170
+ throw new Error(`OGC API Feature collection '${collectionId}' is missing a link entry for relation '${relation}' with encoding type '${encodingType}'`);
97
171
  }
172
+ return new URL(link);
98
173
  }
99
174
  /**
100
175
  * Retrieves items from a specified collection, optionally applying filters like CRS (Coordinate Reference System),
101
176
  * spatial extent, and limit.
102
177
  */
103
- async getItems(collectionId, crsCode, extent, limit) {
104
- const url = new URL(`${this.url}/collections/${collectionId}/items?f=json`);
105
- let crsIdentifier;
106
- if (crsCode) {
107
- crsIdentifier = await this.getCrsIdentifier(collectionId, crsCode);
108
- if (crsIdentifier) {
109
- url.searchParams.append('crs', crsIdentifier);
178
+ async getItems(collectionId, options = {}) {
179
+ const url = await this.getCollectionRelationLink(collectionId, 'items', OgcApiGeoJsonEncoding);
180
+ let crsUri;
181
+ if (options.crsCode) {
182
+ crsUri = await this.getCrsUriFromEpsgCode(collectionId, options.crsCode);
183
+ if (crsUri) {
184
+ url.searchParams.set('crs', crsUri);
185
+ }
186
+ else {
187
+ console.warn(`Requesting items in CRS ${options.crsCode} is not supported by collection ${collectionId}`);
110
188
  }
111
189
  }
112
- if (extent) {
113
- extent = await this.reprojectExtentToSupportedCrs(collectionId, extent, crsCode);
114
- url.searchParams.append('bbox', extent.join(','));
115
- if (crsIdentifier) {
116
- url.searchParams.append('bbox-crs', crsIdentifier);
190
+ if (options.bbox) {
191
+ if (crsUri) {
192
+ url.searchParams.set('bbox-crs', crsUri);
193
+ url.searchParams.set('bbox', options.bbox.join(','));
194
+ }
195
+ else {
196
+ // Transform extent to default
197
+ const extent = this.reprojectExtentToDefaultCrs(options.bbox, options.crsCode);
198
+ url.searchParams.set('bbox', extent.join(','));
117
199
  }
118
200
  }
119
201
  // If no limit is set, set a very high limit. This is to overwrite very low default limits that lead to many
120
202
  // requests and long waiting times. If the server has a lower limit, it will enforce it independent of this limit.
121
- limit = limit ?? 9999;
122
- url.searchParams.append('limit', limit.toString());
123
- const responses = await this.fetchAll(url, 'features', this.getFetchOptions());
203
+ const limit = options.limit ?? 9999;
204
+ url.searchParams.set('limit', limit.toString());
205
+ const responses = await this.fetchAll(url, 'features', this.getFetchOptions('GET', OgcApiGeoJsonEncoding));
124
206
  const items = [];
125
207
  const geoJsonReader = new GeoJSON();
126
208
  responses.forEach((response) => {
@@ -128,21 +210,30 @@ export default class OgcApiFeaturesClient extends OgcApiClient {
128
210
  });
129
211
  return items;
130
212
  }
213
+ buildItemUrl(baseItemsUrl, itemId) {
214
+ const url = new URL(baseItemsUrl);
215
+ url.pathname += `/${itemId}`;
216
+ return url;
217
+ }
131
218
  /**
132
219
  * Retrieves a single item from the specified collection by its ID.
133
220
  */
134
221
  async getItem(collectionId, itemId, crsCode) {
135
- const url = new URL(`${this.url}/collections/${collectionId}/items/${itemId}?f=json`);
222
+ const baseUrl = await this.getCollectionRelationLink(collectionId, 'items', OgcApiGeoJsonEncoding);
223
+ const url = this.buildItemUrl(baseUrl, itemId);
136
224
  // Specify the request CRS
137
225
  if (crsCode) {
138
- const crsIdentifier = await this.getCrsIdentifier(collectionId, crsCode);
139
- if (crsIdentifier) {
140
- url.searchParams.append('crs', crsIdentifier);
226
+ const crsUri = await this.getCrsUriFromEpsgCode(collectionId, crsCode);
227
+ if (crsUri) {
228
+ url.searchParams.set('crs', crsUri);
229
+ }
230
+ else {
231
+ console.warn(`Requesting items in CRS ${crsCode} is not supported by collection ${collectionId}`);
141
232
  }
142
233
  }
143
- const response = await fetch(url, this.getFetchOptions());
234
+ const response = await fetch(url, this.getFetchOptions('GET', OgcApiGeoJsonEncoding));
144
235
  if (!response.ok) {
145
- throw new Error(`Failed to get item: ${response.status} - ${response.statusText}`);
236
+ throw new Error(`${response.status} - ${response.statusText}`);
146
237
  }
147
238
  const responseJson = await response.json();
148
239
  let createdItem = new GeoJSON().readFeature(responseJson);
@@ -156,35 +247,48 @@ export default class OgcApiFeaturesClient extends OgcApiClient {
156
247
  * Geometries are reprojected if the server does not support the items current CRS.
157
248
  */
158
249
  async createItem(collectionId, item, crsCode) {
159
- const url = `${this.url}/collections/${collectionId}/items`;
160
- // Reproject geometry to the collection storage CRS if necessary
161
- item = await this.reprojectItemToStorageCrs(collectionId, item, crsCode);
162
- // Add CRS header information
163
- const crsIdentifier = await this.getStorageCrs(collectionId);
164
- const fetchOptions = this.getFetchOptions('POST', crsIdentifier);
250
+ await this.checkConformsForCrudOperations();
251
+ const url = await this.getCollectionRelationLink(collectionId, 'items', OgcApiGeoJsonEncoding);
252
+ url.searchParams.delete('f');
253
+ // Handle CRS and reprojection
254
+ let crsUri;
255
+ [item, crsUri] = await this.itemReprojectionHandler(collectionId, item, crsCode);
256
+ if (crsUri) {
257
+ url.searchParams.set('crs', crsUri);
258
+ }
259
+ else {
260
+ console.warn(`Requesting items in CRS ${crsCode} is not supported by collection ${collectionId}`);
261
+ }
262
+ const fetchOptions = this.getFetchOptions('POST', OgcApiGeoJsonEncoding);
165
263
  const geoJson = new GeoJSON().writeFeatureObject(item);
166
264
  fetchOptions.body = JSON.stringify(geoJson);
167
265
  const response = await fetch(url, fetchOptions);
168
266
  if (!response.ok) {
169
- throw new Error(`Failed to create feature: ${response.status} - ${response.statusText}`);
267
+ throw new Error(`${response.status} - ${response.statusText}`);
170
268
  }
171
269
  return true;
172
270
  }
173
271
  /**
174
- * Updates an existing item in the specified collection.
272
+ * Replaces an existing item in the specified collection.
273
+ * Geometries are reprojected if the server does not support the items current CRS.
175
274
  */
176
- async updateItem(collectionId, itemId, item, crsCode) {
177
- const url = `${this.url}/collections/${collectionId}/items/${itemId}`;
178
- // Reproject geometry to the collection storage CRS if necessary
179
- item = await this.reprojectItemToStorageCrs(collectionId, item, crsCode);
180
- // Add CRS header information
181
- const crsIdentifier = await this.getStorageCrs(collectionId);
182
- const fetchOptions = this.getFetchOptions('PUT', crsIdentifier);
275
+ async replaceItem(collectionId, itemId, item, crsCode) {
276
+ await this.checkConformsForCrudOperations();
277
+ const baseUrl = await this.getCollectionRelationLink(collectionId, 'items', OgcApiGeoJsonEncoding);
278
+ const url = this.buildItemUrl(baseUrl, itemId);
279
+ url.searchParams.delete('f');
280
+ // Handle CRS and reprojection
281
+ let crsUri;
282
+ [item, crsUri] = await this.itemReprojectionHandler(collectionId, item, crsCode);
283
+ if (crsUri) {
284
+ url.searchParams.set('crs', crsUri);
285
+ }
286
+ const fetchOptions = this.getFetchOptions('PUT', OgcApiGeoJsonEncoding);
183
287
  const geoJson = new GeoJSON().writeFeatureObject(item);
184
288
  fetchOptions.body = JSON.stringify(geoJson);
185
289
  const response = await fetch(url, fetchOptions);
186
290
  if (!response.ok) {
187
- throw new Error(`Failed to update feature: ${response.status} - ${response.statusText}`);
291
+ throw new Error(`${response.status} - ${response.statusText}`);
188
292
  }
189
293
  return true;
190
294
  }
@@ -192,102 +296,124 @@ export default class OgcApiFeaturesClient extends OgcApiClient {
192
296
  * Deletes an item from a specific collection.
193
297
  */
194
298
  async deleteItem(collectionId, itemId) {
195
- const url = `${this.url}/collections/${collectionId}/items/${itemId}`;
299
+ await this.checkConformsForCrudOperations();
300
+ const baseUrl = await this.getCollectionRelationLink(collectionId, 'items', OgcApiGeoJsonEncoding);
301
+ const url = this.buildItemUrl(baseUrl, itemId);
196
302
  const fetchOptions = this.getFetchOptions('DELETE');
197
303
  const response = await fetch(url, fetchOptions);
198
304
  if (!response.ok) {
199
- throw new Error(`Failed to delete feature: ${response.status} - ${response.statusText}`);
305
+ throw new Error(`${response.status} - ${response.statusText}`);
200
306
  }
201
307
  return true;
202
308
  }
203
309
  /**
204
- * Retrieves the CRS (Coordinate Reference System) identifier for a specific collection based on the provided CRS code.
205
- * This is necessary because CRS identifiers can vary slightly (e.g. http vs https) between servers,
206
- * and it's best to use the identifiers provided by the server.
310
+ * Handles reprojection of an item to a CRS supported by the server. No transformation happens if the item's CRS is
311
+ * already supported. CRS fallbacks are:
312
+ * 1. transform item to the collections storage CRS
313
+ * 2. transform item to the OAPIF default CRS
314
+ * Precision loss may occur when reprojecting.
207
315
  */
208
- async getCrsIdentifier(collectionId, crsCode) {
209
- crsCode = crsCode.replace('EPSG:', '');
210
- // Check the supported CRS for the current collection
211
- const collection = await this.getCollection(collectionId);
212
- // If crs code is WGS84, search for default crs with identifier `CRS84`
213
- if (crsCode === '4326') {
214
- return collection.crs?.find((crs) => crs.split('/').includes('CRS84'));
215
- }
216
- else {
217
- return collection.crs?.find((crs) => crs.split('/').includes(crsCode));
316
+ async itemReprojectionHandler(collectionId, item, itemCrsCode) {
317
+ if (itemCrsCode === this.defaultCrsCode) {
318
+ return [item, undefined];
218
319
  }
219
- }
220
- getEpsgCodeFromCrsIdentifier(crsIdentifier) {
221
- if (crsIdentifier.includes('CRS84')) {
222
- return 'EPSG:4326';
320
+ const crsUri = await this.getCrsUriFromEpsgCode(collectionId, itemCrsCode);
321
+ if (crsUri) {
322
+ // Item CRS is supported, no reprojection needed
323
+ return [item, crsUri];
223
324
  }
224
- else {
225
- return `EPSG:${crsIdentifier.trim().split('/').reverse()[0] ?? 4326}`;
325
+ console.warn(`CRS code ${itemCrsCode} not supported by collection ${collectionId}, item will be reprojected.
326
+ Precision loss may occur.`);
327
+ // Fallback 1: transform item to storage CRS
328
+ const storageCrsCode = await this.getCollectionStorageCrsCode(collectionId);
329
+ const itemInStorageCrs = this.reprojectItem(item, itemCrsCode, storageCrsCode);
330
+ if (itemInStorageCrs) {
331
+ const storageCrsUri = await this.getCrsUriFromEpsgCode(collectionId, storageCrsCode);
332
+ return [itemInStorageCrs, storageCrsUri];
226
333
  }
227
- }
228
- /**
229
- * Checks if the provided extent's coordinate reference system (CRS) is supported by a given collection
230
- * and reprojects the extent if necessary.
231
- */
232
- async reprojectExtentToSupportedCrs(collectionId, extent, crsCode = default_crs) {
233
- const crsIdentifier = await this.getCrsIdentifier(collectionId, crsCode);
234
- if (!crsIdentifier) {
235
- // If the current extent's CRS isn't supported, we reproject to the default CRS WGS84
236
- extent = transformExtent(extent, this.state.projection, default_crs);
334
+ // Fallback 2: transform item to the OAPIF default CRS
335
+ if (storageCrsCode !== this.defaultCrsCode) {
336
+ const defaultCrsUri = await this.getCrsUriFromEpsgCode(collectionId, this.defaultCrsCode);
337
+ const itemInDefaultCrs = this.reprojectItem(item, itemCrsCode, this.defaultCrsCode);
338
+ return [itemInDefaultCrs ?? item, defaultCrsUri];
237
339
  }
238
- return extent;
340
+ return [item, undefined];
239
341
  }
240
342
  /**
241
- * Retrieves the storage coordinate reference system (CRS) for a specified collection.
242
- * The storageCrs information is only available if the server supports part 2 of the OGC API Features specification.
343
+ * Retrieves the CRS URI identifier based on the provided CRS code. Getting the identifier from the server is more
344
+ * reliable because CRS URIs can vary slightly (e.g. http vs. https) between servers.
345
+ * Note: EPSG:4326 and OGC:CRS84 technically differ in their coordinate order: CRS84 is lon / lat (east / north),
346
+ * while EPSG:4326 is lat / lon (north / east). However, since Openlayers uses EPSG:4326 with lon / lat
347
+ * coordinate order, we can use EPSG:4326 as the default CRS code.
243
348
  */
244
- async getStorageCrs(collectionId) {
245
- // Check the supported CRS for the current collection
349
+ async getCrsUriFromEpsgCode(collectionId, crsCode) {
350
+ crsCode = crsCode.replace('EPSG:', '');
246
351
  const collection = await this.getCollection(collectionId);
247
- let storageCrs;
248
- if (collection.storageCrs) {
249
- storageCrs = collection.storageCrs;
250
- }
251
- else {
252
- storageCrs = await this.getCrsIdentifier(collectionId, default_crs);
253
- }
254
- if (!storageCrs) {
255
- throw new Error('Not able to save feature: The OAPIF server does not specify a storage coordinate reference system (crs) ' +
256
- 'and also does not support the default WGS84.');
352
+ if (crsCode === '4326') {
353
+ return collection.crs?.find((crs) => crs.split('/').includes('CRS84'));
257
354
  }
258
- return storageCrs;
355
+ return collection.crs?.find((crs) => crs.split('/').includes(crsCode));
356
+ }
357
+ reprojectExtentToDefaultCrs(extent, crsCode = this.defaultCrsCode) {
358
+ return transformExtent(extent, crsCode, this.defaultCrsCode);
259
359
  }
260
360
  /**
261
- * When performing a write operation, reproject the feature geometry to match the storage coordinate reference system
262
- * (CRS) of the server. If no storage CRS is specified, geometries are reprojected to WGS84 lon / lat,
263
- * which is the default CRS for OAPIF and GeoJson.
361
+ * Reproject the item geometry to a coordinate reference system supported by the server to allow write operations.
362
+ * Will throw an error if the reprojection fails.
264
363
  */
265
- async reprojectItemToStorageCrs(collectionId, item, itemCrsCode) {
266
- // if no storage crs is specified, defaults to default_crs
267
- const storageCrs = await this.getStorageCrs(collectionId);
268
- const storageEpsgCode = this.getEpsgCodeFromCrsIdentifier(storageCrs);
269
- // If the current crs doesn't fit the storage coordinate system, reproject the item geometry
364
+ reprojectItem(item, sourceCrsCode, targetCrsCode) {
270
365
  const geometry = item.getGeometry();
271
- if (itemCrsCode !== storageEpsgCode && geometry) {
272
- const reprojectedGeometry = reprojectGeometry(geometry, itemCrsCode, storageEpsgCode);
273
- item.setGeometry(reprojectedGeometry);
366
+ // If the source CRS differs from the target coordinate system, reproject the item geometry
367
+ if (sourceCrsCode !== targetCrsCode && geometry) {
368
+ const reprojectedGeometry = reprojectGeometry(geometry, sourceCrsCode, targetCrsCode);
369
+ const transformedItem = item.clone();
370
+ transformedItem.setGeometry(reprojectedGeometry);
371
+ return transformedItem;
274
372
  }
275
373
  return item;
276
374
  }
277
375
  /**
278
- * Expands the method from OgcApiClient by customizing headers to support GeoJson content and optional CRS identifier.
376
+ * Expands the method from OgcApiClient by customizing headers to support GeoJson content.
279
377
  */
280
- getFetchOptions(method = 'GET', crsIdentifier) {
378
+ getFetchOptions(method = 'GET', acceptType = OgcApiDefaultEncoding) {
281
379
  const fetchOptions = super.getFetchOptions(method);
282
- // Add header info about the request body
380
+ const headers = new Headers(fetchOptions?.headers);
381
+ headers.set('Accept', acceptType);
382
+ // Add header info specifying the request body encoding
283
383
  if (['PUT', 'POST'].includes(method)) {
284
- const headers = new Headers(fetchOptions?.headers);
285
- headers.set('Content-Type', 'application/geo+json');
286
- if (crsIdentifier) {
287
- headers.set('Content-Crs', crsIdentifier);
288
- }
289
- fetchOptions.headers = headers;
384
+ headers.set('Content-Type', OgcApiGeoJsonEncoding);
290
385
  }
386
+ fetchOptions.headers = headers;
291
387
  return fetchOptions;
292
388
  }
389
+ async checkConformanceForSchemaHandling() {
390
+ const server = await this.getServer();
391
+ if (!server.conformsTo?.ogcapi_features_schema) {
392
+ throw new Error(`Client ${server.url} does not support schemas, attribute editing not possible`);
393
+ }
394
+ }
395
+ async checkConformanceForQuerying() {
396
+ const server = await this.getServer();
397
+ if (!server.conformsTo?.ogcapi_features_query) {
398
+ throw new Error(`Client ${server.url} does not support querying`);
399
+ }
400
+ }
401
+ async checkConformsForCrudOperations() {
402
+ const server = await this.getServer();
403
+ if (!server.conformsTo?.ogcapi_features_write) {
404
+ throw new Error(`Client ${server.url} does not support create / replace / update / delete operations`);
405
+ }
406
+ }
293
407
  }
408
+ export const getEpsgCodeFromCrsUri = (crsUri) => {
409
+ if (crsUri.includes(compoundCrsUri)) {
410
+ console.warn('Compound CRS URIs are not supported, falling back to first CRS in URI.');
411
+ const uriAsUrl = new URL(crsUri);
412
+ crsUri = uriAsUrl.searchParams.get('1') ?? '';
413
+ }
414
+ if (crsUri.includes('CRS84')) {
415
+ return 'EPSG:4326';
416
+ }
417
+ const code = crsUri.trim().split('/').reverse()[0];
418
+ return code && !Number.isNaN(code) ? `EPSG:${code}` : undefined;
419
+ };
@@ -1,12 +1,7 @@
1
1
  import OgcApiFeaturesClient from './ogcapifeaturesclient.js';
2
2
  import ServerOgc from '../../models/serverogc.js';
3
- import { OapifCollection } from '../../models/serverogcapifeatures.js';
4
3
  import IGirafeContext from '../context/icontext.js';
5
4
  import { OgcApiClientOptions } from './ogcapiclient.js';
6
5
  export default class OgcApiFeaturesClientGeorama extends OgcApiFeaturesClient {
7
6
  constructor(serverConfig: ServerOgc, opt: OgcApiClientOptions, context: IGirafeContext);
8
- /**
9
- * POC overwrite: Upper/lowercase issues with collection property `storageCrs`: pygeoapi uses `storageCRS`.
10
- */
11
- getCollection(collectionId: string): Promise<OapifCollection>;
12
7
  }
@@ -4,15 +4,4 @@ export default class OgcApiFeaturesClientGeorama extends OgcApiFeaturesClient {
4
4
  constructor(serverConfig, opt, context) {
5
5
  super(serverConfig, opt, context);
6
6
  }
7
- /**
8
- * POC overwrite: Upper/lowercase issues with collection property `storageCrs`: pygeoapi uses `storageCRS`.
9
- */
10
- async getCollection(collectionId) {
11
- const collection = await super.getCollection(collectionId);
12
- if (Object.keys(collection).includes('storageCRS')) {
13
- // @ts-expect-error Wrong property name form server
14
- collection.storageCrs = collection.storageCRS;
15
- }
16
- return collection;
17
- }
18
7
  }
@@ -0,0 +1,8 @@
1
+ import OgcApiFeaturesClient from './ogcapifeaturesclient.js';
2
+ import ServerOgc from '../../models/serverogc.js';
3
+ import IGirafeContext from '../context/icontext.js';
4
+ import { OgcApiClientOptions } from './ogcapiclient.js';
5
+ export default class OgcApiFeaturesClientQgis extends OgcApiFeaturesClient {
6
+ constructor(serverConfig: ServerOgc, opt: OgcApiClientOptions, context: IGirafeContext);
7
+ protected buildItemUrl(baseItemsUrl: URL, itemId: string): URL;
8
+ }
@@ -0,0 +1,13 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import OgcApiFeaturesClient from './ogcapifeaturesclient.js';
3
+ export default class OgcApiFeaturesClientQgis extends OgcApiFeaturesClient {
4
+ constructor(serverConfig, opt, context) {
5
+ super(serverConfig, opt, context);
6
+ }
7
+ buildItemUrl(baseItemsUrl, itemId) {
8
+ const url = new URL(baseItemsUrl);
9
+ url.pathname = url.pathname.replace('.geojson', '');
10
+ url.pathname += `/${itemId}.geojson`;
11
+ return url;
12
+ }
13
+ }