|
@ -5,15 +5,41 @@ |
|
|
<script> |
|
|
<script> |
|
|
import { onceObserver } from "@screen/utils/resizeObserver"; |
|
|
import { onceObserver } from "@screen/utils/resizeObserver"; |
|
|
import Vue from "vue"; |
|
|
import Vue from "vue"; |
|
|
import { Graph } from '@antv/x6' |
|
|
import { Graph, Shape } from '@antv/x6' |
|
|
|
|
|
import { debounce } from "lodash"; |
|
|
import { actualLocationList, canvasList } from "./data.js"; |
|
|
import { actualLocationList, canvasList } from "./data.js"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const mouseenterDebounceFunc = debounce(({ node }) => { |
|
|
|
|
|
if (["singleNode-html", "multiNode-html"].indexOf(node.shape) >= 0) { |
|
|
|
|
|
node.setZIndex(100); |
|
|
|
|
|
console.log(node); |
|
|
|
|
|
} |
|
|
|
|
|
}, 100); |
|
|
|
|
|
const mouseleaveDebounceFunc = debounce(({ node }) => { |
|
|
|
|
|
if (["singleNode-html", "multiNode-html"].indexOf(node.shape) >= 0) { |
|
|
|
|
|
node.setZIndex(1); |
|
|
|
|
|
} |
|
|
|
|
|
}, 100); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const clickDebounceFunc = debounce(({ node }) => { |
|
|
|
|
|
const mapIns = Vue.prototype.mapIns; |
|
|
|
|
|
if (["singleNode-html", "multiNode-html"].indexOf(node.shape) >= 0) { |
|
|
|
|
|
const extData = node.getData()?.extData; |
|
|
|
|
|
if (extData) { |
|
|
|
|
|
mapIns.setZoomAndCenter(18, [extData.longitude, extData.latitude]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}, 100); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setFont(size, bold = "normal", family = "微软雅黑") { |
|
|
function setFont(size, bold = "normal", family = "微软雅黑") { |
|
|
return `${bold} ${size}px ${family}`; |
|
|
return `${bold} ${size}px ${family}`; |
|
|
} |
|
|
} |
|
|
let width, height; |
|
|
let width, height; |
|
|
const actualDis = actualLocationList.reduce( |
|
|
const allActualDis = actualLocationList.reduce( |
|
|
(count, item) => count + item.intervalDistance, |
|
|
(count, item) => count + item.intervalDistance, |
|
|
0 |
|
|
0 |
|
|
); |
|
|
); |
|
@ -157,17 +183,77 @@ export default { |
|
|
// return true; |
|
|
// return true; |
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}); |
|
|
Vue.prototype.graphInstance = graph; |
|
|
graph.on('node:mouseenter', mouseenterDebounceFunc); |
|
|
|
|
|
graph.on('node:mouseleave', mouseleaveDebounceFunc); |
|
|
|
|
|
graph.on('node:click', clickDebounceFunc); |
|
|
|
|
|
|
|
|
|
|
|
Shape.HTML.register({ |
|
|
|
|
|
shape: 'singleNode-html', |
|
|
|
|
|
width: 160, |
|
|
|
|
|
height: 80, |
|
|
|
|
|
html(node) { |
|
|
|
|
|
const data = node.getData(); |
|
|
|
|
|
const { height, width } = node.prop().size; |
|
|
|
|
|
const div = document.createElement('div') |
|
|
|
|
|
div.innerHTML = ` |
|
|
|
|
|
<div style=" |
|
|
|
|
|
background-image: url(${data.nowBg}); |
|
|
|
|
|
background-size: 100% 100%; |
|
|
|
|
|
background-repeat: no-repeat; |
|
|
|
|
|
width: ${width * 1.2}px; |
|
|
|
|
|
height: ${height * 1.2}px; |
|
|
|
|
|
display: flex; |
|
|
|
|
|
justify-content: center; |
|
|
|
|
|
"> |
|
|
|
|
|
<img style=" |
|
|
|
|
|
width: ${width * 0.8}px; |
|
|
|
|
|
height: ${height * 0.8}px; |
|
|
|
|
|
margin-top: ${height * 0.1}px; |
|
|
|
|
|
" src='${data.src}' |
|
|
|
|
|
> |
|
|
|
|
|
</div> |
|
|
|
|
|
`; |
|
|
|
|
|
return div |
|
|
|
|
|
}, |
|
|
|
|
|
}) |
|
|
|
|
|
Shape.HTML.register({ |
|
|
|
|
|
shape: 'multiNode-html', |
|
|
|
|
|
width: 160, |
|
|
|
|
|
height: 80, |
|
|
|
|
|
html(node) { |
|
|
|
|
|
const data = node.getData(); |
|
|
|
|
|
const { height, width } = node.prop().size; |
|
|
|
|
|
const div = document.createElement('div') |
|
|
|
|
|
div.innerHTML = ` |
|
|
|
|
|
<div style=" |
|
|
|
|
|
background-image: url(${data.nowBg}); |
|
|
|
|
|
background-size: 100% 100%; |
|
|
|
|
|
background-repeat: no-repeat; |
|
|
|
|
|
display: flex; |
|
|
|
|
|
justify-content: center; |
|
|
|
|
|
align-items: center; |
|
|
|
|
|
padding-bottom: ${height * 0.1}px; |
|
|
|
|
|
"> |
|
|
|
|
|
${data.length} |
|
|
|
|
|
</div> |
|
|
|
|
|
`; |
|
|
|
|
|
return div |
|
|
|
|
|
}, |
|
|
|
|
|
}) |
|
|
|
|
|
window.graphInstance = graph; |
|
|
baseData.nodes.forEach(node => { |
|
|
baseData.nodes.forEach(node => { |
|
|
graph.addNode(node) |
|
|
graph.addNode(node) |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
this.drawCongestionAreas(graph, 1404, 80); |
|
|
this.drawCongestionAreas(graph, 1404, 80); |
|
|
|
|
|
|
|
|
|
|
|
const ratio = ((width - width * 0.08 * 2) / allActualDis); //减去俩侧空白区域 才是画布要计算的比例 |
|
|
|
|
|
window.canvasRatio = ratio; |
|
|
|
|
|
window.canvasWidth = width; |
|
|
|
|
|
|
|
|
this.list.forEach(item => this.allInstance += item.distance); |
|
|
this.list.forEach(item => this.allInstance += item.distance); |
|
|
for (let index in this.list) { |
|
|
for (let index in this.list) { |
|
|
const info = this.list[index]; |
|
|
const info = this.list[index]; |
|
|
const ratio = ((width - width * 0.08 * 2) / actualDis); //减去俩侧空白区域 才是画布要计算的比例 |
|
|
|
|
|
info.distance = actualLocationList[index].intervalDistance * ratio; |
|
|
info.distance = actualLocationList[index].intervalDistance * ratio; |
|
|
await this.drawTag(info, graph); |
|
|
await this.drawTag(info, graph); |
|
|
} |
|
|
} |
|
|