当前位置:Gxlcms > PHP教程 > 百度地图api-百度地图API开发,使用MarkerClusterer进行点聚合的问题

百度地图api-百度地图API开发,使用MarkerClusterer进行点聚合的问题

时间:2021-07-01 10:21:17 帮助过:12人阅读

百度地图api百度地图phpjavascript

新手求助,我开发的程序在地图上放置marker,是通过一个函数完成的:

 function addMarker(getPoint,outContent,titleContent){ var opts = { position : getPoint, // 指定文本标注所在的地理位置 offset : new BMap.Size(10, 0) //设置文本偏移量 } var label = new BMap.Label(titleContent, opts); // 创建文本标注对象 label.setStyle({ color : "red", fontSize : "12px", height : "20px", lineHeight : "20px", fontFamily:"微软雅黑" }); var marker = new BMap.Marker(getPoint); var infoWindow = new BMap.InfoWindow(outContent,{width:300}); // 创建信息窗口对象 // var titleWindow = new BMap.InfoWindow(titleContent,     {width:50,height:5}); map.addOverlay(marker); marker.addEventListener("mouseover",function() {this.map.addOverlay(label);}); marker.addEventListener("mouseout",function() {this.map.removeOverlay(label);}); marker.addEventListener("click", function(){  this.openInfoWindow(infoWindow); document.getElementById('smallpic').onload = function ()          {infoWindow.redraw();}  }); }

然后再用for循环将已经读取好的每个点的坐标、需要显示的label、需要弹窗的infowindow的内容等输入函数,在地图上标点:

 for (i = 0; i < locations.length; i++) {addMarker(point,readContent,titleContent); }

现在的问题是点很多,需要用MarkerClusterer进行点聚合,但是如果按照示例代码那样,建一个数组将坐标全部导入,聚合是成功了,但生成的聚合点是没有label和infowindow的,感觉像是聚合点是直接生成了一批新的marker盖在上面了。请问要怎么写才能解决这个问题?谢谢!

人气教程排行