home_map.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. /**
  2. * Created by Wandergis on 2015/7/8.
  3. * 提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换
  4. */
  5. var map, geoc;
  6. $.ajax({
  7. type: "post",
  8. url: "user_location",
  9. data: {
  10. // req: "cbd",
  11. },
  12. dataType: "json",
  13. success: function (data) {
  14. //百度地图获取坐标
  15. map = new BMap.Map("allmap", { });// 创建地图实例
  16. // map = new BMap.Map("allmap", { mapType: BMAP_HYBRID_MAP });// 创建地图实例
  17. // map.centerAndZoom(new BMap.Point(113.64964385, 34.75661006), 13);// 创建点坐标
  18. var parentUserName = $('#parentUserName', parent.document).html();
  19. if (parentUserName == '罗普特') {
  20. map.centerAndZoom(new BMap.Point(112.55, 37.87), 13);// 创建点坐标
  21. } else if (data.user_pro != '' || data.user_city != '' ||data.user_area != '') {
  22. if(data.user_area){
  23. map.centerAndZoom(data.user_area,11);
  24. }else if(data.user_city){
  25. map.centerAndZoom(data.user_city,11);
  26. }else{
  27. map.centerAndZoom(data.user_pro,11);
  28. }
  29. }else{
  30. map.centerAndZoom(new BMap.Point(113.64964385, 34.75661006), 13);// 创建点坐标
  31. }
  32. map.enableScrollWheelZoom(true);
  33. map.addControl(new BMap.NavigationControl()); // 添加平移缩放控件
  34. map.addControl(new BMap.ScaleControl()); // 添加比例尺控件
  35. map.addControl(new BMap.OverviewMapControl()); //添加缩略地图控件
  36. map.enableScrollWheelZoom(); //启用滚轮放大缩小
  37. map.addControl(new BMap.MapTypeControl()); //添加地图类型控件
  38. // map.setMapStyle({style:'midnight'});
  39. map.addEventListener("tilesloaded", function () {
  40. $(".BMap_cpyCtrl").hide();
  41. // $(".anchorBL").hide();
  42. });//地图加载完毕后 隐藏百度图标
  43. geoc = new BMap.Geocoder();
  44. if ($('.content').height() > 750) {
  45. $('#iframe-main', parent.document).css('height', $('.content').height() + 20)
  46. } else {
  47. $('#iframe-main', parent.document).css('height', '750px')
  48. }
  49. }
  50. });
  51. // //百度地图获取坐标
  52. // var map = new BMap.Map("allmap", { mapType: BMAP_HYBRID_MAP });// 创建地图实例
  53. // // map.centerAndZoom(new BMap.Point(113.64964385, 34.75661006), 13);// 创建点坐标
  54. // var parentUserName = $('#parentUserName', parent.document).html();
  55. // if (parentUserName == '罗普特') {
  56. // map.centerAndZoom(new BMap.Point(112.55, 37.87), 13);// 创建点坐标
  57. // } else {
  58. // map.centerAndZoom(new BMap.Point(113.64964385, 34.75661006), 13);// 创建点坐标
  59. // }
  60. // map.enableScrollWheelZoom(true);
  61. // map.addControl(new BMap.NavigationControl()); // 添加平移缩放控件
  62. // map.addControl(new BMap.ScaleControl()); // 添加比例尺控件
  63. // map.addControl(new BMap.OverviewMapControl()); //添加缩略地图控件
  64. // map.enableScrollWheelZoom(); //启用滚轮放大缩小
  65. // map.addControl(new BMap.MapTypeControl()); //添加地图类型控件
  66. // // map.setMapStyle({style:'midnight'});
  67. // var stCtrl = new BMap.PanoramaControl(); //全景图
  68. // stCtrl.setOffset(new BMap.Size(20, 20));
  69. // map.addControl(stCtrl);
  70. window.onload = function () {
  71. //请求数据:
  72. // $.ajax({
  73. // type: "post",
  74. // url: "home_map/map_locat",
  75. // data: {
  76. // req: "cbd",
  77. // },
  78. // dataType: "json",
  79. // success: function (data) {
  80. // eachItem(data)
  81. // }
  82. // });
  83. // $.ajax({
  84. // type: "post",
  85. // url: "home_map/map_locat",
  86. // data: {
  87. // req: "scd",
  88. // },
  89. // dataType: "json",
  90. // success: function (data) {
  91. // eachItem(data)
  92. // }
  93. // });
  94. // $.ajax({
  95. // type: "post",
  96. // url: "home_map/map_locat",
  97. // data: {
  98. // req: "qxz",
  99. // },
  100. // dataType: "json",
  101. // success: function (data) {
  102. // eachItem(data)
  103. // }
  104. // });
  105. }
  106. // function eachItem(data_info) {
  107. // var points = []; // 添加海量点数据
  108. // for (var i = 0; i < data_info.length; i++) {
  109. // if (data_info[i].lng > 999) {
  110. // var lng = Math.floor(data_info[i].lng / 100) + ((data_info[i].lng % 100) / 60);
  111. // var lat = Math.floor(data_info[i].lat / 100) + ((data_info[i].lat % 100) / 60);
  112. // } else {
  113. // var lat = data_info[i].lat;
  114. // var lng = data_info[i].lng;
  115. // }
  116. // if (data_info[i].lat && data_info[i].lng) {
  117. // //标注图标
  118. // var orgType = data_info[i].equip_type;//parseInt(0) data_info[i].equip_type
  119. // if (orgType == 5) {
  120. // var equip_type = '环境监测';
  121. // var options = {
  122. // size: BMAP_POINT_SIZE_BIG,
  123. // shape: BMAP_POINT_SHAPE_CIRCLE,
  124. // color: '#001dff'
  125. // }
  126. // // 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) });
  127. // } else if (orgType == 2) {
  128. // var equip_type = '杀虫灯';
  129. // var options = {
  130. // size: BMAP_POINT_SIZE_BIG,
  131. // shape: BMAP_POINT_SHAPE_CIRCLE,
  132. // color: '#ff6600'
  133. // }
  134. // // 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) });
  135. // } else if (orgType == 3) {
  136. // var equip_type = '虫情测报';
  137. // var options = {
  138. // size: BMAP_POINT_SIZE_BIG,
  139. // shape: BMAP_POINT_SHAPE_CIRCLE,
  140. // color: '#9c1ee4'
  141. // }
  142. // // 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) });
  143. // } else if (orgType == 4) {
  144. // var equip_type = '性诱器设备';
  145. // var options = {
  146. // size: BMAP_POINT_SIZE_BIG,
  147. // shape: BMAP_POINT_SHAPE_CIRCLE,
  148. // color: '#ff2da9'
  149. // }
  150. // // 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) });
  151. // } else if (orgType == 6) {
  152. // var equip_type = '监控设备';
  153. // var options = {
  154. // size: BMAP_POINT_SIZE_BIG,
  155. // shape: BMAP_POINT_SHAPE_CIRCLE,
  156. // color: 'green'
  157. // }
  158. // // 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) });
  159. // } else if (orgType == 7) {
  160. // var equip_type = '孢子仪设备';
  161. // var options = {
  162. // size: BMAP_POINT_SIZE_BIG,
  163. // shape: BMAP_POINT_SHAPE_CIRCLE,
  164. // color: '#ff0000'
  165. // }
  166. // // 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) });
  167. // } else if (orgType == 8) {
  168. // var equip_type = '农药残留';
  169. // var options = {
  170. // size: BMAP_POINT_SIZE_BIG,
  171. // shape: BMAP_POINT_SHAPE_CIRCLE,
  172. // color: '#ff7600'
  173. // }
  174. // // 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) });
  175. // }
  176. // // console.log(lat,lng);
  177. // //判断当前是否为杀虫灯
  178. // if (data_info[i].equip_type == 2) {
  179. // if (data_info[i].gps == 1) {
  180. // // 先从WGS84转火星再转百度 GPS定位
  181. // var lng1 = wgs84togcj02(lng, lat);
  182. // var lngData = gcj02tobd09(lng1[0], lng1[1]);
  183. // // console.log(lngData + 'GPS定位')
  184. // } else if (data_info[i].gps == 2) {
  185. // //直接从火星转百度 基站定位
  186. // var lngData = gcj02tobd09(lng, lat)
  187. // // console.log(lngData + '基站定位')
  188. // } else if (data_info[i].gps == 0) {
  189. // //手动定位不需要进行操作
  190. // var lngData = []
  191. // lngData.push(lng)
  192. // lngData.push(lat)
  193. // // console.log(lngData + '手动定位')
  194. // }
  195. // var point = new BMap.Point(lngData[0], lngData[1]);
  196. // point.equip_id= data_info[i].equip_id;
  197. // point.equip_name= data_info[i].equip_name;
  198. // point.equip_type = equip_type;
  199. // point.orgType = orgType;
  200. // points.push(point);
  201. // } else if (data_info[i].equip_type == 3) {
  202. // // console.log('测报灯')
  203. // //测报灯
  204. // if (data_info[i].gps == 1) {
  205. // // 先从WGS84转火星再转百度 GPS定位
  206. // var lng1 = wgs84togcj02(lng, lat);
  207. // var lngData = gcj02tobd09(lng1[0], lng1[1]);
  208. // // console.log(lngData + 'GPS定位')
  209. // } else if (data_info[i].gps == 2) {
  210. // //直接从火星转百度 基站定位
  211. // var lngData = gcj02tobd09(lng, lat)
  212. // // console.log(lngData + '基站定位')
  213. // } else if (data_info[i].gps == 0) {
  214. // //手动定位不需要进行操作
  215. // var lngData = []
  216. // lngData.push(lng)
  217. // lngData.push(lat)
  218. // // console.log(lngData + '手动定位')
  219. // }
  220. // var point = new BMap.Point(lngData[0], lngData[1]);
  221. // point.equip_id= data_info[i].equip_id;
  222. // point.equip_name= data_info[i].equip_name;
  223. // point.equip_type = equip_type;
  224. // point.orgType = orgType;
  225. // points.push(point);
  226. // } else {
  227. // var lng1 = wgs84togcj02(lng, lat);
  228. // var lng2 = gcj02tobd09(lng1[0], lng1[1]);
  229. // // console.log(lng1[0] + ',' + lng1[1] + '火星坐标')
  230. // // console.log(lng2[0] + ',' + lng2[1] + '百度坐标')
  231. // // console.log(lng1,lng2);
  232. // // pointArray[i] = new BMap.Point(lng2[0], lng2[1]);
  233. // // pointArray.push(new BMap.Point(lng2[0], lng2[1]))
  234. // // var point = new BMap.Point(lng2[0], lng2[1]);
  235. // var point = new BMap.Point(lng1[0], lng1[1]);
  236. // point.equip_id= data_info[i].equip_id;
  237. // point.equip_name= data_info[i].equip_name;
  238. // point.equip_type = equip_type;
  239. // point.orgType = orgType;
  240. // points.push(point);
  241. // }
  242. // // var lng1 = wgs84togcj02(lng, lat);
  243. // // var lng2 = gcj02tobd09(lng1[0], lng1[1]);
  244. // // // console.log(lng1[0] + ',' + lng1[1] + '火星坐标')
  245. // // // console.log(lng2[0] + ',' + lng2[1] + '百度坐标')
  246. // // // console.log(lng1,lng2);
  247. // // // pointArray[i] = new BMap.Point(lng2[0], lng2[1]);
  248. // // // pointArray.push(new BMap.Point(lng2[0], lng2[1]))
  249. // // // var point = new BMap.Point(lng2[0], lng2[1]);
  250. // // var point = new BMap.Point(lng1[0], lng1[1]);
  251. // // point.equip_id= data_info[i].equip_id;
  252. // // point.equip_name= data_info[i].equip_name;
  253. // // point.equip_type = equip_type;
  254. // // point.orgType = orgType;
  255. // // points.push(point);
  256. // // var enterNum = equip_type;//data_info[i].equip_name
  257. // // 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>';
  258. // // if (data_info[i].equip_location) {
  259. // // var flag = true;
  260. // // } else {
  261. // // var flag = false;
  262. // // }
  263. // // 将标注添加到地图中
  264. // // addClickHandler(content, marker, enterNum, flag);
  265. // }
  266. // }
  267. // var pointCollection = new BMap.PointCollection(points, options); // 初始化PointCollection
  268. // // var pointCollection = new BMap.Marker(new BMap.Point(118.60865944575743,36.938527592949285));
  269. // pointCollection.addEventListenr('click', function (e) {
  270. // var point = new BMap.Point(e.point.lng, e.point.lat);
  271. // geoc.getLocation(point, function (rs) {
  272. // var addComp = rs.addressComponents;
  273. // $('.area').html('位置:' + addComp.province + ", " + addComp.city + ", " + addComp.district)
  274. // });
  275. // var opts = {
  276. // width: 200, // 信息窗口宽度
  277. // height: 150, // 信息窗口高度
  278. // title: e.point.equip_type, // 信息窗口标题
  279. // enableMessage: true//设置允许信息窗发送短息
  280. // };
  281. // 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>';
  282. // var infoWindow = new BMap.InfoWindow(content, opts)
  283. // map.openInfoWindow(infoWindow, point)
  284. // });
  285. // map.addOverlay(pointCollection); // 添加Overlay
  286. // //让所有点在视野范围内
  287. // map.setViewport(points);
  288. // }
  289. function eachItem(data_info) {
  290. var points = []; // 添加海量点数据
  291. for (var i = 0; i < data_info.length; i++) {
  292. if (data_info[i].lng > 999) {
  293. var lng = Math.floor(data_info[i].lng / 100) + ((data_info[i].lng % 100) / 60);
  294. var lat = Math.floor(data_info[i].lat / 100) + ((data_info[i].lat % 100) / 60);
  295. } else {
  296. var lat = data_info[i].lat;
  297. var lng = data_info[i].lng;
  298. }
  299. if (lat && lng) {
  300. //标注图标
  301. var orgType = data_info[i].equip_type;//parseInt(0) data_info[i].equip_type
  302. if (orgType == 5) {
  303. var equip_type = '环境监测';
  304. var options = {
  305. size: BMAP_POINT_SIZE_BIG,
  306. shape: BMAP_POINT_SHAPE_CIRCLE,
  307. color: '#001dff'
  308. }
  309. // 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) });
  310. } else if (orgType == 2) {
  311. var equip_type = '杀虫灯';
  312. var options = {
  313. size: BMAP_POINT_SIZE_BIG,
  314. shape: BMAP_POINT_SHAPE_CIRCLE,
  315. color: '#ff6600'
  316. }
  317. // 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) });
  318. } else if (orgType == 3) {
  319. var equip_type = '虫情测报';
  320. var options = {
  321. size: BMAP_POINT_SIZE_BIG,
  322. shape: BMAP_POINT_SHAPE_CIRCLE,
  323. color: '#9c1ee4'
  324. }
  325. // 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) });
  326. } else if (orgType == 4) {
  327. var equip_type = '性诱器设备';
  328. var options = {
  329. size: BMAP_POINT_SIZE_BIG,
  330. shape: BMAP_POINT_SHAPE_CIRCLE,
  331. color: '#ff2da9'
  332. }
  333. // 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) });
  334. } else if (orgType == 6) {
  335. var equip_type = '监控设备';
  336. var options = {
  337. size: BMAP_POINT_SIZE_BIG,
  338. shape: BMAP_POINT_SHAPE_CIRCLE,
  339. color: 'green'
  340. }
  341. // 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) });
  342. } else if (orgType == 7) {
  343. var equip_type = '孢子仪设备';
  344. var options = {
  345. size: BMAP_POINT_SIZE_BIG,
  346. shape: BMAP_POINT_SHAPE_CIRCLE,
  347. color: '#ff0000'
  348. }
  349. // 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) });
  350. } else if (orgType == 8) {
  351. var equip_type = '农药残留';
  352. var options = {
  353. size: BMAP_POINT_SIZE_BIG,
  354. shape: BMAP_POINT_SHAPE_CIRCLE,
  355. color: '#ff7600'
  356. }
  357. // 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) });
  358. }
  359. if (data_info[i].equip_type == 2 ||data_info[i].equip_type ==3 || data_info[i].equip_type ==4 ) {
  360. if (data_info[i].gps == 1) {
  361. //convert wgs84 to cj02
  362. var cj02 = coordtransform.wgs84togcj02(lng, lat);//gps转火星定位
  363. //convert cj02 to bd09
  364. var lngData = coordtransform.gcj02tobd09(cj02[0], cj02[1]);//火星转百度定位
  365. } else if (data_info[i].gps == 2) {
  366. //convert cj02 to bd09
  367. var lngData = coordtransform.gcj02tobd09(lng, lat);//火星转百度定位
  368. } else if (data_info[i].gps == 0) {
  369. //手动定位不需要进行操作
  370. var lngData = []
  371. lngData.push(lng)
  372. lngData.push(lat)
  373. }else{
  374. //万一上报设备定位GPS标志不为012
  375. var lngData = []
  376. lngData.push(lng)
  377. lngData.push(lat)
  378. }
  379. }else if(data_info[i].equip_type == 5){
  380. //convert cj02 to bd09
  381. var lngData = coordtransform.gcj02tobd09(lng, lat);//火星转百度定位
  382. }else {
  383. var lngData = []
  384. lngData.push(lng)
  385. lngData.push(lat)
  386. }
  387. var point = new BMap.Point(lngData[0], lngData[1]);
  388. point.equip_id= data_info[i].equip_id;
  389. point.equip_name= data_info[i].equip_name;
  390. point.equip_type = equip_type;
  391. point.orgType = orgType;
  392. points.push(point);
  393. }
  394. }
  395. var pointCollection = new BMap.PointCollection(points, options); // 初始化PointCollection
  396. pointCollection.addEventListener('click', function (e) {
  397. var point = new BMap.Point(e.point.lng, e.point.lat);
  398. geoc.getLocation(point, function (rs) {
  399. var addComp = rs.addressComponents;
  400. $('.area').html('位置:' + addComp.province + ", " + addComp.city + ", " + addComp.district)
  401. });
  402. var opts = {
  403. width: 200, // 信息窗口宽度
  404. height: 150, // 信息窗口高度
  405. title: e.point.equip_type, // 信息窗口标题
  406. enableMessage: true//设置允许信息窗发送短息
  407. };
  408. 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>';
  409. var infowindow = new BMap.InfoWindow(content, opts);
  410. map.openInfoWindow(infowindow, point);
  411. });
  412. map.addOverlay(pointCollection); // 添加Overlay
  413. // 让所有点在视野范围内
  414. map.setViewport(points);
  415. }
  416. function eachItem1(data_info) {
  417. var pointArray = [];
  418. for (var i = 0; i < data_info.length; i++) {
  419. if (data_info[i].lng > 999) {
  420. var lng = Math.floor(data_info[i].lng / 100) + ((data_info[i].lng % 100) / 60);
  421. var lat = Math.floor(data_info[i].lat / 100) + ((data_info[i].lat % 100) / 60);
  422. } else {
  423. var lat = data_info[i].lat;
  424. var lng = data_info[i].lng;
  425. }
  426. if (data_info[i].lat && data_info[i].lng) {
  427. //标注图标
  428. var orgType = data_info[i].equip_type;//parseInt(0) data_info[i].equip_type
  429. if (orgType == 5) {
  430. var equip_type = '环境监测';
  431. 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) });
  432. } else if (orgType == 2) {
  433. var equip_type = '杀虫灯';
  434. 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) });
  435. } else if (orgType == 3) {
  436. var equip_type = '虫情测报';
  437. 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) });
  438. } else if (orgType == 4) {
  439. var equip_type = '性诱器设备';
  440. 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) });
  441. } else if (orgType == 6) {
  442. var equip_type = '监控设备';
  443. 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) });
  444. } else if (orgType == 7) {
  445. var equip_type = '孢子仪设备';
  446. 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) });
  447. } else if (orgType == 8) {
  448. var equip_type = '农药残留';
  449. 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) });
  450. }
  451. var lng1 = wgs84togcj02(lng, lat);
  452. var lng2 = gcj02tobd09(lng1[0], lng1[1]);
  453. // pointArray[i] = new BMap.Point(lng2[0], lng2[1]);
  454. pointArray.push(new BMap.Point(lng2[0], lng2[1]))
  455. var marker = new BMap.Marker(new BMap.Point(lng2[0], lng2[1]), { icon: myIcon }); // 创建标注
  456. map.addOverlay(marker);
  457. var enterNum = equip_type;//data_info[i].equip_name
  458. 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>';
  459. if (data_info[i].equip_location) {
  460. var flag = true;
  461. } else {
  462. var flag = false;
  463. }
  464. // 将标注添加到地图中
  465. addClickHandler(content, marker, enterNum, flag);
  466. }
  467. }
  468. //让所有点在视野范围内
  469. map.setViewport(pointArray);
  470. }
  471. function addClickHandler(content, marker, enterNum, flag) {
  472. marker.addEventListener("click", function (e) {
  473. if (!flag) {
  474. var pt = marker.point;
  475. geoc.getLocation(pt, function (rs) {
  476. var addComp = rs.addressComponents;
  477. $('.area').html('位置:' + addComp.province + ", " + addComp.city + ", " + addComp.district)
  478. // alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
  479. });
  480. }
  481. openInfo(content, e, enterNum)
  482. }
  483. );
  484. }
  485. function openInfo(content, event, orgname) {
  486. var p = event.target;
  487. var opts = {
  488. title: orgname, // 信息窗口标题
  489. enableMessage: true//设置允许信息窗发送短息
  490. };
  491. var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
  492. var infoWindow = new BMap.InfoWindow(content, opts); // 创建信息窗口对象
  493. map.openInfoWindow(infoWindow, point); //开启信息窗口
  494. }
  495. // 查询相对类型的数据
  496. $('#selectType').on('click', 'span', function () {
  497. var dtype = $(this).data('type');
  498. if (dtype == 2 || dtype == 3 || dtype == 5 || dtype == 7 || dtype == 8) {
  499. if (dtype == 2) { dtype = "scd" }
  500. else if (dtype == 3) { dtype = "cbd" }
  501. else if (dtype == 5) { dtype = "qxz" }
  502. else if (dtype == 7) { dtype = "bzy" }
  503. else if (dtype == 8) { dtype = "xyq" }
  504. map.clearOverlays();//清除全部
  505. $.ajax({
  506. type: "post",
  507. url: "home_map/map_locat",
  508. data: { req: dtype },
  509. dataType: "json",
  510. success: function (data) {
  511. map.clearOverlays();//清除全部
  512. eachItem(data)
  513. }
  514. });
  515. } else if (dtype == 0) {
  516. map.clearOverlays();//清除全部
  517. $.ajax({
  518. type: "post",
  519. url: "home_map/map_locat",
  520. data: {
  521. req: "cbd",
  522. },
  523. dataType: "json",
  524. success: function (data) {
  525. eachItem(data)
  526. }
  527. });
  528. $.ajax({
  529. type: "post",
  530. url: "home_map/map_locat",
  531. data: {
  532. req: "scd",
  533. },
  534. dataType: "json",
  535. success: function (data) {
  536. eachItem(data)
  537. }
  538. });
  539. $.ajax({
  540. type: "post",
  541. url: "home_map/map_locat",
  542. data: {
  543. req: "qxz",
  544. },
  545. dataType: "json",
  546. success: function (data) {
  547. eachItem(data)
  548. }
  549. });
  550. $.ajax({
  551. type: "post",
  552. url: "home_map/map_locat",
  553. data: {
  554. req: "bzy",
  555. },
  556. dataType: "json",
  557. success: function (data) {
  558. eachItem(data)
  559. }
  560. });
  561. $.ajax({
  562. type: "post",
  563. url: "home_map/map_locat",
  564. data: {
  565. req: "xyq",
  566. },
  567. dataType: "json",
  568. success: function (data) {
  569. eachItem(data)
  570. }
  571. });
  572. } else {
  573. // layer.msg("此功能暂未开启!", { time: 2000 });
  574. }
  575. })
  576. //搜索城市
  577. $('#searchCityBtn').on('click', searchCity);
  578. $('#searchCity').on('keyup', function (event) {
  579. if (event.keyCode == 13) {
  580. searchCity();
  581. }
  582. })
  583. function searchCity() {
  584. var local = new BMap.LocalSearch(map, {
  585. renderOptions: { map: map, panel: "r-result" },
  586. pageCapacity: 5
  587. });
  588. local.search($('#searchCity').val());
  589. }
  590. //搜索imei
  591. $('#searchBtn').on('click', searchImei);
  592. $('#searchImei').on('keyup', function (event) {
  593. if (event.keyCode == 13) {
  594. searchImei();
  595. }
  596. })
  597. function searchImei() {
  598. var imei = $('#searchImei').val();
  599. if (imei != '') {
  600. $.ajax({
  601. type: "post",
  602. url: "home_map/map_locat",
  603. data: {
  604. req: "imei",
  605. equip_id: imei
  606. },
  607. dataType: "json",
  608. success: function (data) {
  609. if (data == '0') {
  610. layer.msg("没有找到该设备,请核对设备id!", { time: 2000 });
  611. map.clearOverlays();//清除全部
  612. }
  613. else {
  614. map.clearOverlays();//清除全部
  615. eachItem(data)
  616. }
  617. }
  618. });
  619. } else {
  620. layer.msg("请输入imei!", { time: 2000 });
  621. }
  622. }
  623. var as = [{ "equip_id": "11111111", "equip_type": 3, "equip_name": "", "lng": "113.66080475001185", "lat": "34.81039429", "equip_location": "" }]
  624. function gotoManageDetial(imei, orgType) {
  625. var sidebar = $('#sidebar', parent.document);
  626. var menuLi = sidebar.find('.nav-list.nav').children();
  627. if (orgType == 3 || orgType == 2) {
  628. menuLi.each(function (idx, val) {
  629. $(val).removeClass('active');
  630. if ($(val).children('a').find('.menu-text').html() == '报表管理') {
  631. $(val).addClass('active');
  632. $(val).addClass('open');
  633. $(val).children('ul').removeClass('nav-hide').addClass('nav-show').show();
  634. if (orgType == 3) {
  635. $(val).children('ul').children().each(function (index, obj) {
  636. if ($(obj).find('.menu-text').html() == '虫情测报') {
  637. $(obj).addClass('active');
  638. }
  639. })
  640. } else if (orgType == 2) {
  641. $(val).children('ul').children().each(function (index, obj) {
  642. if ($(obj).find('.menu-text').html() == '杀虫灯') {
  643. $(obj).addClass('active');
  644. }
  645. })
  646. }
  647. }
  648. })
  649. }
  650. if (orgType == 3) {
  651. location.href = 'cbd_report_detail?id=' + imei;
  652. } else if (orgType == 2) {
  653. location.href = 'scd_report_detail?id=' + imei;
  654. }
  655. }