deviceMap.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <!-- -->
  2. <template>
  3. <div class="component_box">
  4. <h1 class="t_title">设备分布</h1>
  5. <div ref="chart" style="height: 100%"></div>
  6. </div>
  7. </template>
  8. <script>
  9. import * as echarts from "echarts";
  10. import { getMap, mapInfo } from "@/api/board/cockpit.js";
  11. import { deviceCountOfChildren } from "@/api/iot/board";
  12. export default {
  13. props: ["orgId", "orgName"],
  14. data() {
  15. return {
  16. map: {},
  17. deviceCount: {},
  18. coordinates: [],
  19. icon: "image://data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAAUCAYAAABvVQZ0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAF3SURBVDhPvZTBK4RBGIe/z56UklDay+6JkhM3RYo/wVlOrg4uTtyc3JSrg6Lc2CQHp5U7RyVylBBJXD7PO/PO7M43Y3OQp57mfd/fzOz6dlf2LxRFMYLr2hro63io7e/gQI53uKwjA303Cr06CujStcwV1rCHg3Kpgf4E1/CBtsraGTbN4wv24Q0K2/hsy2IFN/FJj6Rhw4zshg2ctGVxodkcfmET+/EVd8zBFISXKH+O1HtSQ92EQD2Bo1rfSggLJmyHoQvNZYK27nKXm3fDGu030I/ZsecDh/DIdCHy9Ti1peceK+6yFGeaLaE8q1UcxllMYR8HxYHtI4IHTO8+oDJvOOA2VfFTpgm2zCagfrejiIZuaaFBhGb+gZfYNYfLEKQeuFDBny7zX50IwvIn1emdTZlDSuq3ua+r41rX8jzL87ypZQyvVLMvGDCoseTuV+EI/kUFEB7bPZ5FjTw6b2dcoxYMGzbznGsUwHzaxp5Hjf6SLPsG2jnZyz2k38wAAAAASUVORK5CYII=",
  20. };
  21. },
  22. components: {},
  23. computed: {},
  24. watch: {
  25. orgId: {
  26. deep: true,
  27. handler(val) {
  28. // this.resetTimer();
  29. this.getData();
  30. },
  31. },
  32. // map: {
  33. // deep: true,
  34. // handler() {
  35. // this.$nextTick(() => {
  36. // this.initMap();
  37. // });
  38. // },
  39. // },
  40. },
  41. created() {
  42. // this.types = types;
  43. // this.maxDisplay = 16;
  44. // this.refreshTime = 1 * 10 * 1000;
  45. this.isMouseOver = false;
  46. },
  47. async mounted() {
  48. // console.info(this.fjMap)
  49. window.addEventListener("resize", this.windowResize);
  50. },
  51. beforeDestroy() {
  52. this.timer && clearInterval(this.timer);
  53. this.timer = null;
  54. window.removeEventListener("resize", this.windowResize);
  55. },
  56. methods: {
  57. // handleClick() {
  58. // this.resetTimer();
  59. // this.getData();
  60. // },
  61. handleMouseEnter() {
  62. this.isMouseOver = true;
  63. },
  64. handleMouseLeave() {
  65. this.isMouseOver = false;
  66. },
  67. async getData() {
  68. let mapinfo = await mapInfo(this.orgId);
  69. let deviceCount = (await deviceCountOfChildren(this.orgId)).data;
  70. let orgIdsHasDevice = deviceCount.map((d) => d.orgId);
  71. let map = mapinfo.data.map;
  72. let coordinates = mapinfo.data.sites
  73. .filter((s) => orgIdsHasDevice.includes(s.orgId))
  74. .map((s) => ({
  75. name: s.orgName,
  76. id: s.orgId,
  77. value: [s.longitude, s.latitude, 10],
  78. }));
  79. this.map = map;
  80. this.coordinates = coordinates;
  81. this.deviceCount = deviceCount;
  82. this.$nextTick(() => {
  83. this.initMap();
  84. });
  85. },
  86. initMap() {
  87. this.myChart && this.myChart.dispose();
  88. // 基于准备好的dom,初始化echarts实例
  89. this.myChart = echarts.init(this.$refs["chart"]);
  90. let t = this;
  91. getMap(this.map).then((data) => {
  92. echarts.registerMap("map", data);
  93. let option = {
  94. tooltip: {
  95. trigger: "item",
  96. },
  97. geo: {
  98. show: true,
  99. map: "map",
  100. zoom: 1.25,
  101. showLegendSymbol: false, // 存在legend时显示
  102. emphasis: {
  103. show: false,
  104. color: "#fff", //悬浮字体颜色
  105. label: {
  106. show: false,
  107. color: "#c1b496", //控制地图省市文字颜色
  108. fontSize: 14,
  109. },
  110. emphasis: {
  111. borderWidth: 1,
  112. borderColor: "#fff",
  113. areaColor: "#2B91B7",
  114. },
  115. },
  116. roam: true,
  117. selectedMode: "single", //选择模式,单选,只能选中一个地市
  118. select: {
  119. //这个就是鼠标点击后,地图想要展示的配置
  120. disabled: false, //可以被选中
  121. itemStyle: {
  122. //相关配置项很多,可以参考echarts官网
  123. borderWidth: 1, //区域边框宽度
  124. borderColor: "#2B91B7ff", //区域边框颜色
  125. areaColor: "#2B91B730", //选中
  126. },
  127. label: {
  128. show: false,
  129. color: "#fff", //悬浮字体颜色
  130. },
  131. },
  132. itemStyle: {
  133. borderWidth: 1, //区域边框宽度
  134. borderColor: "#3fdaffff", //区域边框颜色
  135. areaColor: "#3fdaff55", //区域颜色"rgba(23,107,221,0.7)",//
  136. },
  137. },
  138. legend: [
  139. {
  140. selectedMode: true, //取消图例上的点击事件
  141. },
  142. ],
  143. series: [
  144. {
  145. map: "map",
  146. type: "effectScatter",
  147. // silent: true,
  148. coordinateSystem: "geo",
  149. // datasetIndex: 0,
  150. // geoIndex: 0,
  151. // selectedMode: false,
  152. // focusNodeAdjacency: false,
  153. // label: {
  154. // show: true,
  155. // width: 13,
  156. // height: 15,
  157. // fontSize: 0,
  158. // color: "#1DF9FC",
  159. // backgroundColor: {
  160. // image: iconRQ
  161. // },
  162. // },
  163. label: {
  164. formatter: (param) => {
  165. return param.name;
  166. },
  167. position: "top",
  168. fontSize: "10",
  169. color: "#fff",
  170. show: true,
  171. },
  172. tooltip: {
  173. show: false,
  174. },
  175. tooltip: {
  176. position: "right",
  177. textStyle: {
  178. // color:'#fff',
  179. },
  180. // backgroundColor:'rgba(184,189,192,1)',
  181. formatter: function (param) {
  182. // debugger
  183. let deviceCount = t.deviceCount.find(
  184. (d) => d.orgId == param.data.id
  185. );
  186. // console.info(deviceCount)
  187. if (deviceCount) {
  188. return `<div >
  189. <div> ${param.data.name} </div>
  190. <div>视频监控设备:${
  191. deviceCount.monitorCount ? deviceCount.monitorCount : 0
  192. } </div>
  193. <div>消防预警设备:${
  194. deviceCount.fireCount ? deviceCount.fireCount : 0
  195. } </div>
  196. <div>环境监测设备:${
  197. deviceCount.environmentCount
  198. ? deviceCount.environmentCount
  199. : 0
  200. } </div>
  201. </div>`;
  202. } else {
  203. return param.data.name;
  204. }
  205. },
  206. },
  207. itemStyle: {
  208. color: "#ddb926",
  209. },
  210. symbol: this.icon, //自定义图标
  211. symbolSize: [10, 10],
  212. // encode: {
  213. // value: 2,
  214. // },
  215. // showEffectOn: "emphasis", //关闭涟漪
  216. // hoverEffectOn: true,
  217. rippleEffect: {
  218. brushType: "fill",
  219. period: 0,
  220. number: 0,
  221. },
  222. data: this.coordinates,
  223. },
  224. ],
  225. };
  226. if (option && typeof option === "object") {
  227. this.myChart.setOption(option);
  228. }
  229. });
  230. },
  231. windowResize() {
  232. this.myChart && this.myChart.resize();
  233. },
  234. },
  235. };
  236. </script>
  237. <style scoped src="./../css/index.css"></style>
  238. <style lang="scss" scoped>
  239. .content {
  240. display: flex;
  241. margin-bottom: 20px;
  242. margin-left: 5px;
  243. margin-right: 5px;
  244. border: solid 1px #b8bdc088;
  245. & > span {
  246. margin-right: 10px;
  247. padding-top: 5px;
  248. padding-bottom: 5px;
  249. height: 30px;
  250. color: rgb(245, 245, 245);
  251. font-size: 14px;
  252. }
  253. & > span:first-child {
  254. width: 100px;
  255. background-color: #b8bdc088;
  256. text-align: center;
  257. }
  258. }
  259. .t_title {
  260. position: absolute;
  261. font-size: 16px;
  262. font-weight: 700;
  263. color: #fff;
  264. margin-left: 5%;
  265. margin-top: calc(5% + 18px);
  266. }
  267. </style>