rt-sim-training-client/src/jmapNew/shape/StationStand/EEarlyStart.js

77 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-10-22 13:40:56 +08:00
import Group from 'zrender/src/container/Group';
import Text from 'zrender/src/graphic/Text';
class EEarlyStart extends Group {
constructor(model) {
super();
this.model = model;
this.detain = null;
this.isNew = false;
}
create(deviceParam) {
if (!this.isNew) {
const model = this.model.modelData;
const style = this.model.style;
this.isNew = true;
/** 提前发车*/
const startD = model.right ? 1 : -1;
const startX = model.position.x - startD * (deviceParam.offset.x - model.width / 2);
const startY = model.position.y + startD * (deviceParam.offset.y - model.height / 2);
this.earlyStart = new Text({
zlevel: this.model.zlevel,
z: this.model.z,
position: [0, 0],
style: {
x: startX,
y: startY,
text: deviceParam.text,
fontSize: deviceParam.fontSize,
fontFamily: style.fontFamily,
fontWeight: deviceParam.fontWeight,
textFill: deviceParam.centerTrainColor,
textStroke: style.backgroundColor,
textAlign: style.textStyle.textAlign,
textVerticalAlign: deviceParam.textVerticalAlign || style.textStyle.textVerticalAlign
}
});
this.add(this.detain);
}
}
setColor(color) {
this.detain.setStyle('textFill', color);
}
recover() {
this.hideMode();
}
hideMode() {
this.detain && this.detain.hide();
}
showMode(deviceParam) {
this.create(deviceParam);
this.detain && this.detain.show();
}
setState(model, deviceParam = this.model.style.StationStand.detainNormal) {
/** 设置扣车*/
if (model.stationHoldTrain && model.centerHoldTrain) {
this.showMode(deviceParam);
this.setColor(deviceParam.andCenterTrainColor);
} else if (model.stationHoldTrain) {
this.showMode(deviceParam);
this.setColor(deviceParam.detainTrainTextColor);
} else if (model.centerHoldTrain) {
this.showMode(deviceParam);
this.setColor(deviceParam.centerTrainColor);
}
}
}
export default EDetain;