2019-11-29 12:51:58 +08:00
|
|
|
import * as zrUtil from 'zrender/src/core/util';
|
|
|
|
import zrender from 'zrender';
|
|
|
|
import localStore from 'storejs';
|
|
|
|
import Painter from './painter';
|
|
|
|
import Options from './options';
|
|
|
|
import MouseController from './mouseController';
|
|
|
|
import KeyboardController from './keyboardController';
|
2020-02-11 14:50:56 +08:00
|
|
|
import deviceState from './constant/deviceState'; // 初始化默认状态
|
2019-11-29 12:51:58 +08:00
|
|
|
import deviceType from './constant/deviceType';
|
|
|
|
import { selectLineCode } from './config/deviceStyle';
|
|
|
|
import { deviceFactory, createBoundingRect, calculateDCenter } from './utils/parser';
|
|
|
|
import { deepAssign } from '@/utils/index';
|
2021-02-24 18:52:38 +08:00
|
|
|
import * as adapter from '@/jmapNew/utils/adapter';
|
2020-12-15 11:18:15 +08:00
|
|
|
import store from '@/store/index';
|
2020-07-06 17:02:13 +08:00
|
|
|
import Vue from 'vue';
|
2019-11-29 12:51:58 +08:00
|
|
|
|
|
|
|
const renderer = 'canvas';
|
|
|
|
const devicePixelRatio = 1;
|
|
|
|
|
|
|
|
class Jlmap {
|
|
|
|
constructor(opts) {
|
|
|
|
// 回调事件
|
|
|
|
this.methods = opts.methods;
|
|
|
|
|
|
|
|
// 鼠标事件
|
|
|
|
this.events = { __Pan: 'pan', __Zoom: 'zoom', Selected: 'selected', Contextmenu: 'contextmenu', DataZoom: 'dataZoom', Keyboard: 'keyboard'};
|
|
|
|
|
|
|
|
// 线路参数
|
|
|
|
this.lineCode = '';
|
|
|
|
|
2020-07-06 17:02:13 +08:00
|
|
|
// 大屏判断
|
|
|
|
this.screenFlag = false;
|
|
|
|
|
2019-11-29 12:51:58 +08:00
|
|
|
// 皮肤风格
|
|
|
|
this.style = {};
|
|
|
|
|
|
|
|
// 设备数据
|
|
|
|
this.mapDevice = {};
|
|
|
|
|
|
|
|
// 默认状态
|
|
|
|
this.defaultStateDict = this.loadDefaultState();
|
|
|
|
|
|
|
|
this.initMapInstance(opts);
|
2020-03-13 13:01:58 +08:00
|
|
|
|
|
|
|
// 显示集中站
|
|
|
|
this.stationCode = '';
|
2020-06-17 15:31:15 +08:00
|
|
|
this.isUpdateShowTrainList = false;
|
2021-03-03 16:15:02 +08:00
|
|
|
this.isUpdateRunLineTrain = false;
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 初始化属性有鼠标事件 缩放等
|
|
|
|
initMapInstance(opts) {
|
|
|
|
const width = opts.dom.clientWidth;
|
|
|
|
const height = opts.dom.clientHeight;
|
|
|
|
this.zoomOnMouseWheel = opts.options.zoomOnMouseWheel;
|
2020-03-12 14:41:53 +08:00
|
|
|
this.previewOrMapDraw = opts.showConfig.previewOrMapDraw;
|
2019-11-29 12:51:58 +08:00
|
|
|
|
|
|
|
this.$zr = zrender.init(opts.dom, deepAssign({ renderer, devicePixelRatio, width, height }, opts.config));
|
2020-10-12 16:21:24 +08:00
|
|
|
this.$zr.dom.setAttribute('tabIndex', -1);
|
2019-11-29 12:51:58 +08:00
|
|
|
|
|
|
|
this.$options = new Options(deepAssign({ scaleRate: 1, offsetX: 0, offsetY: 0 }, opts.options || {}), (dataZoom) => { this.$mouseController.trigger(this.events.DataZoom, dataZoom); }); // 缩放
|
|
|
|
this.$painter = new Painter(this);
|
2020-11-24 16:53:13 +08:00
|
|
|
this.$painter.updateZrSize({width: this.$zr.getWidth(), height: this.$zr.getHeight(), isUpdate:false});
|
2020-08-19 15:50:33 +08:00
|
|
|
this.$zr.dom.style.backgroundColor = this.style.backgroundColor || '#000';
|
2019-11-29 12:51:58 +08:00
|
|
|
this.optionsHandler = this.setOptions.bind(this);
|
|
|
|
|
|
|
|
this.$mouseController = new MouseController(this);
|
|
|
|
this.$mouseController.enable();
|
|
|
|
|
|
|
|
this.$mouseController.on(this.events.__Pan, this.optionsHandler);
|
|
|
|
this.$mouseController.on(this.events.__Zoom, this.optionsHandler);
|
|
|
|
|
|
|
|
this.$keyboardController = new KeyboardController(this);
|
|
|
|
this.$keyboardController.enable();
|
2020-03-11 15:10:08 +08:00
|
|
|
this.showConfig = opts.showConfig;
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
loadStyle(lineCode) {
|
|
|
|
return selectLineCode(lineCode);
|
|
|
|
}
|
|
|
|
|
2020-02-11 14:50:56 +08:00
|
|
|
loadDefaultState() { // 加载默认状态
|
2019-11-29 12:51:58 +08:00
|
|
|
const defaultStateDict = {};
|
|
|
|
|
|
|
|
zrUtil.each(Object.keys(deviceState), (type) => {
|
|
|
|
defaultStateDict[type] = {};
|
|
|
|
zrUtil.each(Object.keys(deviceState[type] || {}), (state) => {
|
2020-01-13 13:45:39 +08:00
|
|
|
defaultStateDict[type][state] = deviceState[type][state]; // 新版地图直接使用判断结果
|
2019-11-29 12:51:58 +08:00
|
|
|
}, this);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
return defaultStateDict;
|
|
|
|
}
|
|
|
|
|
2020-03-20 14:12:02 +08:00
|
|
|
setMap(map, mapDevice, logicData) {
|
2019-11-29 12:51:58 +08:00
|
|
|
// 保存皮肤类型
|
|
|
|
if (map.skinVO) {
|
|
|
|
this.lineCode = map.skinVO.code;
|
2020-05-11 14:45:07 +08:00
|
|
|
this.$options.scaleRate = map.scaling || 1;
|
|
|
|
this.$options.offsetX = map.origin ? map.origin.x : 0;
|
|
|
|
this.$options.offsetY = map.origin ? map.origin.y : 0;
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
// 更新视图大小
|
|
|
|
this.$painter.updateTransform({ scaleRate: this.$options.scaleRate, offsetX: this.$options.offsetX, offsetY: this.$options.offsetY });
|
|
|
|
|
|
|
|
// 解析后的数据
|
|
|
|
this.mapDevice = mapDevice;
|
2020-02-14 18:07:54 +08:00
|
|
|
// 进路数据
|
2020-03-20 14:12:02 +08:00
|
|
|
this.logicData = logicData;
|
2019-11-29 12:51:58 +08:00
|
|
|
// 加载对应皮肤
|
|
|
|
this.style = this.loadStyle(this.lineCode);
|
2020-08-19 15:50:33 +08:00
|
|
|
this.$zr.dom.style.backgroundColor = this.style.backgroundColor || '#000';
|
2019-11-29 12:51:58 +08:00
|
|
|
|
|
|
|
// 数据加载完成 回调
|
|
|
|
if (this.methods.dataLoaded instanceof Function) { this.methods.dataLoaded(this.mapDevice); }
|
|
|
|
|
|
|
|
// 初次渲染视图
|
|
|
|
this.$painter.repaint(this.mapDevice);
|
|
|
|
|
|
|
|
// 视图加载完成 回调
|
|
|
|
if (this.methods.viewLoaded instanceof Function) { this.methods.viewLoaded(this.mapDevice); }
|
|
|
|
}
|
|
|
|
|
|
|
|
setMapDevice(mapDevice) {
|
|
|
|
this.mapDevice = mapDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
setDefaultState() {
|
|
|
|
const list = [];
|
|
|
|
|
|
|
|
Object.values(this.mapDevice).forEach(elem => {
|
|
|
|
const code = elem.code;
|
|
|
|
const type = elem._type;
|
|
|
|
// 列车不需要设置默认状态
|
|
|
|
type != deviceType.Train && list.push(Object.assign({ code, _type: type }, this.defaultStateDict[type]));
|
2020-07-27 14:11:43 +08:00
|
|
|
});
|
2019-11-29 12:51:58 +08:00
|
|
|
this.update(list);
|
|
|
|
|
|
|
|
if (this.methods.stateLoaded instanceof Function) { this.methods.stateLoaded(list); }
|
|
|
|
}
|
|
|
|
|
|
|
|
setOptions(opts) {
|
|
|
|
const options = this.pullBack(opts);
|
2020-07-06 17:02:13 +08:00
|
|
|
if (this.screenFlag) {
|
|
|
|
this.$painter.updateScreen(options);
|
|
|
|
} else {
|
|
|
|
this.$options.update(options);
|
|
|
|
this.$painter.updateTransform(this.$options);
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
if (this.$options.disabled == true) {
|
|
|
|
this.$mouseController.disable();
|
|
|
|
} else {
|
|
|
|
opts['zoomOnMouseWheel'] = this.zoomOnMouseWheel;
|
2020-03-12 14:41:53 +08:00
|
|
|
opts['previewOrMapDraw'] = this.previewOrMapDraw;
|
2019-11-29 12:51:58 +08:00
|
|
|
this.$mouseController.enable(opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.methods.optionsUpdate instanceof Function) { this.methods.optionsUpdate(this.$options); }
|
|
|
|
}
|
|
|
|
|
2021-01-08 16:50:50 +08:00
|
|
|
switchScreen(data, num, sum, obj) {
|
|
|
|
const opts = {};
|
|
|
|
if (obj.width == 1) {
|
|
|
|
const dy = data.height / sum;
|
|
|
|
opts['dx'] = 0;
|
|
|
|
opts['dy'] = dy * (num - 1);
|
|
|
|
} else {
|
|
|
|
const sumHalf = sum <= 2 ? sum : sum / 2;
|
|
|
|
const dx = data.width / sumHalf;
|
|
|
|
const dy = data.height / sumHalf;
|
|
|
|
const row = num <= sumHalf ? 0 : 1;
|
|
|
|
opts['dx'] = dx * (row == 0 ? num - 1 : num - sumHalf - 1);
|
|
|
|
opts['dy'] = dy * row;
|
|
|
|
}
|
2020-07-06 17:02:13 +08:00
|
|
|
this.$painter.updateScreenNum(opts);
|
|
|
|
}
|
|
|
|
|
2021-02-20 17:02:40 +08:00
|
|
|
setCenterWithOffset(deviceCode, dx, offsetY) {
|
2021-02-05 18:01:16 +08:00
|
|
|
const arr = Object.keys(this.mapDevice);
|
|
|
|
if (arr.length != 0) {
|
|
|
|
const device = this.mapDevice[deviceCode];
|
|
|
|
if (device && device.instance) {
|
|
|
|
var rect = createBoundingRect(device.instance);
|
2021-02-20 17:02:40 +08:00
|
|
|
var dcenter = calculateDCenter(rect, dx);
|
|
|
|
this.setOptions({...dcenter, offsetY});
|
2021-02-05 18:01:16 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
setTimeout(() => {
|
2021-02-20 17:02:40 +08:00
|
|
|
this.setCenterWithOffset(deviceCode, dx, offsetY);
|
2021-02-05 18:01:16 +08:00
|
|
|
}, 60);
|
|
|
|
}
|
2021-02-18 16:58:35 +08:00
|
|
|
}
|
2021-02-05 18:01:16 +08:00
|
|
|
|
2019-11-29 12:51:58 +08:00
|
|
|
setCenter(deviceCode) {
|
2020-08-27 16:43:37 +08:00
|
|
|
const arr = Object.keys(this.mapDevice);
|
|
|
|
if (arr.length != 0) {
|
|
|
|
const device = this.mapDevice[deviceCode];
|
|
|
|
if (device && device.instance) {
|
|
|
|
var rect = createBoundingRect(device.instance);
|
2021-02-20 17:02:40 +08:00
|
|
|
var dcenter = calculateDCenter(rect, this.$zr.getWidth() / 2);
|
2020-08-27 16:43:37 +08:00
|
|
|
this.setOptions(dcenter);
|
|
|
|
}
|
|
|
|
} else {
|
2021-02-26 16:23:16 +08:00
|
|
|
setTimeout(() => { this.setCenter(deviceCode); }, 60);
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
}
|
2020-06-10 16:56:52 +08:00
|
|
|
setRevoverBigScreen() {
|
2020-07-06 17:02:13 +08:00
|
|
|
this.screenFlag = false;
|
2020-06-10 16:56:52 +08:00
|
|
|
this.$painter.updateTransform({ scaleRate: this.$options.scaleRate, offsetX: this.$options.offsetX, offsetY: this.$options.offsetY });
|
|
|
|
}
|
2020-05-13 15:31:12 +08:00
|
|
|
setRecover(opts) {
|
2020-07-06 17:02:13 +08:00
|
|
|
this.screenFlag = false;
|
2020-05-13 15:31:12 +08:00
|
|
|
this.$painter.updateTransform({ scaleRate: opts.scaleRate, offsetX: opts.offsetX, offsetY: opts.offsetY });
|
|
|
|
}
|
|
|
|
|
2020-05-07 09:04:28 +08:00
|
|
|
setUpdateScreen(opts) {
|
2020-05-13 15:31:12 +08:00
|
|
|
this.setRecover({ scaleRate: 1, offsetX: 0, offsetY: 0 });
|
2020-07-06 17:02:13 +08:00
|
|
|
this.screenFlag = true;
|
|
|
|
const screenList = [];
|
2020-05-11 15:29:25 +08:00
|
|
|
const rectList = [];
|
2020-05-08 16:12:03 +08:00
|
|
|
let rect = '';
|
|
|
|
for (const i in this.mapDevice) {
|
|
|
|
const element = this.mapDevice[i];
|
2020-07-06 17:02:13 +08:00
|
|
|
if (element.instance && (element._type == 'Section' || element._type == 'Station' || element._type == 'StationStand')) {
|
2020-05-08 16:12:03 +08:00
|
|
|
if (!rect) {
|
|
|
|
rect = element.instance.getBoundingRect().clone();
|
|
|
|
} else {
|
|
|
|
rect.union(element.instance.getBoundingRect().clone());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-06 17:02:13 +08:00
|
|
|
if (!opts.offsetList) {
|
|
|
|
opts.offsetList = [];
|
|
|
|
}
|
|
|
|
const screenSplit = opts.list.length ? opts.list : Vue.prototype.$theme.loadPropConvert(this.lineCode).screenSplit;
|
|
|
|
const screenDifference = Vue.prototype.$theme.loadPropConvert(this.lineCode).screenDifference || 160;
|
2020-05-13 15:31:12 +08:00
|
|
|
const splitList = JSON.parse(JSON.stringify(screenSplit));
|
|
|
|
const num = screenSplit.length + 1;
|
|
|
|
const offsetY = (opts.height - 100) / num; // 高度差
|
|
|
|
const maxWidth = rect.width;
|
|
|
|
splitList.push(maxWidth);
|
2020-07-06 17:02:13 +08:00
|
|
|
const scaleX = Math.floor((((opts.width - 200) * num) / rect.width) * 100) / 100;
|
|
|
|
const scaleY = Math.floor(((opts.height - 100) / (rect.height * num)) * 100) / 100;
|
|
|
|
const scale = Math.min(scaleX, scaleY);
|
2020-06-10 17:59:51 +08:00
|
|
|
|
2020-05-11 15:29:25 +08:00
|
|
|
for (let i = 0; i < splitList.length; i++) {
|
|
|
|
let offsetX = '';
|
|
|
|
if (i == 0) {
|
2020-05-11 16:01:21 +08:00
|
|
|
offsetX = -(opts.width - splitList[0] * scale) / 2;
|
2020-05-11 15:29:25 +08:00
|
|
|
} else {
|
|
|
|
const dx = (opts.width - (splitList[i] - splitList[i - 1]) * scale) / 2; // 居中计算偏移值
|
|
|
|
offsetX = splitList[i - 1] * scale - dx;
|
|
|
|
}
|
2020-07-06 17:02:13 +08:00
|
|
|
const offset = opts.offsetList[i] || 0;
|
|
|
|
const param = { scaleRateX: scale, scaleRateY: scale, offsetX: offsetX, offsetY: -screenDifference - (offsetY * i) - offset };
|
|
|
|
screenList.push(param);
|
2020-05-11 17:36:21 +08:00
|
|
|
const rect = {x: 0, y: 0, width: Number(splitList[i]) + 5, height: opts.height};
|
2020-05-11 15:29:25 +08:00
|
|
|
rectList.push(rect);
|
2020-05-08 16:12:03 +08:00
|
|
|
}
|
2020-07-06 17:02:13 +08:00
|
|
|
this.$painter.updateTransform1(screenList, rectList);
|
2020-05-12 18:23:56 +08:00
|
|
|
}
|
2020-05-07 09:04:28 +08:00
|
|
|
|
2019-11-29 12:51:58 +08:00
|
|
|
setLevelVisible(list) {
|
|
|
|
this.$painter.setLevelVisible(list);
|
|
|
|
}
|
|
|
|
|
2021-02-02 16:40:58 +08:00
|
|
|
render(list = []) {
|
|
|
|
list.forEach(elem => {
|
2019-11-29 12:51:58 +08:00
|
|
|
const code = elem.code;
|
|
|
|
const type = elem._type;
|
2020-06-30 16:20:51 +08:00
|
|
|
const oDevice = deviceFactory(type, elem, this.showConfig);
|
2021-02-26 16:23:16 +08:00
|
|
|
|
2020-06-30 16:20:51 +08:00
|
|
|
if (this.mapDevice[code]) {
|
2020-09-04 17:21:34 +08:00
|
|
|
this.$painter.delete(this.mapDevice[code]);
|
2020-09-11 10:18:07 +08:00
|
|
|
delete this.mapDevice[code];
|
2020-06-30 16:20:51 +08:00
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
if (!elem._dispose) {
|
2020-09-04 17:21:34 +08:00
|
|
|
this.mapDevice[code] = deepAssign(this.mapDevice[code] || {}, oDevice);
|
|
|
|
this.$painter.add(this.mapDevice[code]);
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-03 16:15:02 +08:00
|
|
|
const prdType2ShowMode = { '01': '03', '02': '02'};
|
|
|
|
const showMode = prdType2ShowMode[this.showConfig.prdType];
|
|
|
|
const stationCode = this.stationCode;
|
2021-02-25 11:18:59 +08:00
|
|
|
|
2021-02-26 16:23:16 +08:00
|
|
|
this.updateShowMode(list, showMode);
|
|
|
|
this.updateShowStation(list, stationCode);
|
2021-02-25 11:18:59 +08:00
|
|
|
|
2021-03-03 16:15:02 +08:00
|
|
|
if (this.methods.viewUpdate instanceof Function) { this.methods.viewUpdate(list); }
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 中间处理
|
|
|
|
hookHandle(oDevice, elem) {
|
2020-02-11 14:50:56 +08:00
|
|
|
// 老数据 新数据
|
2019-11-29 12:51:58 +08:00
|
|
|
const code = elem.code;
|
|
|
|
const type = elem._type;
|
|
|
|
// 如果是延时计时,需要保存计数值到全局
|
|
|
|
if (type === deviceType.StationCounter) {
|
|
|
|
let val = '' + elem.val;
|
|
|
|
if (val === '0' || !elem.val) {
|
|
|
|
val = elem.val = localStore.get(code) || '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
localStore(code, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var prop in elem) {
|
|
|
|
if (oDevice[prop] != elem[prop]) {
|
2020-02-11 14:50:56 +08:00
|
|
|
deepAssign(oDevice, elem); // 更新状态
|
2019-11-29 12:51:58 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2021-02-18 16:58:35 +08:00
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2021-02-18 16:58:35 +08:00
|
|
|
setUpdateMapDevice(list = [], fetch = true) {
|
|
|
|
if (fetch) {
|
|
|
|
store.commit('map/updateMapDevice', list);
|
|
|
|
}
|
2021-02-05 18:01:16 +08:00
|
|
|
|
2021-02-02 16:40:58 +08:00
|
|
|
list.forEach(elem => {
|
2020-02-29 00:04:24 +08:00
|
|
|
const code = elem.code;
|
|
|
|
const type = elem._type;
|
|
|
|
const oDevice = this.mapDevice[code] || deviceFactory(type, elem);
|
2020-03-11 10:53:09 +08:00
|
|
|
this.hookHandle(oDevice, elem);
|
2020-02-29 00:04:24 +08:00
|
|
|
});
|
2020-07-27 14:11:43 +08:00
|
|
|
}
|
2020-03-11 15:10:08 +08:00
|
|
|
getShowConfig() {
|
|
|
|
return this.showConfig;
|
|
|
|
}
|
2020-03-13 13:01:58 +08:00
|
|
|
showStationHandlePsd(oDevice, stationCode) {
|
|
|
|
const standDevice = this.mapDevice[oDevice.standCode];
|
2020-04-17 16:39:42 +08:00
|
|
|
if (standDevice && standDevice.deviceStationCode === stationCode || !stationCode) {
|
2020-03-13 13:01:58 +08:00
|
|
|
this.$painter.updateSpecialShowStation(oDevice, true);
|
|
|
|
} else {
|
|
|
|
this.$painter.updateSpecialShowStation(oDevice, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
showStationHandleSection(oDevice, stationCode) {
|
|
|
|
const trainWinDevice = this.mapDevice[oDevice.trainWindowCode];
|
|
|
|
if (oDevice.stationCode === stationCode || !stationCode) {
|
|
|
|
this.$painter.updateSpecialShowStation(trainWinDevice, true);
|
|
|
|
} else {
|
|
|
|
this.$painter.updateSpecialShowStation(trainWinDevice, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
showStationHandleStation (oDevice, stationCode) {
|
|
|
|
if ((oDevice.centralized && oDevice.code === stationCode) || !stationCode) {
|
|
|
|
this.$painter.updateSpecialShowStation(oDevice, true);
|
|
|
|
oDevice.chargeStationCodeList.forEach(staCode => {
|
|
|
|
const staDevice = this.mapDevice[staCode];
|
|
|
|
this.$painter.updateSpecialShowStation(staDevice, true);
|
|
|
|
});
|
|
|
|
} else if (oDevice.centralized && oDevice.code !== stationCode) {
|
|
|
|
this.$painter.updateSpecialShowStation(oDevice, false);
|
|
|
|
oDevice.chargeStationCodeList.forEach(staCode => {
|
|
|
|
const staDevice = this.mapDevice[staCode];
|
|
|
|
this.$painter.updateSpecialShowStation(staDevice, false);
|
|
|
|
});
|
|
|
|
}
|
2021-02-26 16:23:16 +08:00
|
|
|
}
|
2021-03-03 16:15:02 +08:00
|
|
|
updateShowStation(list = [], stationCode = '') {
|
2021-02-26 16:23:16 +08:00
|
|
|
this.stationCode = stationCode;
|
|
|
|
|
|
|
|
store.dispatch('map/setShowCentralizedStationCode', stationCode);
|
|
|
|
list.forEach(elem => {
|
|
|
|
const code = elem.code;
|
|
|
|
const type = elem._type;
|
|
|
|
const oDevice = this.mapDevice[code] || deviceFactory(type, elem, this.showConfig);
|
|
|
|
if (oDevice._type === deviceType.Station) {
|
|
|
|
this.showStationHandleStation(oDevice, stationCode);
|
|
|
|
} else if (oDevice._type === deviceType.Section) {
|
|
|
|
this.$painter.updateShowStation(oDevice, stationCode);
|
|
|
|
this.showStationHandleSection(oDevice, stationCode);
|
|
|
|
} else if (oDevice._type === deviceType.TrainWindow) {
|
|
|
|
// 不处理车次窗 勿删
|
|
|
|
} else if (oDevice._type === deviceType.Psd) {
|
|
|
|
this.showStationHandlePsd(oDevice, stationCode);
|
|
|
|
} else {
|
|
|
|
this.$painter.updateShowStation(oDevice, stationCode);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.$painter.$transformHandle.revisibleAll();
|
|
|
|
if (stationCode) {
|
|
|
|
this.$painter.$transformHandle.setFoldLines(store.state.map.foldLineMap[stationCode]);
|
|
|
|
} else {
|
|
|
|
this.$painter.$transformHandle.setFoldLines([]);
|
|
|
|
}
|
2020-03-13 13:01:58 +08:00
|
|
|
}
|
2021-03-03 16:15:02 +08:00
|
|
|
// 模式选择 -> 更新
|
|
|
|
updateShowMode(list = [], showMode = '03') {
|
|
|
|
this.showConfig.showMode = showMode;
|
|
|
|
list.forEach(elem => {
|
|
|
|
const code = elem.code;
|
|
|
|
const type = elem._type;
|
|
|
|
const oDevice = this.mapDevice[code] || deviceFactory(type, elem, this.showConfig);
|
|
|
|
oDevice.showMode = showMode;
|
|
|
|
this.$painter.updateShowMode(oDevice);
|
|
|
|
});
|
|
|
|
this.$painter.$transformHandle.revisibleAll();
|
|
|
|
}
|
2021-03-08 16:20:29 +08:00
|
|
|
// updatePrdType(list = [], showMode = '03', val = '') {
|
|
|
|
// this.showConfig.prdType = val;
|
|
|
|
// this.showConfig.showMode = showMode;
|
|
|
|
// list.forEach(item => {
|
|
|
|
// const code = item.code;
|
|
|
|
// const type = item._type;
|
|
|
|
// const oDevice = this.mapDevice[code] || deviceFactory(type, item, this.showConfig);
|
|
|
|
// this.hookHandle(oDevice, this.showConfig);
|
|
|
|
// this.$painter.update(oDevice);
|
|
|
|
// this.$painter.updateShowMode(oDevice);
|
|
|
|
// });
|
|
|
|
// }
|
2021-02-18 16:58:35 +08:00
|
|
|
update(list = [], fetch = true) {
|
|
|
|
this.setUpdateMapDevice(list, fetch); // 增加一个 前数据 处理 为了在区段中 获取全部的 道岔信息
|
2021-02-05 18:01:16 +08:00
|
|
|
|
2021-02-18 16:58:35 +08:00
|
|
|
const codeList = [];
|
2020-08-07 17:13:12 +08:00
|
|
|
const controlTransferList = [];
|
2021-02-18 16:58:35 +08:00
|
|
|
const signalDeviceList = [];
|
|
|
|
const selected = store.state.menuOperation.selected;
|
2021-01-29 18:37:10 +08:00
|
|
|
|
2021-02-02 16:40:58 +08:00
|
|
|
list.forEach((elem, index) => {
|
2019-11-29 12:51:58 +08:00
|
|
|
const code = elem.code;
|
2021-02-18 16:58:35 +08:00
|
|
|
const type = elem._type;
|
2021-02-02 16:40:58 +08:00
|
|
|
|
2020-06-11 17:06:29 +08:00
|
|
|
if (elem.deviceType === 'ROUTE' && this.logicData.routeData) { // 处理进路数据状态
|
2020-02-14 18:07:54 +08:00
|
|
|
store.dispatch('map/updateRouteState', elem);
|
2020-03-20 14:12:02 +08:00
|
|
|
const route = this.logicData.routeData[code];
|
2020-03-19 10:23:24 +08:00
|
|
|
if (route.automaticRouteCode) {
|
|
|
|
const automaticRoute = this.mapDevice[route.automaticRouteCode];
|
|
|
|
const automaticRouteStatus = {fleetMode: elem.fleetMode};
|
|
|
|
if (this.hookHandle(automaticRoute, automaticRouteStatus)) {
|
|
|
|
this.$painter.update(automaticRoute);
|
|
|
|
}
|
|
|
|
}
|
2020-02-14 18:07:54 +08:00
|
|
|
const signalDevice = this.mapDevice[route.startSignalCode];
|
2020-04-09 14:47:44 +08:00
|
|
|
const index = signalDeviceList.indexOf(signalDevice);
|
|
|
|
if (index === -1) {
|
|
|
|
signalDeviceList.push(signalDevice);
|
2020-02-14 18:07:54 +08:00
|
|
|
}
|
2020-08-13 19:27:02 +08:00
|
|
|
} else if (elem.deviceType == 'OVERLAP') {
|
2020-08-14 10:49:11 +08:00
|
|
|
const overlapRoute = this.mapDevice[elem.code];
|
2020-08-13 19:27:02 +08:00
|
|
|
const model = this.mapDevice[overlapRoute.pathList[0].sectionList[0]];
|
2020-08-14 10:49:11 +08:00
|
|
|
if (overlapRoute.pathList[0].right) {
|
|
|
|
overlapRoute['points'] = { x: model.points[0].x, y: model.points[0].y };
|
|
|
|
} else {
|
|
|
|
overlapRoute['points'] = { x: model.points[model.points.length - 1].x, y: model.points[model.points.length - 1].y };
|
|
|
|
}
|
2020-08-14 13:17:29 +08:00
|
|
|
overlapRoute['offsetRight'] = overlapRoute.pathList[0].right;
|
2020-08-17 16:48:19 +08:00
|
|
|
overlapRoute['sectionName'] = model.name;
|
2020-08-14 10:49:11 +08:00
|
|
|
this.$painter.update(overlapRoute);
|
2020-03-20 14:12:02 +08:00
|
|
|
} else if (elem.deviceType === 'CYCLE') {
|
|
|
|
store.dispatch('map/updateAutoReentryState', elem);
|
|
|
|
const autoReentryData = this.logicData.autoReentryData[code];
|
|
|
|
const cycleButton = this.mapDevice[autoReentryData.cycleButtonCode];
|
|
|
|
const cycleButtonStatus = {setUp: elem.setUp};
|
|
|
|
if (cycleButton && this.hookHandle(cycleButton, cycleButtonStatus)) {
|
|
|
|
this.$painter.update(cycleButton);
|
|
|
|
}
|
|
|
|
} else if (elem.deviceType === 'STATION') {
|
2020-08-06 19:34:13 +08:00
|
|
|
// 如果是控制权转移消息
|
2020-08-13 16:45:27 +08:00
|
|
|
if (elem.hasOwnProperty('applicantId')) {
|
2020-08-07 17:13:12 +08:00
|
|
|
controlTransferList.push(elem);
|
2020-08-07 13:17:09 +08:00
|
|
|
}
|
2020-08-13 16:45:27 +08:00
|
|
|
if (!elem.applicantId) {
|
2020-08-06 19:34:13 +08:00
|
|
|
const oDevice = this.mapDevice[code] || deviceFactory(type, elem, this.showConfig);
|
|
|
|
const guideLock = this.mapDevice[oDevice.guideLockCode];
|
|
|
|
const guideLockStatus = {totalGuideLock: elem.totalGuideLock};
|
|
|
|
if (guideLock && this.hookHandle(guideLock, guideLockStatus)) {
|
|
|
|
this.$painter.update(guideLock);
|
|
|
|
}
|
|
|
|
if (elem.dispose) {
|
|
|
|
this.$painter.delete(oDevice);
|
|
|
|
} else {
|
|
|
|
this.$painter.update(oDevice);
|
2021-01-20 15:53:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
store.commit('map/mapStationStateUpdate');
|
2019-11-29 12:51:58 +08:00
|
|
|
} else {
|
2021-02-18 16:58:35 +08:00
|
|
|
if (elem.deviceType === 'TRAIN') {
|
2020-06-17 15:31:15 +08:00
|
|
|
this.isUpdateShowTrainList = true;
|
2021-03-03 16:15:02 +08:00
|
|
|
if (elem.destinationCode) { this.isUpdateRunLineTrain = true; }
|
2020-10-27 16:51:57 +08:00
|
|
|
store.commit('map/updateActiveTrainList', elem);
|
2020-05-22 18:41:23 +08:00
|
|
|
} else if (elem.deviceType === 'STAND') {
|
|
|
|
store.dispatch('map/updateStationStand', elem);
|
2020-07-03 13:55:04 +08:00
|
|
|
const psdDevice = this.mapDevice[this.mapDevice[elem.code].psdCode];
|
|
|
|
if (psdDevice) {
|
|
|
|
psdDevice.fault = elem.fault;
|
|
|
|
this.$painter.update(psdDevice);
|
|
|
|
}
|
2021-02-02 16:40:58 +08:00
|
|
|
} else if (elem.deviceType == 'SWITCH') {
|
2021-02-18 16:58:35 +08:00
|
|
|
const oDevice = this.mapDevice[code];
|
|
|
|
if (oDevice) {
|
|
|
|
const sectionA = this.mapDevice[oDevice.sectionACode];
|
|
|
|
const sectionB = this.mapDevice[oDevice.sectionBCode];
|
|
|
|
const sectionC = this.mapDevice[oDevice.sectionCCode];
|
|
|
|
if (sectionA && sectionB && sectionC) {
|
|
|
|
oDevice['cutOff'] = sectionA.cutOff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$painter.update(oDevice);
|
|
|
|
} else if (elem.deviceType == 'SECTION') {
|
|
|
|
const oDevice = this.mapDevice[code];
|
|
|
|
if (oDevice) {
|
|
|
|
const sDevice = this.mapDevice[oDevice.relSwitchCode];
|
|
|
|
if (sDevice) {
|
|
|
|
const sectionA = this.mapDevice[sDevice.sectionACode];
|
|
|
|
const sectionB = this.mapDevice[sDevice.sectionBCode];
|
|
|
|
const sectionC = this.mapDevice[sDevice.sectionCCode];
|
|
|
|
if (sectionA && sectionB && sectionC) {
|
|
|
|
sDevice['cutOff'] = sectionA.cutOff;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$painter.update(sDevice);
|
|
|
|
codeList.push(sDevice.code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (elem.deviceType === 'DIRECTION_ROD' && elem.uniqueCode) {
|
2020-10-12 17:55:57 +08:00
|
|
|
store.state.map.map.directionRodList.forEach(item => {
|
2020-10-15 14:17:55 +08:00
|
|
|
if (elem.uniqueCode === item.uniqueCode) {
|
2020-10-14 14:27:52 +08:00
|
|
|
const updateRod = this.mapDevice[item.code];
|
|
|
|
updateRod.reversed = elem.reversed;
|
|
|
|
this.$painter.update(updateRod);
|
2020-10-12 16:21:24 +08:00
|
|
|
}
|
|
|
|
});
|
2021-02-18 16:58:35 +08:00
|
|
|
}
|
2021-02-02 16:40:58 +08:00
|
|
|
|
2021-02-18 16:58:35 +08:00
|
|
|
const oDevice = this.mapDevice[code] || deviceFactory(type, elem, this.showConfig);
|
2021-03-02 15:06:40 +08:00
|
|
|
|
2020-02-14 18:07:54 +08:00
|
|
|
if (elem.dispose) {
|
|
|
|
this.$painter.delete(oDevice);
|
|
|
|
} else {
|
2020-03-11 10:53:09 +08:00
|
|
|
this.$painter.update(oDevice);
|
2021-02-18 16:58:35 +08:00
|
|
|
}
|
|
|
|
}
|
2021-01-29 18:37:10 +08:00
|
|
|
|
2021-02-18 16:58:35 +08:00
|
|
|
codeList.push(code);
|
2019-11-29 12:51:58 +08:00
|
|
|
});
|
2020-08-07 17:13:12 +08:00
|
|
|
|
|
|
|
if (controlTransferList.length > 0) {
|
|
|
|
store.dispatch('map/setControlTransfer', controlTransferList);
|
|
|
|
}
|
|
|
|
|
2020-06-17 15:31:15 +08:00
|
|
|
if (this.isUpdateShowTrainList) {
|
|
|
|
store.dispatch('map/setActiveTrainList');
|
|
|
|
this.isUpdateShowTrainList = false;
|
2021-02-18 16:58:35 +08:00
|
|
|
}
|
2021-03-03 16:15:02 +08:00
|
|
|
if (this.isUpdateRunLineTrain) {
|
|
|
|
store.dispatch('map/setRunLineTrain');
|
|
|
|
this.isUpdateRunLineTrain = false;
|
|
|
|
}
|
2021-02-02 16:40:58 +08:00
|
|
|
|
2021-02-18 16:58:35 +08:00
|
|
|
if (selected && codeList.includes(selected.code)) {
|
|
|
|
store.commit('menuOperation/setSelected', {device: {...selected}});
|
|
|
|
}
|
2021-02-02 16:40:58 +08:00
|
|
|
|
2020-05-27 18:35:05 +08:00
|
|
|
this.handleRouteSignalStatus(signalDeviceList);
|
2019-11-29 12:51:58 +08:00
|
|
|
|
|
|
|
if (this.methods.stateUpdate instanceof Function) { this.methods.stateUpdate(list); }
|
|
|
|
}
|
2020-05-27 18:35:05 +08:00
|
|
|
handleRouteSignalStatus(signalDeviceList) {
|
|
|
|
const routeStartSignalData = store.state.map.routeStartSignalData;
|
2020-04-09 14:47:44 +08:00
|
|
|
signalDeviceList.forEach((item, index)=> {
|
2020-05-27 18:35:05 +08:00
|
|
|
const status = {};
|
|
|
|
if (routeStartSignalData[item.code] && routeStartSignalData[item.code].length) {
|
|
|
|
routeStartSignalData[item.code].forEach((elem, index)=> {
|
|
|
|
if (index) {
|
|
|
|
status.atsControl = status.atsControl && elem.atsControl;
|
|
|
|
status.fleetMode = status.fleetMode || elem.fleetMode;
|
2020-06-19 09:17:03 +08:00
|
|
|
status.ciControl = status.ciControl || elem.ciControl;
|
2021-01-29 15:01:38 +08:00
|
|
|
status.lock = status.lock || elem.lock;
|
2020-05-27 18:35:05 +08:00
|
|
|
} else {
|
|
|
|
status.atsControl = elem.atsControl;
|
|
|
|
status.fleetMode = elem.fleetMode;
|
2020-06-09 18:40:48 +08:00
|
|
|
status.ciControl = elem.ciControl;
|
2021-01-29 15:01:38 +08:00
|
|
|
status.lock = elem.lock;
|
2020-05-27 18:35:05 +08:00
|
|
|
}
|
2020-06-19 09:17:03 +08:00
|
|
|
status.canSetCi = status.arc || elem.arc;
|
2020-05-27 18:35:05 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if (item && this.hookHandle(item, status)) {
|
2020-04-09 14:47:44 +08:00
|
|
|
this.$painter.update(item);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
pullBack(payload) {
|
|
|
|
if (payload.type === 'zoom') {
|
|
|
|
const zrWidth = this.$zr.getWidth();
|
|
|
|
const zrHeight = this.$zr.getHeight();
|
|
|
|
const originX = payload.originX || zrWidth / 2;
|
|
|
|
const originY = payload.originY || zrHeight / 2;
|
2021-02-26 16:23:16 +08:00
|
|
|
|
2021-03-03 16:15:02 +08:00
|
|
|
const x = (this.$options.offsetX + originX) / this.$options.scaleRate;
|
2019-11-29 12:51:58 +08:00
|
|
|
const y = (this.$options.offsetY + originY) / this.$options.scaleRate;
|
|
|
|
const newScaleRate = this.$options.getScaleRate(payload.scale);
|
|
|
|
const dx = originX - (x * newScaleRate - this.$options.offsetX);
|
|
|
|
const dy = originY - (y * newScaleRate - this.$options.offsetY);
|
2021-02-26 16:23:16 +08:00
|
|
|
|
2019-11-29 12:51:58 +08:00
|
|
|
payload.dx = dx;
|
|
|
|
payload.dy = dy;
|
|
|
|
}
|
|
|
|
|
|
|
|
return payload || {};
|
|
|
|
}
|
|
|
|
|
|
|
|
getZr() {
|
|
|
|
return this.$zr;
|
|
|
|
}
|
|
|
|
|
|
|
|
getEvents() {
|
|
|
|
return this.events;
|
|
|
|
}
|
|
|
|
|
|
|
|
getDeviceByCode(code) {
|
|
|
|
return this.mapDevice[code];
|
|
|
|
}
|
|
|
|
|
|
|
|
getShapeTipPoint(opts) {
|
2021-02-24 18:52:38 +08:00
|
|
|
const device = adapter.adapterByDevice(this.mapDevice[opts.code], this.mapDevice);
|
2019-11-29 12:51:58 +08:00
|
|
|
if (device) {
|
2021-03-03 16:15:02 +08:00
|
|
|
return this.$painter.getShapeTipPoint(device.instance, opts);
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resize(opt) {
|
|
|
|
this.$zr.resize(opt);
|
2020-11-24 16:53:13 +08:00
|
|
|
opt.isUpdate = false;
|
2019-11-29 12:51:58 +08:00
|
|
|
this.$painter.updateZrSize(opt);
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh() {
|
|
|
|
this.$painter.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
clearTrainView() {
|
|
|
|
this.$painter.clearLevel(deviceType.Train);
|
|
|
|
zrUtil.each(Object.values(this.mapDevice), device => {
|
|
|
|
if (device._type == deviceType.Train) {
|
|
|
|
device.instance = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-03 16:15:02 +08:00
|
|
|
clearEvent() {
|
|
|
|
this.$zr.curEvent = null;
|
|
|
|
}
|
2021-02-20 18:23:26 +08:00
|
|
|
|
2019-11-29 12:51:58 +08:00
|
|
|
clear() {
|
|
|
|
this.lineCode = '';
|
|
|
|
this.style = {};
|
|
|
|
this.mapDevice = {};
|
|
|
|
this.$painter.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
dispose() {
|
|
|
|
this.off(this.events.Pan, this.optionsHandler);
|
|
|
|
this.off(this.events.Zoom, this.optionsHandler);
|
|
|
|
|
2020-11-24 16:53:13 +08:00
|
|
|
// this.clear();
|
2019-11-29 12:51:58 +08:00
|
|
|
|
|
|
|
this.$mouseController.dispose();
|
|
|
|
this.$keyboardController.dispose();
|
|
|
|
this.$zr && zrender.dispose(this.$zr);
|
|
|
|
this.$painter.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
on(eventname, cb, context) {
|
|
|
|
const idx = Object.values(this.events).indexOf(eventname);
|
|
|
|
if (idx >= 0) {
|
|
|
|
switch (eventname) {
|
|
|
|
case this.events.Selected:
|
|
|
|
this.$mouseController.on(this.events.Selected, cb, context);
|
|
|
|
break;
|
|
|
|
case this.events.Contextmenu:
|
|
|
|
this.$mouseController.on(this.events.Contextmenu, cb, context);
|
|
|
|
break;
|
|
|
|
case this.events.DataZoom:
|
|
|
|
this.$mouseController.on(this.events.DataZoom, cb, context);
|
|
|
|
break;
|
|
|
|
case this.events.Keyboard:
|
|
|
|
this.$keyboardController.on(this.events.Keyboard, cb, context);
|
2020-05-06 16:57:07 +08:00
|
|
|
break;
|
2020-05-13 15:31:12 +08:00
|
|
|
case this.events.__Pan:
|
|
|
|
this.$mouseController.on(this.events.__Pan, this.optionsHandler);
|
|
|
|
break;
|
|
|
|
case this.events.__Zoom:
|
|
|
|
this.$mouseController.on(this.events.__Zoom, this.optionsHandler);
|
2021-01-20 15:53:13 +08:00
|
|
|
break;
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
off(eventname, cb) {
|
2020-05-06 17:18:06 +08:00
|
|
|
const idx = Object.values(this.events).indexOf(eventname);
|
2019-11-29 12:51:58 +08:00
|
|
|
if (idx >= 0) {
|
|
|
|
switch (eventname) {
|
|
|
|
case this.events.Selected:
|
|
|
|
this.$mouseController.off(this.events.Selected, cb);
|
|
|
|
break;
|
|
|
|
case this.events.Contextmenu:
|
|
|
|
this.$mouseController.off(this.events.Contextmenu, cb);
|
|
|
|
break;
|
|
|
|
case this.events.DataZoom:
|
|
|
|
this.$mouseController.off(this.events.DataZoom, cb);
|
|
|
|
break;
|
|
|
|
case this.events.Keyboard:
|
|
|
|
this.$keyboardController.off(this.events.keyboard, cb);
|
|
|
|
break;
|
2020-05-06 16:57:07 +08:00
|
|
|
case this.events.__Pan:
|
2020-05-06 17:18:06 +08:00
|
|
|
this.$mouseController.off(this.events.__Pan, cb);
|
|
|
|
break;
|
|
|
|
case this.events.__Zoom:
|
|
|
|
this.$mouseController.off(this.events.__Zoom, cb);
|
2020-05-06 16:57:07 +08:00
|
|
|
break;
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderCheckBox(model) {
|
|
|
|
const type = model._type;
|
|
|
|
const code = model.code;
|
|
|
|
const oDevice = this.mapDevice[code] || deviceFactory(type, model);
|
|
|
|
const nDevice = deviceFactory(type, Object.assign(oDevice.model || {}, model));
|
|
|
|
delete this.mapDevice[code];
|
|
|
|
this.$painter.delete(oDevice);
|
|
|
|
if (!model._dispose) {
|
|
|
|
this.mapDevice[code] = nDevice;
|
|
|
|
this.$painter.add(nDevice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
deleteCheckBox(code) {
|
|
|
|
const oDevice = this.mapDevice[code];
|
|
|
|
if (oDevice) {
|
|
|
|
delete this.mapDevice[code];
|
|
|
|
this.$painter.delete(oDevice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Jlmap;
|