介绍

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控制着属性的编辑,*代表都可以写入,也可以只填写你需要编辑的属性字段。

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

界面

  1. <Grid>
  2. <StackPanel x:Name="UserEdit" Orientation="Horizontal">
  3. <Button Content="Edit"
  4. Margin="2"
  5. IsEnabled="False"
  6. x:Name="EditButton"
  7. Click="EditButton_Click" />
  8. <Button Content="Attribute"
  9. Margin="2"
  10. IsEnabled="False"
  11. x:Name="AttributeButton"
  12. Click="AttributeButton_Click" />
  13. <Button Content="Delete"
  14. Margin="2"
  15. IsEnabled="False"
  16. x:Name="DeleteButton"
  17. Click="EditButton_Click" />
  18. <Button Content="Draw"
  19. Margin="2"
  20. x:Name="DrawButton"
  21. Click="DrawButton_Click" />
  22. <Button Content="Delete Vertex"
  23. Margin="10,2,2,2"
  24. Command="{Binding DeleteVertex}" />
  25. <Button Content="Undo"
  26. Margin="2"
  27. Command="{Binding Undo}" />
  28. <Button Content="Redo"
  29. Margin="2"
  30. Command="{Binding Redo}" />
  31. <Button Content="Complete"
  32. Margin="2"
  33. Command="{Binding Complete}" />
  34. <Button Content="Cancel"
  35. Margin="2"
  36. Command="{Binding Cancel}" />
  37. </StackPanel>
  38. </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()将编辑结果上传到服务中。

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

    题目描述 给你一个$n$个点$m$条边的带边权的无向图(无重边,无自环),现在对于每条边,问你这条边的权值最大可以是多大,使得这条边在无向图的所有最小生成树中?(边权都是整数). 输入格式 第一行包含 ...

  2. Checking out pull requests locally

    https://help.github.com/en/articles/checking-out-pull-requests-locally https://github.com/betaflight ...

  3. 删除STL容器中的元素

    有关stl容器删除元素的问题,错误的代码如下: std::vector<struct> mFriendList; ... std::vector<struct>::iterat ...

  4. 【SpringBoot】 一种解决接口返回慢的方式

    前言 使用springboot开发后台代码的时候,很核心的一个功能是为前端提供接口,那么很可能你会遇到如下问题: 1. 接口里面调用的service层是第三方库或者第三方后台程序,导致访问很慢. 2. ...

  5. Windows 08 R2_组策略

    目录 目录 组策略 组策略对象GPO 实验一组策略的计算机配置 实验二组策略的用户配置 实验三首选设置 实验四组策略更改计算机桌面 常用的组策略管理模块策略 限制用户运行指定的Windows程序 隐藏 ...

  6. <读书笔记>《锋利的jQuery》

    2016年4月3日 第4章 jq中的事件和动画 4.1 jq中的事件 (1)window.onload.$(documet).ready()的区别: 1.执行时机:window.onload需要整个页 ...

  7. UVA12174_Shuffle

    Shuffle 大致题意: 你有一个随机播放的播放器,有s首歌,在这s首播放完之前不会重新打乱顺序,现在给出一段只含有1~s的n长度序列,现在问你下次随机排序发生的时间有多少种可能 其实就是问你这个播 ...

  8. 十万级百万级数据量的Excel文件导入并写入数据库

    一.需求分析 最近接到一个需求,导入十万级,甚至可能百万数据量的记录了车辆黑名单的Excel文件,借此机会分析下编码过程; 首先将这个需求拆解,发现有三个比较复杂的问题: 问题一:Excel文件导入后 ...

  9. 如何将自己的代码上传至github

    前提条件: 有个github账号,电脑安装了git; 首先在自己的账号里新建一个仓库: https://github.com/qiqi105/littleAlbum.git 进入到你要上传的文件夹内部 ...

  10. Blueprint的实现

    Blueprint其实本身只是对view上的接口进行了注册,然后整体挂载在app上,Blueprint本身的目的就是组织多模块的平行共存,避免直接在app上注册view,其实更多的只是方便开发和代码的 ...