一、概述
测量操作:长度、面积
(1)效果
(2)数据下载地址
链接:https://pan.baidu.com/s/1ggfytWZ 密码:nq0o
二、实现逻辑
前期基础数据加载过程(数据加载、许可设置)参见如下链接:
http://blog.youkuaiyun.com/weixin_37027518/article/details/79331487
设置地图动作具体实现:
//设置地图监听
mMapView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()){
case MotionEvent.ACTION_DOWN:{
}break;
case MotionEvent.ACTION_UP:{
addOnePoint(motionEvent.getX(), motionEvent.getY());
}break;
case MotionEvent.ACTION_MOVE:{
}break;
}
return true;
}
});
/**
* 添加一个点
* @param x
* @param y
*/
private void addOnePoint(float x, float y){
//获得新的点
Point point = new Point();
point.x = (int)x;
point.x = (int)y;
Point2D point2D = mMapView.DeviceToMapPoint(point);
lstMeasureDatas.add(point2D);
if(measuerOpt == MEASUER_LINE){
if(lstMeasureDatas.size() > 1){
//显示
Point2D[] arrDatas = (Point2D[]) lstMeasureDatas.toArray();
GeoLine geometry = new GeoLine().Make(arrDatas);
double result = geometry.GetLength(mMapView.GetPrjCoordSys());
showGeometry(geometry);
}
}else if(measuerOpt == MEASUER_AREA){
if(lstMeasureDatas.size() > 2){
//显示
Point2D[] arrDatas = (Point2D[]) lstMeasureDatas.toArray();
GeoRegion geometry = new GeoRegion().Make(arrDatas);
showGeometry(geometry);
}
}
}
/**
* 显示
* @param geometry
*/
public void showGeometry(Geometry geometry){
if(geometry != null){
Style style = new Style();
style.fillForeColor = Color.RED;
style.lineColor = Color.RED;
style.lineWidth = Color.RED;
mMapView.GetTrackingLayer().Add(geometry);
mMapView.Refresh(true);
}
}
三、代码工程
https://github.com/junqinghaha/EasyMapDemos