ArcGIS for android 要素添加 案例
来源:互联网 发布:证券行业研究员 知乎 编辑:程序博客网 时间:2024/05/21 21:44
要向地图添加要素,必须需要地图有 相应的接口
主要的难点在于理解FeatrueLayer下的applyEdit方法
public void applyEdits (Graphic[] adds, Graphic[] deletes, Graphic[] updates, CallbackListener<FeatureEditResult[][]> callback)
方法需要Graphic对象,而Graphic对象要从FeatrueLayer下的 createFeatureWithTemplate 得到public Graphic createFeatureWithTemplate (FeatureTemplate template, Geometry geometry)
而这个方法中的template又是从FeatureType对象方法中获得。一层套一层,挺麻烦的。通过不断的了解终于弄出了一个添加要素的demo程序
package guet.aerospider;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import com.esri.android.map.GraphicsLayer;import com.esri.android.map.MapView;import com.esri.android.map.ags.ArcGISFeatureLayer;import com.esri.android.map.ags.ArcGISTiledMapServiceLayer;import com.esri.android.map.event.OnSingleTapListener;import com.esri.android.map.event.OnStatusChangedListener;import com.esri.core.geometry.Point;import com.esri.core.map.CallbackListener;import com.esri.core.map.FeatureEditResult;import com.esri.core.map.FeatureTemplate;import com.esri.core.map.FeatureType;import com.esri.core.map.Graphic;public class TestActivity extends Activity {MapView mMapView ;ArcGISTiledMapServiceLayer tileLayer;ArcGISFeatureLayer fLayer;GraphicsLayer gLayer;Button featureAdd;Button featureUpdate;Button featureDel;Button featureSave;Point point;private static final int ADD = 0;protected static final String TAG = "mydemo";int editingmode = -1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);mMapView = (MapView)findViewById(R.id.mapview);featureAdd = (Button)findViewById(R.id.mainadd);featureDel = (Button)findViewById(R.id.maindelete);featureUpdate = (Button)findViewById(R.id.mainedit);featureSave = (Button)findViewById(R.id.mainsave);OnClickListenerImpl lis = new OnClickListenerImpl();featureAdd.setOnClickListener(lis);featureDel.setOnClickListener(lis);featureUpdate.setOnClickListener(lis);featureSave.setOnClickListener(lis);tileLayer = new ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer");fLayer = new ArcGISFeatureLayer("http://sampleserver5.arcgisonline.com/ArcGIS/rest/services/LocalGovernment/Recreation/FeatureServer/0", ArcGISFeatureLayer.MODE.ONDEMAND);mMapView.addLayer(tileLayer);mMapView.addLayer(fLayer);//设置mapview的状态改变监听mMapView.setOnStatusChangedListener(new OnStatusChangedListener(){private static final long serialVersionUID = -8650595291230795928L;public void onStatusChanged(Object source, STATUS status) {if(STATUS.INITIALIZED==status){gLayer = new GraphicsLayer();mMapView.addLayer(gLayer);featureUpdate.setEnabled(true);featureSave.setEnabled(true);featureDel.setEnabled(true);featureAdd.setEnabled(true);}}});//设置mapview的单击事件mMapView.setOnSingleTapListener(new OnSingleTapListener() {private static final long serialVersionUID = 1631794627814713202L;public void onSingleTap(float x, float y) {point = mMapView.toMapPoint(x, y);featureSave.setEnabled(true);}}); }//onCreate end //按钮监听类 class OnClickListenerImpl implements OnClickListener{public void onClick(View v) {switch (v.getId()) {case R.id.mainadd:editingmode = ADD;featureUpdate.setEnabled(false);featureDel.setEnabled(false);featureSave.setEnabled(false);featureAdd.setEnabled(false);break;case R.id.mainsave:save();break;default:break;}} } private void save() { //添加操作,默认添加camptingif (editingmode == ADD){featureSave.setEnabled(false);Graphic g = null;FeatureType[] types = fLayer.getTypes();for (FeatureType fType : types) {FeatureTemplate[] templates = fType.getTemplates();for (FeatureTemplate fTemp : templates) {String name = fTemp.getName();Log.i(TAG, "" + name);if ("Camping".equals(name)) {g = fLayer.createFeatureWithTemplate(fTemp, point);}}}fLayer.applyEdits(new Graphic[] { g }, null, null,new CallbackListener<FeatureEditResult[][]>() {public void onError(Throwable e) {Log.d(TAG, e.getMessage());}public void onCallback(FeatureEditResult[][] objs) {Log.i(TAG, "applyEdit returns");featureUpdate.setEnabled(true);featureDel.setEnabled(true);featureSave.setEnabled(true);featureAdd.setEnabled(true);}});editingmode = -1;}}@Override protected void onDestroy() { super.onDestroy(); }@Overrideprotected void onPause() {super.onPause();mMapView.pause(); }@Override protected void onResume() {super.onResume(); mMapView.unpause();}}
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context=".TestActivity" > <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"><Button android:id="@+id/mainadd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="添加" android:enabled="false"/><Button android:id="@+id/mainedit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="修改" android:enabled="false"/><Button android:id="@+id/maindelete" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="删除" android:enabled="false"/><Button android:id="@+id/mainsave" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="保存" android:enabled="false"/></LinearLayout><com.esri.android.map.MapView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent"> </com.esri.android.map.MapView></LinearLayout>
- ArcGIS for android 要素添加 案例
- ArcGIS For Android 之客户端添加要素(130412)
- ArcGIS for Android示例解析之高亮要素-----HighlightFeatures
- ArcGIS for Android示例解析之要素识别-----IdentifyTask
- arcgis for Android 高亮显示选中要素
- ArcGIS API for Android 案例教程 1
- ArcGIS API for Android 案例教程 2
- ArcGIS API for Android 案例教程 3
- ArcGIS API for Android 案例教程 4
- ArcGIS API for Android 案例教程 5
- ArcGIS API for Android 案例教程 6
- ArcGIS API for Android 案例教程 7
- ArcGIS API for Android 案例教程 8
- ArcGIS API for Android 案例教程 9
- ArcGIS API for Android 案例教程 10
- ArcGIS API for Android 案例教程 11
- ArcGIS API for Android 案例教程 12
- ArcGIS API for Android 案例教程 13
- 用Myeclipse开发 遇到顽固问题,一定要到tomcat webapp 下的classes下 看一下是否真的编译过去了。
- ABAP 月份加1
- Web_使用列表创建下拉菜单CSS
- 查找元素
- Android源码下载并绑定到Eclipse中
- ArcGIS for android 要素添加 案例
- Learning D3.js(4) layout之弦图chord的绘制(1)
- 数据库常断开问题
- test
- 栈的10进制以内转化
- Linux 系统中用户切换
- 关于使用vim插件的心得
- 深拷贝和浅拷贝的区别是什么?
- poj 1201 -Intervals