ArcGIS for Android 测距测面

一、测距

 mapView.setOnTouchListener(new DefaultMapViewOnTouchListener(context, mapView) {
            @Override
            public boolean onSingleTapConfirmed(MotionEvent e) {
                Point point = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY())));
                mPointCollection.add(point);
                Polyline polyline = new Polyline(mPointCollection);
                // 设置单位 - METERS(米)
                LinearUnit linearUnit = new LinearUnit(LinearUnitId.METERS);
                /**测量距离
                 * @param1 - 线段
                 * @param2 - 单位
                 * @param3 - 测量地面
                 * GeometryEngine.lengthGeodetic(param1,param2,param3)
                 * */
                double lengthPolyline =  GeometryEngine.lengthGeodetic(polyline,linearUnit,GeodeticCurveType.GEODESIC);
                /** 测量距离
                 * FormateDoubleUtils.formatDoubleToDouble() - 自定义保留小数点后两位方法
                 * GeometryEngine.length() - ArcGISSDK 测量距离方法
                 * */
                //double lengthPolyline = FormateDoubleUtils.formatDoubleToDouble(GeometryEngine.length(polyline));
                /**
                 * 赋值单位
                 * 距离小于1000单位为(米)
                 * 距离大于等于1000单位为(千米)
                 */
                String disLength = null;
                if (lengthPolyline < 1000.00){
                    disLength = FormateDoubleUtils.formatDoubleToStrong(lengthPolyline)+"米";
                } else {
                    disLength = FormateDoubleUtils.formatDoubleToStrong(lengthPolyline / 1000.00)+"千米";
                }
                // 文字
                TextSymbol textSymbol = new TextSymbol(15, disLength, Color.RED,
                        TextSymbol.HorizontalAlignment.CENTER, TextSymbol.VerticalAlignment.MIDDLE);
                //点颜色和大小
                //SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 10);
                Graphic pointGraphic = new Graphic(point, textSymbol);
                mGraphicsOverlay.getGraphics().add(pointGraphic);

                //线
                SimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.parseColor("#FC8145"), 3);
                Graphic graphic = new Graphic(polyline, simpleLineSymbol);
                mGraphicsOverlay.getGraphics().add(graphic);

                return super.onSingleTapConfirmed(e);
            }
            // 控制旋转
            @Override
            public boolean onRotate(MotionEvent event,double rotationAngle) {
                return false;
            }
        });

二、测面 

mapView.setOnTouchListener(new DefaultMapViewOnTouchListener(context, mapView) {
            @Override
            public boolean onSingleTapConfirmed(MotionEvent e) {
                mGraphicsOverlay.getGraphics().clear();
                Point point = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY())));
                mPointCollection.add(point);

                Polygon polygon = new Polygon(mPointCollection);
                // 测量面积
                double areaPolygon = Math.abs(GeometryEngine.area(polygon));
                /** 测量面积
                 * Math.abs()  - 绝对值否则会出现负数情况
                 * FormateDoubleUtils.formatDoubleToDouble() - 自定义保留小数点后两位方法
                 * GeometryEngine.area() - ArcGISSDK 测量面积方法
                 * */
                //double areaPolygon = Math.abs(FormateDoubleUtils.formatDoubleToDouble(GeometryEngine.area(polygon)));

                /**
                 * 赋值单位
                 * 面积小于10000单位为(平方米)
                 * 面积大于等于10000单位为(平方千米)
                 */
                String disArea = null;
                if (areaPolygon < 10000.00){
                    disArea = FormateDoubleUtils.formatDoubleToStrong(areaPolygon)+"平方米";
                }else {
                    disArea = FormateDoubleUtils.formatDoubleToStrong(areaPolygon/1000000.00)+"平方千米";
                }
                // 文字
                TextSymbol textSymbol = new TextSymbol(15, disArea, Color.RED,
                        TextSymbol.HorizontalAlignment.CENTER, TextSymbol.VerticalAlignment.MIDDLE);
                Graphic pointGraphic = new Graphic(point, textSymbol);
                mGraphicsOverlay.getGraphics().add(pointGraphic);

                SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.GREEN, 3.0f);
                SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.parseColor("#33e97676"), lineSymbol);
                Graphic graphic = new Graphic(polygon, simpleFillSymbol);
                mGraphicsOverlay.getGraphics().add(graphic);

                return super.onSingleTapConfirmed(e);
            }
            // 控制旋转
            @Override
            public boolean onRotate(MotionEvent event,double rotationAngle) {
                return false;
            }
        });

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值