惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
有赞技术团队
有赞技术团队
罗磊的独立博客
博客园 - 叶小钗
Jina AI
Jina AI
博客园 - 司徒正美
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
Microsoft Security Blog
Microsoft Security Blog
大猫的无限游戏
大猫的无限游戏
量子位
MyScale Blog
MyScale Blog
V
Visual Studio Blog
博客园 - 聂微东
The Cloudflare Blog
Engineering at Meta
Engineering at Meta
小众软件
小众软件
宝玉的分享
宝玉的分享

博客园 - 赵长青

每天fetch origin, rebase origin/xx gerrit冲突修改 安装wine 安装claude code 安装playwright vue3中 element-plus ,vein-plus的 aria-hidden问题,无障碍访问警告,辅助技术如屏幕阅读器无法识别聚集元素,违反wai-aria规范 vue3中图片、示例文件下载适应打包后路径不存在 ant-design中<a-table前端分页 ant-design中<a-table获取多分页中选择、全选问题处理 GeoScene Pro试用申请 nuget问题,程序包源找不到,安装不上 arcgis engine10.8现在都没有破解的吧,这些功能报错 超图版本cesium加载3dtiles数据要加这行 使用超图SuperMap iClient3D for Cesium 2025 webstorm 右键打开项目不见src目录,删除.idea目录 删除右键"上传到夸克网盘"/"上传到百度网盘"/“上传到迅雷云盘 pyqt5+qgis 01-修改界面颜色 wsl-windows中ubuntu22.04 postgis初始sql pycharm2023的intepreter 路径存在哪儿呢 ?太多要清理一下 qq小程序不能创建
cesium 点击弹窗鼠标移动跟随,不用infobox
赵长青 · 2025-07-09 · via 博客园 - 赵长青

cesium原有infobox 不好调位置,样式不好调,自己写一个灵活

 1、map.vue中 html:

<template>
  <div ref="mapContainer" id="mapContainer" style="width: 100%; height: 100%;">
    <div style="position: absolute;z-index: 2;
    visibility: hidden;background-color: #ffffff;
    max-height: 300px;
    overflow-y: auto;
    box-shadow: rgba(106, 146, 228, 0.2) 0rem 0.285714rem 2.14286rem 0rem, rgb(255, 255, 255) 0.142857rem 0.142857rem 0.0714286rem 0rem inset;"
         ref="infoBox" id="infobox">
    </div>
  </div>
</template>

2、代码

<script lang="ts" setup>
import { onMounted, ref, defineProps, watch, toRefs } from 'vue';
let viewer: Viewer
| null = null; let cartesian; onMounted(() => { Cesium.Credential.CREDENTIAL = new Cesium.Credential( "超图iserver地图token", "token"); viewer = new Cesium.Viewer('mapContainer',{infoBox: false }); //鼠标单击左键 点击白模 事件 viewer.screenSpaceEventHandler.setInputAction(async function onMouseClick(click) { const ray = viewer.camera.getPickRay(click.position); cartesian = viewer.scene.globe.pick(ray, viewer.scene); //获取到了白模实体 var pickedFeature = viewer.scene.pick(click.position); if (Cesium.defined(pickedFeature)) {
//根据白模上的id 值请求接口数据 let params
= { "datasetNames": ["fclt:xx_bm"], "getFeatureMode": "ID", "ids": [pickedFeature.id], "hasGeometry": true } const res = await featureResults(params, '超图iserver地图token') let item = createObjByFeature(res.data.features[0].fieldNames,res.data.features[0].fieldValues); let desp = createDescriptionHtml(item); //添加事件,左键点击到实体了就添加 viewer.scene.postRender.addEventListener(updatePosition); Popupposition(click.position,pickedFeature.id,desp) }else{ //未点击到实体,隐藏 + 移除事件 document.getElementById('infobox').style.display = "none"; viewer.scene.postRender.removeEventListener(updatePosition); } },Cesium.ScreenSpaceEventType.LEFT_CLICK); }); const updatePosition=()=> { // 将WGS84坐标中的位置转换为窗口坐标 let windowPosition = Cesium.SceneTransforms.wgs84ToWindowCoordinates(viewer.scene, cartesian); // 数值是样式中定义的宽高 if (windowPosition == undefined) return document.getElementById('infobox').style.left = (windowPosition.x - (220 / 2)) + 'px' document.getElementById('infobox').style.top = (windowPosition.y +20) + 'px' } const createDescriptionHtml = (item)=>{ let contentHtml = '<table class="cesium-infoBox-defaultTable"><tbody>'; for (let pro in item) { if (pro == "positions") continue; contentHtml += '<tr><th>' + `${pro}` + '</th>' + '<td>' + `${item[pro]}` + '</td>' + '</tr>' } contentHtml += '</tbody></table>' return contentHtml } const createObjByFeature=(fieldNames,fieldValues)=>{ let obj = {}; for(let i = 0; i < fieldNames.length; i++){ // 构造对象 obj[fieldNames[i]] = fieldValues[i]; } return obj; } const Popupposition=(pos,id,desp)=>{ document.getElementById('infobox').innerHTML = desp document.getElementById('infobox').style.display = 'block' //弹出信息框 document.getElementById('infobox').style.visibility = 'visible' document.getElementById('infobox').style.left = (pos.x) + 'px' document.getElementById('infobox').style.top = (pos.y) + 'px' }

超图接口返回:

 位置跟随也可以参考这里

posted on 2025-07-09 14:39  赵长青  阅读(72)  评论()    收藏  举报