当前位置: 首页 > backend >正文

vue项目通过GetCapabilities获取wmts服务元数据信息并在openlayers进行叠加显示

vue项目通过openlayers加载wmts服务示例:

<template><div id="map" ref="mapContainer"></div>
</template><script>
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import WMTS from 'ol/source/WMTS';
import WMTSCapabilities from 'ol/format/WMTSCapabilities';
import {get as getProjection} from 'ol/proj';
import {getTopLeft, getWidth} from 'ol/extent';
import OSM from 'ol/source/OSM';export default {name: 'WmtsMap',data() {return {map: null,wmtsCapabilitiesUrl: 'https://your-wmts-service-url?request=GetCapabilities&service=WMTS'};},mounted() {this.initMap();},methods: {async initMap() {// 创建基础地图const baseLayer = new TileLayer({source: new OSM()});// 初始化地图视图const view = new View({center: [0, 0],zoom: 2});// 创建地图实例this.map = new Map({target: this.$refs.mapContainer,layers: [baseLayer],view: view});// 加载WMTS服务await this.loadWmtsLayer();},// 重点  async loadWmtsLayer() {try {//  获取WMTS能力文档const parser = new WMTSCapabilities();const response = await fetch(this.wmtsCapabilitiesUrl);const text = await response.text();const result = parser.read(text);//  解析WMTS能力文档const options = this.getWmtsOptions(result);//  创建WMTS图层const wmtsLayer = new TileLayer({opacity: 0.7,source: new WMTS(options)});//  添加到地图this.map.addLayer(wmtsLayer);} catch (error) {console.error('加载WMTS服务失败:', error);}},getWmtsOptions(result) {// 这里我们选择第一个可用的图层和矩阵集// 实际应用中可能需要根据需求选择特定的图层和矩阵集const layer = result.Contents.Layer[0];const tileMatrixSet = result.Contents.TileMatrixSet[0];const matrixSet = result.Contents.TileMatrixSet.filter((tms) => tms.Identifier === tileMatrixSet.Identifier)[0];const projection = getProjection(matrixSet.SupportedCRS);const resolutions = [];const matrixIds = [];const {TileMatrix} = result.Contents;for (let i = 0; i < TileMatrix.length; i++) {const tileMatrix = TileMatrix[i];if (tileMatrix.TileMatrixSet === tileMatrixSet.Identifier) {matrixIds.push(tileMatrix.Identifier);resolutions.push(tileMatrix.ScaleDenominator * 0.00028 / projection.getMetersPerUnit());}}// 获取第一个资源URLconst resourceUrl = layer.ResourceURL.find((resource) => resource.resourceType === 'tile').template;return {url: resourceUrl,layer: layer.Identifier,matrixSet: matrixSet.Identifier,format: layer.Format[0],projection: projection,tileGrid: {origin: getTopLeft(projection.getExtent()),resolutions: resolutions,matrixIds: matrixIds},style: 'default',};}}
};
</script><style scoped>
#map {width: 100%;height: 100%;
}
</style>

http://www.xdnf.cn/news/1000.html

相关文章:

  • 配置管理CM
  • 衡石chatbi如何通过 iframe 集成
  • 制作一款打飞机游戏14:资源优化
  • Nginx下搭建rtmp流媒体服务 并使用HLS或者OBS测试
  • 性能比拼: Nginx vs Caddy
  • NHANES指标推荐:PhenoAge
  • Ldap高效数据同步- Delta-Syncrepl复制模式配置实战手册(上)
  • 极验4滑块笔记:整理思路--填坑各种问题
  • 傲来云分享,负载均衡:提升网站性能与稳定性
  • 无人机飞控运行在stm32上的RTOS实时操作系统上,而不是linux这种非实时操作系统的必要性
  • 【前端】【面试】【业务场景】前端如何获取并生成设备唯一标识
  • 报错 | 配置 postcss 出现 报错:A `require()` style import is forbidden.
  • C++中的算术转换、其他隐式类型转换和显示转换详解
  • 开发指南:构建结合数字孪生、大语言模型与知识图谱的智能设备日志分析及生产异常预警系统
  • ByteTrack自定义数据集训练指南
  • 如何将SpringBoot前后端项目制作成windows运行的exe文件
  • 【python实用小脚本系列】用Python让鼠标“动起来”:光标自动移动、自动点击、自动图象识别的小技巧
  • 【教程】Digispark实现串口通信
  • 计算机是如何工作的
  • 使用Python可视化偶极子的电场
  • 2025年一站式AI创作平台主要功能介绍及使用教程
  • rac防火墙未禁用服务器重启导致二节点启动异常
  • Unity 场景管理核心教程:从 LoadScene 到 Loading Screen 实战 (Day 35)
  • 简单了解一下Unity Shader中的Swizzle操作
  • AI Agent认知框架(ReAct、函数调用、计划与执行、自问自答、批判修正、思维链、思维树详解和对比,最后表格整理总结
  • 移动端数据抓取:Android App的TLS流量解密方案
  • Springboot集成websocket实现消息推送
  • 深入解析 Spring 中的 @Value 注解(含源码级剖析 + 自定义实现)
  • jmeter跟踪重定向和自动重定向有什么区别?
  • 【计算机视觉】CV实战项目- CMU目标检测与跟踪系统 Object Detection Tracking for Surveillance Video