rt-sim-training-client/src/jmap/shape/Section/ESeparator.js

94 lines
2.9 KiB
JavaScript
Raw Normal View History

2019-07-16 16:03:56 +08:00
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;
2019-07-16 16:19:01 +08:00
this.style = model.style;
2019-07-16 16:03:56 +08:00
this.z = 6;
this._create(model);
}
_create(model) {
2019-07-17 15:54:01 +08:00
this.partition = new Polyline({
zlevel: this.zlevel,
2019-07-22 17:20:01 +08:00
progressive: model.progressive,
2019-07-17 15:54:01 +08:00
z: this.z,
shape: {
points: []
},
style: {
lineWidth: this.style.Section.sectionSeparatorWidth,
stroke: this.style.Section.sectionSeparatorColor
}
});
2019-07-16 16:03:56 +08:00
2019-07-17 15:54:01 +08:00
this.circle = new Circle({
zlevel: this.zlevel,
2019-07-22 13:39:33 +08:00
z: this.z,
2019-07-22 17:20:01 +08:00
progressive: model.progressive,
2019-07-17 15:54:01 +08:00
shape: {
cx: model.point.x,
cy: model.point.y,
r: this.style.Section.sectionWidth
},
style: {
stroke: this.style.Section.sectionInvadeColor,
GBaseLineWidth: 0.5,
fill: this.style.transparentColor
}
});
2019-07-16 16:03:56 +08:00
2019-07-17 15:54:01 +08:00
this.add(this.partition);
this.setType();
2019-07-16 16:03:56 +08:00
}
2019-07-17 15:54:01 +08:00
setType() {
const type = this.model.sepType;
2019-07-16 16:03:56 +08:00
const model = this.model;
2019-07-16 16:19:01 +08:00
if (model && this.style && model.traingle) {
2019-07-16 16:03:56 +08:00
this.remove(this.circle);
if (type === '00') {
this.partition.setShape('points', [
[model.point.x, model.point.y],
[model.point.x, model.point.y]
]);
} else if (type === '01') {
this.partition.setShape('points', [
2019-07-16 16:19:01 +08:00
[model.point.x, model.point.y - (this.style.Section.sectionWidth)],
[model.point.x, model.point.y + (this.style.Section.sectionWidth)]
2019-07-16 16:03:56 +08:00
]);
this.add(this.partition);
} else if (type === '02') {
this.partition.setShape('points', [
2019-07-16 16:19:01 +08:00
[model.point.x + model.drict * (this.style.Section.sectionWidth), model.point.y - (this.style.Section.sectionWidth * 1.5)],
[model.point.x, model.point.y - (this.style.Section.sectionWidth * 1.5)],
[model.point.x, model.point.y + (this.style.Section.sectionWidth * 1.5)]
2019-07-16 16:03:56 +08:00
]);
this.add(this.partition);
} else if (type === '03') {
this.partition.setShape('points', [
2019-07-16 16:19:01 +08:00
[model.point.x + model.drict * (this.style.Section.sectionWidth) * 1.2, model.point.y - (this.style.Section.sectionWidth * 1.2)],
[model.point.x, model.point.y - (this.style.Section.sectionWidth * 1.2)],
[model.point.x, model.point.y + (this.style.Section.sectionWidth * 1.2)],
[model.point.x + model.drict * (this.style.Section.sectionWidth) * 1.2, model.point.y + (this.style.Section.sectionWidth * 1.2)]
2019-07-16 16:03:56 +08:00
]);
this.add(this.partition);
2019-07-17 15:54:01 +08:00
this.partition.setStyle({'lineWidth': this.style.Section.sectionEndSeparatorWidth, 'stroke': this.style.Section.sectionEndSeparatorStroke });
2019-07-16 16:03:56 +08:00
} else if (type === '04') {
this.add(this.circle);
}
}
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(); // 可以无需调用
}
}
}