首页 / 浏览问题 / 移动GIS / 问题详情
测面绘制三个点后无法继续
29EXP 2022年02月21日

想实现测面结果展示在图形中心,且展示最终结果,但按照下列代码绘制时,仅能绘制三个点后就无响应,其他功能也用不了了

 private int index = -1;
    private void measureSurearea(Tracking3DEvent tracking3DEvent) {

        double TotalArea = tracking3DEvent.getTotalArea();
        double totalcurrentlength = tracking3DEvent.getCurrentLength();


        Message msg = new Message();
        Bundle bundle = new Bundle();
        bundle.putDouble("Area", Double.parseDouble(new DecimalFormat("############.##").format(TotalArea)));
        msg.setData(bundle);
        totalLengthHandler.sendMessage(msg);
        Log.v("lzw", "TotalArea=" + TotalArea + ";" + "totalcurrentlength=" + totalcurrentlength);

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

        if(TotalArea > 0.0) {
            Point3D innerPoint3D = tracking3DEvent.getGeometry().getInnerPoint3D();
            TextPart3D textPart3D2 = new TextPart3D();
            textPart3D2.setX(innerPoint3D.getX());
            textPart3D2.setY(innerPoint3D.getY());
            textPart3D2.setZ(innerPoint3D.getZ());
            textPart3D2.setText("共" + msg.getData().getDouble("Area") + "平方米");
            Log.i("测试2", "textPart3D=" + textPart3D2.getText());
            if(index >= 0) {
                sceneControl.getScene().getTrackingLayer().remove(index);
            }

            GeoText3D geoText3D = new GeoText3D(textPart3D2);
            geoText3D.setTextStyle(textStyle);
            GeoPlacemark geoPlacemark = new GeoPlacemark("3D", geoText3D);

            index = sceneControl.getScene().getTrackingLayer().add(geoPlacemark, "面积");

        }

    }

 

听取建议后改用Tracked3DEvent,但不出结果了

private int index = -1;
    private void measureSurearea(Tracked3DEvent tracked3DEvent) {

        // 加点
        // 更新测量面积
        double TotalArea = tracked3DEvent.getArea();
        double totalcurrentlength = tracked3DEvent.getLength();

        Message msg = new Message();
        Bundle bundle = new Bundle();
        bundle.putDouble("Area", Double.parseDouble(new DecimalFormat("############.##").format(TotalArea)));
        msg.setData(bundle);
        totalLengthHandler.sendMessage(msg);
        Log.v("lzw", "TotalArea=" + TotalArea + ";" + "totalcurrentlength=" + totalcurrentlength);

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

        if(TotalArea > 0.0) {
            Point3D innerPoint3D = tracked3DEvent.getGeometry().getInnerPoint3D();
            TextPart3D textPart3D2 = new TextPart3D();
            textPart3D2.setX(innerPoint3D.getX());
            textPart3D2.setY(innerPoint3D.getY());
            textPart3D2.setZ(innerPoint3D.getZ());
            textPart3D2.setText("共" + msg.getData().getDouble("Area") + "平方米");
            Log.i("测试2", "textPart3D=" + textPart3D2.getText());
            if(index >= 0) {
                sceneControl.getScene().getTrackingLayer().remove(index);
            }

            GeoText3D geoText3D = new GeoText3D(textPart3D2);
            geoText3D.setTextStyle(textStyle);
            GeoPlacemark geoPlacemark = new GeoPlacemark("3D", geoText3D);

            index = sceneControl.getScene().getTrackingLayer().add(geoPlacemark, "面积");

        }

    }

想问一下是什么原因啊。。已经研究了好多次了

1个回答

你好,可以断点调试一下,看下是否还是在绘制第四个点的时候,sceneControl.getScene().getTrackingLayer().remove(index);  这句代码没有走通;Tracked3DEvent表示的是绘制结束时触发,逻辑上就不需要再移除之前的面积显示了啊,这个remove在监听里面出不来。建议用button单独清除
2,842EXP 2022年02月21日
还是在绘制第四个点的时候,sceneControl.getScene().getTrackingLayer().remove(index);  这句有问题,还是没有解决。

那用Tracked3DEven的时候就不需要if(index >= 0)这部分了吗

但是用Tracked3DEvent的时候,运行在这里就出问题了,断点测试在这断了,不走这里

   private Tracked3DListener mTracked3dListener = new Tracked3DListener() {
        @Override
        public void tracked(Tracked3DEvent tracked3DEvent) {
            initAnalySis1(sceneControl, tracked3DEvent);
            Log.i("绘制完成", "监听结束");
        }
    };

这是Tracked3DEvent的测面代码

private void measureSurearea(Tracked3DEvent tracked3DEvent) {

        // 加点
        // 更新测量面积
        double TotalArea = tracked3DEvent.getArea();
        double totalcurrentlength = tracked3DEvent.getLength();

        Message msg = new Message();
        Bundle bundle = new Bundle();
        bundle.putDouble("Area", Double.parseDouble(new DecimalFormat("############.##").format(TotalArea)));
        msg.setData(bundle);
        totalLengthHandler.sendMessage(msg);
        Log.v("lzw", "TotalArea=" + TotalArea + ";" + "totalcurrentlength=" + totalcurrentlength);

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

        if(TotalArea > 0.0) {
            Point3D innerPoint3D = tracked3DEvent.getGeometry().getInnerPoint3D();
            TextPart3D textPart3D2 = new TextPart3D();
            textPart3D2.setX(innerPoint3D.getX());
            textPart3D2.setY(innerPoint3D.getY());
            textPart3D2.setZ(innerPoint3D.getZ());
            textPart3D2.setText("共" + msg.getData().getDouble("Area") + "平方米");
            Log.i("测试2", "textPart3D=" + textPart3D2.getText());


            GeoText3D geoText3D = new GeoText3D(textPart3D2);
            geoText3D.setTextStyle(textStyle);
            GeoPlacemark geoPlacemark = new GeoPlacemark("3D", geoText3D);

            sceneControl.getScene().getTrackingLayer().add(geoPlacemark, "面积");

        }

    }

正在跟研发确认中,请稍等
你好,已确认Tracked3DListener 不能触发为缺陷,并且已经跟研发上报了。感谢您提出的产品问题,使我们的产品更加完善
绕行的话,暂时用Tracked3DListener,但是建议单次测量,不建议连续测量,可以额外加一个按钮控制,绘制完后进行测量,在下次测面积前,把之前所绘制的面和测量结果清空然后重新绘制面
...