Skip to content
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

Merged
merged 2 commits into from Oct 9, 2023

Conversation

inforithmics
Copy link
Contributor

Fixes this
#2209
#2208

@@ -699,8 +703,20 @@ private List<IWidgetExtended> GetExtendedWidgets()
return _extendedWidgets;
}

private void AssureWidgets()
{
if (_widgetCollection != Map.Widgets)
Copy link
Contributor Author

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)
Copy link
Contributor Author

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
Copy link
Contributor Author

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;
Copy link
Member

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.

Copy link
Member

@pauldendulk pauldendulk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Muchas gracias!

@pauldendulk pauldendulk merged commit 9d25731 into Mapsui:master Oct 9, 2023
6 checks passed
@pauldendulk pauldendulk changed the title Fix: Mouse Pointer Widget and Widget Updates after Map Change Fix MouseCoordinatesWidget and Widget updates after Map change Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants