百度地圖api點(diǎn)聚合+marker事件

var map = new BMap.Map("allmap");

map.setCurrentCity("重慶"); // 設(shè)置地圖顯示的城市 此項(xiàng)是必須設(shè)置的

map.centerAndZoom(new BMap.Point(116.404, 39.915), 5);

map.enableScrollWheelZoom(true);

var MAX = 12;

var markers = [];

var pt = null;

var i = 0;

for(; i < MAX; i++) {

pt = new BMap.Point(Math.random() * 40 + 85, Math.random() * 30 + 21);

markers.push(new BMap.Marker(pt));

}

//最簡單的用法,生成一個(gè)marker數(shù)組,然后調(diào)用markerClusterer類即可。

var markerClusterer = new BMapLib.MarkerClusterer(map, {

markers: markers

});

$.each(markers, function(i, item) {

var content = item.point;

addClickHandler(content, item); //添加點(diǎn)擊事件

});

function addClickHandler(content, item) {

item.addEventListener("click", function() {

openInfo(content)

});

}

var opts = {

width: 250, // 信息窗口寬度

height: 80, // 信息窗口高度

title: "信息窗口", // 信息窗口標(biāo)題

enableMessage: true //設(shè)置允許信息窗發(fā)送短息

};

function openInfo(content) {

var point = new BMap.Point(content.lng, content.lat);

var infoWindow = new BMap.InfoWindow('content', opts); // 創(chuàng)建信息窗口對(duì)象

map.openInfoWindow(infoWindow, point); //開啟信息窗口

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容