91 lines
2.7 KiB
JavaScript
91 lines
2.7 KiB
JavaScript
import Line from 'zrender/src/graphic/shape/Line';
|
|
import Group from 'zrender/src/container/Group';
|
|
import {isShowThePrdType} from '../../utils/handlePath';
|
|
import Polygon from 'zrender/src/graphic/shape/Polygon';
|
|
|
|
export default class Arrow extends Group {
|
|
constructor(model, style) {
|
|
super();
|
|
this._code = model.code;
|
|
this._type = model._type;
|
|
this.zlevel = model.zlevel;
|
|
this.z = 0;
|
|
this.model = model;
|
|
this.style = style;
|
|
this.isShowShape = true;
|
|
if (isShowThePrdType(model.prdType, model.showConditions) || model.previewOrMapDraw) {
|
|
this.create();
|
|
this.setState(model);
|
|
}
|
|
if (model.previewOrMapDraw) {
|
|
this.setShowMode();
|
|
}
|
|
}
|
|
|
|
create() {
|
|
const model = this.model;
|
|
this.triangle = new Polygon({
|
|
zlevel: this.zlevel,
|
|
z: this.z,
|
|
shape: {
|
|
points: [
|
|
[model.position.x, model.position.y],
|
|
[model.position.x + model.triangleLength, model.position.y + model.triangleHeight / 2],
|
|
[model.position.x + model.triangleLength, model.position.y - model.triangleHeight / 2]
|
|
]
|
|
},
|
|
style: {
|
|
fill: model.color
|
|
}
|
|
});
|
|
this.line = new Line({
|
|
zlevel: this.zlevel,
|
|
z: this.z,
|
|
shape: {
|
|
x1: model.position.x + model.triangleLength,
|
|
y1: model.position.y,
|
|
x2: model.position.x + model.length,
|
|
y2: model.position.y
|
|
},
|
|
style: {
|
|
lineWidth: model.lineWidth,
|
|
stroke: model.color
|
|
}
|
|
});
|
|
this.add(this.triangle);
|
|
this.add(this.line);
|
|
}
|
|
|
|
setState(model) {
|
|
if (!this.isShowShape) return;
|
|
}
|
|
// 设置显示模式
|
|
setShowMode() {
|
|
const showMode = this.model.showMode;
|
|
const showConditions = this.model.showConditions;
|
|
if (!showConditions || showConditions === '01' || showMode === showConditions) {
|
|
this.eachChild((child) => {
|
|
child.show();
|
|
});
|
|
} else {
|
|
this.eachChild((child) => {
|
|
child.hide();
|
|
});
|
|
}
|
|
}
|
|
setShowStation(stationCode) {
|
|
if (!stationCode || this.model.stationCode === stationCode) {
|
|
this.eachChild((child) => {
|
|
child.show();
|
|
});
|
|
this.isShowShape = true;
|
|
this.setState(this.model);
|
|
} else {
|
|
this.eachChild((child) => {
|
|
child.hide();
|
|
});
|
|
this.isShowShape = false;
|
|
}
|
|
}
|
|
}
|