当前位置:网站首页>Cesium drag 3D model
Cesium drag 3D model
2022-06-25 04:04:00 【Wang +v】
Cesium Drag and drop 3D Model
What effect does this place want to achieve ? Is the use of cesium Add a... To the map 3D Model , Then the drag and drop effect is realized .
Add a base station model
Then this blog post is not about adding models , But simply paste the code directly , I won't go into details .
// Add a base station model
function addSite() {
let position = Cesium.Cartesian3.fromDegrees(116.236393, 40.075119, 0);
// Set model orientation
let hpRoll = new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(0), 0, 0);
let orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpRoll);
// Add model
let model = viewer.entities.add({
id: 'site', // Model id
position: position, // Model location
orientation: orientation, // Model orientation
model: {
uri: './models/siteModel/scene.gltf', // Model path , Change into your own model
scale: 1,
show: true, // Whether the model is visible
},
description: ' Base station model ' // Add model description
});
viewer.trackedEntity = model; // View switch to model
}
The code above completes adding model functions to the interface .

Drag and drop
In fact, dragging is for this cesium Add a listening event .
For example, the simple logic analysis of drag and drop :
1、 Mouse down event , If there is a model , You can set a color for the model , Know which model is selected by pressing .
2、 Then listen for mouse drag events , Get the position of the mouse drag , Assign to model .
3、 Mouse up event , End the mouse movement event , Then change the color back .
// Registration events
function setHandler() {
handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
// Register mouse down events
handler.setInputAction((e) => {
const pick = viewer.scene.pick(e.position);
if (!Cesium.defined(pick)) {
return; };// If you click on a blank area , Then it doesn't go down
viewer.scene.screenSpaceCameraController.enableRotate = false;// Lock camera , Otherwise, the camera will move when the entity is moved later
pick.id.model.color = Cesium.Color.fromAlpha(Cesium.Color.RED, 1) // Set the color
// Register mouse drag events
viewer.screenSpaceEventHandler.setInputAction((arg) => {
// by viewer binding MOUSE_MOVE Event listener ( Execute function , Listening events )
const position = arg.endPosition;// arg Yes startPosition And endPosition Two attributes , That is, the position information before and after the movement :Cartesian2 object
const cartesian = viewer.scene.globe.pick(viewer.camera.getPickRay(position), viewer.scene);// take Cartesian2 To Cartesian3
pick.id.position._value = cartesian
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
// Bind the mouse up event
viewer.screenSpaceEventHandler.setInputAction(({
position }) => {
// by viewer binding LEFT_UP Event listener ( Execute function , Listening events )
viewer.scene.screenSpaceCameraController.enableRotate = true;// Unlock camera
pick.id.model.color = null // Set the color
viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);// relieve viewer Of MOUSE_MOVE Event listener
}, Cesium.ScreenSpaceEventType.LEFT_UP)
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
}

When it's done, it's , It's so simple .
边栏推荐
猜你喜欢

opencv最大能打开多少图像?

Does it count as staying up late to sleep at 2:00 and get up at 10:00? Unless you can do it every day

opencv怎么安装?opencv下载安装教程
![[harmony OS] [ark UI] basic ETS context operations](/img/fb/a1b8463ba160e6c5aa23d671a0c245.png)
[harmony OS] [ark UI] basic ETS context operations

opencv 红色区域在哪里?

可能是拿反了的原因

Deveco studio 3.0 editor configuration tips

Peking University has a new president! Gongqihuang, academician of the Chinese Academy of Sciences, took over and was admitted to the Physics Department of Peking University at the age of 15

俄罗斯AIRI研究院等 | SEMA:利用深度迁移学习进行抗原B细胞构象表征预测

《悉达多》:一生之书,可以时常反刍
随机推荐
Jilin University 22 spring March new development English comprehensive course (I) assignment assessment-00080
威马招股书拆解:电动竞争已结束,智能排位赛刚开始
Solution to the problem that Linux crontab timed operation Oracle does not execute (crontab environment variable problem)
Amazon's other side in China
Peking University has a new president! Gongqihuang, academician of the Chinese Academy of Sciences, took over and was admitted to the Physics Department of Peking University at the age of 15
一文搞懂php中的(DI)依赖注入
Serious PHP defects can lead to rce attacks on QNAP NAS devices
Development of trading system (XII) - Official quickfix document
Dr. Sun Jian was commemorated at the CVPR conference. The best student thesis was awarded to Tongji Ali. Lifeifei won the huangxutao Memorial Award
练习:仿真模拟福彩双色球——中500w巨奖到底有多难?跑跑代码就晓得了。
数学分析_笔记_第3章:极限
1.初识半音阶口琴
Redis related-01
Xidian AI ranked higher than Qingbei in terms of AI majors, and Nantah ranked the first in China in 2022 in terms of soft science majors
About PLSQL error initialization failure
PHP代码审计1—PHP.ini的那些事
js工具函数,自己封装一个节流函数
代表多样性的彩色 NFT 系列上线 The Sandbox 市场平台
Wuenda, the new course of machine learning is coming again! Free auditing, Xiaobai friendly
Redis related-03