《ArcGIS Runtime SDK for .NET开发笔记》--在线编辑
来源:互联网 发布:jackson转换json 编辑:程序博客网 时间:2024/06/08 04:14
介绍
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>
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>
功能
主要是对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); }
代码下载
0 0
- 《ArcGIS Runtime SDK for .NET开发笔记》--在线编辑
- 《ArcGIS Runtime SDK for .NET开发笔记》 --Hello Word
- 《ArcGIS Runtime SDK for .NET开发笔记》--三维功能
- 《ArcGIS Runtime SDK for Android开发笔记》——(3)、ArcGIS Runtime SDK概述
- 《ArcGIS Runtime SDK for .Net开发笔记》--介绍与环境搭建
- ArcGIS Runtime for .Net Quartz开发探秘(一):ArcGIS Runtime SDK for .Net简介及开发必要准备
- ArcGIS Runtime SDK for .Net介绍
- ArcGIS Runtime Sdk for .Net基本介绍
- 《ArcGIS Runtime SDK for Android开发笔记》——翻译:ArcGIS Runtime SDK for Android 10.2.7发布
- ArcGIS Runtime SDK for iOS开发介绍
- 《ArcGIS Runtime SDK for Android开发笔记》——(10)、ArcGIS Runtime SDK支持的空间数据类型
- 《ArcGIS Runtime SDK for Android开发笔记》——(7)、示例代码arcgis-runtime-samples-android的使用
- ArcGIS Runtime for .Net Quartz开发探秘(七):外业数据采集-离线数据编辑
- ArcGIS Runtime for .NET
- 《ArcGIS Runtime SDK for Android开发笔记》——(1)、Android Studio下载与安装
- 《ArcGIS Runtime SDK for Android开发笔记》——(4)、基于Android Studio构建ArcGIS Android开发环境
- 《ArcGIS Runtime SDK for Android开发笔记》——(6)、基于Android Studio的ArcGIS Android工程结构解析
- ArcGIS Runtime SDK for Android 1.1 搭建开发环境说明
- MYSQL使用UTF8中文乱码终极解决办法
- js 函数的几种写法
- 友盟分享遇到的问题iphone5
- Java NIO:浅析I/O模型
- Fragment中使用startActivityForResult
- 《ArcGIS Runtime SDK for .NET开发笔记》--在线编辑
- c语言宏定义#define的理解与资料整理
- jfinal前端前台传json后台接收
- 内存映射函数
- iOS屏幕截取,截屏办法
- 敏捷开发流程
- 项目管理
- jQuery UI 配合 icon 设计出 gif 动态图效果
- FFMPEG新老接口问题的部分解决方案