105 lines
3.4 KiB
JavaScript
105 lines
3.4 KiB
JavaScript
import Group from 'zrender/src/container/Group';
|
|
import Text from 'zrender/src/graphic/Text';
|
|
|
|
class EDetain extends Group {
|
|
constructor(model) {
|
|
super();
|
|
this.model = model;
|
|
this.isNew = false;
|
|
this.detain = null;
|
|
// if (this.model.style.StationStand.common.special) {
|
|
this.create();
|
|
// }
|
|
}
|
|
|
|
create(textName) {
|
|
if (!this.isNew) {
|
|
|
|
const model = this.model;
|
|
const style = this.model.style;
|
|
|
|
this.isNew = true;
|
|
if (style.StationStand.common.special) {
|
|
// inside true 内侧
|
|
const gag = 22;
|
|
const gagX = 6; // 左右间隔
|
|
let height = '';
|
|
let position = '';
|
|
if (model.right) {
|
|
if (model.inside) {
|
|
height = -gag;
|
|
position = -model.width / 4 - gagX;
|
|
} else {
|
|
height = gag;
|
|
position = model.width / 4 + gagX;
|
|
}
|
|
} else {
|
|
if (model.inside) {
|
|
height = gag;
|
|
position = model.width / 4 + gagX;
|
|
} else {
|
|
height = -gag;
|
|
position = -model.width / 4 - gagX;
|
|
}
|
|
}
|
|
this.detain = new Text({
|
|
zlevel: model.zlevel,
|
|
z: model.z,
|
|
position: [0, 0],
|
|
style: {
|
|
x: model.x + position,
|
|
y: model.y + height,
|
|
text: textName,
|
|
// textAlign: model.inside ? 'left' : 'right',
|
|
textAlign: 'center',
|
|
fontWeight: 'blod',
|
|
fontSize: `${style.StationStand.detainCar.fontSize} px ${style.fontFamily}`,
|
|
textFill: textName == 'E' ? '#fff' : 'red',
|
|
textVerticalAlign: 'middle'
|
|
}
|
|
});
|
|
this.add(this.detain);
|
|
} else {
|
|
this.detain = new Text({
|
|
zlevel: model.zlevel,
|
|
z: model.z,
|
|
position: [0, 0],
|
|
style: {
|
|
x: model.x,
|
|
y: model.y,
|
|
text: style.StationStand.detainCar.text,
|
|
textAlign: model.textAlign,
|
|
textVerticalAlign: model.textVerticalAlign,
|
|
fontSize: `${style.StationStand.stand.headFontSize} px ${style.fontFamily}`,
|
|
textFill: style.StationStand.detainCar.centerTrainColor,
|
|
textStroke: style.backgroundColor
|
|
}
|
|
});
|
|
this.add(this.detain);
|
|
}
|
|
}
|
|
}
|
|
|
|
setColor(color) {
|
|
this.create();
|
|
this.detain.setStyle('textFill', color);
|
|
}
|
|
|
|
hide() {
|
|
this.create();
|
|
this.detain.hide();
|
|
}
|
|
|
|
show(nameText) {
|
|
if (this.model.style.StationStand.common.special && nameText) {
|
|
this.create();
|
|
this.detain.setStyle('text', nameText);
|
|
} else {
|
|
this.create();
|
|
}
|
|
this.detain.show();
|
|
}
|
|
}
|
|
|
|
export default EDetain;
|