@loaders.gl/wms
Advanced tools
Comparing version 4.2.0-alpha.4 to 4.2.0-alpha.5
import type { LoaderWithParser } from '@loaders.gl/loader-utils'; | ||
import type { XMLLoaderOptions } from '@loaders.gl/xml'; | ||
import type { CSWCapabilities } from './lib/parsers/csw/parse-csw-capabilities'; | ||
import type { CSWCapabilities } from "./lib/parsers/csw/parse-csw-capabilities.js"; | ||
export type { CSWCapabilities }; | ||
@@ -5,0 +5,0 @@ /** CSW loader options */ |
@@ -0,21 +1,29 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { parseCSWCapabilities } from "./lib/parsers/csw/parse-csw-capabilities.js"; | ||
// __VERSION__ is injected by babel-plugin-version-inline | ||
// @ts-ignore TS2304: Cannot find name '__VERSION__'. | ||
const VERSION = typeof "4.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest'; | ||
/** | ||
* Loader for the response to the CSW GetCapability request | ||
*/ | ||
export const CSWCapabilitiesLoader = { | ||
id: 'csw-capabilities', | ||
name: 'CSW Capabilities', | ||
module: 'wms', | ||
version: VERSION, | ||
worker: false, | ||
extensions: ['xml'], | ||
mimeTypes: ['application/vnd.ogc.csw_xml', 'application/xml', 'text/xml'], | ||
testText: testXMLFile, | ||
options: { | ||
csw: {} | ||
}, | ||
parse: async (arrayBuffer, options) => parseCSWCapabilities(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseCSWCapabilities(text, options) | ||
id: 'csw-capabilities', | ||
name: 'CSW Capabilities', | ||
module: 'wms', | ||
version: VERSION, | ||
worker: false, | ||
extensions: ['xml'], | ||
mimeTypes: ['application/vnd.ogc.csw_xml', 'application/xml', 'text/xml'], | ||
testText: testXMLFile, | ||
options: { | ||
csw: {} | ||
}, | ||
parse: async (arrayBuffer, options) => parseCSWCapabilities(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseCSWCapabilities(text, options) | ||
}; | ||
function testXMLFile(text) { | ||
return text.startsWith('<?xml'); | ||
// TODO - There could be space first. | ||
return text.startsWith('<?xml'); | ||
} | ||
//# sourceMappingURL=csw-capabilities-loader.js.map |
import type { LoaderWithParser } from '@loaders.gl/loader-utils'; | ||
import type { XMLLoaderOptions } from '@loaders.gl/xml'; | ||
import type { CSWDomain } from './lib/parsers/csw/parse-csw-domain'; | ||
import type { CSWDomain } from "./lib/parsers/csw/parse-csw-domain.js"; | ||
export type { CSWDomain }; | ||
@@ -5,0 +5,0 @@ export type CSWLoaderOptions = XMLLoaderOptions & { |
@@ -0,21 +1,29 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { parseCSWDomain } from "./lib/parsers/csw/parse-csw-domain.js"; | ||
// __VERSION__ is injected by babel-plugin-version-inline | ||
// @ts-ignore TS2304: Cannot find name '__VERSION__'. | ||
const VERSION = typeof "4.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest'; | ||
/** | ||
* Loader for the response to the CSW GetCapability request | ||
*/ | ||
export const CSWDomainLoader = { | ||
id: 'csw-domain', | ||
name: 'CSW Domain', | ||
module: 'wms', | ||
version: VERSION, | ||
worker: false, | ||
extensions: ['xml'], | ||
mimeTypes: ['application/vnd.ogc.csw_xml', 'application/xml', 'text/xml'], | ||
testText: testXMLFile, | ||
options: { | ||
csw: {} | ||
}, | ||
parse: async (arrayBuffer, options) => parseCSWDomain(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseCSWDomain(text, options) | ||
id: 'csw-domain', | ||
name: 'CSW Domain', | ||
module: 'wms', | ||
version: VERSION, | ||
worker: false, | ||
extensions: ['xml'], | ||
mimeTypes: ['application/vnd.ogc.csw_xml', 'application/xml', 'text/xml'], | ||
testText: testXMLFile, | ||
options: { | ||
csw: {} | ||
}, | ||
parse: async (arrayBuffer, options) => parseCSWDomain(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseCSWDomain(text, options) | ||
}; | ||
function testXMLFile(text) { | ||
return text.startsWith('<?xml'); | ||
// TODO - There could be space first. | ||
return text.startsWith('<?xml'); | ||
} | ||
//# sourceMappingURL=csw-domain-loader.js.map |
import type { LoaderWithParser } from '@loaders.gl/loader-utils'; | ||
import type { XMLLoaderOptions } from '@loaders.gl/xml'; | ||
import type { CSWRecords } from './lib/parsers/csw/parse-csw-records'; | ||
import type { CSWRecords } from "./lib/parsers/csw/parse-csw-records.js"; | ||
export { CSWRecords }; | ||
@@ -5,0 +5,0 @@ export type CSWLoaderOptions = XMLLoaderOptions & { |
@@ -0,21 +1,29 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { parseCSWRecords } from "./lib/parsers/csw/parse-csw-records.js"; | ||
// __VERSION__ is injected by babel-plugin-version-inline | ||
// @ts-ignore TS2304: Cannot find name '__VERSION__'. | ||
const VERSION = typeof "4.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest'; | ||
/** | ||
* Loader for the response to the CSW GetCapability request | ||
*/ | ||
export const CSWRecordsLoader = { | ||
id: 'csw-records', | ||
name: 'CSW Records', | ||
module: 'wms', | ||
version: VERSION, | ||
worker: false, | ||
extensions: ['xml'], | ||
mimeTypes: ['application/vnd.ogc.csw_xml', 'application/xml', 'text/xml'], | ||
testText: testXMLFile, | ||
options: { | ||
csw: {} | ||
}, | ||
parse: async (arrayBuffer, options) => parseCSWRecords(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseCSWRecords(text, options) | ||
id: 'csw-records', | ||
name: 'CSW Records', | ||
module: 'wms', | ||
version: VERSION, | ||
worker: false, | ||
extensions: ['xml'], | ||
mimeTypes: ['application/vnd.ogc.csw_xml', 'application/xml', 'text/xml'], | ||
testText: testXMLFile, | ||
options: { | ||
csw: {} | ||
}, | ||
parse: async (arrayBuffer, options) => parseCSWRecords(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseCSWRecords(text, options) | ||
}; | ||
function testXMLFile(text) { | ||
return text.startsWith('<?xml'); | ||
// TODO - There could be space first. | ||
return text.startsWith('<?xml'); | ||
} | ||
//# sourceMappingURL=csw-records-loader.js.map |
import type { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils'; | ||
import type { Geometry } from './lib/parsers/gml/parse-gml'; | ||
import type { Geometry } from "./lib/parsers/gml/parse-gml.js"; | ||
export type GMLLoaderOptions = LoaderOptions & { | ||
@@ -4,0 +4,0 @@ gml?: {}; |
@@ -0,21 +1,29 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { parseGML } from "./lib/parsers/gml/parse-gml.js"; | ||
// __VERSION__ is injected by babel-plugin-version-inline | ||
// @ts-ignore TS2304: Cannot find name '__VERSION__'. | ||
const VERSION = typeof "4.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest'; | ||
/** | ||
* Loader for the response to the GML GetCapability request | ||
*/ | ||
export const GMLLoader = { | ||
name: 'GML', | ||
id: 'gml', | ||
module: 'wms', | ||
version: VERSION, | ||
worker: false, | ||
extensions: ['xml'], | ||
mimeTypes: ['application/vnd.ogc.gml', 'application/xml', 'text/xml'], | ||
testText: testXMLFile, | ||
options: { | ||
gml: {} | ||
}, | ||
parse: async (arrayBuffer, options) => parseGML(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseGML(text, options) | ||
name: 'GML', | ||
id: 'gml', | ||
module: 'wms', | ||
version: VERSION, | ||
worker: false, | ||
extensions: ['xml'], | ||
mimeTypes: ['application/vnd.ogc.gml', 'application/xml', 'text/xml'], | ||
testText: testXMLFile, | ||
options: { | ||
gml: {} | ||
}, | ||
parse: async (arrayBuffer, options) => parseGML(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseGML(text, options) | ||
}; | ||
function testXMLFile(text) { | ||
return text.startsWith('<?xml'); | ||
// TODO - There could be space first. | ||
return text.startsWith('<?xml'); | ||
} | ||
//# sourceMappingURL=gml-loader.js.map |
@@ -1,34 +0,34 @@ | ||
export type { CSWLoaderOptions } from './csw-capabilities-loader'; | ||
export type { CSWCapabilities } from './csw-capabilities-loader'; | ||
export { CSWCapabilitiesLoader } from './csw-capabilities-loader'; | ||
export type { CSWDomain } from './csw-domain-loader'; | ||
export { CSWDomainLoader } from './csw-domain-loader'; | ||
export type { CSWRecords } from './csw-records-loader'; | ||
export { CSWRecordsLoader } from './csw-records-loader'; | ||
export { WMSErrorLoader } from './wms-error-loader'; | ||
export type { WMSCapabilities, WMSLayer, WMSBoundingBox, WMSDimension } from './wms-capabilities-loader'; | ||
export type { WMSCapabilitiesLoaderOptions } from './wms-capabilities-loader'; | ||
export { WMSCapabilitiesLoader } from './wms-capabilities-loader'; | ||
export type { WMSFeatureInfo as _WMSFeatureInfo } from './wip/wms-feature-info-loader'; | ||
export { WMSFeatureInfoLoader as _WMSFeatureInfoLoader } from './wip/wms-feature-info-loader'; | ||
export type { WMSLayerDescription as _WMSLayerDescription } from './wip/wms-layer-description-loader'; | ||
export { WMSLayerDescriptionLoader as _WMSLayerDescriptionLoader } from './wip/wms-layer-description-loader'; | ||
export type { WFSLoaderOptions as _WFSLoaderOptions } from './wip/wfs-capabilities-loader'; | ||
export type { WFSCapabilities as _WFSCapabilities } from './wip/wfs-capabilities-loader'; | ||
export { WFSCapabilitiesLoader as _WFSCapabilitiesLoader } from './wip/wfs-capabilities-loader'; | ||
export type { CSWLoaderOptions } from "./csw-capabilities-loader.js"; | ||
export type { CSWCapabilities } from "./csw-capabilities-loader.js"; | ||
export { CSWCapabilitiesLoader } from "./csw-capabilities-loader.js"; | ||
export type { CSWDomain } from "./csw-domain-loader.js"; | ||
export { CSWDomainLoader } from "./csw-domain-loader.js"; | ||
export type { CSWRecords } from "./csw-records-loader.js"; | ||
export { CSWRecordsLoader } from "./csw-records-loader.js"; | ||
export { WMSErrorLoader } from "./wms-error-loader.js"; | ||
export type { WMSCapabilities, WMSLayer, WMSBoundingBox, WMSDimension } from "./wms-capabilities-loader.js"; | ||
export type { WMSCapabilitiesLoaderOptions } from "./wms-capabilities-loader.js"; | ||
export { WMSCapabilitiesLoader } from "./wms-capabilities-loader.js"; | ||
export type { WMSFeatureInfo as _WMSFeatureInfo } from "./wip/wms-feature-info-loader.js"; | ||
export { WMSFeatureInfoLoader as _WMSFeatureInfoLoader } from "./wip/wms-feature-info-loader.js"; | ||
export type { WMSLayerDescription as _WMSLayerDescription } from "./wip/wms-layer-description-loader.js"; | ||
export { WMSLayerDescriptionLoader as _WMSLayerDescriptionLoader } from "./wip/wms-layer-description-loader.js"; | ||
export type { WFSLoaderOptions as _WFSLoaderOptions } from "./wip/wfs-capabilities-loader.js"; | ||
export type { WFSCapabilities as _WFSCapabilities } from "./wip/wfs-capabilities-loader.js"; | ||
export { WFSCapabilitiesLoader as _WFSCapabilitiesLoader } from "./wip/wfs-capabilities-loader.js"; | ||
export type { GeoJSON as _GeoJSON } from '@loaders.gl/schema'; | ||
export type { GMLLoaderOptions as _GMLLoaderOptions } from './gml-loader'; | ||
export { GMLLoader as _GMLLoader } from './gml-loader'; | ||
export type { GMLLoaderOptions as _GMLLoaderOptions } from "./gml-loader.js"; | ||
export { GMLLoader as _GMLLoader } from "./gml-loader.js"; | ||
export { ImageSource } from '@loaders.gl/loader-utils'; | ||
export type { ImageType } from '@loaders.gl/images'; | ||
export type { CreateImageServiceProps } from './lib/services/create-image-service'; | ||
export { createImageService } from './lib/services/create-image-service'; | ||
export type { ImageServiceType } from './services/create-image-source'; | ||
export { createImageSource } from './services/create-image-source'; | ||
export type { ImageServiceProps } from './lib/services/image-service'; | ||
export { ImageService } from './lib/services/image-service'; | ||
export { CSWService } from './services/ogc/csw-service'; | ||
export { WMSSource, WMSService } from './services/ogc/wms-service'; | ||
export { getArcGISServices as _getArcGISServices } from './services/arcgis/arcgis-server'; | ||
export { ArcGISImageService as _ArcGISImageService } from './services/arcgis/arcgis-image-service'; | ||
export type { CreateImageServiceProps } from "./lib/services/create-image-service.js"; | ||
export { createImageService } from "./lib/services/create-image-service.js"; | ||
export type { ImageServiceType } from "./services/create-image-source.js"; | ||
export { createImageSource } from "./services/create-image-source.js"; | ||
export type { ImageServiceProps } from "./lib/services/image-service.js"; | ||
export { ImageService } from "./lib/services/image-service.js"; | ||
export { CSWService } from "./services/ogc/csw-service.js"; | ||
export { WMSSource, WMSService } from "./services/ogc/wms-service.js"; | ||
export { getArcGISServices as _getArcGISServices } from "./services/arcgis/arcgis-server.js"; | ||
export { ArcGISImageService as _ArcGISImageService } from "./services/arcgis/arcgis-image-service.js"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,4 +1,8 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
export { CSWCapabilitiesLoader } from "./csw-capabilities-loader.js"; | ||
export { CSWDomainLoader } from "./csw-domain-loader.js"; | ||
export { CSWRecordsLoader } from "./csw-records-loader.js"; | ||
// WMS - Web Map Service | ||
export { WMSErrorLoader } from "./wms-error-loader.js"; | ||
@@ -10,2 +14,4 @@ export { WMSCapabilitiesLoader } from "./wms-capabilities-loader.js"; | ||
export { GMLLoader as _GMLLoader } from "./gml-loader.js"; | ||
// EXPERIMENTAL: DATA SOURCES | ||
// TODO - restore once deck.gl has been udpated | ||
export { ImageSource } from '@loaders.gl/loader-utils'; | ||
@@ -15,6 +21,7 @@ export { createImageService } from "./lib/services/create-image-service.js"; | ||
export { ImageService } from "./lib/services/image-service.js"; | ||
// OGC Services | ||
export { CSWService } from "./services/ogc/csw-service.js"; | ||
export { WMSSource, WMSService } from "./services/ogc/wms-service.js"; | ||
// ArcGIS Services | ||
export { getArcGISServices as _getArcGISServices } from "./services/arcgis/arcgis-server.js"; | ||
export { ArcGISImageService as _ArcGISImageService } from "./services/arcgis/arcgis-image-service.js"; | ||
//# sourceMappingURL=index.js.map |
@@ -0,17 +1,22 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { XMLLoader } from '@loaders.gl/xml'; | ||
import { parseExceptionReport } from "./parse-exception-report.js"; | ||
/** | ||
* Parses a typed data structure from raw XML for `GetCapabilities` response | ||
* @note Error handlings is fairly weak | ||
*/ | ||
export function parseCSWCapabilities(text, options) { | ||
var _XMLLoader$parseTextS; | ||
const parsedXML = (_XMLLoader$parseTextS = XMLLoader.parseTextSync) === null || _XMLLoader$parseTextS === void 0 ? void 0 : _XMLLoader$parseTextS.call(XMLLoader, text, { | ||
...options, | ||
xml: { | ||
...(options === null || options === void 0 ? void 0 : options.xml), | ||
removeNSPrefix: true, | ||
uncapitalizeKeys: true | ||
} | ||
}); | ||
parseExceptionReport(parsedXML); | ||
const xmlCapabilities = parsedXML.capabilities || parsedXML; | ||
return xmlCapabilities; | ||
const parsedXML = XMLLoader.parseTextSync?.(text, { | ||
...options, | ||
xml: { | ||
...options?.xml, | ||
removeNSPrefix: true, | ||
uncapitalizeKeys: true | ||
} | ||
}); | ||
parseExceptionReport(parsedXML); | ||
const xmlCapabilities = parsedXML.capabilities || parsedXML; | ||
return xmlCapabilities; | ||
} | ||
//# sourceMappingURL=parse-csw-capabilities.js.map |
@@ -0,23 +1,31 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { XMLLoader } from '@loaders.gl/xml'; | ||
import { parseExceptionReport } from "./parse-exception-report.js"; | ||
/** | ||
* Parses a typed data structure from raw XML for `GetDomain` response | ||
* @note Error handlings is fairly weak | ||
*/ | ||
export function parseCSWDomain(text, options) { | ||
var _XMLLoader$parseTextS; | ||
const parsedXML = (_XMLLoader$parseTextS = XMLLoader.parseTextSync) === null || _XMLLoader$parseTextS === void 0 ? void 0 : _XMLLoader$parseTextS.call(XMLLoader, text, { | ||
...options, | ||
xml: { | ||
...(options === null || options === void 0 ? void 0 : options.xml), | ||
removeNSPrefix: true, | ||
uncapitalizeKeys: true, | ||
arrayPaths: ['GetDomainResponse.DomainValues', 'GetDomainResponse.DomainValues.ListOfValues.value'] | ||
const parsedXML = XMLLoader.parseTextSync?.(text, { | ||
...options, | ||
xml: { | ||
...options?.xml, | ||
removeNSPrefix: true, | ||
uncapitalizeKeys: true, | ||
arrayPaths: [ | ||
'GetDomainResponse.DomainValues', | ||
'GetDomainResponse.DomainValues.ListOfValues.value' | ||
] | ||
} | ||
}); | ||
parseExceptionReport(parsedXML); | ||
const xmlDomain = parsedXML.getDomainResponse; | ||
for (const domainValue of xmlDomain.domainValues) { | ||
// Drop the nested <listOfValues><value><value><listOfValues> => values[] | ||
domainValue.values = domainValue.listOfValues?.value; | ||
delete domainValue.listOfValues; | ||
} | ||
}); | ||
parseExceptionReport(parsedXML); | ||
const xmlDomain = parsedXML.getDomainResponse; | ||
for (const domainValue of xmlDomain.domainValues) { | ||
var _domainValue$listOfVa; | ||
domainValue.values = (_domainValue$listOfVa = domainValue.listOfValues) === null || _domainValue$listOfVa === void 0 ? void 0 : _domainValue$listOfVa.value; | ||
delete domainValue.listOfValues; | ||
} | ||
return xmlDomain; | ||
return xmlDomain; | ||
} | ||
//# sourceMappingURL=parse-csw-domain.js.map |
@@ -0,44 +1,55 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { convertXMLFieldToArrayInPlace } from '@loaders.gl/xml'; | ||
import { XMLLoader } from '@loaders.gl/xml'; | ||
import { parseExceptionReport } from "./parse-exception-report.js"; | ||
/** | ||
* Parses a typed data structure from raw XML for `GetRecords` response | ||
* @note Error handlings is fairly weak | ||
*/ | ||
export function parseCSWRecords(text, options) { | ||
var _XMLLoader$parseTextS, _options$xml; | ||
const parsedXML = (_XMLLoader$parseTextS = XMLLoader.parseTextSync) === null || _XMLLoader$parseTextS === void 0 ? void 0 : _XMLLoader$parseTextS.call(XMLLoader, text, { | ||
...options, | ||
xml: { | ||
...(options === null || options === void 0 ? void 0 : options.xml), | ||
removeNSPrefix: true, | ||
uncapitalizeKeys: true, | ||
arrayPaths: [], | ||
_fastXML: { | ||
...(options === null || options === void 0 ? void 0 : (_options$xml = options.xml) === null || _options$xml === void 0 ? void 0 : _options$xml._fastXML), | ||
parseAttributeValue: true | ||
} | ||
const parsedXML = XMLLoader.parseTextSync?.(text, { | ||
...options, | ||
xml: { | ||
...options?.xml, | ||
removeNSPrefix: true, | ||
uncapitalizeKeys: true, | ||
arrayPaths: [], | ||
_fastXML: { | ||
...options?.xml?._fastXML, | ||
parseAttributeValue: true | ||
} | ||
} | ||
}); | ||
parseExceptionReport(parsedXML); | ||
const xmlRecords = parsedXML.getRecordsResponse; | ||
// Move results to top | ||
const elementSet = xmlRecords.searchResults.elementSet; | ||
const recordsFieldName = `${elementSet}Record`; | ||
xmlRecords.records = xmlRecords.searchResults[recordsFieldName]; | ||
delete xmlRecords.searchResults[recordsFieldName]; | ||
convertXMLFieldToArrayInPlace(xmlRecords, 'records'); | ||
for (const record of xmlRecords.records) { | ||
record.boundingBoxes = record.boundingBox; | ||
delete record.boundingBox; | ||
convertXMLFieldToArrayInPlace(record, 'boundingBoxes'); | ||
for (const boundingBox of record.boundingBoxes) { | ||
boundingBox.value = [ | ||
boundingBox.upperCorner[0], | ||
boundingBox.upperCorner[1], | ||
boundingBox.lowerCorner[0], | ||
boundingBox.lowerCorner[1] | ||
]; | ||
delete boundingBox.upperCorner; | ||
delete boundingBox.lowerCorner; | ||
} | ||
} | ||
}); | ||
parseExceptionReport(parsedXML); | ||
const xmlRecords = parsedXML.getRecordsResponse; | ||
const elementSet = xmlRecords.searchResults.elementSet; | ||
const recordsFieldName = `${elementSet}Record`; | ||
xmlRecords.records = xmlRecords.searchResults[recordsFieldName]; | ||
delete xmlRecords.searchResults[recordsFieldName]; | ||
convertXMLFieldToArrayInPlace(xmlRecords, 'records'); | ||
for (const record of xmlRecords.records) { | ||
record.boundingBoxes = record.boundingBox; | ||
delete record.boundingBox; | ||
convertXMLFieldToArrayInPlace(record, 'boundingBoxes'); | ||
for (const boundingBox of record.boundingBoxes) { | ||
boundingBox.value = [boundingBox.upperCorner[0], boundingBox.upperCorner[1], boundingBox.lowerCorner[0], boundingBox.lowerCorner[1]]; | ||
delete boundingBox.upperCorner; | ||
delete boundingBox.lowerCorner; | ||
} | ||
} | ||
return xmlRecords; | ||
return xmlRecords; | ||
} | ||
export function renameXMLTags(xml, renameKeys) { | ||
for (const [oldKey, newKey] of Object.entries(renameKeys)) { | ||
xml[newKey] = xml[oldKey]; | ||
delete xml[oldKey]; | ||
} | ||
for (const [oldKey, newKey] of Object.entries(renameKeys)) { | ||
xml[newKey] = xml[oldKey]; | ||
delete xml[oldKey]; | ||
} | ||
} | ||
//# sourceMappingURL=parse-csw-records.js.map |
@@ -0,10 +1,28 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
// import type {XMLLoaderOptions} from '@loaders.gl/xml'; | ||
// import {XMLLoader} from '@loaders.gl/xml'; | ||
/** | ||
* Parses a typed data structure from raw XML for `GetDomain` response | ||
* @note Error handlings is fairly weak | ||
*/ | ||
export function parseExceptionReport(parsedXML) { | ||
var _exceptionReport$exce, _exceptionReport$exce2, _exceptionReport$exce3; | ||
const exceptionReport = parsedXML.exceptionReport; | ||
if (!exceptionReport) { | ||
return; | ||
} | ||
const errorMessage = ((_exceptionReport$exce = exceptionReport.exception) === null || _exceptionReport$exce === void 0 ? void 0 : _exceptionReport$exce.exceptionText) || ((_exceptionReport$exce2 = exceptionReport.exception) === null || _exceptionReport$exce2 === void 0 ? void 0 : _exceptionReport$exce2.exceptionCode) || ((_exceptionReport$exce3 = exceptionReport.exception) === null || _exceptionReport$exce3 === void 0 ? void 0 : _exceptionReport$exce3.locator) || 'server error'; | ||
throw new Error(`Catalog Server: ${errorMessage}`); | ||
// const parsedXML = XMLLoader.parseTextSync?.(text, { | ||
// ...options, | ||
// xml: { | ||
// ...options?.xml, | ||
// removeNSPrefix: true, | ||
// uncapitalizeKeys: true | ||
// } | ||
// }); | ||
const exceptionReport = parsedXML.exceptionReport; | ||
if (!exceptionReport) { | ||
return; | ||
} | ||
const errorMessage = exceptionReport.exception?.exceptionText || | ||
exceptionReport.exception?.exceptionCode || | ||
exceptionReport.exception?.locator || | ||
'server error'; | ||
throw new Error(`Catalog Server: ${errorMessage}`); | ||
} | ||
//# sourceMappingURL=parse-exception-report.js.map |
@@ -0,48 +1,116 @@ | ||
// https://github.com/nodejs/node/commit/c1d82ac2ff15594840e2a1b9531b506ae067ed27; | ||
// http://wiki.commonjs.org/wiki/Unit_Testing/1.0 | ||
// | ||
// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! | ||
// | ||
// Originally from narwhal.js (http://narwhaljs.org) | ||
// Copyright (c) 2009 Thomas Robinson <280north.com> | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the 'Software'), to | ||
// deal in the Software without restriction, including without limitation the | ||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
// sell copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
/** @todo replace this ridiculous choice of deepStrictEqual */ | ||
// eslint-disable-next-line complexity | ||
export function deepStrictEqual(actual, expected, strict) { | ||
if (actual === expected) { | ||
return true; | ||
} else if (actual instanceof Date && expected instanceof Date) { | ||
return actual.getTime() === expected.getTime(); | ||
} else if (actual instanceof RegExp && expected instanceof RegExp) { | ||
return actual.source === expected.source && actual.global === expected.global && actual.multiline === expected.multiline && actual.lastIndex === expected.lastIndex && actual.ignoreCase === expected.ignoreCase; | ||
} else if ((actual === null || typeof actual !== 'object') && (expected === null || typeof expected !== 'object')) { | ||
return strict ? actual === expected : actual == expected; | ||
} | ||
return objEquiv(actual, expected, strict); | ||
// 7.1. All identical values are equivalent, as determined by ===. | ||
if (actual === expected) { | ||
return true; | ||
// } else if (actual instanceof Buffer && expected instanceof Buffer) { | ||
// return compare(actual, expected) === 0; | ||
// // 7.2. If the expected value is a Date object, the actual value is | ||
// // equivalent if it is also a Date object that refers to the same time. | ||
} | ||
else if (actual instanceof Date && expected instanceof Date) { | ||
return actual.getTime() === expected.getTime(); | ||
// 7.3 If the expected value is a RegExp object, the actual value is | ||
// equivalent if it is also a RegExp object with the same source and | ||
// properties (`global`, `multiline`, `lastIndex`, `ignoreCase`). | ||
} | ||
else if (actual instanceof RegExp && expected instanceof RegExp) { | ||
return (actual.source === expected.source && | ||
actual.global === expected.global && | ||
actual.multiline === expected.multiline && | ||
actual.lastIndex === expected.lastIndex && | ||
actual.ignoreCase === expected.ignoreCase); | ||
// 7.4. Other pairs that do not both pass typeof value == 'object', | ||
// equivalence is determined by ==. | ||
} | ||
else if ((actual === null || typeof actual !== 'object') && | ||
(expected === null || typeof expected !== 'object')) { | ||
// eslint-disable-next-line eqeqeq | ||
return strict ? actual === expected : actual == expected; | ||
// 7.5 For all other Object pairs, including Array objects, equivalence is | ||
// determined by having the same number of owned properties (as verified | ||
// with Object.prototype.hasOwnProperty.call), the same set of keys | ||
// (although not necessarily the same order), equivalent values for every | ||
// corresponding key, and an identical 'prototype' property. Note: this | ||
// accounts for both named and indexed properties on Arrays. | ||
} | ||
return objEquiv(actual, expected, strict); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
const pSlice = Array.prototype.slice; | ||
function isPrimitive(arg) { | ||
return arg === null || typeof arg !== 'object' && typeof arg !== 'function'; | ||
return arg === null || (typeof arg !== 'object' && typeof arg !== 'function'); | ||
} | ||
function isArguments(object) { | ||
return Object.prototype.toString.call(object) == '[object Arguments]'; | ||
// eslint-disable-next-line eqeqeq | ||
return Object.prototype.toString.call(object) == '[object Arguments]'; | ||
} | ||
// eslint-disable-next-line complexity | ||
function objEquiv(a, b, strict) { | ||
if (a === null || a === undefined || b === null || b === undefined) return false; | ||
if (isPrimitive(a) || isPrimitive(b)) return a === b; | ||
if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false; | ||
const aIsArgs = isArguments(a); | ||
const bIsArgs = isArguments(b); | ||
if (aIsArgs && !bIsArgs || !aIsArgs && bIsArgs) return false; | ||
if (aIsArgs) { | ||
a = pSlice.call(a); | ||
b = pSlice.call(b); | ||
return deepStrictEqual(a, b, strict); | ||
} | ||
const ka = Object.keys(a); | ||
const kb = Object.keys(b); | ||
let key; | ||
let i; | ||
if (ka.length !== kb.length) return false; | ||
ka.sort(); | ||
kb.sort(); | ||
for (i = ka.length - 1; i >= 0; i--) { | ||
if (ka[i] !== kb[i]) return false; | ||
} | ||
for (i = ka.length - 1; i >= 0; i--) { | ||
key = ka[i]; | ||
if (!deepStrictEqual(a[key], b[key], strict)) return false; | ||
} | ||
return true; | ||
if (a === null || a === undefined || b === null || b === undefined) | ||
return false; | ||
// if one is a primitive, the other must be same | ||
if (isPrimitive(a) || isPrimitive(b)) | ||
return a === b; | ||
if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) | ||
return false; | ||
const aIsArgs = isArguments(a); | ||
const bIsArgs = isArguments(b); | ||
if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs)) | ||
return false; | ||
if (aIsArgs) { | ||
a = pSlice.call(a); | ||
b = pSlice.call(b); | ||
return deepStrictEqual(a, b, strict); | ||
} | ||
const ka = Object.keys(a); | ||
const kb = Object.keys(b); | ||
let key; | ||
let i; | ||
// having the same number of owned properties (keys incorporates | ||
// hasOwnProperty) | ||
if (ka.length !== kb.length) | ||
return false; | ||
// the same set of keys (although not necessarily the same order), | ||
ka.sort(); | ||
kb.sort(); | ||
// ~~~cheap key test | ||
for (i = ka.length - 1; i >= 0; i--) { | ||
if (ka[i] !== kb[i]) | ||
return false; | ||
} | ||
// equivalent values for every corresponding key, and | ||
// ~~~possibly expensive deep test | ||
for (i = ka.length - 1; i >= 0; i--) { | ||
key = ka[i]; | ||
// @ts-ignore | ||
if (!deepStrictEqual(a[key], b[key], strict)) | ||
return false; | ||
} | ||
return true; | ||
} | ||
//# sourceMappingURL=deep-strict-equal.js.map |
@@ -0,335 +1,354 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { XMLLoader } from '@loaders.gl/xml'; | ||
import { deepStrictEqual } from "./deep-strict-equal.js"; | ||
import rewind from '@turf/rewind'; | ||
function noTransform() { | ||
for (var _len = arguments.length, coords = new Array(_len), _key = 0; _key < _len; _key++) { | ||
coords[_key] = arguments[_key]; | ||
} | ||
return coords; | ||
function noTransform(...coords) { | ||
return coords; | ||
} | ||
/** | ||
* Parses a typed data structure from raw XML for GML features | ||
* @note Error handlings is fairly weak | ||
*/ | ||
export function parseGML(text, options) { | ||
var _XMLLoader$parseTextS; | ||
const parsedXML = (_XMLLoader$parseTextS = XMLLoader.parseTextSync) === null || _XMLLoader$parseTextS === void 0 ? void 0 : _XMLLoader$parseTextS.call(XMLLoader, text, options); | ||
options = { | ||
transformCoords: noTransform, | ||
stride: 2, | ||
...options | ||
}; | ||
const context = createChildContext(parsedXML, options, {}); | ||
return parseGMLToGeometry(parsedXML, options, context); | ||
// GeoJSON | null { | ||
const parsedXML = XMLLoader.parseTextSync?.(text, options); | ||
options = { transformCoords: noTransform, stride: 2, ...options }; | ||
const context = createChildContext(parsedXML, options, {}); | ||
return parseGMLToGeometry(parsedXML, options, context); | ||
} | ||
/** Parse a GeoJSON geometry from GML XML */ | ||
export function parseGMLToGeometry(inputXML, options, context) { | ||
const childContext = createChildContext(inputXML, options, context); | ||
let geometry = null; | ||
const [name, xml] = getFirstKeyValue(inputXML); | ||
switch (name) { | ||
case 'gml:LineString': | ||
geometry = { | ||
type: 'LineString', | ||
coordinates: parseLinearRingOrLineString(xml, options, childContext) | ||
}; | ||
break; | ||
case 'gml:Polygon': | ||
case 'gml:Rectangle': | ||
geometry = { | ||
type: 'Polygon', | ||
coordinates: parsePolygonOrRectangle(xml, options, childContext) | ||
}; | ||
break; | ||
case 'gml:Surface': | ||
geometry = { | ||
type: 'MultiPolygon', | ||
coordinates: parseSurface(xml, options, childContext) | ||
}; | ||
break; | ||
case 'gml:MultiSurface': | ||
geometry = { | ||
type: 'MultiPolygon', | ||
coordinates: parseMultiSurface(xml, options, childContext) | ||
}; | ||
break; | ||
default: | ||
return null; | ||
} | ||
return rewind(geometry, { | ||
mutate: true | ||
}); | ||
const childContext = createChildContext(inputXML, options, context); | ||
let geometry = null; | ||
const [name, xml] = getFirstKeyValue(inputXML); | ||
switch (name) { | ||
// case 'gml:MultiPoint': | ||
// geometry = { | ||
// type: 'MultiPoint', | ||
// coordinates: parseMultiPoint(xml, options, childContext) | ||
// }; | ||
// break; | ||
case 'gml:LineString': | ||
geometry = { | ||
type: 'LineString', | ||
coordinates: parseLinearRingOrLineString(xml, options, childContext) | ||
}; | ||
break; | ||
// case 'gml:MultiLineString': | ||
// geometry = { | ||
// type: 'MultiLineString', | ||
// coordinates: parseMultiLineString(xml, options, childContext) | ||
// }; | ||
// break; | ||
case 'gml:Polygon': | ||
case 'gml:Rectangle': | ||
geometry = { | ||
type: 'Polygon', | ||
coordinates: parsePolygonOrRectangle(xml, options, childContext) | ||
}; | ||
break; | ||
case 'gml:Surface': | ||
geometry = { | ||
type: 'MultiPolygon', | ||
coordinates: parseSurface(xml, options, childContext) | ||
}; | ||
break; | ||
case 'gml:MultiSurface': | ||
geometry = { | ||
type: 'MultiPolygon', | ||
coordinates: parseMultiSurface(xml, options, childContext) | ||
}; | ||
break; | ||
default: | ||
return null; | ||
} | ||
// todo | ||
return rewind(geometry, { mutate: true }); | ||
} | ||
/** Parse a list of coordinates from a string */ | ||
function parseCoords(s, options, context) { | ||
const stride = context.srsDimension || options.stride || 2; | ||
const coords = s.replace(/\s+/g, ' ').trim().split(' '); | ||
if (coords.length === 0 || coords.length % stride !== 0) { | ||
throw new Error(`invalid coordinates list (stride ${stride})`); | ||
} | ||
const points = []; | ||
for (let i = 0; i < coords.length - 1; i += stride) { | ||
var _options$transformCoo; | ||
const point = coords.slice(i, i + stride).map(parseFloat); | ||
points.push(((_options$transformCoo = options.transformCoords) === null || _options$transformCoo === void 0 ? void 0 : _options$transformCoo.call(options, ...point)) || point); | ||
} | ||
return points; | ||
const stride = context.srsDimension || options.stride || 2; | ||
// Handle white space | ||
const coords = s.replace(/\s+/g, ' ').trim().split(' '); | ||
if (coords.length === 0 || coords.length % stride !== 0) { | ||
throw new Error(`invalid coordinates list (stride ${stride})`); | ||
} | ||
const points = []; | ||
for (let i = 0; i < coords.length - 1; i += stride) { | ||
const point = coords.slice(i, i + stride).map(parseFloat); | ||
points.push(options.transformCoords?.(...point) || point); | ||
} | ||
return points; | ||
} | ||
export function parsePosList(xml, options, context) { | ||
const childContext = createChildContext(xml, options, context); | ||
const coords = textOf(xml); | ||
if (!coords) { | ||
throw new Error('invalid gml:posList element'); | ||
} | ||
return parseCoords(coords, options, childContext); | ||
const childContext = createChildContext(xml, options, context); | ||
const coords = textOf(xml); | ||
if (!coords) { | ||
throw new Error('invalid gml:posList element'); | ||
} | ||
return parseCoords(coords, options, childContext); | ||
} | ||
export function parsePos(xml, options, context) { | ||
const childContext = createChildContext(xml, options, context); | ||
const coords = textOf(xml); | ||
if (!coords) { | ||
throw new Error('invalid gml:pos element'); | ||
} | ||
const points = parseCoords(coords, options, childContext); | ||
if (points.length !== 1) { | ||
throw new Error('gml:pos must have 1 point'); | ||
} | ||
return points[0]; | ||
const childContext = createChildContext(xml, options, context); | ||
const coords = textOf(xml); | ||
if (!coords) { | ||
throw new Error('invalid gml:pos element'); | ||
} | ||
const points = parseCoords(coords, options, childContext); | ||
if (points.length !== 1) { | ||
throw new Error('gml:pos must have 1 point'); | ||
} | ||
return points[0]; | ||
} | ||
export function parsePoint(xml, options, context) { | ||
const childContext = createChildContext(xml, options, context); | ||
const pos = findIn(xml, 'gml:pos'); | ||
if (!pos) { | ||
throw new Error('invalid gml:Point element, expected a gml:pos subelement'); | ||
} | ||
return parsePos(pos, options, childContext); | ||
const childContext = createChildContext(xml, options, context); | ||
// TODO AV: Parse other gml:Point options | ||
const pos = findIn(xml, 'gml:pos'); | ||
if (!pos) { | ||
throw new Error('invalid gml:Point element, expected a gml:pos subelement'); | ||
} | ||
return parsePos(pos, options, childContext); | ||
} | ||
export function parseLinearRingOrLineString(xml, options, context) { | ||
const childContext = createChildContext(xml, options, context); | ||
let points = []; | ||
const posList = findIn(xml, 'gml:posList'); | ||
if (posList) { | ||
points = parsePosList(posList, options, childContext); | ||
} else { | ||
for (const [childName, childXML] of Object.entries(xml)) { | ||
switch (childName) { | ||
case 'gml:Point': | ||
points.push(parsePoint(childXML, options, childContext)); | ||
break; | ||
case 'gml:pos': | ||
points.push(parsePos(childXML, options, childContext)); | ||
break; | ||
default: | ||
continue; | ||
} | ||
// or a LineStringSegment | ||
const childContext = createChildContext(xml, options, context); | ||
let points = []; | ||
const posList = findIn(xml, 'gml:posList'); | ||
if (posList) { | ||
points = parsePosList(posList, options, childContext); | ||
} | ||
} | ||
if (points.length === 0) { | ||
throw new Error(`${xml.name} must have > 0 points`); | ||
} | ||
return points; | ||
else { | ||
for (const [childName, childXML] of Object.entries(xml)) { | ||
switch (childName) { | ||
case 'gml:Point': | ||
points.push(parsePoint(childXML, options, childContext)); | ||
break; | ||
case 'gml:pos': | ||
points.push(parsePos(childXML, options, childContext)); | ||
break; | ||
default: | ||
continue; | ||
} | ||
} | ||
} | ||
if (points.length === 0) { | ||
throw new Error(`${xml.name} must have > 0 points`); | ||
} | ||
return points; | ||
} | ||
export function parseCurveSegments(xml, options, context) { | ||
const points = []; | ||
for (const [childName, childXML] of Object.entries(xml)) { | ||
switch (childName) { | ||
case 'gml:LineStringSegment': | ||
const points2 = parseLinearRingOrLineString(childXML, options, context); | ||
const end = points[points.length - 1]; | ||
const start = points2[0]; | ||
if (end && start && deepStrictEqual(end, start)) { | ||
points2.shift(); | ||
const points = []; | ||
for (const [childName, childXML] of Object.entries(xml)) { | ||
switch (childName) { | ||
case 'gml:LineStringSegment': | ||
const points2 = parseLinearRingOrLineString(childXML, options, context); | ||
// remove overlapping | ||
const end = points[points.length - 1]; | ||
const start = points2[0]; | ||
if (end && start && deepStrictEqual(end, start)) { | ||
points2.shift(); | ||
} | ||
points.push(...points2); | ||
break; | ||
default: | ||
continue; | ||
} | ||
points.push(...points2); | ||
break; | ||
default: | ||
continue; | ||
} | ||
} | ||
if (points.length === 0) { | ||
throw new Error('gml:Curve > gml:segments must have > 0 points'); | ||
} | ||
return points; | ||
if (points.length === 0) { | ||
throw new Error('gml:Curve > gml:segments must have > 0 points'); | ||
} | ||
return points; | ||
} | ||
export function parseRing(xml, options, context) { | ||
const childContext = createChildContext(xml, options, context); | ||
const points = []; | ||
for (const [childName, childXML] of Object.entries(xml)) { | ||
switch (childName) { | ||
case 'gml:curveMember': | ||
let points2; | ||
const lineString = findIn(childXML, 'gml:LineString'); | ||
if (lineString) { | ||
points2 = parseLinearRingOrLineString(lineString, options, childContext); | ||
} else { | ||
const segments = findIn(childXML, 'gml:Curve', 'gml:segments'); | ||
if (!segments) { | ||
throw new Error(`invalid ${childName} element`); | ||
} | ||
points2 = parseCurveSegments(segments, options, childContext); | ||
const childContext = createChildContext(xml, options, context); | ||
const points = []; | ||
for (const [childName, childXML] of Object.entries(xml)) { | ||
switch (childName) { | ||
case 'gml:curveMember': | ||
let points2; | ||
const lineString = findIn(childXML, 'gml:LineString'); | ||
if (lineString) { | ||
points2 = parseLinearRingOrLineString(lineString, options, childContext); | ||
} | ||
else { | ||
const segments = findIn(childXML, 'gml:Curve', 'gml:segments'); | ||
if (!segments) { | ||
throw new Error(`invalid ${childName} element`); | ||
} | ||
points2 = parseCurveSegments(segments, options, childContext); | ||
} | ||
// remove overlapping | ||
const end = points[points.length - 1]; | ||
const start = points2[0]; | ||
if (end && start && deepStrictEqual(end, start)) { | ||
points2.shift(); | ||
} | ||
points.push(...points2); | ||
break; | ||
} | ||
const end = points[points.length - 1]; | ||
const start = points2[0]; | ||
if (end && start && deepStrictEqual(end, start)) { | ||
points2.shift(); | ||
} | ||
points.push(...points2); | ||
break; | ||
} | ||
} | ||
if (points.length < 4) { | ||
throw new Error(`${xml.name} must have >= 4 points`); | ||
} | ||
return points; | ||
if (points.length < 4) { | ||
throw new Error(`${xml.name} must have >= 4 points`); | ||
} | ||
return points; | ||
} | ||
export function parseExteriorOrInterior(xml, options, context) { | ||
const linearRing = findIn(xml, 'gml:LinearRing'); | ||
if (linearRing) { | ||
return parseLinearRingOrLineString(linearRing, options, context); | ||
} | ||
const ring = findIn(xml, 'gml:Ring'); | ||
if (!ring) { | ||
throw new Error(`invalid ${xml.name} element`); | ||
} | ||
return parseRing(ring, options, context); | ||
const linearRing = findIn(xml, 'gml:LinearRing'); | ||
if (linearRing) { | ||
return parseLinearRingOrLineString(linearRing, options, context); | ||
} | ||
const ring = findIn(xml, 'gml:Ring'); | ||
if (!ring) { | ||
throw new Error(`invalid ${xml.name} element`); | ||
} | ||
return parseRing(ring, options, context); | ||
} | ||
export function parsePolygonOrRectangle(xml, options, context) { | ||
const childContext = createChildContext(xml, options, context); | ||
const exterior = findIn(xml, 'gml:exterior'); | ||
if (!exterior) { | ||
throw new Error(`invalid ${xml.name} element`); | ||
} | ||
const pointLists = [parseExteriorOrInterior(exterior, options, childContext)]; | ||
for (const [childName, childXML] of Object.entries(xml)) { | ||
switch (childName) { | ||
case 'gml:interior': | ||
pointLists.push(parseExteriorOrInterior(childXML, options, childContext)); | ||
break; | ||
// or PolygonPatch | ||
const childContext = createChildContext(xml, options, context); | ||
const exterior = findIn(xml, 'gml:exterior'); | ||
if (!exterior) { | ||
throw new Error(`invalid ${xml.name} element`); | ||
} | ||
} | ||
return pointLists; | ||
const pointLists = [parseExteriorOrInterior(exterior, options, childContext)]; | ||
for (const [childName, childXML] of Object.entries(xml)) { | ||
switch (childName) { | ||
case 'gml:interior': | ||
pointLists.push(parseExteriorOrInterior(childXML, options, childContext)); | ||
break; | ||
} | ||
} | ||
return pointLists; | ||
} | ||
export function parseSurface(xml, options, context) { | ||
const childContext = createChildContext(xml, options, context); | ||
const patches = findIn(xml, 'gml:patches'); | ||
if (!patches) { | ||
throw new Error(`invalid ${xml.name} element`); | ||
} | ||
const polygons = []; | ||
for (const [childName, childXML] of Object.entries(xml)) { | ||
switch (childName) { | ||
case 'gml:PolygonPatch': | ||
case 'gml:Rectangle': | ||
polygons.push(parsePolygonOrRectangle(childXML, options, childContext)); | ||
break; | ||
default: | ||
continue; | ||
const childContext = createChildContext(xml, options, context); | ||
const patches = findIn(xml, 'gml:patches'); | ||
if (!patches) { | ||
throw new Error(`invalid ${xml.name} element`); | ||
} | ||
} | ||
if (polygons.length === 0) { | ||
throw new Error(`${xml.name} must have > 0 polygons`); | ||
} | ||
return polygons; | ||
const polygons = []; | ||
for (const [childName, childXML] of Object.entries(xml)) { | ||
switch (childName) { | ||
case 'gml:PolygonPatch': | ||
case 'gml:Rectangle': | ||
polygons.push(parsePolygonOrRectangle(childXML, options, childContext)); | ||
break; | ||
default: | ||
continue; | ||
} | ||
} | ||
if (polygons.length === 0) { | ||
throw new Error(`${xml.name} must have > 0 polygons`); | ||
} | ||
return polygons; | ||
} | ||
export function parseCompositeSurface(xml, options, context) { | ||
const childContext = createChildContext(xml, options, context); | ||
const polygons = []; | ||
for (const [childName, childXML] of Object.entries(xml)) { | ||
switch (childName) { | ||
case 'gml:surfaceMember': | ||
case 'gml:surfaceMembers': | ||
const [c2Name, c2Xml] = getFirstKeyValue(childXML); | ||
switch (c2Name) { | ||
case 'gml:Surface': | ||
polygons.push(...parseSurface(c2Xml, options, childContext)); | ||
break; | ||
case 'gml:Polygon': | ||
polygons.push(parsePolygonOrRectangle(c2Xml, options, childContext)); | ||
break; | ||
const childContext = createChildContext(xml, options, context); | ||
const polygons = []; | ||
for (const [childName, childXML] of Object.entries(xml)) { | ||
switch (childName) { | ||
case 'gml:surfaceMember': | ||
case 'gml:surfaceMembers': | ||
const [c2Name, c2Xml] = getFirstKeyValue(childXML); | ||
switch (c2Name) { | ||
case 'gml:Surface': | ||
polygons.push(...parseSurface(c2Xml, options, childContext)); | ||
break; | ||
case 'gml:Polygon': | ||
polygons.push(parsePolygonOrRectangle(c2Xml, options, childContext)); | ||
break; | ||
} | ||
break; | ||
} | ||
break; | ||
} | ||
} | ||
if (polygons.length === 0) { | ||
throw new Error(`${xml.name} must have > 0 polygons`); | ||
} | ||
return polygons; | ||
if (polygons.length === 0) { | ||
throw new Error(`${xml.name} must have > 0 polygons`); | ||
} | ||
return polygons; | ||
} | ||
export function parseMultiSurface(xml, options, context) { | ||
let el = xml; | ||
const surfaceMembers = findIn(xml, 'gml:LinearRing'); | ||
if (surfaceMembers) { | ||
el = surfaceMembers; | ||
} | ||
const polygons = []; | ||
for (const [childName, childXML] of Object.entries(el)) { | ||
switch (childName) { | ||
case 'gml:Surface': | ||
const polygons2 = parseSurface(childXML, options, context); | ||
polygons.push(...polygons2); | ||
break; | ||
case 'gml:surfaceMember': | ||
const polygons3 = parseSurfaceMember(childXML, options, context); | ||
polygons.push(...polygons3); | ||
break; | ||
case 'gml:surfaceMembers': | ||
const polygonXML = findIn(childXML, 'gml:Polygon'); | ||
for (const surfaceMemberXML of polygonXML) { | ||
const polygons3 = parseSurfaceMember(surfaceMemberXML, options, context); | ||
polygons.push(...polygons3); | ||
let el = xml; | ||
const surfaceMembers = findIn(xml, 'gml:LinearRing'); | ||
if (surfaceMembers) { | ||
el = surfaceMembers; | ||
} | ||
const polygons = []; | ||
for (const [childName, childXML] of Object.entries(el)) { | ||
switch (childName) { | ||
case 'gml:Surface': | ||
const polygons2 = parseSurface(childXML, options, context); | ||
polygons.push(...polygons2); | ||
break; | ||
case 'gml:surfaceMember': | ||
const polygons3 = parseSurfaceMember(childXML, options, context); | ||
polygons.push(...polygons3); | ||
break; | ||
case 'gml:surfaceMembers': | ||
const polygonXML = findIn(childXML, 'gml:Polygon'); | ||
for (const surfaceMemberXML of polygonXML) { | ||
const polygons3 = parseSurfaceMember(surfaceMemberXML, options, context); | ||
polygons.push(...polygons3); | ||
} | ||
break; | ||
} | ||
break; | ||
} | ||
} | ||
if (polygons.length === 0) { | ||
throw new Error(`${xml.name} must have > 0 polygons`); | ||
} | ||
return polygons; | ||
if (polygons.length === 0) { | ||
throw new Error(`${xml.name} must have > 0 polygons`); | ||
} | ||
return polygons; | ||
} | ||
function parseSurfaceMember(xml, options, context) { | ||
const [childName, childXml] = getFirstKeyValue(xml); | ||
switch (childName) { | ||
case 'gml:CompositeSurface': | ||
return parseCompositeSurface(childXml, options, context); | ||
case 'gml:Surface': | ||
return parseSurface(childXml, options, context); | ||
case 'gml:Polygon': | ||
return [parsePolygonOrRectangle(childXml, options, context)]; | ||
} | ||
throw new Error(`${childName} must have polygons`); | ||
const [childName, childXml] = getFirstKeyValue(xml); | ||
switch (childName) { | ||
case 'gml:CompositeSurface': | ||
return parseCompositeSurface(childXml, options, context); | ||
case 'gml:Surface': | ||
return parseSurface(childXml, options, context); | ||
case 'gml:Polygon': | ||
return [parsePolygonOrRectangle(childXml, options, context)]; | ||
} | ||
throw new Error(`${childName} must have polygons`); | ||
} | ||
// Helpers | ||
function textOf(el) { | ||
if (typeof el !== 'string') { | ||
throw new Error('expected string'); | ||
} | ||
return el; | ||
if (typeof el !== 'string') { | ||
throw new Error('expected string'); | ||
} | ||
return el; | ||
} | ||
function findIn(root) { | ||
let el = root; | ||
for (var _len2 = arguments.length, tags = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
tags[_key2 - 1] = arguments[_key2]; | ||
} | ||
for (const tag of tags) { | ||
const child = el[tag]; | ||
if (!child) { | ||
return null; | ||
function findIn(root, ...tags) { | ||
let el = root; | ||
for (const tag of tags) { | ||
const child = el[tag]; | ||
if (!child) { | ||
return null; | ||
} | ||
el = child; | ||
} | ||
el = child; | ||
} | ||
return el; | ||
return el; | ||
} | ||
/** @returns the first [key, value] pair in an object, or ['', null] if empty object */ | ||
function getFirstKeyValue(object) { | ||
if (object && typeof object === 'object') { | ||
for (const [key, value] of Object.entries(object)) { | ||
return [key, value]; | ||
if (object && typeof object === 'object') { | ||
for (const [key, value] of Object.entries(object)) { | ||
return [key, value]; | ||
} | ||
} | ||
} | ||
return ['', null]; | ||
return ['', null]; | ||
} | ||
/** A bit heavyweight for just tracking dimension? */ | ||
function createChildContext(xml, options, context) { | ||
const srsDimensionAttribute = xml.attributes && xml.attributes.srsDimension; | ||
if (srsDimensionAttribute) { | ||
const srsDimension = parseInt(srsDimensionAttribute); | ||
if (Number.isNaN(srsDimension) || srsDimension <= 0) { | ||
throw new Error(`invalid srsDimension attribute value "${srsDimensionAttribute}", expected a positive integer`); | ||
const srsDimensionAttribute = xml.attributes && xml.attributes.srsDimension; | ||
if (srsDimensionAttribute) { | ||
const srsDimension = parseInt(srsDimensionAttribute); | ||
if (Number.isNaN(srsDimension) || srsDimension <= 0) { | ||
throw new Error(`invalid srsDimension attribute value "${srsDimensionAttribute}", expected a positive integer`); | ||
} | ||
const childContext = Object.create(context); | ||
childContext.srsDimension = srsDimension; | ||
return childContext; | ||
} | ||
const childContext = Object.create(context); | ||
childContext.srsDimension = srsDimension; | ||
return childContext; | ||
} | ||
return context; | ||
return context; | ||
} | ||
//# sourceMappingURL=parse-gml.js.map |
@@ -0,211 +1,231 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { XMLLoader } from '@loaders.gl/xml'; | ||
import { getXMLArray, getXMLStringArray, getXMLInteger, getXMLFloat, getXMLBoolean } from "../xml/parse-xml-helpers.js"; | ||
/** | ||
* Parses a typed data structure from raw XML for `GetCapabilities` response | ||
* @note Error handlings is fairly weak | ||
*/ | ||
export function parseWMSCapabilities(xmlText, options) { | ||
var _XMLLoader$parseTextS; | ||
const parsedXML = (_XMLLoader$parseTextS = XMLLoader.parseTextSync) === null || _XMLLoader$parseTextS === void 0 ? void 0 : _XMLLoader$parseTextS.call(XMLLoader, xmlText, options); | ||
const xmlCapabilities = parsedXML.WMT_MS_Capabilities || parsedXML.WMS_Capabilities || parsedXML; | ||
const capabilities = extractCapabilities(xmlCapabilities); | ||
if (options !== null && options !== void 0 && options.inheritedLayerProps) { | ||
for (const layer of capabilities.layers) { | ||
addInheritedLayerProps(layer, null); | ||
const parsedXML = XMLLoader.parseTextSync?.(xmlText, options); | ||
const xmlCapabilities = parsedXML.WMT_MS_Capabilities || parsedXML.WMS_Capabilities || parsedXML; | ||
const capabilities = extractCapabilities(xmlCapabilities); | ||
// In case the processed, normalized capabilities do not contain everything, | ||
// the user can get the parsed XML structure. | ||
if (options?.inheritedLayerProps) { | ||
// Traverse layers and inject missing props from parents | ||
for (const layer of capabilities.layers) { | ||
addInheritedLayerProps(layer, null); | ||
} | ||
// Not yet implemented | ||
} | ||
} | ||
if (options !== null && options !== void 0 && options.includeRawJSON) { | ||
capabilities.json = xmlCapabilities; | ||
} | ||
if (options !== null && options !== void 0 && options.includeXMLText) { | ||
capabilities.xml = xmlText; | ||
} | ||
return capabilities; | ||
if (options?.includeRawJSON) { | ||
capabilities.json = xmlCapabilities; | ||
} | ||
if (options?.includeXMLText) { | ||
capabilities.xml = xmlText; | ||
} | ||
return capabilities; | ||
} | ||
/** Extract typed capability data from XML */ | ||
function extractCapabilities(xml) { | ||
var _xml$Service, _xml$Service2, _xml$Service3, _xml$Service4, _xml$Service5, _xml$Service6, _xml$Service6$Keyword, _xml$Service7, _xml$Service8, _xml$Service9, _xml$Service10, _xml$Service11, _xml$Service12, _xml$Service13, _xml$Capability, _xml$Capability2; | ||
const capabilities = { | ||
version: String(xml.version || ''), | ||
name: String(((_xml$Service = xml.Service) === null || _xml$Service === void 0 ? void 0 : _xml$Service.Name) || 'unnamed'), | ||
title: (_xml$Service2 = xml.Service) !== null && _xml$Service2 !== void 0 && _xml$Service2.Title ? String((_xml$Service3 = xml.Service) === null || _xml$Service3 === void 0 ? void 0 : _xml$Service3.Title) : undefined, | ||
abstract: (_xml$Service4 = xml.Service) !== null && _xml$Service4 !== void 0 && _xml$Service4.Abstract ? String((_xml$Service5 = xml.Service) === null || _xml$Service5 === void 0 ? void 0 : _xml$Service5.Abstract) : undefined, | ||
keywords: getXMLStringArray((_xml$Service6 = xml.Service) === null || _xml$Service6 === void 0 ? void 0 : (_xml$Service6$Keyword = _xml$Service6.KeywordList) === null || _xml$Service6$Keyword === void 0 ? void 0 : _xml$Service6$Keyword.Keyword), | ||
fees: (_xml$Service7 = xml.Service) !== null && _xml$Service7 !== void 0 && _xml$Service7.Fees ? JSON.stringify((_xml$Service8 = xml.Service) === null || _xml$Service8 === void 0 ? void 0 : _xml$Service8.Fees) : undefined, | ||
accessConstraints: (_xml$Service9 = xml.Service) !== null && _xml$Service9 !== void 0 && _xml$Service9.AccessConstraints ? JSON.stringify((_xml$Service10 = xml.Service) === null || _xml$Service10 === void 0 ? void 0 : _xml$Service10.AccessConstraints) : undefined, | ||
layerLimit: getXMLInteger((_xml$Service11 = xml.Service) === null || _xml$Service11 === void 0 ? void 0 : _xml$Service11.LayerLimit), | ||
maxWidth: getXMLInteger((_xml$Service12 = xml.Service) === null || _xml$Service12 === void 0 ? void 0 : _xml$Service12.maxWidth), | ||
maxHeight: getXMLInteger((_xml$Service13 = xml.Service) === null || _xml$Service13 === void 0 ? void 0 : _xml$Service13.maxHeight), | ||
layers: [], | ||
requests: extractRequests((_xml$Capability = xml.Capability) === null || _xml$Capability === void 0 ? void 0 : _xml$Capability.Request), | ||
exceptions: extractExceptions(xml.Exception) | ||
}; | ||
const xmlLayers = getXMLArray((_xml$Capability2 = xml.Capability) === null || _xml$Capability2 === void 0 ? void 0 : _xml$Capability2.Layer); | ||
for (const xmlSubLayer of xmlLayers) { | ||
capabilities.layers.push(extractLayer(xmlSubLayer)); | ||
} | ||
for (const [key, value] of Object.entries(capabilities)) { | ||
if (value === undefined) { | ||
delete capabilities[key]; | ||
const capabilities = { | ||
version: String(xml.version || ''), | ||
name: String(xml.Service?.Name || 'unnamed'), | ||
title: xml.Service?.Title ? String(xml.Service?.Title) : undefined, | ||
abstract: xml.Service?.Abstract ? String(xml.Service?.Abstract) : undefined, | ||
keywords: getXMLStringArray(xml.Service?.KeywordList?.Keyword), | ||
fees: xml.Service?.Fees ? JSON.stringify(xml.Service?.Fees) : undefined, | ||
accessConstraints: xml.Service?.AccessConstraints | ||
? JSON.stringify(xml.Service?.AccessConstraints) | ||
: undefined, | ||
layerLimit: getXMLInteger(xml.Service?.LayerLimit), | ||
maxWidth: getXMLInteger(xml.Service?.maxWidth), | ||
maxHeight: getXMLInteger(xml.Service?.maxHeight), | ||
layers: [], | ||
requests: extractRequests(xml.Capability?.Request), | ||
exceptions: extractExceptions(xml.Exception) | ||
// contact field is a mess of largely irrelevant information, put it last | ||
// contact: xml.Service?.Contact ? JSON.stringify(xml.Service?.Contact) : undefined, | ||
}; | ||
// LAYERS | ||
const xmlLayers = getXMLArray(xml.Capability?.Layer); | ||
for (const xmlSubLayer of xmlLayers) { | ||
capabilities.layers.push(extractLayer(xmlSubLayer)); | ||
} | ||
} | ||
return capabilities; | ||
// Clean up object | ||
for (const [key, value] of Object.entries(capabilities)) { | ||
if (value === undefined) { | ||
delete capabilities[key]; | ||
} | ||
} | ||
return capabilities; | ||
} | ||
/** Extract typed request metadata from XML requests field */ | ||
function extractRequests(xmlRequests) { | ||
const requests = {}; | ||
for (const [name, xmlRequest] of Object.entries(xmlRequests || {})) { | ||
const mimeTypes = getXMLStringArray(xmlRequest === null || xmlRequest === void 0 ? void 0 : xmlRequest.Format); | ||
requests[name] = { | ||
mimeTypes | ||
}; | ||
} | ||
return requests; | ||
const requests = {}; | ||
for (const [name, xmlRequest] of Object.entries(xmlRequests || {})) { | ||
const mimeTypes = getXMLStringArray(xmlRequest?.Format); | ||
requests[name] = { mimeTypes }; | ||
} | ||
return requests; | ||
} | ||
function extractExceptions(xmlException) { | ||
const xmlExceptionFormats = getXMLArray(xmlException === null || xmlException === void 0 ? void 0 : xmlException.Format); | ||
if (xmlExceptionFormats.length > 0) { | ||
return { | ||
mimeTypes: getXMLStringArray(xmlException) | ||
}; | ||
} | ||
return undefined; | ||
const xmlExceptionFormats = getXMLArray(xmlException?.Format); | ||
if (xmlExceptionFormats.length > 0) { | ||
return { | ||
mimeTypes: getXMLStringArray(xmlException) | ||
}; | ||
} | ||
return undefined; | ||
} | ||
/** Extract request data */ | ||
// eslint-disable-next-line complexity, max-statements | ||
function extractLayer(xmlLayer) { | ||
var _xmlLayer$KeywordList; | ||
const layer = { | ||
title: String((xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.Title) || ''), | ||
name: (xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.Name) && String(xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.Name), | ||
abstract: (xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.Name) && String(xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.Abstract), | ||
keywords: getXMLStringArray((_xmlLayer$KeywordList = xmlLayer.KeywordList) === null || _xmlLayer$KeywordList === void 0 ? void 0 : _xmlLayer$KeywordList.Keyword) | ||
}; | ||
const crs = (xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.CRS) || (xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.SRS); | ||
if (crs && Array.isArray(crs) && crs.every(_ => typeof _ === 'string')) { | ||
layer.crs = crs; | ||
} | ||
let geographicBoundingBox = (xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.EX_GeographicBoundingBox) && extractEXBoundingBox(xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.EX_GeographicBoundingBox); | ||
if (geographicBoundingBox) { | ||
layer.geographicBoundingBox = geographicBoundingBox; | ||
} | ||
geographicBoundingBox = (xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.LatLonBoundingBox) && extractLatLonBoundingBox(xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.LatLonBoundingBox); | ||
if (geographicBoundingBox) { | ||
layer.geographicBoundingBox = geographicBoundingBox; | ||
} | ||
const boundingBoxes = (xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.BoundingBox) && extractWMSBoundingBoxes(xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.BoundingBox); | ||
if (boundingBoxes && boundingBoxes.length > 0) { | ||
layer.boundingBoxes = boundingBoxes; | ||
} | ||
const xmlDimensions = getXMLArray(xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.Dimension); | ||
const dimensions = xmlDimensions.map(xml => extractDimension(xml)); | ||
if (dimensions.length) { | ||
layer.dimensions = dimensions; | ||
} | ||
if (xmlLayer !== null && xmlLayer !== void 0 && xmlLayer.opaque) { | ||
layer.opaque = getXMLBoolean(xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.opaque); | ||
} | ||
if (xmlLayer !== null && xmlLayer !== void 0 && xmlLayer.cascaded) { | ||
layer.cascaded = getXMLBoolean(xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.cascaded); | ||
} | ||
if (xmlLayer !== null && xmlLayer !== void 0 && xmlLayer.queryable) { | ||
layer.queryable = getXMLBoolean(xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.queryable); | ||
} | ||
const xmlLayers = getXMLArray(xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.Layer); | ||
const layers = []; | ||
for (const xmlSubLayer of xmlLayers) { | ||
layers.push(extractLayer(xmlSubLayer)); | ||
} | ||
if (layers.length > 0) { | ||
layer.layers = layers; | ||
} | ||
for (const [key, value] of Object.entries(layer)) { | ||
if (value === undefined) { | ||
delete layer[key]; | ||
const layer = { | ||
// All layers must have a title | ||
title: String(xmlLayer?.Title || ''), | ||
// Name is required only if renderable | ||
name: xmlLayer?.Name && String(xmlLayer?.Name), | ||
abstract: xmlLayer?.Name && String(xmlLayer?.Abstract), | ||
keywords: getXMLStringArray(xmlLayer.KeywordList?.Keyword) | ||
}; | ||
// WMS 1.3.0 changes SRS to CRS | ||
const crs = xmlLayer?.CRS || xmlLayer?.SRS; | ||
if (crs && Array.isArray(crs) && crs.every((_) => typeof _ === 'string')) { | ||
layer.crs = crs; | ||
} | ||
} | ||
return layer; | ||
// v1.3.0 extract simple geographic bounding box | ||
let geographicBoundingBox = xmlLayer?.EX_GeographicBoundingBox && extractEXBoundingBox(xmlLayer?.EX_GeographicBoundingBox); | ||
if (geographicBoundingBox) { | ||
layer.geographicBoundingBox = geographicBoundingBox; | ||
} | ||
// v1.1.1 extract simple geographic bounding box | ||
geographicBoundingBox = | ||
xmlLayer?.LatLonBoundingBox && extractLatLonBoundingBox(xmlLayer?.LatLonBoundingBox); | ||
if (geographicBoundingBox) { | ||
layer.geographicBoundingBox = geographicBoundingBox; | ||
} | ||
// Extract per-CRS bounding boxes | ||
const boundingBoxes = xmlLayer?.BoundingBox && extractWMSBoundingBoxes(xmlLayer?.BoundingBox); | ||
if (boundingBoxes && boundingBoxes.length > 0) { | ||
layer.boundingBoxes = boundingBoxes; | ||
} | ||
// Extract dimensions | ||
const xmlDimensions = getXMLArray(xmlLayer?.Dimension); | ||
const dimensions = xmlDimensions.map((xml) => extractDimension(xml)); | ||
if (dimensions.length) { | ||
layer.dimensions = dimensions; | ||
} | ||
if (xmlLayer?.opaque) { | ||
layer.opaque = getXMLBoolean(xmlLayer?.opaque); | ||
} | ||
if (xmlLayer?.cascaded) { | ||
layer.cascaded = getXMLBoolean(xmlLayer?.cascaded); | ||
} | ||
if (xmlLayer?.queryable) { | ||
layer.queryable = getXMLBoolean(xmlLayer?.queryable); | ||
} | ||
// Single layer is not represented as array in XML | ||
const xmlLayers = getXMLArray(xmlLayer?.Layer); | ||
const layers = []; | ||
for (const xmlSubLayer of xmlLayers) { | ||
layers.push(extractLayer(xmlSubLayer)); | ||
} | ||
if (layers.length > 0) { | ||
layer.layers = layers; | ||
} | ||
// Clean up object | ||
for (const [key, value] of Object.entries(layer)) { | ||
if (value === undefined) { | ||
delete layer[key]; | ||
} | ||
} | ||
return layer; | ||
} | ||
/** WMS 1.3.0 Loosely defined geospatial bounding box in unspecified CRS for quick content searches */ | ||
function extractEXBoundingBox(xmlBoundingBox) { | ||
const { | ||
westBoundLongitude: w, | ||
northBoundLatitude: n, | ||
eastBoundLongitude: e, | ||
southBoundLatitude: s | ||
} = xmlBoundingBox; | ||
return [[w, s], [e, n]]; | ||
const { westBoundLongitude: w, northBoundLatitude: n, eastBoundLongitude: e, southBoundLatitude: s } = xmlBoundingBox; | ||
return [ | ||
[w, s], | ||
[e, n] | ||
]; | ||
} | ||
/** WMS 1.1.1 Loosely defined geospatial bounding box in unspecified CRS for quick content searches */ | ||
function extractLatLonBoundingBox(xmlBoundingBox) { | ||
const { | ||
minx, | ||
miny, | ||
maxx, | ||
maxy | ||
} = xmlBoundingBox; | ||
return [[minx, miny], [maxx, maxy]]; | ||
const { minx, miny, maxx, maxy } = xmlBoundingBox; | ||
return [ | ||
[minx, miny], | ||
[maxx, maxy] | ||
]; | ||
} | ||
/** Loosely defined geospatial bounding box in unspecified CRS for quick content searches */ | ||
function extractWMSBoundingBoxes(xmlBoundingBoxes) { | ||
const xmlBoxes = getXMLArray(xmlBoundingBoxes); | ||
return xmlBoxes.map(xmlBox => extractWMSBoundingBox(xmlBox)); | ||
const xmlBoxes = getXMLArray(xmlBoundingBoxes); | ||
return xmlBoxes.map((xmlBox) => extractWMSBoundingBox(xmlBox)); | ||
} | ||
/** Loosely defined geospatial bounding box in unspecified CRS for quick content searches */ | ||
function extractWMSBoundingBox(xmlBoundingBox) { | ||
const { | ||
CRS, | ||
SRS, | ||
minx, | ||
miny, | ||
maxx, | ||
maxy, | ||
resx, | ||
resy | ||
} = xmlBoundingBox; | ||
const boundingBox = { | ||
crs: CRS || SRS, | ||
boundingBox: [[getXMLFloat(minx), getXMLFloat(miny)], [getXMLFloat(maxx), getXMLFloat(maxy)]] | ||
}; | ||
if (resx) { | ||
boundingBox.xResolution = resx; | ||
} | ||
if (resy) { | ||
boundingBox.yResolution = resy; | ||
} | ||
return boundingBox; | ||
const { CRS, SRS, minx, miny, maxx, maxy, resx, resy } = xmlBoundingBox; | ||
const boundingBox = { | ||
// CRS in 1.3.0, SRS in 1.1.1 | ||
crs: CRS || SRS, | ||
boundingBox: [ | ||
[getXMLFloat(minx), getXMLFloat(miny)], | ||
[getXMLFloat(maxx), getXMLFloat(maxy)] | ||
] | ||
}; | ||
if (resx) { | ||
boundingBox.xResolution = resx; | ||
} | ||
if (resy) { | ||
boundingBox.yResolution = resy; | ||
} | ||
return boundingBox; | ||
} | ||
/** | ||
* Extracts optional WMS Dimension layer field | ||
* @param xmlDimension | ||
* @example <Dimension name="time" units="ISO8601" default="2018-01-01" nearestValue="0">2001-01-01/2018-01-01/P1Y</Dimension> | ||
* @see https://mapserver.org/ogc/wms_dimension.html | ||
*/ | ||
function extractDimension(xmlDimension) { | ||
const { | ||
name, | ||
units, | ||
value: extent | ||
} = xmlDimension; | ||
const dimension = { | ||
name, | ||
units, | ||
extent | ||
}; | ||
if (xmlDimension.unitSymbol) { | ||
dimension.unitSymbol = xmlDimension.unitSymbol; | ||
} | ||
if (xmlDimension.default) { | ||
dimension.defaultValue = xmlDimension.default; | ||
} | ||
if (xmlDimension.multipleValues) { | ||
dimension.multipleValues = getXMLBoolean(xmlDimension.multipleValues); | ||
} | ||
if (xmlDimension.nearestValue) { | ||
dimension.nearestValue = getXMLBoolean(xmlDimension.nearestValue); | ||
} | ||
if (xmlDimension.current) { | ||
dimension.current = getXMLBoolean(xmlDimension.current); | ||
} | ||
return dimension; | ||
const { name, units, value: extent } = xmlDimension; | ||
const dimension = { name, units, extent }; | ||
if (xmlDimension.unitSymbol) { | ||
dimension.unitSymbol = xmlDimension.unitSymbol; | ||
} | ||
if (xmlDimension.default) { | ||
dimension.defaultValue = xmlDimension.default; | ||
} | ||
if (xmlDimension.multipleValues) { | ||
dimension.multipleValues = getXMLBoolean(xmlDimension.multipleValues); | ||
} | ||
if (xmlDimension.nearestValue) { | ||
dimension.nearestValue = getXMLBoolean(xmlDimension.nearestValue); | ||
} | ||
if (xmlDimension.current) { | ||
dimension.current = getXMLBoolean(xmlDimension.current); | ||
} | ||
return dimension; | ||
} | ||
/** Traverse layers and inject missing props from parents */ | ||
// eslint-disable-next-line complexity | ||
function addInheritedLayerProps(layer, parent) { | ||
if (parent !== null && parent !== void 0 && parent.geographicBoundingBox && !layer.geographicBoundingBox) { | ||
layer.geographicBoundingBox = [...parent.geographicBoundingBox]; | ||
} | ||
if (parent !== null && parent !== void 0 && parent.crs && !layer.crs) { | ||
layer.crs = [...parent.crs]; | ||
} | ||
if (parent !== null && parent !== void 0 && parent.boundingBoxes && !layer.boundingBoxes) { | ||
layer.boundingBoxes = [...parent.boundingBoxes]; | ||
} | ||
if (parent !== null && parent !== void 0 && parent.dimensions && !layer.dimensions) { | ||
layer.dimensions = [...parent.dimensions]; | ||
} | ||
for (const subLayer of layer.layers || []) { | ||
addInheritedLayerProps(subLayer, layer); | ||
} | ||
if (parent?.geographicBoundingBox && !layer.geographicBoundingBox) { | ||
layer.geographicBoundingBox = [...parent.geographicBoundingBox]; | ||
} | ||
if (parent?.crs && !layer.crs) { | ||
layer.crs = [...parent.crs]; | ||
} | ||
if (parent?.boundingBoxes && !layer.boundingBoxes) { | ||
layer.boundingBoxes = [...parent.boundingBoxes]; | ||
} | ||
if (parent?.dimensions && !layer.dimensions) { | ||
layer.dimensions = [...parent.dimensions]; | ||
} | ||
for (const subLayer of layer.layers || []) { | ||
addInheritedLayerProps(subLayer, layer); | ||
} | ||
} | ||
//# sourceMappingURL=parse-wms-capabilities.js.map |
@@ -0,9 +1,20 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { XMLLoader } from '@loaders.gl/xml'; | ||
/** | ||
* Extract an error message from WMS error response XML | ||
* @param text | ||
* @param options | ||
* @returns a string with a human readable message | ||
*/ | ||
export function parseWMSError(text, options) { | ||
var _XMLLoader$parseTextS, _parsedXML$ServiceExc, _parsedXML$ogcServic; | ||
const parsedXML = (_XMLLoader$parseTextS = XMLLoader.parseTextSync) === null || _XMLLoader$parseTextS === void 0 ? void 0 : _XMLLoader$parseTextS.call(XMLLoader, text, options); | ||
const serviceExceptionXML = (parsedXML === null || parsedXML === void 0 ? void 0 : (_parsedXML$ServiceExc = parsedXML.ServiceExceptionReport) === null || _parsedXML$ServiceExc === void 0 ? void 0 : _parsedXML$ServiceExc.ServiceException) || (parsedXML === null || parsedXML === void 0 ? void 0 : (_parsedXML$ogcServic = parsedXML['ogc:ServiceExceptionReport']) === null || _parsedXML$ogcServic === void 0 ? void 0 : _parsedXML$ogcServic['ogc:ServiceException']); | ||
const message = typeof serviceExceptionXML === 'string' ? serviceExceptionXML : serviceExceptionXML.value || serviceExceptionXML.code || 'Unknown error'; | ||
return message; | ||
const parsedXML = XMLLoader.parseTextSync?.(text, options); | ||
const serviceExceptionXML = parsedXML?.ServiceExceptionReport?.ServiceException || | ||
parsedXML?.['ogc:ServiceExceptionReport']?.['ogc:ServiceException']; | ||
// Sigh, can be either a string or an object | ||
const message = typeof serviceExceptionXML === 'string' | ||
? serviceExceptionXML | ||
: serviceExceptionXML.value || serviceExceptionXML.code || 'Unknown error'; | ||
return message; | ||
} | ||
//# sourceMappingURL=parse-wms-error.js.map |
@@ -0,24 +1,25 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { XMLLoader } from '@loaders.gl/xml'; | ||
/** | ||
* Parses a typed data structure from raw XML for `GetFeatureInfo` response | ||
* @note Error handlings is fairly weak | ||
*/ | ||
export function parseWMSFeatureInfo(text, options) { | ||
var _XMLLoader$parseTextS, _parsedXML$FeatureInf; | ||
const parsedXML = (_XMLLoader$parseTextS = XMLLoader.parseTextSync) === null || _XMLLoader$parseTextS === void 0 ? void 0 : _XMLLoader$parseTextS.call(XMLLoader, text, options); | ||
const xmlFeatureInfo = ((_parsedXML$FeatureInf = parsedXML.FeatureInfoResponse) === null || _parsedXML$FeatureInf === void 0 ? void 0 : _parsedXML$FeatureInf.FIELDS) || []; | ||
const xmlFeatures = Array.isArray(xmlFeatureInfo) ? xmlFeatureInfo : [xmlFeatureInfo]; | ||
return { | ||
features: xmlFeatures.map(xmlFeature => extractFeature(xmlFeature)) | ||
}; | ||
const parsedXML = XMLLoader.parseTextSync?.(text, options); | ||
const xmlFeatureInfo = parsedXML.FeatureInfoResponse?.FIELDS || []; | ||
const xmlFeatures = Array.isArray(xmlFeatureInfo) ? xmlFeatureInfo : [xmlFeatureInfo]; | ||
return { | ||
features: xmlFeatures.map((xmlFeature) => extractFeature(xmlFeature)) | ||
}; | ||
} | ||
function extractFeature(xmlFeature) { | ||
const xmlFields = xmlFeature || {}; | ||
return { | ||
attributes: xmlFields, | ||
type: '', | ||
bounds: { | ||
bottom: 0, | ||
top: 0, | ||
left: 0, | ||
right: 0 | ||
} | ||
}; | ||
const xmlFields = xmlFeature || {}; | ||
// TODO - not correct | ||
return { | ||
attributes: xmlFields, | ||
type: '', | ||
bounds: { bottom: 0, top: 0, left: 0, right: 0 } | ||
}; | ||
} | ||
//# sourceMappingURL=parse-wms-features.js.map |
@@ -0,7 +1,13 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { XMLLoader } from '@loaders.gl/xml'; | ||
/** | ||
* Parses a typed data structure from raw XML for `GetFeatureInfo` response | ||
* @note Error handlings is fairly weak | ||
*/ | ||
export function parseWMSLayerDescription(text, options) { | ||
var _XMLLoader$parseTextS; | ||
const parsedXML = (_XMLLoader$parseTextS = XMLLoader.parseTextSync) === null || _XMLLoader$parseTextS === void 0 ? void 0 : _XMLLoader$parseTextS.call(XMLLoader, text, options); | ||
return parsedXML; | ||
const parsedXML = XMLLoader.parseTextSync?.(text, options); | ||
// TODO - implement parser | ||
return parsedXML; | ||
} | ||
//# sourceMappingURL=parse-wms-layer-description.js.map |
@@ -0,53 +1,62 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
/** A single element of an array is not represented as an array in XML */ | ||
export function getXMLArray(xmlValue) { | ||
if (Array.isArray(xmlValue)) { | ||
return xmlValue; | ||
} | ||
if (xmlValue) { | ||
return [xmlValue]; | ||
} | ||
return []; | ||
// Already an array, return as is | ||
if (Array.isArray(xmlValue)) { | ||
return xmlValue; | ||
} | ||
// Single value, wrap in array | ||
if (xmlValue) { | ||
return [xmlValue]; | ||
} | ||
// nullish, return empty array | ||
return []; | ||
} | ||
/** Get a list of strings from XML */ | ||
export function getXMLStringArray(xmlValue) { | ||
const xmlArray = getXMLArray(xmlValue); | ||
if (xmlArray.length > 0 && xmlArray.every(_ => typeof _ === 'string')) { | ||
return xmlArray; | ||
} | ||
return []; | ||
const xmlArray = getXMLArray(xmlValue); | ||
if (xmlArray.length > 0 && xmlArray.every((_) => typeof _ === 'string')) { | ||
return xmlArray; | ||
} | ||
// TODO - error handling? | ||
return []; | ||
} | ||
export function getXMLFloat(xmlValue) { | ||
let defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
switch (typeof xmlValue) { | ||
case 'number': | ||
return xmlValue; | ||
case 'string': | ||
return parseFloat(xmlValue); | ||
default: | ||
return undefined; | ||
} | ||
/** Get XML float */ | ||
export function getXMLFloat(xmlValue, defaultValue = undefined) { | ||
switch (typeof xmlValue) { | ||
case 'number': | ||
return xmlValue; | ||
case 'string': | ||
return parseFloat(xmlValue); | ||
default: | ||
return undefined; | ||
} | ||
} | ||
export function getXMLInteger(xmlValue) { | ||
let defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
switch (typeof xmlValue) { | ||
case 'number': | ||
return xmlValue; | ||
case 'string': | ||
return parseInt(xmlValue, 10); | ||
default: | ||
return undefined; | ||
} | ||
/** Get XML integer */ | ||
export function getXMLInteger(xmlValue, defaultValue = undefined) { | ||
switch (typeof xmlValue) { | ||
case 'number': | ||
return xmlValue; | ||
case 'string': | ||
return parseInt(xmlValue, 10); | ||
default: | ||
return undefined; | ||
} | ||
} | ||
/** Somewhat arbitrary boolean parsing */ | ||
export function getXMLBoolean(xmlValue) { | ||
switch (xmlValue) { | ||
case 'true': | ||
return true; | ||
case 'false': | ||
return false; | ||
case '1': | ||
return true; | ||
case '0': | ||
return false; | ||
default: | ||
return false; | ||
} | ||
switch (xmlValue) { | ||
case 'true': | ||
return true; | ||
case 'false': | ||
return false; | ||
case '1': | ||
return true; | ||
case '0': | ||
return false; | ||
default: | ||
return false; | ||
} | ||
} | ||
//# sourceMappingURL=parse-xml-helpers.js.map |
import { ImageSource, Service } from '@loaders.gl/loader-utils'; | ||
import { ImageServiceProps } from './image-service'; | ||
import { ImageServiceProps } from "./image-service.js"; | ||
export type CreateImageServiceProps = ImageServiceProps & { | ||
@@ -4,0 +4,0 @@ type?: string | 'auto'; |
@@ -0,27 +1,39 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
/** | ||
* Creates an image source | ||
* If type is not supplied, will try to automatically detect the the | ||
* @param url URL to the image source | ||
* @param type type of source. if not known, set to 'auto' | ||
* @returns an ImageSource instance | ||
*/ | ||
export function createImageService(props, services) { | ||
const { | ||
type = 'auto' | ||
} = props; | ||
const service = type === 'auto' ? guessServiceType(props.url, services) : getServiceOfType(type, services); | ||
if (!service) { | ||
throw new Error('Not a valid image source type'); | ||
} | ||
return service.create(props); | ||
const { type = 'auto' } = props; | ||
const service = type === 'auto' ? guessServiceType(props.url, services) : getServiceOfType(type, services); | ||
if (!service) { | ||
throw new Error('Not a valid image source type'); | ||
} | ||
return service.create(props); | ||
} | ||
/** Guess service type from URL */ | ||
function getServiceOfType(type, services) { | ||
for (const service of services) { | ||
if (service.type === type) { | ||
return service; | ||
// if (type === 'template') { | ||
// return ImageService; | ||
// } | ||
for (const service of services) { | ||
if (service.type === type) { | ||
return service; | ||
} | ||
} | ||
} | ||
return null; | ||
return null; | ||
} | ||
/** Guess service type from URL */ | ||
function guessServiceType(url, services) { | ||
for (const service of services) { | ||
if (service.testURL && service.testURL(url)) { | ||
return service; | ||
for (const service of services) { | ||
if (service.testURL && service.testURL(url)) { | ||
return service; | ||
} | ||
} | ||
} | ||
return null; | ||
return null; | ||
} | ||
//# sourceMappingURL=create-image-service.js.map |
@@ -0,38 +1,45 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { ImageLoader } from '@loaders.gl/images'; | ||
import { ImageSource } from '@loaders.gl/loader-utils'; | ||
/** | ||
* Quickly connect to "ad hoc" image sources without subclassing ImageSource. | ||
* ImageSource allows template url strings to be used to ad hoc connect to arbitrary image data sources | ||
* Accepts a template url string and builds requests URLs | ||
*/ | ||
export class ImageService extends ImageSource { | ||
constructor(props) { | ||
super(props); | ||
} | ||
async getMetadata() { | ||
throw new Error('ImageSource.getMetadata not implemented'); | ||
} | ||
async getImage(parameters) { | ||
const granularParameters = this.getGranularParameters(parameters); | ||
const url = this.getURLFromTemplate(granularParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
return await ImageLoader.parse(arrayBuffer); | ||
} | ||
getGranularParameters(parameters) { | ||
const [[east, north], [west, south]] = parameters.boundingBox; | ||
return { | ||
...parameters, | ||
east, | ||
north, | ||
south, | ||
west | ||
}; | ||
} | ||
getURLFromTemplate(parameters) { | ||
let url = this.props.url; | ||
for (const [key, value] of Object.entries(parameters)) { | ||
url = url.replace(`\${${key}}`, String(value)); | ||
url = url.replace(`{${key}}`, String(value)); | ||
constructor(props) { | ||
super(props); | ||
} | ||
return url; | ||
} | ||
// IMAGE SOURCE API | ||
async getMetadata() { | ||
throw new Error('ImageSource.getMetadata not implemented'); | ||
} | ||
async getImage(parameters) { | ||
const granularParameters = this.getGranularParameters(parameters); | ||
const url = this.getURLFromTemplate(granularParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
return await ImageLoader.parse(arrayBuffer); | ||
} | ||
// HELPERS | ||
/** Break up bounding box in east, north, south, west */ | ||
getGranularParameters(parameters) { | ||
const [[east, north], [west, south]] = parameters.boundingBox; | ||
return { ...parameters, east, north, south, west }; | ||
} | ||
/** Supports both ${} and {} notations */ | ||
getURLFromTemplate(parameters) { | ||
let url = this.props.url; | ||
for (const [key, value] of Object.entries(parameters)) { | ||
// TODO - parameter could be repeated | ||
// const regex = new RegExp(`\${${key}}`, 'g'); | ||
url = url.replace(`\${${key}}`, String(value)); | ||
url = url.replace(`{${key}}`, String(value)); | ||
} | ||
return url; | ||
} | ||
} | ||
ImageService.type = 'template'; | ||
ImageService.testURL = url => url.toLowerCase().includes('{'); | ||
//# sourceMappingURL=image-service.js.map | ||
ImageService.testURL = (url) => url.toLowerCase().includes('{'); |
import { ImageType } from '@loaders.gl/images'; | ||
import type { Service, ImageSourceMetadata, GetImageParameters } from '@loaders.gl/loader-utils'; | ||
import type { ImageServiceProps } from '../../lib/services/image-service'; | ||
import { ImageService } from '../../lib/services/image-service'; | ||
import type { ImageServiceProps } from "../../lib/services/image-service.js"; | ||
import { ImageService } from "../../lib/services/image-service.js"; | ||
export type ArcGISImageServerProps = ImageServiceProps & { | ||
@@ -6,0 +6,0 @@ url: string; |
@@ -0,60 +1,96 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { ImageService } from "../../lib/services/image-service.js"; | ||
/** | ||
* ArcGIS ImageServer | ||
* Note - exports a big API, that could be exposed here if there is a use case | ||
* @see https://developers.arcgis.com/rest/services-reference/enterprise/image-service.htm | ||
*/ | ||
export class ArcGISImageSource extends ImageService { | ||
constructor(props) { | ||
super(props); | ||
this.data = void 0; | ||
this.data = props.url; | ||
} | ||
async getMetadata() { | ||
return await this.metadata(); | ||
} | ||
async getImage(parameters) { | ||
throw new Error('not implemented'); | ||
} | ||
async metadata() { | ||
throw new Error('not implemented'); | ||
} | ||
exportImage(options) { | ||
throw new Error('not implemented'); | ||
} | ||
metadataURL(options) { | ||
return `${this.props.url}?f=pjson`; | ||
} | ||
exportImageURL(options) { | ||
const bbox = `bbox=${options.bbox[0]},${options.bbox[1]},${options.bbox[2]},${options.bbox[3]}`; | ||
const size = `size=${options.width},${options.height}`; | ||
const arcgisOptions = { | ||
...options, | ||
bbox, | ||
size | ||
}; | ||
delete arcgisOptions.width; | ||
delete arcgisOptions.height; | ||
return this.getUrl('exportImage', arcgisOptions); | ||
} | ||
getUrl(path, options, extra) { | ||
let url = `${this.props.url}/${path}`; | ||
let first = true; | ||
for (const [key, value] of Object.entries(options)) { | ||
url += first ? '?' : '&'; | ||
first = false; | ||
if (Array.isArray(value)) { | ||
url += `${key.toUpperCase()}=${value.join(',')}`; | ||
} else { | ||
url += `${key.toUpperCase()}=${value ? String(value) : ''}`; | ||
} | ||
constructor(props) { | ||
super(props); | ||
this.data = props.url; | ||
} | ||
return url; | ||
} | ||
async checkResponse(response) { | ||
if (!response.ok) { | ||
throw new Error('error'); | ||
// ImageSource (normalized endpoints) | ||
async getMetadata() { | ||
return (await this.metadata()); | ||
// TODO - normalize metadata | ||
} | ||
} | ||
async getImage(parameters) { | ||
throw new Error('not implemented'); | ||
// TODO - Map generic parameters to ArcGIS specific parameters | ||
// return await this.exportImage(parameters); | ||
} | ||
// ImageServer endpoints | ||
async metadata() { | ||
// We just need a JSON parsing... | ||
// return this.getUrl({path: '', ...options}); | ||
throw new Error('not implemented'); | ||
} | ||
/** | ||
* Form a URL to an ESRI ImageServer | ||
// https://sampleserver6.arcgisonline.com/arcgis/rest/services/NLCDLandCover2001/ImageServer/exportImage?bbox=${bounds[0]},${bounds[1]},${bounds[2]},${bounds[3]}&bboxSR=4326&size=${width},${height}&imageSR=102100&time=&format=jpgpng&pixelType=U8&noData=&noDataInterpretation=esriNoDataMatchAny&interpolation=+RSP_NearestNeighbor&compression=&compressionQuality=&bandIds=&mosaicRule=&renderingRule=&f=image`, | ||
*/ | ||
exportImage(options) { | ||
// See WMSService.getMap() | ||
throw new Error('not implemented'); | ||
} | ||
// URL creators | ||
metadataURL(options) { | ||
return `${this.props.url}?f=pjson`; | ||
} | ||
/** | ||
* Form a URL to an ESRI ImageServer | ||
// https://sampleserver6.arcgisonline.com/arcgis/rest/services/NLCDLandCover2001/ImageServer/exportImage? | ||
// bbox=${bounds[0]},${bounds[1]},${bounds[2]},${bounds[3]}&bboxSR=4326& | ||
// size=${width},${height}&imageSR=102100&time=&format=jpgpng&pixelType=U8& | ||
// noData=&noDataInterpretation=esriNoDataMatchAny&interpolation=+RSP_NearestNeighbor&compression=& | ||
// compressionQuality=&bandIds=&mosaicRule=&renderingRule=& | ||
// f=image | ||
*/ | ||
exportImageURL(options) { | ||
const bbox = `bbox=${options.bbox[0]},${options.bbox[1]},${options.bbox[2]},${options.bbox[3]}`; | ||
const size = `size=${options.width},${options.height}`; | ||
const arcgisOptions = { ...options, bbox, size }; | ||
// @ts-expect-error | ||
delete arcgisOptions.width; | ||
// @ts-expect-error | ||
delete arcgisOptions.height; | ||
return this.getUrl('exportImage', arcgisOptions); | ||
} | ||
// INTERNAL METHODS | ||
/** | ||
* @note protected, since perhaps getWMSUrl may need to be overridden to handle certain backends? | ||
* @note if override is common, maybe add a callback prop? | ||
* */ | ||
getUrl(path, options, extra) { | ||
let url = `${this.props.url}/${path}`; | ||
let first = true; | ||
for (const [key, value] of Object.entries(options)) { | ||
url += first ? '?' : '&'; | ||
first = false; | ||
if (Array.isArray(value)) { | ||
url += `${key.toUpperCase()}=${value.join(',')}`; | ||
} | ||
else { | ||
url += `${key.toUpperCase()}=${value ? String(value) : ''}`; | ||
} | ||
} | ||
return url; | ||
} | ||
/** Checks for and parses a WMS XML formatted ServiceError and throws an exception */ | ||
async checkResponse(response) { | ||
if (!response.ok) { | ||
// } || response.headers['content-type'] === WMSErrorLoader.mimeTypes[0]) { | ||
// const arrayBuffer = await response.arrayBuffer(); | ||
// const error = await WMSErrorLoader.parse(arrayBuffer, this.loadOptions); | ||
throw new Error('error'); | ||
} | ||
} | ||
} | ||
export const ArcGISImageService = { | ||
type: 'arcgis-image-server', | ||
testURL: url => url.toLowerCase().includes('ImageServer'), | ||
create: props => new ArcGISImageSource(props) | ||
type: 'arcgis-image-server', | ||
testURL: (url) => url.toLowerCase().includes('ImageServer'), | ||
create: (props) => new ArcGISImageSource(props) | ||
}; | ||
//# sourceMappingURL=arcgis-image-service.js.map |
@@ -1,33 +0,40 @@ | ||
export async function getArcGISServices(url) { | ||
let fetchFile = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : fetch; | ||
if (url.includes('rest/services')) { | ||
const serverUrl = url.replace(/rest\/services.*$/i, 'rest/services'); | ||
return loadServiceDirectory(serverUrl, fetchFile, []); | ||
} | ||
return null; | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
/** | ||
* (Recursively) load the service directory from an ArcGIS Server URL | ||
* @param url | ||
* @param fetchFile= Optional fetch function override | ||
* @returns | ||
*/ | ||
export async function getArcGISServices(url, fetchFile = fetch) { | ||
if (url.includes('rest/services')) { | ||
const serverUrl = url.replace(/rest\/services.*$/i, 'rest/services'); | ||
return loadServiceDirectory(serverUrl, fetchFile, []); | ||
} | ||
return null; | ||
} | ||
async function loadServiceDirectory(serverUrl, fetch, path) { | ||
const serviceUrl = `${serverUrl}/${path.join('/')}`; | ||
const response = await fetch(`${serviceUrl}?f=pjson`); | ||
const directory = await response.json(); | ||
const services = extractServices(directory, serviceUrl); | ||
const folders = directory.folders || []; | ||
const promises = folders.map(folder => loadServiceDirectory(`${serverUrl}`, fetch, [...path, folder])); | ||
for (const folderServices of await Promise.all(promises)) { | ||
services.push(...folderServices); | ||
} | ||
return services; | ||
const serviceUrl = `${serverUrl}/${path.join('/')}`; | ||
const response = await fetch(`${serviceUrl}?f=pjson`); | ||
const directory = await response.json(); | ||
const services = extractServices(directory, serviceUrl); | ||
const folders = (directory.folders || []); | ||
const promises = folders.map((folder) => loadServiceDirectory(`${serverUrl}`, fetch, [...path, folder])); | ||
for (const folderServices of await Promise.all(promises)) { | ||
services.push(...folderServices); | ||
} | ||
return services; | ||
} | ||
function extractServices(directory, url) { | ||
const arcgisServices = directory.services || []; | ||
const services = []; | ||
for (const service of arcgisServices) { | ||
services.push({ | ||
name: service.name, | ||
type: `arcgis-${service.type.toLocaleLowerCase().replace('server', '-server')}`, | ||
url: `${url}${service.name}/${service.type}` | ||
}); | ||
} | ||
return services; | ||
const arcgisServices = (directory.services || []); | ||
const services = []; | ||
for (const service of arcgisServices) { | ||
services.push({ | ||
name: service.name, | ||
type: `arcgis-${service.type.toLocaleLowerCase().replace('server', '-server')}`, | ||
url: `${url}${service.name}/${service.type}` | ||
}); | ||
} | ||
return services; | ||
} | ||
//# sourceMappingURL=arcgis-server.js.map |
import type { ImageSource } from '@loaders.gl/loader-utils'; | ||
import { ImageServiceProps } from '../lib/services/image-service'; | ||
import { CreateImageServiceProps } from '../lib/services/create-image-service'; | ||
import type { WMSSourceProps } from './ogc/wms-service'; | ||
import { ImageServiceProps } from "../lib/services/image-service.js"; | ||
import { CreateImageServiceProps } from "../lib/services/create-image-service.js"; | ||
import type { WMSSourceProps } from "./ogc/wms-service.js"; | ||
export type ImageServiceType = 'wms' | 'arcgis-image-server' | 'template'; | ||
@@ -6,0 +6,0 @@ type CreateImageSourceProps = CreateImageServiceProps & ImageServiceProps & WMSSourceProps & { |
@@ -0,1 +1,4 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { createImageService } from "../lib/services/create-image-service.js"; | ||
@@ -5,5 +8,11 @@ import { WMSService } from "./ogc/wms-service.js"; | ||
const SERVICES = [WMSService, ArcGISImageService]; | ||
/** | ||
* Creates an image source | ||
* If type is not supplied, will try to automatically detect the the | ||
* @param url URL to the image source | ||
* @param type type of source. if not known, set to 'auto' | ||
* @returns an ImageSource instance | ||
*/ | ||
export function createImageSource(props) { | ||
return createImageService(props, SERVICES); | ||
return createImageService(props, SERVICES); | ||
} | ||
//# sourceMappingURL=create-image-source.js.map |
import type { DataSourceProps } from '@loaders.gl/loader-utils'; | ||
import { DataSource } from '@loaders.gl/loader-utils'; | ||
import type { CSWCapabilities } from '../../csw-capabilities-loader'; | ||
import type { CSWRecords } from '../../csw-records-loader'; | ||
import type { CSWDomain } from '../../csw-domain-loader'; | ||
import type { CSWCapabilities } from "../../csw-capabilities-loader.js"; | ||
import type { CSWRecords } from "../../csw-records-loader.js"; | ||
import type { CSWDomain } from "../../csw-domain-loader.js"; | ||
type CSWCommonParameters = { | ||
@@ -7,0 +7,0 @@ /** In case the endpoint supports multiple services */ |
@@ -0,1 +1,4 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { DataSource } from '@loaders.gl/loader-utils'; | ||
@@ -6,150 +9,161 @@ import { CSWCapabilitiesLoader } from "../../csw-capabilities-loader.js"; | ||
import { WMSErrorLoader as CSWErrorLoader } from "../../wms-error-loader.js"; | ||
/** | ||
* The CSWService class | ||
* - provides type safe methods to form URLs to a CSW service | ||
* - provides type safe methods to query and parse results (and errors) from a CSW service | ||
* @note Only the URL parameter conversion is supported. XML posts are not supported. | ||
*/ | ||
export class CSWService extends DataSource { | ||
constructor(props) { | ||
super(props); | ||
this.capabilities = null; | ||
this.data = void 0; | ||
this.url = void 0; | ||
this.loaders = [CSWErrorLoader, CSWCapabilitiesLoader]; | ||
this.url = props.url; | ||
this.data = props.url; | ||
} | ||
async getMetadata() { | ||
const capabilities = await this.getCapabilities(); | ||
return this.normalizeMetadata(capabilities); | ||
} | ||
normalizeMetadata(capabilities) { | ||
return capabilities; | ||
} | ||
async getServiceDirectory(options) { | ||
const services = []; | ||
const unknownServices = []; | ||
const records = await this.getRecords(); | ||
for (const record of records.records) { | ||
for (const reference of record.references) { | ||
const url = reference.value; | ||
switch (reference.scheme) { | ||
case 'OGC:WMS': | ||
services.push({ | ||
name: record.title, | ||
type: 'ogc-wms-service', | ||
...this._parseOGCUrl(url) | ||
}); | ||
break; | ||
case 'OGC:WMTS': | ||
services.push({ | ||
name: record.title, | ||
type: 'ogc-wmts-service', | ||
...this._parseOGCUrl(url) | ||
}); | ||
break; | ||
case 'OGC:WFS': | ||
services.push({ | ||
name: record.title, | ||
type: 'ogc-wfs-service', | ||
...this._parseOGCUrl(url) | ||
}); | ||
break; | ||
default: | ||
unknownServices.push({ | ||
name: record.title, | ||
type: 'unknown', | ||
url: reference.value, | ||
scheme: reference.scheme | ||
}); | ||
/** Create a CSWService */ | ||
constructor(props) { | ||
super(props); | ||
this.capabilities = null; | ||
/** A list of loaders used by the CSWService methods */ | ||
this.loaders = [CSWErrorLoader, CSWCapabilitiesLoader]; | ||
this.url = props.url; | ||
this.data = props.url; | ||
} | ||
async getMetadata() { | ||
const capabilities = await this.getCapabilities(); | ||
return this.normalizeMetadata(capabilities); | ||
} | ||
normalizeMetadata(capabilities) { | ||
return capabilities; | ||
} | ||
async getServiceDirectory(options) { | ||
const services = []; | ||
const unknownServices = []; | ||
const records = await this.getRecords(); | ||
for (const record of records.records) { | ||
for (const reference of record.references) { | ||
const url = reference.value; | ||
switch (reference.scheme) { | ||
case 'OGC:WMS': | ||
services.push({ name: record.title, type: 'ogc-wms-service', ...this._parseOGCUrl(url) }); | ||
break; | ||
case 'OGC:WMTS': | ||
services.push({ | ||
name: record.title, | ||
type: 'ogc-wmts-service', | ||
...this._parseOGCUrl(url) | ||
}); | ||
break; | ||
case 'OGC:WFS': | ||
services.push({ name: record.title, type: 'ogc-wfs-service', ...this._parseOGCUrl(url) }); | ||
break; | ||
default: | ||
unknownServices.push({ | ||
name: record.title, | ||
type: 'unknown', | ||
url: reference.value, | ||
scheme: reference.scheme | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
return options?.includeUnknown ? services.concat(unknownServices) : services; | ||
} | ||
return options !== null && options !== void 0 && options.includeUnknown ? services.concat(unknownServices) : services; | ||
} | ||
_parseOGCUrl(url) { | ||
const parts = url.split('?'); | ||
return { | ||
url: parts[0], | ||
params: parts[1] || '' | ||
}; | ||
} | ||
async getCapabilities(wmsParameters, vendorParameters) { | ||
const url = this.getCapabilitiesURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
const capabilities = await CSWCapabilitiesLoader.parse(arrayBuffer, this.props.loadOptions); | ||
return capabilities; | ||
} | ||
async getRecords(wmsParameters, vendorParameters) { | ||
const url = this.getRecordsURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
return await CSWRecordsLoader.parse(arrayBuffer, this.props.loadOptions); | ||
} | ||
async getDomain(wmsParameters, vendorParameters) { | ||
const url = this.getDomainURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
return await CSWDomainLoader.parse(arrayBuffer, this.props.loadOptions); | ||
} | ||
getCapabilitiesURL(wmsParameters, vendorParameters) { | ||
const options = { | ||
version: '3.0.0', | ||
...wmsParameters, | ||
...vendorParameters, | ||
service: 'CSW', | ||
request: 'GetCapabilities' | ||
}; | ||
return this._getCSWUrl(options, vendorParameters); | ||
} | ||
getRecordsURL(wmsParameters, vendorParameters) { | ||
const options = { | ||
version: '3.0.0', | ||
typenames: 'csw:Record', | ||
...wmsParameters, | ||
...vendorParameters, | ||
service: 'CSW', | ||
request: 'GetRecords' | ||
}; | ||
return this._getCSWUrl(options, vendorParameters); | ||
} | ||
getDomainURL(wmsParameters, vendorParameters) { | ||
const options = { | ||
version: '3.0.0', | ||
...wmsParameters, | ||
...vendorParameters, | ||
service: 'CSW', | ||
request: 'GetDomain' | ||
}; | ||
return this._getCSWUrl(options, vendorParameters); | ||
} | ||
_getCSWUrl(options, vendorParameters) { | ||
let url = this.props.url; | ||
let first = true; | ||
for (const [key, value] of Object.entries(options)) { | ||
url += first ? '?' : '&'; | ||
first = false; | ||
if (Array.isArray(value)) { | ||
url += `${key.toUpperCase()}=${value.join(',')}`; | ||
} else { | ||
url += `${key.toUpperCase()}=${value ? String(value) : ''}`; | ||
} | ||
_parseOGCUrl(url) { | ||
const parts = url.split('?'); | ||
return { | ||
url: parts[0], | ||
params: parts[1] || '' | ||
}; | ||
} | ||
return encodeURI(url); | ||
} | ||
_checkResponse(response, arrayBuffer) { | ||
const contentType = response.headers['content-type']; | ||
if (!response.ok || CSWErrorLoader.mimeTypes.includes(contentType)) { | ||
var _CSWErrorLoader$parse; | ||
const error = (_CSWErrorLoader$parse = CSWErrorLoader.parseSync) === null || _CSWErrorLoader$parse === void 0 ? void 0 : _CSWErrorLoader$parse.call(CSWErrorLoader, arrayBuffer, this.props.loadOptions); | ||
throw new Error(error); | ||
// CSW Service API Stubs | ||
/** Get Capabilities */ | ||
async getCapabilities(wmsParameters, vendorParameters) { | ||
const url = this.getCapabilitiesURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
const capabilities = await CSWCapabilitiesLoader.parse(arrayBuffer, this.props.loadOptions); | ||
return capabilities; | ||
} | ||
} | ||
_parseError(arrayBuffer) { | ||
var _CSWErrorLoader$parse2; | ||
const error = (_CSWErrorLoader$parse2 = CSWErrorLoader.parseSync) === null || _CSWErrorLoader$parse2 === void 0 ? void 0 : _CSWErrorLoader$parse2.call(CSWErrorLoader, arrayBuffer, this.props.loadOptions); | ||
return new Error(error); | ||
} | ||
/** Get Records */ | ||
async getRecords(wmsParameters, vendorParameters) { | ||
const url = this.getRecordsURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
return await CSWRecordsLoader.parse(arrayBuffer, this.props.loadOptions); | ||
} | ||
/** Get Domain */ | ||
async getDomain(wmsParameters, vendorParameters) { | ||
const url = this.getDomainURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
return await CSWDomainLoader.parse(arrayBuffer, this.props.loadOptions); | ||
} | ||
// Typed URL creators | ||
// For applications that want full control of fetching and parsing | ||
/** Generate a URL for the GetCapabilities request */ | ||
getCapabilitiesURL(wmsParameters, vendorParameters) { | ||
const options = { | ||
version: '3.0.0', | ||
...wmsParameters, | ||
...vendorParameters, | ||
service: 'CSW', | ||
request: 'GetCapabilities' | ||
}; | ||
return this._getCSWUrl(options, vendorParameters); | ||
} | ||
/** Generate a URL for the GetCapabilities request */ | ||
getRecordsURL(wmsParameters, vendorParameters) { | ||
const options = { | ||
version: '3.0.0', | ||
typenames: 'csw:Record', | ||
...wmsParameters, | ||
...vendorParameters, | ||
service: 'CSW', | ||
request: 'GetRecords' | ||
}; | ||
return this._getCSWUrl(options, vendorParameters); | ||
} | ||
/** Generate a URL for the GetCapabilities request */ | ||
getDomainURL(wmsParameters, vendorParameters) { | ||
const options = { | ||
version: '3.0.0', | ||
...wmsParameters, | ||
...vendorParameters, | ||
service: 'CSW', | ||
request: 'GetDomain' | ||
}; | ||
return this._getCSWUrl(options, vendorParameters); | ||
} | ||
// INTERNAL METHODS | ||
/** | ||
* @note case _getCSWUrl may need to be overridden to handle certain backends? | ||
* */ | ||
_getCSWUrl(options, vendorParameters) { | ||
let url = this.props.url; | ||
let first = true; | ||
for (const [key, value] of Object.entries(options)) { | ||
url += first ? '?' : '&'; | ||
first = false; | ||
if (Array.isArray(value)) { | ||
url += `${key.toUpperCase()}=${value.join(',')}`; | ||
} | ||
else { | ||
url += `${key.toUpperCase()}=${value ? String(value) : ''}`; | ||
} | ||
} | ||
return encodeURI(url); | ||
} | ||
/** Checks for and parses a CSW XML formatted ServiceError and throws an exception */ | ||
_checkResponse(response, arrayBuffer) { | ||
const contentType = response.headers['content-type']; | ||
if (!response.ok || CSWErrorLoader.mimeTypes.includes(contentType)) { | ||
const error = CSWErrorLoader.parseSync?.(arrayBuffer, this.props.loadOptions); | ||
throw new Error(error); | ||
} | ||
} | ||
/** Error situation detected */ | ||
_parseError(arrayBuffer) { | ||
const error = CSWErrorLoader.parseSync?.(arrayBuffer, this.props.loadOptions); | ||
return new Error(error); | ||
} | ||
} | ||
CSWService.type = 'csw'; | ||
CSWService.testURL = url => url.toLowerCase().includes('csw'); | ||
//# sourceMappingURL=csw-service.js.map | ||
CSWService.testURL = (url) => url.toLowerCase().includes('csw'); |
import type { ImageType } from '@loaders.gl/images'; | ||
import type { Service, ImageSourceMetadata, GetImageParameters } from '@loaders.gl/loader-utils'; | ||
import { ImageSource } from '@loaders.gl/loader-utils'; | ||
import type { ImageServiceProps } from '../../lib/services/image-service'; | ||
import type { WMSCapabilities } from '../../wms-capabilities-loader'; | ||
import type { WMSFeatureInfo } from '../../wip/wms-feature-info-loader'; | ||
import type { WMSLayerDescription } from '../../wip/wms-layer-description-loader'; | ||
import type { ImageServiceProps } from "../../lib/services/image-service.js"; | ||
import type { WMSCapabilities } from "../../wms-capabilities-loader.js"; | ||
import type { WMSFeatureInfo } from "../../wip/wms-feature-info-loader.js"; | ||
import type { WMSLayerDescription } from "../../wip/wms-layer-description-loader.js"; | ||
export declare const WMSService: Service<WMSSource, WMSSourceProps>; | ||
@@ -9,0 +9,0 @@ /** |
@@ -0,1 +1,4 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { ImageLoader } from '@loaders.gl/images'; | ||
@@ -9,258 +12,308 @@ import { mergeLoaderOptions } from '@loaders.gl/loader-utils'; | ||
export const WMSService = { | ||
type: 'wms', | ||
testURL: url => url.toLowerCase().includes('wms'), | ||
create: props => new WMSSource(props) | ||
type: 'wms', | ||
testURL: (url) => url.toLowerCase().includes('wms'), | ||
create: (props) => new WMSSource(props) | ||
}; | ||
/** | ||
* The WMSSource class provides | ||
* - provides type safe methods to form URLs to a WMS service | ||
* - provides type safe methods to query and parse results (and errors) from a WMS service | ||
* - implements the ImageService interface | ||
* @note Only the URL parameter conversion is supported. XML posts are not supported. | ||
*/ | ||
export class WMSSource extends ImageSource { | ||
constructor(props) { | ||
var _props$substituteCRS; | ||
super(props); | ||
this.url = void 0; | ||
this.data = void 0; | ||
this.substituteCRS84 = void 0; | ||
this.flipCRS = void 0; | ||
this.wmsParameters = void 0; | ||
this.vendorParameters = void 0; | ||
this.capabilities = null; | ||
this.url = props.url; | ||
this.data = props.url; | ||
this.substituteCRS84 = (_props$substituteCRS = props.substituteCRS84) !== null && _props$substituteCRS !== void 0 ? _props$substituteCRS : false; | ||
this.flipCRS = ['EPSG:4326']; | ||
this.wmsParameters = { | ||
layers: undefined, | ||
query_layers: undefined, | ||
styles: undefined, | ||
version: '1.3.0', | ||
crs: 'EPSG:4326', | ||
format: 'image/png', | ||
info_format: 'text/plain', | ||
transparent: undefined, | ||
time: undefined, | ||
elevation: undefined, | ||
...props.wmsParameters | ||
}; | ||
this.vendorParameters = props.vendorParameters || {}; | ||
} | ||
async getMetadata() { | ||
const capabilities = await this.getCapabilities(); | ||
return this.normalizeMetadata(capabilities); | ||
} | ||
async getImage(parameters) { | ||
const { | ||
boundingBox, | ||
bbox, | ||
...rest | ||
} = parameters; | ||
const wmsParameters = { | ||
bbox: boundingBox ? [...boundingBox[0], ...boundingBox[1]] : bbox, | ||
...rest | ||
}; | ||
return await this.getMap(wmsParameters); | ||
} | ||
normalizeMetadata(capabilities) { | ||
return capabilities; | ||
} | ||
async getCapabilities(wmsParameters, vendorParameters) { | ||
const url = this.getCapabilitiesURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
const capabilities = await WMSCapabilitiesLoader.parse(arrayBuffer, this.loadOptions); | ||
this.capabilities = capabilities; | ||
return capabilities; | ||
} | ||
async getMap(wmsParameters, vendorParameters) { | ||
const url = this.getMapURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
try { | ||
return await ImageLoader.parse(arrayBuffer, this.loadOptions); | ||
} catch { | ||
throw this._parseError(arrayBuffer); | ||
/** Create a WMSSource */ | ||
constructor(props) { | ||
super(props); | ||
this.capabilities = null; | ||
// TODO - defaults such as version, layers etc could be extracted from a base URL with parameters | ||
// This would make pasting in any WMS URL more likely to make this class just work. | ||
// const {baseUrl, parameters} = this._parseWMSUrl(props.url); | ||
this.url = props.url; | ||
this.data = props.url; | ||
this.substituteCRS84 = props.substituteCRS84 ?? false; | ||
this.flipCRS = ['EPSG:4326']; | ||
this.wmsParameters = { | ||
layers: undefined, | ||
query_layers: undefined, | ||
styles: undefined, | ||
version: '1.3.0', | ||
crs: 'EPSG:4326', | ||
format: 'image/png', | ||
info_format: 'text/plain', | ||
transparent: undefined, | ||
time: undefined, | ||
elevation: undefined, | ||
...props.wmsParameters | ||
}; | ||
this.vendorParameters = props.vendorParameters || {}; | ||
} | ||
} | ||
async getFeatureInfo(wmsParameters, vendorParameters) { | ||
const url = this.getFeatureInfoURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
return await WMSFeatureInfoLoader.parse(arrayBuffer, this.loadOptions); | ||
} | ||
async getFeatureInfoText(wmsParameters, vendorParameters) { | ||
const url = this.getFeatureInfoURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
return new TextDecoder().decode(arrayBuffer); | ||
} | ||
async describeLayer(wmsParameters, vendorParameters) { | ||
const url = this.describeLayerURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
return await WMSLayerDescriptionLoader.parse(arrayBuffer, this.loadOptions); | ||
} | ||
async getLegendGraphic(wmsParameters, vendorParameters) { | ||
const url = this.getLegendGraphicURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
try { | ||
return await ImageLoader.parse(arrayBuffer, this.loadOptions); | ||
} catch { | ||
throw this._parseError(arrayBuffer); | ||
// ImageService implementation | ||
async getMetadata() { | ||
const capabilities = await this.getCapabilities(); | ||
return this.normalizeMetadata(capabilities); | ||
} | ||
} | ||
getCapabilitiesURL(wmsParameters, vendorParameters) { | ||
const options = { | ||
version: this.wmsParameters.version, | ||
...wmsParameters | ||
}; | ||
return this._getWMSUrl('GetCapabilities', options, vendorParameters); | ||
} | ||
getMapURL(wmsParameters, vendorParameters) { | ||
wmsParameters = this._getWMS130Parameters(wmsParameters); | ||
const options = { | ||
version: this.wmsParameters.version, | ||
format: this.wmsParameters.format, | ||
transparent: this.wmsParameters.transparent, | ||
time: this.wmsParameters.time, | ||
elevation: this.wmsParameters.elevation, | ||
layers: this.wmsParameters.layers, | ||
styles: this.wmsParameters.styles, | ||
crs: this.wmsParameters.crs, | ||
...wmsParameters | ||
}; | ||
return this._getWMSUrl('GetMap', options, vendorParameters); | ||
} | ||
getFeatureInfoURL(wmsParameters, vendorParameters) { | ||
wmsParameters = this._getWMS130Parameters(wmsParameters); | ||
const options = { | ||
version: this.wmsParameters.version, | ||
info_format: this.wmsParameters.info_format, | ||
layers: this.wmsParameters.layers, | ||
query_layers: this.wmsParameters.query_layers, | ||
styles: this.wmsParameters.styles, | ||
crs: this.wmsParameters.crs, | ||
...wmsParameters | ||
}; | ||
return this._getWMSUrl('GetFeatureInfo', options, vendorParameters); | ||
} | ||
describeLayerURL(wmsParameters, vendorParameters) { | ||
const options = { | ||
version: this.wmsParameters.version, | ||
...wmsParameters | ||
}; | ||
return this._getWMSUrl('DescribeLayer', options, vendorParameters); | ||
} | ||
getLegendGraphicURL(wmsParameters, vendorParameters) { | ||
const options = { | ||
version: this.wmsParameters.version, | ||
...wmsParameters | ||
}; | ||
return this._getWMSUrl('GetLegendGraphic', options, vendorParameters); | ||
} | ||
_parseWMSUrl(url) { | ||
const [baseUrl, search] = url.split('?'); | ||
const searchParams = search.split('&'); | ||
const parameters = {}; | ||
for (const parameter of searchParams) { | ||
const [key, value] = parameter.split('='); | ||
parameters[key] = value; | ||
async getImage(parameters) { | ||
// Replace the GetImage `boundingBox` parameter with the WMS flat `bbox` parameter. | ||
const { boundingBox, bbox, ...rest } = parameters; | ||
const wmsParameters = { | ||
bbox: boundingBox ? [...boundingBox[0], ...boundingBox[1]] : bbox, | ||
...rest | ||
}; | ||
return await this.getMap(wmsParameters); | ||
} | ||
return { | ||
url: baseUrl, | ||
parameters | ||
}; | ||
} | ||
_getWMSUrl(request, wmsParameters, vendorParameters) { | ||
let url = this.url; | ||
let first = true; | ||
const allParameters = { | ||
service: 'WMS', | ||
version: wmsParameters.version, | ||
request, | ||
...wmsParameters, | ||
...this.vendorParameters, | ||
...vendorParameters | ||
}; | ||
const IGNORE_EMPTY_KEYS = ['transparent', 'time', 'elevation']; | ||
for (const [key, value] of Object.entries(allParameters)) { | ||
if (!IGNORE_EMPTY_KEYS.includes(key) || value) { | ||
url += first ? '?' : '&'; | ||
first = false; | ||
url += this._getURLParameter(key, value, wmsParameters); | ||
} | ||
normalizeMetadata(capabilities) { | ||
return capabilities; | ||
} | ||
return encodeURI(url); | ||
} | ||
_getWMS130Parameters(wmsParameters) { | ||
const newParameters = { | ||
...wmsParameters | ||
}; | ||
if (newParameters.srs) { | ||
newParameters.crs = newParameters.crs || newParameters.srs; | ||
delete newParameters.srs; | ||
// WMS Service API Stubs | ||
/** Get Capabilities */ | ||
async getCapabilities(wmsParameters, vendorParameters) { | ||
const url = this.getCapabilitiesURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
const capabilities = await WMSCapabilitiesLoader.parse(arrayBuffer, this.loadOptions); | ||
this.capabilities = capabilities; | ||
return capabilities; | ||
} | ||
return newParameters; | ||
} | ||
_getURLParameter(key, value, wmsParameters) { | ||
switch (key) { | ||
case 'crs': | ||
if (wmsParameters.version !== '1.3.0') { | ||
key = 'srs'; | ||
} else if (this.substituteCRS84 && value === 'EPSG:4326') { | ||
value = 'CRS:84'; | ||
/** Get a map image */ | ||
async getMap(wmsParameters, vendorParameters) { | ||
const url = this.getMapURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
try { | ||
return await ImageLoader.parse(arrayBuffer, this.loadOptions); | ||
} | ||
break; | ||
case 'srs': | ||
if (wmsParameters.version === '1.3.0') { | ||
key = 'crs'; | ||
catch { | ||
throw this._parseError(arrayBuffer); | ||
} | ||
break; | ||
case 'bbox': | ||
const bbox = this._flipBoundingBox(value, wmsParameters); | ||
if (bbox) { | ||
value = bbox; | ||
} | ||
/** Get Feature Info for a coordinate */ | ||
async getFeatureInfo(wmsParameters, vendorParameters) { | ||
const url = this.getFeatureInfoURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
return await WMSFeatureInfoLoader.parse(arrayBuffer, this.loadOptions); | ||
} | ||
/** Get Feature Info for a coordinate */ | ||
async getFeatureInfoText(wmsParameters, vendorParameters) { | ||
const url = this.getFeatureInfoURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
return new TextDecoder().decode(arrayBuffer); | ||
} | ||
/** Get more information about a layer */ | ||
async describeLayer(wmsParameters, vendorParameters) { | ||
const url = this.describeLayerURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
return await WMSLayerDescriptionLoader.parse(arrayBuffer, this.loadOptions); | ||
} | ||
/** Get an image with a semantic legend */ | ||
async getLegendGraphic(wmsParameters, vendorParameters) { | ||
const url = this.getLegendGraphicURL(wmsParameters, vendorParameters); | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
try { | ||
return await ImageLoader.parse(arrayBuffer, this.loadOptions); | ||
} | ||
break; | ||
default: | ||
catch { | ||
throw this._parseError(arrayBuffer); | ||
} | ||
} | ||
key = key.toUpperCase(); | ||
return Array.isArray(value) ? `${key}=${value.join(',')}` : `${key}=${value ? String(value) : ''}`; | ||
} | ||
_flipBoundingBox(bboxValue, wmsParameters) { | ||
if (!Array.isArray(bboxValue) || bboxValue.length !== 4) { | ||
return null; | ||
// Typed URL creators | ||
// For applications that want full control of fetching and parsing | ||
/** Generate a URL for the GetCapabilities request */ | ||
getCapabilitiesURL(wmsParameters, vendorParameters) { | ||
const options = { | ||
version: this.wmsParameters.version, | ||
...wmsParameters | ||
}; | ||
return this._getWMSUrl('GetCapabilities', options, vendorParameters); | ||
} | ||
const flipCoordinates = wmsParameters.version === '1.3.0' && this.flipCRS.includes(wmsParameters.crs || '') && !(this.substituteCRS84 && wmsParameters.crs === 'EPSG:4326'); | ||
const bbox = bboxValue; | ||
return flipCoordinates ? [bbox[1], bbox[0], bbox[3], bbox[2]] : bbox; | ||
} | ||
async _fetchArrayBuffer(url) { | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
return arrayBuffer; | ||
} | ||
_checkResponse(response, arrayBuffer) { | ||
const contentType = response.headers['content-type']; | ||
if (!response.ok || WMSErrorLoader.mimeTypes.includes(contentType)) { | ||
var _WMSErrorLoader$parse; | ||
const loadOptions = mergeLoaderOptions(this.loadOptions, { | ||
wms: { | ||
throwOnError: true | ||
/** Generate a URL for the GetMap request */ | ||
getMapURL(wmsParameters, vendorParameters) { | ||
wmsParameters = this._getWMS130Parameters(wmsParameters); | ||
const options = { | ||
version: this.wmsParameters.version, | ||
format: this.wmsParameters.format, | ||
transparent: this.wmsParameters.transparent, | ||
time: this.wmsParameters.time, | ||
elevation: this.wmsParameters.elevation, | ||
layers: this.wmsParameters.layers, | ||
styles: this.wmsParameters.styles, | ||
crs: this.wmsParameters.crs, | ||
// bbox: [-77.87304, 40.78975, -77.85828, 40.80228], | ||
// width: 1200, | ||
// height: 900, | ||
...wmsParameters | ||
}; | ||
return this._getWMSUrl('GetMap', options, vendorParameters); | ||
} | ||
/** Generate a URL for the GetFeatureInfo request */ | ||
getFeatureInfoURL(wmsParameters, vendorParameters) { | ||
wmsParameters = this._getWMS130Parameters(wmsParameters); | ||
const options = { | ||
version: this.wmsParameters.version, | ||
// query_layers: [], | ||
// format: this.wmsParameters.format, | ||
info_format: this.wmsParameters.info_format, | ||
layers: this.wmsParameters.layers, | ||
query_layers: this.wmsParameters.query_layers, | ||
styles: this.wmsParameters.styles, | ||
crs: this.wmsParameters.crs, | ||
// bbox: [-77.87304, 40.78975, -77.85828, 40.80228], | ||
// width: 1200, | ||
// height: 900, | ||
// x: undefined!, | ||
// y: undefined!, | ||
...wmsParameters | ||
}; | ||
return this._getWMSUrl('GetFeatureInfo', options, vendorParameters); | ||
} | ||
/** Generate a URL for the GetFeatureInfo request */ | ||
describeLayerURL(wmsParameters, vendorParameters) { | ||
const options = { | ||
version: this.wmsParameters.version, | ||
...wmsParameters | ||
}; | ||
return this._getWMSUrl('DescribeLayer', options, vendorParameters); | ||
} | ||
getLegendGraphicURL(wmsParameters, vendorParameters) { | ||
const options = { | ||
version: this.wmsParameters.version, | ||
// format? | ||
...wmsParameters | ||
}; | ||
return this._getWMSUrl('GetLegendGraphic', options, vendorParameters); | ||
} | ||
// INTERNAL METHODS | ||
_parseWMSUrl(url) { | ||
const [baseUrl, search] = url.split('?'); | ||
const searchParams = search.split('&'); | ||
const parameters = {}; | ||
for (const parameter of searchParams) { | ||
const [key, value] = parameter.split('='); | ||
parameters[key] = value; | ||
} | ||
}); | ||
const error = (_WMSErrorLoader$parse = WMSErrorLoader.parseSync) === null || _WMSErrorLoader$parse === void 0 ? void 0 : _WMSErrorLoader$parse.call(WMSErrorLoader, arrayBuffer, loadOptions); | ||
throw new Error(error); | ||
return { url: baseUrl, parameters }; | ||
} | ||
} | ||
_parseError(arrayBuffer) { | ||
var _WMSErrorLoader$parse2; | ||
const error = (_WMSErrorLoader$parse2 = WMSErrorLoader.parseSync) === null || _WMSErrorLoader$parse2 === void 0 ? void 0 : _WMSErrorLoader$parse2.call(WMSErrorLoader, arrayBuffer, this.loadOptions); | ||
return new Error(error); | ||
} | ||
/** | ||
* Generate a URL with parameters | ||
* @note case _getWMSUrl may need to be overridden to handle certain backends? | ||
* @note at the moment, only URLs with parameters are supported (no XML payloads) | ||
* */ | ||
_getWMSUrl(request, wmsParameters, vendorParameters) { | ||
let url = this.url; | ||
let first = true; | ||
// Add any vendor searchParams | ||
const allParameters = { | ||
service: 'WMS', | ||
version: wmsParameters.version, | ||
request, | ||
...wmsParameters, | ||
...this.vendorParameters, | ||
...vendorParameters | ||
}; | ||
// Encode the keys | ||
const IGNORE_EMPTY_KEYS = ['transparent', 'time', 'elevation']; | ||
for (const [key, value] of Object.entries(allParameters)) { | ||
// hack to preserve test cases. Not super clear if keys should be included when values are undefined | ||
if (!IGNORE_EMPTY_KEYS.includes(key) || value) { | ||
url += first ? '?' : '&'; | ||
first = false; | ||
url += this._getURLParameter(key, value, wmsParameters); | ||
} | ||
} | ||
return encodeURI(url); | ||
} | ||
_getWMS130Parameters(wmsParameters) { | ||
const newParameters = { ...wmsParameters }; | ||
if (newParameters.srs) { | ||
newParameters.crs = newParameters.crs || newParameters.srs; | ||
delete newParameters.srs; | ||
} | ||
return newParameters; | ||
} | ||
// eslint-disable-next-line complexity | ||
_getURLParameter(key, value, wmsParameters) { | ||
// Substitute by key | ||
switch (key) { | ||
case 'crs': | ||
// CRS was called SRS before WMS 1.3.0 | ||
if (wmsParameters.version !== '1.3.0') { | ||
key = 'srs'; | ||
} | ||
else if (this.substituteCRS84 && value === 'EPSG:4326') { | ||
/** In 1.3.0, replaces references to 'EPSG:4326' with the new backwards compatible CRS:84 */ | ||
// Substitute by value | ||
value = 'CRS:84'; | ||
} | ||
break; | ||
case 'srs': | ||
// CRS was called SRS before WMS 1.3.0 | ||
if (wmsParameters.version === '1.3.0') { | ||
key = 'crs'; | ||
} | ||
break; | ||
case 'bbox': | ||
// Coordinate order is flipped for certain CRS in WMS 1.3.0 | ||
const bbox = this._flipBoundingBox(value, wmsParameters); | ||
if (bbox) { | ||
value = bbox; | ||
} | ||
break; | ||
default: | ||
// do nothing | ||
} | ||
key = key.toUpperCase(); | ||
return Array.isArray(value) | ||
? `${key}=${value.join(',')}` | ||
: `${key}=${value ? String(value) : ''}`; | ||
} | ||
/** Coordinate order is flipped for certain CRS in WMS 1.3.0 */ | ||
_flipBoundingBox(bboxValue, wmsParameters) { | ||
// Sanity checks | ||
if (!Array.isArray(bboxValue) || bboxValue.length !== 4) { | ||
return null; | ||
} | ||
const flipCoordinates = | ||
// Only affects WMS 1.3.0 | ||
wmsParameters.version === '1.3.0' && | ||
// Flip if we are dealing with a CRS that was flipped in 1.3.0 | ||
this.flipCRS.includes(wmsParameters.crs || '') && | ||
// Don't flip if we are subsituting EPSG:4326 with CRS:84 | ||
!(this.substituteCRS84 && wmsParameters.crs === 'EPSG:4326'); | ||
const bbox = bboxValue; | ||
return flipCoordinates ? [bbox[1], bbox[0], bbox[3], bbox[2]] : bbox; | ||
} | ||
/** Fetches an array buffer and checks the response (boilerplate reduction) */ | ||
async _fetchArrayBuffer(url) { | ||
const response = await this.fetch(url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
this._checkResponse(response, arrayBuffer); | ||
return arrayBuffer; | ||
} | ||
/** Checks for and parses a WMS XML formatted ServiceError and throws an exception */ | ||
_checkResponse(response, arrayBuffer) { | ||
const contentType = response.headers['content-type']; | ||
if (!response.ok || WMSErrorLoader.mimeTypes.includes(contentType)) { | ||
// We want error responses to throw exceptions, the WMSErrorLoader can do this | ||
const loadOptions = mergeLoaderOptions(this.loadOptions, { | ||
wms: { throwOnError: true } | ||
}); | ||
const error = WMSErrorLoader.parseSync?.(arrayBuffer, loadOptions); | ||
throw new Error(error); | ||
} | ||
} | ||
/** Error situation detected */ | ||
_parseError(arrayBuffer) { | ||
const error = WMSErrorLoader.parseSync?.(arrayBuffer, this.loadOptions); | ||
return new Error(error); | ||
} | ||
} | ||
//# sourceMappingURL=wms-service.js.map |
@@ -0,2 +1,59 @@ | ||
"use strict"; | ||
// loaders.gl, MIT license | ||
/** General data source class */ | ||
// export abstract class DataSource {}; | ||
// export type DataSourceMetadata = {}; | ||
// ImageSource | ||
// Tile Source | ||
/** Data source that serves data by tile index * | ||
export abstract class TileDataSource extends DataSource {}; | ||
//# sourceMappingURL=data-source.js.map | ||
// Image Tile Data Source | ||
export type ImageTileDataSourceCapabilities = { | ||
} | ||
export type ImageTile = Record<string, any>; | ||
export type FeatureInfo = {}; | ||
export abstract class ImageTileDataSource extends TileDataSource { | ||
source: ImageDataSource; | ||
constructor(source: ImageDataSource) { | ||
super(); | ||
this.source = source; | ||
} | ||
getCapabilities(): Promise<ImageTileDataSourceCapabilities> { | ||
return this.source.getCapabilities(); | ||
} | ||
getTile({x, y, z, width, height, layers, parameters}): Promise<ImageType> { | ||
const boundingBox = this.getBoundingBoxFromTileIndex(x, y, z); | ||
return this.source.getImage({boundingBox, width, height, layers, parameters}); | ||
} | ||
getFeatureInfo(): FeatureInfo | null { | ||
return null; | ||
} | ||
getBoundingBoxFromTileIndex(x: number, y: number, z: number): [number, number, number, number] { | ||
return [0, 0, 1, 1]; | ||
} | ||
} | ||
// Vector Tile Source | ||
export type VectorTileDataSourceCapabilities = { | ||
// check tile.json | ||
} | ||
export type VectorTile = Record<string, any>; | ||
export abstract class VectorTileDataSource extends TileDataSource { | ||
abstract getCapabilities(): Promise<VectorTileDataSourceCapabilities>; | ||
abstract getTile({x, y, z, width, height, layers, parameters}): Promise<VectorTile>; | ||
} | ||
*/ |
@@ -0,14 +1,11 @@ | ||
// loaders.gl, MIT license | ||
import { XMLLoader } from '@loaders.gl/xml'; | ||
/** | ||
* Parses a typed data structure from raw XML for `GetCapabilities` response | ||
* @note Error handlings is fairly weak | ||
*/ | ||
export function parseWCSCapabilities(text, options) { | ||
var _XMLLoader$parseTextS; | ||
const parsedXML = (_XMLLoader$parseTextS = XMLLoader.parseTextSync) === null || _XMLLoader$parseTextS === void 0 ? void 0 : _XMLLoader$parseTextS.call(XMLLoader, text, { | ||
...options, | ||
xml: { | ||
...(options === null || options === void 0 ? void 0 : options.xml), | ||
removeNSPrefix: true | ||
} | ||
}); | ||
const xmlCapabilities = parsedXML.Capabilities || parsedXML; | ||
return xmlCapabilities; | ||
const parsedXML = XMLLoader.parseTextSync?.(text, { ...options, xml: { ...options?.xml, removeNSPrefix: true } }); | ||
const xmlCapabilities = parsedXML.Capabilities || parsedXML; | ||
return xmlCapabilities; | ||
} | ||
//# sourceMappingURL=parse-wcs-capabilities.js.map |
@@ -0,15 +1,15 @@ | ||
// loaders.gl, MIT license | ||
import { XMLLoader } from '@loaders.gl/xml'; | ||
/** | ||
* Parses a typed data structure from raw XML for `GetCapabilities` response | ||
* @note Error handlings is fairly weak | ||
*/ | ||
export function parseWFSCapabilities(text, options) { | ||
var _XMLLoader$parseTextS; | ||
const parsedXML = (_XMLLoader$parseTextS = XMLLoader.parseTextSync) === null || _XMLLoader$parseTextS === void 0 ? void 0 : _XMLLoader$parseTextS.call(XMLLoader, text, { | ||
...options, | ||
xml: { | ||
...(options === null || options === void 0 ? void 0 : options.xml), | ||
removeNSPrefix: true, | ||
uncapitalizeKeys: true | ||
} | ||
}); | ||
const xmlCapabilities = parsedXML.Capabilities || parsedXML; | ||
return xmlCapabilities; | ||
const parsedXML = XMLLoader.parseTextSync?.(text, { ...options, xml: { | ||
...options?.xml, | ||
removeNSPrefix: true, | ||
uncapitalizeKeys: true | ||
} }); | ||
const xmlCapabilities = parsedXML.Capabilities || parsedXML; | ||
return xmlCapabilities; | ||
} | ||
//# sourceMappingURL=parse-wfs-capabilities.js.map |
@@ -0,28 +1,28 @@ | ||
// loaders.gl, MIT license | ||
import { XMLLoader } from '@loaders.gl/xml'; | ||
/** | ||
* Parses a typed data structure from raw XML for `GetCapabilities` response | ||
* @note Error handlings is fairly weak | ||
*/ | ||
export function parseWFSCapabilities(text, options) { | ||
var _options, _XMLLoader$parseTextS; | ||
options = { | ||
...options, | ||
xml: { | ||
...((_options = options) === null || _options === void 0 ? void 0 : _options.xml), | ||
removeNSPrefix: true | ||
} | ||
}; | ||
const parsedXML = (_XMLLoader$parseTextS = XMLLoader.parseTextSync) === null || _XMLLoader$parseTextS === void 0 ? void 0 : _XMLLoader$parseTextS.call(XMLLoader, text, options); | ||
const xmlCapabilities = parsedXML.Capabilities || parsedXML; | ||
return uncapitalizeKeys(xmlCapabilities); | ||
// Remove namespaces in XML | ||
options = { ...options, xml: { ...options?.xml, removeNSPrefix: true } }; | ||
const parsedXML = XMLLoader.parseTextSync?.(text, options); | ||
const xmlCapabilities = parsedXML.Capabilities || parsedXML; | ||
return uncapitalizeKeys(xmlCapabilities); | ||
} | ||
/** Uncapitalize all keys of an object */ | ||
function uncapitalizeKeys(object) { | ||
if (object && typeof object === 'object') { | ||
const newObject = {}; | ||
for (const [key, value] of Object.entries(object)) { | ||
newObject[uncapitalize(key)] = uncapitalizeKeys(value); | ||
if (object && typeof object === 'object') { | ||
const newObject = {}; | ||
for (const [key, value] of Object.entries(object)) { | ||
newObject[uncapitalize(key)] = uncapitalizeKeys(value); | ||
} | ||
return newObject; | ||
} | ||
return newObject; | ||
} | ||
return object; | ||
return object; | ||
} | ||
/** Uncapitalize first letter of a string */ | ||
function uncapitalize(str) { | ||
return typeof str === 'string' ? str.charAt(0).toLowerCase() + str.slice(1) : str; | ||
return typeof str === 'string' ? str.charAt(0).toLowerCase() + str.slice(1) : str; | ||
} | ||
//# sourceMappingURL=parse-wfs.js.map |
@@ -0,15 +1,73 @@ | ||
// loaders.gl, MIT license | ||
import { XMLLoader } from '@loaders.gl/xml'; | ||
/** | ||
* Parses a typed data structure from raw XML for `GetCapabilities` response | ||
* @note Error handlings is fairly weak | ||
*/ | ||
export function parseWMTSCapabilities(text, options) { | ||
var _XMLLoader$parseTextS; | ||
const parsedXML = (_XMLLoader$parseTextS = XMLLoader.parseTextSync) === null || _XMLLoader$parseTextS === void 0 ? void 0 : _XMLLoader$parseTextS.call(XMLLoader, text, { | ||
...options, | ||
xml: { | ||
...(options === null || options === void 0 ? void 0 : options.xml), | ||
removeNSPrefix: true, | ||
uncapitalizeKeys: true | ||
} | ||
}); | ||
const xmlCapabilities = parsedXML.Capabilities || parsedXML; | ||
return xmlCapabilities; | ||
const parsedXML = XMLLoader.parseTextSync?.(text, { ...options, xml: { | ||
...options?.xml, | ||
removeNSPrefix: true, | ||
uncapitalizeKeys: true | ||
} }); | ||
const xmlCapabilities = parsedXML.Capabilities || parsedXML; | ||
return xmlCapabilities; | ||
} | ||
//# sourceMappingURL=parse-wmts-capabilities.js.map | ||
/** | ||
* Parses a typed data structure from raw XML for `GetCapabilities` response | ||
* @note Error handlings is fairly weak | ||
*/ | ||
// export function parseWMTSCapabilities(text: string, options): WMTSCapabilities { | ||
// const parsedXML = XMLLoader.parseTextSync(text, options); | ||
// const xmlCapabilities: any = | ||
// parsedXML.WMT_MS_Capabilities || parsedXML.WMS_Capabilities || parsedXML; | ||
// return extractCapabilities(xmlCapabilities); | ||
// } | ||
/** Extract typed capability data from XML */ | ||
// function extractCapabilities(xml: any): WMTSCapabilities { | ||
// const capabilities: WMTSCapabilities = { | ||
// name: xml.Service?.Name || 'unnamed', | ||
// title: xml.Service?.Title, | ||
// keywords: [], | ||
// requests: {}, | ||
// layer: extractLayer(xml.Capability?.Layer), | ||
// raw: xml | ||
// }; | ||
// for (const keyword of xml.Service?.KeywordList?.Keyword || []) { | ||
// capabilities.keywords.push(keyword); | ||
// } | ||
// for (const [name, xmlRequest] of Object.entries(xml.Capability?.Request || {})) { | ||
// capabilities.requests[name] = extractRequest(name, xmlRequest); | ||
// } | ||
// return capabilities; | ||
// } | ||
// /** Extract typed request data from XML */ | ||
// function extractRequest(name: string, xmlRequest: any): WMSRequest { | ||
// const format: string | string[] = xmlRequest?.Format; | ||
// const mimeTypes: string[] = Array.isArray(format) ? format : [format]; | ||
// return {name, mimeTypes}; | ||
// } | ||
// /** Extract request data */ | ||
// function extractLayer(xmlLayer: any): WMSLayer { | ||
// const layer: WMSLayer = { | ||
// name: xmlLayer?.Name, | ||
// title: xmlLayer?.Title, | ||
// srs: xmlLayer?.SRS || [], | ||
// layers: [] | ||
// }; | ||
// // Single layer is not represented as array in XML | ||
// const xmlLayers = getXMLArray(xmlLayer?.Layer); | ||
// for (const xmlSubLayer of xmlLayers) { | ||
// layer.layers?.push(extractLayer(xmlSubLayer)); | ||
// } | ||
// return layer; | ||
// } | ||
// function getXMLArray(xmlValue: any) { | ||
// if (Array.isArray(xmlValue)) { | ||
// return xmlValue; | ||
// } | ||
// if (xmlValue) { | ||
// return [xmlValue]; | ||
// } | ||
// return []; | ||
// } |
@@ -0,28 +1,31 @@ | ||
// loaders.gl, MIT license | ||
import { XMLLoader } from '@loaders.gl/xml'; | ||
/** | ||
* Parses a typed data structure from raw XML for `GetCapabilities` response | ||
* @note Error handlings is fairly weak | ||
*/ | ||
export function parseWMTSCapabilities(text, options) { | ||
var _options, _XMLLoader$parseTextS; | ||
options = { | ||
...options, | ||
xml: { | ||
...((_options = options) === null || _options === void 0 ? void 0 : _options.xml), | ||
removeNSPrefix: true | ||
} | ||
}; | ||
const parsedXML = (_XMLLoader$parseTextS = XMLLoader.parseTextSync) === null || _XMLLoader$parseTextS === void 0 ? void 0 : _XMLLoader$parseTextS.call(XMLLoader, text, options); | ||
const xmlCapabilities = parsedXML.Capabilities || parsedXML; | ||
return uncapitalizeKeys(xmlCapabilities); | ||
// Remove namespaces in XML | ||
options = { ...options, xml: { ...options?.xml, removeNSPrefix: true } }; | ||
const parsedXML = XMLLoader.parseTextSync?.(text, options); | ||
const xmlCapabilities = parsedXML.Capabilities || parsedXML; | ||
return uncapitalizeKeys(xmlCapabilities); | ||
} | ||
function uncapitalizeKeys(object) { | ||
if (object && typeof object === 'object') { | ||
const newObject = {}; | ||
for (const [key, value] of Object.entries(object)) { | ||
newObject[uncapitalize(key)] = uncapitalizeKeys(value); | ||
if (object && typeof object === 'object') { | ||
const newObject = {}; | ||
for (const [key, value] of Object.entries(object)) { | ||
newObject[uncapitalize(key)] = uncapitalizeKeys(value); | ||
} | ||
return newObject; | ||
} | ||
return newObject; | ||
} | ||
return object; | ||
return object; | ||
} | ||
/** | ||
* Uncapitalize first letter of a string | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
function uncapitalize(str) { | ||
return typeof str === 'string' ? str.charAt(0).toLowerCase() + str.slice(1) : str; | ||
return typeof str === 'string' ? str.charAt(0).toLowerCase() + str.slice(1) : str; | ||
} | ||
//# sourceMappingURL=parse-wmts.js.map |
@@ -0,24 +1,24 @@ | ||
// @ts-nocheck | ||
export class ArcGISFeatureService { | ||
constructor(props) { | ||
this.url = void 0; | ||
this.loadOptions = void 0; | ||
this.fetch = void 0; | ||
this.url = props.url; | ||
this.loadOptions = props.loadOptions || {}; | ||
this.fetch = props.fetch || fetch; | ||
} | ||
metadataURL(options) { | ||
return this.getUrl({ | ||
...options | ||
}); | ||
} | ||
exportImageURL(options) { | ||
const { | ||
boundingBox | ||
} = options; | ||
return this.getUrl({ | ||
path: 'exportImage' | ||
}); | ||
} | ||
constructor(props) { | ||
this.url = props.url; | ||
this.loadOptions = props.loadOptions || {}; | ||
this.fetch = props.fetch || fetch; | ||
} | ||
// URL creators | ||
metadataURL(options) { | ||
return this.getUrl({ ...options }); | ||
} | ||
/** | ||
* Form a URL to an ESRI FeatureServer | ||
// https://services2.arcgis.com/CcI36Pduqd0OR4W9/ArcGIS/rest/services/Bicycle_Routes_Public/FeatureServer/0/query? | ||
// returnGeometry=true&where=1%3D1&outSR=4326&outFields=*&inSR=4326&geometry=${-90}%2C+${30}%2C+${-70}%2C+${50}& | ||
// geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelIntersects&geometryPrecision=6&resultType=tile&f=geojson` | ||
*/ | ||
exportImageURL(options) { | ||
const { boundingBox } = options; | ||
// const bbox = `bbox=${boundingBox[0]},${boundingBox[1]},${boundingBox[2]},${boundingBox[3]}`; | ||
// const size = `size=${width},${height}` | ||
return this.getUrl({ path: 'exportImage', }); | ||
} | ||
} | ||
//# sourceMappingURL=arcgis-feature-service.js.map |
import type { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils'; | ||
import type { WCSCapabilities } from './lib/wcs/parse-wcs-capabilities'; | ||
import type { WCSCapabilities } from "./lib/wcs/parse-wcs-capabilities.js"; | ||
export { WCSCapabilities }; | ||
@@ -4,0 +4,0 @@ export type WCSLoaderOptions = LoaderOptions & { |
@@ -0,22 +1,28 @@ | ||
// loaders.gl, MIT license | ||
import { parseWCSCapabilities } from "./lib/wcs/parse-wcs-capabilities.js"; | ||
// __VERSION__ is injected by babel-plugin-version-inline | ||
// @ts-ignore TS2304: Cannot find name '__VERSION__'. | ||
const VERSION = typeof "4.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest'; | ||
/** | ||
* Loader for the response to the WCS GetCapability request | ||
*/ | ||
export const WCSCapabilitiesLoader = { | ||
id: 'wcs-capabilities', | ||
name: 'WFS Capabilities', | ||
module: 'wms', | ||
version: VERSION, | ||
worker: false, | ||
extensions: ['xml'], | ||
mimeTypes: ['application/vnd.ogc.wcs_xml', 'application/xml', 'text/xml'], | ||
testText: testXMLFile, | ||
options: { | ||
wms: {} | ||
}, | ||
parse: async (arrayBuffer, options) => parseWCSCapabilities(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseWCSCapabilities(text, options) | ||
id: 'wcs-capabilities', | ||
name: 'WFS Capabilities', | ||
module: 'wms', | ||
version: VERSION, | ||
worker: false, | ||
extensions: ['xml'], | ||
mimeTypes: ['application/vnd.ogc.wcs_xml', 'application/xml', 'text/xml'], | ||
testText: testXMLFile, | ||
options: { | ||
wms: {} | ||
}, | ||
parse: async (arrayBuffer, options) => parseWCSCapabilities(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseWCSCapabilities(text, options) | ||
}; | ||
function testXMLFile(text) { | ||
return text.startsWith('<?xml'); | ||
// TODO - There could be space first. | ||
return text.startsWith('<?xml'); | ||
} | ||
export const _typecheckWFSCapabilitiesLoader = WCSCapabilitiesLoader; | ||
//# sourceMappingURL=wcs-capabilities-loader.js.map |
import type { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils'; | ||
import type { WFSCapabilities } from './lib/wfs/parse-wfs-capabilities'; | ||
import type { WFSCapabilities } from "./lib/wfs/parse-wfs-capabilities.js"; | ||
export type { WFSCapabilities }; | ||
@@ -4,0 +4,0 @@ export type WFSLoaderOptions = LoaderOptions & { |
@@ -0,22 +1,28 @@ | ||
// loaders.gl, MIT license | ||
import { parseWFSCapabilities } from "./lib/wfs/parse-wfs-capabilities.js"; | ||
// __VERSION__ is injected by babel-plugin-version-inline | ||
// @ts-ignore TS2304: Cannot find name '__VERSION__'. | ||
const VERSION = typeof "4.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest'; | ||
/** | ||
* Loader for the response to the WFS GetCapability request | ||
*/ | ||
export const WFSCapabilitiesLoader = { | ||
id: 'wfs-capabilities', | ||
name: 'WFS Capabilities', | ||
module: 'wms', | ||
version: VERSION, | ||
worker: false, | ||
extensions: ['xml'], | ||
mimeTypes: ['application/vnd.ogc.wfs_xml', 'application/xml', 'text/xml'], | ||
testText: testXMLFile, | ||
options: { | ||
wfs: {} | ||
}, | ||
parse: async (arrayBuffer, options) => parseWFSCapabilities(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseWFSCapabilities(text, options) | ||
id: 'wfs-capabilities', | ||
name: 'WFS Capabilities', | ||
module: 'wms', | ||
version: VERSION, | ||
worker: false, | ||
extensions: ['xml'], | ||
mimeTypes: ['application/vnd.ogc.wfs_xml', 'application/xml', 'text/xml'], | ||
testText: testXMLFile, | ||
options: { | ||
wfs: {} | ||
}, | ||
parse: async (arrayBuffer, options) => parseWFSCapabilities(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseWFSCapabilities(text, options) | ||
}; | ||
function testXMLFile(text) { | ||
return text.startsWith('<?xml'); | ||
// TODO - There could be space first. | ||
return text.startsWith('<?xml'); | ||
} | ||
export const _typecheckWFSCapabilitiesLoader = WFSCapabilitiesLoader; | ||
//# sourceMappingURL=wfs-capabilities-loader.js.map |
import type { LoaderWithParser } from '@loaders.gl/loader-utils'; | ||
import type { XMLLoaderOptions } from '@loaders.gl/xml'; | ||
import type { WMSFeatureInfo } from '../lib/parsers/wms/parse-wms-features'; | ||
import type { WMSFeatureInfo } from "../lib/parsers/wms/parse-wms-features.js"; | ||
export { WMSFeatureInfo }; | ||
@@ -5,0 +5,0 @@ /** |
@@ -0,11 +1,15 @@ | ||
// loaders.gl, MIT license | ||
import { WMSCapabilitiesLoader } from "../wms-capabilities-loader.js"; | ||
import { parseWMSFeatureInfo } from "../lib/parsers/wms/parse-wms-features.js"; | ||
/** | ||
* Loader for the response to the WMS GetFeatureInfo request | ||
*/ | ||
// @ts-expect-error | ||
export const WMSFeatureInfoLoader = { | ||
...WMSCapabilitiesLoader, | ||
id: 'wms-feature-info', | ||
name: 'WMS FeatureInfo', | ||
parse: async (arrayBuffer, options) => parseWMSFeatureInfo(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseWMSFeatureInfo(text, options) | ||
...WMSCapabilitiesLoader, | ||
id: 'wms-feature-info', | ||
name: 'WMS FeatureInfo', | ||
parse: async (arrayBuffer, options) => parseWMSFeatureInfo(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseWMSFeatureInfo(text, options) | ||
}; | ||
export const _typecheckWMSFeatureInfoLoader = WMSFeatureInfoLoader; | ||
//# sourceMappingURL=wms-feature-info-loader.js.map |
import type { LoaderWithParser } from '@loaders.gl/loader-utils'; | ||
import type { XMLLoaderOptions } from '@loaders.gl/xml'; | ||
import type { WMSLayerDescription } from '../lib/parsers/wms/parse-wms-layer-description'; | ||
import type { WMSLayerDescription } from "../lib/parsers/wms/parse-wms-layer-description.js"; | ||
export { WMSLayerDescription }; | ||
@@ -5,0 +5,0 @@ /** |
@@ -0,11 +1,14 @@ | ||
// loaders.gl, MIT license | ||
import { WMSCapabilitiesLoader } from "../wms-capabilities-loader.js"; | ||
import { parseWMSLayerDescription } from "../lib/parsers/wms/parse-wms-layer-description.js"; | ||
/** | ||
* Loader for the response to the WMS DescribeLayer request | ||
*/ | ||
export const WMSLayerDescriptionLoader = { | ||
...WMSCapabilitiesLoader, | ||
id: 'wms-layer-description', | ||
name: 'WMS DescribeLayer', | ||
parse: async (arrayBuffer, options) => parseWMSLayerDescription(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseWMSLayerDescription(text, options) | ||
...WMSCapabilitiesLoader, | ||
id: 'wms-layer-description', | ||
name: 'WMS DescribeLayer', | ||
parse: async (arrayBuffer, options) => parseWMSLayerDescription(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseWMSLayerDescription(text, options) | ||
}; | ||
export const _typecheckWMSFeatureInfoLoader = WMSLayerDescriptionLoader; | ||
//# sourceMappingURL=wms-layer-description-loader.js.map |
@@ -0,22 +1,29 @@ | ||
// loaders.gl, MIT license | ||
// import type {WMTSCapabilities} from './lib/wmts/parse-wmts-capabilities'; | ||
import { parseWMTSCapabilities } from "./lib/wmts/parse-wmts-capabilities.js"; | ||
// __VERSION__ is injected by babel-plugin-version-inline | ||
// @ts-ignore TS2304: Cannot find name '__VERSION__'. | ||
const VERSION = typeof "4.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest'; | ||
/** | ||
* Loader for the response to the WMTS GetCapability request | ||
*/ | ||
export const WMTSCapabilitiesLoader = { | ||
id: 'wmts-capabilities', | ||
name: 'WMTS Capabilities', | ||
module: 'wms', | ||
version: VERSION, | ||
worker: false, | ||
extensions: ['xml'], | ||
mimeTypes: ['application/vnd.ogc.wmts_xml', 'application/xml', 'text/xml'], | ||
testText: testXMLFile, | ||
options: { | ||
wms: {} | ||
}, | ||
parse: async (arrayBuffer, options) => parseWMTSCapabilities(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseWMTSCapabilities(text, options) | ||
id: 'wmts-capabilities', | ||
name: 'WMTS Capabilities', | ||
module: 'wms', | ||
version: VERSION, | ||
worker: false, | ||
extensions: ['xml'], | ||
mimeTypes: ['application/vnd.ogc.wmts_xml', 'application/xml', 'text/xml'], | ||
testText: testXMLFile, | ||
options: { | ||
wms: {} | ||
}, | ||
parse: async (arrayBuffer, options) => parseWMTSCapabilities(new TextDecoder().decode(arrayBuffer), options), | ||
parseTextSync: (text, options) => parseWMTSCapabilities(text, options) | ||
}; | ||
function testXMLFile(text) { | ||
return text.startsWith('<?xml'); | ||
// TODO - There could be space first. | ||
return text.startsWith('<?xml'); | ||
} | ||
export const _typecheckWMTSCapabilitiesLoader = WMTSCapabilitiesLoader; | ||
//# sourceMappingURL=wmts-capabilities-loader.js.map |
import type { LoaderWithParser } from '@loaders.gl/loader-utils'; | ||
import type { XMLLoaderOptions } from '@loaders.gl/xml'; | ||
import { WMSCapabilities } from './lib/parsers/wms/parse-wms-capabilities'; | ||
export type { WMSCapabilities, WMSLayer, WMSBoundingBox, WMSDimension, WMSRequest, WMSExceptions } from './lib/parsers/wms/parse-wms-capabilities'; | ||
import { WMSCapabilities } from "./lib/parsers/wms/parse-wms-capabilities.js"; | ||
export type { WMSCapabilities, WMSLayer, WMSBoundingBox, WMSDimension, WMSRequest, WMSExceptions } from "./lib/parsers/wms/parse-wms-capabilities.js"; | ||
export type WMSCapabilitiesLoaderOptions = XMLLoaderOptions & { | ||
@@ -6,0 +6,0 @@ wms?: { |
@@ -0,21 +1,33 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { parseWMSCapabilities } from "./lib/parsers/wms/parse-wms-capabilities.js"; | ||
// __VERSION__ is injected by babel-plugin-version-inline | ||
// @ts-ignore TS2304: Cannot find name '__VERSION__'. | ||
const VERSION = typeof "4.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest'; | ||
/** | ||
* Loader for the response to the WMS GetCapability request | ||
*/ | ||
export const WMSCapabilitiesLoader = { | ||
id: 'wms-capabilities', | ||
name: 'WMS Capabilities', | ||
module: 'wms', | ||
version: VERSION, | ||
worker: false, | ||
extensions: ['xml'], | ||
mimeTypes: ['application/vnd.ogc.wms_xml', 'application/xml', 'text/xml'], | ||
testText: testXMLFile, | ||
options: { | ||
wms: {} | ||
}, | ||
parse: async (arrayBuffer, options) => parseWMSCapabilities(new TextDecoder().decode(arrayBuffer), options === null || options === void 0 ? void 0 : options.wms), | ||
parseTextSync: (text, options) => parseWMSCapabilities(text, options === null || options === void 0 ? void 0 : options.wms) | ||
id: 'wms-capabilities', | ||
name: 'WMS Capabilities', | ||
module: 'wms', | ||
version: VERSION, | ||
worker: false, | ||
extensions: ['xml'], | ||
mimeTypes: ['application/vnd.ogc.wms_xml', 'application/xml', 'text/xml'], | ||
testText: testXMLFile, | ||
options: { | ||
wms: {} | ||
}, | ||
parse: async (arrayBuffer, options) => | ||
// TODO pass in XML options | ||
parseWMSCapabilities(new TextDecoder().decode(arrayBuffer), options?.wms), | ||
parseTextSync: (text, options) => | ||
// TODO pass in XML options | ||
parseWMSCapabilities(text, options?.wms) | ||
}; | ||
function testXMLFile(text) { | ||
return text.startsWith('<?xml'); | ||
// TODO - There could be space first. | ||
return text.startsWith('<?xml'); | ||
} | ||
//# sourceMappingURL=wms-capabilities-loader.js.map |
@@ -0,36 +1,41 @@ | ||
// 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.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest'; | ||
/** | ||
* Loader for the response to the WMS GetCapability request | ||
*/ | ||
export const WMSErrorLoader = { | ||
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) | ||
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) { | ||
return text.startsWith('<?xml'); | ||
// TODO - There could be space first. | ||
return text.startsWith('<?xml'); | ||
} | ||
function parseTextSync(text, options) { | ||
const wmsOptions = { | ||
...WMSErrorLoader.options.wms, | ||
...(options === null || options === void 0 ? void 0 : 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; | ||
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; | ||
} | ||
//# sourceMappingURL=wms-error-loader.js.map |
{ | ||
"name": "@loaders.gl/wms", | ||
"version": "4.2.0-alpha.4", | ||
"version": "4.2.0-alpha.5", | ||
"description": "Framework-independent loaders for the WMS (Web Map Service) standard", | ||
@@ -46,3 +46,3 @@ "license": "MIT", | ||
"pre-build": "npm run build-bundle && npm run build-bundle -- --env=dev", | ||
"build-bundle": "# ocular-bundle ./src/index.ts --external:{util,fs,path}" | ||
"build-bundle": "# ocular-bundle ./bundle.ts --external:{util,fs,path}" | ||
}, | ||
@@ -54,11 +54,13 @@ "browser": { | ||
"dependencies": { | ||
"@babel/runtime": "^7.3.1", | ||
"@loaders.gl/images": "4.2.0-alpha.4", | ||
"@loaders.gl/loader-utils": "4.2.0-alpha.4", | ||
"@loaders.gl/schema": "4.2.0-alpha.4", | ||
"@loaders.gl/xml": "4.2.0-alpha.4", | ||
"@loaders.gl/images": "4.2.0-alpha.5", | ||
"@loaders.gl/loader-utils": "4.2.0-alpha.5", | ||
"@loaders.gl/schema": "4.2.0-alpha.5", | ||
"@loaders.gl/xml": "4.2.0-alpha.5", | ||
"@turf/rewind": "^5.1.5", | ||
"deep-strict-equal": "^0.2.0" | ||
}, | ||
"gitHead": "6c52dee5c3f005648a394cc4aee7fc37005c8e83" | ||
"peerDependencies": { | ||
"@loaders.gl/core": "^4.0.0" | ||
}, | ||
"gitHead": "32d95a81971f104e4dfeb88ab57065f05321a76a" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
8502
488263
155
+ Added@loaders.gl/core@4.3.3(transitive)
+ Added@loaders.gl/images@4.2.0-alpha.5(transitive)
+ Added@loaders.gl/loader-utils@4.2.0-alpha.54.3.3(transitive)
+ Added@loaders.gl/schema@4.2.0-alpha.54.3.3(transitive)
+ Added@loaders.gl/worker-utils@4.2.0-alpha.54.3.3(transitive)
+ Added@loaders.gl/xml@4.2.0-alpha.5(transitive)
+ Added@probe.gl/env@4.1.0(transitive)
+ Added@probe.gl/log@4.1.0(transitive)
- Removed@babel/runtime@^7.3.1
- Removed@babel/runtime@7.26.0(transitive)
- Removed@loaders.gl/images@4.2.0-alpha.4(transitive)
- Removed@loaders.gl/loader-utils@4.2.0-alpha.4(transitive)
- Removed@loaders.gl/schema@4.2.0-alpha.4(transitive)
- Removed@loaders.gl/worker-utils@4.2.0-alpha.4(transitive)
- Removed@loaders.gl/xml@4.2.0-alpha.4(transitive)
- Removedregenerator-runtime@0.14.1(transitive)