UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

109 lines (108 loc) 3.74 kB
import OgcApiFeaturesClient from './ogcapifeaturesclient.js'; import OgcApiFeaturesClientGeorama from './ogcapifeaturesclientgeorama.js'; import OgcApiFeaturesClientGmf from './ogcapifeaturesclientgmf.js'; import LayerWms from '../../models/layers/layerwms.js'; import OgcApiFeaturesSchema from './ogcapifeaturesschema.js'; import VendorSpecificOgcServerManager from '../vendorspecificogcservermanager.js'; /** * Manages interaction between the GG and an OGC API Features client (OAPIF). */ export default class OgcApiFeaturesManager extends VendorSpecificOgcServerManager { get state() { return this.context.stateManager.state; } getClientId(ogcServer) { return ogcServer.urlOapif ?? ''; } initializeSingleton() { // Register the clients this.registerClientClass('default', OgcApiFeaturesClient); this.registerClientClass('georama', OgcApiFeaturesClientGeorama); this.registerClientClass('gmf', OgcApiFeaturesClientGmf); } async getSchema(layer) { this.state.loading = true; try { const schema = await this.getClient(layer.server).getSchema(layer.collectionId); return new OgcApiFeaturesSchema(schema); } catch (e) { throw new Error(`Unable to get schema: ${e}`, { cause: e }); } finally { this.state.loading = false; } } async getItems(layer, crs, bbox, limit) { this.state.loading = true; try { return await this.getClient(layer.server).getItems(layer.collectionId, crs, bbox, limit); } catch { return []; } finally { this.state.loading = false; } } async getItem(layer, featureId) { this.state.loading = true; try { return await this.getClient(layer.server).getItem(layer.collectionId, featureId, this.state.projection); } catch { return undefined; } finally { this.state.loading = false; } } async createItem(layer, feature) { this.state.loading = true; try { return await this.getClient(layer.server).createItem(layer.collectionId, feature, this.state.projection); } catch { void window.gAlert('Failed to create feature', 'Error'); return false; } finally { this.state.loading = false; } } async updateItem(layer, featureId, feature) { this.state.loading = true; try { return await this.getClient(layer.server).updateItem(layer.collectionId, featureId, feature, this.state.projection); } catch { void window.gAlert('Failed to update feature', 'Error'); return false; } finally { this.state.loading = false; } } async deleteItem(layer, featureId) { this.state.loading = true; try { return await this.getClient(layer.server).deleteItem(layer.collectionId, featureId); } catch { void window.gAlert('Failed to delete feature', 'Error'); return false; } finally { this.state.loading = false; } } async getServer(object) { const ogcServer = object instanceof LayerWms ? object.ogcServer : object; const client = this.getClient(ogcServer); return client.getServer(); } async getCollectionByTitle(title, server) { const collections = await this.getClient(server).getCollections(); return collections.find((collection) => collection.title === title) ?? null; } }