rt-sim-training-client/src/jmapNew/shape/Signal/ESigAuto.js
2020-03-17 11:29:34 +08:00

78 lines
2.0 KiB
JavaScript

import Polygon from 'zrender/src/graphic/shape/Polygon';
import Group from 'zrender/src/container/Group';
import { arrow } from '../utils/ShapePoints';
class ESigPass extends Group {
constructor(model) {
super();
this.model = model;
this.isNew = false;
}
create() {
if (!this.isNew) {
const model = this.model;
const style = this.model.style;
const rotation = model.drict != 1 ? 0 : Math.PI;
this.isNew = true;
this.arrow = new Polygon({
zlevel: model.zlevel,
z: model.z,
origin: [model.x, model.y],
rotation: rotation,
shape: {
points: arrow(model.x, model.y, style.Signal.auto.width, style.Signal.lamp.radiusR * 0.8)
},
style: {
stroke: model.stroke,
lineWidth: model.lineWidth,
fill: model.fill
}
});
this.add(this.arrow);
}
}
// 停止动画
animationRecover() {
this.create();
this.arrow.stopAnimation(false);
}
// 箭头颜色
setColor(color) {
this.create();
this.arrow.setStyle('fill', color);
}
// 箭头闪烁
arrowsAnimation() {
this.create();
const style = this.model.style;
const fill = this.arrow.style.fill;
this.arrow.animateStyle(true)
.when(1000, { fill: style.backgroundColor, stroke: style.backgroundColor })
.when(2000, { fill: fill, stroke: style.sidelineColor })
.when(3000, { fill: style.backgroundColor, stroke: style.backgroundColor })
.when(4000, { fill: fill, stroke: style.sidelineColor })
.start();
}
// 隐藏
hide() {
this.create();
this.arrow.hide();
}
// 显示
show() {
this.create();
this.arrow.show();
}
}
export default ESigPass;