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'; import Vue from 'vue'; export default class EBadShunt extends Group { constructor(model) { super(); this.model = model; this.zlevel = model.zlevel; this.z = model.z; this.create(); } create() { // 分路不良 const model = this.model.modelData; const style = this.model.style; /** 创建区段*/ if (model && model.points.length > 1) { const traingle = new JTriangle(model.points[0], model.points[model.points.length - 1]); let x = traingle.drictx * (style.Section.badShunt.distance) * traingle.getSinRate(); let y = traingle.dricty * (style.Section.badShunt.distance) * traingle.getCosRate(); if (x == Infinity) { x = 0; } if (y == Infinity) { y = 0; } // if (model.switch) { // 上侧临时限速线 const badShuntLeft = this.createLimit({ position: [x, -y], switch: model.switch, code: model.code, isSwitchSection: model.switchSection, relSwitchCode: model.relSwitchCode, isCurve: model.curve, // 是否曲线 points: model.points }); // 下侧临时限速线 const badShuntRight = this.createLimit({ position: [-x, y], switch: model.switch, code: model.code, isSwitchSection: model.switchSection, relSwitchCode: model.relSwitchCode, isCurve: model.curve, // 是否曲线 points: model.points }); badShuntLeft.forEach(item => { this.add(item); }); badShuntRight.forEach(item => { this.add(item); }); // } } } createLimit(model) { const style = this.model.style; const dataList = []; 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; } 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; dataList.push(new BezierCurve({ isLine: true, zlevel: this.zlevel, progressive: model.progressive, z: this.z, culling: true, shape: shape, position: model.position, style: { lineWidth: style.Section.badShunt.width, stroke: style.Section.badShunt.lineColor, fillOpacity: 0 } })); } else { const swPadding = style.Switch.core.length; // 定位和反位时区段距离岔芯的距离 var switchWidth = style.Section.line.width + 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.relSwitchCode]; // 获取道岔model 及状态数据 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); } 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); } } } if (model.points.length == 2) { dataList.push(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: style.Section.badShunt.width, stroke: style.Section.badShunt.lineColor } })); } else { dataList.push(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: style.Section.badShunt.width, stroke: style.Section.badShunt.lineColor } })); for (let i = 1; i < (model.points.length - 2); i++) { dataList.push(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: style.Section.badShunt.width, stroke: style.Section.badShunt.lineColor } })); } dataList.push(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: style.Section.badShunt.width, stroke: style.Section.badShunt.lineColor } })); } } return dataList; } hide() { this.eachChild((child) => { child.hide(); }); } show() { this.eachChild((child) => { child.show(); }); } }