前端解析超图的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])
相关推荐
沙振宇3 小时前
【Web】使用Vue3开发鸿蒙的HelloWorld!
前端·华为·harmonyos
运维@小兵3 小时前
vue开发用户注册功能
前端·javascript·vue.js
蓝婷儿4 小时前
前端面试每日三题 - Day 30
前端·面试·职场和发展
oMMh4 小时前
使用C# ASP.NET创建一个可以由服务端推送信息至客户端的WEB应用(2)
前端·c#·asp.net
一口一个橘子4 小时前
[ctfshow web入门] web69
前端·web安全·网络安全
读心悦5 小时前
CSS:盒子阴影与渐变完全解析:从基础语法到创意应用
前端·css
湛海不过深蓝6 小时前
【ts】defineProps数组的类型声明
前端·javascript·vue.js
layman05286 小时前
vue 中的数据代理
前端·javascript·vue.js
柒七爱吃麻辣烫6 小时前
前端项目打包部署流程j
前端
layman05287 小时前
vue中理解MVVM
前端·javascript·vue.js