1. Preface
The feature drawing and editing of the mid-line surface of mobile GIS project is the most common operation, and the ArcGIS Runtime SDK for IOS comes with the Agssketchlayer class to help users to quickly implement the feature drawing and graphic editing. However, in the ArcGIS Runtime SDK for Android version does not provide similar functionality, the implementation process is relatively complex. (10.2.8 and the following versions require a user-defined extension implementation, by extending the Mapontouchlistener class implementation, the quartz version of the SDK comes with the default)
Before the great God Gispace encapsulated the DrawTools2.0 tool class demo, to achieve a simple feature rendering. However, there is no good representation of the feature drawing and editing state, such as node, fallback operation and so on. So in view of this, I extend the implementation of the DrawTools3.0 on the basis of the DrawTools2.0 tool class, this version can achieve the basic point line Surface feature drawing, fine display the node change information, support DOT, delete point, move point operation.
DrawTools2.0 Address: http://blog.csdn.net/gispace/article/details/6723459
Reprint Please specify source: http://www.cnblogs.com/gis-luq/p/5857661.html
2. Instructions for use
DRAWTOOLS3.0 based on the development of DrawTools2.0 extension, the use of ideas are basically consistent, increase node increase, node deletion, fallback operation, feature editing state open and close operation.
Open source project library address: http://git.oschina.net/gis-luq/DrawTool3.0
Use process
- Initializes the Drawtool tool.
- Use activity to extend the Draweventlistener and set the current activity to Drawtool listener.
- Implement the Handledrawevent method in Draweventlistener.
- Use the Drawtool tool to draw a graphic.
Mainactivity.java
PackageCom.gis_luq.drawtoolsdemo;Importandroid.app.Activity;ImportAndroid.content.Context;ImportAndroid.os.Bundle;ImportAndroid.widget.Button;ImportCom.esri.android.map.GraphicsLayer;ImportCom.esri.android.map.MapOnTouchListener;ImportCom.esri.android.map.MapView;ImportCom.esri.android.map.ags.ArcGISTiledMapServiceLayer;Importcom.esri.core.map.Graphic;Importcom.esri.core.table.TableException;Importcom.gis_luq.lib.Draw.DrawEvent;ImportCom.gis_luq.lib.Draw.DrawEventListener;ImportCom.gis_luq.lib.Draw.DrawTool;Importjava.io.FileNotFoundException; Public classMainactivityextendsActivityImplementsDraweventlistener {Privatecontext Context; PrivateMapview Mapview =NULL; PrivateArcgistiledmapservicelayer Arcgistiledmapservicelayer =NULL; PrivateGraphicslayer Graphicslayer =NULL; PrivateGraphic selectgraphic =NULL; PrivateDrawtool Drawtool; PublicMapontouchlistener Mapdefaultontouchlistener;//Default Click events PublicDraweventlistener Draweventlistener;//feature Draw Click events@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Context= This; This. Mapview = (Mapview) This. Findviewbyid (R.id.map);//set UI and code bindingsString Strmapurl= "Http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer"; This. Arcgistiledmapservicelayer =NewArcgistiledmapservicelayer (Strmapurl); This. Mapview.addlayer (Arcgistiledmapservicelayer); Graphicslayer=NewGraphicslayer (); This. Mapview.addlayer (Graphicslayer); //initializing an Drawtool instance This. Drawtool =NewDrawtool ( This. Mapview); //set this activity to the listener of the Drawtool instance This. Drawtool.addeventlistener ( This); //Set Map EventsMapdefaultontouchlistener =NewMapontouchlistener ( This. Mapview.getcontext (), This. Mapview); Draweventlistener= This; Toolsonclicklistener Toolsonclicklistener=NewToolsonclicklistener (Context,drawtool,selectgraphic,mapview); Button Btndrawpoint= (Button) This. Findviewbyid (R.id.btndrawpoint); Btndrawpoint.setonclicklistener (Toolsonclicklistener); Button Btndrawpolyline= (Button) This. Findviewbyid (R.id.btndrawpolyline); Btndrawpolyline.setonclicklistener (Toolsonclicklistener); Button Btndrawfreepolyline= (Button) This. Findviewbyid (R.id.btndrawfreepolyline); Btndrawfreepolyline.setonclicklistener (Toolsonclicklistener); Button Btndrawpolygon= (Button) This. Findviewbyid (R.id.btndrawpolygon); Btndrawpolygon.setonclicklistener (Toolsonclicklistener); Button Btndrawfreepolygon= (Button) This. Findviewbyid (R.id.btndrawfreepolygon); Btndrawfreepolygon.setonclicklistener (Toolsonclicklistener); Button btndrawcircle= (Button) This. Findviewbyid (r.id.btndrawcircle); Btndrawcircle.setonclicklistener (Toolsonclicklistener); Button Btndrawenvlope= (Button) This. Findviewbyid (R.id.btndrawenvlope); Btndrawenvlope.setonclicklistener (Toolsonclicklistener); Button Btndraweditor= (Button) This. Findviewbyid (R.id.btndrawsave); Btndraweditor.setonclicklistener (Toolsonclicklistener); Button Btndrawundo= (Button) This. Findviewbyid (R.id.btndrawundo); Btndrawundo.setonclicklistener (Toolsonclicklistener); Button Btndrawdeletenode= (Button) This. Findviewbyid (R.id.btndrawdeletenode); Btndrawdeletenode.setonclicklistener (Toolsonclicklistener); } @Override Public voidHandledrawevent (Drawevent event)throwstableexception, FileNotFoundException {//draw the drawing (already instantiated graphic), add to Drawlayer and refresh the display This. Graphicslayer.addgraphic (Event.getdrawgraphic ()); //Modify click events as Default This. Mapview.setontouchlistener (Mapdefaultontouchlistener); }}
Toolsonclicklistener.java
PackageCom.gis_luq.drawtoolsdemo;ImportAndroid.content.Context;ImportAndroid.view.View;ImportCom.esri.android.map.MapView;Importcom.esri.core.map.Graphic;ImportCom.gis_luq.lib.Draw.DrawTool;/*** Draw Click event * Created by Gis-luq on 2016/1/2.*/ Public classToolsonclicklistenerImplementsView.onclicklistener {PrivateContext context =NULL; PrivateDrawtool Drawtool =NULL; PrivateGraphic selectgraphic =NULL; PrivateMapview Mapview =NULL; PublicToolsonclicklistener (Context context, Drawtool Drawtool, Graphic selectgraphic, Mapview mapview) { This. Context =context; This. Drawtool =Drawtool; This. selectgraphic =selectgraphic; This. Mapview =Mapview; } @Override Public voidOnClick (View v) {Switch(V.getid ()) { CaseR.id.btndrawpoint://Draw pointsdrawtool.activate (Drawtool.point); Break; CaseR.id.btndrawpolyline://Draw Linesdrawtool.activate (Drawtool.polyline); Break; CaseR.id.btndrawfreepolyline://draw a flow linedrawtool.activate (Drawtool.freehand_polyline); Break; CaseR.id.btndrawpolygon://Drawing Polygonsdrawtool.activate (Drawtool.polygon); Break; CaseR.id.btndrawfreepolygon://draw a flow surfacedrawtool.activate (Drawtool.freehand_polygon); Break; CaseR.id.btndrawcircle://Draw a circledrawtool.activate (drawtool.circle); Break; CaseR.id.btndrawenvlope://Draw a rectangledrawtool.activate (Drawtool.envelope); Break; CaseR.id.btndrawsave://Savedrawtool.senddrawendevent (); Break; CaseR.id.btndrawundo:// Fallback if(Drawtool.isactive ()) {Drawtool.actionundo (); } Break; CaseR.id.btndrawdeletenode://Delete a node if(Drawtool.isactive ()) {drawtool.actiondelete (); } Break; } }}
"ArcGIS Runtime SDK for Android Development note"--(15), feature draw Drawtools3.0 tool demo