/** |
* 地图控件单击事件 |
* @param e 屏幕单击事件 |
* @return boolean |
*/ |
public boolean onSingleTap(MotionEvent e) { |
|
// 如果正处于编辑状态且不处于查询状态 |
if (!isQuery&&isEdit){ |
|
// 设置浮动按钮可见 |
save.setVisibility(Button.VISIBLE); |
cancel.setVisibility(Button.VISIBLE); |
|
// 如果当前正在编辑的类型为点 |
if (geometryType.length() > 1 && geometryType.equalsIgnoreCase( "POINT" ) && isEdit) { |
|
// 绘制点时首先清除图层要素 |
Log.d(TAG, "---->lastPointID:" +lastGraphicID); |
Log.d(TAG, "---->lastType:" +lastType); |
|
if (lastGraphicID!=- 1 &&lastType.equalsIgnoreCase(geometryTypes[ 0 ])){ |
|
gLayer.updateGraphic(lastGraphicID, map.toMapPoint( new Point(e.getX(), e.getY()))); |
|
Log.d(TAG, "---->Update Point----<" ); |
|
} else { |
|
Graphic graphic = new Graphic(map.toMapPoint( new Point(e.getX(), e.getY())), new SimpleMarkerSymbol(Color.RED, 10 ,STYLE.CIRCLE),graphicAttributes, null ); |
|
Log.d(TAG, "---->Add Point----<" ); |
// 将新建点要素添加到图层上 |
lastGraphicID = gLayer.addGraphic(graphic); |
|
map.addLayer(gLayer); |
} |
Log.d(TAG, "---->NowPointID:" +lastGraphicID); |
|
lastType = geometryTypes[ 0 ]; |
|
} else if (geometryType.length() > 1 && (geometryType.equalsIgnoreCase( "POLYLINE" ))&& isEdit) { |
// 如果当前正在编辑的类型为线 |
Log.d(TAG, "---->L lastType:" +lastType); |
// 得到移动后的点 |
Point movePoint = new Point(map.toMapPoint(e.getX(), e.getY()).getX(),map.toMapPoint(e.getX(), e.getY()).getY()); |
|
// 判断startPoint是否为空,如果为空,给startPoint赋值 |
if (startPoint == null ) { |
|
polyline = new Polyline(); |
|
startPoint = new Point(movePoint.getX(),movePoint.getY()); |
|
//将第一个点存入poly中 |
polyline.startPath(startPoint); |
|
} else { |
// 如果要素存在两点以上(即存在线段) |
if (lastGraphicID!=- 1 &&lastType.equalsIgnoreCase(geometryTypes[ 1 ])&&polyline.getPointCount()> 1 ){ |
|
// 将移动的点放入poly中 |
polyline.lineTo(movePoint); |
|
gLayer.updateGraphic(lastGraphicID,polyline); |
|
map.addLayer(gLayer); |
|
} else { |
// 将移动的点放入poly中 |
polyline.lineTo(movePoint); |
|
Graphic linegraphic = new Graphic(polyline, new SimpleLineSymbol(Color.RED, 3 ),graphicAttributes, null ); |
|
lastGraphicID = gLayer.addGraphic(linegraphic); |
|
map.addLayer(gLayer); |
} |
|
} |
lastType = geometryTypes[ 1 ]; |
|
} else if (geometryType.length() > 1 && (geometryType.equalsIgnoreCase( "POLYGON" ))&& isEdit) { |
// 如果当前正在编辑的类型为面 |
Log.d(TAG, "---->G lastType:" +lastType); |
// 得到移动后的点 |
Point movePoint = map.toMapPoint(e.getX(), e.getY()); |
|
// 判断startPoint是否为空,如果为空,给startPoint赋值 |
if (startPoint == null ) { |
|
startPoint = new Point(movePoint.getX(),movePoint.getY()); |
|
// 将第一个点存入polygon中 |
polygon.startPath(startPoint); |
|
Log.d(TAG, "First Point Polygon!" ); |
|
} else { |
// 将后续点加入polygon中 |
polygon.lineTo(movePoint); |
// 如果上一要素类型为polygon |
if (lastGraphicID!=- 1 &&lastType.equalsIgnoreCase(geometryTypes[ 2 ])&&polygon.getPointCount()> 3 ){ |
// 将起点加入要素中,闭合图形 |
polygon.lineTo(startPoint); |
// 更新图形信息 |
gLayer.updateGraphic(lastGraphicID, polygon); |
|
map.addLayer(gLayer); |
// 移除闭合点 |
polygon.removePoint( 0 , - 1 ); |
|
Log.d(TAG, "Polygon Point >3:" ); |
|
} else if (lastType.equalsIgnoreCase(geometryTypes[ 2 ])&&polygon.getPointCount()== 3 ){ |
// 将起点加入要素中,闭合图形 |
polygon.lineTo(startPoint); |
// 新建闭合 |
Graphic areagraphic = new Graphic(polygon, new SimpleFillSymbol(Color.GRAY),graphicAttributes, null ); |
// 保存当前图形ID |
lastGraphicID = gLayer.addGraphic(areagraphic); |
// 移除闭合点 |
polygon.removePoint( 0 , - 1 ); |
|
map.addLayer(gLayer); |
|
Log.d(TAG, "Polygon Point 3:" ); |
} |
Log.d(TAG, "Polygon Point Count:" +polygon.getPointCount()); |
Log.d(TAG, "Polygon LastGraohic ID:" +lastGraphicID); |
} |
lastType = geometryTypes[ 2 ]; |
} |
hasFinish = false ; |
|
return true ; |
|
} |
by: 发表于:2018-01-02 10:00:41 顶(0) | 踩(0) 回复
??
回复评论