百度地图加载海量点

//初始化坐标点
function initCoordinateInfo(){
  $.ajax({
    url: "url",
    async: true,
    method: 'GET',
    dataType: "json",
    cache: false,
    success: function (result) {
      // console.log(map.getZoom());
//显示海量点
      if (map.getZoom() <= 12) {
  //海量点数据
points = [];
// 添加海量点数据
for(var i = 0; i < result.data.length; i++){
          var p =new BMap.Point(result.data[i].mapX, result.data[i].mapY);
            p.type= result.data[i].type;
            points.push(p)
}
mapOverlay();
      } else {
  map.clearOverlays();
  var allOverlay = map.getOverlays();
        for (var i = 0; i < allOverlay.length; i++) {
   //console.log(allOverlay[i]);
  if (allOverlay[i].__proto__.wQ == "PointCollection") {
    map.removeOverlay(allOverlay[i]);
  }
  }
}
    }
  })
}

//把海量坐标绘制到地图上
function mapOverlay11(type) {
  //坐标点样式
  var options = {size: BMAP_POINT_SIZE_SMALL, shape: BMAP_POINT_SHAPE_CIRCLE, color: '#0000EE'}
  //创建pointCollection
  pointCollection = new BMap.PointCollection(points, options);
  //添加点击控件
  pointCollection.addEventListener("click",function(e){
    var content = "这是弹窗信息"
    var point = new BMap.Point(e.point.lng, e.point.lat);
    var opts = {
       250, // 信息窗口宽度
      height: 70, // 信息窗口高度
      //title:"", // 信息窗口标题
      //enableMessage: false,// 设置允许信息窗发送短息
    }
    var infoWindow = new BMap.InfoWindow(content); // 创建信息窗口对象
    map.openInfoWindow(infoWindow,point); //开启信息窗口
  });
  // 添加Overlay
  map.addOverlay(pointCollection);
}

 
原文地址:https://www.cnblogs.com/LinTianwen/p/12504113.html