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

vue中使用OpenLayer加载Geoserver的WMS

vue3中使用OpenLayer加载Geoserver的WMS

先要在geoserver中发布我们所需要的数据

思路:

1.初始化vue

2.下载ol库npm install ol

3.创建map和source,layer,注:本文数据是WMS(Web Map Service)的,需要layer是TileLayer,需要source是TileWMS,所以需要引入对应的库

4.将layer添加到map

示例代码:

<script setup lang="ts">
import { Map,View } from 'ol';
import { onMounted, ref } from 'vue';
import { TileWMS } from 'ol/source';
import TileLayer from 'ol/layer/Tile.js';

const map = ref<Map>()
const source = ref<TileWMS>()
const layer = ref<TileLayer>()

function calcuLateCenter(bbox:[lonLeftTop:number,latLeftTop:number,lonRightBottom:number,latRightBottom:number]):[centerLon:number,centerLat:number]{
  const [lonLeftTop,latLeftTop,lonRightBottom,latRightBottom] = bbox
  const centerLon = (lonLeftTop+lonRightBottom)/2
  const centerLat = (latLeftTop+latRightBottom)/2
  return [centerLon,centerLat]
}

onMounted(()=>{
  map.value = new Map({
    target:"map"

  })
  map.value.setView(new View({
    center: calcuLateCenter([120.33197479248047,31.19165496826172,120.85912628173828,31.46062774658203]),
    zoom: 12,
    projection: 'EPSG:4326'
  }));
  source.value = new TileWMS({
    url:"http://localhost:7781/geoserver/gisdb/wms",
    projection: 'EPSG:4326', // here is the source projection
    params: {
      'LAYERS': 'gisdb:苏州',
      'VERSION':"1.1.1",
      'REQUEST':'GetMap',
      'FORMAT':'image/jpeg',
      'TRANSPARENT':true,
      'BBOX':[120.33197479248047,31.19165496826172,120.85912628173828,31.46062774658203]
    }
  })
  layer.value = new TileLayer({source:source.value})
  map.value.addLayer(layer.value)
})
</script>

<template>
  <div id="map"></div>
</template>

<style scoped>
#map {
  position: fixed;
  width:100%;
  height:100%;
}
</style>


http://www.kler.cn/a/506394.html

相关文章:

  • javascript基础从小白到高手系列一十二:JSON
  • 麦田物语学习笔记:构建游戏的时间系统
  • 常见链表专题相关算法
  • 网络是怎么样连接的--输入www.baidu.com之后网络的底层运行
  • ​HPM6700——以太网通信lwip_udpecho_freertos_socket
  • 《汽车维护与修理》是什么级别的期刊?是正规期刊吗?能评职称吗?
  • Hadoop图书数据分析系统 大屏数据展示 智能图书推荐系统(协同过滤余弦函数) 代码 数据库 全套开发工具
  • C++ 学习
  • AngularJs入门之创建最简单HelloWorld Demo应用
  • Java ee 文件操作和IO
  • python-leetcode-单词规律
  • C# OpenCV机器视觉:图片去水印
  • 自然语言处理(GloVe):原理、特点、应用、技术、相关学术分享
  • ASP.NET Core - .NET 6 以上版本的入口文件
  • Python 爬虫爬取京东商品信息 ||京东商品详情API
  • 记一次CentOS扩容boot升级内核版本
  • 告别烦恼:WiFi出现感叹号?快速恢复网络畅通指南
  • electron 如何申请 Mac 系统权限
  • 【Tortoise-ORM】 基础与数据库操作
  • 力扣-数组-228 汇总区间