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

Vue.js2+Cesium1.103.0 十三、通过经纬度查询 GeoServer 发布的 wms 服务下的 feature 对象的相关信息

Vue.js2+Cesium1.103.0 十三、通过经纬度查询 GeoServer 发布的 wms 服务下的 feature 对象的相关信息

Demo

<template><divid="cesium-container"style="width: 100%; height: 100%;"><div style="position: absolute;z-index: 999;bottom: 0;left: 0;background: #fff;width: 100%;padding: 20px;box-sizing: border-box;"><div> {{ position }}</div><div>{{ info }}</div></div></div>
</template><script>
/* eslint-disable no-undef */
import axios from 'axios'
export default {data() {return {position: '',info: ''}},computed: {},watch: {},mounted() {const _this = thiswindow.$InitMap()const imageryLayer = new Cesium.ImageryLayer(new Cesium.WebMapServiceImageryProvider({url: 'http://openlayers.vip/geoserver/cite/wms',layers: 'cite:2000',parameters: {transparent: true,format: 'image/png',srs: 'EPSG:4326'},tileWidth: 1024,tileHeight: 1024}))viewer.imageryLayers.add(imageryLayer)viewer.camera.flyTo({destination: Cesium.Rectangle.fromDegrees(114.4491417723215,38.96451275547338,118.24157311104125,41.29160446951736)})/*** @description: 根据用户点击的坐标计算 bbox 参数* @param {*} latlng* @param {*} zoom* @return {*}*/function PositionToBbox(latlng, zoom) {const box = getZoomBbox(zoom)const boxMin = {lat: latlng.lat - box,lng: latlng.lng - box}const boxMax = {lat: latlng.lat + box,lng: latlng.lng + box}return `${boxMin.lng},${boxMin.lat},${boxMax.lng},${boxMax.lat}`}/*** @description: 计算用户坐标`应该减去的差值* @param {*} zoom* @return {*}*/function getZoomBbox(zoom) {const level0 = 142.03125let box = level0 / Math.pow(2, zoom)box = box / 2return box}function geoServerQuery(data) {return axios({method: 'get',url: `http://openlayers.vip/geoserver/cite/wms`,headers: {// Authorization: "",},params: data}).then(res => {if (res && res.data) {return res.data}}).catch(() => {return false})}// 鼠标事件const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)handler.setInputAction(function (movement) {const earthPosition = viewer.camera.pickEllipsoid(movement.endPosition,viewer.scene.globe.ellipsoid)const cartographic = Cesium.Cartographic.fromCartesian(earthPosition,viewer.scene.globe.ellipsoid,new Cesium.Cartographic())const longitude = Cesium.Math.toDegrees(cartographic.longitude)const latitude = Cesium.Math.toDegrees(cartographic.latitude)if (longitude && latitude) {console.log('.................', longitude, latitude)_this.position = `${longitude}, ${latitude}`geoServerQuery({service: 'wms',version: '1.1.1',request: 'getfeatureinfo',format: 'image/png',transparent: true,query_layers: 'cite:2000',layers: 'cite:2000',exceptions: 'application/vnd.ogc.se_inimage',info_format: 'application/json',feature_count: 50,x: 50,y: 50,srs: 'epsg:4490',width: 101,height: 101,bbox: PositionToBbox({lng: longitude,lat: latitude},24)}).then(res => {console.log('..............res', res)if (res && res.features && res.features.length > 0) {_this.info = res.features[0].properties} else {_this.info = ''}}).catch(err => {_this.info = ''console.log(err)})}}, Cesium.ScreenSpaceEventType.MOUSE_MOVE)},methods: {}
}
</script><style>
</style>
http://www.lryc.cn/news/198142.html

相关文章:

  • 使用STM32怎么喂狗 (IWDG)
  • GEE:计算和打印GEE程序的执行时间
  • GDPU 数据结构 天码行空5
  • SQLAlchemy学习-12.查询之 order_by 按desc 降序排序
  • 如何轻松打造数字人克隆系统+直播系统?OEM教你快速部署数字人SaaS系统源码
  • 药物滥用第四篇介绍
  • Apache Doris (四十三): Doris数据更新与删除 - Update数据更新
  • 面试算法29:排序的循环链表
  • python中不可变类型和可变类型
  • vue3封装Axios库的 API 请求并使用拦截器来处理请求和响应
  • RK3588开发笔记(二):基于方案商提供sdk搭建引入mpp和sdk的宿主机交叉编译Qt5.12.10环境
  • rust学习——函数返回值
  • 【Cadence】配置文件cdsinit和cdsenv的使用
  • 软考 系统架构设计师系列知识点之基于架构的软件开发方法ABSD(6)
  • MATLAB常用命令大全,非常详细(持续更新中)
  • js笔试面试题5道附答案
  • 4-k8s-部署springboot项目简单实践
  • Ai数字人直播系统SaaS源码大开源,源码独立部署助力中小企业发展!
  • 新的 Work Node 如何加入 K8s 集群 - Kubeadm ?
  • laravel框架的优缺点是什么?
  • 程序员接单都在用这六大平台,你呢?
  • 2022年亚太杯APMCM数学建模大赛D题储能系统中传热翅片的结构优化求解全过程文档及程序
  • 图像处理软件Photoshop 2023 mac新增功能 ps 2023中文版
  • CSS基本讲解与使用(详解)
  • 最新AI创作系统ChatGPT源码+搭建部署教程+支持GPT4.0+支持ai绘画(Midjourney)/支持Prompt
  • Linux系统之部署SSCMS内容管理系统并实现外网访问
  • JVS-rules中的基础与复合变量:规则引擎的心脏
  • RN:指定模拟器启动
  • 【ARM Cache 系列文章 10 -- ARM Cortex-A720 Hunter 介绍】
  • 深度学习——残差网络(ResNet)