-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add Pin.ShowInfoWindow() and Pin.HideInfoWindow() methods #33985
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b6b880f
Add Pin.ShowInfoWindow() and Pin.HideInfoWindow() methods
jfversluis 9137d50
Address review feedback for Show Info Window
jfversluis edb5499
Fix missing using and duplicate gallery entry
jfversluis 515a4c0
Fix missing using System and Location type ambiguity in gallery
jfversluis 936b853
Change ShowInfoWindow/HideInfoWindow to no-ops on unsupported platforms
jfversluis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/InfoWindowGallery.xaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| xmlns:maps="clr-namespace:Microsoft.Maui.Controls.Maps;assembly=Microsoft.Maui.Controls.Maps" | ||
| x:Class="Maui.Controls.Sample.Pages.MapsGalleries.InfoWindowGallery" | ||
| Title="Info Window"> | ||
| <Grid RowDefinitions="Auto,*"> | ||
| <HorizontalStackLayout Spacing="10" Padding="10"> | ||
| <Button Text="Show Seattle" AutomationId="ShowSeattle" Clicked="OnShowSeattle" /> | ||
| <Button Text="Show NYC" AutomationId="ShowNYC" Clicked="OnShowNYC" /> | ||
| <Button Text="Hide All" AutomationId="HideAll" Clicked="OnHideAll" /> | ||
| </HorizontalStackLayout> | ||
| <maps:Map x:Name="map" Grid.Row="1" /> | ||
| </Grid> | ||
| </ContentPage> |
60 changes: 60 additions & 0 deletions
60
src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/InfoWindowGallery.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| using System; | ||
| using Microsoft.Maui.Controls; | ||
| using Microsoft.Maui.Controls.Maps; | ||
| using Microsoft.Maui.Devices.Sensors; | ||
| using Microsoft.Maui.Maps; | ||
|
|
||
| namespace Maui.Controls.Sample.Pages.MapsGalleries; | ||
|
|
||
| public partial class InfoWindowGallery : ContentPage | ||
| { | ||
| Pin _seattlePin; | ||
| Pin _nycPin; | ||
|
|
||
| public InfoWindowGallery() | ||
| { | ||
| InitializeComponent(); | ||
|
|
||
| _seattlePin = new Pin | ||
| { | ||
| Label = "Seattle", | ||
| Address = "Washington, USA", | ||
| Location = new Microsoft.Maui.Devices.Sensors.Location(47.6062, -122.3321) | ||
| }; | ||
|
|
||
| _nycPin = new Pin | ||
| { | ||
| Label = "New York City", | ||
| Address = "New York, USA", | ||
| Location = new Microsoft.Maui.Devices.Sensors.Location(40.7128, -74.0060) | ||
| }; | ||
|
|
||
| map.Pins.Add(_seattlePin); | ||
| map.Pins.Add(_nycPin); | ||
| map.Pins.Add(new Pin | ||
| { | ||
| Label = "Los Angeles", | ||
| Address = "California, USA", | ||
| Location = new Microsoft.Maui.Devices.Sensors.Location(34.0522, -118.2437) | ||
| }); | ||
|
|
||
| map.MoveToRegion(MapSpan.FromCenterAndRadius( | ||
| new Microsoft.Maui.Devices.Sensors.Location(39.8, -98.5), Distance.FromMiles(1500))); | ||
| } | ||
|
|
||
| void OnShowSeattle(object? sender, EventArgs e) | ||
| { | ||
| _seattlePin.ShowInfoWindow(); | ||
| } | ||
|
|
||
| void OnShowNYC(object? sender, EventArgs e) | ||
| { | ||
| _nycPin.ShowInfoWindow(); | ||
| } | ||
|
|
||
| void OnHideAll(object? sender, EventArgs e) | ||
| { | ||
| _seattlePin.HideInfoWindow(); | ||
| _nycPin.HideInfoWindow(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
PinsOnCollectionChangedsetspin.ParentforNewItemsand clears it forOldItems, butObservableCollection.Clear()raises aResetaction with noOldItems. That meansmap.Pins.Clear()(and other reset scenarios) will leave the removed pins'Parentpointing at the Map, which can cause incorrect behavior and keep the Map alive (leak) if pins are retained elsewhere. Consider handlingNotifyCollectionChangedAction.Reset(e.g., by using a custom collection that raises aRemoveevent with the removed items, similar toGestureElement.GestureRecognizerCollection).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.
I think it looks like a good point. I've seen some devs reporting issues with memory leaks when it comes to map, so it would be good to make sure we avoid them
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.
This is a valid concern but it's a pre-existing issue in Map.cs, not introduced by this PR. The Reset action not clearing Parent was already the behavior before this change. A separate issue/PR should address this collection management improvement.