前端解析超图的iserver xml

发布于:2024-12-18 ⋅ 阅读:(36) ⋅ 点赞:(0)

前端解析超图的iserver xml

        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])

网站公告

今日签到

点亮在社区的每一天
去签到