googlemap.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. $(document).ready(function() {
  2. var cluster, markers = [];
  3. var map=new google.maps.Map(document.getElementById('map'), {
  4. center: {lat: 31.851859, lng: 117.27978},
  5. zoom: 8,
  6. mapTypeId: google.maps.MapTypeId.SATELLITE,
  7. tilt: 45
  8. });
  9. var inti=initmap();
  10. function initmap(){
  11. $.ajax({
  12. url:"/list",
  13. type: "GET",
  14. "dataType": "json",
  15. success:function(response){
  16. markers=[];
  17. $.each(response.data, function(i, obj) {
  18. var myLatLng=new google.maps.LatLng(obj.fields.latitude, obj.fields.longitude)
  19. var title='<span style="font-size:11px;color:#F00;">'+obj.fields.pestname+'</span>'
  20. var contentString = "<div id='content'>"+
  21. "<div id='siteNotice'>"+
  22. "</div>"+
  23. "<h1 style='font-size:14px;color:#F00;'>调查人:"+obj.fields.researchpeople+"</h1>"+
  24. "<div id='bodyContent'>"+
  25. "<p><a href="+"/showform/"+obj.pk+" data-toggle='modal' data-target='#treeModal' >详细信息</a></p>"+
  26. "</div>"+
  27. "</div>";
  28. var infowindow = new google.maps.InfoWindow({
  29. content: contentString,
  30. maxWidth: 160
  31. });
  32. var marker = new google.maps.Marker({
  33. position: myLatLng,
  34. map: map,
  35. title:obj.fields.pestname
  36. });
  37. markers.push(marker);
  38. marker.addListener('click', function() {
  39. infowindow.open(map, marker);
  40. });
  41. });
  42. var markerCluster = new MarkerClusterer(map, markers, {imagePath: 'http://7u2iif.com1.z0.glb.clouddn.com/m'});
  43. },
  44. error: function(){
  45. }
  46. });
  47. }
  48. $('#search').click(function(event){
  49. var posturl="/gsmm/multsearch?"
  50. var areaid = $("#areaid").find("option:selected").val();
  51. var pestname = $("#pestname").find("option:selected").val();
  52. var researchpeople = $("#researchpeople").find("option:selected").val();
  53. if(areaid !=0){
  54. posturl=posturl+'area='+areaid;
  55. }
  56. if(keid !=0){
  57. posturl=posturl+'&ke='+keid;
  58. }
  59. if(lid !=0){
  60. posturl= posturl+'&level='+lid;
  61. }
  62. var map=new google.maps.Map(document.getElementById('map'), {
  63. center: {lat: 31.851859, lng: 117.27978},
  64. zoom: 8,
  65. mapTypeId: google.maps.MapTypeId.SATELLITE,
  66. tilt: 45
  67. });
  68. $.ajax({
  69. url: posturl,
  70. type: "GET",
  71. "dataType": "json",
  72. success:function(response){
  73. markers=[];
  74. $.each(response.data, function(i, obj) {
  75. var myLatLng=new google.maps.LatLng(obj.latitude, obj.longitude)
  76. var title='<span style="font-size:11px;color:#F00;">'+obj.gsbh+'</span>'
  77. var contentString = "<div id='content'>"+
  78. "<div id='siteNotice'>"+
  79. "</div>"+
  80. "<h1 style='font-size:14px;color:#F00;'>古树编号:"+obj.gsbh+"</h1>"+
  81. "<div id='bodyContent'>"+
  82. "<p><b>中文名:</b>" +obj.cname+"</p>"+
  83. "<p><b>等级:</b>" +obj.treelevel+"</p>"+
  84. "<p><b>科属:</b>" +obj.ke+"</p>"+
  85. "<p><b>树龄:</b>" +obj.treeage+"</p>"+
  86. "<p><b>树高:</b>" +obj.treeheight+"</p>"+
  87. "<p><b>胸围:</b>" +obj.treechest+"</p>"+
  88. "<p><a href="+"/showform/"+obj.id+" data-toggle='modal' data-target='#treeModal' >详细信息</a></p>"+
  89. "</div>"+
  90. "</div>";
  91. var infowindow = new google.maps.InfoWindow({
  92. content: contentString,
  93. maxWidth: 160
  94. });
  95. var marker = new google.maps.Marker({
  96. position: myLatLng,
  97. map: map,
  98. title:obj.mainbreed
  99. });
  100. markers.push(marker);
  101. marker.addListener('click', function() {
  102. infowindow.open(map, marker);
  103. });
  104. });
  105. var markerCluster = new MarkerClusterer(map, markers, {imagePath: 'http://7u2iif.com1.z0.glb.clouddn.com/m'});
  106. },
  107. error: function(){
  108. }
  109. });
  110. });
  111. });