Files
dvcp_v2_webapp/ui/dv/AiDvMap.vue

200 lines
5.3 KiB
Vue
Raw Permalink Normal View History

2023-03-27 18:02:05 +08:00
<template>
<div class="AiDvMap" v-resize="onDomResize">
<div class="chart-map" ref="dvMap"/>
2023-03-27 18:02:05 +08:00
</div>
</template>
<script>
2023-03-29 14:43:34 +08:00
import http from "dui/lib/js/request";
import {mapState} from "vuex";
2023-03-27 18:02:05 +08:00
2023-03-29 14:43:34 +08:00
export default {
name: 'AiDvMap',
props: {
2024-03-27 12:31:39 +08:00
geoJson: String,
2024-04-14 22:09:26 +08:00
data: Array,
2024-04-15 00:27:45 +08:00
ops: Object
},
2023-03-29 14:43:34 +08:00
data() {
return {
2024-03-27 12:31:39 +08:00
chart: null,
2023-03-29 14:43:34 +08:00
}
},
directives: {
resize: {
bind(el, binding) {
let width = ''
let height = ''
2023-03-27 18:02:05 +08:00
function isResize() {
2023-03-29 14:43:34 +08:00
const style = document.defaultView.getComputedStyle(el)
if (width !== style.width || height !== style.height) {
binding.value({
width: style.width,
height: style.height
})
}
width = style.width
height = style.height
2023-03-27 18:02:05 +08:00
}
2023-03-29 14:43:34 +08:00
el.__vueSetInterval__ = setInterval(isResize, 300)
2023-03-29 14:43:34 +08:00
},
unbind(el) {
clearInterval(el.__vueSetInterval__)
2023-03-27 18:02:05 +08:00
}
2023-03-29 14:43:34 +08:00
}
},
computed: {
...mapState(['user'])
},
2023-03-29 14:43:34 +08:00
mounted() {
this.$load(this.$refs.dvMap).then(() => this.initChart())
2023-03-29 14:43:34 +08:00
},
methods: {
onDomResize() {
2023-03-27 18:02:05 +08:00
this.$nextTick(() => {
2023-03-29 14:43:34 +08:00
this.chart.resize()
2023-03-27 18:02:05 +08:00
})
},
2023-03-29 14:43:34 +08:00
initChart() {
const {echarts} = window
this.chart = echarts.init(this.$refs.dvMap)
2024-04-15 00:27:45 +08:00
this.chart.showLoading({
text: "数据加载中...", textColor: "#fff",
maskColor: 'rgba(0, 0, 0, 0.2)'
})
2024-04-15 01:14:33 +08:00
this.getData(this.geoJson).then(res => {
if (!!res?.data) {
echarts.registerMap('customMap', res.data)
const option = {
2024-03-27 12:31:39 +08:00
geo: [
2024-04-15 00:27:45 +08:00
// 重影
...Array(3).fill(1).map((e, i) => {
return {
type: "map",
map: "customMap",
zlevel: -1,
aspectScale: 1,
zoom: 0.65,
layoutCenter: ["50%", `${51 + i}%`],
layoutSize: "180%",
roam: false,
silent: true,
itemStyle: {
normal: {
borderWidth: 1,
// borderColor:"rgba(17, 149, 216,0.6)",
borderColor: `rgba(2, 198, 220, ${0.6 - i * 0.2})`,
shadowColor: `rgba(2, 198, 220, ${0.6 - i * 0.2})`,
shadowOffsetY: 5,
shadowBlur: 15,
areaColor: "transparent",
},
},
}
}),
2024-04-15 01:14:33 +08:00
],
series: {
type: "map",
map: "customMap",
aspectScale: 1,
zoom: 0.65,
layoutCenter: ["50%", "50%"],
layoutSize: "180%",
show: true,
roam: false,
selectedMode: 'single',
emphasis: {
show: true,
2024-04-15 01:14:33 +08:00
label: {
textStyle: {
color: "#FFFFFF"
2024-03-27 12:31:39 +08:00
},
},
2024-04-15 01:14:33 +08:00
itemStyle: {
areaColor: '#02C6DC'
}
},
select: {
2024-03-27 12:31:39 +08:00
label: {
2024-04-15 01:14:33 +08:00
color: "#fff"
2024-03-27 12:31:39 +08:00
},
itemStyle: {
2024-04-15 01:14:33 +08:00
areaColor: '#02bcff29'
}
2023-03-29 14:43:34 +08:00
},
2024-04-15 01:14:33 +08:00
label: {
show: true,
color: '#fff',
fontSize: 22
},
itemStyle: {
2024-04-16 14:55:21 +08:00
borderColor: "rgba(2, 198, 220, 0)",
2024-04-15 01:14:33 +08:00
borderWidth: 2,
areaColor: "#02bcff29",
shadowBlur: 120,
},
data: this.data
},
2024-04-15 00:27:45 +08:00
...this.ops
2024-03-27 12:31:39 +08:00
// geo3D: {
// map: "customMap",
// shading: 'color',
// regionHeight: 8,
// show: true,
// emphasis: {
// show: true,
// },
// label: {
// show: true,
// color: '#fff',
// fontSize: 22
// },
// itemStyle: {
// color: '#02bcff29',
// borderColor: "rgba(2, 198, 220, 1)",
// borderWidth: 2
// },
// viewControl: {
// rotateSensitivity: 0,
// zoomSensitivity: 0,
// panMouseButton: 0,
// distance: 250,
// alpha:50,
// center:[0,-60,0]
// }
// },
2023-03-27 18:02:05 +08:00
}
2023-03-29 14:43:34 +08:00
this.chart.setOption(option)
2024-04-15 01:14:33 +08:00
this.chart.on('click', evt => this.$emit("click", {...evt, info: res.data.features.find(e => e.properties?.name == evt.name)?.properties}))
2024-04-15 00:27:45 +08:00
this.chart.on('globalout', () => this.$emit("globalout"))
2023-03-29 14:43:34 +08:00
}
2024-04-15 00:27:45 +08:00
return 1
}).finally(() => this.chart.hideLoading())
2023-03-29 14:43:34 +08:00
},
getData(url = `https://geo.datav.aliyun.com/areas_v3/bound/geojson?code=${this.user.info.areaId?.substring(0, 6)}`) {
return http.post(`/app/appdvcpconfig/apiForward?url=${encodeURIComponent(url)}`)
2024-03-27 12:31:39 +08:00
},
2023-03-27 18:02:05 +08:00
}
2023-03-29 14:43:34 +08:00
}
2023-03-27 18:02:05 +08:00
</script>
<style lang="scss" scoped>
2023-03-29 14:43:34 +08:00
.AiDvMap {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
padding: 16px;
box-sizing: border-box;
2024-03-27 12:31:39 +08:00
position: relative;
.chart-map {
width: 100%;
height: 100%;
}
2023-03-29 14:43:34 +08:00
}
2023-03-27 18:02:05 +08:00
</style>