From 2ebba580b57379e030cf71d6c5257a8c90b3d01e Mon Sep 17 00:00:00 2001 From: Prathamesh Narkhede Date: Fri, 31 Oct 2025 17:33:54 -0700 Subject: [PATCH] Introduced logic to clear selected features when exiting Feature mode to prevent persistence. Added event handlers for GeometryEditor.PropertyChanged to manage geometry editing state changes. Implemented OnExternalGeometryEditorPropertyChanged to cancel feature measurement if an external geometry editing session starts, ensuring no conflict with feature identify measurement. --- .../MeasureToolbar/MeasureToolbar.cs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/Toolkit/Toolkit.UI.Controls/MeasureToolbar/MeasureToolbar.cs b/src/Toolkit/Toolkit.UI.Controls/MeasureToolbar/MeasureToolbar.cs index c329df2a6..43b5ffa9a 100644 --- a/src/Toolkit/Toolkit.UI.Controls/MeasureToolbar/MeasureToolbar.cs +++ b/src/Toolkit/Toolkit.UI.Controls/MeasureToolbar/MeasureToolbar.cs @@ -59,6 +59,15 @@ private MeasureToolbarMode Mode { if (_mode != value) { + // When leaving Feature mode, clear any previously selected feature so it does not persist. + if (_mode is MeasureToolbarMode.Feature && value is not MeasureToolbarMode.Feature) + { + _measureFeatureResultOverlay.Graphics.Clear(); + if (_clearButton is not null) + { + _clearButton.IsEnabled = false; + } + } _mode = value; PrepareMeasureMode(); } @@ -617,9 +626,50 @@ private static void OnMapViewPropertyChanged(DependencyObject d, DependencyPrope { oldMapView.GeoViewTapped -= toolbar.OnMapViewTapped; toolbar.RemoveMeasureFeatureResultOverlay(oldMapView); + if (oldMapView.GeometryEditor is not null) + { + oldMapView.GeometryEditor.PropertyChanged -= toolbar.OnExternalGeometryEditorPropertyChanged; + } } newMapView.GeoViewTapped += toolbar.OnMapViewTapped; + if (newMapView.GeometryEditor is not null) + { + newMapView.GeometryEditor.PropertyChanged += toolbar.OnExternalGeometryEditorPropertyChanged; + } + } + + /// + /// Watches the MapView.GeometryEditor for sessions started externally (not by this toolbar). + /// If a geometry editing session starts while in feature measurement mode, feature measurement is cancelled. + /// + /// + /// We only care when we are in Feature mode and the toolbar has not itself hooked the editor + /// (length/area measuring). In that case a foreign geometry editing workflow would conflict with + /// feature identify measurement, so we exit Feature mode and clear any selection. + /// + private void OnExternalGeometryEditorPropertyChanged(object? sender, PropertyChangedEventArgs e) + { + if (e.PropertyName is not nameof(GeometryEditor.IsStarted)) + { + return; + } + if (sender is not GeometryEditor ge) + { + return; + } + // Ignore if this toolbar owns the session (length/area modes) + if (_isGeometryEditorHooked) + { + return; + } + // If an external session starts while measuring a feature, end feature measurement. + if (ge.IsStarted && Mode is MeasureToolbarMode.Feature) + { + _measureFeatureResultOverlay.Graphics.Clear(); + Mode = MeasureToolbarMode.None; + DisplayResult(); + } } ///