rt-sim-training-client/src/jmapNew/shape/graph/Station/EStationText.js

102 lines
3.7 KiB
JavaScript
Raw Normal View History

2020-11-13 10:21:36 +08:00
import Group from 'zrender/src/container/Group';
import Text from 'zrender/src/graphic/Text';
class EStationText extends Group {
constructor(model) {
super();
this.model = model;
this.style = model.style;
2020-11-13 10:21:36 +08:00
this.create();
}
create() {
const model = this.model.modelData;
const style = this.model.style;
// 车站名称
this.stationName = new Text({
zlevel: this.model.zlevel,
z: this.model.z,
silent: !model.visible || false,
style: {
x: model.position.x,
y: model.position.y,
fontWeight: style.Station.stationText.fontWeight,
fontSize: isNaN(Number(model.nameFont)) ? 20 : Number(model.nameFont),
fontFamily: style.fontFamily,
text: model.number ? model.number + model.name : model.name,
textAlign: 'middle',
textFill: model.nameFontColor,
textVerticalAlign: 'top',
textPadding:style.Station.stationText.textPadding,
textBorderColor:style.Station.stationText.borderColor || model.nameFontColor,
textBorderWidth:style.Station.stationText.textBorderWidth
}
});
2020-12-08 09:52:07 +08:00
this.add(this.stationName);
if (!model.visible) {
this.stationName.setStyle('fontSize', 0);
}
2020-11-13 10:21:36 +08:00
if (model.subheadDisplay) { // 副标题
this.subheadText = new Text({
zlevel: this.model.zlevel,
z: this.model.z,
silent: !model.visible || false,
style: {
x: model.subheadPosition.x,
y: model.subheadPosition.y,
fontWeight: model.fontWeight,
fontSize: model.subheadFont || 18,
fontFamily: style.fontFamily,
text: model.subhead,
textAlign: 'middle',
textVerticalAlign: 'top',
textFill: model.subheadFontColor,
textPadding:style.Station.stationText.textPadding,
textBorderColor:style.Station.stationText.borderColor || model.nameFontColor,
textBorderWidth:style.Station.stationText.textBorderWidth
}
});
this.add(this.subheadText);
}
}
recover() {
}
setState() {
}
setAnimateStyle(noneBeforeMode) {
this.stopAnimate();
const color = noneBeforeMode === 'Center' ? this.style.Station.stationText.centerModeColor : this.style.Station.stationText.localModeColor;
this.stationName.animateStyle(true).when(500, {textFill: '#000'}).when(1000, {textFill: color}).when(1500, {textFill: '#000'}).start();
}
stopAnimate() {
this.stationName.stopAnimation(true);
}
2020-11-16 10:08:37 +08:00
setColor(color) {
const style = this.model.style;
if (style.Station.StationControl.disPlayNone) {
this.stationName.setStyle('textFill', color);
this.subheadText && this.subheadText.setStyle('textFill', color);
}
}
setBackground(color) {
const style = this.model.style;
if (style.Station.StationControl.disPlayNone) {
this.stationName.setStyle('textBackgroundColor', color);
this.subheadText && this.subheadText.setStyle('textBackgroundColor', color);
}
}
setFlash() {
this.stopAnimate();
this.stationName.animateStyle(true).when(500, {opacity: 1}).when(1000, {opacity: 0}).when(1500, {opacity: 1}).start();
}
getBoundingRect() {
return this.stationName.getBoundingRect();
}
2020-11-13 10:21:36 +08:00
}
export default EStationText;