來源:互聯網
上載者:User
關鍵字
百度地圖api
百度地圖
php
javascript
百度地圖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蓋在上面了。請問要怎麼寫才能解決這個問題?謝謝!