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
Package Com.gis_luq.drawtoolsdemo;import Android.app.activity;import Android.content.context;import Android.os.bundle;import Android.widget.button;import Com.esri.android.map.graphicslayer;import Com.esri.android.map.mapontouchlistener;import Com.esri.android.map.mapview;import Com.esri.android.map.ags.arcgistiledmapservicelayer;import Com.esri.core.map.graphic;import Com.esri.core.table.tableexception;import Com.gis_luq.lib.draw.drawevent;import Com.gis_ Luq.lib.draw.draweventlistener;import Com.gis_luq.lib.draw.drawtool;import Java.io.filenotfoundexception;public Class Mainactivity extends Activity implements Draweventlistener {private context context; Private Mapview Mapview = null; Private Arcgistiledmapservicelayer arcgistiledmapservicelayer = null; Private Graphicslayer graphicslayer = null; Private Graphic selectgraphic = null; Private Drawtool Drawtool; Public mapontouchlistener mapdefaultontouchlistener;//Default Click event Public Draweventlistener Draweventlistener;//feature Draw Click event @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate ); Setcontentview (R.layout.activity_main); context = this; This.mapview = (Mapview) This.findviewbyid (R.ID.MAP);//Set UI and code binding String strmapurl= "http://map.geoq.cn/ArcGIS/rest/s Ervices/chinaonlinecommunity/mapserver "; This.arcgistiledmapservicelayer = new Arcgistiledmapservicelayer (Strmapurl); This.mapView.addLayer (Arcgistiledmapservicelayer); Graphicslayer = new Graphicslayer (); This.mapView.addLayer (Graphicslayer); Initializes the Drawtool instance This.drawtool = new Drawtool (This.mapview); Set this activity to the listener This.drawTool.addEventListener (this) of the Drawtool instance; Set Map Events Mapdefaultontouchlistener = new Mapontouchlistener (This.mapView.getContext (), This.mapview); Draweventlistener = this; Toolsonclicklistener Toolsonclicklistener = new Toolsonclicklistener (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 void Handledrawevent (Drawevent event) throws Tableexception, FileNotFoundException {//will draw Good graphics (already instantiated graphic), add to Drawlayer and refresh the display this.graphicsLayer.addGraphic (Event.getdrawgraphic ()); Modify the Click event as Default This.mapView.setOnTouchListener (Mapdefaultontouchlistener); }}
Toolsonclicklistener.java
Package Com.gis_luq.drawtoolsdemo;import Android.content.context;import Android.view.view;import Com.esri.android.map.mapview;import com.esri.core.map.graphic;import com.gis_luq.lib.draw.drawtool;/** * Drawing Click events * Created by Gis-luq on 2016/1/2. */public class Toolsonclicklistener implements View.onclicklistener {Private context context = NULL; Private Drawtool drawtool = null; Private Graphic selectgraphic =null; Private Mapview Mapview = null; Public Toolsonclicklistener (context context, Drawtool Drawtool, Graphic selectgraphic, Mapview mapview) {This.cont ext = context; This.drawtool = Drawtool; This.selectgraphic = selectgraphic; This.mapview = Mapview; } @Override public void OnClick (View v) {switch (V.getid ()) {r.id.btndrawpoint://plot point Drawtool.activate (Drawtool.point); Break Case r.id.btndrawpolyline://Draw Line Drawtool.activate (Drawtool.polyline); Break Case r.id.btndrawfreepolyline://Draw Flow line drawtool.activate (drawtool.freehand_polyline); Break Case r.id.btndrawpolygon://Drawing Surface drawtool.activate (Drawtool.polygon); Break Case r.id.btndrawfreepolygon://Draw the Drawtool.activate (Drawtool.freehand_polygon) of the flow plane; Break Case r.id.btndrawcircle://Draw round drawtool.activate (drawtool.circle); Break Case r.id.btndrawenvlope://Draws a rectangle drawtool.activate (drawtool.envelope); Break Case r.id.btndrawsave://Save Drawtool.senddrawendevent (); Break Case r.id.btndrawundo://fallback Drawtool.actionundo (); Break Case r.id.btndrawdeletenode://Delete node drawtool.actiondelete (); Break } }}
"ArcGIS Runtime SDK for Android Development note"--(15), feature draw Drawtools3.0 tool demo