// Use the EditOperation in the RowChangedEventArgs to append actions to be executed. // Your actions will become part of the operation and combined into one item on the undo stack private void HookEvents() { // subscribe to the RowCreatedEvent Table table = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault().GetTable(); RowCreatedEvent.Subscribe(MyRowCreatedEvent, table); }
internal static void subRowEvent() { Dockpane1ViewModel pane = FrameworkApplication.DockPaneManager.Find(_dockPaneID) as Dockpane1ViewModel; QueuedTask.Run(() => { if (MapView.Active.GetSelectedLayers().Count == 0) { MessageBox.Show("Select a feature class from the Content 'Table of Content' first."); Utils.RunOnUIThread(() => { var contentsPane = FrameworkApplication.DockPaneManager.Find("esri_core_contentsDockPane"); contentsPane.Activate(); }); return; } //Listen for row events on a layer var featLayer = MapView.Active.GetSelectedLayers().First() as FeatureLayer; var layerTable = featLayer.GetTable(); pane.SelectedLayer = featLayer as BasicFeatureLayer; //subscribe to row events var rowCreateToken = RowCreatedEvent.Subscribe(pane.onCreatedRowEvent, layerTable); var rowChangedToken = RowChangedEvent.Subscribe(pane.onRowChangedEvent, layerTable); }); }
private void onProjectOpened(ProjectEventArgs obj) { //subscribe to edit completed event //this is across all maps and layers in the project EditCompletedEvent.Subscribe(onEditCompleted); //subscribe to row events for a certain layer in a certain map //look for a map named 'Layers' in the project var mapProjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name == "Layers"); if (mapProjItem == null) { return; } //run on MCT QueuedTask.Run(() => { var theMap = mapProjItem.GetMap(); //look for a layer named 'Parcels' in the map var featLayer = theMap.FindLayers("Parcels").FirstOrDefault() as FeatureLayer; if (featLayer == null) { return; } var layerTable = featLayer.GetTable(); //setup row events _rowCreateToken = RowCreatedEvent.Subscribe(onRowCreateEvent, layerTable); _rowDeleteToken = RowDeletedEvent.Subscribe(onRowDeleteEvent, layerTable); _rowChangedToken = RowChangedEvent.Subscribe(onRowChangedEvent, layerTable); }); }
protected override void OnClick() { QueuedTask.Run(async() => { //find layer and derive geodatabase var cpLayer = MapView.Active.Map.FindLayers("CrowdPlanning").FirstOrDefault() as FeatureLayer; if (cpLayer == null) { return; } var geodatabase = cpLayer.GetFeatureClass().GetDatastore() as Geodatabase; //Advise if the project has edits. Need to clear edits to make schema changes. if (Project.Current.HasEdits) { MessageBox.Show("Please save or discard edits", "Pending Edits"); return; } //Delete and Create the editlog table //For the purpose of this sample, start with a fresh table var mva = Geoprocessing.MakeValueArray(geodatabase.GetPath().AbsolutePath, "EditLog"); var cts = new System.Threading.CancellationTokenSource(); await Geoprocessing.ExecuteToolAsync("CreateTable_management", mva); //add fields to editlog var tablePath = geodatabase.GetPath().AbsolutePath + @"\EditLog"; mva = Geoprocessing.MakeValueArray(tablePath, "Layer", "STRING"); await Geoprocessing.ExecuteToolAsync("AddField_management", mva); mva = Geoprocessing.MakeValueArray(tablePath, "OID", "LONG"); await Geoprocessing.ExecuteToolAsync("AddField_management", mva); mva = Geoprocessing.MakeValueArray(tablePath, "Date", "DATE"); await Geoprocessing.ExecuteToolAsync("AddField_management", mva); mva = Geoprocessing.MakeValueArray(tablePath, "EditType", "STRING"); await Geoprocessing.ExecuteToolAsync("AddField_management", mva); _ehTable = MapView.Active.Map.FindStandaloneTables("EditLog").FirstOrDefault(); //setup row events for layer if (_rowChangedToken == null) { _rowChangedToken = RowChangedEvent.Subscribe(OnRowEvent, cpLayer.GetTable()); } if (_rowCreatedToken == null) { _rowCreatedToken = RowCreatedEvent.Subscribe(OnRowEvent, cpLayer.GetTable()); } if (_rowDeletedToken == null) { _rowDeletedToken = RowDeletedEvent.Subscribe(OnRowEvent, cpLayer.GetTable()); } }); }
protected void subRowEvent() { QueuedTask.Run(() => { //Listen for row events on a layer var featLayer = MapView.Active.GetSelectedLayers().First() as FeatureLayer; var layerTable = featLayer.GetTable(); //subscribe to row events var rowCreateToken = RowCreatedEvent.Subscribe(onRowEvent, layerTable); var rowChangeToken = RowChangedEvent.Subscribe(onRowEvent, layerTable); var rowDeleteToken = RowDeletedEvent.Subscribe(onRowEvent, layerTable); }); }
/// <summary> /// setup event listeners for a given featurelayer (with featurelayer name) /// </summary> /// <param name="activeMapView"></param> /// <param name="featureLayerName"></param> private void SetUpRowEventListener(MapView activeMapView, string featureLayerName) { // Find our polygon feature layer _workedOnPolygonLayer = activeMapView.Map.GetLayersAsFlattenedList().FirstOrDefault((fl) => fl.Name == featureLayerName) as FeatureLayer; UpdateStatusText((_workedOnPolygonLayer == null) ? $@"{featureLayerName} NOT found" : $@"Listening to {featureLayerName} changes"); // setup event listening ... QueuedTask.Run(() => { _onRowChangedEvent = RowChangedEvent.Subscribe(OnRowChangedEvent, _workedOnPolygonLayer.GetTable()); _onRowCreatedEvent = RowCreatedEvent.Subscribe(OnRowCreatedEvent, _workedOnPolygonLayer.GetTable()); }); }
protected void SetupEvents() { QueuedTask.Run(() => { var featLayer = MapView.Active.GetSelectedLayers().First() as FeatureLayer; var layerTable = featLayer.GetTable(); //subscribe to row events for a layer var rowCreateToken = RowCreatedEvent.Subscribe(onRowEvent, layerTable); var rowChangeToken = RowChangedEvent.Subscribe(onRowEvent, layerTable); var rowDeleteToken = RowDeletedEvent.Subscribe(onRowEvent, layerTable); }); //subscribe to editevents var editComplete = EditCompletedEvent.Subscribe(onEditComplete); }
private bool Register() { var layers = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>(); QueuedTask.Run(() => { foreach (var fl in layers) { var fc = fl.GetFeatureClass(); var tokens = new List <SubscriptionToken>(); //These events are fired once ~per feature~, //per table tokens.Add(RowCreatedEvent.Subscribe((rc) => RowEventHandler(rc), fc)); tokens.Add(RowChangedEvent.Subscribe((rc) => RowEventHandler(rc), fc)); tokens.Add(RowDeletedEvent.Subscribe((rc) => RowEventHandler(rc), fc)); _rowevents[fl.Name] = tokens; } //This event is fired once per edit execute //Note: This event won't fire if the edits were cancelled _editevents.Add(EditCompletingEvent.Subscribe((ec) => { RecordEvent("EditCompletingEvent", ""); //can also cancel edit in the completing event... //cancels everything (that is cancealable) // //you'll need to modify the RowEventHandler() to prevent if //from doing the cancel or this will never get called if (_cancelEdit) { ec.CancelEdit($"EditCompletingEvent, edit cancelled"); AddEntry("*** edits cancelled"); AddEntry("---------------------------------"); } })); //This event is fired after all the edits are completed (and on //save, discard, undo, redo) and is fired once _editevents.Add(EditCompletedEvent.Subscribe((ec) => { HandleEditCompletedEvent(ec); return(Task.FromResult(0)); })); }); return(true); }
public async Task <bool> InitializeEventsAsync() { bool result = (Layer.ConnectionStatus == ConnectionStatus.Connected); if (result) { MapSelectionChangedEvent.Subscribe(OnMapSelectionChanged); DrawCompleteEvent.Subscribe(OnDrawCompleted); await QueuedTask.Run(() => { var table = Layer.GetTable(); _rowChanged = RowChangedEvent.Subscribe(OnRowChanged, table); _rowDeleted = RowDeletedEvent.Subscribe(OnRowDeleted, table); _rowCreated = RowCreatedEvent.Subscribe(OnRowCreated, table); }); } await LoadMeasurementsAsync(); return(result); }