Skip to content

Commit

Permalink
BookmarksViewSample fixes (#543)
Browse files Browse the repository at this point in the history
* WinUI app crash fix

* data fix

* web scene spec comments

* Revert "WinUI app crash fix"

This reverts commit 0b420e3.

* webscene spec comments

* content dialog

* toggle listeners
  • Loading branch information
williambohrmann3 authored Feb 7, 2024
1 parent 2a46374 commit aaad3ef
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
<Button Text="Map/Scene" Grid.Row="3" Grid.Column="2" Clicked="AddToMapScene_Click" />
<Button Text="Red fore" Grid.Row="4" Grid.Column="1" Clicked="SetItemTemplateOne_Click" />
<Button Text="Red back" Grid.Row="4" Grid.Column="2" Clicked="SetItemTemplateTwo_Click" />
<Button Text="Add" Grid.Row="5" Grid.Column="1" Clicked="AddSelectionListener_Click" />
<Button Text="Remove" Grid.Row="5" Grid.Column="2" Clicked="RemoveSelectionListener_Click" />
<Switch x:Name="BookmarkListenerSwitch" Grid.Row="5" Grid.Column="1" HorizontalOptions="Start"
Toggled="BookmarkListenerSwitch_Toggled"/>
</Grid>
</Grid>
</ScrollView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial class BookmarksViewSample : ContentPage
private const string webMapOneUrl = "https://arcgisruntime.maps.arcgis.com/home/item.html?id=e50fafe008ac4ce4ad2236de7fd149c3";
private const string webMapTwoUrl = "https://arcgisruntime.maps.arcgis.com/home/item.html?id=16f1b8ba37b44dc3884afc8d5f454dd2";
private const string webSceneOne = "https://arcgisruntime.maps.arcgis.com/home/item.html?id=6b6588041965408e84ba319e12d9d7ad";
private const string webSceneTwo = "https://www.arcgis.com/home/webscene/viewer.html?webscene=b9ad8372ff884bc4a4e78d936b170f7d";
private const string webSceneTwo = "https://arcgisruntime.maps.arcgis.com/home/item.html?id=b3e2230e170d4f91aa3d47f88821743d";
private MapView MyMapView;
private SceneView MySceneView;
private Random _randomizer = new Random();
Expand Down Expand Up @@ -48,6 +48,8 @@ private void SetMapViewBinding_Click(object? sender, EventArgs e)
BookmarksView.SetBinding(Esri.ArcGISRuntime.Toolkit.Maui.BookmarksView.GeoViewProperty, geoviewBinding);
}

// Note that the Web Scene Specification does not use bookmarks.
// As such, the BookmarksView will initially be empty, so click the "Set list" button to generate bookmarks.
private void SetSceneViewBinding_Click(object? sender, EventArgs e)
{
if (_viewContainer.Children.Contains(MySceneView) == false)
Expand Down Expand Up @@ -128,14 +130,16 @@ private void SetItemTemplateTwo_Click(object? sender, EventArgs e)
BookmarksView.ItemTemplate = template;
}

private void AddSelectionListener_Click(object? sender, EventArgs e)
private void BookmarkListenerSwitch_Toggled(object sender, ToggledEventArgs e)
{
BookmarksView.BookmarkSelected += BookmarkSelected;
}

private void RemoveSelectionListener_Click(object? sender, EventArgs e)
{
BookmarksView.BookmarkSelected -= BookmarkSelected;
if (BookmarkListenerSwitch.IsToggled)
{
BookmarksView.BookmarkSelected += BookmarkSelected;
}
else
{
BookmarksView.BookmarkSelected -= BookmarkSelected;
}
}

private void BookmarkSelected(object? sender, Bookmark bookmark)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
</Setter.Value>
</Setter>
</Style>
<Grid x:Name="Dialog" />
</Page.Resources>
<Grid>
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -143,8 +144,8 @@
<Button Content="Map/Scene" Grid.Row="3" Grid.Column="2" Click="AddToMapScene_Click" />
<Button Content="Red fore" Grid.Row="4" Grid.Column="1" Click="SetItemTemplateOne_Click" />
<Button Content="Red back" Grid.Row="4" Grid.Column="2" Click="SetItemTemplateTwo_Click" />
<Button Content="Add" Grid.Row="5" Grid.Column="1" Click="AddSelectionListener_Click" />
<Button Content="Remove" Grid.Row="5" Grid.Column="2" Click="RemoveSelectionListener_Click" />
<ToggleButton x:Name="BookmarkListenerToggle" Content="Add listener" Grid.Row="5" Grid.Column="1"
Grid.ColumnSpan="2" Click="SelectionListenerToggle_Click" HorizontalAlignment="Stretch" Margin="5" />
<Button Content="Default" Grid.Row="6" Grid.Column="1" Click="SelectDefaultItemContainer_Click" />
<Button Content="Custom" Grid.Row="6" Grid.Column="2" Click="SelectCustomItemContainer_Click" />
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed partial class BookmarksViewSample : Page
private const string webMapOneUrl = "https://arcgisruntime.maps.arcgis.com/home/item.html?id=e50fafe008ac4ce4ad2236de7fd149c3";
private const string webMapTwoUrl = "https://arcgisruntime.maps.arcgis.com/home/item.html?id=16f1b8ba37b44dc3884afc8d5f454dd2";
private const string webSceneOne = "https://arcgisruntime.maps.arcgis.com/home/item.html?id=6b6588041965408e84ba319e12d9d7ad";
private const string webSceneTwo = "https://www.arcgis.com/home/webscene/viewer.html?webscene=b9ad8372ff884bc4a4e78d936b170f7d";
private const string webSceneTwo = "https://arcgisruntime.maps.arcgis.com/home/item.html?id=b3e2230e170d4f91aa3d47f88821743d";

private Random _randomizer = new Random();

Expand Down Expand Up @@ -46,6 +46,8 @@ private void SetMapViewBinding_Click(object sender, RoutedEventArgs e)
BookmarksView.SetBinding(UI.Controls.BookmarksView.GeoViewProperty, geoviewBinding);
}

// Note that the Web Scene Specification does not use bookmarks.
// As such, the BookmarksView will initially be empty, so click the "Set list" button to generate bookmarks.
private void SetSceneViewBinding_Click(object sender, RoutedEventArgs e)
{
MyMapView.Visibility = Visibility.Collapsed;
Expand Down Expand Up @@ -124,19 +126,30 @@ private void SetItemTemplateTwo_Click(object sender, RoutedEventArgs e)
BookmarksView.ItemTemplate = template;
}

private void AddSelectionListener_Click(object sender, RoutedEventArgs e)
private void SelectionListenerToggle_Click(object sender, RoutedEventArgs e)
{
BookmarksView.BookmarkSelected += BookmarkSelected;
}

private void RemoveSelectionListener_Click(object sender, RoutedEventArgs e)
{
BookmarksView.BookmarkSelected -= BookmarkSelected;
if (BookmarkListenerToggle.IsChecked == true)
{
BookmarksView.BookmarkSelected += BookmarkSelected;
BookmarkListenerToggle.Content = "Remove";
}
else
{
BookmarksView.BookmarkSelected -= BookmarkSelected;
BookmarkListenerToggle.Content = "Add";
}
}

private async void BookmarkSelected(object sender, Bookmark bookmark)
{
await new MessageDialog($"{bookmark.Name} Selected!").ShowAsync();
await new ContentDialog
{
XamlRoot = Dialog.XamlRoot,
Title = "Bookmark Selected",
Content = bookmark.Name,
CloseButtonText = "Ok"
}
.ShowAsync();
}

private void SelectDefaultItemContainer_Click(object sender, RoutedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@
<Button Content="Map/Scene" Grid.Row="3" Grid.Column="2" Click="AddToMapScene_Click" />
<Button Content="Red fore" Grid.Row="4" Grid.Column="1" Click="SetItemTemplateOne_Click" />
<Button Content="Red back" Grid.Row="4" Grid.Column="2" Click="SetItemTemplateTwo_Click" />
<Button Content="Add" Grid.Row="5" Grid.Column="1" Click="AddSelectionListener_Click" />
<Button Content="Remove" Grid.Row="5" Grid.Column="2" Click="RemoveSelectionListener_Click" />
<ToggleButton x:Name="SelectionListenerToggle" Content="Add listener" Grid.Row="5" Grid.Column="1"
Grid.ColumnSpan="2" Click="SelectionListenerToggle_Click" />
<Button Content="Default" Grid.Row="6" Grid.Column="1" Click="SelectDefaultItemContainer_Click" />
<Button Content="Custom" Grid.Row="6" Grid.Column="2" Click="SelectCustomItemContainer_Click" />
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public partial class BookmarksViewSample : UserControl
private const string webMapOneUrl = "https://arcgisruntime.maps.arcgis.com/home/item.html?id=e50fafe008ac4ce4ad2236de7fd149c3";
private const string webMapTwoUrl = "https://arcgisruntime.maps.arcgis.com/home/item.html?id=16f1b8ba37b44dc3884afc8d5f454dd2";
private const string webSceneOne = "https://arcgisruntime.maps.arcgis.com/home/item.html?id=6b6588041965408e84ba319e12d9d7ad";
private const string webSceneTwo = "https://www.arcgis.com/home/webscene/viewer.html?webscene=b9ad8372ff884bc4a4e78d936b170f7d";
private const string webSceneTwo = "https://arcgisruntime.maps.arcgis.com/home/item.html?id=b3e2230e170d4f91aa3d47f88821743d";

private Random _randomizer = new Random();

Expand Down Expand Up @@ -57,6 +57,8 @@ private void SetMapViewBinding_Click(object sender, RoutedEventArgs e)
BookmarksView.SetBinding(UI.Controls.BookmarksView.GeoViewProperty, geoviewBinding);
}

// Note that the Web Scene specification does not use bookmarks.
// As such, the BookmarksView will initially be empty, so click the "Set list" button to generate bookmarks.
private void SetSceneViewBinding_Click(object sender, RoutedEventArgs e)
{
MyMapView.Visibility = Visibility.Collapsed;
Expand Down Expand Up @@ -135,14 +137,18 @@ private void SetItemTemplateTwo_Click(object sender, RoutedEventArgs e)
BookmarksView.ItemTemplate = template;
}

private void AddSelectionListener_Click(object sender, RoutedEventArgs e)
private void SelectionListenerToggle_Click(object sender, RoutedEventArgs e)
{
BookmarksView.BookmarkSelected += BookmarkSelected;
}

private void RemoveSelectionListener_Click(object sender, RoutedEventArgs e)
{
BookmarksView.BookmarkSelected -= BookmarkSelected;
if (SelectionListenerToggle.IsChecked == true)
{
BookmarksView.BookmarkSelected += BookmarkSelected;
SelectionListenerToggle.Content = "Remove";
}
else
{
BookmarksView.BookmarkSelected -= BookmarkSelected;
SelectionListenerToggle.Content = "Add";
}
}

private void BookmarkSelected(object sender, Bookmark bookmark)
Expand Down

0 comments on commit aaad3ef

Please sign in to comment.