View in MAUI WPF WinUI View on GitHub

Find webmap portal items by using a search term.

Image of search for webmap

Use case

Portals can contain many portal items and at times you may wish to query the portal to find what you’re looking for. In this example, we search for webmap portal items using a text search.

How to use the sample

Enter search terms into the search bar. Once the search is complete, a list is populated with the resultant webmaps. Tap on a webmap to set it to the map view. Scrolling to the bottom of the webmap recycler view will get more results.

How it works

  1. Create a new Portal and load it.
  2. Create new PortalItemQueryParameters. Set the type to PortalItem.Type.WebMap and add the text you want to search for.
  3. Use portal.FindItemsAsync(params) to find matching items.

Relevant API

  • Portal
  • PortalItem
  • PortalQueryParameters
  • PortalQueryResultSet

Tags

keyword, query, search, webmap

Sample Code

SearchPortalMaps.xaml SearchPortalMaps.xaml SearchPortalMaps.xaml.cs
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGIS.Samples.SearchPortalMaps.SearchPortalMaps"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:esriPortal="clr-namespace:Esri.ArcGISRuntime.Portal;assembly=Esri.ArcGISRuntime"
xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Maui;assembly=Esri.ArcGISRuntime.Maui">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid Grid.Row="0" ColumnDefinitions="*,*">
<Button Margin="5"
Clicked="ShowSearchUI"
Text="Search Maps" />
<Button Grid.Column="1"
Margin="5"
Clicked="GetMyMaps"
Text="My Maps" />
</Grid>
<esriUI:MapView x:Name="MyMapView" Grid.Row="1" />
<Border x:Name="SearchMapsUI"
Grid.Row="1"
BackgroundColor="{AppThemeBinding Light=#dfdfdf,
Dark=#303030}"
HorizontalOptions="Center"
IsVisible="False"
StrokeShape="RoundRectangle 10"
VerticalOptions="Center">
<Grid Padding="10"
ColumnDefinitions="auto,auto"
RowDefinitions="auto,auto">
<Label Grid.Row="0"
Grid.Column="0"
Margin="5"
Text="Search text:"
VerticalTextAlignment="Center" />
<Entry x:Name="SearchTextEntry"
Grid.Row="0"
Grid.Column="1"
Margin="5"
HorizontalOptions="Start"
Placeholder=""
VerticalOptions="Center"
WidthRequest="240" />
<Button Grid.Row="1"
Grid.Column="0"
Margin="20,0"
Clicked="CancelSearchClicked"
Text="Cancel" />
<Button Grid.Row="1"
Grid.Column="1"
Clicked="SearchMapsClicked"
Text="Search" />
</Grid>
</Border>
<Border x:Name="MapsListBorder"
Grid.Row="1"
BackgroundColor="{AppThemeBinding Light=#dfdfdf,
Dark=#303030}"
HorizontalOptions="Center"
IsVisible="False"
StrokeShape="RoundRectangle 10"
VerticalOptions="Center"
WidthRequest="{OnIdiom Default=-1,
Desktop=500}">
<StackLayout Padding="10" HeightRequest="{OnIdiom Default=-1, Desktop=500}">
<ListView x:Name="MapsListView"
Margin="5"
ItemSelected="MapItemSelected"
SelectionMode="Single"
VerticalScrollBarVisibility="Default">
<ListView.ItemTemplate>
<DataTemplate x:DataType="esriPortal:PortalItem">
<TextCell Text="{Binding Title}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Button Margin="5"
Clicked="ListCloseClicked"
Text="Close" />
</StackLayout>
</Border>
</Grid>
</ContentPage>