北京经济技术开发区经开区虚拟城市项目-【前端】--政府服务中心-1号屏Web
Surpriseplus
2023-10-07 a77448eb072f10dd3827694140f87c3069b1dba4
src/components/left/leftmenu.vue
@@ -1019,6 +1019,118 @@
        }
      }
    },
    initCluster(treeNode) {
      this.$set(treeNode, "disabled", true);//给treeNode添加disabled属性
      let that = this;
      let imgUrl;
      new Cesium.GeoJsonDataSource.load(
        treeNode.urls +
        "?version=1.3.0&request=GetFeature&format=json&typename=" +
        treeNode.layer
      ).then((dataSource) => {
        that.$set(treeNode, "disabled", false);
        Viewer.dataSources.add(dataSource);
        clusterItemList.push({ name: treeNode.id, dataSource: dataSource });
        // window.clusterItem = dataSource;
        // 设置聚合参数
        // dataSource.clustering.enabled = true;
        // window.dataClustering = dataSource.clustering;
        // dataSource.clustering.pixelRange = 20;
        // dataSource.clustering.minimumClusterSize = 20;
        // foreach用于调用数组的每个元素,并将元素传递给回调函数。
        dataSource.entities.values.forEach((entity) => {
          // if (entity.featureType == "yz井数据") {
          //   switch (feature.properties["井类型"]) {
          //     default:
          //       imgUrl = treeNode.image;
          //       break;
          //   }
          // }
          // 将点拉伸一定高度,防止被地形压盖
          // entity.position._value.z += 50.0;
          // 使用大小为64*64的icon,缩小展示poi
          entity.billboard = {
            image: entity.featureType == "yz井数据" ? imgUrl : treeNode.image,
            scale: treeNode.imageScale,
            // width: 50,
            // height: 50,
            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
              0,
              1000.0
            ),
            disableDepthTestDistance: Number.POSITIVE_INFINITY,
          };
          // entity.tag = treeNode.id;
          // entity.label = {
          //   // text: "POI",
          //   font: "bold 15px Microsoft YaHei",
          //   // 竖直对齐方式
          //   verticalOrigin: Cesium.VerticalOrigin.CENTER,
          //   // 水平对齐方式
          //   horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
          //   // 偏移量
          //   pixelOffset: new Cesium.Cartesian2(15, 0),
          // };
        });
        // 添加监听函数
        // dataSource.clustering.clusterEvent.addEventListener(function (
        //   clusteredEntities,
        //   cluster
        // ) {
        //   // 关闭自带的显示聚合数量的标签
        //   cluster.label.show = true;
        //   cluster.label.color = Cesium.Color.WHITE;
        //   cluster.label.outlineColor = Cesium.Color.BLACK;
        //   cluster.label.outlineWidth = 3.0;
        //   cluster.label.style = Cesium.LabelStyle.FILL_AND_OUTLINE;
        //   cluster.label.eyeOffset = new Cesium.Cartesian3(0, 0, -100);
        //   cluster.label.disableDepthTestDistance = Number.POSITIVE_INFINITY;
        //   cluster.billboard.disableDepthTestDistance = Number.POSITIVE_INFINITY;
        //   cluster.billboard.show = true;
        //   cluster.billboard.id = cluster.label.id;
        //   cluster.billboard.horizontalOrigin = Cesium.HorizontalOrigin.LEFT;
        //   cluster.billboard.verticalOrigin = Cesium.VerticalOrigin.CENTER;
        //   var reg1 = new RegExp(",", "g");
        //   cluster.label.text = cluster.label.text.replace(reg1, "");
        //   // 根据聚合数量的多少设置不同层级的图片以及大小
        //   if (clusteredEntities.length >= 10000) {
        //     cluster.billboard.image = require("@/assets/img/right/test01.png");
        //     cluster.billboard.pixelOffset = new Cesium.Cartesian2(-25, -10);
        //     cluster.billboard.width = 142;
        //     cluster.billboard.height = 142;
        //   } else if (clusteredEntities.length >= 1000) {
        //     cluster.billboard.image = require("@/assets/img/right/test01.png");
        //     cluster.billboard.pixelOffset = new Cesium.Cartesian2(-35, -10);
        //     cluster.billboard.width = 135;
        //     cluster.billboard.height = 135;
        //   } else if (clusteredEntities.length >= 100) {
        //     cluster.billboard.image = require("@/assets/img/right/test01.png");
        //     cluster.billboard.pixelOffset = new Cesium.Cartesian2(-26, -10);
        //     cluster.billboard.width = 102;
        //     cluster.billboard.height = 102;
        //   }
        //   else if (clusteredEntities.length >= 10) {
        //     cluster.billboard.image = require("@/assets/img/right/test04.png");
        //     cluster.billboard.pixelOffset = new Cesium.Cartesian2(-25, -10);
        //     cluster.billboard.width = 82;
        //     cluster.billboard.height = 82;
        //   } else {
        //     cluster.billboard.image = require("@/assets/img/right/test04.png");
        //     cluster.billboard.pixelOffset = new Cesium.Cartesian2(-25, -10);
        //     cluster.billboard.width = 62;
        //     cluster.billboard.height = 62;
        //   }
        // });
      });
    },
    async addTreeData(treeNode) {
      // if (treeNode.disabled) return;
      let _data = sgworld.ProjectTree.getObject(treeNode.id);
@@ -1274,6 +1386,10 @@
          );
          treeNode.id = layer.treeobj.id;
          break;
        case "cluster":
          layer = this.initCluster(treeNode);
          break;
        case "yztile":
          layer = new YZWMS(treeNode);
          sgworld._Viewer.imageryLayers.addImageryProvider(layer);