cesium绘制动态线,多段线
动态线实现
传递顶点时,附加每个顶点距线段起点的距离,用此距离来实现线段分段
shader中对传入的距离取模,即可实现分段绘制不通的颜色
PolylineColorAppearance + Fabric 创建Appearance后,将appearance的材质替换为fabric,此时可以通过color获取每个顶点对应的距离。此时已经可以分段绘制线段了。分段的线要动起来,可以传入Cesium绘制的时间,通过preRender(在场景渲染之前触发)事件可以获取绘制的起始事件,当前时间减起始时间即为已经开始绘制的时间。
效果
代码实现
动态线
createdynamicLine(coordinate1, coordinate2) {var scene = this.viewer.scene;var material = new Cesium.Material({fabric: {uniforms: {u_itime: 10.0, //时间u_trailpercent: 0.3, //拖尾百分比u_trailmovespeed: 5.0 / 50.0, //速率}}});var primitive = new Cesium.Primitive({geometryInstances: new Cesium.GeometryInstance({geometry: new Cesium.PolylineGeometry({// positions: Cesium.Cartesian3.fromDegreesArray([// 119.196653,// 26.031937,// 159.196653,// 26.031937,// ]),positions: Cesium.Cartesian3.fromDegreesArrayHeights([coordinate1.Longitude,//线的初始经纬度coordinate1.latitude,coordinate1.height,//高度coordinate2.Longitude,//结束位置coordinate2.latitude,coordinate2.height,//高度]),width: 3.0,vertexFormat: Cesium.PolylineColorAppearance.VERTEX_FORMAT,colorsPerVertex: true,colors: [new Cesium.Color(0.1, 0.0, 0.0, 1.0),new Cesium.Color(0.7, 0.0, 0.0, 1.0),new Cesium.Color(1.0, 0.0, 0.0, 1.0), //Alpha通道是计算机图形学中的术语,指的是特别的通道,意思是“非彩色”通道,主要是用来保存选区和编辑选区//Alvy Ray Smith 提出每个像素再增加一个 Alpha 通道,取值为0到1,//用来储存这个像素是否对图片有「贡献」,0代表透明、1代表不透明。],}),}),appearance: new Cesium.PolylineColorAppearance({ //设置线的颜色变化translucent: false,fragmentShaderSource: `precision highp float;varying vec4 v_color;void main(){float r=v_color.r-u_itime_0*u_trailmovespeed_2;float dist=smoothstep(0.0,u_trailpercent_1,mod(r,u_trailpercent_1));gl_FragColor=mix(vec4(1.0,0.0,1.0,1.0),vec4(0.0,1.0,1.0,1.0),dist);}`,}),});primitive.appearance.material = material;scene.primitives.add(primitive);scene.preRender.addEventListener(function (s, t) { //预渲染监听 该事件发生在每次渲染之前let elaspTime = Cesium.JulianDate.now().secondsOfDay - t.secondsOfDay;primitive.appearance.material.uniforms.u_itime = elaspTime;});},
多段线
createline() {//创建多段线和每段颜色this.positions = [];this.colors = [];for (let j = 0; j <= 50; j++) {this.positions[j] = (Cesium.Cartesian3.fromDegrees(124.0 + j, 40, 50000.0));// this.colors[j] = (Cesium.Color.ORANGE);this.colors[j] = (Cesium.Color.fromRandom({ alpha: 1.0 }));}//设置线段的位置和颜色,一一对应,arcType为ArcType.NONEconst perSegmentPolyline = new Cesium.GeometryInstance({geometry: new Cesium.SimplePolylineGeometry({positions: this.positions,colors: this.colors,arcType: Cesium.ArcType.NONE,}),});//使用逐顶点着色绘制多段线//对于逐顶点着色,将colorsPerVertex选项设置为true,并为colors选项提供长度等于位置数的颜色数组const perVertexPolyline = new Cesium.GeometryInstance({geometry: new Cesium.SimplePolylineGeometry({positions: Cesium.Cartesian3.fromDegreesArray([-130, 40, -80, 30]),colors: this.colors,colorsPerVertex: true,}),});//添加多段线instances到primitives entity方式绘制对象,和Primitive方式this.viewer.scene.primitives.add(new Cesium.Primitive({geometryInstances: [perSegmentPolyline, perVertexPolyline], //几何形状appearance: new Cesium.PerInstanceColorAppearance({ //外观flat: true,renderState: {lineWidth: Math.min(2.0, this.viewer.scene.maximumAliasedLineWidth),},}),}));},
cesium绘制动态线,多段线相关推荐
- cesium绘制不同颜色的多段线(SimplePolylineGeometry)
记录一下用SimplePolylineGeometry绘制不同颜色的多段线,代码看下面 //创建多段线和每段颜色 const positions = []; const colors = []; fo ...
- cesium开发系列:SimplePolylineGeometry绘制不同颜色的多段线
记录一下用SimplePolylineGeometry绘制不同颜色的多段线,代码看下面 //创建多段线和每段颜色 addColorLine(){//多颜色线段var m= this;//创建多段线和每 ...
- osg画线_OSG 绘制直线、多段线
写在前面:翻了一遍国内的博客,我竟然没有找到关于 osg 绘制线段的相关代码,反而看到都是一些相同内容的网站,就这风气. osg::ref_ptr<:matrixtransform> xf ...
- 【OpenCV 例程300篇】216. 绘制多段线和多边形
专栏地址:『youcans 的 OpenCV 例程200篇』 文章目录:『youcans 的 OpenCV 例程200篇-总目录』 [youcans 的 OpenCV 例程300篇]216. 绘制多段 ...
- 怎么设置CAD多段线线宽?CAD多段线线宽设置技巧
在绘制CAD图纸的过程中,有些CAD新手不知道怎么设置CAD多段线线宽,其实很简单,下面就和小编一起来了解一下浩辰CAD软件中设置多段线线宽的相关操作技巧吧! CAD多段线线宽设置步骤: 首先打开浩辰 ...
- 百度云 职称计算机cad,2017年职称计算机CAD知识:多段线
2017年职称计算机CAD知识:多段线 导语:在AutoCAD 2010中,用户可以一次编辑一条多段线,也可以同时编辑多条多段线.这些内容你都知道吗?我们一起来看看吧. 多段线 多段线是一种由直线段和 ...
- ARX和ODA中关于多段线曲线拟合的方法curveFit()
目前的二次开发中使用比较多的是AcDbPolyline(OdDbPolyline)也就是轻量多段线,虽然在CAD中绘制轻量多段线,选中之后右键菜单编辑可以进行"曲线拟合".&quo ...
- java中线段宽度怎么设置,CAD中多段线宽度怎么设置? 来看看吧
我们在使用CAD绘图时,常常需要设置线段的宽度以达到我们的设计要求,下面一起来看看CAD中多段线宽度是怎么设置的吧. 工具/材料 使用软件:CAD 操作方法一. 01 在桌面上双击CAD的快捷图标,打 ...
- lisp pl线线段数_编写lisp程序多条多段线连接成一条多段线
展开全部 命令HB合并多段线(defun c:hb (/ @myL @lpNum @etLst @@62616964757a686964616fe4b893e5b19e31333363383339en ...
最新文章
- 新JSON绑定库JSON-B发布公开预览版
- 通过防火墙堵住×××安全漏洞
- CodeForces - 1547F Array Stabilization (GCD version)(ST表+二分)
- android usb存储固定,如何在Android 10中设置默认USB行为
- java建立类的思想_JAVA类和对象创建
- html 表格_HTML------表格
- hdu I Hate It
- 蓝桥杯2016年第七届C++省赛B组第二题-生日蜡烛
- 旋转数组的最小数字(牛客网C++代码)
- 成人高考专升本- 你需要知道的事情!!
- Spring Boot设置上传文件大小
- 基于FFmpeg的编解码器设计实现方案
- 矩阵连乘c语言实验报告,矩阵连乘实验报告.docx
- Artnet对话孙宇晨:做自己的偶像
- We will rock you (我们将震憾你)
- 【Multisim仿真】LM317-337双路输出可调直流稳压电源电路
- iOS小技能: 开发 uni 原生插件(支持iOS Extension)
- 全国计算机等级一级b真题,2011年3月全国计算机等级考试一级B真题及参考答案.doc...
- 雄岸基金战略投资 Filenet,共建分布式存储新生态
- 用c语言编写智能停车系统,浅谈:智能停车系统设计是什么