UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

105 lines (104 loc) 3.28 kB
import StateManager from '../state/statemanager'; import OgcApiFeaturesClient from './ogcapifeaturesclient'; import OgcApiManager from './ogcapimanager'; import OgcApiFeaturesClientGeorama from './ogcapifeaturesclientgeorama'; import OgcApiFeaturesClientGmf from './ogcapifeaturesclientgmf'; /** * Manages interaction between the app and an OGC API Features client (Oapif). */ export default class OgcApiFeaturesManager extends OgcApiManager { get state() { return this.stateManager.state; } constructor(type) { super(type); Object.defineProperty(this, "stateManager", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.stateManager = StateManager.getInstance(); // Register the default client this.registerClientClass('default', OgcApiFeaturesClient); this.registerClientClass('georama', OgcApiFeaturesClientGeorama); this.registerClientClass('gmf', OgcApiFeaturesClientGmf); } getClientId(server) { return server.url ?? ''; } async getItemTemplate(layer) { this.state.loading = true; try { const queryables = await this.getClient(layer.server).getQueryables(layer.collectionId); if (queryables?.properties) { return Object.fromEntries(Object.entries(queryables?.properties) .filter(([key]) => !['id', 'geometry'].includes(key)) .map(([key]) => [key, null])); } else { return {}; } } catch { return {}; } finally { this.state.loading = false; } } async getItems(layer, bbox, bboxCrs) { this.state.loading = true; try { return await this.getClient(layer.server).getItems(layer.collectionId, bbox, bboxCrs); } 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, layer.crs); } 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); } catch { 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); } finally { this.state.loading = false; } } async deleteItem(layer, featureId) { this.state.loading = true; try { await this.getClient(layer.server).deleteItem(layer.collectionId, featureId); } finally { this.state.loading = false; } } }