UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

31 lines (30 loc) 1.27 kB
// SPDX-License-Identifier: Apache-2.0 import GirafeSingleton from '../base/GirafeSingleton.js'; import LayerWms from '../models/layers/layerwms.js'; export default class VendorSpecificOgcServerManager extends GirafeSingleton { _clientClasses = new Map(); _clients = new Map(); createClient(clientClass, ogcServer) { return new clientClass(ogcServer, {}, this.context); } // Register a client with an identifier registerClientClass(type, clientClass) { this._clientClasses.set(type, clientClass); } getClient(object) { const ogcServer = object instanceof LayerWms ? object.ogcServer : object; const type = ogcServer.type; const clientId = this.getClientId(ogcServer); 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: ${ogcServer}. `); clientClass = this._clientClasses.get('default'); } client = this.createClient(clientClass, ogcServer); this._clients.set(clientId, client); } return client; } }