介绍

ArcGIS可以发布具有编辑功能的Feature Service。利用Feature Service我们可以实现对数据的在线编辑。 
数据制作参考: 
https://server.arcgis.com/zh-cn/server/latest/get-started/windows/tutorial-set-up-feature-service-data-for-offline-use.htm

实现

1.主界面

其中OutFields控制着属性的编辑,*代表都可以写入,也可以只填写你需要编辑的属性字段。

    <Grid>
<esri:MapView x:Name="MyMapView">
<esri:Map x:Name="MyMap">
<esri:ArcGISTiledMapServiceLayer x:Name="baseMap" ServiceUri="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
<esri:FeatureLayer ID="Incidents">
<esri:ServiceFeatureTable ServiceUri="http://localhost:6080/arcgis/rest/services/sichuan/test1/FeatureServer/0"
OutFields="*"/>
<!-- ServiceFeatureTable 中的 OutFields 控制着Attribute的编辑-->
</esri:FeatureLayer>
</esri:Map>
</esri:MapView>
<StackPanel x:Name="headPanel" Orientation="Horizontal" Margin="20,20,0,0">
<!-- 绑定编辑按钮-->
<StackPanel x:Name="headPanelMid" DataContext="{Binding ElementName=MyMapView, Path=Editor}"> </StackPanel> </StackPanel>
<Grid x:Name="centerGrid" Margin="200"></Grid>
</Grid>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

2.编辑

界面

<Grid>
<StackPanel x:Name="UserEdit" Orientation="Horizontal">
<Button Content="Edit"
Margin="2"
IsEnabled="False"
x:Name="EditButton"
Click="EditButton_Click" />
<Button Content="Attribute"
Margin="2"
IsEnabled="False"
x:Name="AttributeButton"
Click="AttributeButton_Click" />
<Button Content="Delete"
Margin="2"
IsEnabled="False"
x:Name="DeleteButton"
Click="EditButton_Click" />
<Button Content="Draw"
Margin="2"
x:Name="DrawButton"
Click="DrawButton_Click" /> <Button Content="Delete Vertex"
Margin="10,2,2,2"
Command="{Binding DeleteVertex}" />
<Button Content="Undo"
Margin="2"
Command="{Binding Undo}" />
<Button Content="Redo"
Margin="2"
Command="{Binding Redo}" />
<Button Content="Complete"
Margin="2"
Command="{Binding Complete}" />
<Button Content="Cancel"
Margin="2"
Command="{Binding Cancel}" />
</StackPanel>
</Grid>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

功能

主要是对Featureservice的图形进行编辑。 
首先从Featureservice中获取table,在table中进行一系列的操作。UpdateAsync修改的feature,DeleteAsync删除,AddAsync添加。最后通过SaveResult()将编辑结果上传到服务中。

public Edit()
{
InitializeComponent();
GlobalApp.MyMapView.MapViewTapped += MyMapView_MapViewTapped;
}
private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
{
if (GlobalApp.MyMapView.Editor.IsActive)
return;
var layer = GlobalApp.MyMapView.Map.Layers["Incidents"] as FeatureLayer;
layer.ClearSelection();
SetGeometryEditor();
string message = null;
try
{
// Performs hit test on layer to select feature.
var features = await layer.HitTestAsync(GlobalApp.MyMapView, e.Position);
if (features == null || !features.Any())
return;
var featureID = features.FirstOrDefault();
layer.SelectFeatures(new long[] { featureID });
var feature = await layer.FeatureTable.QueryAsync(featureID);
SetGeometryEditor(feature);
}
catch (Exception ex)
{
message = ex.Message;
}
if (!string.IsNullOrWhiteSpace(message))
MessageBox.Show(message);
}
private void SetGeometryEditor(Feature feature = null)
{
EditButton.Tag = feature;
EditButton.IsEnabled = feature == null ? false : true;
DeleteButton.IsEnabled = feature == null ? false : true;
AttributeButton.IsEnabled = feature == null ? false : true;
DrawButton.IsEnabled = feature == null ? true : false;
} private async void EditButton_Click(object sender, RoutedEventArgs e)
{
var feature = (Feature)EditButton.Tag;
var layer = GlobalApp.MyMapView.Map.Layers["Incidents"] as FeatureLayer;
var table = (ArcGISFeatureTable)layer.FeatureTable; string which_Button = (sender as Button).Content.ToString();
// Hides feature from feature layer while its geometry is being modified.
layer.SetFeatureVisibility(layer.SelectedFeatureIDs, false); string message = null;
try
{
// Enables geometry editing and update its geometry
// using GeometryEngine to correct ring orientation. if (which_Button == "Edit")
{
var geometry = await GlobalApp.MyMapView.Editor.EditGeometryAsync(feature.Geometry);
feature.Geometry = GeometryEngine.Simplify(geometry);
await table.UpdateAsync(feature);
this.SaveResult(table);
}
if (which_Button == "Delete")
{
await table.DeleteAsync(feature);
this.SaveResult(table);
}
if (which_Button == "Attribute1")
{
if (GlobalApp.mainwindow.centerGrid.Children != null)
GlobalApp.mainwindow.centerGrid.Children.Clear();
EditAttribute editAttribute = new EditAttribute(feature);
editAttribute.Height = 400;
editAttribute.Width = 400;
GlobalApp.mainwindow.centerGrid.Children.Add(editAttribute);
}
}
catch (TaskCanceledException)
{
// Ignore TaskCanceledException - usually happens if the editor gets cancelled or restarted
}
catch (Exception ex)
{
message = ex.Message;
}
finally
{
layer.SetFeatureVisibility(layer.SelectedFeatureIDs, true);
layer.ClearSelection();
SetGeometryEditor();
}
if (!string.IsNullOrWhiteSpace(message))
MessageBox.Show(message);
} private async void DrawButton_Click(object sender, RoutedEventArgs e)
{
var layer = GlobalApp.MyMapView.Map.Layers["Incidents"] as FeatureLayer;
var table = (ArcGISFeatureTable)layer.FeatureTable;
GeodatabaseFeature feature = table.CreateNew();
Esri.ArcGISRuntime.Geometry.Geometry addGeo = await GlobalApp.MyMapView.Editor.RequestShapeAsync(DrawShape.Polygon, null);
feature.Geometry = addGeo;
await table.AddAsync(feature.Attributes, addGeo);
this.SaveResult(table);
} private async void SaveResult(ArcGISFeatureTable table)
{
try
{
string message = null;
if (table.HasEdits)
{
if (table is ServiceFeatureTable)
{
var serviceTable = (ServiceFeatureTable)table;
// Pushes geometry edits back to the server.
var result = await serviceTable.ApplyEditsAsync();
if (result.UpdateResults == null || result.UpdateResults.Count < 1)
return;
var updateResult = result.UpdateResults[0];
if (updateResult.Error != null)
message = updateResult.Error.Message;
}
}
}catch(Exception e)
{ }
} private void AttributeButton_Click(object sender, RoutedEventArgs e)
{
var feature = (Feature)EditButton.Tag;
if (GlobalApp.mainwindow.centerGrid.Children != null)
GlobalApp.mainwindow.centerGrid.Children.Clear();
EditAttribute editAttribute = new EditAttribute(feature);
editAttribute.Height = 400;
editAttribute.Width = 300;
GlobalApp.mainwindow.centerGrid.Children.Add(editAttribute);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144

代码下载

《ArcGIS Runtime SDK for .NET开发笔记》--在线编辑的更多相关文章

  1. 《ArcGIS Runtime SDK for Android开发笔记》——离在线一体化技术:概述

    1.前言 数据生产和数据展示是常见的两大专业级移动GIS应用场景,这里我们针对数据生产环节的ArcGIS的离在线一体化技术给大家做一个基本的介绍和梳理. 使用ArcGIS离在线一体化技术首先需要以下基 ...

  2. 《ArcGIS Runtime SDK for Android开发笔记》——离在线一体化技术:离线矢量数据同步

    1.前言 上一篇文章中我们实现了离线要素的编辑操作,这一篇中主要介绍离在线一体化技术中最后一个环节离线数据的同步功能,通过对数据的上传,服务器端的版本化管理,实现数据生产管理的整个流程. 转载请注明出 ...

  3. 《ArcGIS Runtime SDK for Android开发笔记》

    开发笔记之基础教程 ArcGIS Runtime SDK for Android 各版本下载地址 <ArcGIS Runtime SDK for Android开发笔记>——(1).And ...

  4. 《ArcGIS Runtime SDK for Android开发笔记》——(7)、示例代码arcgis-runtime-samples-android的使用

    1.前言 学习ArcGIS Runtime SDK开发,其实最推荐的学习方式是直接看官方的教程.示例代码和帮助文档,因为官方的示例一般来说都是目前技术最新,也是最详尽的.对于ArcGIS Runtim ...

  5. 《ArcGIS Runtime SDK for Android开发笔记》——(9)、空间数据的容器-地图MapView

    1.前言 在上一篇内容里介绍了 关于ArcGIS Android开发的未来(“Quartz”版Beta)相关内容,期间也提到了关于API接口的重构,开发思路的调整,根据2015UC资料也可以知道新版预 ...

  6. 《ArcGIS Runtime SDK for Android开发笔记》——(5)、基于Android Studio构建ArcGIS Android开发环境(离线部署)(转)

    1.前言 在上一篇的内容里我们介绍了基于Android Studio构建ArcGIS Runtime SDK for Android开发环境的基本流程,流程中我们采用的是基于Gradle的构建方式,在 ...

  7. 《ArcGIS Runtime SDK for Android开发笔记》——(6)、基于Android Studio的ArcGIS Android工程结构解析

    1.前言 Android Studio 是第一个Google官方的 Android 开发环境.其他工具,例如 Eclipse,在 Android Studio 发布之前已经有了大规模的使用.为了帮助开 ...

  8. 《ArcGIS Runtime SDK for Android开发笔记》——(11)、ArcGIS Runtime SDK常见空间数据加载

    ArcGIS Runtime SDK for Android 支持多种类型空间数据源.每一种都提供了相应的图层来直接加载,图层Layer是空间数据的载体,其主要继承关系及类型说明如下图所示: 转载请注 ...

  9. 《ArcGIS Runtime SDK for Android开发笔记》——(3)、ArcGIS Runtime SDK概述

    1.前言 ArcGIS Runtime SDK是一整套用于构建原生及跨平台的地图应用程序的开发包,包括移动设备的Android.iOS.Windows Phone,针对桌面的.Net.Java.OSX ...

  10. 《ArcGIS Runtime SDK for Android开发笔记》——(8)、关于ArcGIS Android开发的未来(“Quartz”版Beta)

    1.前言 今天再一次在官网看到了ArcGIS Runtime SDK for Android下一个版本“Quartz”版的更新资料,它将是一个非常重要的更新,包括API接口的重构和开发思路的调整.具体 ...

随机推荐

  1. [CSP-S模拟测试]:涂色游戏(DP+组合数+矩阵快速幂)

    题目描述 小$A$和小$B$在做游戏.他们找到了一个$n$行$m$列呈网格状的画板.小$A$拿出了$p$支不同颜色的画笔,开始在上面涂色.看到小$A$涂好的画板,小$B$觉得颜色太单调了,于是把画板擦 ...

  2. 2018-2019-2 实验三 敏捷开发与XP实践

    实验内容 1.XP基础 2.XP核心实践 3.相关工具 实验要求 1.没有Linux基础的同学建议先学习<Linux基础入门(新版)><Vim编辑器> 课程 2.完成实验.撰写 ...

  3. frida的js脚本处理正则的一个小坑

    frida的server模式需要python支持,所以js脚本中的正则需要多一次转义 比如匹配"/proc/{数字pid}" server: paramPath.match(&qu ...

  4. PHP递归获得树形菜单和遍历文件夹下的所有文件以及子文件夹

    PHP递归获得树形菜单和遍历文件夹下的所有文件以及子文件夹 一.使用递归获取树形菜单 数据表category(id,name,parent_id) <?php class category{ / ...

  5. fiddler 暂停抓包

    或者点击左下角 capturing

  6. IPython notebook在浏览器中显示不正常的问题及解决方法

    使用过Python的童鞋们应该知道IPython是一个比python自带的交互式界面更加友好的交互界面,IPython提供了自动补齐什么的,其实我还没开始用所以这里也不扯淡了,大家自己去网上查,IPy ...

  7. JS实现上传图片的三种方法并实现预览图片功能

    地址:http://www.jb51.net/article/118660.htm js HTML5拖拽图片预览 地址:http://www.jb51.net/article/88803.htm js ...

  8. canvas时间粒子

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. python基础之运算符和编码

    while循环 什么是循环? 就是不断的重复做一件事 while --关键字 后边跟条件 :还有循环体. 条件体为真,循环体内执行,为假不执行 while else 两者为一体的,相当于 if els ...

  10. 49-python基础-python3-列表-常用列表统计函数-max()-min()-sum()

    max() min() sum() 1-数字列表统计 实例: 2-字符串列表统计. 根据ASCII码大小统计字符串列表的min()和max(). 注意:sum()函数无法统计字符串列表. 实例: