2019-07-25 10:32:29 +08:00
|
|
|
<template>
|
2019-07-25 13:26:20 +08:00
|
|
|
<div class="jlmap-canvas" :style="{ width: width+'px', height: height+28+'px' }">
|
2019-07-25 13:35:58 +08:00
|
|
|
<div :id="canvasId" style="background: #000;" />
|
|
|
|
<progress-bar ref="progressBar" />
|
|
|
|
<zoom-box v-if="!isScreen" :scale-rate="dataZoom.scaleRate" @setShrink="setShrink" @setMagnify="setMagnify" />
|
2019-07-25 13:26:20 +08:00
|
|
|
<div v-if="show" class="zoom-view" :style="{ width: width +'px'}">
|
|
|
|
<el-form :model="dataZoom" label-width="60px" size="mini" inline>
|
|
|
|
<el-form-item label="偏移:">
|
2019-07-25 13:35:58 +08:00
|
|
|
<el-input v-model="dataZoom.offsetX" :disabled="true" />
|
2019-07-25 13:26:20 +08:00
|
|
|
</el-form-item>
|
|
|
|
<el-form-item>
|
2019-07-25 13:35:58 +08:00
|
|
|
<el-input v-model="dataZoom.offsetY" :disabled="true" />
|
2019-07-25 13:26:20 +08:00
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="缩放:" style="float: right">
|
2019-07-25 13:35:58 +08:00
|
|
|
<el-input v-model="dataZoom.scaleRate" :disabled="true" />
|
2019-07-25 13:26:20 +08:00
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
2019-07-25 10:32:29 +08:00
|
|
|
</div>
|
2019-07-25 13:26:20 +08:00
|
|
|
</div>
|
2019-07-25 10:32:29 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-07-25 13:26:20 +08:00
|
|
|
import Vue from 'vue';
|
|
|
|
import localStore from 'storejs';
|
|
|
|
import Jlmap from '@/jmap/map';
|
|
|
|
import ZoomBox from './zoom/zoom';
|
|
|
|
import ProgressBar from '@/views/components/progressBar/index';
|
|
|
|
import { mapGetters } from 'vuex';
|
|
|
|
import { TrainingMode } from '@/scripts/ConstDic';
|
2019-07-25 15:48:51 +08:00
|
|
|
// import { debuglog } from 'util';
|
2019-07-25 13:35:58 +08:00
|
|
|
// import { Loading } from 'element-ui';
|
2019-07-25 10:32:29 +08:00
|
|
|
|
2019-07-25 13:26:20 +08:00
|
|
|
export default {
|
|
|
|
name: 'JlmapVisual',
|
|
|
|
components: {
|
|
|
|
ZoomBox,
|
|
|
|
ProgressBar
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
width: this.$store.state.config.width,
|
|
|
|
height: this.$store.state.config.height,
|
|
|
|
loading: true,
|
|
|
|
dataZoom: {
|
|
|
|
offsetX: '0',
|
|
|
|
offsetY: '0',
|
|
|
|
scaleRate: '1'
|
|
|
|
},
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
show() {
|
|
|
|
if (this.mode === TrainingMode.EDIT || this.mode === TrainingMode.MAP_EDIT) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
isScreen() {
|
|
|
|
return this.$route.params.mode === 'dp';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
'$store.state.map.map': function (val, old) {
|
2019-07-25 14:03:26 +08:00
|
|
|
try {
|
|
|
|
this.setMap(val);
|
|
|
|
} catch (error) {
|
2019-07-26 10:38:57 +08:00
|
|
|
console.log(`[ERROR] ${error}`);
|
2019-07-25 13:26:20 +08:00
|
|
|
this.mapViewLoaded(false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'$store.state.training.rezoomCount': function (val, old) {
|
2019-07-25 15:44:23 +08:00
|
|
|
this.setCenter(this.$store.state.training.offsetStationCode);
|
2019-07-25 13:26:20 +08:00
|
|
|
},
|
|
|
|
'$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');
|
|
|
|
if (this.$jlmap) {
|
|
|
|
this.$jlmap.dispose();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
// 初始化jlmap
|
|
|
|
initLoadPage() {
|
2019-07-25 13:35:58 +08:00
|
|
|
document.getElementById(this.canvasId).oncontextmenu = function (e) {
|
2019-07-25 13:26:20 +08:00
|
|
|
return false;
|
|
|
|
};
|
2019-07-25 10:32:29 +08:00
|
|
|
|
2019-07-25 13:26:20 +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
|
|
|
|
},
|
|
|
|
methods: {
|
2019-07-25 18:25:04 +08:00
|
|
|
dataLoaded: this.handleDataLoaded,
|
|
|
|
viewLoaded: this.handleViewLoaded,
|
|
|
|
stateLoaded: this.handleStateLoaded,
|
|
|
|
viewUpdate: this.handleViewUpdate,
|
|
|
|
stateUpdate: this.handleStateUpdate,
|
|
|
|
optionsUpdate: this.handleOptionsUpdate
|
2019-07-25 13:26:20 +08:00
|
|
|
}
|
|
|
|
});
|
2019-07-25 10:32:29 +08:00
|
|
|
|
2019-07-25 18:25:04 +08:00
|
|
|
this.$jlmap.on('dataZoom', this.onDataZoom, this);
|
2019-07-25 13:26:20 +08:00
|
|
|
this.$jlmap.on('selected', this.onSelected, this);
|
|
|
|
this.$jlmap.on('contextmenu', this.onContextMenu, this);
|
2019-07-25 10:32:29 +08:00
|
|
|
|
2019-07-25 13:26:20 +08:00
|
|
|
window.document.oncontextmenu = function () {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
// 重置jlmap宽高
|
|
|
|
resetSize() {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.width = this.$store.state.config.width;
|
|
|
|
this.height = this.$store.state.config.height;
|
2019-07-25 10:32:29 +08:00
|
|
|
|
2019-07-25 13:26:20 +08:00
|
|
|
this.$jlmap && this.$jlmap.resize({ width: this.width, height: this.height });
|
2019-07-25 10:32:29 +08:00
|
|
|
|
2019-07-25 13:26:20 +08:00
|
|
|
this.$store.dispatch('training/updateOffsetStationCode', { offsetStationCode: this.offsetStationCode });
|
2019-07-25 10:32:29 +08:00
|
|
|
|
2019-07-25 13:26:20 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
this.$store.dispatch('config/resetCanvasOffset');
|
|
|
|
this.$store.dispatch('training/emitTipFresh');
|
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
},
|
2019-07-25 15:44:23 +08:00
|
|
|
// 设置显示图级
|
|
|
|
setLayerVisible(layer) {
|
2019-07-26 12:18:40 +08:00
|
|
|
this.$jlmap && this.$jlmap.setLayerVisible(layer);
|
2019-07-25 13:26:20 +08:00
|
|
|
},
|
2019-07-25 15:44:23 +08:00
|
|
|
// 设置显示图层
|
|
|
|
setLevelVisible(levels) {
|
2019-07-26 12:18:40 +08:00
|
|
|
this.$jlmap && this.$jlmap.setLevelVisible(levels);
|
2019-07-25 13:26:20 +08:00
|
|
|
},
|
|
|
|
// 设置显示中心
|
2019-07-25 15:44:23 +08:00
|
|
|
setCenter(deviceCode) {
|
2019-07-25 14:19:55 +08:00
|
|
|
this.$jlmap && this.$jlmap.setCenter(deviceCode);
|
2019-07-25 13:26:20 +08:00
|
|
|
},
|
2019-07-26 12:18:40 +08:00
|
|
|
// 地图数据加载完成
|
|
|
|
handleDataLoaded() {
|
2019-07-26 15:59:31 +08:00
|
|
|
this.$store.dispatch('map/mapDataLoaded');
|
2019-07-26 12:18:40 +08:00
|
|
|
console.log('dataloaded');
|
|
|
|
},
|
|
|
|
// 地图视图加载完成
|
|
|
|
handleViewLoaded() {
|
2019-07-25 18:25:04 +08:00
|
|
|
console.log('viewLoaded');
|
2019-07-26 15:59:31 +08:00
|
|
|
this.$store.dispatch('map/mapViewLoaded');
|
2019-07-26 12:18:40 +08:00
|
|
|
this.mapViewLoaded(false);
|
|
|
|
},
|
|
|
|
// 地图状态加载完成
|
|
|
|
handleStateLoaded() {
|
2019-07-25 18:25:04 +08:00
|
|
|
console.log('stateLoaded');
|
2019-07-26 12:18:40 +08:00
|
|
|
this.mapViewLoaded(false);
|
|
|
|
},
|
|
|
|
// 地图视图更新
|
|
|
|
handleViewUpdate() {
|
|
|
|
console.log('viewUpdate');
|
|
|
|
},
|
|
|
|
// 地图状态更新
|
|
|
|
handleStateUpdate() {
|
|
|
|
console.log('stateUpdate');
|
2019-07-25 18:25:04 +08:00
|
|
|
},
|
|
|
|
// 视图参数改变
|
|
|
|
handleOptionsUpdate(options) {
|
|
|
|
console.log('optionsUpdate');
|
|
|
|
},
|
|
|
|
// 视图缩放事假
|
2019-07-25 13:26:20 +08:00
|
|
|
onDataZoom(dataZoom) {
|
2019-07-25 13:35:58 +08:00
|
|
|
this.dataZoom.offsetX = dataZoom.offsetX.toFixed(1) + '';
|
|
|
|
this.dataZoom.offsetY = dataZoom.offsetY.toFixed(1) + '';
|
|
|
|
this.dataZoom.scaleRate = dataZoom.scaleRate + '';
|
2019-07-25 10:32:29 +08:00
|
|
|
|
2019-07-25 13:26:20 +08:00
|
|
|
const skinStyle = this.$store.state.map.map.skinStyle;
|
|
|
|
if (skinStyle) {
|
|
|
|
const param = {
|
|
|
|
scaleRate: this.dataZoom.scaleRate,
|
2019-07-26 12:18:40 +08:00
|
|
|
offsetY: this.dataZoom.offsetY,
|
2019-07-25 15:44:23 +08:00
|
|
|
skinCode: skinStyle
|
2019-07-25 13:26:20 +08:00
|
|
|
};
|
2019-07-25 10:32:29 +08:00
|
|
|
|
2019-07-25 13:26:20 +08:00
|
|
|
localStore.set(`scaleRate_${skinStyle}`, 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.start();
|
|
|
|
} else {
|
|
|
|
this.$refs.progressBar.end(true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 设置地图加载进度
|
|
|
|
mapViewProgressAt(percentage) {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$refs.progressBar.progressAt(percentage);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
// 设置新的地图数据
|
|
|
|
setMap(map) {
|
|
|
|
this.$jlmap.setMap(map);
|
|
|
|
},
|
|
|
|
// 刷新地图数据
|
|
|
|
refresh(map) {
|
|
|
|
},
|
|
|
|
// 新增设备
|
|
|
|
addOrUpdateDevices(devices) {
|
|
|
|
this.$jlmap.render(devices);
|
|
|
|
},
|
|
|
|
// 删除设备
|
|
|
|
deleteDevices(devices) {
|
|
|
|
this.$jlmap.render(devices);
|
|
|
|
},
|
|
|
|
// 缩小
|
|
|
|
setShrink() {
|
2019-07-25 18:25:04 +08:00
|
|
|
this.$jlmap.setOptions({scale: -1});
|
2019-07-25 13:26:20 +08:00
|
|
|
},
|
|
|
|
// 放大
|
|
|
|
setMagnify() {
|
2019-07-25 18:25:04 +08:00
|
|
|
this.$jlmap.setOptions({scale: 1});
|
2019-07-25 13:26:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2019-07-25 10:32:29 +08:00
|
|
|
</script>
|
|
|
|
<style rel="stylesheet/scss" lang="scss" scoped>
|
|
|
|
.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
.zoom-view {
|
|
|
|
position: fixed;
|
|
|
|
height: 28px;
|
|
|
|
}
|
|
|
|
|
|
|
|
/deep/ {
|
|
|
|
.el-form.el-form--inline {
|
|
|
|
height: 28px !important;
|
|
|
|
line-height: 28px !important
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-loading-mask {
|
|
|
|
background-color: rgba(0, 0, 0, 0.3);
|
|
|
|
}
|
|
|
|
}
|
2019-07-25 10:30:30 +08:00
|
|
|
</style>
|