android绘制二维图形,ArcGIS二维地图标绘

[android]代码库/**

* 地图控件单击事件

* @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;

}

694748ed64b9390909c0d88230893790.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值