/* * @Description: 流动线 */ function FlowDashedLine() { class FlowDashedLineFlowMaterialProperty { constructor(options) { this._definitionChanged = new Cesium.Event(); this._color = undefined; this._speed = undefined; this._uType = undefined; this._space = undefined; this._dashSize = undefined; this._scale = undefined; this.color = new Cesium.Color.fromCssColorString(options.color || "rgba(255,255,255,1)"); this.speed = options.speed != undefined ? options.speed : 1.0;//速度 this.space = options.space || 0.0;//速度 this.dashSize = options.dashSize || 0.03;//速度 this.uType = options.uType === undefined ? 1 : options.uType;//类型:0:普通流动线 1:虚化虚线 this.lineBackAlpha = options.lineBackAlpha || 0.05; this.scale = options.scale || 1.0; } get isConstant() { return false; } get definitionChanged() { return this._definitionChanged; } getType(time) { return Cesium.Material.FlowDashedLineMaterialType; } getValue(time, result) { if (!Cesium.defined(result)) { result = {}; } result.color = Cesium.Property.getValueOrDefault( this._color, time, Cesium.Color.RED, result.color ); result.speed = Cesium.Property.getValueOrDefault( this._speed, time, 10, result.speed ); result.space = Cesium.Property.getValueOrDefault( this._space, time, 10, result.space ); result.dashSize = Cesium.Property.getValueOrDefault( this._dashSize, time, 10, result.dashSize ); result.uType = Cesium.Property.getValueOrDefault( this._uType, time, 1, result.uType ); result.scale = Cesium.Property.getValueOrDefault( this._scale, time, 1.0, result.scale ); result.lineBackAlpha = this.lineBackAlpha; result.frameNumber = Cesium.getTimestamp(); return result; } equals(other) { return ( this === other || (other instanceof FlowDashedLineFlowMaterialProperty && Cesium.Property.equals(this._color, other._color) && Cesium.Property.equals(this._speed, other.speed) && Cesium.Property.equals(this._uType, other.uType) && Cesium.Property.equals(this._lineBackAlpha, other.lineBackAlpha) && Cesium.Property.equals(this._scale, other.scale)) ); } } Object.defineProperties(FlowDashedLineFlowMaterialProperty.prototype, { color: Cesium.createPropertyDescriptor("color"), speed: Cesium.createPropertyDescriptor("speed"), space: Cesium.createPropertyDescriptor("space"), dashSize: Cesium.createPropertyDescriptor("dashSize"), uType: Cesium.createPropertyDescriptor("uType"), transparency: Cesium.createPropertyDescriptor("lineBackAlpha"), scale: Cesium.createPropertyDescriptor("scale"), }); Cesium.FlowDashedLineFlowMaterialProperty = FlowDashedLineFlowMaterialProperty; Cesium.Material.FlowDashedLineFlowMaterialProperty = "FlowDashedLineFlowMaterialProperty"; Cesium.Material.FlowDashedLineMaterialType = "FlowDashedLineMaterialType"; Cesium.Material.FlowDashedLineMaterialSource = ` uniform vec4 color; uniform float speed; // uniform int uType; uniform float lineBackAlpha; czm_material czm_getMaterial(czm_materialInput materialInput) { czm_material material = czm_getDefaultMaterial(materialInput); vec2 st = materialInput.st; float dashSize = 0.1; float gapSize = space; // speed现在表示完成一次完整动画循环的秒数 float progress = speed==0.0 ? 0.0 : fract(frameNumber / 1000.0 / speed * scale); float pattern = fract(st.x / dashSize * (1.0 + gapSize) + progress / dashSize * (1.0 + gapSize)); float dash1 = step(0.0, pattern) - step(1.0/(1.0 + gapSize), pattern); float dash2 = smoothstep(0.0, 0.2, pattern) - smoothstep(1.0/(1.0 + gapSize), 1.0/(1.0 + gapSize) + 0.2, pattern); float dash = (float(uType) != 1.0)?dash1:dash2; material.alpha = dash; material.diffuse = color.rgb; return material; } `; Cesium.Material._materialCache.addMaterial( Cesium.Material.FlowDashedLineMaterialType, { fabric: { type: Cesium.Material.FlowDashedLineMaterialType, uniforms: { color: new Cesium.Color(1.0, 1.0, 1.0, 1.0), speed: 1, space: 0.0, scale: 1.0, dashSize: 0.03, frameNumber: Cesium.getTimestamp(), uType: 1, lineBackAlpha: 0.05, }, source: Cesium.Material.FlowDashedLineMaterialSource, }, translucent: function (material) { return true; }, } ); } export { FlowDashedLine }