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

【Cesium入门教程】第七课:Primitive图元

Cesium丰富的空间数据可视化API分为两部分:primitive API面向三维图形开发者,更底层一些。

Entity API是数据驱动更高级一些。

// entity
// 调用方便,封装完美
// 是基于primitive的封装// primitive
// 更接近底层
// 可以绘制高级图形
// 由Geometry(几何形状)、(Appearance)外观组成
const primitive = new Cesium.Primitive({geometryInstances: new Cesium.GeometryInstance({geometry: new Cesium.EllipseGeometry({center: Cesium.Cartesian3.fromDegrees(-100.0, 20.0),semiMinorAxis: 500000.0,semiMajorAxis: 1000000.0,rotation: Cesium.Math.PI_OVER_FOUR,vertexFormat: Cesium.VertexFormat.POSITION_AND_ST}),}),appearance: new Cesium.EllipsoidSurfaceAppearance({material: Cesium.Material.fromType('Stripe')})
})
viewer.scene.primitives.add(primitive);

组合图形

<h1 id="m7WFT">组合图形</h1>
```javascript
const rectangleInstance = new Cesium.GeometryInstance({geometry: new Cesium.RectangleGeometry({rectangle: Cesium.Rectangle.fromDegrees(-140.0, 30.0, -100.0, 40.0),vertexFormat: Cesium.PerInstanceColorAppearance.VERTEX_FORMAT}),id: 'rectangle',attributes: {color: new Cesium.ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5)}
});const ellipsoidInstance = new Cesium.GeometryInstance({geometry: new Cesium.EllipsoidGeometry({radii: new Cesium.Cartesian3(500000.0, 500000.0, 1000000.0),vertexFormat: Cesium.VertexFormat.POSITION_AND_NORMAL}),modelMatrix: Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(-95.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 500000.0), new Cesium.Matrix4()),id: 'ellipsoid',attributes: {color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.AQUA)}
});viewer.scene.primitives.add(new Cesium.Primitive({geometryInstances: [rectangleInstance, ellipsoidInstance],appearance: new Cesium.PerInstanceColorAppearance()
}));

点击事件


<h1 id="qr6o4">点击事件:</h1>
<h3 id="XXD1c">添加地形图层后去画点</h3>
```javascript
let viewer = new Cesium.Viewer('cesiumContainer', {terrainProvider: Cesium.createWorldTerrain()
})let handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction((event) => {//返回一个笛卡尔坐标let position = viewer.scene.pickPosition(event.position);//如果有这个坐标if (Cesium.defined(position)) {console.log(position)viewer.entities.add({position: position,point: {color: Cesium.Color.BLUE,pixelSize: 20,},})console.log(viewer.entities)}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

事件注销

handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)//移除左键点击事件

申明变量

let pickModel

鼠标移动事件

//添加建筑物
const city = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({url: Cesium.IonResource.fromAssetId(75343),})
);
viewer.flyTo(city)let handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction((event) => {//拾取模型const pick = viewer.scene.pick(event.endPosition);if (pick) {if (pickModel) {pickModel.color = Cesium.Color.WHITE;}pick.color = Cesium.Color.ORANGERED;pickModel = pick;}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

注销事件

handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)//移除左键点击事件
http://www.xdnf.cn/news/419095.html

相关文章:

  • 算法备案部分咨询问题解答第三期
  • leetcode-hot-100 (滑动窗口)
  • Windows部署LatentSync唇形同步(字节跳动北京交通大学联合开源)
  • 【Redis 进阶】缓存
  • 3.3 阶数的作用
  • 基于机器学习的卫星钟差预测方法研究HPSO-BP
  • Java【10_1】用户注册登录(面向过程与面向对象)
  • Spring Boot配置文件
  • Vue2 elementUI 二次封装命令式表单弹框组件
  • InternVL3: 利用AI处理文本、图像、视频、OCR和数据分析
  • docker部署WeDataSphere开源大数据平台
  • 【人工智能】自然语言编程革命:腾讯云CodeBuddy实战5步搭建客户管理系统,效率飙升90%
  • 论软件设计模式及其应用
  • EXCEL Python 实现绘制柱状线型组合图和树状图(包含数据透视表)
  • 工程类论文查重困局破解:基于知识图谱的跨学科语义重构技术实证研究
  • java复习笔记-面向对象
  • 速卖通如何低成本测评,让店铺流量与销量双提升
  • MapReduce基本介绍
  • 原生小程序+springboot+vue医院医患纠纷管理系统的设计与开发(程序+论文+讲解+安装+售后)
  • 内存中的“BANK”
  • 125.在 Vue3 中使用 OpenLayers 实现通过 WebGLVector 的方式添加海量点
  • MapReduce打包运行
  • 基于大模型预测胸椎管狭窄诊疗全流程的研究报告
  • 基于开源AI大模型AI智能名片S2B2C商城小程序的零售结算技术创新研究——以京东AI与香港冯氏零售集团智能结算台为例
  • 深入理解 JVM:StackOverFlow、OOM 与 GC overhead limit exceeded 的本质剖析及 Stack 与 Heap 的差异
  • 逆强化学习IRL在医疗行为模式研究中的应用
  • Three.js模型材质调整与性能优化实战
  • JPG与PDF格式转换器
  • 【论文阅读】Dip-based Deep Embedded Clustering with k-Estimation
  • 如何优化MCU中断响应时间