javascript
复制代码
const res = await axios.get(url)
const xmlDom = new DOMParser().parseFromString(res.data, 'text/xml');
// 获取version
const version = xmlDom.getElementsByTagNameNS('*', 'ServiceTypeVersion')[0].textContent
// 获取layer
const layerDom = xmlDom.getElementsByTagNameNS('*', 'Layer')[0]
const layer = layerDom.getElementsByTagNameNS('*', 'Identifier')[0].textContent
// 获取style
const styleDom = layerDom.getElementsByTagNameNS('*', 'Style')[0]
const style = styleDom.getElementsByTagNameNS('*', 'Identifier')[0].textContent
// 获取format
const format = layerDom.getElementsByTagNameNS('*', 'Format')[0].textContent
// 获取crs
const crsBoundingBox = layerDom.getElementsByTagNameNS('*', 'BoundingBox')[1]
const crs = crsBoundingBox.attributes.crs.value
// 获取TileMatrixSet
const TileMatrixSetBox = layerDom.getElementsByTagNameNS('*', 'TileMatrixSet')[2]
const TileMatrixSet = TileMatrixSetBox.textContent
// 获取serviceUrl
const ResourceURL = layerDom.getElementsByTagNameNS('*', 'ResourceURL')[0]
const serviceUrl = ResourceURL.attributes.template.value.replace('{TileMatrixSet}', TileMatrixSet)
// 获取四至
const boundingBox = layerDom.getElementsByTagNameNS('*', 'BoundingBox')[0]
const lowerCorner = boundingBox.getElementsByTagNameNS('*', 'LowerCorner')[0].textContent
const upperCorner = boundingBox.getElementsByTagNameNS('*', 'UpperCorner')[0].textContent
const xMin = parseFloat(lowerCorner.split(' ')[0])
const yMin = parseFloat(lowerCorner.split(' ')[1])
const xMax = parseFloat(upperCorner.split(' ')[0])
const yMax = parseFloat(upperCorner.split(' ')[1])