2019-11-29 12:51:58 +08:00
|
|
|
<template>
|
2020-01-15 10:29:30 +08:00
|
|
|
<div class="jlmap-canvas" :style="{ width: width+'px', height: height+'px' }" @mousemove="mousemove">
|
2020-01-07 10:52:44 +08:00
|
|
|
<div v-show="maskOpen" class="mask" />
|
2019-12-30 14:06:42 +08:00
|
|
|
<div :id="canvasId" style="background: #000;" class="display_canvas" />
|
2019-11-29 12:51:58 +08:00
|
|
|
<progress-bar ref="progressBar" />
|
|
|
|
<zoom-box v-if="!isScreen" :scale-rate="dataZoom.scaleRate" @setShrink="setShrink" @setMagnify="setMagnify" />
|
|
|
|
<div v-if="show" class="zoom-view" :style="{ width: width +'px'}">
|
2019-12-10 16:09:45 +08:00
|
|
|
<el-form :model="dataZoom" label-width="80px" size="mini" inline>
|
2019-11-29 12:51:58 +08:00
|
|
|
<el-form-item :label="$t(`global.offset`)">
|
2019-12-10 16:09:45 +08:00
|
|
|
<el-input v-model="dataZoom.offsetX" :disabled="true" style="width: 95px" />
|
2019-11-29 12:51:58 +08:00
|
|
|
</el-form-item>
|
|
|
|
<el-form-item>
|
2019-12-10 16:09:45 +08:00
|
|
|
<el-input v-model="dataZoom.offsetY" :disabled="true" style="width: 95px" />
|
2019-12-10 15:44:46 +08:00
|
|
|
</el-form-item>
|
2019-12-10 16:09:45 +08:00
|
|
|
<div style="display: inline-block">
|
|
|
|
<span class="title" style="">鼠标偏移:</span>
|
|
|
|
<el-form-item label="x" label-width="12px">
|
|
|
|
<el-input v-model="offset.x" :disabled="true" style="width: 95px" />
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="y" label-width="12px">
|
|
|
|
<el-input v-model="offset.y" :disabled="true" style="width: 95px" />
|
|
|
|
</el-form-item>
|
|
|
|
</div>
|
2019-11-29 12:51:58 +08:00
|
|
|
<el-form-item :label="$t(`global.zoom`)" style="float: right">
|
|
|
|
<el-input v-model="dataZoom.scaleRate" :disabled="true" />
|
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Vue from 'vue';
|
|
|
|
import localStore from 'storejs';
|
|
|
|
import Jlmap from '@/jmapNew/map';
|
|
|
|
import ZoomBox from './zoom/zoom';
|
|
|
|
import ProgressBar from '@/views/components/progressBar/index';
|
|
|
|
import { mapGetters } from 'vuex';
|
|
|
|
import { TrainingMode } from '@/scripts/ConstDic';
|
|
|
|
import { EventBus } from '@/scripts/event-bus';
|
2019-12-31 15:36:49 +08:00
|
|
|
import Theme from '@/jmapNew/theme/factory';
|
2019-11-29 12:51:58 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'JlmapVisual',
|
|
|
|
components: {
|
|
|
|
ZoomBox,
|
|
|
|
ProgressBar
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
loading: true,
|
|
|
|
dataZoom: {
|
|
|
|
offsetX: '0',
|
|
|
|
offsetY: '0',
|
|
|
|
scaleRate: '1'
|
|
|
|
},
|
2019-12-10 16:09:45 +08:00
|
|
|
offset: {
|
|
|
|
x: 0,
|
|
|
|
y: 0
|
|
|
|
},
|
2019-11-29 12:51:58 +08:00
|
|
|
sectionActive: false,
|
|
|
|
operate: null
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters('training', [
|
|
|
|
'mode',
|
|
|
|
'offsetStationCode'
|
|
|
|
]),
|
|
|
|
canvasId() {
|
|
|
|
const canvasId = ['map', (Math.random().toFixed(5)) * 100000].join('_');
|
|
|
|
this.$store.dispatch('config/setCurrentCancasId', { id: canvasId });
|
|
|
|
return canvasId;
|
|
|
|
},
|
|
|
|
width() {
|
|
|
|
return this.$store.state.config.width;
|
|
|
|
},
|
|
|
|
height() {
|
|
|
|
return this.$store.state.config.height;
|
|
|
|
},
|
|
|
|
show() {
|
|
|
|
if (this.mode == TrainingMode.EDIT || this.mode == TrainingMode.MAP_EDIT) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
isScreen() {
|
|
|
|
return this.$route.params.mode == 'dp' || this.$store.state.training.roles == 'BigScreen';
|
2020-01-07 10:52:44 +08:00
|
|
|
},
|
|
|
|
maskOpen() {
|
|
|
|
return this.$store.state.config.maskOpen;
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
'$store.state.map.map': function (val, old) {
|
|
|
|
try {
|
|
|
|
if (val) {
|
|
|
|
this.setMap(val);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log('[ERROR] ', error);
|
|
|
|
this.mapViewLoaded(false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'$store.state.training.rezoomCount': function (val, old) {
|
|
|
|
this.setCenter(this.$store.state.training.offsetStationCode);
|
|
|
|
},
|
|
|
|
'$store.state.exam.deviceCode': function (val) {
|
|
|
|
val && this.setCenter(val);
|
|
|
|
},
|
|
|
|
'$store.state.config.canvasSizeCount': function (val) {
|
|
|
|
this.resetSize();
|
|
|
|
},
|
|
|
|
'$store.state.menuOperation.magnifyCount': function () {
|
|
|
|
this.setMagnify();
|
|
|
|
},
|
|
|
|
'$store.state.menuOperation.shrinkCount': function () {
|
|
|
|
this.setShrink();
|
|
|
|
},
|
|
|
|
$route() {
|
|
|
|
this.mapViewLoaded(true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
EventBus.$on('viewLoading', (loading) => {
|
|
|
|
this.mapViewLoaded(loading);
|
|
|
|
});
|
|
|
|
EventBus.$on('viewProgressAt', (percentage) => {
|
|
|
|
this.mapViewProgressAt(percentage);
|
|
|
|
});
|
|
|
|
EventBus.$on('refresh', () => {
|
|
|
|
this.refresh(this.$store.state.map.map);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.initLoadPage();
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
EventBus.$off('refresh');
|
|
|
|
EventBus.$off('viewLoading');
|
|
|
|
EventBus.$off('viewProgressAt');
|
|
|
|
this.$store.dispatch('map/mapClear');
|
|
|
|
if (this.$jlmap) {
|
|
|
|
this.$jlmap.dispose();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
// 初始化jlmap
|
|
|
|
initLoadPage() {
|
|
|
|
document.getElementById(this.canvasId).oncontextmenu = function (e) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
// 默认个人地图绘制可以滚轮放大缩小 其他地图显示不允许此操作
|
|
|
|
const path = window.location.href;
|
|
|
|
let mouseWheelFlag = false;
|
2019-12-03 18:13:44 +08:00
|
|
|
if (path.includes('design/userlist/map/draw') || path.includes('design/usermap/map/draw')) {
|
2019-11-29 12:51:58 +08:00
|
|
|
mouseWheelFlag = true;
|
|
|
|
}
|
|
|
|
|
2019-12-31 15:36:49 +08:00
|
|
|
Vue.prototype.$theme = new Theme();
|
2019-11-29 12:51:58 +08:00
|
|
|
Vue.prototype.$jlmap = new Jlmap({
|
|
|
|
dom: document.getElementById(this.canvasId),
|
|
|
|
config: {
|
|
|
|
renderer: 'canvas',
|
|
|
|
width: this.width,
|
|
|
|
height: this.height
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scaleRate: 1,
|
|
|
|
offsetX: 0,
|
|
|
|
offsetY: 0,
|
|
|
|
zoomOnMouseWheel: mouseWheelFlag
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
dataLoaded: this.handleDataLoaded,
|
|
|
|
viewLoaded: this.handleViewLoaded,
|
|
|
|
stateLoaded: this.handleStateLoaded
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$jlmap.on('dataZoom', this.onDataZoom, this);
|
|
|
|
this.$jlmap.on('selected', this.onSelected, this);
|
|
|
|
this.$jlmap.on('contextmenu', this.onContextMenu, this);
|
2019-12-06 10:11:29 +08:00
|
|
|
if (this.$route.path.startsWith('/design/usermap/map/draw')) {
|
|
|
|
this.$jlmap.on('keyboard', this.onKeyboard, this);
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
window.document.oncontextmenu = function () {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
// 重置jlmap宽高
|
|
|
|
resetSize() {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$jlmap && this.$jlmap.resize({ width: this.width, height: this.height });
|
|
|
|
|
|
|
|
this.$store.dispatch('training/updateOffsetStationCode', { offsetStationCode: this.offsetStationCode });
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
this.$store.dispatch('config/resetCanvasOffset');
|
|
|
|
this.$store.dispatch('training/emitTipFresh');
|
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
// 设置显示图层
|
|
|
|
setLevelVisible(levels) {
|
|
|
|
this.$jlmap && this.$jlmap.setLevelVisible(levels);
|
|
|
|
},
|
|
|
|
// 设置显示中心
|
|
|
|
setCenter(deviceCode) {
|
|
|
|
this.$jlmap && this.$jlmap.setCenter(deviceCode);
|
|
|
|
},
|
|
|
|
// 地图数据加载完成
|
|
|
|
handleDataLoaded() {
|
|
|
|
this.$store.dispatch('map/mapDataLoaded');
|
|
|
|
},
|
|
|
|
// 地图视图加载完成
|
|
|
|
handleViewLoaded() {
|
|
|
|
this.$store.dispatch('map/mapViewLoaded');
|
|
|
|
if (!this.$store.state.training.prdType) {
|
|
|
|
this.mapViewLoaded(false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 地图状态加载完成
|
|
|
|
handleStateLoaded() {
|
|
|
|
this.mapViewLoaded(false);
|
|
|
|
},
|
|
|
|
// 地图视图更新
|
|
|
|
handleViewUpdate() {
|
|
|
|
},
|
|
|
|
// 地图状态更新
|
|
|
|
handleStateUpdate() {
|
|
|
|
},
|
|
|
|
// 视图参数改变
|
|
|
|
handleOptionsUpdate(options) {
|
|
|
|
},
|
|
|
|
// 键盘快捷键事件
|
|
|
|
onKeyboard(hook) {
|
|
|
|
switch (hook) {
|
2019-12-06 10:05:14 +08:00
|
|
|
case 'Ctrl_Z': this.$store.dispatch('map/setRevocation');
|
2019-11-29 12:51:58 +08:00
|
|
|
break;
|
2019-12-06 10:05:14 +08:00
|
|
|
case 'Ctrl_Y': this.$store.dispatch('map/setRecover');
|
2019-11-29 12:51:58 +08:00
|
|
|
break;
|
2019-12-06 10:05:14 +08:00
|
|
|
case 'Delete': this.$store.dispatch('map/setDeleteCount');
|
2019-12-05 18:53:06 +08:00
|
|
|
break;
|
2019-12-06 15:12:22 +08:00
|
|
|
case 'Update': this.$store.dispatch('map/setUpdateCount');
|
|
|
|
break;
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// 视图缩放事件
|
|
|
|
onDataZoom(dataZoom) {
|
|
|
|
this.dataZoom.offsetX = dataZoom.offsetX.toFixed(1) + '';
|
|
|
|
this.dataZoom.offsetY = dataZoom.offsetY.toFixed(1) + '';
|
|
|
|
this.dataZoom.scaleRate = dataZoom.scaleRate + '';
|
2019-12-10 16:09:45 +08:00
|
|
|
this.offset.x = this.dataZoom.offsetX;
|
|
|
|
this.offset.y = this.dataZoom.offsetY;
|
2019-11-29 12:51:58 +08:00
|
|
|
|
|
|
|
const lineCode = this.$store.getters['map/lineCode'];
|
|
|
|
if (lineCode) {
|
|
|
|
const param = {
|
|
|
|
scaleRate: this.dataZoom.scaleRate,
|
|
|
|
offsetY: this.dataZoom.offsetY,
|
|
|
|
offsetX: this.dataZoom.offsetX,
|
|
|
|
lineCode: lineCode
|
|
|
|
};
|
|
|
|
this.$store.dispatch('map/updateZoom', this.dataZoom);
|
|
|
|
localStore.set(`scaleRate_${lineCode}`, JSON.stringify(param)); // 保存缩放倍数
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$store.dispatch('training/emitTipFresh');
|
|
|
|
},
|
|
|
|
// 点击选择事件
|
|
|
|
onSelected(em) {
|
|
|
|
this.$emit('onSelect', em);
|
|
|
|
},
|
|
|
|
// 右键点击事件
|
|
|
|
onContextMenu(em) {
|
|
|
|
this.$emit('onMenu', em);
|
|
|
|
},
|
|
|
|
// 设置地图加载状态
|
|
|
|
mapViewLoaded(loading) {
|
|
|
|
this.loading = loading;
|
|
|
|
if (loading) {
|
|
|
|
this.$refs.progressBar && this.$refs.progressBar.start();
|
|
|
|
} else {
|
|
|
|
this.$refs.progressBar && this.$refs.progressBar.end(true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 设置地图加载进度
|
|
|
|
mapViewProgressAt(percentage) {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$refs.progressBar.progressAt(percentage);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
// 设置新的地图数据
|
|
|
|
setMap(map) {
|
2020-02-14 18:07:54 +08:00
|
|
|
this.$jlmap.setMap(map, this.$store.state.map.mapDevice, this.$store.state.map.routeData);
|
2019-11-29 12:51:58 +08:00
|
|
|
},
|
|
|
|
// 刷新地图数据
|
|
|
|
refresh(map) {
|
|
|
|
},
|
|
|
|
// 缩小
|
|
|
|
setShrink() {
|
|
|
|
this.$jlmap.setOptions({type: 'zoom', scale: -1});
|
|
|
|
},
|
|
|
|
// 放大
|
|
|
|
setMagnify() {
|
|
|
|
this.$jlmap.setOptions({type: 'zoom', scale: 1});
|
2019-12-10 16:09:45 +08:00
|
|
|
},
|
|
|
|
mousemove(e) {
|
|
|
|
this.offset = {
|
|
|
|
x: e.offsetX + Number(this.dataZoom.offsetX),
|
|
|
|
y: e.offsetY + Number(this.dataZoom.offsetY)
|
|
|
|
};
|
2019-12-30 14:06:42 +08:00
|
|
|
this.$store.dispatch('map/setMousemove');
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<style rel="stylesheet/scss" lang="scss" scoped>
|
2020-01-07 10:52:44 +08:00
|
|
|
.mask{
|
|
|
|
opacity: 0;
|
|
|
|
background: #000;
|
|
|
|
position: absolute;
|
|
|
|
left: 0;
|
|
|
|
top: 0;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
z-index: 9;
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
.jlmap-canvas {
|
|
|
|
position: relative;
|
|
|
|
-moz-user-select: none;
|
|
|
|
-o-user-select: none;
|
|
|
|
-khtml-user-select: none;
|
|
|
|
-webkit-user-select: none;
|
|
|
|
-ms-user-select: none;
|
|
|
|
user-select: none;
|
|
|
|
}
|
2019-12-10 16:09:45 +08:00
|
|
|
.title{
|
|
|
|
text-align: right;
|
|
|
|
font-size: 14px;
|
|
|
|
color: #606266;
|
|
|
|
line-height: 32px;
|
|
|
|
-webkit-box-sizing: border-box;
|
|
|
|
box-sizing: border-box;
|
|
|
|
font-weight: 700;
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
|
|
|
.zoom-view {
|
|
|
|
position: absolute;
|
|
|
|
bottom: 0;
|
|
|
|
background: #fff;
|
|
|
|
padding-top: 5px;
|
|
|
|
height: 42px;
|
|
|
|
border-bottom: 1px #f3f3f3 solid;
|
|
|
|
border-right: 1px #f3f3f3 solid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/deep/ {
|
|
|
|
.el-form.el-form--inline {
|
|
|
|
height: 28px !important;
|
|
|
|
line-height: 28px !important
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-loading-mask {
|
|
|
|
background-color: rgba(0, 0, 0, 0.3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|