前端解析超图的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])
相关推荐
花楸树12 分钟前
前端搭建 MCP Client(Web版)+ Server + Agent 实践
前端·人工智能
wuaro13 分钟前
RBAC权限控制具体实现
前端·javascript·vue
专业抄代码选手17 分钟前
【JS】instanceof 和 typeof 的使用
前端·javascript·面试
用户00798136209718 分钟前
6000 字+6 个案例:写给普通人的 MCP 入门指南
前端
用户876128290737422 分钟前
前端ai对话框架semi-design-vue
前端·人工智能
干就完了125 分钟前
项目中遇到浏览器跨域前端和后端解决方案以及大概过程
前端
我是福福大王27 分钟前
前后端SM2加密交互问题解析与解决方案
前端·后端
实习生小黄31 分钟前
echarts 实现环形渐变
前端·echarts
_未知_开摆38 分钟前
uniapp APP端在线升级(简版)
开发语言·前端·javascript·vue.js·uni-app
sen_shan1 小时前
Vue3+Vite+TypeScript+Element Plus开发-02.Element Plus安装与配置
前端·javascript·typescript·vue3·element·element plus