Skip to content

Commit

Permalink
Popupviewer - maui (#517)
Browse files Browse the repository at this point in the history
Adds the new popup viewer experience to .NET MAUI
  • Loading branch information
dotMorten authored Jul 2, 2023
1 parent d03aa50 commit 855f22c
Show file tree
Hide file tree
Showing 33 changed files with 1,767 additions and 256 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<Copyright>Copyright © 2014-$([System.DateTime]::Now.ToString('yyyy')) Esri.</Copyright>

<DefaultLanguage>en-US</DefaultLanguage>
<LangVersion>10</LangVersion>
<LangVersion>11</LangVersion>

<!--Project type identifiers-->
<IsSampleProject>$(MSBuildProjectName.Contains('.Samples.'))</IsSampleProject>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
<Grid>
<esriUI:MapView x:Name="mapView" />

<esriTK:PopupViewer
x:Name="popupViewer"
Margin="{OnPlatform Default='0,0,0,0',
iOS='0,0,0,16'}"
BackgroundColor="White"
Foreground="Black"
HorizontalOptions="FillAndExpand"
IsVisible="False"
VerticalOptions="EndAndExpand" />

<Border Background="#99ffffff" x:Name="popupPanel" IsVisible="False">
<Border HorizontalOptions="Center" VerticalOptions="Center" Background="{AppThemeBinding Dark=Black, Light=White}" Margin="0,50" Padding="20">
<Grid>
<esriTK:PopupViewer x:Name="popupViewer" Margin="20" MaximumWidthRequest="400" HeightRequest="400" PopupAttachmentClicked="popupViewer_PopupAttachmentClicked" />
<Button BorderWidth="0" Text="X" HorizontalOptions="End" VerticalOptions="Start" Clicked="CloseButton_Click" BackgroundColor="Transparent" TextColor="{AppThemeBinding Dark=White, Light=Black}" Margin="5" />
</Grid>
</Border>
</Border>
</Grid>
</ContentPage.Content>
</ContentPage>
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,36 @@
using Esri.ArcGISRuntime.Maui;
using Esri.ArcGISRuntime.Security;
using Esri.ArcGISRuntime.UI;
using Microsoft.Maui.Controls.Shapes;

namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[XamlCompilation(XamlCompilationOptions.Compile)]
[SampleInfoAttribute(Category = "PopupViewer", Description = "Use PopupViewer to display detailed feature information")]
public partial class PopupViewerSample : ContentPage
{
public PopupViewerSample()
{
InitializeComponent();
mapView.Map = new Esri.ArcGISRuntime.Mapping.Map(new Uri("https://www.arcgis.com/home/item.html?id=d4fe39d300c24672b1821fa8450b6ae2"));

// Used to demonstrate display of EditSummary in PopupViewer
// Provides credentials to token-secured layer that has editor-tracking enabled
AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(async (info) =>
{
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, "user1", "user1");
});

{
public PopupViewerSample()
{
InitializeComponent();
mapView.Map = new Esri.ArcGISRuntime.Mapping.Map(new Uri("https://www.arcgis.com/home/item.html?id=9f3a674e998f461580006e626611f9ad"));
mapView.GeoViewTapped += mapView_GeoViewTapped;
} // Used in Callout to see feature details in PopupViewer
private RuntimeImage InfoIcon => new RuntimeImage(new Uri("https://cdn3.iconfinder.com/data/icons/web-and-internet-icons/512/Information-256.png"));
}


private async void mapView_GeoViewTapped(object? sender, GeoViewInputEventArgs e)
{
Exception error = null;
Exception? error = null;
try
{
var result = await mapView.IdentifyLayersAsync(e.Position, 3, false);

// Retrieves or builds Popup from IdentifyLayerResult
var popup = GetPopup(result);

// Displays callout and updates visibility of PopupViewer
if (popup != null)
{
var callout = new CalloutDefinition(popup.GeoElement);
callout.Tag = popup;
callout.ButtonImage = InfoIcon;
callout.OnButtonClick = new Action<object>((s) =>
{
popupViewer.IsVisible = true;
popupViewer.PopupManager = new PopupManager(s as Popup);
});
mapView.ShowCalloutForGeoElement(popup.GeoElement, e.Position, callout);
}
else
{
popupViewer.PopupManager = null;
popupViewer.IsVisible = false;
popupViewer.Popup = popup;
popupPanel.IsVisible = true;
}
}
catch (Exception ex)
Expand Down Expand Up @@ -121,5 +101,21 @@ private Popup GetPopup(IEnumerable<IdentifyLayerResult> results)

return null;
}

private void CloseButton_Click(object sender, EventArgs e)
{
popupPanel.IsVisible = false;
}

private void popupViewer_PopupAttachmentClicked(object sender, Esri.ArcGISRuntime.Toolkit.Maui.PopupAttachmentClickedEventArgs e)
{
e.Handled = true; // Prevent default launch action
// Share file:
// _ = Share.Default.RequestAsync(new ShareFileRequest(new ReadOnlyFile(e.Attachment.Filename!, e.Attachment.ContentType)));

// Open default file handler
_ = Microsoft.Maui.ApplicationModel.Launcher.Default.OpenAsync(
new Microsoft.Maui.ApplicationModel.OpenFileRequest(e.Attachment.Name, new ReadOnlyFile(e.Attachment.Filename!, e.Attachment.ContentType)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,9 @@

<!-- TODO: -->
<Compile Remove="Samples\LayerLegendSample.xaml.cs" />
<Compile Remove="Samples\PopupViewerSample.xaml.cs" />
<Compile Remove="Samples\TimeSliderSample.xaml.cs" />
<MauiXaml Remove="Samples\LayerLegendSample.xaml" />
<MauiXaml Remove="Samples\PopupViewerSample.xaml" />
<MauiXaml Remove="Samples\TimeSliderSample.xaml" />

</ItemGroup>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.$(ArcGISRuntime_MinimumSupportedWindowsBuild).0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.$(ArcGISRuntime_MinimumSupportedWindowsBuild).0</TargetPlatformMinVersion>
<DefineConstants>$(DefineConstants);MAUI</DefineConstants>
<LangVersion>10</LangVersion>
<Nullable>annotations</Nullable>
</PropertyGroup>

Expand Down
38 changes: 38 additions & 0 deletions src/Toolkit/Toolkit.Maui/Internal/EmptyToFalseConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// /*******************************************************************************
// * Copyright 2012-2018 Esri
// *
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// ******************************************************************************/

using System.Globalization;

namespace Esri.ArcGISRuntime.Toolkit.Maui.Internal
{
internal class EmptyToFalseConverter : IValueConverter
{
public static EmptyToFalseConverter Instance { get; } = new EmptyToFalseConverter();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is null) return false;
if (value is string str) return !string.IsNullOrWhiteSpace(str);
if (value is System.Collections.ICollection coll) return coll.Count > 0;
if (value is Array arr) return arr.Length > 0;
return true;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
<Compile Include="$(MSBuildThisFileDirectory)Legend\LegendItemTemplateSelector.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MeasureToolbar\MeasureToolbar.cs" />
<Compile Include="$(MSBuildThisFileDirectory)OverviewMap\OverviewMap.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PopupViewer\PopupViewer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PopupViewer\PopupViewer.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PopupViewer\PopupViewer.Xamarin.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ScaleLine\ScaleLine.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ScaleLine\ScaleLine.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SearchView\SearchView.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<StackPanel>
<TextBlock Text="{Binding Title, Mode=OneWay}" Style="{StaticResource PopupViewerTitleStyle}" Visibility="{Binding Title, Converter={StaticResource PopupViewerVisibilityConverter}}" />
<TextBlock Text="{Binding Description, Mode=OneWay}" Style="{StaticResource PopupViewerCaptionStyle}" Visibility="{Binding Description, Converter={StaticResource PopupViewerVisibilityConverter}}" />
<ListView x:Name="AttachmentList" BorderThickness="0">
<ListView x:Name="AttachmentList" BorderThickness="0" SelectionMode="Single">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" Margin="5" Cursor="Hand"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// * limitations under the License.
// ******************************************************************************/

#if !WPF
#if WINDOWS_XAML

using Esri.ArcGISRuntime.Mapping.Popups;

Expand Down
6 changes: 5 additions & 1 deletion src/Toolkit/Toolkit/Internal/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ namespace Esri.ArcGISRuntime.Toolkit.Internal
internal static class Launcher
{
public static
Task<bool> LaunchUriAsync(Uri uri)
Task<bool> LaunchUriAsync(Uri? uri)
{
if (uri is null)
{
return Task.FromResult(false);
}
#if NET6_0_OR_GREATER && WINDOWS || NETFX_CORE
return Windows.System.Launcher.LaunchUriAsync(uri).AsTask();
#elif WINDOWS
Expand Down
Loading

0 comments on commit 855f22c

Please sign in to comment.