import Group from 'zrender/src/container/Group'; import TrainBodyBox from './TrainBodyBox'; import '../StationStand/EDetain'; import ETextName from '../element/ETextName'; // 名称文字 (共有) import EMouse from './EMouse'; import store from '@/store'; /** 车身*/ export default class TrainBody extends Group { constructor(model) { super(); this.model = model; this.deviceModel = model.model; this.nameFormat = model.nameFormat; this.create(); this.createMouse(); // 鼠标事件 } createMouse() { this.mouseEvent = new EMouse(this); this.add(this.mouseEvent); if (this.deviceModel.down) { store.dispatch('map/setTrainDetails', this.deviceModel); this.mouseEvent.mouseover(); } this.on('mouseover', () => { store.dispatch('map/setTrainDetails', this.deviceModel); this.mouseEvent.mouseover(); }); this.on('mouseout', () => { store.dispatch('map/setTrainDetails', null); this.mouseEvent.mouseout(); }); } create() { const model = this.model; const style = this.model.style; this.trainBodyBox = new TrainBodyBox({ zlevel: model.zlevel, z: model.z, point: model.point, style: style }); const beginX = (model.point.x + style.Train.trainBody.lrPadding); const beginY = (model.point.y - style.Train.hsda.trainHSDATextFontSize - style.Train.hsda.upPaddingHSDA); const margin = (style.Train.common.trainWidth - style.Train.hsda.lrPaddingHSDA * 2) / 4; this.textH = style.Train.common.haveTextHSDA ? new ETextName({ zlevel: model.zlevel, z: model.z, x: parseInt(beginX + margin * 0), y: parseInt(beginY), text: style.Train.hsda.textHContent, textFill: style.trainYellowColor, fontSize: style.Train.hsda.trainHSDATextFontSize, fontFamily: style.Train.common.fontFamily, textAlign: 'middle', textVerticalAlign: 'top' }) : ''; this.textS = style.Train.common.haveTextHSDA ? new ETextName({ zlevel: model.zlevel, z: model.z, x: parseInt(beginX + margin * 1), y: parseInt(beginY), text: style.Train.hsda.textSContent, textFill: style.trainBlueColor, fontSize: style.Train.hsda.trainHSDATextFontSize, fontFamily: style.Train.common.fontFamily, textAlign: 'middle', textVerticalAlign: 'top' }) : ''; this.textD = style.Train.common.haveTextHSDA ? new ETextName({ zlevel: model.zlevel, z: model.z, x: parseInt(beginX + margin * 2), y: parseInt(beginY), text: style.Train.hsda.textDContent, textFill: style.trainGreenColor, fontSize: style.Train.hsda.trainHSDATextFontSize, fontFamily: style.Train.common.fontFamily, textAlign: 'middle', textVerticalAlign: 'top' }) : ''; this.textA = style.Train.common.haveTextHSDA ? new ETextName({ zlevel: model.zlevel, z: model.z, x: parseInt(beginX + margin * 3), y: parseInt(beginY), text: style.Train.hsda.textAContent, textFill: style.trainRedColor, fontSize: style.Train.hsda.trainHSDATextFontSize, fontFamily: style.Train.common.fontFamily, textAlign: 'middle', textVerticalAlign: 'top' }) : ''; const serviceNumber = style.Train.trainServer.serviceNumberPrefix + (model.serviceNumber || style.Train.trainServer.defaultServiceNumber) + '';// 服务号(表号) const tripNumber = style.Train.trainTarget.tripNumberPrefix + (style.Train.trainTarget.defaultDirectionCode ?(model.directionCode||style.Train.trainTarget.defaultDirectionCode) + (model.tripNumber || style.Train.trainTarget.defaultTripNumber) :model.tripNumber || style.Train.trainTarget.defaultTripNumber) + ''; // 车次号 const targetCode = style.Train.trainNumber.targetCodePrefix + (model.targetCode || style.Train.trainNumber.defaultTargetCode) + ''; // 目的地码 const groupNumber = style.Train.trainTargetNumber.groupNumberPrefix + (model.groupNumber || style.Train.trainTargetNumber.defaultGroupNumber) + ''; // 车组号 this.textTrainServer = new ETextName({ zlevel: model.zlevel, z: model.z+1, x: parseInt(model.point.x + style.Train.trainServer.trainServerOffset.x), y: parseInt(model.point.y + style.Train.trainServer.trainServerOffset.y), text: serviceNumber.substring(serviceNumber.length - style.Train.trainServer.serviceNumberPrefix.length), textFill: style.trainTextColor, fontSize: model.fontSize, fontFamily: style.Train.common.fontFamily, textAlign: 'left', textVerticalAlign: 'top' }); this.textTrainTarget = new ETextName({ zlevel: this.model.zlevel, z: this.model.z+1, x: parseInt(model.point.x + model.style.Train.trainTarget.trainTargetOffset.x), y: parseInt(model.point.y + model.style.Train.trainTarget.trainTargetOffset.y), text: tripNumber.substring(tripNumber.length - style.Train.trainTarget.tripNumberPrefix.length), textFill: style.trainTextColor, fontSize: model.fontSize, fontFamily: style.Train.common.fontFamily, textAlign: style.Train.trainTarget.trainTargetTextAlign, textVerticalAlign: 'top' }); this.textTrainNumber = new ETextName({ zlevel: model.zlevel, z: model.z+1, x: parseInt(model.point.x + style.Train.trainNumber.trainNumberOffset.x), y: parseInt(model.point.y + style.Train.trainNumber.trainNumberOffset.y), text: targetCode.substring(targetCode.length - 3), textFill: style.trainTextColor, textStroke: style.trainTextColor, fontWeight: 400, textStrokeWidth: 0, fontSize: model.fontSize, fontFamily: style.Train.common.fontFamily, textAlign: 'left', textVerticalAlign: 'top' }); this.textTrainTargetNumber = new ETextName({ zlevel: model.zlevel, z: model.z+1, x: parseInt(model.point.x - style.Train.trainBody.lrPadding), y: parseInt(model.point.y + style.Train.trainBody.upPadding), text: groupNumber.substring(groupNumber.length - 3), textFill: style.trainTextColor, textStroke: style.trainTextColor, textStrokeWidth: 0, fontSize: model.fontSize, fontFamily: style.Train.common.fontFamily, textAlign: 'left', textVerticalAlign: 'top' }); this.formatChangePosition(model, style); this.add(this.trainBodyBox); if (style.Train.common.haveTextHSDA) { this.add(this.textH); this.add(this.textS); this.add(this.textD); this.add(this.textA); } } removeTrainDetail() { this.mouseEvent.mouseout(); store.dispatch('map/setTrainDetails', null); this.deviceModel.down = false; } setTrainColor(color) { this.trainBodyBox && this.trainBodyBox.setStyle('fill', color); } setTextTrainServerColor(color) { this.textTrainServer&&this.textTrainServer.setStyle('textFill', color); this.textTrainServer&&this.textTrainServer.setStyle('textStroke', color); } setTextTrainTargetColor(color) { this.textTrainTarget&&this.textTrainTarget.setStyle('textFill', color); this.textTrainTarget&&this.textTrainTarget.setStyle('textStroke', color); } setTextTrainNumberColor(color) { this.textTrainNumber&&this.textTrainNumber.setStyle('textFill', color); this.textTrainNumber&&this.textTrainNumber.setStyle('textStroke', color); } setTextTrainTargetNumberColor(color) { this.textTrainTargetNumber&&this.textTrainTargetNumber.setStyle('textFill', color); this.textTrainTargetNumber&&this.textTrainTargetNumber.setStyle('textStroke', color); } setHShow(isShow) { if (this.textH) { isShow ? this.textH.show() : this.textH.hide(); } } setSShow(isShow) { if (this.textS) { isShow ? this.textS.show() : this.textS.hide(); } } setDShow(isShow) { if (this.textD) { isShow ? this.textD.show() : this.textD.hide(); } } setAShow(isShow) { if (this.textA) { isShow ? this.textA.show() : this.textA.hide(); } } setBodyBoxShape(key, color) { this.trainBodyBox && this.trainBodyBox.setColor(key, color); } formatChangePosition(model, style) { if (this.nameFormat) { const arr = this.nameFormat.split(':'); let widthText = 0; arr.forEach(ele => { if (ele == 'targetCode') { this.textTrainNumber.setStyle('x', parseInt(model.point.x + widthText + style.Train.common.textOffset) ); widthText += this.textTrainNumber.getBoundingRect().width; this.add(this.textTrainNumber); } else if (ele == 'serviceNumber') { this.textTrainServer.setStyle('x', parseInt(model.point.x + widthText + style.Train.common.textOffset)); widthText += this.textTrainServer.getBoundingRect().width; this.add(this.textTrainServer); } else if (ele == 'tripNumber') { this.textTrainTarget.setStyle('x', parseInt(model.point.x + widthText + style.Train.common.textOffset)); widthText += this.textTrainTarget.getBoundingRect().width; this.add(this.textTrainTarget); } else if (ele == 'groupNumber') { this.textTrainTargetNumber.setStyle('x', parseInt(model.point.x + widthText + style.Train.common.textOffset)); widthText += this.textTrainTargetNumber.getBoundingRect().width; this.add(this.textTrainTargetNumber); } }); } } }