map.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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/coordOffset.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. for(var i = 0;i<data.length;i++){
  281. if(data[i].equip_type == 2){
  282. var iconurl = '../images/2.png';
  283. var title = '杀虫灯设备';
  284. }else if(data[i].equip_type == 3){
  285. var iconurl = '../images/3.png';
  286. var title = '测报灯设备';
  287. }else if(data[i].equip_type == 5){
  288. var iconurl = '../images/1.png';
  289. var title = '环境监测设备';
  290. }else if(data[i].equip_type == 7){
  291. var iconurl = '../images/7.png';
  292. var title = '孢子仪设备';
  293. }else if(data[i].equip_type == 4){
  294. var iconurl = '../images/8.png';
  295. var title = '性诱设备';
  296. }
  297. if(data[i].equip_type == 2||data[i].equip_type == 3|| data[i].equip_type==4){
  298. if(data[i].gps == 0){
  299. var point = new plus.maps.Point(data[i].lng, data[i].lat);
  300. }else if(data[i].gps == 1){
  301. var GCj02 = wgs84togcj02(data[i].lng, data[i].lat); //gps转火星定位
  302. var baidulnglat = gcj02tobd09(GCj02[0],GCj02[1]) //火星转百度定位
  303. var point = new plus.maps.Point(baidulnglat[0], baidulnglat[1]);
  304. }else if(data[i].gps == 2){
  305. var baidulnglat = gcj02tobd09(data[i].lng, data[i].lat) //火星转百度定位
  306. var point = new plus.maps.Point(baidulnglat[0], baidulnglat[1]);
  307. }
  308. }else{
  309. var point = new plus.maps.Point(data[i].lng, data[i].lat);
  310. }
  311. var txt = title+'\n名称:'+data[i].equip_name+'\n设备号:'+data[i].equip_id;
  312. addMarker(point,iconurl,txt);
  313. }
  314. }
  315. function plusReady() {
  316. // 确保DOM解析完成
  317. if(!em || !window.plus || map) {
  318. return
  319. };
  320. map = new plus.maps.Map("map");
  321. map.centerAndZoom(new plus.maps.Point(105.740332,34.038286), 4);
  322. map.showZoomControls( true );
  323. //顶部右上角按钮menu触发弹出菜单
  324. document.getElementById('openPopover').addEventListener('tap', function() {
  325. floatWebview()
  326. })
  327. // 创建悬浮窗口
  328. function floatWebview() {
  329. if(floatw) { // 避免快速多次点击创建多个窗口
  330. floatw.show("fade-in");
  331. } else {
  332. floatw = plus.webview.create("map_nav.html", "map_nav", {
  333. background: 'transparent',
  334. zindex: 10,
  335. });
  336. floatw.show("fade-in");
  337. }
  338. }
  339. }
  340. if(window.plus) {
  341. plusReady();
  342. } else {
  343. document.addEventListener("plusready", plusReady, false);
  344. }
  345. // DOMContentloaded事件处理
  346. document.addEventListener("DOMContentLoaded", function() {
  347. em = document.getElementById("map");
  348. plusReady();
  349. }, false);
  350. // 编写自定义函数,创建标注
  351. function addMarker(point,iconurl,txt){
  352. var marker = new plus.maps.Marker(point);
  353. marker.setIcon(iconurl);
  354. var bubble = new plus.maps.Bubble(txt);
  355. marker.setBubble(bubble);
  356. map.addOverlay(marker);
  357. map.setZoom(4);
  358. map.setCenter(105.740332,34.038286);
  359. }
  360. //搜索
  361. $("#searchInp").on('keypress',function(e) {
  362. var keycode = e.keyCode;
  363. var searchName = $(this).val();
  364. if(keycode=='13') {
  365. e.preventDefault();
  366. //请求搜索接口
  367. searchFun(searchName)
  368. }
  369. });
  370. document.getElementById('searchBtn').addEventListener('tap', function() {
  371. var imei = document.getElementById('searchInp').value;
  372. searchFun(imei)
  373. })
  374. function searchFun(imei){
  375. if(imei) {
  376. $.ajax({
  377. type: "post",
  378. url: "http://120.27.222.26/home_map/map_locat",
  379. data: {
  380. req: "imei",
  381. equip_id: imei
  382. },
  383. timeout: 10000, //超时时间:30秒
  384. dataType: "json",
  385. beforeSend: function() {
  386. plus.nativeUI.showWaiting("加载中...");
  387. },
  388. complete: function() {
  389. plus.nativeUI.closeWaiting();
  390. },
  391. success: function(data) {
  392. if(data == '0') {
  393. mui.toast("没有找到该设备,请核对设备id!");
  394. map.clearOverlays(); //清除全部
  395. } else {
  396. map.clearOverlays(); //清除全部
  397. setmarker(data)
  398. }
  399. },
  400. error:function(type){
  401. mui.toast('网络超时!')
  402. }
  403. });
  404. } else {
  405. mui.toast("请输入设备IMEI");
  406. }
  407. }
  408. </script>
  409. </body>
  410. </html>