bigScreenMap.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. {% load staticfiles %}
  2. <!doctype html>
  3. <html>
  4. <head>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  8. <link rel="stylesheet" href="{% static 'bigData/css/reset.css'%}" media="all">
  9. <!-- <link rel="stylesheet" href="{% static 'font-awesome/4.5.0/css/font-awesome.css'%}" media="all"> -->
  10. <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
  11. <title>大数据平台</title>
  12. <style>
  13. #map {
  14. width: 100%;
  15. height: 100%;
  16. background: #01052d;
  17. }
  18. html,body{
  19. height: 100%;
  20. background: transparent;
  21. }
  22. /* 地图弹出框 */
  23. .custom-input-card {
  24. width: 18rem;
  25. }
  26. .custom-input-card .btn:last-child {
  27. margin-left: 1rem;
  28. }
  29. .content-window-card {
  30. position: relative;
  31. width: 23rem;
  32. /* padding: 0.75rem 0 0 1.25rem; */
  33. box-shadow: none;
  34. bottom: 0;
  35. left: 0;
  36. }
  37. .content-window-card p {
  38. height: 2rem;
  39. }
  40. .input-card {
  41. background-color: #00000063;
  42. }
  43. .amap-info-content {
  44. background-color: #00000063;
  45. border: 1px solid #288bc0;
  46. box-shadow: 0px 0px 5px 0px #4bfafd;
  47. color: #fff;
  48. }
  49. .amap-info-contentContainer:hover .amap-info-outer {
  50. box-shadow: 0px 0px 5px 0px #4bfafd;
  51. }
  52. .bottom-center .amap-info-sharp {
  53. border-top: 8px solid #2d92c6;
  54. }
  55. /* layui弹出框式样覆盖 */
  56. div.layui-layer-title {
  57. /* background-color: #3495c7; */
  58. background-color: #1c658b;
  59. color: #fff;
  60. border-bottom: 1px solid #082d48;
  61. }
  62. .layui-layer-content {
  63. background: #082d48;
  64. }
  65. </style>
  66. </head>
  67. <body>
  68. <div id="map"></div>
  69. <input type="hidden" id="type" value="{{type}}">
  70. <!-- 加载地图JSAPI脚本 -->
  71. <script src="https://webapi.amap.com/maps?v=1.4.15&key=3939967b919a8003377dd113fc445a3d&plugin=AMap.Geocoder"></script>
  72. <script src="{% static '/lib/js/jquery-2.1.4.min.js'%}"></script>
  73. <!-- <script src="{% static '/lib/layui/layui.js'%}"></script> -->
  74. <script>
  75. var map = new AMap.Map('map', {
  76. resizeEnable: true, //是否监控地图容器尺寸变化
  77. zoom: 11, //初始化地图层级
  78. center: [113.647216,34.743024] //初始化地图中心点
  79. });
  80. map.setMapStyle('amap://styles/blue');
  81. $.ajax({
  82. url: 'display_map',
  83. type: 'post',
  84. data: {
  85. type:$('#type').val()
  86. },
  87. dataType: 'json',
  88. success: function (data) {
  89. console.log(data)
  90. if(data.dat.length){
  91. reateMarke(data.dat, $('#type').val())
  92. }
  93. },
  94. error: function (type) {
  95. console.log(type)
  96. }
  97. })
  98. function reateMarke(capitals, all) {
  99. map.clearMap(); // 清除地图覆盖物
  100. var scd = 0, cbd = 0, bzy = 0, qxz = 0, jk = 0;
  101. for (var i = 0; i < capitals.length; i += 1) {
  102. if (capitals[i].equip_type == 2) {
  103. scd++;
  104. var bgColor = '#00e921';
  105. var animationName = 'myfirst01';
  106. var equipType = '杀虫灯';
  107. var icon = '../static/bigData/imgs/icon1.svg';
  108. } else if (capitals[i].equip_type == 3) {
  109. cbd++;
  110. var bgColor = '#fffa02';
  111. var animationName = 'myfirst02';
  112. var equipType = '测报灯';
  113. var icon = '../static/bigData/imgs/icon2.svg';
  114. } else if (capitals[i].equip_type == 5) {
  115. qxz++;
  116. var bgColor = '#4b1382';
  117. var animationName = 'myfirst03';
  118. var equipType = '环境监测';
  119. var icon = '../static/bigData/imgs/icon3.svg';
  120. } else if (capitals[i].equip_type == 6) {
  121. bzy++;
  122. var bgColor = '#ff7d00';
  123. var animationName = 'myfirst04';
  124. var equipType = '孢子仪';
  125. var icon = '../static/bigData/imgs/icon4.svg';
  126. } else if (capitals[i].equip_type == 7) {
  127. jk++;
  128. var bgColor = '#1b7ddd';
  129. var animationName = 'myfirst05';
  130. var equipType = '监控';
  131. var icon = '../static/bigData/imgs/icon5.svg';
  132. }
  133. if (all == 'all') {
  134. var currStatus = true;
  135. } else {
  136. var currStatus = capitals[i].equip_type == all
  137. }
  138. if (capitals[i].lng && capitals[i].lat && currStatus ) {
  139. var text = new AMap.Marker({
  140. map: map,
  141. position: [parseFloat(capitals[i].lng), parseFloat(capitals[i].lat)],
  142. icon: icon, // 添加 Icon 图标 URL
  143. title: "",
  144. // extData:{type:12,id:'00000000-0000-0000-0000-000000000000'} //用户自定义属性
  145. });
  146. //构建自定义信息窗体
  147. var info = [];
  148. info.push("<div class='input-card content-window-card'> ");
  149. info.push("<div style=\"padding:7px 0px 0px 0px;\"><div>" + equipType + "设备</div>");
  150. info.push("<p style=\"padding:7px 0px 0px 0px;\">设备IMEI :" + capitals[i].e_id + "</p>");
  151. info.push("<p class='input-item'>经度 : " + parseFloat(capitals[i].lng).toFixed(5) + " 纬度 : " + parseFloat(capitals[i].lat).toFixed(5) + "</p>");
  152. info.push("<p class='input-item' id='currAddress'>地址 :</p></div></div>");
  153. var content = info.join("");
  154. var place = [parseFloat(capitals[i].lng), parseFloat(capitals[i].lat)]
  155. addClickHandler(text, place, content) //标注点击事件
  156. text.setMap(this.map); //将标注添加到地图上
  157. }
  158. if (i == capitals.length - 1) {
  159. // $('#scdNum').html(scd);
  160. // $('#cbdNum').html(cbd);
  161. // $('#bzyNum').html(bzy);
  162. // $('#qxzNum').html(qxz);
  163. // $('#jkNum').html(jk);
  164. // $('#allNum').html(capitals.length);
  165. map.setFitView(); //标注在可视范围
  166. }
  167. }
  168. }
  169. function addClickHandler(marker, place, content) {
  170. marker.on("mouseover", function (e) {
  171. // 根据经纬度查询地址
  172. var geocoder;
  173. geocoder = new AMap.Geocoder({});
  174. geocoder.getAddress(place, function (status, result) {
  175. if (status === 'complete' && result.regeocode) {
  176. var address = result.regeocode.formattedAddress;
  177. $('#currAddress').html('地址 :' + address)
  178. } else {
  179. alert('根据经纬度查询地址失败')
  180. }
  181. });
  182. //在指定位置打开信息窗体
  183. var infoWindow = new AMap.InfoWindow({
  184. content: content, //使用默认信息窗体框样式,显示信息内容
  185. offset: new AMap.Pixel(5, -15)
  186. });
  187. infoWindow.open(map, place)
  188. });
  189. }
  190. </script>
  191. </body>
  192. </html>