areaTreeList.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <%@ page contentType="text/html;charset=UTF-8" %>
  2. <script>
  3. $(document).ready(function() {
  4. $("#search-a").click("click", function() {// 绑定查询按扭
  5. $.ajax({
  6. type: "POST",
  7. url: '${ctx}/plate/plate/gisPostionList',
  8. data: { userName:$("#userName").val()},
  9. dataType:'json',
  10. cache: false,
  11. success: function(data){
  12. if(data.total>0) {
  13. map.clearOverlays(); //清除地图上所有覆盖物
  14. var list = data.rows;
  15. //console.log(list);
  16. //var map = new BMap.Map("container");
  17. //var point,pos,marker;
  18. //创建检索信息窗口对象
  19. //var searchInfoWindow = null;
  20. var point = new Array(); //存放标注点经纬信息的数组
  21. var marker = new Array(); //存放标注点对象的数组
  22. var content = new Array(); //存放提示信息窗口对象的数组
  23. var searchInfoWindow = new Array(); //存放检索信息窗口对象的数组
  24. for (index = 0; index < list.length; index++) {
  25. pos = list[index];
  26. point[index] = new BMap.Point(Number(pos.lon), Number(pos.lat));
  27. marker[index] = new BMap.Marker(point[index]);
  28. content[index] = '<div style="margin:0;line-height:20px;padding:2px;">' +
  29. '第一书记:'+pos.userName+'<br/>打卡时间:'+pos.updateDate +
  30. '</div>';
  31. searchInfoWindow[index] = new BMapLib.SearchInfoWindow(map, content[index], {
  32. title: '第一书记打卡信息', //标题
  33. width: 290, //宽度
  34. height: 105, //高度
  35. panel: "panel", //检索结果面板
  36. enableAutoPan: true, //自动平移
  37. searchTypes: [
  38. BMAPLIB_TAB_SEARCH, //周边检索
  39. BMAPLIB_TAB_TO_HERE, //到这里去
  40. BMAPLIB_TAB_FROM_HERE //从这里出发
  41. ]
  42. });
  43. //添加点击事件
  44. marker[index].addEventListener("click",
  45. (function (k) {
  46. // js 闭包
  47. return function () {
  48. //map.centerAndZoom(point[k], 18);
  49. //marker[k].openInfoWindow(info[k]);
  50. searchInfoWindow[k].open(marker[k]);
  51. }
  52. })(index)
  53. );
  54. map.addOverlay(marker[index]); //在地图中添加marker
  55. if (index == 0) {
  56. map.setCenter(point[index]); // 由于写了这句,每一个被设置的点都是中心点的过程
  57. }
  58. /*point = new BMap.Point(Number(pos.lon), Number(pos.lat));//124.834,45.147);//
  59. map.centerAndZoom(point, 15);
  60. marker = new BMap.Marker(point); // 创建标注
  61. map.addOverlay(marker);
  62. var content = '<div style="margin:0;line-height:20px;padding:2px;">' +
  63. '村支书:'+pos.userName+'<br/>上传时间:'+pos.createDate +
  64. '</div>';
  65. addClickHandler(content,marker);*/
  66. }
  67. }else{
  68. jp.alert('未查询到GIS轨迹信息!');
  69. return false;
  70. }
  71. }
  72. });
  73. });
  74. $.ajax({
  75. type: "POST",
  76. url: '${ctx}/plate/plate/gisPostionList',
  77. data: {},
  78. dataType:'json',
  79. cache: false,
  80. success: function(data){
  81. if(data.total>0) {
  82. var list = data.rows;
  83. //console.log(list);
  84. //var map = new BMap.Map("container");
  85. //var point,pos,marker;
  86. //创建检索信息窗口对象
  87. //var searchInfoWindow = null;
  88. var point = new Array(); //存放标注点经纬信息的数组
  89. var marker = new Array(); //存放标注点对象的数组
  90. var content = new Array(); //存放提示信息窗口对象的数组
  91. var searchInfoWindow = new Array(); //存放检索信息窗口对象的数组
  92. for (index = 0; index < list.length; index++) {
  93. pos = list[index];
  94. point[index] = new BMap.Point(Number(pos.lon), Number(pos.lat));
  95. marker[index] = new BMap.Marker(point[index]);
  96. content[index] = '<div style="margin:0;line-height:20px;padding:2px;">' +
  97. '第一书记:'+pos.userName+'<br/>打卡时间:'+pos.updateDate +
  98. '</div>';
  99. searchInfoWindow[index] = new BMapLib.SearchInfoWindow(map, content[index], {
  100. title: '第一书记打卡信息', //标题
  101. width: 290, //宽度
  102. height: 105, //高度
  103. panel: "panel", //检索结果面板
  104. enableAutoPan: true, //自动平移
  105. searchTypes: [
  106. BMAPLIB_TAB_SEARCH, //周边检索
  107. BMAPLIB_TAB_TO_HERE, //到这里去
  108. BMAPLIB_TAB_FROM_HERE //从这里出发
  109. ]
  110. });
  111. //添加点击事件
  112. marker[index].addEventListener("click",
  113. (function (k) {
  114. // js 闭包
  115. return function () {
  116. //map.centerAndZoom(point[k], 18);
  117. //marker[k].openInfoWindow(info[k]);
  118. searchInfoWindow[k].open(marker[k]);
  119. }
  120. })(index)
  121. );
  122. map.addOverlay(marker[index]); //在地图中添加marker
  123. if (index == 0) {
  124. map.setCenter(point[index]); // 由于写了这句,每一个被设置的点都是中心点的过程
  125. }
  126. /*point = new BMap.Point(Number(pos.lon), Number(pos.lat));//124.834,45.147);//
  127. map.centerAndZoom(point, 15);
  128. marker = new BMap.Marker(point); // 创建标注
  129. map.addOverlay(marker);
  130. var content = '<div style="margin:0;line-height:20px;padding:2px;">' +
  131. '村支书:'+pos.userName+'<br/>上传时间:'+pos.createDate +
  132. '</div>';
  133. addClickHandler(content,marker);*/
  134. }
  135. }else{
  136. jp.alert('未查询到GIS轨迹信息!');
  137. return false;
  138. }
  139. }
  140. });
  141. });
  142. function addClickHandler(content,marker){
  143. marker.addEventListener("click",function(e){
  144. openInfo(content,e)
  145. }
  146. );
  147. }
  148. var opts = {
  149. width : 250, // 信息窗口宽度
  150. height: 80, // 信息窗口高度
  151. title : "信息窗口" , // 信息窗口标题
  152. enableMessage:true//设置允许信息窗发送短息
  153. };
  154. function openInfo(content,e){
  155. var p = e.target;
  156. var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
  157. var infoWindow = new BMap.InfoWindow(content,opts); // 创建信息窗口对象
  158. map.openInfoWindow(infoWindow,point); //开启信息窗口
  159. }
  160. </script>