Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

Display draw status

This code sample is available for these platforms:
View Sample on GitHub

Get the draw status of your map view or scene view to know when all layers in the map or scene have finished drawing.

Image of display drawing status

Use case

You may want to display a loading indicator while layers are loading, which could then be removed on DrawStatus.Completed.

How to use the sample

Pan and zoom around the map. Observe how the status changes from a loading animation to solid, indicating that drawing has completed.

How it works

  1. Create a MapView and subscribe to the DrawStatusChanged event.
  2. Inspect the draw status property in the event handler to determine draw status.

Relevant API

  • Map
  • DrawStatus
  • DrawStatusChangedEvent
  • DrawStatusChangedListener
  • MapView

Tags

draw, loading, map, render

Sample Code

<?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"
             xmlns:sampleViewer="clr-namespace:Forms.Resources"
             x:Class="ArcGISRuntime.Samples.DisplayDrawingStatus.DisplayDrawingStatus">
    <RelativeLayout>
        <esriUI:MapView x:Name="myMapView" Style="{StaticResource MapWithFormStyle}" ViewInsets="0" />
        <sampleViewer:ResponsiveFormContainer x:Name="FormContainer">
            <StackLayout>
                <Label Text="Pan and zoom to see drawing status changes." Style="{StaticResource LabelStyle}" />
                <ActivityIndicator x:Name="activityIndicator" Color="Black" />
            </StackLayout>
        </sampleViewer:ResponsiveFormContainer>
    </RelativeLayout>
</ContentPage>
// 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 Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.UI;
using System;
using Xamarin.Forms;

namespace ArcGISRuntime.Samples.DisplayDrawingStatus
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        name: "Display draw status",
        category: "MapView",
        description: "Get the draw status of your map view or scene view to know when all layers in the map or scene have finished drawing.",
        instructions: "Pan and zoom around the map. Observe how the status changes from a loading animation to solid, indicating that drawing has completed.",
        tags: new[] { "draw", "loading", "map", "render" })]
    public partial class DisplayDrawingStatus : ContentPage
    {
        public DisplayDrawingStatus()
        {
            InitializeComponent();

            // Create the UI, setup the control references and execute initialization 
            Initialize();
        }

        private void Initialize()
        {
            // Hook up the DrawStatusChanged event
            myMapView.DrawStatusChanged += OnDrawStatusChanged;

            // Create new Map with basemap
            Map myMap = new Map(BasemapType.Topographic, 34.056, -117.196, 4);

            // Create uri to the used feature service
            Uri serviceUri = new Uri(
                "https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0");

            // Initialize a new feature layer
            ServiceFeatureTable myFeatureTable = new ServiceFeatureTable(serviceUri);
            FeatureLayer myFeatureLayer = new FeatureLayer(myFeatureTable);

            // Add the feature layer to the Map
            myMap.OperationalLayers.Add(myFeatureLayer);

            // Provide used Map to the MapView
            myMapView.Map = myMap;
        }

        private void OnDrawStatusChanged(object sender, DrawStatusChangedEventArgs e)
        {
            // Make sure that the UI changes are done in the UI thread
            Device.BeginInvokeOnMainThread(() =>
            {
                // Show the activity indicator if the map is drawing
                if (e.Status == DrawStatus.InProgress)
                {
                    activityIndicator.IsVisible = true;
                    activityIndicator.IsRunning = true;
                }
                else
                {
                    activityIndicator.IsRunning = false;
                    activityIndicator.IsVisible = false;
                }
            });
        }
    }
}