map.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>地图</title>
  6. <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  7. <link href="../css/mui.min.css" rel="stylesheet" />
  8. <link rel="stylesheet" type="text/css" href="../css/iconfont.css" />
  9. <link href="../css/common.css" rel="stylesheet" />
  10. <style type="text/css">
  11. .mui-content {
  12. position: absolute;
  13. left: 0;
  14. top: 0;
  15. bottom: 0;
  16. right: 0;
  17. }
  18. .mapCover {
  19. position: absolute;
  20. left: 0;
  21. top: 96px;
  22. bottom: 0;
  23. right: 0;
  24. }
  25. #map {
  26. width: 100%;
  27. position: fixed;
  28. top: 96px;
  29. bottom: 0px;
  30. line-height: 200px;
  31. text-align: center;
  32. background: #FFFFFF;
  33. }
  34. #btn {
  35. margin-top: 50px;
  36. width: 80%;
  37. left: 10%;
  38. }
  39. #NativewUI {
  40. margin-top: 50px;
  41. width: 80%;
  42. left: 10%;
  43. }
  44. .mui-popover {
  45. width: 160px;
  46. }
  47. /*#popover {
  48. display: block;
  49. top: 57px;
  50. left: 165px;
  51. }*/
  52. /*搜索框*/
  53. .searchBox {
  54. background-color: #eee;
  55. padding: 0px 8px;
  56. position: relative;
  57. margin-top: 10px;
  58. }
  59. .mui-search .mui-placeholder {
  60. text-align: left;
  61. left: 5px;
  62. }
  63. input[type=search] {
  64. background: #fff;
  65. }
  66. .mui-search .mui-placeholder .mui-icon {
  67. color: #777;
  68. }
  69. .searchBtnBox {
  70. position: absolute;
  71. right: 8px;
  72. top: 0px;
  73. z-index: 3;
  74. }
  75. #searchBtn {
  76. letter-spacing: 3px;
  77. line-height: 1.6;
  78. border: none;
  79. }
  80. .cutline {
  81. display: inline-block;
  82. border-left: .08em dashed #777;
  83. margin-top: 6px;
  84. }
  85. /*分类*/
  86. .mui-table-view-cell i {
  87. font-size: 18px;
  88. margin-right: 5px;
  89. }
  90. </style>
  91. </head>
  92. <body>
  93. <header class="mui-bar mui-bar-nav">
  94. <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  95. <h1 class="mui-title">设备分布图</h1>
  96. <a id="openPopover" class="mui-icon mui-icon-more mui-pull-right"></a>
  97. <!--<a class="fa fa-search mui-pull-right" id="searchBtn">搜索</a>-->
  98. </header>
  99. <div class="mui-content">
  100. <div class="faxSearchBox">
  101. <div class="mui-input-row mui-search">
  102. <input type="search" id="searchInp" placeholder="请输入设备ID">
  103. </div>
  104. <div class="searchBtnBox">
  105. <span class="cutline">&nbsp;</span>
  106. <button id="searchBtn">搜索</button>
  107. </div>
  108. </div>
  109. <div class="mapCover">
  110. <div id="map"></div>
  111. </div>
  112. </div>
  113. <script src="../js/mui.min.js"></script>
  114. <script src="../js/jquery-2.1.0.js"></script>
  115. <script src="../js/coordtransform_utils.js"></script><!--坐标偏移 -->
  116. <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=La58N63t7hPhafQ7Eror2kon"></script>
  117. <script type="text/javascript">
  118. var em = null,
  119. map = null;
  120. var floatw = null;
  121. // H5 plus事件处理
  122. window.addEventListener('requestPerson',function(event){
  123. //获得事件参数
  124. var id = event.detail.id;
  125. requestPerson = id;
  126. getdata(id)
  127. })
  128. function getdata(type){
  129. // mui('#popover').popover('toggle'); //show hide toggle
  130. var dtype = '';
  131. map.clearOverlays(); //清除全部
  132. if(type == 2 || type == 3 || type == 5 || type == 7 || type == 8) {
  133. if(type == 2) {
  134. dtype = 'scd';
  135. } else if(type == 3) {
  136. dtype = 'cbd';
  137. }else if(type == 5) {
  138. dtype = 'qxz';
  139. }else if(type == 7) {
  140. dtype = 'bzy';
  141. }else if(type == 8) {
  142. dtype = 'xyq';
  143. }
  144. $.ajax({
  145. type: "post",
  146. url: "http://120.27.222.26/home_map/map_locat",
  147. data: {
  148. req: dtype
  149. },
  150. timeout: 10000, //超时时间:30秒
  151. beforeSend: function() {
  152. plus.nativeUI.showWaiting("加载中...");
  153. },
  154. complete: function() {
  155. plus.nativeUI.closeWaiting();
  156. },
  157. dataType: "json",
  158. success: function(data) {
  159. // console.log(JSON.stringify(data))
  160. setmarker(data)
  161. },
  162. error:function(type){
  163. mui.toast('网络超时!')
  164. }
  165. });
  166. } else {
  167. $.ajax({
  168. type: "post",
  169. url: "http://120.27.222.26/home_map/map_locat",
  170. data: {
  171. req: 'scd'
  172. },
  173. timeout: 10000, //超时时间:30秒
  174. beforeSend: function() {
  175. plus.nativeUI.showWaiting("加载中...");
  176. },
  177. complete: function() {
  178. plus.nativeUI.closeWaiting();
  179. },
  180. dataType: "json",
  181. success: function(data) {
  182. // console.log(JSON.stringify(data))
  183. setmarker(data)
  184. },
  185. error:function(type){
  186. mui.toast('网络超时!')
  187. }
  188. });
  189. $.ajax({
  190. type: "post",
  191. url: "http://120.27.222.26/home_map/map_locat",
  192. data: {
  193. req: 'cbd'
  194. },
  195. timeout: 10000, //超时时间:30秒
  196. beforeSend: function() {
  197. plus.nativeUI.showWaiting("加载中...");
  198. },
  199. complete: function() {
  200. plus.nativeUI.closeWaiting();
  201. },
  202. dataType: "json",
  203. success: function(data) {
  204. // console.log(JSON.stringify(data))
  205. setmarker(data)
  206. },
  207. error:function(type){
  208. mui.toast('网络超时!')
  209. }
  210. });
  211. $.ajax({
  212. type: "post",
  213. url: "http://120.27.222.26/home_map/map_locat",
  214. data: {
  215. req: 'qxz'
  216. },
  217. timeout: 10000, //超时时间:30秒
  218. beforeSend: function() {
  219. plus.nativeUI.showWaiting("加载中...");
  220. },
  221. complete: function() {
  222. plus.nativeUI.closeWaiting();
  223. },
  224. dataType: "json",
  225. success: function(data) {
  226. // console.log(JSON.stringify(data))
  227. setmarker(data)
  228. },
  229. error:function(type){
  230. mui.toast('网络超时!')
  231. }
  232. });
  233. $.ajax({
  234. type: "post",
  235. url: "http://120.27.222.26/home_map/map_locat",
  236. data: {
  237. req: 'bzy'
  238. },
  239. timeout: 10000, //超时时间:30秒
  240. beforeSend: function() {
  241. plus.nativeUI.showWaiting("加载中...");
  242. },
  243. complete: function() {
  244. plus.nativeUI.closeWaiting();
  245. },
  246. dataType: "json",
  247. success: function(data) {
  248. // console.log(JSON.stringify(data))
  249. setmarker(data)
  250. },
  251. error:function(type){
  252. mui.toast('网络超时!')
  253. }
  254. });
  255. $.ajax({
  256. type: "post",
  257. url: "http://120.27.222.26/home_map/map_locat",
  258. data: {
  259. req: 'xyq'
  260. },
  261. timeout: 10000, //超时时间:30秒
  262. beforeSend: function() {
  263. plus.nativeUI.showWaiting("加载中...");
  264. },
  265. complete: function() {
  266. plus.nativeUI.closeWaiting();
  267. },
  268. dataType: "json",
  269. success: function(data) {
  270. // console.log(JSON.stringify(data))
  271. setmarker(data)
  272. },
  273. error:function(type){
  274. mui.toast('网络超时!')
  275. }
  276. });
  277. }
  278. }
  279. function setmarker(data){
  280. console.log(JSON.stringify(data))
  281. for(var i = 0;i<data.length;i++){
  282. if(data[i].equip_type == 2){
  283. var iconurl = '../images/2.png';
  284. var title = '杀虫灯设备';
  285. }else if(data[i].equip_type == 3){
  286. var iconurl = '../images/3.png';
  287. var title = '测报灯设备';
  288. }else if(data[i].equip_type == 5){
  289. var iconurl = '../images/1.png';
  290. var title = '环境监测设备';
  291. }else if(data[i].equip_type == 7){
  292. var iconurl = '../images/7.png';
  293. var title = '孢子仪设备';
  294. }else if(data[i].equip_type == 4){
  295. var iconurl = '../images/8.png';
  296. var title = '性诱设备';
  297. }
  298. if(data[i].equip_type == 2||data[i].equip_type == 3|| data[i].equip_type==4){
  299. if(data[i].gps == 0){
  300. var point = new plus.maps.Point(data[i].lng, data[i].lat);
  301. }else if(data[i].gps == 1){
  302. //convert wgs84 to cj02
  303. var cj02 = coordtransform.wgs84togcj02(data[i].lng, data[i].lat);//gps转火星定位
  304. //convert cj02 to bd09
  305. // var bd09 = coordtransform.gcj02tobd09(cj02[0], cj02[1]);//火星转百度定位
  306. var point = new plus.maps.Point(cj02[0], cj02[1]);
  307. }else if(data[i].gps == 2){
  308. // var baidulnglat = coordtransform.gcj02tobd09(data[i].lng, data[i].lat) //火星转百度定位
  309. var point = new plus.maps.Point(data[i].lng, data[i].lat);
  310. }
  311. }else if(data[i].equip_type == 5){
  312. var point = new plus.maps.Point(data[i].lng, data[i].lat);
  313. }else{
  314. var point = new plus.maps.Point(data[i].lng, data[i].lat);
  315. }
  316. var txt = title+'\n名称:'+data[i].equip_name+'\n设备号:'+data[i].equip_id;
  317. addMarker(point,iconurl,txt);
  318. }
  319. }
  320. function plusReady() {
  321. // 确保DOM解析完成
  322. if(!em || !window.plus || map) {
  323. return
  324. };
  325. map = new plus.maps.Map("map");
  326. map.centerAndZoom(new plus.maps.Point(105.740332,34.038286), 4);
  327. map.showZoomControls( true );
  328. //顶部右上角按钮menu触发弹出菜单
  329. document.getElementById('openPopover').addEventListener('tap', function() {
  330. floatWebview()
  331. })
  332. // 创建悬浮窗口
  333. function floatWebview() {
  334. if(floatw) { // 避免快速多次点击创建多个窗口
  335. floatw.show("fade-in");
  336. } else {
  337. floatw = plus.webview.create("map_nav.html", "map_nav", {
  338. background: 'transparent',
  339. zindex: 10,
  340. });
  341. floatw.show("fade-in");
  342. }
  343. }
  344. }
  345. if(window.plus) {
  346. plusReady();
  347. } else {
  348. document.addEventListener("plusready", plusReady, false);
  349. }
  350. // DOMContentloaded事件处理
  351. document.addEventListener("DOMContentLoaded", function() {
  352. em = document.getElementById("map");
  353. plusReady();
  354. }, false);
  355. // 编写自定义函数,创建标注
  356. function addMarker(point,iconurl,txt){
  357. var marker = new plus.maps.Marker(point);
  358. marker.setIcon(iconurl);
  359. var bubble = new plus.maps.Bubble(txt);
  360. marker.setBubble(bubble);
  361. map.addOverlay(marker);
  362. map.setZoom(4);
  363. map.setCenter(105.740332,34.038286);
  364. }
  365. //搜索
  366. $("#searchInp").on('keypress',function(e) {
  367. var keycode = e.keyCode;
  368. var searchName = $(this).val();
  369. if(keycode=='13') {
  370. //请求搜索接口
  371. searchFun(searchName)
  372. e.preventDefault();
  373. }
  374. });
  375. document.getElementById('searchBtn').addEventListener('tap', function() {
  376. var imei = document.getElementById('searchInp').value;
  377. searchFun(imei)
  378. })
  379. function searchFun(imei){
  380. map.clearOverlays(); //清除全部
  381. if(imei) {
  382. $.ajax({
  383. type: "post",
  384. url: "http://120.27.222.26/home_map/map_locat",
  385. data: {
  386. req: "imei",
  387. equip_id: imei
  388. },
  389. timeout: 10000, //超时时间:30秒
  390. dataType: "json",
  391. beforeSend: function() {
  392. plus.nativeUI.showWaiting("加载中...");
  393. },
  394. complete: function() {
  395. plus.nativeUI.closeWaiting();
  396. },
  397. success: function(data) {
  398. if(data == '0') {
  399. mui.toast("没有找到该设备,请核对设备id!");
  400. } else {
  401. setmarker(data)
  402. }
  403. },
  404. error:function(type){
  405. mui.toast('网络超时!')
  406. }
  407. });
  408. } else {
  409. mui.toast("请输入设备IMEI");
  410. }
  411. }
  412. </script>
  413. </body>
  414. </html>