一、测距
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;
}
});