diff --git a/src/jmap/map.js b/src/jmap/map.js index b058dd6f3..2fae18d8d 100644 --- a/src/jmap/map.js +++ b/src/jmap/map.js @@ -8,6 +8,7 @@ import deviceState from './constant/deviceState'; import { selectSkinStyle } from './config/deviceStyle'; import deviceType from './constant/deviceType'; import { parser, deviceFactory, createBoundingRect, calculateDCenter } from './utils/parser'; +import { lstat } from 'fs'; const renderer = 'canvas'; const devicePixelRatio = 1; @@ -166,21 +167,24 @@ class Jlmap { if (this.methods.viewUpdate instanceof Function) { this.methods.viewUpdate(list); } } - pretreatment(list) { - const tempList = []; - - list.forEach(elem => { - // 设置计数器增加 - if (elem._type === deviceType.StationCounter) { - let val = '' + elem.val; - if (val === '0' || !elem.val) { - val = elem.val = localStore.get(elem._code) || '0'; - } - - localStore(elem._code, val); + // 中间处理 + hookHandle(elem) { + // 如果是延时计时,需要保存计数值到全局 + if (elem._type === deviceType.StationCounter) { + let val = '' + elem.val; + if (val === '0' || !elem.val) { + val = elem.val = localStore.get(elem._code) || '0'; } - // 设置区段层级 + localStore(elem._code, val); + } + + return elem; + } + + // 后处理 + postHandle(list) { + list.forEach(elem => { if (elem._type == deviceType.Switch) { const item = this.mapDevice[elem.code]; if (item) { @@ -188,15 +192,16 @@ class Jlmap { const sectionB = this.mapDevice[item.model.sectionBCode]; const sectionC = this.mapDevice[item.model.sectionCCode]; if (sectionA && sectionB && sectionC) { - elem.cutOff = sectionA.state.cutOff; - elem.sectionAstatus = sectionA.state.status; - elem.sectionBstatus = sectionB.state.status; - elem.sectionCstatus = sectionC.state.status; + item.state['cutOff'] = sectionA.state.cutOff; + item.state['sectionAstatus'] = sectionA.state.status; + item.state['sectionBstatus'] = sectionB.state.status; + item.state['sectionCstatus'] = sectionC.state.status; } } + + this.$painter.update(item); } - // 设置道岔切除 if (elem._type == deviceType.Section) { const item = this.mapDevice[elem.code]; if (item) { @@ -206,33 +211,34 @@ class Jlmap { const sectionB = this.mapDevice[swch.model.sectionBCode]; const sectionC = this.mapDevice[swch.model.sectionCCode]; if (sectionA && sectionB && sectionC) { - swch.state.sectionAstatus = sectionA.state.status; - swch.state.sectionBstatus = sectionB.state.status; - swch.state.sectionCstatus = sectionC.state.status; + swch.state['sectionAstatus'] = sectionA.state.status; + swch.state['sectionBstatus'] = sectionB.state.status; + swch.state['sectionCstatus'] = sectionC.state.status; } - tempList.push(swch.state); + this.$painter.update(swch); } } } }); - - return [...list, ...tempList]; } update(list) { - this.pretreatment(list).forEach(elem => { + (list || []).forEach(elem => { const code = elem.code; const oDevice = this.mapDevice[code] || {}; if (elem._dispose) { this.$painter.delete(oDevice); } else { - const state = Object.assign(oDevice.state || {}, elem); + const state = Object.assign(oDevice.state || {}, this.hookHandle(elem)); const nDevice = Object.assign(oDevice, { state }); this.$painter.update(nDevice); } }); + // 状态后处理 + this.postHandle(list); + if (this.methods.stateUpdate instanceof Function) { this.methods.stateUpdate(list); } } diff --git a/src/jmap/shape/Section/index.js b/src/jmap/shape/Section/index.js index cdf160e0b..73e5cd9c5 100644 --- a/src/jmap/shape/Section/index.js +++ b/src/jmap/shape/Section/index.js @@ -15,7 +15,6 @@ export default class Section extends Group { this._type = _type; this.zlevel = zlevel; this.z = 5 + parseInt(model.layer || 0); - console.log(model.layer); this.model = model; this.state = state; this.style = style; @@ -165,7 +164,7 @@ export default class Section extends Group { const fontSize = model.type == '02' ? style.Section.text.fontSize + 2: style.Section.text.fontSize; this.sectionText = new ETextName({ zlevel: this.zlevel, - z: this.z + 6, + z: this.z + 2, style: this.style, silent: false, x: tempx, @@ -195,7 +194,7 @@ export default class Section extends Group { // 创建站台轨名称 this.standTrackText = new ETextName({ zlevel: this.zlevel, - z: 6, + z: this.z + 2, x: tempx + model.standTrackNamePosition.x, y: tempy + model.standTrackNamePosition.y, fontWeight: 'bold', @@ -216,7 +215,7 @@ export default class Section extends Group { // 创建折返轨名称 this.reentryTrackText = new ETextName({ zlevel: this.zlevel, - z: 6, + z: this.z + 2, x: x + model.reentryTrackNamePosition.x, y: y + model.reentryTrackNamePosition.y + style.nameDistance + style.Section.text.fontSize, fontWeight: 'bold', @@ -237,7 +236,7 @@ export default class Section extends Group { // 转换轨名称 this.transferTrackText = new ETextName({ zlevel: this.zlevel, - z: 6, + z: this.z + 2, x: x + model.transferTrackNamePosition.x, y: y + model.transferTrackNamePosition.y + style.nameDistance + style.Section.text.fontSize * 2, fontWeight: 'bold', @@ -258,7 +257,7 @@ export default class Section extends Group { // 转换轨名称 this.destinationText = new ETextName({ zlevel: this.zlevel, - z: 6, + z: this.z + 2, x: x + model.destinationCodePoint.x, y: y + model.destinationCodePoint.y, fontWeight: 'bold', diff --git a/src/jmap/shape/Signal/index.js b/src/jmap/shape/Signal/index.js index b8f219f1e..a85826882 100644 --- a/src/jmap/shape/Signal/index.js +++ b/src/jmap/shape/Signal/index.js @@ -22,7 +22,7 @@ class Signal extends Group { this.count = parseInt(model.lampPositionType); this.lamps = new Array(this.count); this.zlevel = zlevel; - this.z = 1; + this.z = 7; this.create(); this.transformRotation(this); this.setState(state); diff --git a/src/jmap/shape/Switch/ESwLnversion.js b/src/jmap/shape/Switch/ESwLnversion.js index 2534fd762..ec065c312 100644 --- a/src/jmap/shape/Switch/ESwLnversion.js +++ b/src/jmap/shape/Switch/ESwLnversion.js @@ -29,7 +29,7 @@ class ESwLnversion extends Group { this.section = new Polygon({ zlevel: model.zlevel, - z: model.z, + z: model.z + 1, shape: { points: model.sectionPoints }, diff --git a/src/jmap/shape/Switch/index.js b/src/jmap/shape/Switch/index.js index b966a1e7a..3ccbae572 100644 --- a/src/jmap/shape/Switch/index.js +++ b/src/jmap/shape/Switch/index.js @@ -185,6 +185,7 @@ export default class Switch extends Group { this.releaseBackground.hide(); this.setHasTextBorder(0); + switch (this.state.locateType) { case '01': this.setTextColor(this.style.Switch.text.switchTextLocateColor); @@ -212,6 +213,7 @@ export default class Switch extends Group { this.setSwitchCoreInvisible(true); this.locShelter.hide(); this.relocShelter.show(); + this.setSectionState(this.relocShelter.getSection(), 'fill', this.state.sectionAstatus); } /** 失去*/ @@ -261,7 +263,6 @@ export default class Switch extends Group { switch (this.model.locateType) { case '01': this.releaseBackground.hide(); - this.setSectionState(this.relocShelter.getSection(), 'stroke', this.state.sectionAstatus); break; case '02': this.relocShelter.getSection().animateStyle(true) @@ -271,48 +272,46 @@ export default class Switch extends Group { } } - setSectionState(section, styleKey, state) { + setSectionState(section, style, state) { if (section) { switch (state) { case '00': break; case '01': /** 空闲*/ - section.setStyle(styleKey, this.style.Section.line.spareColor); + section.setStyle(style, this.style.Section.line.spareColor); break; case '02': /** 通信车占用*/ - section.setStyle(styleKey, this.style.Section.line.communicationOccupiedColor); + section.setStyle(style, this.style.Section.line.communicationOccupiedColor); break; case '03': /** 非通信车占用*/ - section.setStyle(styleKey, this.style.Section.line.unCommunicationOccupiedColor); + section.setStyle(style, this.style.Section.line.unCommunicationOccupiedColor); break; case '04': /** 进路锁闭*/ - section.setStyle(styleKey, this.style.Section.line.routeLockColor); + section.setStyle(style, this.style.Section.line.routeLockColor); break; case '05': /** 故障锁闭*/ - section.setStyle(styleKey, this.style.Section.line.faultLockColor); + section.setStyle(style, this.style.Section.line.faultLockColor); break; case '06': /** 封锁*/ - section.setStyle(styleKey, this.style.Section.line.blockColor); + section.setStyle(style, this.style.Section.line.blockColor); break; case '07': /** ATC切除*/ - section.setStyle(styleKey, this.style.Section.line.atcExcisionColor); + section.setStyle(style, this.style.Section.line.atcExcisionColor); break; case '08': /** ATS切除*/ - section.setStyle(styleKey, this.style.Section.line.atsExcisionColor); + section.setStyle(style, this.style.Section.line.atsExcisionColor); section.animateStyle(true) .when(1000, { fill: this.style.backgroundColor }) .when(2000, { fill: this.style.Section.line.atsExcisionColor }) .start(); break; case '09': /** 进路延续保护 */ - section.setStyle(styleKey, this.style.Section.line.protectiveLockColor); + section.setStyle(style, this.style.Section.line.protectiveLockColor); break; } } } setLocateType(state) { - console.log(this.state.sectionCstatus); - this.setSectionState(this.relocShelter.getSection(), 'fill', this.state.sectionCstatus); switch (state.locateType) { case '01': this.setLocationAction(); /** 定位*/ diff --git a/src/jmap/utils/parser.js b/src/jmap/utils/parser.js index 13731f01a..3595baea5 100644 --- a/src/jmap/utils/parser.js +++ b/src/jmap/utils/parser.js @@ -108,9 +108,9 @@ export function parser(data, jmap) { }, this); zrUtil.each(data.switchList || [], elem => { - const cnodeSection = elem['sectionA'] = mapDevice[elem.sectionACode]; - const lnodeSection = elem['sectionB'] = mapDevice[elem.sectionBCode]; - const rnodeSection = elem['sectionC'] = mapDevice[elem.sectionCCode]; + const cnodeSection = mapDevice[elem.sectionACode]; + const lnodeSection = mapDevice[elem.sectionBCode]; + const rnodeSection = mapDevice[elem.sectionCCode]; cnodeSection.model['switch'] = lnodeSection.model['switch'] = rnodeSection.model['switch'] = elem;