-
-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix MouseCoordinatesWidget and Widget updates after Map change #2210
Conversation
@@ -699,8 +703,20 @@ private List<IWidgetExtended> GetExtendedWidgets() | |||
return _extendedWidgets; | |||
} | |||
|
|||
private void AssureWidgets() | |||
{ | |||
if (_widgetCollection != Map.Widgets) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the widget Collection changes set the cached Widgets (touchable and extended to null) to recreate them. The widgetcollection changes normally when a new map is assigned to the control
if (_updateWidget != Map.Widgets.Count || _extendedWidgets == null) | ||
{ | ||
_updateWidget = Map.Widgets.Count; | ||
_extendedWidgets = new List<IWidgetExtended>(); | ||
var widgetsOfMapAndLayers = Map.GetWidgetsOfMapAndLayers().ToList(); | ||
foreach (var widget in widgetsOfMapAndLayers) | ||
{ | ||
if (widget is IWidgetExtended extendedWidget && extendedWidget.Touchable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extended Widget do not need to handle touchable this is only for IWidget Widgets.
Because When a IWidget is Touchable I cancle the Touching Event so that the Touching Event does not propagate further.
@@ -1,5 +1,5 @@ | |||
namespace Mapsui.Widgets; | |||
public interface IWidgetExtended : IWidget, IWidgetTouchable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the IWidgetTouchable because an IWidgetExtended handles all Events anyway
@@ -64,6 +65,8 @@ public partial class MapControl : INotifyPropertyChanged, IDisposable | |||
private readonly System.Diagnostics.Stopwatch _stopwatch = new System.Diagnostics.Stopwatch(); | |||
// saving list of extended Widgets | |||
private List<IWidgetExtended>? _extendedWidgets; | |||
// old widget Collection to compare if widget Collection was changed. | |||
private ConcurrentQueue<IWidget>? _widgetCollection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One general remark about the ConcurrentQueue. If we need a thread save collection one of the things we need to ask ourselves is why is it needed. Not everything needs to be accessed from multiple threads and if we can make cross thread access impossible with our design this a better solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Muchas gracias!
Fixes this
#2209
#2208