参考文档
https://lbsyun.baidu.com/index.php?title=jspopular3.0/guide/infowindow
https://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference_3_0.html#a0b0
var opts = {
width: 200, // 信息窗口宽度
height: 40, // 信息窗口高度
title: `${point.name}`, // 信息窗口标题
};
var infoWindow = new BMap.InfoWindow(
"点击查看相关工单",
opts
); // 创建信息窗口对象
marker.addEventListener("click", function () {
map.openInfoWindow(infoWindow, bPoint); //开启信息窗口
document.getElementById("markerbtn").onclick = function (e) {
alert("门店编号:");
};
});
var map = new BMap.Map("container");
map.addEventListener("zoomstart", function (e) {
console.log(e.target.getZoom()); //监听缩放层级
});
const bPoint = new BMap.Point(point.lon, point.lat); // 创建点
map.panTo(bPoint); //平移到这个点
var point = new BMap.Point(IMlat, IMlon);
map.enableScrollWheelZoom(true);//是否允许忘了
map.centerAndZoom(point, 16);//地图放大到16层级
// 自定义覆盖物 这是方框
let content = `${IMname}`;
let label = new BMap.Label(content, {
position: point,
});
label.setStyle({
padding: "5px 10px",
textAlign: "center",
color: "#fff",
fontSize: "12px",
backgroundColor: "#ED2D2D",
});
//这是个三角
let content1 = `▼`;
let label1 = new BMap.Label(content1, {
position: point,
});
label1.setOffset(new BMap.Size(0, 22));//设置三角偏移
label1.setStyle({
color: "#ED2D2D",
backgroundColor: "transparent",
border: "none",
});
label.setZIndex(999);
map.addOverlay(label);
map.addOverlay(label1);
参考链接:https://api.map.baidu.com/library/MarkerClusterer/1.2/docs/symbols/BMapLib.MarkerClusterer.html
<script type="text/javascript" src="https://api.map.baidu.com/library/TextIconOverlay/1.2/src/TextIconOverlay_min.js">script>
<script type="text/javascript" src="https://api.map.baidu.com/library/MarkerClusterer/1.2/src/MarkerClusterer_min.js">script>
var map= new BMap.Map("container");
var markerClusterer = new BMapLib.MarkerClusterer(map, {
markers: [],
gridSize: 100,
maxZoom: 18,
}); //点聚合初始化
//设置点 点聚合
var markers = [];
function drawAreaPoint(AreaPointArr) {
if (markers.length > 0) {
markerClusterer.clearMarkers(markers);//设置新的点需要先清除之前的点
}
AreaPointArr.forEach((point) => {
let bPoint = new BMap.Point(point.lon, point.lat); // 创建点
markers.push(new BMap.Marker(bPoint));
});
markerClusterer = new BMapLib.MarkerClusterer(map, {
markers: markers,
}); //点聚合
}
function clickreSet(handleSelect) {
//清除聚合
markers = [];
if (markers.length > 0) {
markerClusterer.clearMarkers(markers);
}
}
下载这个js