mapJs.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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. height: 100%;
  28. }
  29. #btn {
  30. margin-top: 50px;
  31. width: 80%;
  32. left: 10%;
  33. }
  34. #NativewUI {
  35. margin-top: 50px;
  36. width: 80%;
  37. left: 10%;
  38. }
  39. .mui-popover {
  40. width: 160px;
  41. }
  42. /*#popover {
  43. display: block;
  44. top: 57px;
  45. left: 165px;
  46. }*/
  47. /*搜索框*/
  48. .searchBox {
  49. background-color: #eee;
  50. padding: 0px 8px;
  51. position: relative;
  52. margin-top: 10px;
  53. }
  54. .mui-search .mui-placeholder {
  55. text-align: left;
  56. left: 5px;
  57. }
  58. input[type=search] {
  59. background: #fff;
  60. }
  61. .mui-search .mui-placeholder .mui-icon {
  62. color: #777;
  63. }
  64. .searchBtnBox {
  65. position: absolute;
  66. right: 8px;
  67. top: 0px;
  68. z-index: 3;
  69. }
  70. #searchBtn {
  71. letter-spacing: 3px;
  72. line-height: 1.6;
  73. border: none;
  74. }
  75. .cutline {
  76. display: inline-block;
  77. border-left: .08em dashed #777;
  78. margin-top: 6px;
  79. }
  80. /*分类*/
  81. .mui-table-view-cell i {
  82. font-size: 18px;
  83. margin-right: 5px;
  84. }
  85. </style>
  86. </head>
  87. <body>
  88. <header class="mui-bar mui-bar-nav">
  89. <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  90. <h1 class="mui-title">设备分布图</h1>
  91. <a href="#popover" id="openPopover" class="mui-icon mui-icon-more mui-pull-right"></a>
  92. <!--<a class="fa fa-search mui-pull-right" id="searchBtn">搜索</a>-->
  93. </header>
  94. <div class="mui-content">
  95. <div id="popover" class="mui-popover">
  96. <ul class="mui-table-view">
  97. <li class="mui-table-view-cell" data-id="2">
  98. <a href="#">
  99. <i class="iconfont">&#xe621;</i>杀虫灯
  100. </a>
  101. </li>
  102. <li class="mui-table-view-cell" data-id="3">
  103. <a href="#">
  104. <i class="iconfont">&#xe71f;</i>虫情测报
  105. </a>
  106. </li>
  107. <!--<li class="mui-table-view-cell" data-id="3">
  108. <a href="#">
  109. <i class="iconfont">&#xe604;</i>农药残留
  110. </a>
  111. </li>-->
  112. <li class="mui-table-view-cell" data-id="5">
  113. <a href="#">
  114. <i class="iconfont">&#xe60e;</i>环境监测
  115. </a>
  116. </li>
  117. <li class="mui-table-view-cell" data-id="7">
  118. <a href="#">
  119. <i class="iconfont">&#xe64e;</i>孢子仪
  120. </a>
  121. </li>
  122. <!--<li class="mui-table-view-cell" data-id="5">
  123. <a href="#">
  124. <i class="iconfont">&#xe645;</i>监控设备
  125. </a>
  126. </li>-->
  127. </ul>
  128. </div>
  129. <div class="faxSearchBox">
  130. <div class="mui-input-row mui-search">
  131. <input type="search" id="searchInp" placeholder="请输入设备ID">
  132. </div>
  133. <div class="searchBtnBox">
  134. <span class="cutline">&nbsp;</span>
  135. <button id="searchBtn">搜索</button>
  136. </div>
  137. </div>
  138. <div class="mapCover">
  139. <div id="map"></div>
  140. </div>
  141. </div>
  142. <script src="../js/mui.min.js"></script>
  143. <script src="../js/jquery-2.1.0.js"></script>
  144. <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=La58N63t7hPhafQ7Eror2kon"></script>
  145. <script type="text/javascript">
  146. mui.init();
  147. //百度地图获取坐标
  148. var map = new BMap.Map("map"); // 创建地图实例
  149. map.centerAndZoom(new BMap.Point(113.64964385, 34.75661006), 13); // 创建点坐标
  150. map.enableScrollWheelZoom(true);
  151. map.addControl(new BMap.ScaleControl()); // 添加比例尺控件
  152. map.addControl(new BMap.NavigationControl()); //为地图添加鱼骨(默认)
  153. map.addEventListener("tilesloaded", function() {
  154. $(".BMap_cpyCtrl").hide();
  155. geoc = new BMap.Geocoder();
  156. }); //地图加载完毕后 隐藏百度图标
  157. mui.plusReady(function() {
  158. if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
  159. mui.toast("网络异常,请检查网络设置!");
  160. }
  161. //请求数据:
  162. // $.ajax({
  163. // type: "post",
  164. // url: "http://120.27.222.26/home_map/map_locat",
  165. // data: {
  166. // req: "cbd",
  167. // },
  168. // timeout:10000, //超时时间:30秒
  169. // beforeSend: function() {
  170. // plus.nativeUI.showWaiting("加载中...");
  171. // },
  172. // complete: function() {
  173. // plus.nativeUI.closeWaiting();
  174. // },
  175. // dataType: "json",
  176. // success: function(data) {
  177. // // plus.nativeUI.closeWaiting();
  178. // eachItem(data)
  179. // },
  180. // error:function(type){
  181. // mui.toast('网络超时!')
  182. // }
  183. // });
  184. // $.ajax({
  185. // type: "post",
  186. // url: "http://120.27.222.26/home_map/map_locat",
  187. // data: {
  188. // req: "scd",
  189. // },
  190. // timeout: 10000, //超时时间:30秒
  191. // beforeSend: function() {
  192. // plus.nativeUI.showWaiting("加载中...");
  193. // },
  194. // complete: function() {
  195. // plus.nativeUI.closeWaiting();
  196. // },
  197. // dataType: "json",
  198. // success: function(data) {
  199. // // eachItem(data)
  200. // },
  201. // error:function(type){
  202. // mui.toast('网络超时!')
  203. // }
  204. // });
  205. //搜索
  206. $("#searchInp").on('keypress',function(e) {
  207. var keycode = e.keyCode;
  208. var searchName = $(this).val();
  209. if(keycode=='13') {
  210. e.preventDefault();
  211. //请求搜索接口
  212. searchFun(searchName)
  213. }
  214. });
  215. document.getElementById('searchBtn').addEventListener('tap', function() {
  216. var imei = document.getElementById('searchInp').value;
  217. searchFun(imei)
  218. })
  219. function searchFun(imei){
  220. if(imei) {
  221. $.ajax({
  222. type: "post",
  223. url: "http://120.27.222.26/home_map/map_locat",
  224. data: {
  225. req: "imei",
  226. equip_id: imei
  227. },
  228. timeout: 10000, //超时时间:30秒
  229. dataType: "json",
  230. beforeSend: function() {
  231. plus.nativeUI.showWaiting("加载中...");
  232. },
  233. complete: function() {
  234. plus.nativeUI.closeWaiting();
  235. },
  236. success: function(data) {
  237. if(data == '0') {
  238. mui.toast("没有找到该设备,请核对设备id!");
  239. map.clearOverlays(); //清除全部
  240. } else {
  241. map.clearOverlays(); //清除全部
  242. eachItem(data)
  243. }
  244. },
  245. error:function(type){
  246. mui.toast('网络超时!')
  247. }
  248. });
  249. } else {
  250. mui.toast("请输入设备IMEI");
  251. }
  252. }
  253. //右上角种类查询
  254. mui('#popover').on('tap', 'li', function() {
  255. mui('#popover').popover('toggle'); //show hide toggle
  256. var dtype = '';
  257. var type = this.getAttribute('data-id');
  258. if(type == 2 || type == 3 || type == 5 || type == 7) {
  259. if(type == 2) {
  260. dtype = 'scd';
  261. } else if(type == 3) {
  262. dtype = 'cbd';
  263. }else if(type == 5) {
  264. dtype = 'qxz';
  265. }else if(type == 7) {
  266. dtype = 'bzy';
  267. }
  268. map.clearOverlays(); //清除全部
  269. $.ajax({
  270. type: "post",
  271. url: "http://120.27.222.26/home_map/map_locat",
  272. data: {
  273. req: dtype
  274. },
  275. timeout: 10000, //超时时间:30秒
  276. beforeSend: function() {
  277. plus.nativeUI.showWaiting("加载中...");
  278. },
  279. complete: function() {
  280. plus.nativeUI.closeWaiting();
  281. },
  282. dataType: "json",
  283. success: function(data) {
  284. console.log(data)
  285. map.clearOverlays(); //清除全部
  286. // console.log(JSON.stringify(data))
  287. eachItem(data)
  288. },
  289. error:function(type){
  290. mui.toast('网络超时!')
  291. }
  292. });
  293. } else {
  294. mui.toast("此功能暂未开启!");
  295. }
  296. console.log(this.getAttribute('data-id'))
  297. })
  298. // }
  299. })
  300. /**
  301. * WGS84转GCj02
  302. * @param lng
  303. * @param lat
  304. * @returns {*[]}
  305. */
  306. //定义一些常量
  307. var x_PI = 3.14159265358979324 * 3000.0 / 180.0;
  308. var PI = 3.1415926535897932384626;
  309. var a = 6378245.0;
  310. var ee = 0.00669342162296594323;
  311. function wgs84togcj02(lng, lat) {
  312. var lat = +lat;
  313. var lng = +lng;
  314. var dlat = transformlat(lng - 105.0, lat - 35.0);
  315. var dlng = transformlng(lng - 105.0, lat - 35.0);
  316. var radlat = lat / 180.0 * PI;
  317. var magic = Math.sin(radlat);
  318. magic = 1 - ee * magic * magic;
  319. var sqrtmagic = Math.sqrt(magic);
  320. dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
  321. dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
  322. var mglat = lat + dlat;
  323. var mglng = lng + dlng;
  324. return [mglng, mglat]
  325. };
  326. /**
  327. * 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
  328. * 即谷歌、高德 转 百度
  329. * @param lng
  330. * @param lat
  331. * @returns {*[]}
  332. */
  333. function gcj02tobd09(lng, lat) {
  334. var lat = +lat;
  335. var lng = +lng;
  336. var z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
  337. var theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
  338. var bd_lng = z * Math.cos(theta) + 0.0065;
  339. var bd_lat = z * Math.sin(theta) + 0.006;
  340. return [bd_lng, bd_lat]
  341. };
  342. var transformlat = function transformlat(lng, lat) {
  343. var lat = +lat;
  344. var lng = +lng;
  345. var ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
  346. ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
  347. ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
  348. ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
  349. return ret
  350. };
  351. var transformlng = function transformlng(lng, lat) {
  352. var lat = +lat;
  353. var lng = +lng;
  354. var ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
  355. ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
  356. ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
  357. ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
  358. return ret
  359. };
  360. // function eachItem(data_info) {
  361. // console.log(data_info)
  362. // var pointArray = [];
  363. // for(var i = 0; i < data_info.length; i++) {
  364. // if(data_info[i].lng > 999) {
  365. // var lng = Math.floor(data_info[i].lng / 100) + ((data_info[i].lng % 100) / 60);
  366. // var lat = Math.floor(data_info[i].lat / 100) + ((data_info[i].lat % 100) / 60);
  367. //// console.log(lng, lat)
  368. // } else {
  369. // var lat = data_info[i].lat;
  370. // var lng = data_info[i].lng;
  371. // }
  372. // if(data_info[i].lng && data_info[i].lat){
  373. // //标注图标
  374. // var orgType = data_info[i].equip_type; //parseInt(0) data_info[i].equip_type
  375. // if(orgType == 7) {
  376. // var equip_type = '孢子仪';
  377. // var myIcon = new BMap.Icon("../images/locationIcon.png", new BMap.Size(17, 23), {
  378. // offset: new BMap.Size(0, -18),
  379. // imageOffset: new BMap.Size(0, 0 - 0 * 23)
  380. // });
  381. // }else if(orgType == 5) {
  382. // var equip_type = '环境监测';
  383. // var myIcon = new BMap.Icon("../images/locationIcon.png", new BMap.Size(17, 23), {
  384. // offset: new BMap.Size(0, -18),
  385. // imageOffset: new BMap.Size(0, 0 - 1 * 23)
  386. // });
  387. // } else if(orgType == 2) {
  388. // var equip_type = '杀虫灯';
  389. // var myIcon = new BMap.Icon("../images/locationIcon.png", new BMap.Size(17, 23), {
  390. // offset: new BMap.Size(0, -18),
  391. // imageOffset: new BMap.Size(0, 0 - 2 * 23)
  392. // });
  393. // } else if(orgType == 3) {
  394. // var equip_type = '虫情测报';
  395. // var myIcon = new BMap.Icon("../images/locationIcon.png", new BMap.Size(17, 23), {
  396. // offset: new BMap.Size(0, -18),
  397. // imageOffset: new BMap.Size(0, 0 - 3 * 23)
  398. // });
  399. // } else if(orgType == 4) {
  400. // var equip_type = '农药残留';
  401. // var myIcon = new BMap.Icon("../images/locationIcon.png", new BMap.Size(17, 23), {
  402. // offset: new BMap.Size(0, -18),
  403. // imageOffset: new BMap.Size(0, 0 - 4 * 23)
  404. // });
  405. // } else if(orgType == 6) {
  406. // var equip_type = '监控设备';
  407. // var myIcon = new BMap.Icon("../images/locationIcon.png", new BMap.Size(17, 23), {
  408. // offset: new BMap.Size(0, -18),
  409. // imageOffset: new BMap.Size(0, 0 - 5 * 23)
  410. // });
  411. // }
  412. // var lng1 = wgs84togcj02(lng, lat);
  413. // var lng2 = gcj02tobd09(lng1[0], lng1[1]);
  414. //// pointArray[i] = new BMap.Point(lng2[0], lng2[1]);
  415. // pointArray.push(new BMap.Point(lng2[0], lng2[1]))
  416. //
  417. // var marker = new BMap.Marker(new BMap.Point(lng2[0], lng2[1]), {
  418. // icon: myIcon
  419. // }); // 创建标注
  420. // map.addOverlay(marker);
  421. // var enterNum = equip_type; //data_info[i].equip_name
  422. // var content = '<p>名称:' + data_info[i].equip_name + '</p><p>IMEI:' + data_info[i].equip_id + '</p><p>经度:' + lng2[0] + '</p><p>维度:' + lng2[1] + '</p><p>位置:' + data_info[i].equip_location + '</p>';
  423. //
  424. // // 将标注添加到地图中
  425. // addClickHandler(content, marker, enterNum);
  426. // }
  427. //
  428. //
  429. // if(i == data_info.length-1){
  430. // //让所有点在视野范围内
  431. // map.setViewport(pointArray);
  432. // }
  433. //
  434. // }
  435. //
  436. // }
  437. //测试
  438. function eachItem(data_info) {
  439. console.log(data_info)
  440. var points = []; // 添加海量点数据
  441. for (var i = 0; i < data_info.length; i++) {
  442. if (data_info[i].lng > 999) {
  443. var lng = Math.floor(data_info[i].lng / 100) + ((data_info[i].lng % 100) / 60);
  444. var lat = Math.floor(data_info[i].lat / 100) + ((data_info[i].lat % 100) / 60);
  445. } else {
  446. var lat = data_info[i].lat;
  447. var lng = data_info[i].lng;
  448. }
  449. if (data_info[i].lat && data_info[i].lng) {
  450. //标注图标
  451. var orgType = data_info[i].equip_type;//parseInt(0) data_info[i].equip_type
  452. if (orgType == 5) {
  453. var equip_type = '环境监测';
  454. var options = {
  455. size: BMAP_POINT_SIZE_BIG,
  456. shape: BMAP_POINT_SHAPE_CIRCLE,
  457. color: '#001dff'
  458. }
  459. // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 1 * 23) });
  460. } else if (orgType == 2) {
  461. var equip_type = '杀虫灯';
  462. var options = {
  463. size: BMAP_POINT_SIZE_BIG,
  464. shape: BMAP_POINT_SHAPE_CIRCLE,
  465. color: '#ff6600'
  466. }
  467. // var myIcon = new BMap.Icon("/static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 2 * 23) });
  468. } else if (orgType == 3) {
  469. var equip_type = '虫情测报';
  470. var options = {
  471. size: BMAP_POINT_SIZE_BIG,
  472. shape: BMAP_POINT_SHAPE_CIRCLE,
  473. color: '#9c1ee4'
  474. }
  475. // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -13), imageOffset: new BMap.Size(0, 0 - 3 * 23) });
  476. } else if (orgType == 4) {
  477. var equip_type = '性诱器设备';
  478. var options = {
  479. size: BMAP_POINT_SIZE_BIG,
  480. shape: BMAP_POINT_SHAPE_CIRCLE,
  481. color: '#ff2da9'
  482. }
  483. // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 6 * 23) });
  484. } else if (orgType == 6) {
  485. var equip_type = '监控设备';
  486. var options = {
  487. size: BMAP_POINT_SIZE_BIG,
  488. shape: BMAP_POINT_SHAPE_CIRCLE,
  489. color: 'green'
  490. }
  491. // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 5 * 23) });
  492. } else if (orgType == 7) {
  493. var equip_type = '孢子仪设备';
  494. var options = {
  495. size: BMAP_POINT_SIZE_BIG,
  496. shape: BMAP_POINT_SHAPE_CIRCLE,
  497. color: '#ff0000'
  498. }
  499. // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 0 * 23) });
  500. } else if (orgType == 8) {
  501. var equip_type = '农药残留';
  502. var options = {
  503. size: BMAP_POINT_SIZE_BIG,
  504. shape: BMAP_POINT_SHAPE_CIRCLE,
  505. color: '#ff7600'
  506. }
  507. // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 4 * 23) });
  508. }
  509. // console.log(lat,lng);
  510. var lng1 = wgs84togcj02(lng, lat);
  511. var lng2 = gcj02tobd09(lng1[0], lng1[1]);
  512. // console.log(lng1,lng2);
  513. // pointArray[i] = new BMap.Point(lng2[0], lng2[1]);
  514. // pointArray.push(new BMap.Point(lng2[0], lng2[1]))
  515. var point = new BMap.Point(lng2[0], lng2[1]);
  516. point.equip_id= data_info[i].equip_id;
  517. point.equip_name= data_info[i].equip_name;
  518. point.equip_type = equip_type;
  519. point.orgType = orgType;
  520. points.push(point);
  521. // var enterNum = equip_type;//data_info[i].equip_name
  522. // var content = '<p>名称:' + data_info[i].equip_name + '</p><p class="gotoDetial" onclick="gotoManageDetial(\'' + data_info[i].equip_id + ' \',' + orgType + ')">IMEI:' + data_info[i].equip_id + '</p><p>经度:' + lng2[0] + '</p><p>纬度:' + lng2[1] + '</p><p class="area">位置:' + data_info[i].equip_location + '</p></br>';
  523. // if (data_info[i].equip_location) {
  524. // var flag = true;
  525. // } else {
  526. // var flag = false;
  527. // }
  528. // 将标注添加到地图中
  529. // addClickHandler(content, marker, enterNum, flag);
  530. }
  531. }
  532. var pointCollection = new BMap.PointCollection(points, options); // 初始化PointCollection
  533. pointCollection.addEventListener('click', function (e) {
  534. var point = new BMap.Point(e.point.lng, e.point.lat);
  535. geoc.getLocation(point, function (rs) {
  536. var addComp = rs.addressComponents;
  537. $('.area').html('位置:' + addComp.province + ", " + addComp.city + ", " + addComp.district)
  538. // alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
  539. });
  540. var opts = {
  541. width: 200, // 信息窗口宽度
  542. height: 150, // 信息窗口高度
  543. title: e.point.equip_type, // 信息窗口标题
  544. enableMessage: true//设置允许信息窗发送短息
  545. };
  546. console.log(e.point)
  547. console.log(e.point.equip_location)
  548. var content = '<p>名称:' + e.point.equip_name + '</p><p class="gotoDetial" onclick="gotoManageDetial(\'' + e.point.equip_id + ' \',' + e.point.orgType + ')">IMEI:' + e.point.equip_id + '</p><p>经度:' + e.point.lng + '</p><p>纬度:' + e.point.lat + '</p><p class="area">位置:' + e.point.equip_location + '</p></br>';
  549. var infowindow = new BMap.InfoWindow(content, opts);
  550. map.openInfoWindow(infowindow, point);
  551. // alert('单击点的坐标为:' + e.point.lng + ',' + e.point.lat); // 监听点击事件
  552. });
  553. map.addOverlay(pointCollection); // 添加Overlay
  554. //让所有点在视野范围内
  555. map.setViewport(points);
  556. }
  557. //测试
  558. function addClickHandler(content, marker, enterNum) {
  559. marker.addEventListener("click", function(e) {
  560. openInfo(content, e, enterNum)
  561. });
  562. }
  563. function openInfo(content, event, orgname) {
  564. var p = event.target;
  565. var opts = {
  566. title: orgname, // 信息窗口标题
  567. enableMessage: true //设置允许信息窗发送短息
  568. };
  569. var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
  570. var infoWindow = new BMap.InfoWindow(content, opts); // 创建信息窗口对象
  571. map.openInfoWindow(infoWindow, point); //开启信息窗口
  572. }
  573. </script>
  574. </body>
  575. </html>