rt-sim-training-client/src/jmapNew/shape/Text/index.js
2020-03-13 13:01:58 +08:00

77 lines
2.2 KiB
JavaScript

import Text from 'zrender/src/graphic/Text';
import Group from 'zrender/src/container/Group';
import {isShowThePrdType} from '../../utils/handlePath';
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;
this.isShowShape = true;
if (isShowThePrdType(model.prdType, model.showConditions) || model.previewOrMapDraw) {
this.create();
this.setState(model);
}
if (model.previewOrMapDraw) {
this.setShowMode();
}
}
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;
}
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);
}
setState(model) {
if (!this.isShowShape) return;
}
// 设置显示模式
setShowMode() {
const showMode = this.model.showMode;
const showConditions = this.model.showConditions;
if (!showConditions || showConditions === '01' || showMode === showConditions) {
this.text && this.text.show();
} else {
this.text && this.text.hide();
}
}
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;
}
}
}