本文介绍通过百度地图api显示聚合点。效果如下:先看它是如何实现的(以vue为例):创建地图容器this.baiduMapOut=newBMap.Map(document.getElementById(this.className));设置中心点,支持缩放this.baiduMapOut.enableScrollWheelZoom();this.baiduMapOut.centerAndZoom('中华人民共和国',5);绘制点if(this.markerClusterer){this.markerClusterer.clearMarkers(this.markers);}for(constpointofpoints){letimgurl=require('../../../../assets/images/dataMarket/location-little.png');让iconStop=newBMap.Icon(imgurl,newBMap.Size(32,34),{anchor:newBMap.Size(23,20)});让pointStop=newBMap.Point(point.lng,point.lat);这个.points.push(pointStop);让markerStop=newBMap.Marker(pointStop,{icon:iconStop});this.markers.push(markerStop);if(this.markers.length>0){this.markerClusterer=newBMapLib.MarkerClusterer(this.baiduMapOut,{markers:this.markers});}上述代码中points是从后台界面获取的点的经纬度集合。重点是:newBMapLib.MarkerClusterer将添加的marker转化为聚合点显示注意:此时会出现地图初始化和点绘制顺序问题,可能会导致一些坑,所以要确保地图已经完整绘制点时加载。您可以添加延迟来解决它
