来自:http://blog.csdn.net/arcgis_mobile/article/details/8084763
GISpace博客《ArcGIS for Android入门程序之DrawTool》http://blog.csdn.net/gispace/article/details/6723459 在ArcGIS Android SDK 0.9版本实现绘制各种几个图形。ArcGIS Android SDK目前版本为2.0,较之前版本变化较大,故将之前版本移植到2.0版本下。源代码下载地址:http://download.csdn.net/detail/arcgis_mobile/4659389
该程序主要说明如何处理与MapView交互的各种事件,以订阅发布模式封装几何图形绘制工具类DrawTool,使用方法如下:
- <span style="font-family:Courier New;font-size:18px;">package cn.com.esrichina.drawtool;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuInflater;
- import android.view.MenuItem;
- import com.esri.android.map.GraphicsLayer;
- import com.esri.android.map.MapView;
- import com.esri.android.map.ags.ArcGISTiledMapServiceLayer;
- public class DrawToolActivity extends Activity implements DrawEventListener {
- private MapView mapView;
- private GraphicsLayer drawLayer;
- private DrawTool drawTool;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- this.mapView = (MapView) this.findViewById(R.id.map);
- // 添加底图
- this.mapView
- .addLayer(new ArcGISTiledMapServiceLayer(
- "http://www.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer"));
- // 在drawLayer上绘制几何图形
- this.drawLayer = new GraphicsLayer();
- this.mapView.addLayer(this.drawLayer);
- this.drawTool = new DrawTool(this.mapView);
- // 此类实现DawEventListener接口
- this.drawTool.addEventListener(this);
- }
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = this.getMenuInflater();
- inflater.inflate(R.menu.menu, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.point:
- drawTool.activate(DrawTool.POINT);
- break;
- case R.id.envelope:
- drawTool.activate(DrawTool.ENVELOPE);
- break;
- case R.id.polygon:
- drawTool.activate(DrawTool.POLYGON);
- break;
- case R.id.polyline:
- drawTool.activate(DrawTool.POLYLINE);
- break;
- case R.id.freehandpolygon:
- drawTool.activate(DrawTool.FREEHAND_POLYGON);
- break;
- case R.id.freehandpolyline:
- drawTool.activate(DrawTool.FREEHAND_POLYLINE);
- break;
- case R.id.circle:
- drawTool.activate(DrawTool.CIRCLE);
- break;
- case R.id.clear:
- this.drawLayer.removeAll();
- this.drawTool.deactivate();
- break;
- }
- return true;
- }
- // 实现DrawEventListener中定义的方法
- public void handleDrawEvent(DrawEvent event) {
- // 将画好的图形(已经实例化了Graphic),添加到drawLayer中并刷新显示
- this.drawLayer.addGraphic(event.getDrawGraphic());
- }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- }
- }</span>
在Android模拟器执行效果图如下: