This commit is contained in:
ann 2024-01-10 15:07:58 +08:00
parent db4ea371a0
commit 294508d806
1 changed files with 151 additions and 86 deletions

View File

@ -4,12 +4,9 @@
<el-button @click="clickback()">返回</el-button> <el-button @click="clickback()">返回</el-button>
</div> </div>
<div class="top"> <div class="top">
<canvas id="container" /> <div class="canvasBox">
</div> <canvas id="container" />
<div class="center"> </div>
<el-button :class="activeTab === 'ys' ? 'active':''" @click="filterData('ys')"><div>数算中心 {{ count.ys }}</div></el-button>
<el-button :class="activeTab === 'zs' ? 'active':''" @click="filterData('zs')"><div>智算中心 {{ count.zs }}</div></el-button>
<el-button :class="activeTab === 'cs' ? 'active':''" @click="filterData('cs')"><div>超算中心 {{ count.cs }}</div></el-button>
</div> </div>
<div class="spin"> <div class="spin">
<div class="circle circle1"> <div class="circle circle1">
@ -58,7 +55,7 @@ export default {
}, },
data() { data() {
return { return {
count: { ys: 0, zs: 0, cs: 0 }, selectedCity: '',
allJSON: { allJSON: {
guangdongJson, guangdongJson,
chuanyuJson, chuanyuJson,
@ -66,12 +63,16 @@ export default {
guizhouJson, jingjinjiJson, neimengguJson, ningxiaJson, changsanjiaoJson, guizhouJson, jingjinjiJson, neimengguJson, ningxiaJson, changsanjiaoJson,
guangdongOutline, hunanJson, hunanOutline guangdongOutline, hunanJson, hunanOutline
}, },
// yscount: 0, currentIndex: 0,
// zscount: 0, interval: undefined,
// cscount: 0, img: undefined,
activeTab: '', activeTab: '',
scale: 1, scale: 1,
geoCenter: {}, geoCenter: {},
offsetX: 0,
offsetY: 0,
eventType: '',
cursorFlag: false,
mapMap: { mapMap: {
1: 'ningxia', 1: 'ningxia',
2: 'neimenggu', 2: 'neimenggu',
@ -111,59 +112,94 @@ export default {
mapType(val) { mapType(val) {
if (val) { if (val) {
this.getBoxArea() this.getBoxArea()
this.initMap() this.drawMap()
} }
} }
}, },
mounted() { mounted() {
this.getBoxArea() this.getBoxArea()
this.initOutline() this.$nextTick(() => {
this.initMap() this.img = new Image()
this.setPoint() this.img.src = process.env.VUE_APP_PUBLIC_SOURCE_API + '/click-point.svg'
this.img.addEventListener('load', () => {
this.setDataRoll()
})
const canvas = document.querySelector('#container')
//
canvas.addEventListener('mousemove', (event) => {
this.offsetX = event.offsetX / 0.55
this.offsetY = event.offsetY / 0.65
this.eventType = 'mousemove'
this.drawMap()
})
//
canvas.addEventListener('click', (event) => {
this.offsetX = event.offsetX / 0.55
this.offsetY = event.offsetY / 0.65
this.eventType = 'click'
clearInterval(this.interval)
this.drawMap()
})
})
}, },
methods: { methods: {
setDataRoll() {
clearInterval(this.interval)
this.interval = setInterval(() => {
this.currentIndex = (this.currentIndex + 1) % this.cluster.length//
this.drawMap()
}, 4000)
},
clickback() { clickback() {
this.dialogVisible = false this.dialogVisible = false
}, },
filterData(type) { filterData(data) {
console.log(type) this.selectedCity = data
if (data === '') {
this.setDataRoll()
}
this.$emit('selectedCity', data)
},
drawMap() {
const canvas = document.querySelector('#container')
const ctx = canvas.getContext('2d')
ctx.clearRect(0, 0, window.innerWidth, window.innerHeight)
this.initOutline()
this.initMap()
this.setPoint()
}, },
setPoint() { setPoint() {
var img = new Image() // const canvas = document.querySelector('#container')
img.src = process.env.VUE_APP_PUBLIC_SOURCE_API + '/click-point.svg' // const ctx = canvas.getContext('2d')
img.addEventListener('load', () => { ctx.beginPath()
// Canvas this.cluster.forEach((e, i) => {
const canvas = document.querySelector('#container') const position = this.toScreenPosition(e.longitude, e.latitude)
const ctx = canvas.getContext('2d') if (this.currentIndex === i) {
const map = { ctx.drawImage(this.img, position.x - 40, position.y - 55, 80, 80)
'cloud': 'ys', ctx.fillStyle = 'rgba(255, 197, 39, 1)'
'ai': 'zs', ctx.font = '30px PangMenZhengDao'
'hpc': 'cs' ctx.fillText(e.name, position.x - e.name.length / 2 * 35, position.y - 55)
}
if (this.cluster.length) { ctx.fillStyle = 'rgba(0, 0, 0, 0.5)'
this.cluster.forEach(e => { ctx.fillRect(position.x + 20, position.y + 5, 300, 90)
const position = this.toScreenPosition(e.longitude, e.latitude) ctx.strokeStyle = '#3EDFFC'
// e.type ctx.strokeRect(position.x + 20, position.y + 5, 300, 90)
this.count[map[e.type || 'hpc']]++ ctx.fillStyle = '#FFFFFF'
ctx.drawImage(img, position.x - 50, position.y - 55, 80, 80) ctx.font = '20px Arial'
ctx.fillStyle = 'rgba(255, 197, 39, 1)' // ctx.fillText('名称:' + e.name, position.x + 20 + 20, position.y + 5 + 40)
ctx.font = '30px PangMenZhengDao' // ctx.fillText('地址:' + e.address || '-', position.x + 20 + 20, position.y + 5 + 70)
ctx.fillText(e.name, position.x - e.name.length / 2 * 35, position.y - 55)
})
} else { } else {
const position = this.toScreenPosition(113, 28) ctx.beginPath()
ctx.drawImage(img, position.x - 50, position.y - 55, 80, 80) ctx.arc(position.x, position.y, 5, 0, Math.PI * 2) // 5
// ctx.beginPath() ctx.fillStyle = '#ffffff' //
// ctx.moveTo(position.x - 50, position.y + 20) ctx.fill()
ctx.fillStyle = 'rgba(255, 197, 39, 1)' // ctx.closePath()
ctx.font = '30px PangMenZhengDao' //
ctx.fillText('长沙', position.x - 40, position.y - 55)
} }
// ctx.fillStyle = 'red'
// ctx.beginPath()
// ctx.arc(x, y, r, 0, 2 * Math.PI)
// ctx.fill()// xyCanvaswh
}) })
ctx.stroke()
ctx.restore()
}, },
getBoxArea() { getBoxArea() {
const canvasW = window.innerWidth const canvasW = window.innerWidth
@ -173,7 +209,6 @@ export default {
if (item.geometry.type === 'Polygon') { if (item.geometry.type === 'Polygon') {
item.geometry.coordinates = [item.geometry.coordinates] item.geometry.coordinates = [item.geometry.coordinates]
} }
//
item.geometry.coordinates.forEach(area => { item.geometry.coordinates.forEach(area => {
area[0].forEach(elem => { area[0].forEach(elem => {
if (elem[0] < W) { if (elem[0] < W) {
@ -191,34 +226,17 @@ export default {
}) })
}) })
}) })
// var wScale = canvasW / Math.abs(E - W)
var wScale = canvasW / Math.abs(E - W) - 20 var hScale = canvasH / Math.abs(N - S)
var hScale = canvasH / Math.abs(N - S) - 20 this.scale = (wScale > hScale ? hScale : wScale) * 0.9
// const width = Math.abs(E - W)
// const height = Math.abs(N - S)
// const wScale = canvasW / width / 3
// const hScale = canvasH / height / 3
//
this.scale = wScale > hScale ? hScale : wScale
//
// this.geoCenterX = (E + W) / 2
// this.geoCenterY = (N + S) / 2
this.geoCenter = { this.geoCenter = {
W: W, W: W,
N: N, N: N,
xoffset: canvasW / 2 - Math.abs(E - W) / 2 * this.scale, xoffset: canvasW / 2 - Math.abs(E - W) / 2 * this.scale,
yoffset: canvasH / 2 - Math.abs(N - S) / 2 * this.scale yoffset: canvasH / 2 - Math.abs(N - S) / 2 * this.scale
} }
// this.geoCenterY = S
// console.log({
// xoffset: width / 2.0 - width / 2 * this.scale,
// yoffset: height / 2.0 - height / 2 * this.scale
// })
}, },
toScreenPosition(longitude, latitude) { toScreenPosition(longitude, latitude) {
// var xoffset=width/2.0-width/2*scale
// var yoffset=height/2.0-height/2*scale
return { return {
x: (longitude - this.geoCenter.W) * this.scale + this.geoCenter.xoffset, x: (longitude - this.geoCenter.W) * this.scale + this.geoCenter.xoffset,
y: (this.geoCenter.N - latitude) * this.scale + this.geoCenter.yoffset y: (this.geoCenter.N - latitude) * this.scale + this.geoCenter.yoffset
@ -227,41 +245,53 @@ export default {
initMap() { initMap() {
const canvas = document.querySelector('#container') const canvas = document.querySelector('#container')
const ctx = canvas.getContext('2d') const ctx = canvas.getContext('2d')
this.cursorFlag = false
ctx.beginPath() ctx.beginPath()
ctx.strokeStyle = '#3EDFFC' ctx.strokeStyle = '#3EDFFC'
ctx.lineWidth = 1 ctx.lineWidth = 1
this.allJSON[this.mapMap[this.mapType] + 'Json'].features.forEach(elem => { this.allJSON[this.mapMap[this.mapType] + 'Json'].features.forEach(elem => {
const coordinates = elem.geometry.coordinates const coordinates = elem.geometry.coordinates
// const centerX = canvasW / 2
// const centerY = canvasH / 2
ctx.save()
// ctx.beginPath()
// ctx.translate(centerX, centerY)
coordinates.forEach(multiPolygon => { coordinates.forEach(multiPolygon => {
multiPolygon.forEach(polygon => { multiPolygon.forEach(polygon => {
ctx.save()
ctx.beginPath()
// ctx.translate(0, 0)
for (let i = 0; i < polygon.length; i++) { for (let i = 0; i < polygon.length; i++) {
// console.log(polygon[i])
const position = this.toScreenPosition(polygon[i][0], polygon[i][1]) const position = this.toScreenPosition(polygon[i][0], polygon[i][1])
// console.log(position)
if (i === 0) { if (i === 0) {
ctx.moveTo(position.x, position.y - 5) ctx.moveTo(position.x, position.y - 5)
} else { } else {
ctx.lineTo(position.x, position.y - 5) ctx.lineTo(position.x, position.y - 5)
} }
} }
ctx.closePath()
ctx.strokeStyle = '#34CEE9'
ctx.lineWidth = 1
if (ctx.isPointInPath(this.offsetX, this.offsetY)) {
this.cursorFlag = true
ctx.fillStyle = '#a2f7ff'
if (this.eventType === 'click') {
this.filterData(elem.properties.name)
//
}
} else {
if (this.eventType === 'mousemove' && this.selectedCity === '') ctx.fillStyle = 'transparent'
}
if (this.selectedCity === elem.properties.name) ctx.fillStyle = '#00eaff'
ctx.fill()
ctx.stroke()
ctx.restore()
}) })
}) })
}) })
ctx.closePath()
var g = ctx.createRadialGradient(700, 600, 50, 1000, 600, 600)
g.addColorStop(0, '#29a0ee')
g.addColorStop(1, '#0b4eaf')
ctx.fillStyle = g if (this.cursorFlag) {
ctx.fill() canvas.style.cursor = 'pointer'
ctx.stroke() } else {
ctx.restore() canvas.style.cursor = 'default'
}
}, },
initOutline() { initOutline() {
const canvas = document.querySelector('#container') const canvas = document.querySelector('#container')
@ -280,9 +310,7 @@ export default {
coordinates.forEach(multiPolygon => { coordinates.forEach(multiPolygon => {
multiPolygon.forEach(polygon => { multiPolygon.forEach(polygon => {
for (let i = 0; i < polygon.length; i++) { for (let i = 0; i < polygon.length; i++) {
// console.log(polygon[i])
const position = this.toScreenPosition(polygon[i][0], polygon[i][1]) const position = this.toScreenPosition(polygon[i][0], polygon[i][1])
// console.log(position)
if (i === 0) { if (i === 0) {
ctx.moveTo(position.x, position.y + 5) ctx.moveTo(position.x, position.y + 5)
} else { } else {
@ -293,6 +321,12 @@ export default {
}) })
}) })
ctx.closePath() ctx.closePath()
if (!ctx.isPointInPath(this.offsetX, this.offsetY)) {
if (this.eventType === 'click') {
this.filterData('')
//
}
}
ctx.fillStyle = '#3edffc' ctx.fillStyle = '#3edffc'
var grd = ctx.createLinearGradient(0, 0, 1500, 0) var grd = ctx.createLinearGradient(0, 0, 1500, 0)
for (let i = 0; i < 1000; i++) { for (let i = 0; i < 1000; i++) {
@ -307,6 +341,32 @@ export default {
ctx.fill() ctx.fill()
ctx.stroke() ctx.stroke()
ctx.restore() ctx.restore()
ctx.beginPath()
this.allJSON[this.mapMap[this.mapType] + 'Outline'].features.forEach(elem => {
const coordinates = elem.geometry.coordinates
ctx.save()
coordinates.forEach(multiPolygon => {
multiPolygon.forEach(polygon => {
for (let i = 0; i < polygon.length; i++) {
const position = this.toScreenPosition(polygon[i][0], polygon[i][1])
if (i === 0) {
ctx.moveTo(position.x, position.y - 5)
} else {
ctx.lineTo(position.x, position.y - 5)
}
}
})
})
})
ctx.closePath()
var g = ctx.createRadialGradient(700, 600, 50, 1000, 600, 600)
g.addColorStop(0, '#29a0ee')
g.addColorStop(1, '#0b4eaf')
ctx.fillStyle = g
ctx.fill()
ctx.stroke()
ctx.restore()
} }
} }
} }
@ -396,6 +456,11 @@ export default {
background-size: 100% 100%; background-size: 100% 100%;
} }
} }
.canvasBox{
width: 100%;
height: 100%;
position: relative;
}
#container { #container {
width: 55vw; width: 55vw;
height: 65vh; height: 65vh;