Click or drag to resize

FeatureCollectionLayer Class

A layer that can visualize a FeatureCollection.
Inheritance Hierarchy
SystemObject
  Esri.ArcGISRuntime.MappingLayer
    Esri.ArcGISRuntime.MappingFeatureCollectionLayer

Namespace:  Esri.ArcGISRuntime.Mapping
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.9.0.0
Syntax
C#
public sealed class FeatureCollectionLayer : Layer

The FeatureCollectionLayer type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleFeatureCollectionLayer
Initializes a new instance of the FeatureCollectionLayer class.
Top
Properties
  NameDescription
Public propertyAttribution
Gets the attribution text for the layer.
(Inherited from Layer.)
Public propertyCanChangeVisibility
Gets a value indicating whether the layer content's visibility can be changed.
(Inherited from Layer.)
Public propertyDescription
Gets the description for the layer.
(Inherited from Layer.)
Public propertyFeatureCollection
Gets the feature layers associated with this layer.
Public propertyCode exampleFullExtent
Gets the full extent of the layer, which is the extent where all the data in the layer is contained.
(Inherited from Layer.)
Public propertyCode exampleId
Gets or sets an identifier for the layer
(Inherited from Layer.)
Public propertyIsIdentifyEnabled
Gets a value indicating whether the layer supports the identify operation.
(Inherited from Layer.)
Public propertyCode exampleIsVisible
Gets or sets a value indicating whether the layer content is visible.
(Inherited from Layer.)
Public propertyItem
Gets the ArcGIS Item
(Inherited from Layer.)
Public propertyLayers
Gets the feature layers associated with this layer.
Public propertyLoadError
Gets the load error of the layer, if there is one.
(Inherited from Layer.)
Public propertyCode exampleLoadStatus
Gets the load status of the layer.
(Inherited from Layer.)
Public propertyCode exampleMaxScale
Gets or sets the maximum scale where the layer is visible.
(Inherited from Layer.)
Public propertyCode exampleMinScale
Gets or sets the minimum scale where the layer is visible.
(Inherited from Layer.)
Public propertyCode exampleName
Gets or sets the name of the layer content.
(Inherited from Layer.)
Public propertyCode exampleOpacity
Gets or sets the opacity of the layer.
(Inherited from Layer.)
Public propertyShowInLegend
Gets or sets a value indicating whether the layer content participates in the legend.
(Inherited from Layer.)
Public propertySpatialReference
Gets the spatial reference of the layer.
(Inherited from Layer.)
Public propertyCode exampleSublayerContents
Gets the sub layer contents of a layer content.
(Inherited from Layer.)
Top
Methods
  NameDescription
Public methodCancelLoad
Cancels an ongoing load.
(Inherited from Layer.)
Public methodCode exampleClone
Clones this instance of Layer and its members.
(Inherited from Layer.)
Public methodGetLegendInfosAsync
Returns an immutable list of LegendInfo.
(Inherited from Layer.)
Public methodIsVisibleAtScale
Returns the layer content's effective visibility at the specified scale.
(Inherited from Layer.)
Public methodCode exampleLoadAsync
Initiates loading of a layer
(Inherited from Layer.)
Public methodRetryLoadAsync
Retry loading the layer.
(Inherited from Layer.)
Top
Events
  NameDescription
Public eventCode exampleLoaded
Occurs when the layer is loaded.
(Inherited from Layer.)
Public eventLoadStatusChanged
Occurs when the layer LoadStatus is changed.
(Inherited from Layer.)
Public eventPropertyChanged
Occurs when a property value changes.
(Inherited from Layer.)
Top
Remarks

A feature collection groups logically-related tables of features even though they may have different schema, geometry types, and symbology. A feature collection layer allows multiple tables with different schemas to be managed as a group.

Functional characteristics

Sketch information (called Map Notes in ArcGIS Online), may contain points, lines, polygons, and associated text to describe things in the map. Because they have different schema and geometry types, these features are stored in several distinct tables. A feature collection layer allows these tables to be rendered and managed as a group.

A feature collection can be saved in the map or as a stand-alone portal item. If you need to share the feature collection between several maps, it's best to store it as a separate portal item. If you need to make frequent (near real-time) edits to features in a collection, consider storing these in a feature service instead, because the feature collection is not refreshed until the map or portal item is reloaded. If features are used by a single map or are not subject to frequent updates, it might be best to store them directly in the map. Edits made to features stored in a map will be saved when the map is saved. Edits made to features stored in a portal item (and loaded into a map, for example) must be explicitly saved to the original portal item.

Performance characteristics

Feature collection layers are designed to display a moderate amount of feature data (hundreds or thousands of features). They are ideal for sharing static data (not subject to frequent updates) among several clients.

As full feature information is cached locally in a geodatabase and features are drawn natively, this layer type offers excellent display performance when zooming and panning the map, within the extent of cached features.

Downloading features to the device may require extensive network usage and local device storage space. After the features are present on the client, the app no longer needs to make requests for the data. App memory usage increases with the number and complexity of the features in the collection.

Sample Code:

Examples

Android

Example Name: FeatureCollectionLayerFromQuery

Create a feature collection layer to show a query result from a service feature table.

Code example screen shot.

C#
// Copyright 2016 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 Android.App;
using Android.OS;
using Android.Widget;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.UI.Controls;
using System;

namespace ArcGISRuntime.Samples.FeatureCollectionLayerFromQuery
{
    [Activity (ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        name: "Feature collection layer (query)",
        category: "Layers",
        description: "Create a feature collection layer to show a query result from a service feature table.",
        instructions: "When launched, this sample displays a map with point features as a feature collection layer. Pan and zoom to explore the map.",
        tags: new[] { "layer", "query", "search", "table" })]
    public class FeatureCollectionLayerFromQuery : Activity
    {
        // Hold a reference to the map view.
        private MapView _myMapView;

        // Service endpoint to query for features
        private const string FeatureLayerUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire/FeatureServer/0";

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Title = "Add a query result as a feature collection layer";

            // Create the UI
            CreateLayout();

            // Initialize the app
            Initialize();
        }

        private void Initialize()
        {
            // Create a new map with the oceans basemap and add it to the map view
            Map myMap = new Map(Basemap.CreateOceans());
            _myMapView.Map = myMap;

            // Call a function that will create a new feature collection layer from a service query
            GetFeaturesFromQuery();
        }

        private async void GetFeaturesFromQuery()
        {
            try
            {
                // Create a service feature table to get features from
                ServiceFeatureTable featTable = new ServiceFeatureTable(new Uri(FeatureLayerUrl));

                // Create a query to get all features in the table
                QueryParameters queryParams = new QueryParameters
                {
                    WhereClause = "1=1"
                };

                // Query the table to get all features
                FeatureQueryResult featureResult = await featTable.QueryFeaturesAsync(queryParams);

                // Create a new feature collection table from the result features
                FeatureCollectionTable collectTable = new FeatureCollectionTable(featureResult);

                // Create a feature collection and add the table
                FeatureCollection featCollection = new FeatureCollection();
                featCollection.Tables.Add(collectTable);

                // Create a layer to display the feature collection, add it to the map's operational layers
                FeatureCollectionLayer featCollectionTable = new FeatureCollectionLayer(featCollection);
                _myMapView.Map.OperationalLayers.Add(featCollectionTable);
            }
            catch (Exception e)
            {
                new AlertDialog.Builder(this).SetMessage(e.ToString()).SetTitle("Error").Show();
            }
        }

        private void CreateLayout()
        {
            // Create a new layout
            LinearLayout layout = new LinearLayout(this) { Orientation = Orientation.Vertical };

            // Add the map view to the layout
            _myMapView = new MapView(this);
            layout.AddView(_myMapView);

            // Show the layout in the app
            SetContentView(layout);
        }
    }
}
Examples

Xamarin Forms Android

Example Name: FeatureCollectionLayerFromPortal

Create a feature collection layer from a portal item.

Code example screen shot.

C#
// Copyright 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 Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Portal;
using System;
using Xamarin.Forms;

namespace ArcGISRuntime.Samples.FeatureCollectionLayerFromPortal
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        name: "Create feature collection layer (Portal item)",
        category: "Layers",
        description: "Create a feature collection layer from a portal item.",
        instructions: "The feature collection is loaded from the Portal item when the sample starts.",
        tags: new[] { "collection", "feature collection", "feature collection layer", "id", "item", "map notes", "portal" })]
    public partial class FeatureCollectionLayerFromPortal : ContentPage
    { 
        // Default portal item Id to load features from.
        private const string FeatureCollectionItemId = "32798dfad17942858d5eef82ee802f0b";

        public FeatureCollectionLayerFromPortal()
        {
            InitializeComponent();

            // call a function to initialize a map to display in the MyMapView control.
            Initialize();
        }

        private void Initialize()
        {
            // Add a default value for the portal item Id.
            CollectionItemIdTextBox.Text = FeatureCollectionItemId;

            // Create a new map with the oceans basemap and add it to the map view.
            Map myMap = new Map(Basemap.CreateOceans());
            MyMapView.Map = myMap;
        }

        private async void OpenFeaturesFromArcGISOnline(string itemId)
        {
            try
            {
                // Open a portal item containing a feature collection.
                ArcGISPortal portal = await ArcGISPortal.CreateAsync();
                PortalItem collectionItem = await PortalItem.CreateAsync(portal, itemId);

                // Verify that the item is a feature collection.
                if (collectionItem.Type == PortalItemType.FeatureCollection)
                {
                    // Create a new FeatureCollection from the item.
                    FeatureCollection featureCollection = new FeatureCollection(collectionItem);

                    // Create a layer to display the collection and add it to the map as an operational layer.
                    FeatureCollectionLayer featureCollectionLayer = new FeatureCollectionLayer(featureCollection)
                    {
                        Name = collectionItem.Title
                    };

                    MyMapView.Map.OperationalLayers.Add(featureCollectionLayer);
                }
                else
                {
                    await Application.Current.MainPage.DisplayAlert("Feature Collection", "Portal item with ID '" + itemId + "' is not a feature collection.", "OK");
                }
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Unable to open item with ID '" + itemId + "': " + ex.Message, "OK");
            }
        }

        private async void OpenPortalFeatureCollectionClick(object sender, EventArgs e)
        {
            // Get the portal item Id from the user.
            string collectionItemId = CollectionItemIdTextBox.Text.Trim();

            // Make sure an Id was entered.
            if (String.IsNullOrEmpty(collectionItemId))
            {
                await Application.Current.MainPage.DisplayAlert("Feature Collection ID", "Please enter a portal item ID", "OK");
                return;
            }

            // Call a function to add the feature collection from the specified portal item.
            OpenFeaturesFromArcGISOnline(collectionItemId);
        }
    }
}
XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage 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"
             x:Class="ArcGISRuntime.Samples.FeatureCollectionLayerFromPortal.FeatureCollectionLayerFromPortal">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
        </Grid.RowDefinitions>
        <esriUI:MapView x:Name="MyMapView"
                        Grid.Row="0"/>
        <Entry x:Name="CollectionItemIdTextBox"
               Placeholder="Portal item Id"
               Grid.Row="1"
               HorizontalOptions="Fill"/>
        <Button Grid.Row="2"
                HorizontalOptions="Fill"
                Text="Open feature collection item"
                Clicked="OpenPortalFeatureCollectionClick"/>
    </Grid>
</ContentPage>
See Also
Additional Examples
Hyperlink to ExampleDescription
CreateFeatureCollectionLayerCreate a Feature Collection Layer from a Feature Collection Table, and add it to a map.
FeatureCollectionLayerFromPortalCreate a feature collection layer from a portal item.
FeatureCollectionLayerFromQueryCreate a feature collection layer to show a query result from a service feature table.