crossSectionChart.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <div ref="pipeSectionPicture" style="width: 99%; height: 99%"></div>
  3. </template>
  4. <script>
  5. import * as echarts from 'echarts'
  6. import PipeQueryHelper from '@/utils/mapCommon/PipeQueryHelper'
  7. import Config from './config.json'
  8. export default {
  9. name: 'crossSectionChart', //断面图
  10. props: {
  11. drawSectionInfo: null
  12. },
  13. data() {
  14. return {
  15. config: Config,
  16. _echart: null,
  17. crossResult: null,
  18. SelectPipe: null,
  19. crossLinePoints: null
  20. }
  21. },
  22. methods: {
  23. //绘制断面图
  24. drawSectionPicture() {
  25. if (this._echart) {
  26. this._echart.dispose()
  27. this._echart = null
  28. }
  29. if (this.crossResult == undefined && this.SelectPipe == undefined && this.crossLinePoints == undefined) return
  30. const minDiameter = 10
  31. const minScatter = 10
  32. const maxScatter = 30
  33. const maxDiameter = 1000
  34. this.crossResult.sort((a, b) => {
  35. return a.distance - b.distance
  36. })
  37. const s3mlayername = this.SelectPipe.s3mlayername
  38. const currentSceneLayer = this.$_.find(PipeQueryHelper.pipe, (item) => {
  39. return item.origindataset === s3mlayername
  40. })
  41. //选中管线信息
  42. const selectPipeColor = 'rgb(' + currentSceneLayer.lineColor.join(',') + ')'
  43. const selectPipe = this.crossLinePoints
  44. const fromPoint = Cesium.Cartographic.fromCartesian(selectPipe[0])
  45. const toPoint = Cesium.Cartographic.fromCartesian(selectPipe[1])
  46. const selectPipeDiameter = isNaN(this.SelectPipe[this.config.sjFields.diameter])
  47. ? 10
  48. : parseFloat(this.SelectPipe[this.config.sjFields.diameter])
  49. const selepipeLineSymbol =
  50. selectPipeDiameter < 10
  51. ? minDiameter
  52. : ((selectPipeDiameter - minDiameter) / (maxDiameter - minDiameter)) * (maxScatter - minScatter) + minScatter
  53. //起始点地面高程
  54. const inRoadHeight = parseFloat(this.SelectPipe[this.config.sjFields.inSurfaceH])
  55. const outRoadHeight = parseFloat(this.SelectPipe[this.config.sjFields.outSurfaceH])
  56. const demHeight = []
  57. const roadHeight = []
  58. const data = this.crossResult.map((item) => {
  59. const carto = Cesium.Cartographic.fromCartesian(item.position).height
  60. demHeight.push(carto)
  61. roadHeight.push(item.height)
  62. return {
  63. value: [item.distance, carto],
  64. symbol: item.diameterType === 'circle' ? 'circle' : 'emptyRectangle',
  65. symbolSize:
  66. item.diameter < 10
  67. ? minDiameter
  68. : ((item.diameter - minDiameter) / (maxDiameter - minDiameter)) * (maxScatter - minScatter) + minScatter,
  69. itemStyle: {
  70. color: 'rgba(255,255,255,0)',
  71. borderColor: 'rgb(' + item.lineColor.join(',') + ')',
  72. borderWidth: 3
  73. }
  74. }
  75. })
  76. demHeight.push(fromPoint.height)
  77. demHeight.push(toPoint.height)
  78. demHeight.push(inRoadHeight)
  79. demHeight.push(outRoadHeight)
  80. //点积求投影长度
  81. const fcross = Cesium.Cartographic.fromCartesian(this.crossLinePoints[0])
  82. const lcross = Cesium.Cartographic.fromCartesian(this.crossLinePoints[1])
  83. const newLcross = Cesium.Cartographic.fromRadians(lcross.longitude, lcross.latitude, fcross.height)
  84. const vectora = Cesium.Cartesian3.subtract(
  85. Cesium.Cartographic.toCartesian(newLcross),
  86. Cesium.Cartographic.toCartesian(fcross),
  87. new Cesium.Cartesian3()
  88. )
  89. const vectorb = Cesium.Cartesian3.subtract(
  90. this.crossLinePoints[1],
  91. this.crossLinePoints[0],
  92. new Cesium.Cartesian3()
  93. )
  94. const projectDistance = Cesium.Cartesian3.dot(vectora, vectorb) / Cesium.Cartesian3.magnitude(vectora)
  95. const maxHeight = Math.max.apply(null, roadHeight)
  96. const lineLength = Math.abs(projectDistance)
  97. let minYAxis = Math.floor(Math.min.apply(null, demHeight)) - 1
  98. const maxYAxis = Math.ceil(Math.max.apply(null, demHeight))
  99. const maxXAxis = Math.ceil(lineLength)
  100. const minXAxis = -(maxXAxis / 10)
  101. const splitTick = (maxYAxis - minYAxis) / 8
  102. //const splitTick = 1;
  103. minYAxis = minYAxis - splitTick * 4
  104. // minYAxis=minYAxis-splitTick*;
  105. let pipeInfoArea = []
  106. this.crossResult.forEach((item, index) => {
  107. const height = parseFloat(item.height).toFixed(2)
  108. const diameter = item.diameterStr
  109. const depth = parseFloat(item.depth).toFixed(2)
  110. if (index === 0) {
  111. const value = parseFloat(item.distance).toFixed(2)
  112. pipeInfoArea.push([
  113. { name: value, label: { show: true, position: 'inside' }, coord: [0, splitTick + minYAxis] },
  114. { coord: [item.distance, minYAxis] }
  115. ])
  116. pipeInfoArea.push([
  117. { name: depth, label: { show: true, position: 'insideRight' }, coord: [0, splitTick * 2 + minYAxis] },
  118. { coord: [item.distance, splitTick + minYAxis] }
  119. ])
  120. pipeInfoArea.push([
  121. { name: diameter, label: { show: true, position: 'insideRight' }, coord: [0, splitTick * 3 + minYAxis] },
  122. { coord: [item.distance, splitTick * 2 + minYAxis] }
  123. ])
  124. pipeInfoArea.push([
  125. { name: height, label: { show: true, position: 'insideRight' }, coord: [0, splitTick * 4 + minYAxis] },
  126. { coord: [item.distance, splitTick * 3 + minYAxis] }
  127. ])
  128. } else {
  129. const value = (parseFloat(item.distance) - parseFloat(this.crossResult[index - 1].distance)).toFixed(2)
  130. const preDistance = parseFloat(this.crossResult[index - 1].distance)
  131. const distance = parseFloat(item.distance)
  132. if (parseFloat(value) > 0) {
  133. pipeInfoArea.push([
  134. { name: value, label: { show: true, position: 'inside' }, coord: [preDistance, splitTick + minYAxis] },
  135. { coord: [distance, minYAxis] }
  136. ])
  137. pipeInfoArea.push([
  138. { name: depth, label: { show: true, position: 'insideRight' }, coord: [0, splitTick * 2 + minYAxis] },
  139. { coord: [item.distance, splitTick + minYAxis] }
  140. ])
  141. pipeInfoArea.push([
  142. {
  143. name: diameter,
  144. label: { show: true, position: 'insideRight' },
  145. coord: [preDistance, splitTick * 3 + minYAxis]
  146. },
  147. { coord: [distance, splitTick * 2 + minYAxis] }
  148. ])
  149. pipeInfoArea.push([
  150. {
  151. name: height,
  152. label: { show: true, position: 'insideRight' },
  153. coord: [preDistance, splitTick * 4 + minYAxis]
  154. },
  155. { coord: [distance, splitTick * 3 + minYAxis] }
  156. ])
  157. }
  158. }
  159. })
  160. const image = new Image()
  161. image.src = require('@/views/groupPage/images/sectionbg.png')
  162. image.onload = () => {
  163. const backData = [
  164. [0, splitTick * 4 + minYAxis],
  165. [maxXAxis, splitTick * 4 + minYAxis],
  166. [maxXAxis, outRoadHeight],
  167. [0, inRoadHeight]
  168. ]
  169. this._echart = echarts.init(this.$refs['pipeSectionPicture'])
  170. const options = {
  171. title: {
  172. text: '地下管线横断面图',
  173. left: 'center',
  174. show: false
  175. },
  176. tooltip: { show: true },
  177. toolbox: {
  178. show: false,
  179. feature: {
  180. saveAsImage: {}
  181. }
  182. },
  183. grid: {
  184. left: '25%',
  185. bottom: 10,
  186. right: '10%',
  187. top: 30
  188. },
  189. backgroundcolor: 'transparent',
  190. xAxis: {
  191. name: '(m)',
  192. nameTextStyle: {
  193. color: '#fff'
  194. },
  195. type: 'value',
  196. min: 0,
  197. max: maxXAxis,
  198. splitLine: { show: false },
  199. axisLabel: { show: false },
  200. axisTick: { show: false }
  201. },
  202. yAxis: [
  203. {
  204. name: '高程(m)',
  205. nameTextStyle: {
  206. color: '#fff'
  207. },
  208. type: 'value',
  209. min: minYAxis,
  210. max: maxYAxis,
  211. splitLine: { show: false },
  212. axisLabel: {
  213. color: '#fff',
  214. inside: false,
  215. //margin: -(-minXAxis / (maxXAxis - minXAxis)) * 862 + 8,
  216. formatter: (value, index) => {
  217. if (value >= splitTick * 4 + minYAxis) {
  218. return value
  219. }
  220. }
  221. }
  222. }
  223. ],
  224. dataZoom: [
  225. {
  226. type: 'inside',
  227. filterMode: 'filter',
  228. xAxisIndex: 0,
  229. start: 0,
  230. end: 100
  231. }
  232. ],
  233. series: [
  234. {
  235. type: 'custom',
  236. silent: true,
  237. animation: false,
  238. zlevel: 0,
  239. renderItem: (params, api) => {
  240. if (params.context.rendered) {
  241. return
  242. }
  243. params.context.rendered = true
  244. var points = []
  245. for (var i = 0; i < backData.length; i++) {
  246. points.push(api.coord(backData[i]))
  247. }
  248. var color = api.visual('color')
  249. return {
  250. type: 'polygon',
  251. transition: ['shape'],
  252. shape: {
  253. points: points
  254. },
  255. style: api.style({
  256. fill: color,
  257. stroke: echarts.color.lift(color)
  258. })
  259. }
  260. },
  261. itemStyle: {
  262. color: {
  263. image: image,
  264. repeat: 'no-repeat'
  265. }
  266. },
  267. clip: true,
  268. data: backData
  269. },
  270. {
  271. name: '管点',
  272. type: 'scatter',
  273. zlevel: 4,
  274. tooltip: {
  275. formatter: (params) => {
  276. return this.crossResult[params.dataIndex].title
  277. }
  278. },
  279. markLine: {
  280. symbol: ['none', 'none'],
  281. silent: true,
  282. animation: false,
  283. lineStyle: {
  284. type: 'solid',
  285. color: '#696969',
  286. width: 2
  287. },
  288. data: data.map((item) => {
  289. return [
  290. { name: '', coord: [item.value[0], minYAxis] },
  291. { name: '', coord: [item.value[0], minYAxis + splitTick * 4] }
  292. ]
  293. })
  294. },
  295. data: data,
  296. animation: false
  297. },
  298. {
  299. name: '距离标注',
  300. type: 'scatter',
  301. symbol: 'emptyCircle',
  302. symbolSize: 1,
  303. silent: true,
  304. animation: false,
  305. label: {
  306. show: true,
  307. position: 'left',
  308. formatter: '{b}',
  309. fontWeight: 'bold',
  310. fontSize: 14,
  311. color: '#fff'
  312. },
  313. markLine: {
  314. symbol: ['none', 'none'],
  315. label: {
  316. show: false
  317. },
  318. lineStyle: {
  319. normal: {
  320. type: 'solid',
  321. width: 2
  322. }
  323. },
  324. data: [
  325. { yAxis: minYAxis },
  326. { yAxis: splitTick + minYAxis },
  327. { yAxis: splitTick * 2 + minYAxis },
  328. { yAxis: splitTick * 3 + minYAxis },
  329. { yAxis: splitTick * 4 + minYAxis }
  330. ]
  331. },
  332. markArea: {
  333. silent: true,
  334. label: {
  335. color: '#333'
  336. },
  337. itemStyle: {
  338. color: 'transparent',
  339. borderColor: '#ff0000',
  340. borderWidth: 0
  341. },
  342. data: pipeInfoArea
  343. },
  344. data: [
  345. { name: '间距(m)', value: [0, splitTick / 2 + minYAxis] },
  346. { name: '埋深(m)', value: [0, splitTick * 1.5 + minYAxis] },
  347. { name: '管径(mm)', value: [0, splitTick * 2.5 + minYAxis] },
  348. { name: '地面高程(m)', value: [0, splitTick * 3.5 + minYAxis] }
  349. ]
  350. },
  351. {
  352. name: '选中管线',
  353. type: 'scatter',
  354. zlevel: 3,
  355. symbol: 'circle',
  356. symbolSize: 1,
  357. slient: true,
  358. animation: false,
  359. markLine: {
  360. silent: true,
  361. animation: false,
  362. symbol: ['none', 'none'],
  363. lineStyle: {
  364. color: selectPipeColor,
  365. type: 'solid',
  366. width: selepipeLineSymbol
  367. },
  368. data: [[{ coord: [0, fromPoint.height] }, { coord: [maxXAxis, toPoint.height] }]]
  369. },
  370. data: [{ value: [0, maxHeight] }]
  371. }
  372. ]
  373. }
  374. this._echart.setOption(options)
  375. }
  376. }
  377. },
  378. watch: {
  379. drawSectionInfo: {
  380. handler(n, o) {
  381. this.crossResult = n.crossResult
  382. this.SelectPipe = n.SelectPipe
  383. this.crossLinePoints = n.crossLinePoints
  384. this.$nextTick(() => {
  385. this.drawSectionPicture()
  386. })
  387. },
  388. immediate: true
  389. }
  390. }
  391. }
  392. </script>
  393. <style>
  394. </style>