美文网首页
cesium鼠标动态绘制面

cesium鼠标动态绘制面

作者: 你的小纯儿 | 来源:发表于2020-10-23 10:48 被阅读0次

let arr: any[] = [];

        let new_arr: any[] = [];

        this.polygon = null;

        handler.setInputAction((movement: Cesium.MoveEvent) =>{

          let position = this.viewer.camera.pickEllipsoid(movement.endPosition,this.viewer.scene.globe.ellipsoid)

          if(!Cesium.defined(position)){ //跳出地球异常

            return;

          }

          if(arr.length >= 2){

            if(!Cesium.defined(this.polygon)){

              this.polygon = this.drawPolygon(arr) as IPolygon;

            }else{

              arr.pop();

              arr.push(position);

            }

          }  

        }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

        handler.setInputAction((movement: Cesium.PositionedEvent) =>{

          let position = this.viewer.camera.pickEllipsoid(movement.position,this.viewer.scene.globe.ellipsoid)

          if(!Cesium.defined(position)){ //跳出地球异常

            return;

          }

          if(arr.length == 0){

            arr.push(position.clone());

          }

          arr.push(position)

          let ellipsoid=this.viewer.scene.globe.ellipsoid;

          let cartographic=ellipsoid.cartesianToCartographic(position);

          let lat=Cesium.Math.toDegrees(cartographic.latitude);

          let lon=Cesium.Math.toDegrees(cartographic.longitude);

          let alt = cartographic.height;

          new_arr.push([lon,lat,alt]);

        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

        handler.setInputAction(v=> {

          arr.pop();

          handler.destroy();

          arr = [];

          this.end = true;

          console.log("polygon: ", this.polygon)

          this.pointService.savePlot(this.polygon,'polygon',new_arr,this.end);          

        },Cesium.ScreenSpaceEventType.RIGHT_CLICK)

  drawPolygon(positions){

    let namecount = this.pointService.test1.points.source.length + 1;

    let polygonGeometry = this.viewer.entities.add({

      name: `面${namecount}`,

      polygon: {

        hierarchy: new Cesium.CallbackProperty(() =>{

          return {positions}

        }, false),

        perPositionHeight: true,

        material: Cesium.Color.GREENYELLOW.withAlpha(.5)

      }

    });

    return polygonGeometry;

  }

相关文章

网友评论

      本文标题:cesium鼠标动态绘制面

      本文链接:https://www.haomeiwen.com/subject/axfvmktx.html