UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

58 lines (57 loc) 1.9 kB
function sameUrlAndImageTypeForAll(layers) { if (layers.length === 0) { return [true, true]; } const url = layers[0].ogcServer.url; const imageType = layers[0].ogcServer.imageType; let sameUrlForAll = true; let sameImageTypeForAll = true; for (const layer of layers) { sameUrlForAll = sameUrlForAll && layer.ogcServer.url === url; sameImageTypeForAll = sameImageTypeForAll && layer.ogcServer.imageType === imageType; } if (!sameUrlForAll) { throw new Error('Not all layers of this list have the same server URL.'); } if (!sameImageTypeForAll) { throw new Error('Not all layers of this list have the same image type.'); } return [sameUrlForAll, sameImageTypeForAll]; } /** Selection parameters defined by: * - 1 ogc Sever * - a list of layers * - a selection box OR a WFS query */ export default class SelectionParam { _ogcServer; get ogcServer() { return this._ogcServer; } _layers; get layers() { return this._layers; } _oLayer; get oLayer() { return this._oLayer; } srid; selectionBox; selectionQuery; constructor(ogcServer, layers, srid, selectionBox, oLayer, selectionQuery) { this._ogcServer = ogcServer; this._layers = layers; this.srid = srid; this.selectionBox = selectionBox; this._oLayer = oLayer; this.selectionQuery = selectionQuery; if (!this.selectionBox && !this.selectionQuery) { throw new Error('SelectionParam needs either a `selectionBox` or a `selectionQuery` parameter.'); } sameUrlAndImageTypeForAll(this.layers); } clone(layerFilter = () => true) { return new SelectionParam(this._ogcServer, this._layers.filter(layerFilter), this.srid, this.selectionBox, this._oLayer, this.selectionQuery); } }