UNPKG

@loaders.gl/wms

Version:

Framework-independent loaders for the WMS (Web Map Service) standard

44 lines (43 loc) 1.53 kB
// loaders.gl // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors import { parseWMSError } from "./lib/parsers/wms/parse-wms-error.js"; // __VERSION__ is injected by babel-plugin-version-inline // @ts-ignore TS2304: Cannot find name '__VERSION__'. const VERSION = typeof "4.3.3" !== 'undefined' ? "4.3.3" : 'latest'; /** * Loader for the response to the WMS GetCapability request */ export const WMSErrorLoader = { dataType: null, batchType: null, id: 'wms-error', name: 'WMS Error', module: 'wms', version: VERSION, worker: false, extensions: ['xml'], mimeTypes: ['application/vnd.ogc.se_xml', 'application/xml', 'text/xml'], testText: testXMLFile, options: { wms: { throwOnError: false } }, parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options), parseSync: (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options), parseTextSync: (text, options) => parseTextSync(text, options) }; function testXMLFile(text) { // TODO - There could be space first. return text.startsWith('<?xml'); } function parseTextSync(text, options) { const wmsOptions = { ...WMSErrorLoader.options.wms, ...options?.wms }; const error = parseWMSError(text, wmsOptions); const message = wmsOptions.minimalErrors ? error : `WMS Service error: ${error}`; if (wmsOptions.throwOnError) { throw new Error(message); } return message; }