ArcGIS for Android入门程序之DrawTool2.0

来自: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,使用方法如下:

 

 

[java]  view plain copy
 
  1. <span style="font-family:Courier New;font-size:18px;">package cn.com.esrichina.drawtool;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.view.Menu;  
  6. import android.view.MenuInflater;  
  7. import android.view.MenuItem;  
  8.   
  9. import com.esri.android.map.GraphicsLayer;  
  10. import com.esri.android.map.MapView;  
  11. import com.esri.android.map.ags.ArcGISTiledMapServiceLayer;  
  12.   
  13. public class DrawToolActivity extends Activity implements DrawEventListener {  
  14.   
  15.     private MapView mapView;  
  16.     private GraphicsLayer drawLayer;  
  17.     private DrawTool drawTool;  
  18.   
  19.     public void onCreate(Bundle savedInstanceState) {  
  20.         super.onCreate(savedInstanceState);  
  21.         setContentView(R.layout.main);  
  22.   
  23.         this.mapView = (MapView) this.findViewById(R.id.map);  
  24.         // 添加底图  
  25.         this.mapView  
  26.                 .addLayer(new ArcGISTiledMapServiceLayer(  
  27.                         "http://www.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer"));  
  28.         // 在drawLayer上绘制几何图形  
  29.         this.drawLayer = new GraphicsLayer();  
  30.         this.mapView.addLayer(this.drawLayer);  
  31.         this.drawTool = new DrawTool(this.mapView);  
  32.         // 此类实现DawEventListener接口  
  33.         this.drawTool.addEventListener(this);  
  34.     }  
  35.   
  36.     public boolean onCreateOptionsMenu(Menu menu) {  
  37.         MenuInflater inflater = this.getMenuInflater();  
  38.         inflater.inflate(R.menu.menu, menu);  
  39.         return true;  
  40.     }  
  41.   
  42.     @Override  
  43.     public boolean onOptionsItemSelected(MenuItem item) {  
  44.         switch (item.getItemId()) {  
  45.         case R.id.point:  
  46.             drawTool.activate(DrawTool.POINT);  
  47.             break;  
  48.         case R.id.envelope:  
  49.             drawTool.activate(DrawTool.ENVELOPE);  
  50.             break;  
  51.         case R.id.polygon:  
  52.             drawTool.activate(DrawTool.POLYGON);  
  53.             break;  
  54.         case R.id.polyline:  
  55.             drawTool.activate(DrawTool.POLYLINE);  
  56.             break;  
  57.         case R.id.freehandpolygon:  
  58.             drawTool.activate(DrawTool.FREEHAND_POLYGON);  
  59.             break;  
  60.         case R.id.freehandpolyline:  
  61.             drawTool.activate(DrawTool.FREEHAND_POLYLINE);  
  62.             break;  
  63.         case R.id.circle:  
  64.             drawTool.activate(DrawTool.CIRCLE);  
  65.             break;  
  66.         case R.id.clear:  
  67.             this.drawLayer.removeAll();  
  68.             this.drawTool.deactivate();  
  69.             break;  
  70.         }  
  71.         return true;  
  72.     }  
  73.   
  74.     // 实现DrawEventListener中定义的方法  
  75.     public void handleDrawEvent(DrawEvent event) {  
  76.         // 将画好的图形(已经实例化了Graphic),添加到drawLayer中并刷新显示  
  77.         this.drawLayer.addGraphic(event.getDrawGraphic());  
  78.     }  
  79.   
  80.     @Override  
  81.     protected void onDestroy() {  
  82.         super.onDestroy();  
  83.     }  
  84. }</span>  


在Android模拟器执行效果图如下:

 

ArcGIS for Android入门程序之DrawTool2.0

你可能感兴趣的:(android)