point.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <!-- 引入 ECharts 文件 -->
  6. <script type="text/javascript" src="static/jquery-3.3.1.min.js"></script>
  7. <script src="static/echarts.min.js"></script>
  8. <script src="static/plug-in.min.js"></script>
  9. <link rel="stylesheet" href="static/index.css" media="all" />
  10. </head>
  11. <body>
  12. <div class="positon">
  13. <span>
  14. 底图:<select id="mapName">
  15. </select>
  16. </span>
  17. <span></span><span>水平位置: </span><input id="x"></input><span>,垂直位置: </span><input id="y"></input>
  18. <span id="y"><a class="ahref">保存位置</a></span>
  19. </div>
  20. <div class="point">
  21. </div>
  22. <div id="echart" class="echart"></div>
  23. <!-- <div class="data">
  24. <div>
  25. <span id="monthNum">暂无</span>
  26. </div>
  27. <div>
  28. <span id="waitNum">暂无</span>
  29. <span id="rate">暂无</span>
  30. </div>
  31. <div>
  32. <div id="weekJob" class="item title">
  33. <span>设备名称</span>
  34. <span>保养任务</span>
  35. <span>报修时间</span>
  36. </div>
  37. </div>
  38. </div> -->
  39. </body>
  40. <script>
  41. const ACCESS_TOKEN = 'Access-Token'
  42. const VUE_STORE_BASE = 'pro__'
  43. let mapList = []
  44. var id = window.location.search.split("id=")[1]
  45. id = filterUrlData(id);
  46. var xx = window.location.search.split("zjm=")[1];
  47. xx = filterUrlData(xx) || 0;
  48. var yy = window.location.search.split("jbdh=")[1] || 0;
  49. yy = filterUrlData(yy);
  50. var mapName = window.location.search.split("mapName=")[1];
  51. mapName = decodeURI(filterUrlData(mapName));
  52. function getMapList() {
  53. $.ajax({
  54. type: "GET",
  55. url: "/api/upms/files?type=56",
  56. headers: getHeader(),
  57. success: function (res) {
  58. var data = res.data
  59. mapList = data
  60. console.log(2);
  61. for (var i = 0; i < data.length; i++) {
  62. var option = '<option value="' + data[i].targetId + '">' + data[i].targetId + '</option>'
  63. $('#mapName').append(option)
  64. }
  65. if (!mapName) {
  66. mapName = mapList[0].targetId
  67. }
  68. img.src = mapList.find(item => item.targetId == mapName).url
  69. $('#mapName').val(mapName);
  70. }
  71. })
  72. }
  73. getMapList()
  74. // 初始化设备位置
  75. $(function () {
  76. $('#x').val(xx);
  77. $('#y').val(yy);
  78. console.log($('#mapName').val);
  79. $('.point').attr("style", 'left: ' + xx + 'px;top: ' + yy + 'px');
  80. $('#echart').click(function (e) {
  81. xx = e.pageX || 0;
  82. yy = e.pageY || 0;
  83. console.log(xx + ' ' + yy);
  84. $('#x').val(xx);
  85. $('#y').val(yy);
  86. $('.point').css('left', xx).css('top', yy);
  87. })
  88. $('#x').on('input', function (e) {
  89. xx = e.delegateTarget.value
  90. $('.point').attr("style", 'left: ' + xx + 'px;top: ' + yy + 'px')
  91. });
  92. $('#y').on('input', function (e) {
  93. yy = e.delegateTarget.value
  94. $('.point').attr("style", 'left: ' + xx + 'px;top: ' + yy + 'px')
  95. });
  96. $('#mapName').on('change', function (e) {
  97. mapName = e.delegateTarget.value
  98. img.src = mapList.find(item => item.targetId == mapName).url
  99. });
  100. $('.ahref').click(function (e) {
  101. if (id == null) {
  102. alert('请设置设备')
  103. return
  104. }
  105. if (xx == null || yy == null || xx == 0 || yy == 0) {
  106. alert('请点击位置,该位置将作为设备的显示位置')
  107. return
  108. }
  109. var data = { id: id, zjm: xx, jbdh: yy }
  110. $.ajax({
  111. type: "PUT",
  112. url: "/api/sb/infos/" + id,
  113. headers: getHeader(),
  114. data: JSON.stringify(data),
  115. success: function (response) {
  116. const data = response.data;
  117. alert("保存成功。")
  118. },
  119. error: function (xhr, textStatus, errorThrown) {
  120. error(xhr, textStatus, errorThrown);
  121. }
  122. });
  123. })
  124. })
  125. /**
  126. * filterUrlData 过滤url数据
  127. * @param Boolean {name}
  128. * @param Boolean {value}
  129. * @param Boolean {data}
  130. * Created by preference on 2020/08/01
  131. */
  132. function filterUrlData(data) {
  133. if (data) {
  134. var dataArr = data.split('');
  135. var tempArr = [];
  136. for (var i = 0; i <= dataArr.length; i++) {
  137. if (dataArr[i] != '&') {
  138. tempArr.push(dataArr[i]);
  139. } else {
  140. break;
  141. }
  142. }
  143. return tempArr.join('');
  144. }
  145. };
  146. // 基于准备好的dom,初始化echarts实例
  147. var myChart = echarts.init(document.getElementById('echart'))
  148. var img = new Image()
  149. var canvas = document.createElement('canvas')
  150. var ctx = canvas.getContext('2d')
  151. canvas.width = myChart.getWidth() * window.devicePixelRatio
  152. canvas.height = myChart.getHeight() * window.devicePixelRatio
  153. var fullImage = new Image()
  154. img.onload = function () {
  155. ctx.drawImage(img, 0, 0, canvas.width, canvas.height)
  156. fullImage.src = canvas.toDataURL()
  157. setTimeout(function () {
  158. myChart.resize()
  159. }, 100)
  160. }
  161. var option = {
  162. // 背景
  163. backgroundColor: {
  164. repeat: 'no-repeat',
  165. image: fullImage
  166. },
  167. // 地图
  168. geo: {
  169. map: 'world',
  170. silent: true,
  171. top: 0,
  172. left: 0,
  173. right: 0,
  174. bottom: 0,
  175. itemStyle: {
  176. normal: {
  177. opacity: 0.8,
  178. borderWidth: 0,
  179. color: '#a53d13'
  180. }
  181. }
  182. },
  183. title: {
  184. text: '',
  185. },
  186. // 开启工具栏
  187. tooltip: {
  188. "trigger": "item",
  189. "confine": true
  190. },
  191. series: [{
  192. name: '正常',
  193. type: 'effectScatter',
  194. coordinateSystem: 'geo',
  195. data: [
  196. ],
  197. showEffectOn: 'render',
  198. rippleEffect: {
  199. brushType: 'stroke'
  200. },
  201. hoverAnimation: true,
  202. label: {
  203. normal: {
  204. formatter: '{@value}',
  205. position: 'left',
  206. show: false
  207. }
  208. },
  209. itemStyle: {
  210. normal: {
  211. color: '#17bf9e',
  212. shadowBlur: 200,
  213. shadowColor: '#17bf9e'
  214. }
  215. },
  216. zlevel: 1
  217. }, {
  218. name: '异常点',
  219. type: 'scatter',
  220. coordinateSystem: 'geo',
  221. symbol: 'pin', // 气泡
  222. symbolSize: 50,
  223. label: {
  224. normal: {
  225. show: true,
  226. formatter: '{@value}',
  227. textStyle: {
  228. color: '#fff',
  229. fontSize: 11
  230. }
  231. }
  232. },
  233. itemStyle: {
  234. normal: {
  235. color: 'red'
  236. }
  237. },
  238. zlevel: 6,
  239. data: [
  240. ]
  241. }, {
  242. name: '异常图片和名称',
  243. type: 'effectScatter',
  244. coordinateSystem: 'geo',
  245. data: [
  246. ],
  247. showEffectOn: 'render',
  248. rippleEffect: {
  249. brushType: 'stroke'
  250. },
  251. hoverAnimation: true,
  252. label: {
  253. normal: {
  254. formatter: '{@value}',
  255. position: 'left',
  256. show: false
  257. }
  258. },
  259. itemStyle: {
  260. normal: {
  261. color: 'yellow',
  262. shadowBlur: 200,
  263. shadowColor: 'yellow'
  264. }
  265. },
  266. zlevel: 1
  267. }]
  268. }
  269. // 使用刚指定的配置项和数据显示图表
  270. myChart.setOption(option);
  271. function getHeader() {
  272. return {
  273. Authorization: getToken(),
  274. "Cache-Control": "no-cache",
  275. accept: "application/json; charset=utf-8",
  276. 'Content-Type': 'application/json;charset=UTF-8'
  277. // "Access-Control-Allow-Headers":"Origin, X-Requested-With, Content-Type, Accept"
  278. }
  279. }
  280. function getToken() {
  281. const storeTokenJson = JSON.parse(localStorage.getItem(VUE_STORE_BASE + ACCESS_TOKEN))
  282. return 'Bearer ' + storeTokenJson.value
  283. }
  284. </script>
  285. <style>
  286. .positon {
  287. position: absolute;
  288. top: 20px;
  289. left: 30%;
  290. z-index: 1000;
  291. }
  292. .point {
  293. position: absolute;
  294. padding: 5px;
  295. background: blue;
  296. border-radius: 5px;
  297. z-index: 1000;
  298. }
  299. #mapName {
  300. width: 120px;
  301. }
  302. .ahref {
  303. background: blue;
  304. padding: 8px;
  305. cursor: pointer;
  306. }
  307. </style>
  308. </html>