2019-11-29 12:51:58 +08:00
|
|
|
import Group from 'zrender/src/container/Group';
|
|
|
|
import BezierCurve from 'zrender/src/graphic/shape/BezierCurve';
|
|
|
|
import Line from 'zrender/src/graphic/shape/Line';
|
|
|
|
import JTriangle from '../../utils/JTriangle';
|
2020-03-03 12:57:26 +08:00
|
|
|
import Vue from 'vue';
|
2019-11-29 12:51:58 +08:00
|
|
|
// import Path from 'zrender/src/graphic/Path';
|
|
|
|
|
|
|
|
// 创建区段限速限集合
|
2020-03-03 12:57:26 +08:00
|
|
|
// export default const ELimitLines = Path.extend({
|
2019-11-29 12:51:58 +08:00
|
|
|
// type: 'ELimitLines',
|
|
|
|
// shape: {
|
|
|
|
// points: null
|
|
|
|
// },
|
|
|
|
// buildPath: function (ctx, model) {
|
|
|
|
// /** 创建区段*/
|
|
|
|
// if (model && model.points.length > 1) {
|
|
|
|
// if (model.isCurve) {
|
|
|
|
// ctx.beginPath();
|
|
|
|
// const shape = {};
|
|
|
|
// for (let i = 1; i < (model.points.length - 1); i++) {
|
|
|
|
// shape[`cpx${i}`] = model.points[i].x;
|
|
|
|
// shape[`cpy${i}`] = model.points[i].y;
|
|
|
|
// }
|
|
|
|
// shape[`x1`] = model.points[0].x;
|
|
|
|
// shape[`y1`] = model.points[0].y;
|
|
|
|
// shape[`x2`] = model.points[model.points.length - 1].x;
|
|
|
|
// shape[`y2`] = model.points[model.points.length - 1].y;
|
|
|
|
|
|
|
|
// ctx.moveTo(shape[`x1`], shape[`y1`]);
|
|
|
|
// if (model.points.length <= 3) {
|
|
|
|
// ctx.quadraticCurveTo(shape[`cpx1`], shape[`cpy1`], shape[`x2`], shape[`y2`]);
|
|
|
|
// } else {
|
|
|
|
// ctx.bezierCurveTo(shape[`cpx1`], shape[`cpy1`], shape[`cpx2`], shape[`cpy2`], shape[`x2`], shape[`y2`]);
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// const swPadding = model.style.Switch.core.length; // 定位和反位时区段距离岔芯的距离
|
|
|
|
// var switchWidth = model.style.Section.line.width + model.style.Section.line.beyondWidth; // 道岔宽度
|
|
|
|
// const beg = Object.assign({}, model.points[0]);
|
|
|
|
// const end = Object.assign({}, model.points[model.points.length - 1]);
|
|
|
|
// if (model.isSwitchSection && beg.y !== end.y) {
|
|
|
|
// const swch = model.switch;
|
|
|
|
// if (swch) {
|
|
|
|
// const traingle = new JTriangle(swch.intersection, swch.skew);
|
|
|
|
// if ((swch.intersection.x === beg.x) && (swch.intersection.y === beg.y)) {
|
|
|
|
// beg.x = beg.x + traingle.drictx * (swPadding + switchWidth) * traingle.getCotRate();
|
|
|
|
// beg.y = beg.y + traingle.dricty * (swPadding + switchWidth);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if ((swch.intersection.x === end.x) && (swch.intersection.y === end.y)) {
|
|
|
|
// end.x = end.x + traingle.drictx * (swPadding + switchWidth) * traingle.getCotRate();
|
|
|
|
// end.y = end.y + traingle.dricty * (swPadding + switchWidth);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (model.points.length == 2) {
|
|
|
|
// ctx.moveTo(beg.x, beg.y);
|
|
|
|
// ctx.lineTo(end.x, end.y);
|
|
|
|
// ctx.closePath();
|
|
|
|
// } else {
|
|
|
|
// ctx.moveTo(beg.x, beg.y);
|
|
|
|
// ctx.lineTo(model.points[1].x, model.points[1].y);
|
|
|
|
// ctx.closePath();
|
|
|
|
|
|
|
|
// for (let i = 1; i < (model.points.length - 2); i++) {
|
|
|
|
// ctx.moveTo(model.points[i].x, model.points[i].y);
|
|
|
|
// ctx.lineTo(model.points[i + 1].x, model.points[i + 1].y);
|
|
|
|
// ctx.closePath();
|
|
|
|
// }
|
|
|
|
// ctx.moveTo(model.points[model.points.length - 2].x, model.points[model.points.length - 2].y);
|
|
|
|
// ctx.lineTo(end.x, end.y);
|
|
|
|
// ctx.closePath();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
|
|
|
|
export default class ELimitLines extends Group {
|
2020-03-13 15:06:14 +08:00
|
|
|
constructor(model) {
|
|
|
|
super();
|
|
|
|
this.model = model;
|
|
|
|
this.zlevel = model.zlevel;
|
|
|
|
this.z = model.z;
|
|
|
|
this.create(model);
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2020-03-13 15:06:14 +08:00
|
|
|
create(model) {
|
|
|
|
/** 创建区段*/
|
|
|
|
if (model && model.points.length > 1) {
|
|
|
|
if (model.isCurve) {
|
|
|
|
const shape = {};
|
|
|
|
for (let i = 1; i < (model.points.length - 1); i++) {
|
|
|
|
shape[`cpx${i}`] = model.points[i].x;
|
|
|
|
shape[`cpy${i}`] = model.points[i].y;
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2020-03-13 15:06:14 +08:00
|
|
|
shape[`x1`] = model.points[0].x;
|
|
|
|
shape[`y1`] = model.points[0].y;
|
|
|
|
shape[`x2`] = model.points[model.points.length - 1].x;
|
|
|
|
shape[`y2`] = model.points[model.points.length - 1].y;
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2020-03-13 15:06:14 +08:00
|
|
|
this.add(new BezierCurve({
|
|
|
|
isLine: true,
|
|
|
|
zlevel: this.zlevel,
|
|
|
|
progressive: model.progressive,
|
|
|
|
z: this.z,
|
|
|
|
culling: true,
|
|
|
|
shape: shape,
|
|
|
|
position: model.position,
|
|
|
|
style: {
|
|
|
|
lineWidth: model.style.Section.speedLimit.width,
|
|
|
|
stroke: model.style.Section.speedLimit.lineColor,
|
|
|
|
fillOpacity: 0
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
const swPadding = model.style.Switch.core.length; // 定位和反位时区段距离岔芯的距离
|
|
|
|
var switchWidth = model.style.Section.line.width + model.style.Section.line.beyondWidth; // 道岔宽度
|
|
|
|
const beg = Object.assign({}, model.points[0]);
|
|
|
|
const end = Object.assign({}, model.points[model.points.length - 1]);
|
|
|
|
if (model.isSwitchSection && beg.y !== end.y) {
|
|
|
|
const swch = Vue.prototype.$jlmap.mapDevice[model.switch.code]; // 获取道岔model 及状态数据
|
2020-03-03 12:57:26 +08:00
|
|
|
|
2020-03-13 15:06:14 +08:00
|
|
|
if (swch && swch.instance) {
|
|
|
|
const traingle = new JTriangle(swch.intersection, swch.skew);
|
|
|
|
if ((swch.intersection.x === beg.x) && (swch.intersection.y === beg.y) && !swch.normalPosition && swch.sectionCCode == model.code) {
|
|
|
|
beg.x = beg.x + traingle.drictx * (swPadding + switchWidth) * traingle.getCotRate();
|
|
|
|
beg.y = beg.y + traingle.dricty * (swPadding + switchWidth);
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2020-03-13 15:06:14 +08:00
|
|
|
if ((swch.intersection.x === end.x) && (swch.intersection.y === end.y) && swch.normalPosition && swch.sectionCCode == model.code) {
|
|
|
|
end.x = end.x + traingle.drictx * (swPadding + switchWidth) * traingle.getCotRate();
|
|
|
|
end.y = end.y + traingle.dricty * (swPadding + switchWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2020-03-13 15:06:14 +08:00
|
|
|
if (model.points.length == 2) {
|
|
|
|
this.add(new Line({
|
|
|
|
isLine: true,
|
|
|
|
zlevel: this.zlevel,
|
|
|
|
progressive: model.progressive,
|
|
|
|
z: this.z,
|
|
|
|
position: model.position,
|
|
|
|
shape: {
|
|
|
|
x1: beg.x,
|
|
|
|
y1: beg.y,
|
|
|
|
x2: end.x,
|
|
|
|
y2: end.y
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
lineWidth: model.style.Section.speedLimit.width,
|
|
|
|
stroke: model.style.Section.speedLimit.lineColor
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
this.add(new Line({
|
|
|
|
isLine: true,
|
|
|
|
zlevel: this.zlevel,
|
|
|
|
progressive: model.progressive,
|
|
|
|
z: this.z,
|
|
|
|
position: model.position,
|
|
|
|
shape: {
|
|
|
|
x1: beg.x,
|
|
|
|
y1: beg.y,
|
|
|
|
x2: model.points[1].x,
|
|
|
|
y2: model.points[1].y
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
lineWidth: model.style.Section.speedLimit.width,
|
|
|
|
stroke: model.style.Section.speedLimit.lineColor
|
|
|
|
}
|
|
|
|
}));
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2020-03-13 15:06:14 +08:00
|
|
|
for (let i = 1; i < (model.points.length - 2); i++) {
|
|
|
|
this.add(new Line({
|
|
|
|
isLine: true,
|
|
|
|
zlevel: this.zlevel,
|
|
|
|
z: this.z,
|
|
|
|
progressive: model.progressive,
|
|
|
|
position: model.position,
|
|
|
|
shape: {
|
|
|
|
x1: model.points[i].x,
|
|
|
|
y1: model.points[i].y,
|
|
|
|
x2: model.points[i + 1].x,
|
|
|
|
y2: model.points[i + 1].y
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
lineWidth: model.style.Section.speedLimit.width,
|
|
|
|
stroke: model.style.Section.speedLimit.lineColor
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2020-03-13 15:06:14 +08:00
|
|
|
this.add(new Line({
|
|
|
|
isLine: true,
|
|
|
|
zlevel: this.zlevel,
|
|
|
|
z: this.z,
|
|
|
|
position: model.position,
|
|
|
|
progressive: model.progressive,
|
|
|
|
shape: {
|
|
|
|
x1: model.points[model.points.length - 2].x,
|
|
|
|
y1: model.points[model.points.length - 2].y,
|
|
|
|
x2: end.x,
|
|
|
|
y2: end.y
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
lineWidth: model.style.Section.speedLimit.width,
|
|
|
|
stroke: model.style.Section.speedLimit.lineColor
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|