home_map1.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  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. }
  374. }else if(data_info[i].equip_type == 5){
  375. //convert cj02 to bd09
  376. var lngData = coordtransform.gcj02tobd09(lng, lat);//火星转百度定位
  377. }else {
  378. var lngData = []
  379. lngData.push(lng)
  380. lngData.push(lat)
  381. }
  382. var point = new BMap.Point(lngData[0], lngData[1]);
  383. point.equip_id= data_info[i].equip_id;
  384. point.equip_name= data_info[i].equip_name;
  385. point.equip_type = equip_type;
  386. point.orgType = orgType;
  387. points.push(point);
  388. }
  389. }
  390. var pointCollection = new BMap.PointCollection(points, options); // 初始化PointCollection
  391. pointCollection.addEventListener('click', function (e) {
  392. var point = new BMap.Point(e.point.lng, e.point.lat);
  393. geoc.getLocation(point, function (rs) {
  394. var addComp = rs.addressComponents;
  395. $('.area').html('位置:' + addComp.province + ", " + addComp.city + ", " + addComp.district)
  396. });
  397. var opts = {
  398. width: 200, // 信息窗口宽度
  399. height: 150, // 信息窗口高度
  400. title: e.point.equip_type, // 信息窗口标题
  401. enableMessage: true//设置允许信息窗发送短息
  402. };
  403. 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>';
  404. var infowindow = new BMap.InfoWindow(content, opts);
  405. map.openInfoWindow(infowindow, point);
  406. });
  407. map.addOverlay(pointCollection); // 添加Overlay
  408. // 让所有点在视野范围内
  409. map.setViewport(points);
  410. }
  411. function eachItem1(data_info) {
  412. var pointArray = [];
  413. for (var i = 0; i < data_info.length; i++) {
  414. if (data_info[i].lng > 999) {
  415. var lng = Math.floor(data_info[i].lng / 100) + ((data_info[i].lng % 100) / 60);
  416. var lat = Math.floor(data_info[i].lat / 100) + ((data_info[i].lat % 100) / 60);
  417. } else {
  418. var lat = data_info[i].lat;
  419. var lng = data_info[i].lng;
  420. }
  421. if (data_info[i].lat && data_info[i].lng) {
  422. //标注图标
  423. var orgType = data_info[i].equip_type;//parseInt(0) data_info[i].equip_type
  424. if (orgType == 5) {
  425. var equip_type = '环境监测';
  426. 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) });
  427. } else if (orgType == 2) {
  428. var equip_type = '杀虫灯';
  429. 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) });
  430. } else if (orgType == 3) {
  431. var equip_type = '虫情测报';
  432. 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) });
  433. } else if (orgType == 4) {
  434. var equip_type = '性诱器设备';
  435. 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) });
  436. } else if (orgType == 6) {
  437. var equip_type = '监控设备';
  438. 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) });
  439. } else if (orgType == 7) {
  440. var equip_type = '孢子仪设备';
  441. 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) });
  442. } else if (orgType == 8) {
  443. var equip_type = '农药残留';
  444. 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) });
  445. }
  446. var lng1 = wgs84togcj02(lng, lat);
  447. var lng2 = gcj02tobd09(lng1[0], lng1[1]);
  448. // pointArray[i] = new BMap.Point(lng2[0], lng2[1]);
  449. pointArray.push(new BMap.Point(lng2[0], lng2[1]))
  450. var marker = new BMap.Marker(new BMap.Point(lng2[0], lng2[1]), { icon: myIcon }); // 创建标注
  451. map.addOverlay(marker);
  452. var enterNum = equip_type;//data_info[i].equip_name
  453. 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>';
  454. if (data_info[i].equip_location) {
  455. var flag = true;
  456. } else {
  457. var flag = false;
  458. }
  459. // 将标注添加到地图中
  460. addClickHandler(content, marker, enterNum, flag);
  461. }
  462. }
  463. //让所有点在视野范围内
  464. map.setViewport(pointArray);
  465. }
  466. function addClickHandler(content, marker, enterNum, flag) {
  467. marker.addEventListener("click", function (e) {
  468. if (!flag) {
  469. var pt = marker.point;
  470. geoc.getLocation(pt, function (rs) {
  471. var addComp = rs.addressComponents;
  472. $('.area').html('位置:' + addComp.province + ", " + addComp.city + ", " + addComp.district)
  473. // alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
  474. });
  475. }
  476. openInfo(content, e, enterNum)
  477. }
  478. );
  479. }
  480. function openInfo(content, event, orgname) {
  481. var p = event.target;
  482. var opts = {
  483. title: orgname, // 信息窗口标题
  484. enableMessage: true//设置允许信息窗发送短息
  485. };
  486. var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
  487. var infoWindow = new BMap.InfoWindow(content, opts); // 创建信息窗口对象
  488. map.openInfoWindow(infoWindow, point); //开启信息窗口
  489. }
  490. // 查询相对类型的数据
  491. $('#selectType').on('click', 'span', function () {
  492. var dtype = $(this).data('type');
  493. if (dtype == 2 || dtype == 3 || dtype == 5 || dtype == 7 || dtype == 8) {
  494. if (dtype == 2) { dtype = "scd" }
  495. else if (dtype == 3) { dtype = "cbd" }
  496. else if (dtype == 5) { dtype = "qxz" }
  497. else if (dtype == 7) { dtype = "bzy" }
  498. else if (dtype == 8) { dtype = "xyq" }
  499. map.clearOverlays();//清除全部
  500. $.ajax({
  501. type: "post",
  502. url: "home_map/map_locat",
  503. data: { req: dtype },
  504. dataType: "json",
  505. success: function (data) {
  506. map.clearOverlays();//清除全部
  507. eachItem(data)
  508. }
  509. });
  510. } else if (dtype == 0) {
  511. map.clearOverlays();//清除全部
  512. $.ajax({
  513. type: "post",
  514. url: "home_map/map_locat",
  515. data: {
  516. req: "cbd",
  517. },
  518. dataType: "json",
  519. success: function (data) {
  520. eachItem(data)
  521. }
  522. });
  523. $.ajax({
  524. type: "post",
  525. url: "home_map/map_locat",
  526. data: {
  527. req: "scd",
  528. },
  529. dataType: "json",
  530. success: function (data) {
  531. eachItem(data)
  532. }
  533. });
  534. $.ajax({
  535. type: "post",
  536. url: "home_map/map_locat",
  537. data: {
  538. req: "qxz",
  539. },
  540. dataType: "json",
  541. success: function (data) {
  542. eachItem(data)
  543. }
  544. });
  545. $.ajax({
  546. type: "post",
  547. url: "home_map/map_locat",
  548. data: {
  549. req: "bzy",
  550. },
  551. dataType: "json",
  552. success: function (data) {
  553. eachItem(data)
  554. }
  555. });
  556. $.ajax({
  557. type: "post",
  558. url: "home_map/map_locat",
  559. data: {
  560. req: "xyq",
  561. },
  562. dataType: "json",
  563. success: function (data) {
  564. eachItem(data)
  565. }
  566. });
  567. } else {
  568. // layer.msg("此功能暂未开启!", { time: 2000 });
  569. }
  570. })
  571. //搜索城市
  572. $('#searchCityBtn').on('click', searchCity);
  573. $('#searchCity').on('keyup', function (event) {
  574. if (event.keyCode == 13) {
  575. searchCity();
  576. }
  577. })
  578. function searchCity() {
  579. var local = new BMap.LocalSearch(map, {
  580. renderOptions: { map: map, panel: "r-result" },
  581. pageCapacity: 5
  582. });
  583. local.search($('#searchCity').val());
  584. }
  585. //搜索imei
  586. $('#searchBtn').on('click', searchImei);
  587. $('#searchImei').on('keyup', function (event) {
  588. if (event.keyCode == 13) {
  589. searchImei();
  590. }
  591. })
  592. function searchImei() {
  593. var imei = $('#searchImei').val();
  594. if (imei != '') {
  595. $.ajax({
  596. type: "post",
  597. url: "home_map/map_locat",
  598. data: {
  599. req: "imei",
  600. equip_id: imei
  601. },
  602. dataType: "json",
  603. success: function (data) {
  604. if (data == '0') {
  605. layer.msg("没有找到该设备,请核对设备id!", { time: 2000 });
  606. map.clearOverlays();//清除全部
  607. }
  608. else {
  609. map.clearOverlays();//清除全部
  610. eachItem(data)
  611. }
  612. }
  613. });
  614. } else {
  615. layer.msg("请输入imei!", { time: 2000 });
  616. }
  617. }
  618. var as = [{ "equip_id": "11111111", "equip_type": 3, "equip_name": "", "lng": "113.66080475001185", "lat": "34.81039429", "equip_location": "" }]
  619. function gotoManageDetial(imei, orgType) {
  620. var sidebar = $('#sidebar', parent.document);
  621. var menuLi = sidebar.find('.nav-list.nav').children();
  622. if (orgType == 3 || orgType == 2) {
  623. menuLi.each(function (idx, val) {
  624. $(val).removeClass('active');
  625. if ($(val).children('a').find('.menu-text').html() == '报表管理') {
  626. $(val).addClass('active');
  627. $(val).addClass('open');
  628. $(val).children('ul').removeClass('nav-hide').addClass('nav-show').show();
  629. if (orgType == 3) {
  630. $(val).children('ul').children().each(function (index, obj) {
  631. if ($(obj).find('.menu-text').html() == '虫情测报') {
  632. $(obj).addClass('active');
  633. }
  634. })
  635. } else if (orgType == 2) {
  636. $(val).children('ul').children().each(function (index, obj) {
  637. if ($(obj).find('.menu-text').html() == '杀虫灯') {
  638. $(obj).addClass('active');
  639. }
  640. })
  641. }
  642. }
  643. })
  644. }
  645. if (orgType == 3) {
  646. location.href = 'cbd_report_detail?id=' + imei;
  647. } else if (orgType == 2) {
  648. location.href = 'scd_report_detail?id=' + imei;
  649. }
  650. }