deviceMap.vue 8.1 KB

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