Click or drag to resize

FeatureTableLayer Property

Gets the layer this table is associated with, or created from, if any.

Namespace:  Esri.ArcGISRuntime.Data
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.11.0
Syntax
public Layer Layer { get; }

Return Value

Type: Layer
The layer this table is associated with, or created from, if any.
Remarks
This can be an AnnotationLayer, a FeatureLayer, or null if this table is not associated with a layer.
Examples

UWP

Example Name: EditFeatureLinkedAnnotation

Edit feature attributes which are linked to annotation through an expression.

Code example screen shot.

C#
// Copyright 2021 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 ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.UI.Popups;

namespace ArcGISRuntime.UWP.Samples.EditFeatureLinkedAnnotation
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        name: "Edit features with feature-linked annotation",
        category: "Data",
        description: "Edit feature attributes which are linked to annotation through an expression.",
        instructions: "Pan and zoom the map to see that the text on the map is annotation, not labels. Click one of the address points to update the house number (AD_ADDRESS) and street name (ST_STR_NAM). Click one of the dashed parcel polylines and click another location to change its geometry. NOTE: Selection is only enabled for points and straight (single segment) polylines.",
        tags: new[] { "annotation", "attributes", "feature-linked annotation", "features", "fields" })]
    [ArcGISRuntime.Samples.Shared.Attributes.OfflineData("74c0c9fa80f4498c9739cc42531e9948")]
    public partial class EditFeatureLinkedAnnotation
    {
        private Feature _selectedFeature;

        public EditFeatureLinkedAnnotation()
        {
            InitializeComponent();
            _ = Initialize();
        }

        private async Task Initialize()
        {
            // NOTE: to be a writable geodatabase, this geodatabase must be generated from a service with a GeodatabaseSyncTask. See the "Generate geodatabase" sample.
            try
            {
                // Create and load geodatabase.
                string geodatabasePath = DataManager.GetDataFolder("74c0c9fa80f4498c9739cc42531e9948", "loudoun_anno.geodatabase");
                Geodatabase geodatabase = await Geodatabase.OpenAsync(geodatabasePath);

                // Create feature layers from tables in the geodatabase.
                FeatureLayer addressFeatureLayer = new FeatureLayer(geodatabase.GeodatabaseFeatureTable("Loudoun_Address_Points_1"));
                FeatureLayer parcelFeatureLayer = new FeatureLayer(geodatabase.GeodatabaseFeatureTable("ParcelLines_1"));

                // Create annotation layers from tables in the geodatabase.
                AnnotationLayer addressAnnotationLayer = new AnnotationLayer(geodatabase.GeodatabaseAnnotationTable("Loudoun_Address_PointsAnno_1"));
                AnnotationLayer parcelAnnotationLayer = new AnnotationLayer(geodatabase.GeodatabaseAnnotationTable("ParcelLinesAnno_1"));

                // Create a map with the layers.
                MyMapView.Map = new Map(BasemapStyle.ArcGISLightGray);
                MyMapView.Map.OperationalLayers.AddRange(new List<Layer> { addressFeatureLayer, parcelFeatureLayer, addressAnnotationLayer, parcelAnnotationLayer });

                // Zoom to the extent of the parcels.
                await parcelFeatureLayer.LoadAsync();
                MyMapView.SetViewpoint(new Viewpoint(parcelFeatureLayer.FullExtent));
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.Message, "Error").ShowAsync();
            }
        }

        private void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // Check if there is already a selected feature.
            if (_selectedFeature == null)
            {
                _ = SelectFeature(e.Position);
            }
            else
            {
                // Project the user selected point.
                MapPoint projPoint = GeometryEngine.Project(e.Location, _selectedFeature.Geometry.SpatialReference) as MapPoint;

                // Update the geometry of the selected feature.
                _ = UpdateGeometry(projPoint);
            }
        }

        private async Task SelectFeature(Point clickedPoint)
        {
            try
            {
                // Identify across all layers.
                IReadOnlyList<IdentifyLayerResult> identifyResults = await MyMapView.IdentifyLayersAsync(clickedPoint, 10.0, false);
                foreach (IdentifyLayerResult result in identifyResults)
                {
                    if (result.LayerContent is FeatureLayer layer)
                    {
                        _selectedFeature = result.GeoElements.First() as Feature;
                        if (_selectedFeature.Geometry is Polyline line)
                        {
                            // No support for curved lines.
                            if (line.Parts.Count > 1)
                            {
                                _selectedFeature = null;
                                return;
                            }
                        }
                        else if (_selectedFeature.Geometry is MapPoint)
                        {
                            // Open attribute editor for point features.
                            ShowEditableAttributes();
                        }

                        // Select the feature.
                        layer.SelectFeature(_selectedFeature);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.Message, "Error").ShowAsync();
            }
        }

        private async Task UpdateGeometry(MapPoint point)
        {
            if (_selectedFeature.Geometry is Polyline line)
            {
                // Get the nearest point on the selected line.
                ProximityResult nearestVertex = GeometryEngine.NearestVertex(line, point);

                // Create a new polyline.
                PolylineBuilder polylineBuilder = new PolylineBuilder(line);
                Part part = polylineBuilder.Parts[nearestVertex.PartIndex];

                // Replace the nearest point with the new point.
                part.SetPoint(nearestVertex.PointIndex, point);

                // Update the geometry of the feature.
                _selectedFeature.Geometry = GeometryEngine.Project(polylineBuilder.ToGeometry(), _selectedFeature.Geometry.SpatialReference);
                await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature);
            }
            else if (_selectedFeature.Geometry is MapPoint)
            {
                // Update the geometry of the feature.
                _selectedFeature.Geometry = point;
                await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature);
            }

            // Clear the selection.
            (_selectedFeature.FeatureTable.Layer as FeatureLayer).ClearSelection();
            _selectedFeature = null;
        }

        private void ShowEditableAttributes()
        {
            // Show entry UI.
            MyMapView.IsEnabled = false;
            AttributesBorder.Visibility = Windows.UI.Xaml.Visibility.Visible;

            // Populate entry fields with data from feature.
            AdressBox.Text = _selectedFeature.Attributes["AD_ADDRESS"].ToString();
            StreetNameBox.Text = _selectedFeature.Attributes["ST_STR_NAM"].ToString();
        }

        private void CancelClick(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Hide entry UI.
            MyMapView.IsEnabled = true;
            AttributesBorder.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
        }

        private async void OkClick(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            try
            {
                // Update the feature attributes with the user input.
                _selectedFeature.Attributes["AD_ADDRESS"] = int.Parse(AdressBox.Text);
                _selectedFeature.Attributes["ST_STR_NAM"] = StreetNameBox.Text;
                await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature);
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.Message, "Error").ShowAsync();
            }
            finally
            {
                // Hide entry UI.
                MyMapView.IsEnabled = true;
                AttributesBorder.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
        }
    }
}
XAML
<UserControl
    x:Class="ArcGISRuntime.UWP.Samples.EditFeatureLinkedAnnotation.EditFeatureLinkedAnnotation"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
    <Grid>
        <esriUI:MapView x:Name="MyMapView" GeoViewTapped="MyMapView_GeoViewTapped" />
        <Border Style="{StaticResource BorderStyle}"  HorizontalAlignment="Left">
            <TextBlock Text="1. Click to select a feature.&#x0a;2. For MapPoint features, edit the feature attributes.&#x0a;3. Click again to move the feature."/>
        </Border>
        <Border
            x:Name="AttributesBorder"
            Style="{StaticResource BorderStyle}"
            Visibility="Collapsed">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <TextBlock
                    Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
                    Margin="5"
                    Text="Edit feature attribute:" />
                <TextBlock
                    Grid.Row="1" Grid.Column="0"
                    VerticalAlignment="Center"
                    Text="AD_ADDRESS" />
                <TextBox
                    x:Name="AdressBox"
                    Grid.Row="1" Grid.Column="1"
                    Margin="5" />
                <TextBlock
                    Grid.Row="2" Grid.Column="0"
                    VerticalAlignment="Center"
                    Text="ST_STR_NAM" />
                <TextBox
                    x:Name="StreetNameBox"
                    Grid.Row="2" Grid.Column="1"
                    Margin="5" />
                <Button
                    Grid.Row="3" Grid.Column="0"
                    Margin="5" HorizontalAlignment="Stretch"
                    Click="CancelClick" Content="Cancel" />
                <Button
                    Grid.Row="3" Grid.Column="1"
                    Margin="5"
                    Click="OkClick" Content="OK" />
            </Grid>
        </Border>
    </Grid>
</UserControl>
Examples

Xamarin Forms UWP

Example Name: EditFeatureLinkedAnnotation

Edit feature attributes which are linked to annotation through an expression.

Code example screen shot.

C#
// Copyright 2021 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 ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace ArcGISRuntimeXamarin.Samples.EditFeatureLinkedAnnotation
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        name: "Edit features with feature-linked annotation",
        category: "Data",
        description: "Edit feature attributes which are linked to annotation through an expression.",
        instructions: "Pan and zoom the map to see that the text on the map is annotation, not labels. Tap one of the address points to update the house number (AD_ADDRESS) and street name (ST_STR_NAM). Tap one of the dashed parcel polylines and tap another location to change its geometry. NOTE: Selection is only enabled for points and straight (single segment) polylines.",
        tags: new[] { "annotation", "attributes", "feature-linked annotation", "features", "fields" })]
    [ArcGISRuntime.Samples.Shared.Attributes.OfflineData("74c0c9fa80f4498c9739cc42531e9948")]
    public partial class EditFeatureLinkedAnnotation : ContentPage
    {
        private Feature _selectedFeature;

        public EditFeatureLinkedAnnotation()
        {
            InitializeComponent();
            _ = Initialize();
        }

        private async Task Initialize()
        {
            // NOTE: to be a writable geodatabase, this geodatabase must be generated from a service with a GeodatabaseSyncTask. See the "Generate geodatabase" sample.
            try
            {
                // Create and load geodatabase.
                string geodatabasePath = DataManager.GetDataFolder("74c0c9fa80f4498c9739cc42531e9948", "loudoun_anno.geodatabase");
                Geodatabase geodatabase = await Geodatabase.OpenAsync(geodatabasePath);

                // Create feature layers from tables in the geodatabase.
                FeatureLayer addressFeatureLayer = new FeatureLayer(geodatabase.GeodatabaseFeatureTable("Loudoun_Address_Points_1"));
                FeatureLayer parcelFeatureLayer = new FeatureLayer(geodatabase.GeodatabaseFeatureTable("ParcelLines_1"));

                // Create annotation layers from tables in the geodatabase.
                AnnotationLayer addressAnnotationLayer = new AnnotationLayer(geodatabase.GeodatabaseAnnotationTable("Loudoun_Address_PointsAnno_1"));
                AnnotationLayer parcelAnnotationLayer = new AnnotationLayer(geodatabase.GeodatabaseAnnotationTable("ParcelLinesAnno_1"));

                // Create a map with the layers.
                MyMapView.Map = new Map(BasemapStyle.ArcGISLightGray);
                MyMapView.Map.OperationalLayers.AddRange(new List<Layer> { addressFeatureLayer, parcelFeatureLayer, addressAnnotationLayer, parcelAnnotationLayer });

                // Zoom to the extent of the parcels.
                await parcelFeatureLayer.LoadAsync();
                MyMapView.SetViewpoint(new Viewpoint(parcelFeatureLayer.FullExtent));
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK");
            }
        }

        private void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            // Check if there is already a selected feature.
            if (_selectedFeature == null)
            {
                _ = SelectFeature(e.Position);
            }
            else
            {
                // Project the user selected point.
                MapPoint projPoint = GeometryEngine.Project(e.Location, _selectedFeature.Geometry.SpatialReference) as MapPoint;

                // Update the geometry of the selected feature.
                _ = UpdateGeometry(projPoint);
            }
        }

        private async Task SelectFeature(Point clickedPoint)
        {
            try
            {
                // Identify across all layers.
                IReadOnlyList<IdentifyLayerResult> identifyResults = await MyMapView.IdentifyLayersAsync(clickedPoint, 10.0, false);
                foreach (IdentifyLayerResult result in identifyResults)
                {
                    if (result.LayerContent is FeatureLayer layer)
                    {
                        _selectedFeature = result.GeoElements.First() as Feature;
                        if (_selectedFeature.Geometry is Polyline line)
                        {
                            // No support for curved lines.
                            if (line.Parts.Count > 1)
                            {
                                _selectedFeature = null;
                                return;
                            }
                        }
                        else if (_selectedFeature.Geometry is MapPoint)
                        {
                            // Open attribute editor for point features.
                            ShowEditableAttributes();
                        }

                        // Select the feature.
                        layer.SelectFeature(_selectedFeature);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK");
            }
        }

        private async Task UpdateGeometry(MapPoint point)
        {
            if (_selectedFeature.Geometry is Polyline line)
            {
                // Get the nearest point on the selected line.
                ProximityResult nearestVertex = GeometryEngine.NearestVertex(line, point);

                // Create a new polyline.
                PolylineBuilder polylineBuilder = new PolylineBuilder(line);
                Part part = polylineBuilder.Parts[nearestVertex.PartIndex];

                // Replace the nearest point with the new point.
                part.SetPoint(nearestVertex.PointIndex, point);

                // Update the geometry of the feature.
                _selectedFeature.Geometry = GeometryEngine.Project(polylineBuilder.ToGeometry(), _selectedFeature.Geometry.SpatialReference);
                await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature);
            }
            else if (_selectedFeature.Geometry is MapPoint)
            {
                // Update the geometry of the feature.
                _selectedFeature.Geometry = point;
                await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature);
            }

            // Clear the selection.
            (_selectedFeature.FeatureTable.Layer as FeatureLayer).ClearSelection();
            _selectedFeature = null;
        }

        private void ShowEditableAttributes()
        {
            // Show entry UI.
            MyMapView.IsEnabled = false;
            InstructionsText.IsVisible = false;
            AttributesGrid.IsVisible = true;

            // Populate entry fields with data from feature.
            AdressBox.Text = _selectedFeature.Attributes["AD_ADDRESS"].ToString();
            StreetNameBox.Text = _selectedFeature.Attributes["ST_STR_NAM"].ToString();
        }

        private async void OkClick(object sender, System.EventArgs e)
        {
            try
            {
                // Update the feature attributes with the user input.
                _selectedFeature.Attributes["AD_ADDRESS"] = int.Parse(AdressBox.Text);
                _selectedFeature.Attributes["ST_STR_NAM"] = StreetNameBox.Text;
                await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK");
            }
            finally
            {
                // Hide entry UI.
                MyMapView.IsEnabled = true;
                InstructionsText.IsVisible = true;
                AttributesGrid.IsVisible = false;
            }
        }

        private void CancelClick(object sender, System.EventArgs e)
        {
            // Hide entry UI.
            MyMapView.IsEnabled = true;
            InstructionsText.IsVisible = true;
            AttributesGrid.IsVisible = false;
        }
    }
}
XAML
<ContentPage
    x:Class="ArcGISRuntimeXamarin.Samples.EditFeatureLinkedAnnotation.EditFeatureLinkedAnnotation"
    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" xmlns:resources="clr-namespace:Forms.Resources;assembly=ArcGISRuntime">
    <RelativeLayout>
        <esriUI:MapView
            x:Name="MyMapView"
            BindingContext="{x:Reference Name=ResponsiveFormContainer}"
            GeoViewTapped="MyMapView_GeoViewTapped"
            Style="{StaticResource MapWithFormStyle}" />
        <resources:ResponsiveFormContainer x:Name="ResponsiveFormContainer">
            <StackLayout>
                <Label x:Name="InstructionsText" Text="1. Tap to select a feature.&#x0a;2. For MapPoint features, edit the feature attributes.&#x0a;3. Tap again to move the feature." />
                <Grid x:Name="AttributesGrid" IsVisible="false">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Label
                        Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
                        Text="Edit feature attribute:" />
                    <Label
                        Grid.Row="1" Grid.Column="0"
                        Text="AD_ADDRESS" VerticalTextAlignment="Center" />
                    <Entry
                        x:Name="AdressBox"
                        Grid.Row="1" Grid.Column="1"
                        Margin="5" />
                    <Label
                        Grid.Row="2" Grid.Column="0"
                        Text="ST_STR_NAM" VerticalTextAlignment="Center" />
                    <Entry
                        x:Name="StreetNameBox"
                        Grid.Row="2" Grid.Column="1"
                        Margin="5" />
                    <Button
                        Grid.Row="3" Grid.Column="0"
                        Margin="5"
                        Clicked="CancelClick" Text="Cancel" />
                    <Button
                        Grid.Row="3" Grid.Column="1"
                        Margin="5"
                        Clicked="OkClick" Text="OK" />
                </Grid>
            </StackLayout>
        </resources:ResponsiveFormContainer>
    </RelativeLayout>
</ContentPage>
See Also
Additional Examples
Hyperlink to ExampleDescription
EditFeatureLinkedAnnotationEdit feature attributes which are linked to annotation through an expression.