cloudTreeList.js 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <%@ page contentType="text/html;charset=UTF-8" %>
  2. <script>
  3. $(document).ready(function() {
  4. $.ajax({
  5. type: "POST",
  6. url: '${ctx}/plate/plate/getCloudChartData',
  7. data: {},
  8. dataType:'json',
  9. cache: false,
  10. success: function(data){
  11. if(data.total>0) {
  12. var list = data.rows;
  13. //console.log(list);
  14. //var map = new BMap.Map("container");
  15. //var point,pos,marker;
  16. //创建检索信息窗口对象
  17. //var searchInfoWindow = null;
  18. var point = new Array(); //存放标注点经纬信息的数组
  19. var marker = new Array(); //存放标注点对象的数组
  20. var content = new Array(); //存放提示信息窗口对象的数组
  21. var searchInfoWindow = new Array(); //存放检索信息窗口对象的数组
  22. for (index = 0; index < list.length; index++) {
  23. pos = list[index];
  24. point[index] = new BMap.Point(Number(pos.lon), Number(pos.lat));
  25. marker[index] = new BMap.Marker(point[index]);
  26. content[index] = '<div style="margin:0;line-height:20px;padding:2px;">' +
  27. '党组织名称:'+ pos.name+
  28. '</div>';
  29. searchInfoWindow[index] = new BMapLib.SearchInfoWindow(map, content[index], {
  30. width: 290, //宽度
  31. height: 105, //高度
  32. panel: "panel", //检索结果面板
  33. enableAutoPan: true, //自动平移
  34. searchTypes: [
  35. BMAPLIB_TAB_SEARCH, //周边检索
  36. BMAPLIB_TAB_TO_HERE, //到这里去
  37. BMAPLIB_TAB_FROM_HERE //从这里出发
  38. ]
  39. });
  40. //添加点击事件
  41. marker[index].addEventListener("click",
  42. (function (k) {
  43. // js 闭包
  44. return function () {
  45. //map.centerAndZoom(point[k], 18);
  46. //marker[k].openInfoWindow(info[k]);
  47. searchInfoWindow[k].open(marker[k]);
  48. }
  49. })(index)
  50. );
  51. map.addOverlay(marker[index]); //在地图中添加marker
  52. if (index == 0) {
  53. map.setCenter(point[index]); // 由于写了这句,每一个被设置的点都是中心点的过程
  54. }
  55. /*point = new BMap.Point(Number(pos.lon), Number(pos.lat));//124.834,45.147);//
  56. map.centerAndZoom(point, 15);
  57. marker = new BMap.Marker(point); // 创建标注
  58. map.addOverlay(marker);
  59. var content = '<div style="margin:0;line-height:20px;padding:2px;">' +
  60. '村支书:'+pos.userName+'<br/>上传时间:'+pos.createDate +
  61. '</div>';
  62. addClickHandler(content,marker);*/
  63. }
  64. }else{
  65. jp.alert('未查询到GIS轨迹信息!');
  66. return false;
  67. }
  68. }
  69. });
  70. });
  71. function addClickHandler(content,marker){
  72. marker.addEventListener("click",function(e){
  73. openInfo(content,e)
  74. }
  75. );
  76. }
  77. var opts = {
  78. width : 250, // 信息窗口宽度
  79. height: 80, // 信息窗口高度
  80. title : "信息窗口" , // 信息窗口标题
  81. enableMessage:true//设置允许信息窗发送短息
  82. };
  83. function openInfo(content,e){
  84. var p = e.target;
  85. var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
  86. var infoWindow = new BMap.InfoWindow(content,opts); // 创建信息窗口对象
  87. map.openInfoWindow(infoWindow,point); //开启信息窗口
  88. }
  89. </script>