@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
114 lines (113 loc) • 3.79 kB
JavaScript
import StateManager from '../state/statemanager';
import OgcApiFeaturesClient from './ogcapifeaturesclient';
import OgcApiFeaturesClientGeorama from './ogcapifeaturesclientgeorama';
import OgcApiFeaturesClientGmf from './ogcapifeaturesclientgmf';
import LayerWms from '../../models/layers/layerwms';
import OgcApiFeaturesSchema from './ogcapifeaturesschema';
import VendorSpecificOgcServerManager from '../vendorspecificogcservermanager';
/**
* Manages interaction between the GG and an OGC API Features client (OAPIF).
*/
export default class OgcApiFeaturesManager extends VendorSpecificOgcServerManager {
get state() {
return this.stateManager.state;
}
getClientId(ogcServer) {
return ogcServer.urlOapif ?? '';
}
constructor(type) {
super(type);
Object.defineProperty(this, "stateManager", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.stateManager = StateManager.getInstance();
// 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}`);
}
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();
}
}