首页 / 浏览问题 / 移动GIS / 问题详情
测距绘制后的清除功能
29EXP 2022年01月20日

在绘制功能上加了标注显示后,根据功能实现删除,但是根据示例里面的清除方式后,标注内容没有被清除,只有点线面被清除了,但是测高功能得到的线段没有被清除,想问一下是要怎么写,用什么方法这是实现的代码

//距离量算
        fab_cj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                closeAnalysis();
                AnalysisTypeArea = 0;
//                line.setBackgroundResource(R.color.red);
//                area.setBackgroundResource(R.color.purple);
                startMeasureAnalysis();
            }
        });
        //面积量算
        fab_cm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                closeAnalysis();
                AnalysisTypeArea = 1;
//                line.setBackgroundResource(R.color.aqua);
//                area.setBackgroundResource(R.color.blanchedalmond);
                startSurearea();

            }
        });
        //高度量算
        fab_cg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                closeAnalysis();
                AnalysisTypeArea = 2;
//                line.setBackgroundResource(R.color.aqua);
//                area.setBackgroundResource(R.color.blanchedalmond);
                startMeasureHeight();

            }
        });
        //清除
        fab_qc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                closeAnalysis();

            }
        });
//关闭分析
    public void closeAnalysis()
    {
        sceneControl.setAction(Action3D.PANSELECT3D);
    }

public void initAnalySis(SceneControl sceneControl, Tracking3DEvent tracking3DEvent) {
        if (sightline != null && sceneControl.getAction() == Action3D.CREATEPOINT3D) {
            Point3D p3D = new Point3D(tracking3DEvent.getX(),tracking3DEvent.getY(),tracking3DEvent.getZ());

            if (sightline.getvViewerPosition().getX() == 0)
            {
                sightline.setViewerPosition(p3D);
                sightline.build();
                //加点
                Point3D point3D = new Point3D(tracking3DEvent.getX(),tracking3DEvent.getY(),tracking3DEvent.getZ());
                GeoPoint3D geoPoint3D = new GeoPoint3D(point3D);
                GeoStyle3D geoStyle3D = new GeoStyle3D();
                geoPoint3D.setStyle3D(geoStyle3D);
                sceneControl.getScene().getTrackingLayer().add(geoPoint3D,"point");

            }
            else {
                sightline.addTargetPoint(p3D);
                //加点
                Point3D point3d = new Point3D(tracking3DEvent.getX(), tracking3DEvent.getY(), tracking3DEvent.getZ());
                GeoPoint3D geoPoint3D = new GeoPoint3D(point3d);
                GeoStyle3D geoStyle3D = new GeoStyle3D();
                geoPoint3D.setStyle3D(geoStyle3D);
                sceneControl.getScene().getTrackingLayer().add(geoPoint3D, "point");
            }
        }else if (sceneControl.getAction() == Action3D.MEASUREDISTANCE3D) {
            //测量距离
            measureDistance(tracking3DEvent);
        } else if (sceneControl.getAction() == Action3D.MEASUREALTITUDE3D) {
            //测量高度
            measureHeight(tracking3DEvent);
        } else if (sceneControl.getAction() == Action3D.MEASUREAREA3D) {
            //测量面积
            measureSurearea(tracking3DEvent);
        }
    }

    // 测量距离
    private void measureDistance(Tracking3DEvent tracking3DEvent) {
        // 加点
        // 更新总距离长度
        double totalLength = tracking3DEvent.getTotalLength();
        double totalcurrentlength = tracking3DEvent.getCurrentLength();
        double x = tracking3DEvent.getX();
        Log.v("lzw", "totalLength=" + totalLength + ";" + "totalcurrentlength=" + totalcurrentlength);
        Message msg = new Message();
        Bundle bundle = new Bundle();
        bundle.putDouble("length", Double.parseDouble(new DecimalFormat("############.##").format(totalLength)));
        msg.setData(bundle);
        totalLengthHandler.sendMessage(msg);

        //1.12
        TextStyle textStyle = new TextStyle();
        textStyle.setAlignment(TextAlignment.MIDDLECENTER);
        textStyle.setFontScale(1);

        TextPart3D textPart3D1 = new TextPart3D();
        textPart3D1.setX(tracking3DEvent.getX());
        textPart3D1.setY(tracking3DEvent.getY());
        textPart3D1.setZ(tracking3DEvent.getZ());
        textPart3D1.setText("共" + String.valueOf(msg.getData().getDouble("length"))+"米");
        Log.i("测试1", "textPart3D=" + textPart3D1.getText());

        GeoText3D geoText3D = new GeoText3D(textPart3D1);
        geoText3D.setTextStyle(textStyle);
        GeoPlacemark geoPlacemark = new GeoPlacemark("3D",geoText3D);
        sceneControl.getScene().getTrackingLayer().add(geoPlacemark,"geoText");

        textStyle.dispose();
        textPart3D1.dispose();
        geoText3D.dispose();

    }

// 测量高度
    private void measureHeight(Tracking3DEvent tracking3DEvent) {
        // 加点
        // 更新测量面积
        Point3D point3d = new Point3D(tracking3DEvent.getX(), tracking3DEvent.getY(), tracking3DEvent.getZ());
        double length = tracking3DEvent.getCurrentHeight();
        Point3D point3d1 = new Point3D(point3d.getX(), point3d.getY(),
                point3d.getZ() + tracking3DEvent.getCurrentHeight());
        Point3D[] p = {point3d, point3d1};
        Point3Ds point3Ds = new Point3Ds(p);
        GeoLine3D geoLine3D = new GeoLine3D(point3Ds);
        GeoStyle3D geoStyle3D = new GeoStyle3D();
        geoStyle3D.setLineWidth(10);
        geoStyle3D.setFillForeColor(new Color(255, 125, 0));
        geoStyle3D.setLineColor(new Color(255, 125, 0));
        geoStyle3D.setAltitudeMode(AltitudeMode.ABSOLUTE);
        geoLine3D.setStyle3D(geoStyle3D);
        double totalaltitude = tracking3DEvent.getCurrentHeight();
        Message msg = new Message();
        Bundle bundle = new Bundle();
        bundle.putDouble("Totalheight", Double.parseDouble(new DecimalFormat("############.##").format(totalaltitude)));
        msg.setData(bundle);
        totalLengthHandler.sendMessage(msg);
        sceneControl.getScene().getTrackingLayer().add(geoLine3D, "高度");
        Log.v("lzw", "Totalheight=" + totalaltitude );

        //1.12
        TextStyle textStyle = new TextStyle();
        textStyle.setAlignment(TextAlignment.MIDDLECENTER);
        textStyle.setFontScale(1);

        TextPart3D textPart3D3 = new TextPart3D();
        textPart3D3.setX(tracking3DEvent.getX());
        textPart3D3.setY(tracking3DEvent.getY());
        textPart3D3.setZ(tracking3DEvent.getZ());
        textPart3D3.setText("共" + String.valueOf(msg.getData().getDouble("Totalheight"))+"米");
        Log.i("测试3", "textPart3D=" + textPart3D3.getText());

        GeoText3D geoText3D = new GeoText3D(textPart3D3);
        geoText3D.setTextStyle(textStyle);
        GeoPlacemark geoPlacemark = new GeoPlacemark("3D",geoText3D);
        sceneControl.getScene().getTrackingLayer().add(geoPlacemark,"geoText");

        textStyle.dispose();
        textPart3D3.dispose();
        geoText3D.dispose();
    }

1个回答

您好,量算的结果是显示在跟踪图层的,如果要清楚可以使用跟踪图层的清楚功能哈,trackinglayer3d.clear
9,197EXP 2022年01月21日
...