@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
45 lines (44 loc) • 1.68 kB
JavaScript
import GirafeSingleton from '../../base/GirafeSingleton';
export default class OgcApiManager extends GirafeSingleton {
constructor() {
super(...arguments);
Object.defineProperty(this, "_clientClasses", {
enumerable: true,
configurable: true,
writable: true,
value: new Map()
});
Object.defineProperty(this, "_clients", {
enumerable: true,
configurable: true,
writable: true,
value: new Map()
});
}
createClient(clientClass, server) {
return new clientClass(server, {});
}
// Register a client with an identifier
registerClientClass(type, clientClass) {
this._clientClasses.set(type, clientClass);
}
// Get a client based on the identifier
getClient(server) {
// public getClient(layer: LayerOapif): OgcApiClient
// public getClient(object: ServerOgcApi | LayerOapif): OgcApiClient
// const server = object instanceof ServerOgcApi ? object.type : object;
const type = server.type;
const clientId = this.getClientId(server);
let client = this._clients.get(clientId);
if (!client) {
let clientClass = this._clientClasses.get(type);
if (!clientClass) {
console.info(`Client not found for ogcServer with type: ${type}. Using default client. ogcServer: ${server}. `);
clientClass = this._clientClasses.get('default');
}
client = this.createClient(clientClass, server);
this._clients.set(clientId, client);
}
return client;
}
}