【cesium-5】鼠标交互与数据查询

scene.pick返回的是包含给定窗口位置基元的对象

scene.drillpack返回的是给定窗口位置所有对象的列表

Globe.pick返回的是给光线和地形的交点

Cesium.ScreenSpaceEventType.MIDDLE_CLICK 鼠标中间点击事件

Cesium.ScreenSpaceEventType.MOUSE_MOVE 鼠标移入事件

Cesium.ScreenSpaceEventType.RIGHT_CLICK 鼠标右击事件

复制代码
Cesium.Ion.defaultAccessToken = '';

var viewer = new Cesium.Viewer('cesiumContainer', {
        animation: false,
        timeline: false
});

var position = new Cesium.Cartesian3.fromDegrees(116.39, 38.9, 0.0);
const entity = viewer.entities.add({
    id:'BlueModel',
    position: position,
    plane: {
        plane: new Cesium.Plane(Cesium.Cartesian3.UNIT_X, 0.0),
        dimensions: new Cesium.Cartesian2(400, 300),
        material: "../testdata/test.png",
        outline: true,
        outlineColor: Cesium.Color.BLACK  
    },
    description:`<div>
                <img width="100%" height="300px" src="../testdata/data.png">
                <h3>你好呀</h3>
                <h3>欢迎学习cesium</h3>
                </div>` 
}) 

viewer.trackedEntity = entity;  //将摄像机视口快速绑定到模型位置 

var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function (movement){
    var pick = viewer.scene.pick(movement.position);
    if(Cesium.defined(pick) && (pick.id.id ==='BlueModel')){
        alert("欢迎加入")
    }
},Cesium.ScreenSpaceEventType.LEFT_CLICK);  //监听鼠标左键点击事件 

参考链接 9、cesium使用entity进行页面交互效果 - 哔哩哔哩

相关推荐
Lank_M39 分钟前
白底都占八成,PNG 为何只在图表页赢过 JPG
前端
张一凡9340 分钟前
给 Coding Agent 加一道"架构闸门":Jin 是如何做到"先审架构、再写代码、不漂移"的
前端·后端·agent
Linye40 分钟前
AI 写的 HTML 原型全是空壳?聊聊真实 DOM 交互避坑
前端·人工智能
ZANE1 小时前
纯前端实现的 PDF 与图片互相转换工具技术实现
前端
Swot1 小时前
SvelteKit Remote Functions 使用指南
前端·后端
Cooper251 小时前
三源热榜去重加 AI 摘要:URL 唯一键踩出的三个坑
前端·python
Yk酱228402 小时前
A2UI探索随笔-技术选型
前端
前端繁华如梦2 小时前
# 从 73000 行压缩代码到 TypeScript 模块化:我把一个 Three.js FPS 游戏 1:1 复刻了一遍
前端
Penge6662 小时前
React Context 详解:从 Props 传递到跨组件状态共享
前端
Penge6662 小时前
React 事件处理:bind(this) 原理与实际开发常用写法
前端