Cesium GeometryIntstance 選中改變顏色 和 繪制帶箭頭的直線


1、GeometryInstance選中顏色更改

let that = this;
      that.leftHander = new Cesium.ScreenSpaceEventHandler(
        that.Earth.viewer.scene.canvas
      );

      that.leftHander.setInputAction((click) => {
        let pickObj = that.Earth.viewer.scene.pick(click.position);
        if (pickObj) {
          that.clearSelected();
          let attributes = pickObj.primitive.getGeometryInstanceAttributes(
            pickObj.id
          );

          if (attributes) {
            that.primitive = pickObj.primitive;
            that.selectId = pickObj.id;
            attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(
              Cesium.Color.fromCssColorString("#7B68EE").withAlpha(0.6)
            );
          }

          let data =
            that.Earth.cimdatamanager.paishuiFacilityData.psdypolygonList;
          if (data) {
            data.forEach((o) => {
              if (o.properties.gw_id == pickObj.id) {
                that.isShow = 2;
                that.unitData = o.properties;
                that.drawPaiShuiLine(o.properties.drauintid);
              }
            });
          }
        }
      }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

2、恢復原來的顏色

    clearSelected() {
      if (this.primitive) {
        let attributes = this.primitive.getGeometryInstanceAttributes(
          this.selectId
        );
        if (attributes) {
          attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(
            Cesium.Color.fromCssColorString("#4a7d84").withAlpha(0.6)
          );
        }
      }
    },

3、繪制帶箭頭直線

      result.forEach((o) => {
        var redLine = this.viewer.entities.add({
          // 貼在地面上 兩點之間的直線距離
          name: "line",
          polyline: {
            positions: Cesium.Cartesian3.fromDegreesArray([
              o.inx,
              o.iny,
              o.outx,
              o.outy,
            ]),
            width: 10,
            // 不帶箭頭的線
            // material: Cesium.Color.RED,
            // 是否緊貼地面
            //clampToGround: true,
            // 帶箭頭的線
            material: new Cesium.PolylineArrowMaterialProperty(
              Cesium.Color.RED
            ),
          },
        });

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM