$(document).ready(function() { var cluster, markers = []; var map=new google.maps.Map(document.getElementById('map'), { center: {lat: 31.851859, lng: 117.27978}, zoom: 8, mapTypeId: google.maps.MapTypeId.SATELLITE, tilt: 45 }); var inti=initmap(); function initmap(){ $.ajax({ url:"/list", type: "GET", "dataType": "json", success:function(response){ markers=[]; $.each(response.data, function(i, obj) { var myLatLng=new google.maps.LatLng(obj.fields.latitude, obj.fields.longitude) var title=''+obj.fields.pestname+'' var contentString = "
"+ "
"+ "
"+ "

调查人:"+obj.fields.researchpeople+"

"+ "
"+ "

详细信息

"+ "
"+ "
"; var infowindow = new google.maps.InfoWindow({ content: contentString, maxWidth: 160 }); var marker = new google.maps.Marker({ position: myLatLng, map: map, title:obj.fields.pestname }); markers.push(marker); marker.addListener('click', function() { infowindow.open(map, marker); }); }); var markerCluster = new MarkerClusterer(map, markers, {imagePath: 'http://7u2iif.com1.z0.glb.clouddn.com/m'}); }, error: function(){ } }); } $('#search').click(function(event){ var posturl="/gsmm/multsearch?" var areaid = $("#areaid").find("option:selected").val(); var pestname = $("#pestname").find("option:selected").val(); var researchpeople = $("#researchpeople").find("option:selected").val(); if(areaid !=0){ posturl=posturl+'area='+areaid; } if(keid !=0){ posturl=posturl+'&ke='+keid; } if(lid !=0){ posturl= posturl+'&level='+lid; } var map=new google.maps.Map(document.getElementById('map'), { center: {lat: 31.851859, lng: 117.27978}, zoom: 8, mapTypeId: google.maps.MapTypeId.SATELLITE, tilt: 45 }); $.ajax({ url: posturl, type: "GET", "dataType": "json", success:function(response){ markers=[]; $.each(response.data, function(i, obj) { var myLatLng=new google.maps.LatLng(obj.latitude, obj.longitude) var title=''+obj.gsbh+'' var contentString = "
"+ "
"+ "
"+ "

古树编号:"+obj.gsbh+"

"+ "
"+ "

中文名:" +obj.cname+"

"+ "

等级:" +obj.treelevel+"

"+ "

科属:" +obj.ke+"

"+ "

树龄:" +obj.treeage+"

"+ "

树高:" +obj.treeheight+"

"+ "

胸围:" +obj.treechest+"

"+ "

详细信息

"+ "
"+ "
"; var infowindow = new google.maps.InfoWindow({ content: contentString, maxWidth: 160 }); var marker = new google.maps.Marker({ position: myLatLng, map: map, title:obj.mainbreed }); markers.push(marker); marker.addListener('click', function() { infowindow.open(map, marker); }); }); var markerCluster = new MarkerClusterer(map, markers, {imagePath: 'http://7u2iif.com1.z0.glb.clouddn.com/m'}); }, error: function(){ } }); }); });