/**/ import Group from 'zrender/src/container/Group'; import ETime from './ETime'; import ELevel from './ELevel'; import EReentry from './EReentry'; import EDetain from './EDetain'; import ESafeStand from './ESafeStand'; import ESafeEmergent from './ESafeEmergent'; import EMouse from './EMouse'; import EJump from './EJump'; import EHighlight from '../element/EHighlight'; import ETrainStop from './ETrainStop'; import ETrainDepart from './ETrainDepart'; class StationStand extends Group { constructor(model, style) { super(); this._code = model.code; this._type = model._type; this.model = model; this.style = style; this.zlevel = model.zlevel; this.z = 1; this.doors = new Group(); this.create(); this.createMouseEvent(); this.setVisible(model.visible); this.setState(model); this.checkIsDrawMap(); } create() { const model = this.model; const style = this.style; const drict = 1; /** 列车站台*/ const standX = model.position.x - model.width / 2; const standY = model.position.y - model.height / 2; this.safeStand = new ESafeStand({ zlevel: this.zlevel, z: this.z, style: style, x: standX, y: standY, name: model.name, inside: model.inside, right: model.right, width: model.width, height: model.height }); this.add(this.safeStand); /** 站台紧急关闭*/ const emergentH = model.right ? 1 : -1; let emergentX = model.position.x + drict * (style.StationStand.standEmergent.offset.x); let emergentY = model.position.y + emergentH * (model.height / 2 + style.StationStand.standEmergent.mergentR); if (style.StationStand.common.special) { emergentX = model.position.x; emergentY = model.position.y; } this.emergent = new ESafeEmergent({ zlevel: this.zlevel, z: this.z + 1, style: style, inside: model.inside, right: model.right, width: model.width, x: emergentX, y: emergentY, r: style.StationStand.standEmergent.mergentR, n: 4 }); // 列车停站 const stopX = model.position.x; const stopY = model.position.y; this.trainStop = new ETrainStop({ zlevel: this.zlevel, z: this.z + 1, style: style, inside: model.inside, right: model.right, width: model.width, x: stopX, y: stopY, r: style.StationStand.standEmergent.mergentR, n: 4 }); // 列车出发 const departX = model.position.x; const departY = model.position.y; this.trainDepart = new ETrainDepart({ zlevel: this.zlevel, z: this.z + 1, style: style, inside: model.inside, right: model.right, width: model.width, x: departX, y: departY }); /** 站台折返策略*/ const reentryH = style.StationStand.standEmergent.mergentR; const reentryX = model.position.x - (style.StationStand.reentry.position || drict) * (style.StationStand.reentry.offset.x - model.width / 2); const reentryY = model.position.y + (style.StationStand.reentry.position || drict) * (style.StationStand.reentry.offset.y) + drict * reentryH; this.reentry = new EReentry({ zlevel: this.zlevel, z: this.z + 1, style: style, drict: drict, x: reentryX, y: reentryY, lineWidth: 0, fill: style.StationStand.reentry.noHumanColor }); // const distance = style.StationStand.safetyDoor.height * 2 - style.StationStand.stand.headFontSize / 2 - 2; /** 站台扣车*/ const detainD = model.right ? 1 : -1; let detainX = model.position.x - (style.StationStand.stopTime.position || detainD) * (style.StationStand.detainCar.offset.x - model.width / 2); let detainY = model.position.y + (style.StationStand.stopTime.position || detainD) * (style.StationStand.detainCar.offset.y - model.height / 2); if (style.StationStand.common.special) { detainX = model.position.x; detainY = model.position.y; } this.detain = new EDetain({ zlevel: this.zlevel, z: this.z, style: style, x: detainX, y: detainY, width: model.width, inside: model.inside, right: model.right, textAlign: 'middle', textVerticalAlign: 'top' }); /** 停站时间*/ const timeH = style.StationStand.standEmergent.mergentR; const timeX = model.position.x - (style.StationStand.stopTime.position || drict) * (style.StationStand.stopTime.offset.x - model.width / 2); const timeY = model.position.y + (style.StationStand.stopTime.position || drict) * (style.StationStand.stopTime.offset.y) + drict * timeH; this.time = new ETime({ zlevel: this.zlevel, z: this.z + 1, style: style, x: timeX, y: timeY, name: model.parkingTime || '30' }); /** 运行等级*/ const levelH = style.StationStand.standEmergent.mergentR; const levelX = model.position.x - (style.StationStand.level.position || drict) * (style.StationStand.level.offset.x - model.width / 2); const levelY = model.position.y + (style.StationStand.level.position || drict) * (style.StationStand.level.offset.y) + drict * levelH; this.level = new ELevel({ zlevel: this.zlevel, z: this.z + 1, style: style, x: levelX, y: levelY, name: model.runLevelTime || '5' }); /** 列车停跳 */ if (style.StationStand.common.haveJumpShow) { const jumpH = style.StationStand.standEmergent.mergentR; const jumpX = model.position.x - (style.StationStand.jump.position || drict) * (style.StationStand.jump.offset.x - model.width / 2); const jumpY = model.position.y + (style.StationStand.jump.position || drict) * (style.StationStand.jump.offset.y) + drict * jumpH; const jumpCX = model.position.x - (style.StationStand.jump.position || drict) * (style.StationStand.jump.offset.x - model.width / 2); const jumpCY = model.position.y + (style.StationStand.jump.position || drict) * (style.StationStand.jump.offset.y - style.StationStand.common.textFontSize / 2) + drict * jumpH; this.jump = new EJump({ zlevel: this.zlevel, z: this.z + 1, style: style, x: jumpX, y: jumpY, cx: jumpCX, cy: jumpCY, textAlign: 'middle', textVerticalAlign: 'top', allSkip: model.allSkip, assignSkip: model.assignSkip }); this.add(this.jump); } this.add(this.emergent); this.add(this.detain); this.add(this.reentry); this.add(this.time); this.add(this.level); this.add(this.trainStop); this.add(this.trainDepart); } createMouseEvent() { if (this.style.StationStand.mouseOverStyle) { this.mouseEvent = new EMouse(this); this.add(this.mouseEvent); this.on('mouseout', (e) => { this.mouseEvent.mouseout(e); }); this.on('mouseover', (e) => { this.mouseEvent.mouseover(e); }); } } setVisible(visible) { if (visible) { this.eachChild(elem => { elem.show(); }); } else { this.eachChild(elem => { elem.hide(); }); } } /** 恢复初始状态*/ recover() { this.time && this.time.hide(); this.level && this.level.hide(); if (!this.style.StationStand.common.special) { this.detain && this.detain.hide(); } this.emergent && this.emergent.hide(); this.trainStop && this.trainStop.hide(); // 列车停站 this.trainDepart && this.trainDepart.hide(); this.reentry && this.reentry.hide(); this.jump && this.jump.hide(); this.jump && this.jump.setStatus(0, 0); } /** 空闲*/ spare() { if (!this.style.StationStand.common.special) { this.safeStand && this.safeStand.setColor(this.style.StationStand.stand.spareColor); } } /** 列车停站*/ stop() { if (!this.style.StationStand.common.special) { this.safeStand && this.safeStand.setColor(this.style.StationStand.stand.stopColor); } this.trainStop && this.trainStop.show(); this.trainDepart && this.trainDepart.show(); } /** 站台紧急关闭*/ emergentClose() { if (!this.style.StationStand.common.special) { this.safeStand && this.safeStand.setColor(this.style.StationStand.stand.spareColor); } this.emergent && this.emergent.show(); } /** 指定列车跳站*/ designatedJumpStop() { this.safeStand && this.safeStand.setColor(this.style.StationStand.stand.designatedJumpStopColor); this.jump && this.jump.show(); this.jump && this.jump.setStatus(0, 1); } /** 未设置跳停*/ unJumpStop() { this.jump && this.jump.hide(); this.jump && this.jump.setStatus(0, 0); } /** 站台跳停*/ jumpStop() { this.safeStand && this.safeStand.setColor(this.style.StationStand.stand.jumpStopColor); this.jump && this.jump.show(); this.jump && this.jump.setStatus(1, 0); } /** 车站扣车*/ standDetainTrain() { this.detain && this.detain.show(); this.detain && this.detain.setColor(this.style.StationStand.detainCar.detainTrainTextColor); } /** 中心扣车*/ centerDetainTrain() { this.detain && this.detain.show(); this.detain && this.detain.setColor(this.style.StationStand.detainCar.centerTrainColor); } /** 中心+车站扣车*/ standAndCenterDetainTrain() { this.detain && this.detain.show(); this.detain && this.detain.setColor(this.style.StationStand.detainCar.andCenterTrainColor); } /** 人工设置停战时间*/ setManuallyArmisticeTime(val) { this.time && this.time.show(); this.time && this.time.setName(val); } /** 人工设置运行等级*/ setManuallyOperationLevel(val) { this.level && this.level.show(); this.level && this.level.setName(val); } /** 无折返(默认)*/ noReentry() { this.reentry && this.reentry.hide(); } /** 无人折返*/ noHumanReentry() { this.reentry && this.reentry.show(); this.reentry && this.reentry.setColor(this.style.StationStand.reentry.noHumanColor); } /** 自动换端*/ autoChangeEnds() { this.reentry && this.reentry.show(); this.reentry && this.reentry.setColor(this.style.StationStand.reentry.autoChangeEndsColor); } setState(model) { // 新版地图使用新版状态变更方式 this.recover(); model.free && this.spare(); /** 空闲*/ model.trainParking && this.stop(); /** 列车停站*/ model.emergencyClosed && this.emergentClose(); /** 站台紧急关闭*/ if (Number(model.parkingTime) > 0) { this.setManuallyArmisticeTime(model.parkingTime); // 设置站台停车时间 } if (Number(model.runLevelTime) > 0) { this.setManuallyOperationLevel(model.runLevelTime); // 设置站台间运行等级 } /** 设置跳停*/ // this.unJumpStop(); // 未设置跳停 model.assignSkip && this.designatedJumpStop(); // 指定站台跳停 model.allSkip && this.jumpStop(); // 站台全部跳停 /** 设置扣车*/ if (model.stationHoldTrain && model.centerHoldTrain) { this.standAndCenterDetainTrain(); // 中心+车站扣车 } else if (model.stationHoldTrain) { this.standDetainTrain(); // 车站扣车 } else if (model.centerHoldTrain) { this.centerDetainTrain(); // 中心扣车 } /** 设置折返策略*/ switch (model.reentryStrategy) { case '04': /** 默认*/ case '01': this.noReentry(); /** 无折返策略*/ break; case '02': this.noHumanReentry(); /** 无人折返*/ break; case '03': this.autoChangeEnds(); /** 自动换端*/ break; } } getBoundingRect() { const rect = this.safeStand.getBoundingRect().clone(); return rect; } getShapeTipPoint() { const rect = this.getBoundingRect(); if (rect) { return { x: rect.x + rect.width / 2, y: rect.y }; } return null; } drawSelected(selected) { this.highlight && this.highlight.drawSelected(selected); } checkIsDrawMap() { const path = window.location.href; if (path.includes('/map/draw')) { this.highlight = new EHighlight(this); this.add(this.highlight); this.on('mouseout', () => { this.highlight.mouseout(); }); this.on('mouseover', () => { this.highlight.mouseover(); }); } } } export default StationStand;