rt-sim-training-client/src/jmapNew/shape/Section/EStopRouteImg.js

53 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-08-21 14:14:26 +08:00
import Group from 'zrender/src/container/Group';
import Rect from 'zrender/src/graphic/shape/Rect';
import Stop_Route from '@/assets/stop_route.png';
import Pattern from 'zrender/src/graphic/Pattern';
import JTriangle from '../../utils/JTriangle';
export default class EStopRouteImg extends Group {
constructor(model) {
super();
this.model = model;
this.zlevel = model.zlevel;
this.z = model.z;
this.stopRouteImgList = [];
this.create();
}
create() {
const image = new Image(5, 8);
image.src = Stop_Route;
image.decode()
.then(() => {
const pattern = new Pattern(image, 'repeat');
for (let i = 1; i < this.model.points.length; i++) {
const triangle = new JTriangle(this.model.points[i - 1], this.model.points[i]);
this.stopRouteImgList.push(new Rect({
zlevel: this.zlevel,
z: this.z + 1,
origin: [this.model.points[i - 1].x, this.model.points[i - 1].y],
rotation: -triangle.getRotation(),
shape: {
x: this.model.points[i - 1].x,
y: this.model.points[i - 1].y - this.model.style.Section.line.width / 2,
width: triangle.getLength(),
height: this.model.style.Section.line.width
},
style: {
fill: pattern
}
}));
}
this.stopRouteImgList.forEach(item => {
this.add(item);
item.hide();
});
});
}
setModel(dx, dy) {
}
setCursor(mouseStyle) {
this.imageBg.attr('cursor', mouseStyle);
}
}