前端解析超图的iserver xml

前端解析超图的iserver xml

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])
相关推荐
烂蜻蜓22 分钟前
前端已死?什么是前端
开发语言·前端·javascript·vue.js·uni-app
谢尔登1 小时前
Vue 和 React 的异同点
前端·vue.js·react.js
祈澈菇凉6 小时前
Webpack的基本功能有哪些
前端·javascript·vue.js
小纯洁w6 小时前
Webpack 的 require.context 和 Vite 的 import.meta.glob 的详细介绍和使用
前端·webpack·node.js
想睡好6 小时前
css文本属性
前端·css
qianmoQ7 小时前
第三章:组件开发实战 - 第五节 - Tailwind CSS 响应式导航栏实现
前端·css
zhoupenghui1687 小时前
golang时间相关函数总结
服务器·前端·golang·time
White graces7 小时前
正则表达式效验邮箱格式, 手机号格式, 密码长度
前端·spring boot·spring·正则表达式·java-ee·maven·intellij-idea
庸俗今天不摸鱼7 小时前
Canvas进阶-4、边界检测(流光,鼠标拖尾)
开发语言·前端·javascript·计算机外设
bubusa~>_<7 小时前
解决npm install 出现error,比如:ERR_SSL_CIPHER_OPERATION_FAILED
前端·npm·node.js