rt-sim-training-client/src/jmapNew/shape/Signal/ESigLamp.js
2020-04-30 17:40:25 +08:00

126 lines
3.9 KiB
JavaScript

import Line from 'zrender/src/graphic/shape/Line';
import Arc from 'zrender/src/graphic/shape/Arc';
import Group from 'zrender/src/container/Group';
class ESigLamp extends Group {
constructor(model) {
super();
this.model = model;
this.create();
}
create() {
const model = this.model;
const style = this.model.style;
this.lamp = new Arc({
_subType: 'SignalLamp',
_val: '3',
name: model.index,
zlevel: model.zlevel,
z: model.z,
shape: {
cx: model.x,
cy: model.y,
r: style.Signal.lamp.radiusR
},
style: {
lineWidth: style.Signal.lamp.borderWidth,
fill: style.backgroundColor,
stroke: style.Signal.lamp.borderColor
}
});
if ( !style.Signal.lamp.logicDisplayNone ) {
this.lstop = new Line({
_subType: 'SignalLamp',
_val: '3',
zlevel: model.zlevel,
z: model.z,
origin: {
x: model.originX,
y: model.originY
},
shape: {
x1: model.x + (style.Signal.lamp.radiusR + 1) * Math.cos(Math.PI / 4),
y1: model.y + (style.Signal.lamp.radiusR + 1) * Math.sin(Math.PI / 4),
x2: model.x - (style.Signal.lamp.radiusR + 1) * Math.cos(Math.PI / 4),
y2: model.y - (style.Signal.lamp.radiusR + 1) * Math.sin(Math.PI / 4)
},
style: {
lineWidth: style.Signal.lamp.stopWidth,
stroke: style.backgroundColor
}
});
this.rstop = new Line({
_subType: 'SignalLamp',
_val: '3',
zlevel: model.zlevel,
z: model.z,
origin: {
x: model.originX,
y: model.originY
},
shape: {
x1: model.x + (style.Signal.lamp.radiusR + 1) * Math.cos(Math.PI / 4),
y1: model.y + (style.Signal.lamp.radiusR + 1) * (Math.sin(Math.PI / 4) - Math.sqrt(2)),
x2: model.x - (style.Signal.lamp.radiusR + 1) * Math.cos(Math.PI / 4),
y2: model.y - (style.Signal.lamp.radiusR + 1) * (Math.sin(Math.PI / 4) - Math.sqrt(2))
},
style: {
lineWidth: style.Signal.lamp.stopWidth,
stroke: style.backgroundColor
}
});
}
this.add(this.lamp);
if (!style.Signal.lamp.logicDisplayNone) {
this.add(this.lstop);
this.add(this.rstop);
}
}
setColor(color) {
if (this.model.style.Signal.lamp.borderVariable) {
this.lamp.setStyle({ fill: color, stroke: color });
} else {
this.lamp.setStyle({ fill: color });
}
}
setBorderColor(color) {
this.lamp.setStyle({ stroke: color });
}
setStyle(data) {
this.lamp.setStyle(data);
}
setStop(has) {
if (has) {
this.lstop && this.lstop.show();
this.rstop && this.rstop.show();
} else {
this.lstop && this.lstop.hide();
this.rstop && this.rstop.hide();
}
}
getBoundingRect() {
return this.lamp.getBoundingRect();
}
setAnimationStart(color) {
this.lamp && this.lamp.animateStyle(true)
.when(0, { fill: this.model.style.backgroundColor })
.when(1000, { fill: color })
.when(2000, { fill: this.model.style.backgroundColor })
.when(3000, { fill: color })
.start();
}
setAnimationEnd() {
this.lamp && this.lamp.stopAnimation(false);
}
}
export default ESigLamp;