2025-07-03 16:28:48 +08:00
|
|
|
|
/*
|
|
|
|
|
* @Description: 流动线
|
|
|
|
|
*/
|
|
|
|
|
function FlowDashedLine() {
|
|
|
|
|
class FlowDashedLineFlowMaterialProperty {
|
|
|
|
|
constructor(options) {
|
|
|
|
|
this._definitionChanged = new Cesium.Event();
|
|
|
|
|
this._color = undefined;
|
|
|
|
|
this._speed = undefined;
|
|
|
|
|
this._uType = undefined;
|
2025-07-07 16:21:01 +08:00
|
|
|
|
this._space = undefined;
|
|
|
|
|
this._dashSize = undefined;
|
2025-07-03 16:28:48 +08:00
|
|
|
|
this.color = new Cesium.Color.fromCssColorString(options.color || "rgba(255,255,255,1)");
|
2025-07-07 16:21:01 +08:00
|
|
|
|
this.speed = options.speed != undefined ? options.speed : 1.0;//速度
|
2025-07-09 11:26:33 +08:00
|
|
|
|
this.space = options.space || 0.0;//速度
|
2025-07-07 16:21:01 +08:00
|
|
|
|
this.dashSize = options.dashSize || 0.03;//速度
|
2025-07-03 16:28:48 +08:00
|
|
|
|
this.uType = options.uType === undefined ? 1 : options.uType;//类型:0:普通流动线 1:虚化虚线
|
|
|
|
|
this.lineBackAlpha = options.lineBackAlpha || 0.05;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
);
|
2025-07-07 16:21:01 +08:00
|
|
|
|
result.space = Cesium.Property.getValueOrDefault(
|
|
|
|
|
this._space,
|
|
|
|
|
time,
|
|
|
|
|
10,
|
|
|
|
|
result.space
|
|
|
|
|
);
|
|
|
|
|
result.dashSize = Cesium.Property.getValueOrDefault(
|
|
|
|
|
this._dashSize,
|
|
|
|
|
time,
|
|
|
|
|
10,
|
|
|
|
|
result.dashSize
|
|
|
|
|
);
|
2025-07-03 16:28:48 +08:00
|
|
|
|
result.uType = Cesium.Property.getValueOrDefault(
|
|
|
|
|
this._uType,
|
|
|
|
|
time,
|
|
|
|
|
1,
|
|
|
|
|
result.uType
|
|
|
|
|
);
|
|
|
|
|
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))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object.defineProperties(FlowDashedLineFlowMaterialProperty.prototype, {
|
|
|
|
|
color: Cesium.createPropertyDescriptor("color"),
|
|
|
|
|
speed: Cesium.createPropertyDescriptor("speed"),
|
2025-07-07 16:21:01 +08:00
|
|
|
|
space: Cesium.createPropertyDescriptor("space"),
|
|
|
|
|
dashSize: Cesium.createPropertyDescriptor("dashSize"),
|
2025-07-03 16:28:48 +08:00
|
|
|
|
uType: Cesium.createPropertyDescriptor("uType"),
|
|
|
|
|
transparency: Cesium.createPropertyDescriptor("lineBackAlpha"),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2025-07-09 11:26:33 +08:00
|
|
|
|
float dashSize = 0.1;
|
2025-07-07 16:21:01 +08:00
|
|
|
|
float gapSize = space;
|
2025-07-09 11:26:33 +08:00
|
|
|
|
// speed现在表示完成一次完整动画循环的秒数
|
|
|
|
|
float progress = speed==0.0 ? 0.0 : fract(frameNumber / 1000.0 / speed);
|
|
|
|
|
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);
|
2025-07-03 16:28:48 +08:00
|
|
|
|
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),
|
2025-07-07 16:21:01 +08:00
|
|
|
|
speed: 1,
|
2025-07-09 11:26:33 +08:00
|
|
|
|
space: 0.0,
|
2025-07-07 16:21:01 +08:00
|
|
|
|
dashSize: 0.03,
|
2025-07-09 11:26:33 +08:00
|
|
|
|
frameNumber: Cesium.getTimestamp(),
|
2025-07-03 16:28:48 +08:00
|
|
|
|
uType: 1,
|
|
|
|
|
lineBackAlpha: 0.05,
|
|
|
|
|
},
|
|
|
|
|
source: Cesium.Material.FlowDashedLineMaterialSource,
|
|
|
|
|
},
|
|
|
|
|
translucent: function (material) {
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export { FlowDashedLine }
|