ArcGIS for Android中的图层及其特点和使用方法 - 2012-12-14(3)

2019-09-01 15:22

new CallbackListener() {

public void onError(Throwable error) { // TODO implement error code }

public void onCallback(FeatureEditResult[][] editResult) {

// Check the response for success or failure

if (editResult[2] != null &&editResult[2][0] != null &&editResult[2][0].isSuccess()) {

// TODO implement success logic } } }); }

同样的,

CallbackListener用来监听applyEdits()方法异步处理的结果,onCallback()方法接收了一个多维数

组对象FeatureEditResult[ ][ ],这个对象包含了FeatureEditResult对象,而该对象是每次add、delete、update的结果。editResult[0]、editResult[1]、editResult[2]分别存储add、delete和update的结果。

Oncallback()方法即使在编辑错误时也会被调用,因此需要自己写一些代码来判断编辑是否成功。

Editing attributes

属性的编辑最重要的是要获取图层的字段信息,可使用feature layer的getFields()方法,该方法返回字段对象数组,字段对象(field objects)告诉你字段是否可编辑,以及字段的类型等,以下代码展示了如何获取图层字段,该代码片段确定了哪些字段可编辑哪些不可编辑,因此用户可以使用键盘键入数字、文字、日期等:

public booleanisFieldValidForEditing(Field field) {

intfieldType = field.getFieldType();

if (field.isEditable() &&fieldType != Field.esriFieldTypeOID&&fieldType != Field.esriFieldTypeGeometry

&&fieldType != Field.esriFieldTypeBlob&&fieldType != Field.esriFieldTypeRaster &&fieldType != Field.esriFieldTypeGUID&&fieldType != Field.esriFieldTypeXML) {

return true;

return false;

} else {

} }

以下方法是确定类型是text, date, number 和 decimal:

public void determineFieldType(Field field) {

if (field.getFieldType()== Field.esriFieldTypeString) { return FieldType.STRING;

} else if (field.getFieldType() == Field.esriFieldTypeSmallInteger || field.getFieldType() == Field.esriFieldTypeInteger) { return FieldType.NUMBER;

} else if (field.getFieldType() == Field.esriFieldTypeSingle || field.getFieldType()== Field.esriFieldTypeDouble) { return FieldType.DECIMAL;

} else if (field.getFieldType() == Field.esriFieldTypeDate) { return FieldType.DATE; }

return null; }

当你知道哪些字段可以编辑,你就能将其展现给用户,ArcGIS API for Android包含了多种view来展示,EditText就是最常用的对象,用来接收用户的输入,并且其大小、长度都能被灵活设定,不同类型的字段可现实不同类型的软键盘,以下示例展示了使用EditText对象来输入

decimal对象:

android:id=\android:layout_width=\android:layout_height=\android:minWidth=\android:maxWidth=\android:padding=\android:textSize=\

android:layout_alignParentLeft=\android:layout_marginLeft=\

android:inputType=\

对于子类型和值域,可以使用下拉列表对象。

在ArcGIS API for Android中,用户通过下拉列表和编辑文本框输入的内容都是string型的,在上传到服务器上之前,需要把他们转换成正确的类型,就可以使用到上上段代码。

上传至服务器Using FeatureLayer.applyEdits()

编辑已有要素的属性不同于add和delete这两种操作,而是要素的更新,同样也使用ArcGISFeatureLayer.applyEdits()异步方法实现,更新的要素作为第三个参数传递,被编辑过的要素的graphic对象不必包含很多attributes,可能只传递修改过的属性,但ObjectID必须传递过去以保证更新完成。示例如下:

/**

* Applies updates to a string field for a single feature. */

public void applyAttributeUpdates(String newAttributeValue, Field newAttributeField, String ObjectID, ArcGISFeatureLayerfeatureLayer, SimpleMarkerSymbol symbol) {

Mapattr = new HashMap(); attr.put(newAttributeField.getName(), newAttributeValue); attr.put(featureLayer.getObjectIdField(), ObjectID); graphic = new Graphic(geometry, symbol, attr, null);

featureLayer.applyEdits(null, null, new Graphic[] { graphic }, new CallbackListener() {

public void onError(Throwable error) { // TODO implement error code }

public void onCallback(FeatureEditResult[][] editResult) {

// Check the response for success or failure

if (editResult[2] != null &&editResult[2][0] != null &&editResult[2][0].isSuccess()) {

// TODO implement success logic } } }); }

同样的,

CallbackListener用来监听applyEdits()方法异步处理的结果,onCallback()方法接收了一个多维数

组对象FeatureEditResult[ ][ ],这个对象包含了FeatureEditResult对象,而该对象是每次add、delete、update的结果。editResult[0]、editResult[1]、editResult[2]分别存储add、delete和update的结果。

Oncallback()方法即使在编辑错误时也会被调用,因此需要自己写一些代码来判断编辑是否成功。


ArcGIS for Android中的图层及其特点和使用方法 - 2012-12-14(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:将进酒导学案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: