cesium点聚合

//点聚合  mapComManager.js内容

addClusterDataSource(params,myDataSource){
    let entity ={
      id: params.id,
      name: '点',
      show: true,
      position: Cesium.Cartesian3.fromDegrees(params.lon, params.lat, 100),
      billboard: {
        image: params.imgurl,
        width: 30,
      //  height: 30,
      scale:1.0,
      },
    };
    
    myDataSource.entities.add(entity)
  },
ClusterData(myDataSource,viewer){
    
    this.myDataSource =myDataSource;
    viewer.dataSources.add(myDataSource).then(function(dataSource) {
      dataSource.clustering.enabled = true; //是否聚合
      dataSource.clustering.pixelRange = 20; //聚合范围(单位px)
      dataSource.clustering.minimumClusterSize = 20; //最小屏幕聚合对象数值(小于等于该数值,不聚合)
    });
      this.customStyle();
  },
   pin50 (length) { return new Cesium.PinBuilder().fromText(length, Cesium.Color.RED, 48).toDataURL()},
   pin40(length) { return new Cesium.PinBuilder().fromText(length, Cesium.Color.ORANGE, 48).toDataURL()},
   pin30 (length) { return new Cesium.PinBuilder().fromText(length, Cesium.Color.YELLOW, 48).toDataURL()},
   pin20(length) { return new Cesium.PinBuilder().fromText(length, Cesium.Color.GREEN, 48).toDataURL()},
   pin10(length) { return new Cesium.PinBuilder().fromText(length, Cesium.Color.BLUE, 48).toDataURL()},
  customStyle() {
    if (this.removeListener==1) {
      this.removeListener();
      this.removeListener = undefined;
    
    } else {
      let self =this;
      this.removeListener =
      this.myDataSource.clustering.clusterEvent.addEventListener(
          function(clusteredEntities, cluster) {
            cluster.label.show = false;
            cluster.billboard.show = true;
            cluster.billboard.id = cluster.label.id;
            cluster.billboard.verticalOrigin = Cesium.VerticalOrigin.BOTTOM;
            if (clusteredEntities.length >= 50) {
              cluster.billboard.image = self.pin50(clusteredEntities.length);
            } else if (clusteredEntities.length >= 40) {
              cluster.billboard.image = self.pin40(clusteredEntities.length);
            } else if (clusteredEntities.length >= 30) {
              cluster.billboard.image = self.pin30(clusteredEntities.length);
            } else if (clusteredEntities.length >= 20) {
              cluster.billboard.image = self.pin20(clusteredEntities.length);
            } else if (clusteredEntities.length >= 10) {
              cluster.billboard.image = self.pin10(clusteredEntities.length);
            } else {
              cluster.billboard.image =
                singleDigitPins[clusteredEntities.length - 2];
            }
          }
        );
    }
  },
//页面调用
this.clusterDataSource = new Cesium.CustomDataSource("myDataSource");

addData(data,type){
   for (var i = 0; i < data.length; i++) {
       let lonlat = mapComManager.mercatorTolonlat(
            data[i].geometry.coordinates[0],
            data[i].geometry.coordinates[1]
          );
          let imgurl = "../../static/images/urbanPartsImg/"+type+".png"
          let params = {
            id: data[i].id,
            lon: lonlat.x,
            lat: lonlat.y,
            imgurl: imgurl,
            type: type,
          };
          mapComManager.addClusterDataSource(params, this.clusterDataSource); //聚合
      }
      mapComManager.ClusterData(this.clusterDataSource, this.viewer, this.num);
}

实现效果图在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值