调整代码

This commit is contained in:
zyy 2019-07-25 10:55:31 +08:00
parent 8b46424116
commit cf0cabadaf

View File

@ -1,282 +1,282 @@
<template>
<div class="jlmap-canvas" :style="{ width: width+'px', height: height+28+'px' }">
<div :id="canvasId" style="background: #000;"></div>
<progress-bar ref="progressBar" ></progress-bar>
<zoom-box @setShrink="setShrink" @setMagnify="setMagnify" :scaleRate="dataZoom.scaleRate" v-if="!isScreen"></zoom-box>
<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="偏移:">
<el-input v-model="dataZoom.offsetX" :disabled="true"></el-input>
</el-form-item>
<el-form-item>
<el-input v-model="dataZoom.offsetY" :disabled="true"></el-input>
</el-form-item>
<el-form-item label="缩放:" style="float: right">
<el-input v-model="dataZoom.scaleRate" :disabled="true"></el-input>
</el-form-item>
</el-form>
</div>
<div class="jlmap-canvas" :style="{ width: width+'px', height: height+28+'px' }">
<div :id="canvasId" style="background: #000;" />
<progress-bar ref="progressBar" />
<zoom-box :scale-rate="dataZoom.scaleRate" v-if="!isScreen" @setShrink="setShrink" @setMagnify="setMagnify" />
<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="偏移:">
<el-input v-model="dataZoom.offsetX" :disabled="true" />
</el-form-item>
<el-form-item>
<el-input v-model="dataZoom.offsetY" :disabled="true" />
</el-form-item>
<el-form-item label="缩放:" 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 '@/jmap/map';
import ZoomBox from './zoom/zoom';
import ProgressBar from '@/views/components/progressBar/index';
import { mapGetters } from 'vuex';
import { Loading } from 'element-ui';
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 { Loading } from 'element-ui';
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;
return true;
},
isScreen() {
return this.$route.params.mode === 'dp'
}
},
watch: {
'$store.state.map.map': function (val, old) {
if (val && val.skinStyle) {
try {
this.setMap(val);
} catch (error) {
console.log(error);
}
}
},
'$store.state.training.rezoomCount': function (val, old) {
this.setShowCenter(this.$store.state.training.offsetStationCode);
},
'$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() {
const dom = document.getElementById(this.canvasId).oncontextmenu = function (e) {
return false;
};
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;
return true;
},
isScreen() {
return this.$route.params.mode === 'dp';
}
},
watch: {
'$store.state.map.map': function (val, old) {
if (val && val.skinStyle) {
try {
this.setMap(val);
} catch (error) {
console.log(error);
}
}
},
'$store.state.training.rezoomCount': function (val, old) {
this.setShowCenter(this.$store.state.training.offsetStationCode);
},
'$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() {
document.getElementById(this.canvasId).oncontextmenu = function (e) {
return false;
};
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: {
dataLoaded() {
console.log('dataLoaded');
},
viewLoaded() {
console.log('viewLoaded');
this.mapViewLoaded(true);
},
stateLoaded() {
},
viewUpdate() {
console.log('viewUpdate');
},
stateUpdate() {
console.log('stateUpdate');
},
optionsUpdate() { console.log('optionsUpdate'); }
}
});
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: {
dataLoaded() {
console.log('dataLoaded');
},
viewLoaded() {
console.log('viewLoaded');
this.mapViewLoaded(true);
},
stateLoaded() {
},
viewUpdate() {
console.log('viewUpdate');
},
stateUpdate() {
console.log('stateUpdate');
},
optionsUpdate() { console.log('optionsUpdate'); }
}
});
this.$jlmap.on('datazoom', this.onDataZoom, this);
this.$jlmap.on('selected', this.onSelected, this);
this.$jlmap.on('contextmenu', this.onContextMenu, this);
this.$jlmap.on('datazoom', this.onDataZoom, this);
this.$jlmap.on('selected', this.onSelected, this);
this.$jlmap.on('contextmenu', this.onContextMenu, this);
window.document.oncontextmenu = function () {
return false;
}
},
// jlmap
resetSize() {
this.$nextTick(() => {
this.width = this.$store.state.config.width;
this.height = this.$store.state.config.height;
window.document.oncontextmenu = function () {
return false;
};
},
// jlmap
resetSize() {
this.$nextTick(() => {
this.width = this.$store.state.config.width;
this.height = this.$store.state.config.height;
if (this.$jlmap) {
this.$jlmap.resizeZr({ width: this.width, height: this.height });
}
if (this.$jlmap) {
this.$jlmap.resize({ width: this.width, height: this.height });
}
this.$store.dispatch('training/updateOffsetStationCode', { offsetStationCode: this.offsetStationCode });
// this.$store.dispatch('training/updateOffsetStationCode', { offsetStationCode: this.offsetStationCode });
setTimeout(() => {
this.$store.dispatch('config/resetCanvasOffset');
this.$store.dispatch('training/emitTipFresh');
}, 100);
});
},
//
setShowLevel(level) {
if (this.$jlmap) {
console.log('设置显示图层');
// this.$jlmap.setShowLevel(level);
}
},
// Level
setShowLogicalLevel(levels) {
if (this.$jlmap) {
console.log('设置逻辑视图Level');
// this.$jlmap.setShowLogicalLevel(levels);
}
},
// Level
setShowPhysicalLevel(levels) {
if (this.$jlmap) {
onsole.log('设置物理视图Level');
// this.$jlmap.setShowPhysicalLevel(levels);
}
},
//
setShowCenter(deviceCode) {
if (this.$jlmap) {
this.$jlmap.setCenter(deviceCode);
}
},
//
onDataZoom(dataZoom) {
this.dataZoom.offsetX = dataZoom._offsetX.toFixed(1) + '';
this.dataZoom.offsetY = dataZoom._offsetY.toFixed(1) + '';
this.dataZoom.scaleRate = dataZoom._scaleRate + '';
// setTimeout(() => {
// this.$store.dispatch('config/resetCanvasOffset');
// this.$store.dispatch('training/emitTipFresh');
// }, 100);
});
},
//
setShowLevel(level) {
if (this.$jlmap) {
console.log('设置显示图层');
// this.$jlmap.setShowLevel(level);
}
},
// Level
setShowLogicalLevel(levels) {
if (this.$jlmap) {
console.log('设置逻辑视图Level');
// this.$jlmap.setShowLogicalLevel(levels);
}
},
// Level
setShowPhysicalLevel(levels) {
if (this.$jlmap) {
console.log('设置物理视图Level');
// this.$jlmap.setShowPhysicalLevel(levels);
}
},
//
setShowCenter(deviceCode) {
if (this.$jlmap) {
this.$jlmap.setCenter(deviceCode);
}
},
//
onDataZoom(dataZoom) {
this.dataZoom.offsetX = dataZoom._offsetX.toFixed(1) + '';
this.dataZoom.offsetY = dataZoom._offsetY.toFixed(1) + '';
this.dataZoom.scaleRate = dataZoom._scaleRate + '';
let skinStyle = this.$store.state.map.map.skinStyle;
if (skinStyle) {
let param = {
scaleRate: this.dataZoom.scaleRate,
skinCode: skinStyle,
offsetY: this.dataZoom.offsetY,
}
const skinStyle = this.$store.state.map.map.skinStyle;
if (skinStyle) {
const param = {
scaleRate: this.dataZoom.scaleRate,
skinCode: skinStyle,
offsetY: this.dataZoom.offsetY
};
localStore.set(`scaleRate_${skinStyle}`, JSON.stringify(param)); //
}
localStore.set(`scaleRate_${skinStyle}`, JSON.stringify(param)); //
}
this.$store.dispatch('map/updateZoom', this.dataZoom);
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() {
this.$jlmap.setOptions({scale: -1});
},
//
setMagnify() {
this.$jlmap.setOptions({scale: 1});
}
}
}
this.$store.dispatch('map/updateZoom', this.dataZoom);
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() {
this.$jlmap.setOptions({scale: -1});
},
//
setMagnify() {
this.$jlmap.setOptions({scale: 1});
}
}
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.jlmap-canvas {