Home >Backend Development >PHP Tutorial >百度地图api-百度地图API开发,使用MarkerClusterer进行点聚合的问题

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

WBOY
WBOYOriginal
2016-06-02 11:34:492218browse

百度地图api百度地图phpjavascript

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

<code> 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();}  }); }</code>

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

<code> for (i = 0; i </code>

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn