-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a GeoView controller to help with common MVVM challenges (#528)
* Adds a GeoView controller to help with common MVVM challenges
- Loading branch information
Showing
16 changed files
with
542 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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
25 changes: 25 additions & 0 deletions
25
src/Samples/Toolkit.SampleApp.Maui/Samples/GeoViewControllerSample.xaml
This file contains 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,25 @@ | ||
<?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" | ||
x:Class="Toolkit.SampleApp.Maui.Samples.GeoViewControllerSample" | ||
xmlns:local="clr-namespace:Toolkit.SampleApp.Maui.Samples" | ||
xmlns:esri="clr-namespace:Esri.ArcGISRuntime.Maui;assembly=Esri.ArcGISRuntime.Maui" | ||
xmlns:toolkit="clr-namespace:Esri.ArcGISRuntime.Toolkit.Maui;assembly=Esri.ArcGISRuntime.Toolkit.Maui" | ||
xmlns:toolkitbase="clr-namespace:Esri.ArcGISRuntime.Toolkit;assembly=Esri.ArcGISRuntime.Toolkit.Maui" | ||
xmlns:mauitoolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" | ||
Title="GeoViewController"> | ||
<ContentPage.Resources> | ||
<local:GeoViewControllerSampleVM x:Key="VM" /> | ||
</ContentPage.Resources> | ||
<Grid> | ||
<esri:MapView x:Name="MyMapView" | ||
Map="{Binding Map, Source={StaticResource VM}}" | ||
toolkit:GeoViewController.GeoViewController="{Binding Controller, Source={StaticResource VM}}"> | ||
<esri:MapView.Behaviors> | ||
<mauitoolkit:EventToCommandBehavior EventName="GeoViewTapped" | ||
x:TypeArguments="esri:GeoViewInputEventArgs" | ||
Command="{Binding GeoViewTappedCommand, Source={StaticResource VM}}" /> | ||
</esri:MapView.Behaviors> | ||
</esri:MapView> | ||
</Grid> | ||
</ContentPage> |
40 changes: 40 additions & 0 deletions
40
src/Samples/Toolkit.SampleApp.Maui/Samples/GeoViewControllerSample.xaml.cs
This file contains 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,40 @@ | ||
using CommunityToolkit.Mvvm.Input; | ||
using Esri.ArcGISRuntime.Data; | ||
using Esri.ArcGISRuntime.Geometry; | ||
using Esri.ArcGISRuntime.Mapping; | ||
using Esri.ArcGISRuntime.Maui; | ||
using Esri.ArcGISRuntime.Toolkit.Maui; | ||
|
||
namespace Toolkit.SampleApp.Maui.Samples; | ||
|
||
public partial class GeoViewControllerSample : ContentPage | ||
{ | ||
public GeoViewControllerSample() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
|
||
public partial class GeoViewControllerSampleVM | ||
{ | ||
public Map Map { get; } = new Map(new Uri("https://www.arcgis.com/home/item.html?id=9f3a674e998f461580006e626611f9ad")); | ||
|
||
public GeoViewController Controller { get; } = new GeoViewController(); | ||
|
||
[RelayCommand] | ||
public async Task OnGeoViewTapped(GeoViewInputEventArgs eventArgs) => await Identify(eventArgs.Position, eventArgs.Location); | ||
|
||
public async Task Identify(Point location, MapPoint? mapLocation) | ||
{ | ||
Controller.DismissCallout(); | ||
var result = await Controller.IdentifyLayersAsync(location, 10); | ||
if (result.FirstOrDefault()?.GeoElements?.FirstOrDefault() is GeoElement element) | ||
{ | ||
Controller.ShowCalloutForGeoElement(element, location, new Esri.ArcGISRuntime.UI.CalloutDefinition(element)); | ||
} | ||
else if (mapLocation is not null) | ||
{ | ||
Controller.ShowCalloutAt(mapLocation, new Esri.ArcGISRuntime.UI.CalloutDefinition("No features found")); | ||
} | ||
} | ||
} |
This file contains 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 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
19 changes: 19 additions & 0 deletions
19
src/Samples/Toolkit.SampleApp.UWP/Samples/GeoViewController/GeoViewControllerSample.xaml
This file contains 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,19 @@ | ||
<Page | ||
x:Class="Esri.ArcGISRuntime.Toolkit.SampleApp.Samples.GeoViewController.GeoViewControllerSample" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:Esri.ArcGISRuntime.Toolkit.SampleApp.Samples.GeoViewController" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:esri="using:Esri.ArcGISRuntime.UI.Controls" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:toolkit="using:Esri.ArcGISRuntime.Toolkit.UI.Controls" | ||
xmlns:toolkitui="using:Esri.ArcGISRuntime.Toolkit.UI" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<Grid> | ||
<esri:MapView x:Name="MyMapView" Map="{x:Bind VM.Map}" | ||
toolkitui:GeoViewController.GeoViewController="{x:Bind VM.Controller}" | ||
GeoViewTapped="{x:Bind VM.OnGeoViewTapped}" /> | ||
</Grid> | ||
</Page> |
11 changes: 11 additions & 0 deletions
11
src/Samples/Toolkit.SampleApp.UWP/Samples/GeoViewController/GeoViewControllerSample.xaml.cs
This file contains 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,11 @@ | ||
namespace Esri.ArcGISRuntime.Toolkit.SampleApp.Samples.GeoViewController | ||
{ | ||
public sealed partial class GeoViewControllerSample : Page | ||
{ | ||
public GeoViewControllerSample() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
public GeoViewControllerSampleVM VM { get; } = new GeoViewControllerSampleVM(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Samples/Toolkit.SampleApp.UWP/Samples/GeoViewController/GeoViewControllerSampleVM.cs
This file contains 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,32 @@ | ||
using System; | ||
using System.Linq; | ||
using Esri.ArcGISRuntime.Data; | ||
using Esri.ArcGISRuntime.Geometry; | ||
using Esri.ArcGISRuntime.Mapping; | ||
using Esri.ArcGISRuntime.UI.Controls; | ||
using Windows.Foundation; | ||
|
||
namespace Esri.ArcGISRuntime.Toolkit.SampleApp.Samples.GeoViewController; | ||
|
||
public class GeoViewControllerSampleVM | ||
{ | ||
public Map Map { get; } = new Map(new Uri("https://www.arcgis.com/home/item.html?id=9f3a674e998f461580006e626611f9ad")); | ||
|
||
public UI.GeoViewController Controller { get; } = new UI.GeoViewController(); | ||
|
||
public void OnGeoViewTapped(object sender, GeoViewInputEventArgs eventArgs) => Identify(eventArgs.Position, eventArgs.Location); | ||
|
||
public async void Identify(Point location, MapPoint mapLocation) | ||
{ | ||
Controller.DismissCallout(); | ||
var result = await Controller.IdentifyLayersAsync(location, 10); | ||
if (result.FirstOrDefault()?.GeoElements?.FirstOrDefault() is GeoElement element) | ||
{ | ||
Controller.ShowCalloutForGeoElement(element, location, new Esri.ArcGISRuntime.UI.CalloutDefinition(element)); | ||
} | ||
else if (mapLocation is not null) | ||
{ | ||
Controller.ShowCalloutAt(mapLocation, new Esri.ArcGISRuntime.UI.CalloutDefinition("No features found")); | ||
} | ||
} | ||
} |
This file contains 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 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
25 changes: 25 additions & 0 deletions
25
src/Samples/Toolkit.SampleApp.WPF/Samples/GeoViewController/GeoViewControllerSample.xaml
This file contains 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,25 @@ | ||
<UserControl x:Class="Esri.ArcGISRuntime.Toolkit.Samples.GeoViewController.GeoViewControllerSample" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:Esri.ArcGISRuntime.Toolkit.Samples.GeoViewController" | ||
xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013" | ||
xmlns:Behaviors="http://schemas.microsoft.com/xaml/behaviors" | ||
mc:Ignorable="d" | ||
d:DesignHeight="450" d:DesignWidth="800"> | ||
<UserControl.Resources> | ||
<local:GeoViewControllerSampleVM x:Key="VM" /> | ||
</UserControl.Resources> | ||
<Grid> | ||
<esri:MapView x:Name="MyMapView" | ||
Map="{Binding Map, Source={StaticResource VM}}" | ||
esri:GeoViewController.GeoViewController="{Binding Controller, Source={StaticResource VM}}"> | ||
<Behaviors:Interaction.Triggers> | ||
<Behaviors:EventTrigger EventName="GeoViewTapped" > | ||
<Behaviors:InvokeCommandAction Command="{Binding GeoViewTappedCommand, Source={StaticResource VM}}" PassEventArgsToCommand="True" /> | ||
</Behaviors:EventTrigger> | ||
</Behaviors:Interaction.Triggers> | ||
</esri:MapView> | ||
</Grid> | ||
</UserControl> |
12 changes: 12 additions & 0 deletions
12
src/Samples/Toolkit.SampleApp.WPF/Samples/GeoViewController/GeoViewControllerSample.xaml.cs
This file contains 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,12 @@ | ||
using System.Windows.Controls; | ||
|
||
namespace Esri.ArcGISRuntime.Toolkit.Samples.GeoViewController | ||
{ | ||
public partial class GeoViewControllerSample : UserControl | ||
{ | ||
public GeoViewControllerSample() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/Samples/Toolkit.SampleApp.WPF/Samples/GeoViewController/GeoViewControllerSampleVM.cs
This file contains 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,64 @@ | ||
#nullable enable | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using CommunityToolkit.Mvvm.Input; | ||
using Esri.ArcGISRuntime.Data; | ||
using Esri.ArcGISRuntime.Geometry; | ||
using Esri.ArcGISRuntime.Mapping; | ||
using Esri.ArcGISRuntime.UI.Controls; | ||
|
||
namespace Esri.ArcGISRuntime.Toolkit.Samples.GeoViewController; | ||
public partial class GeoViewControllerSampleVM | ||
{ | ||
public Map Map { get; } = new Map(new Uri("https://www.arcgis.com/home/item.html?id=9f3a674e998f461580006e626611f9ad")); | ||
|
||
public IMyMapViewController Controller { get; } = new MyMapViewController(); | ||
|
||
[RelayCommand] | ||
public async Task OnGeoViewTapped(GeoViewInputEventArgs eventArgs) => await Identify(eventArgs.Position, eventArgs.Location); | ||
|
||
public async Task Identify(Point location, MapPoint? mapLocation) | ||
{ | ||
Controller.DismissCallout(); | ||
var result = await Controller.IdentifyLayersAsync(location, 10); | ||
if (result.FirstOrDefault()?.GeoElements?.FirstOrDefault() is GeoElement element) | ||
{ | ||
Controller.ShowCalloutForGeoElement(element, location, new Esri.ArcGISRuntime.UI.CalloutDefinition(element)); | ||
_ = Controller.PanToAsync(mapLocation); | ||
} | ||
else if (mapLocation is not null) | ||
{ | ||
Controller.ShowCalloutAt(mapLocation, new Esri.ArcGISRuntime.UI.CalloutDefinition("No features found")); | ||
} | ||
} | ||
} | ||
|
||
// Custom controller that extends the toolkit controller | ||
public class MyMapViewController : UI.GeoViewController, IMyMapViewController | ||
{ | ||
public MapView? ConnectedMapView => ConnectedView as MapView; | ||
|
||
public Task PanToAsync(MapPoint? center) | ||
{ | ||
if (center is null) | ||
return Task.FromResult(false); | ||
return ConnectedMapView?.SetViewpointCenterAsync(center) ?? Task.FromResult(false); | ||
} | ||
|
||
public MapPoint? ScreenToLocation(Point screenLocation) => ConnectedMapView?.ScreenToLocation(screenLocation); | ||
} | ||
|
||
// Custom interface for testability of VM | ||
public interface IMyMapViewController | ||
{ | ||
void DismissCallout(); | ||
void ShowCalloutForGeoElement(GeoElement element, Point tapPosition, ArcGISRuntime.UI.CalloutDefinition definition); | ||
void ShowCalloutAt(MapPoint location, ArcGISRuntime.UI.CalloutDefinition definition); | ||
Task<IReadOnlyList<IdentifyLayerResult>> IdentifyLayersAsync(Point screenPoint, double tolerance, bool returnPopupsOnly = false, CancellationToken cancellationToken = default); | ||
MapPoint? ScreenToLocation(Point screenLocation); | ||
Task PanToAsync(MapPoint? center); | ||
} |
This file contains 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.