前端解析超图的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])
相关推荐
超级无敌攻城狮1 小时前
3 分钟学会!波浪文字动画超详细教程,从 0 到 1 实现「思考中 / 加载中」高级效果
前端
excel2 小时前
用 TensorFlow.js Node 实现猫图像识别(教学版逐步分解)
前端
gnip2 小时前
JavaScript事件流
前端·javascript
赵得C3 小时前
【前端技巧】Element Table 列标题如何优雅添加 Tooltip 提示?
前端·elementui·vue·table组件
wow_DG3 小时前
【Vue2 ✨】Vue2 入门之旅 · 进阶篇(一):响应式原理
前端·javascript·vue.js
weixin_456904273 小时前
UserManagement.vue和Profile.vue详细解释
前端·javascript·vue.js
资深前端之路3 小时前
react 面试题 react 有什么特点?
前端·react.js·面试·前端框架
aaaweiaaaaaa3 小时前
HTML和CSS学习
前端·css·学习·html
秋秋小事3 小时前
React Hooks useContext
前端·javascript·react.js
Jinuss3 小时前
Vue3源码reactivity响应式篇之reactive响应式对象的track与trigger
前端·vue3