rt-sim-training-client/src/jmap/shape/Section/ESeparator.js
2019-08-05 16:17:46 +08:00

93 lines
2.9 KiB
JavaScript

import Group from 'zrender/src/container/Group';
import Polyline from 'zrender/src/graphic/shape/Polyline';
import Circle from 'zrender/src/graphic/shape/Circle';
/** 分隔符*/
export default class ESeparator extends Group {
constructor(model) {
super();
this.model = model;
this.zlevel = model.zlevel;
this.z = model.style.Section.separator.z || 6;
this.style = model.style;
this.setType();
}
createModel(points, lineWidth = null, stroke = null) {
const model = this.model;
this.partition = new Polyline({
zlevel: this.zlevel,
progressive: model.progressive,
z: this.z,
shape: {
points: points
},
style: {
lineWidth: lineWidth || this.style.Section.separator.width,
stroke: stroke || this.style.Section.separator.color
}
});
this.add(this.partition);
}
// 创建 侵限分隔符
createCircle() {
const model = this.model;
this.circle = new Circle({
zlevel: this.zlevel,
z: this.z,
progressive: model.progressive,
shape: {
cx: model.point.x,
cy: model.point.y,
r: this.style.Section.line.width
},
style: {
stroke: this.style.Section.line.invadeColor,
GBaseLineWidth: 0.5,
fill: this.style.transparentColor
}
});
this.add(this.circle);
}
setType() {
const type = this.model.sepType;
const model = this.model;
if (model && this.style && model.traingle) {
if (type === '01') { // 普通分割
const points = [
[model.point.x, model.point.y - (this.style.Section.line.width)],
[model.point.x, model.point.y + (this.style.Section.line.width)]
];
this.createModel(points);
} else if (type === '02') { // 单侧分割符
const points = [
[model.point.x + model.drict * (this.style.Section.line.width), model.point.y - (this.style.Section.line.width * 1.5)],
[model.point.x, model.point.y - (this.style.Section.line.width * 1.5)],
[model.point.x, model.point.y + (this.style.Section.line.width * 1.5)]
];
this.createModel(points);
} else if (type === '03') { // 尽头分隔符
const points = [
[model.point.x + model.drict * (this.style.Section.line.width) * 1.2, model.point.y - (this.style.Section.line.width * 1.2)],
[model.point.x, model.point.y - (this.style.Section.line.width * 1.2)],
[model.point.x, model.point.y + (this.style.Section.line.width * 1.2)],
[model.point.x + model.drict * (this.style.Section.line.width) * 1.2, model.point.y + (this.style.Section.line.width * 1.2)]
];
const lineWidth = this.style.Section.separator.endWidth;
const stroke = this.style.Section.separator.endColor;
this.createModel(points, lineWidth, stroke);
} else if (type === '04') { // 侵限分隔符
this.createCircle();
}
}
if (model.traingle) {
this.origin = [model.point.x, model.point.y];
this.rotation = Math.PI * 2 - Math.atan2(model.traingle.absy, model.traingle.absx) * model.traingle.drictx * model.traingle.dricty;
this.dirty(); // 可以无需调用
}
}
}