Select features in a feature layer.
Use case
Selecting features, whether by query or identify, can be an important step both in editing data and visualizing results. One possible use case would be to query a feature layer containing street furniture. A query might look for type "bench" and return a list of bench features contained in the features with an attribute of type bench. These might be selected for further editing (see FeatureQueryResult) or may just be highlighted visually.
How to use the sample
Tap on a feature in the map. All features within a given tolerance (in pixels) of the tap will be selected.
How it works
- Create a
ServiceFeatureTable
from a feature service URL. - Create a
FeatureLayer
from the service feature table. - Identify nearby features at the tapped location using
IdentifyLayerAsync(featureLayer, clickLocation, tolerance, returnPopupsOnly, maxResults)
on the map view. - Select all identified features in the feature layer with
SelectFeatures(features)
.
Relevant API
- Feature
- FeatureLayer
- ServiceFeatureTable
About the data
This sample uses the Gross Domestic Product, 1960-2016 feature service. Only the 2016 GDP values are shown.
Tags
features, layers, select, selection, tolerance
Sample Code
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGISRuntime.Samples.FeatureLayerSelection.FeatureLayerSelection"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label HorizontalTextAlignment="Center" Text="Tap to select features." />
<esriUI:MapView x:Name="MyMapView" Grid.Row="1" />
</Grid>
</ContentPage>