/// <summary> /// React on editing ended. /// </summary> /// <param name="commit">Is in case of editing in grid try to commit changes.</param> private void _EditEnded(bool commit) { if (_isReccurent) return; if (_barrierPopupEditor != null) { // If barrier popup editor is still showed - close it. _barrierPopupEditor.Close(); _barrierPopupEditor.OnComplete -= new EventHandler(_BarrierPopupEditorOnComplete); _barrierPopupEditor = null; } _mapCtrl.EditEnded(); if (_mapCtrl.IsInEditedMode) { _isReccurent = true; _mapCtrl.EditEnded(); _isReccurent = false; } if (_dataGridControl.IsBeingEdited && !_canceledByGrid) { _isReccurent = true; // If command from map to commit was come, than try to end edit and commit // otherwise cancel edit. if (commit) { _SaveGeometry(); try { _dataGridControl.EndEdit(); } catch { _dataGridControl.CancelEdit(); } } else _dataGridControl.CancelEdit(); _isReccurent = false; } // Must be set false after commiting\cancelling in datagrid control. // Because of supporting API issues in cancelling. _isInEditedMode = false; if (_dataGridControl.SelectedItems.Count != 1) _SetToolsEnabled(false); _parentLayer.Selectable = true; }
/// <summary> /// Show barrier editor on map /// </summary> /// <param name="barrier">Barrier to show.</param> /// <param name="point">Last added point.</param> private void _ShowBarrierEditor(Barrier barrier, Point point) { _barrierPopupEditor = new BarrierPopupEditor(); //Subscribe to popupeditor events. _barrierPopupEditor.OnComplete += new EventHandler(_BarrierPopupEditorOnComplete); _barrierPopupEditor.OnCancel += new EventHandler(_BarrierPopupEditorOnCancel); Point projectedPoint = new Point(point.X, point.Y); if (_mapCtrl.Map.SpatialReferenceID.HasValue) { projectedPoint = WebMercatorUtil.ProjectPointToWebMercator(projectedPoint, _mapCtrl.Map.SpatialReferenceID.Value); } // Get left down point. System.Windows.Point screenPoint = _mapCtrl.map.MapToScreen(new ESRI.ArcGIS.Client.Geometry.MapPoint(projectedPoint.X, projectedPoint.Y)); System.Windows.Rect rect = new System.Windows.Rect( screenPoint.X, screenPoint.Y - _barrierPopupEditor.MinHeight, _barrierPopupEditor.MinWidth, _barrierPopupEditor.MinHeight); Popup popup = _CreatePopup(_barrierPopupEditor, rect); _barrierPopupEditor.Initialize(barrier, popup); }
/// <summary> /// Reset tools and revert to initial geometry. /// </summary> private void _CancelEdit() { // Close popup if it is open. if (_barrierPopupEditor != null) { _barrierPopupEditor.Close(); _barrierPopupEditor = null; } // Deactivate current tool. _SetToolsEnabled(false); // Enable tools. _SetToolsEnabled(true); // End edit. if (_isInEditedMode) _EditEnded(false); // Restore item's initial geometry. if (_currentItem is Barrier) (_currentItem as Barrier).Geometry = _initialGeometry; else if (_currentItem is Zone) (_currentItem as Zone).Geometry = _initialGeometry; }