public partial class MainWindow : Window { ArcGISLocalFeatureLayer arcGISLocalFeatureLayer; ESRI.ArcGIS.Client.Geometry.MapPoint _clickPoint; public MainWindow() { InitializeComponent(); LocalFeatureService.GetServiceAsync("Path to .mpk", (localFeatureService) => { arcGISLocalFeatureLayer = new ArcGISLocalFeatureLayer() { Service = localFeatureService, Editable = true, LayerId = 0, DisableClientCaching = true, AutoSave = false, Mode = ESRI.ArcGIS.Client.FeatureLayer.QueryMode.OnDemand, OutFields = new OutFields() { "*" }, };
arcGISLocalFeatureLayer.Initialized += (s, e) => { MessageBox.Show(arcGISLocalFeatureLayer.Graphics.Count.ToString()); }; arcGISLocalFeatureLayer.InitializationFailed += (s, e) => { MessageBox.Show(arcGISLocalFeatureLayer.InitializationFailure.Message); }; arcGISLocalFeatureLayer.UpdateCompleted += (s, e) => { _mapControl.IsEnabled = true; MessageBox.Show(arcGISLocalFeatureLayer.Graphics.Count.ToString()); };
_mapControl.Layers.Insert(1,arcGISLocalFeatureLayer);
private void _mapControl_MouseClick(object sender, Map.MouseEventArgs e) { _clickPoint = e.MapPoint; var graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = _clickPoint, };
if (arcGISLocalFeatureLayer.LayerInfo == null) return; //use LayerInfo.Fields foreach (var field in arcGISLocalFeatureLayer.LayerInfo.Fields) graphic.Attributes[field.Name] = null; //use PrototypeAttributes FeatureTemplate featureTemplate = null; if (arcGISLocalFeatureLayer.LayerInfo.Templates != null && arcGISLocalFeatureLayer.LayerInfo.Templates.Count > 0) featureTemplate = arcGISLocalFeatureLayer.LayerInfo.Templates.FirstOrDefault().Value; else if (arcGISLocalFeatureLayer.LayerInfo.FeatureTypes != null && arcGISLocalFeatureLayer.LayerInfo.FeatureTypes.Count > 0) { var featureType = arcGISLocalFeatureLayer.LayerInfo.FeatureTypes.FirstOrDefault(); if (featureType.Value != null && featureType.Value.Templates != null) featureTemplate = featureType.Value.Templates.FirstOrDefault().Value; } if (featureTemplate != null && featureTemplate.PrototypeAttributes != null) { foreach (var item in featureTemplate.PrototypeAttributes) graphic.Attributes[item.Key] = item.Value; }
arcGISLocalFeatureLayer.Graphics.Add(graphic);
arcGISLocalFeatureLayer.BeginSaveEdits += (s1, beginEditEventArgs) => { }; arcGISLocalFeatureLayer.EndSaveEdits += (s2, endEditEventArgs) => { MessageBox.Show(arcGISLocalFeatureLayer.Graphics.Count.ToString()); }; arcGISLocalFeatureLayer.SaveEditsFailed += (s3, taskFailedEventArgs) => { string message = taskFailedEventArgs.Error.Message; ServiceException serviceEx = taskFailedEventArgs.Error as ServiceException; if (serviceEx != null && serviceEx.Details != null && serviceEx.Details.Count > 0) message += serviceEx.Details[0]; };
arcGISLocalFeatureLayer.SaveEdits(); } } }
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.