rt-sim-training-client/src/jmapNew/shape/Text/index.js

77 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-11-29 12:51:58 +08:00
import Text from 'zrender/src/graphic/Text';
import Group from 'zrender/src/container/Group';
2020-03-11 15:10:08 +08:00
import {isShowThePrdType} from '../../utils/handlePath';
2019-11-29 12:51:58 +08:00
export default class Text2 extends Group {
constructor(model, style) {
super();
this._code = model.code;
this._type = model._type;
this.name = model.code;
this.zlevel = model.zlevel;
this.model = model;
this.style = style;
this.z = 6;
2020-03-13 13:01:58 +08:00
this.isShowShape = true;
2020-03-11 10:53:09 +08:00
if (isShowThePrdType(model.prdType, model.showConditions) || model.previewOrMapDraw) {
2020-03-10 09:49:05 +08:00
this.create();
this.setState(model);
}
2020-03-11 10:53:09 +08:00
if (model.previewOrMapDraw) {
this.setShowMode();
}
}
2019-11-29 12:51:58 +08:00
create() {
var model = this.model;
var [direction, content] = model.content.split('::');
if (direction == 'V') {
content = content.split('').join('\n');
} else if (direction != 'H') {
content = model.content;
}
2019-11-29 12:51:58 +08:00
this.text = new Text({
zlevel: this.zlevel,
z: this.z,
style: {
x: model.position.x,
y: model.position.y,
text: content,
textFont: model.font,
textFill: model.fontColor,
textAlign: 'middle'
}
});
this.add(this.text);
}
2019-11-29 12:51:58 +08:00
setState(model) {
2020-03-13 13:01:58 +08:00
if (!this.isShowShape) return;
}
2020-03-11 15:10:08 +08:00
// 设置显示模式
2020-03-11 10:53:09 +08:00
setShowMode() {
const showMode = this.model.showMode;
2020-03-11 15:10:08 +08:00
const showConditions = this.model.showConditions;
2020-03-11 10:53:09 +08:00
if (!showConditions || showConditions === '01' || showMode === showConditions) {
2020-03-11 15:10:08 +08:00
this.text && this.text.show();
2020-03-11 10:53:09 +08:00
} else {
2020-03-11 15:10:08 +08:00
this.text && this.text.hide();
2020-03-11 10:53:09 +08:00
}
}
2020-03-13 13:01:58 +08:00
setShowStation(stationCode) {
if (!stationCode || this.model.stationCode === stationCode) {
this.eachChild(item => {
item.show();
});
this.isShowShape = true;
this.setState(this.model);
} else {
this.eachChild(item => {
item.hide();
});
this.isShowShape = false;
}
}
2019-11-29 12:51:58 +08:00
}