Click or drag to resize

MapLoadAsync Method

Initiates loading of a map

Namespace:  Esri.ArcGISRuntime.Mapping
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.7.0.0
Syntax
C#
public Task LoadAsync()

Return Value

Type: Task
A task that represents the asynchronous load operation.

Implements

ILoadableLoadAsync
Examples

Android

Example Name: MapReferenceScale

Set a map's reference scale and control which feature layers should honor that scale.

Code example screen shot.

C#
// Copyright 2019 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.Views;
using Android.Widget;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Portal;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Linq;

namespace ArcGISRuntimeXamarin.Samples.MapReferenceScale
{
    [Activity (ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Map reference scale",
        "Map",
        "Set a map's reference scale and control which feature layers honor that scale.",
        "")]
    public class MapReferenceScale : Activity
    {
        // Hold references to the UI controls.
        private MapView _myMapView;
        private TextView _currentScaleLabel;
        private TextView _referenceScaleSelectionLabel;
        private Button _layersButton;

        // List of reference scale options.
        private readonly double[] _referenceScales =
        {
            50000,
            100000,
            250000,
            500000
        };

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

            Title = "Map reference scale";

            CreateLayout();
            Initialize();
        }

        private async void Initialize()
        {
            // Create a portal and an item; the map will be loaded from portal item.
            ArcGISPortal portal = await ArcGISPortal.CreateAsync(new Uri("https://runtime.maps.arcgis.com"));
            PortalItem mapItem = await PortalItem.CreateAsync(portal, "3953413f3bd34e53a42bf70f2937a408");

            // Create the map from the item.
            Map webMap = new Map(mapItem);

            // Update the UI when the map navigates.
            _myMapView.ViewpointChanged += (o, e) => _currentScaleLabel.Text = $"Current map scale: 1:{_myMapView.MapScale:n0}";

            // Display the map.
            _myMapView.Map = webMap;

            // Wait for the map to load.
            await webMap.LoadAsync();

            // Enable the button now that the map is ready.
            _layersButton.Enabled = true;
        }

        private void ChooseScale_Clicked(object sender, EventArgs e)
        {
            try
            {
                Button scaleButton = (Button) sender;

                // Create menu for showing layer controls.
                PopupMenu sublayersMenu = new PopupMenu(this, scaleButton);
                sublayersMenu.MenuItemClick += ScaleSelection_Changed;

                // Create menu options.
                int index = 0;
                foreach (double scale in _referenceScales)
                {
                    // Add the menu item.
                    sublayersMenu.Menu.Add(0, index, index, $"1:{scale:n0}");
                    index++;
                }

                // Show menu in the view
                sublayersMenu.Show();
            }
            catch (Exception ex)
            {
                new AlertDialog.Builder(this).SetMessage(ex.ToString()).SetTitle("Error").Show();
            }
        }

        private void ScaleSelection_Changed(object sender, PopupMenu.MenuItemClickEventArgs e)
        {
            // Find the index of the selected scale.
            int selectionIndex = e.Item.Order;

            // Apply the selected scale.
            _myMapView.Map.ReferenceScale = _referenceScales[selectionIndex];

            // Update the UI.
            _referenceScaleSelectionLabel.Text = $"1:{_referenceScales[selectionIndex]:n0}";
        }

        private void ChooseLayers_Clicked(object sender, EventArgs e)
        {
            try
            {
                Button layersButton = (Button) sender;

                // Create menu for showing layer controls.
                PopupMenu sublayersMenu = new PopupMenu(this, layersButton);
                sublayersMenu.MenuItemClick += LayerScaleSelection_Changed;

                // Create menu options.
                int index = 0;
                foreach (FeatureLayer layer in _myMapView.Map.OperationalLayers.OfType<FeatureLayer>())
                {
                    // Add the menu item.
                    sublayersMenu.Menu.Add(0, index, index, layer.Name);

                    // Configure the menu item.
                    sublayersMenu.Menu.GetItem(index).SetCheckable(true).SetChecked(layer.ScaleSymbols);

                    index++;
                }

                // Show menu in the view
                sublayersMenu.Show();
            }
            catch (Exception ex)
            {
                new AlertDialog.Builder(this).SetMessage(ex.ToString()).SetTitle("Error").Show();
            }
        }

        private void LayerScaleSelection_Changed(object sender, PopupMenu.MenuItemClickEventArgs e)
        {
            // Get the checked item.
            int selectedLayerIndex = e.Item.Order;

            // Find the layer.
            FeatureLayer selectedLayer = _myMapView.Map.OperationalLayers.OfType<FeatureLayer>().ElementAt(selectedLayerIndex);

            // Set the symbol scale mode.
            selectedLayer.ScaleSymbols = !selectedLayer.ScaleSymbols;

            // Update the UI.
            e.Item.SetChecked(selectedLayer.ScaleSymbols);
        }

        private void CreateLayout()
        {
            // Create a new vertical layout for the app.
            var layout = new LinearLayout(this) {Orientation = Orientation.Vertical};

            // Button for choosing the map's reference scale.
            Button chooseScaleButton = new Button(this);
            chooseScaleButton.Text = "Choose map reference scale";
            chooseScaleButton.Click += ChooseScale_Clicked;
            layout.AddView(chooseScaleButton);

            // Label for showing current reference scale.
            _referenceScaleSelectionLabel = new TextView(this);
            _referenceScaleSelectionLabel.Text = "Choose a reference scale";
            layout.AddView(_referenceScaleSelectionLabel);

            // Button for selecting which layers will have symbol scaling enabled.
            _layersButton = new Button(this);
            _layersButton.Text = "Manage scaling for layers";
            _layersButton.Click += ChooseLayers_Clicked;
            layout.AddView(_layersButton);

            // Add a horizontal line separator.
            View separatorView = new View(this);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 1);
            separatorView.LayoutParameters = lp;
            layout.AddView(separatorView);

            // Add a label that shows the current map scale.
            _currentScaleLabel = new TextView(this);
            _currentScaleLabel.Text = "Current map scale: ";
            layout.AddView(_currentScaleLabel);

            // 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: ChangeBlendRenderer

Blend a hillshade with a raster by specifying the elevation data. The resulting raster looks similar to the original raster, but with some terrain shading, giving it a textured look.

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.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Rasters;
using ArcGISRuntime.Samples.Managers;
using System;
using System.Collections.Generic;
using Xamarin.Forms;

namespace ArcGISRuntime.Samples.ChangeBlendRenderer
{
    [Shared.Attributes.Sample(
        "Blend renderer",
        "Layers",
        "This sample demonstrates how to use blend renderer on a raster layer. You can get a hillshade blended with either a colored raster or color ramp.",
        "Tap on the 'Update Renderer' button to change the settings for the blend renderer. The sample allows you to change the Altitude, Azimuth, SlopeType and ColorRamp. If you use None as the ColorRamp, a standard hill shade raster output is displayed. For all the other ColorRamp types an elevation raster is used.",
        "Featured")]
    [Shared.Attributes.OfflineData("7c4c679ab06a4df19dc497f577f111bd","caeef9aa78534760b07158bb8e068462")]
    public partial class ChangeBlendRenderer : ContentPage
    {
        public ChangeBlendRenderer()
        {
            InitializeComponent();

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

        private async void Initialize()
        {
            // Get all the ColorRamp names from the PresetColorRampType Enumeration and put them 
            // in an array of strings, then set the ComboBox.ItemSource to the array, and finally 
            // select the first item in the ComboBox
            string[] myPresetColorRampTypes = Enum.GetNames(typeof(PresetColorRampType));
            ColorRamps.ItemsSource = myPresetColorRampTypes;
            ColorRamps.SelectedItem = "Elevation";

            // Get all the SlopeType names from the SlopeType Enumeration and put them 
            // in an array of strings, then set the ComboBox.ItemSource to the array, and finally 
            // select the first item in the ComboBox
            string[] mySlopeTypes = Enum.GetNames(typeof(SlopeType));
            SlopeTypes.ItemsSource = mySlopeTypes;
            SlopeTypes.SelectedItem = "Degree";

            // Set the altitude slider min/max and initial value
            Altitude_Slider.Minimum = 0;
            Altitude_Slider.Maximum = 90;
            Altitude_Slider.Value = 45;

            // Set the azimuth slider min/max and initial value
            Azimuth_Slider.Minimum = 0;
            Azimuth_Slider.Maximum = 360;
            Azimuth_Slider.Value = 180;

            // Load the raster file using a path on disk
            Raster myRasterImagery = new Raster(GetRasterPath_Imagery());

            // Create the raster layer from the raster
            RasterLayer myRasterLayerImagery = new RasterLayer(myRasterImagery);

            // Create a new map using the raster layer as the base map 
            Map myMap = new Map(new Basemap(myRasterLayerImagery));

            try
            {
                // Wait for the layer to load - this enabled being able to obtain the extent information 
                // of the raster layer
                await myRasterLayerImagery.LoadAsync();

                // Create a new EnvelopeBuilder from the full extent of the raster layer 
                EnvelopeBuilder myEnvelopBuilder = new EnvelopeBuilder(myRasterLayerImagery.FullExtent);

                // Zoom in the extent just a bit so that raster layer encompasses the entire viewable area of the map
                myEnvelopBuilder.Expand(0.75);

                // Set the viewpoint of the map to the EnvelopeBuilder's extent
                myMap.InitialViewpoint = new Viewpoint(myEnvelopBuilder.ToGeometry().Extent);

                // Add map to the map view
                MyMapView.Map = myMap;

                // Wait for the map to load
                await myMap.LoadAsync();

                // Enable the 'Update Renderer' button now that the map has loaded
                UpdateRenderer.IsEnabled = true;
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert("Error", e.ToString(), "OK");
            }
        }

        private void OnUpdateRendererClicked(object sender, EventArgs e)
        {
            // Define the RasterLayer that will be used to display in the map
            RasterLayer rasterLayer_ForDisplayInMap;

            // Define the ColorRamp that will be used by the BlendRenderer
            ColorRamp myColorRamp;

            // Based on ColorRamp type chosen by the user, create a different
            // RasterLayer and define the appropriate ColorRamp option
            if (ColorRamps.SelectedItem.ToString() == "None")
            {
                // The user chose not to use a specific ColorRamp, therefore 
                // need to create a RasterLayer based on general imagery (ie. Shasta.tif)
                // for display in the map and use null for the ColorRamp as one of the
                // parameters in the BlendRenderer constructor

                // Load the raster file using a path on disk
                Raster raster_Imagery = new Raster(GetRasterPath_Imagery());

                // Create the raster layer from the raster
                rasterLayer_ForDisplayInMap = new RasterLayer(raster_Imagery);

                // Set up the ColorRamp as being null
                myColorRamp = null;
            }
            else
            {
                // The user chose a specific ColorRamp (options: are Elevation, DemScreen, DemLight), 
                // therefore create a RasterLayer based on an imagery with elevation 
                // (ie. Shasta_Elevation.tif) for display in the map. Also create a ColorRamp 
                // based on the user choice, translated into an Enumeration, as one of the parameters 
                // in the BlendRenderer constructor

                // Load the raster file using a path on disk
                Raster raster_Elevation = new Raster(GetRasterPath_Elevation());

                // Create the raster layer from the raster
                rasterLayer_ForDisplayInMap = new RasterLayer(raster_Elevation);

                // Create a ColorRamp based on the user choice, translated into an Enumeration
                PresetColorRampType myPresetColorRampType = (PresetColorRampType)Enum.Parse(typeof(PresetColorRampType), ColorRamps.SelectedItem.ToString());
                myColorRamp = ColorRamp.Create(myPresetColorRampType, 256);
            }

            // Define the parameters used by the BlendRenderer constructor
            Raster raster_ForMakingBlendRenderer = new Raster(GetRasterPath_Elevation());
            IEnumerable<double> myOutputMinValues = new List<double> { 9 };
            IEnumerable<double> myOutputMaxValues = new List<double> { 255 };
            IEnumerable<double> mySourceMinValues = new List<double>();
            IEnumerable<double> mySourceMaxValues = new List<double>();
            IEnumerable<double> myNoDataValues = new List<double>();
            IEnumerable<double> myGammas = new List<double>();
            SlopeType mySlopeType = (SlopeType)Enum.Parse(typeof(SlopeType), SlopeTypes.SelectedItem.ToString());

            BlendRenderer myBlendRenderer = new BlendRenderer(
                raster_ForMakingBlendRenderer, // elevationRaster - Raster based on a elevation source
                myOutputMinValues, // outputMinValues - Output stretch values, one for each band
                myOutputMaxValues, // outputMaxValues - Output stretch values, one for each band
                mySourceMinValues, // sourceMinValues - Input stretch values, one for each band
                mySourceMaxValues, // sourceMaxValues - Input stretch values, one for each band
                myNoDataValues, // noDataValues - NoData values, one for each band
                myGammas, // gammas - Gamma adjustment
                myColorRamp, // colorRamp - ColorRamp object to use, could be null
                Altitude_Slider.Value, // altitude - Altitude angle of the light source
                Azimuth_Slider.Value, // azimuth - Azimuth angle of the light source, measured clockwise from north
                1, // zfactor - Factor to convert z unit to x,y units, default is 1
                mySlopeType, // slopeType - Slope Type
                1, // pixelSizeFactor - Pixel size factor, default is 1
                1, // pixelSizePower - Pixel size power value, default is 1
                8); // outputBitDepth - Output bit depth, default is 8-bi

            // Set the RasterLayer.Renderer to be the BlendRenderer
            rasterLayer_ForDisplayInMap.Renderer = myBlendRenderer;

            // Set the new base map to be the RasterLayer with the BlendRenderer applied
            MyMapView.Map.Basemap = new Basemap(rasterLayer_ForDisplayInMap);
        }

        private static string GetRasterPath_Imagery()
        {
            return DataManager.GetDataFolder("7c4c679ab06a4df19dc497f577f111bd", "raster-file", "Shasta.tif");
        }

        private static string GetRasterPath_Elevation()
        {
            return DataManager.GetDataFolder("caeef9aa78534760b07158bb8e068462", "Shasta_Elevation.tif");
        }

    }
}
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.ChangeBlendRenderer.ChangeBlendRenderer"
             Title="Blend Renderer">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="90"/>
            <RowDefinition Height="90"/>
            <RowDefinition Height="60"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <StackLayout Grid.Row="0" Orientation="Horizontal">
            <Label x:Name="Label_Altitude" Text="Altitude" Margin="10,5"/>
            <Slider x:Name="Altitude_Slider" WidthRequest="100"/>
        </StackLayout>
        <StackLayout Grid.Row="1" Orientation="Horizontal">
            <Label x:Name="Label_Azimuth"  Text="Azimuth" Margin="10, 5"/>
            <Slider x:Name="Azimuth_Slider" WidthRequest="100"/>
        </StackLayout>
        <StackLayout Grid.Row="2" Orientation="Horizontal">
            <Label x:Name="Label_SlopeTypes"  Text="Slope Type" Margin="10, 5" WidthRequest="80"/>
            <ListView x:Name="SlopeTypes" Margin="10,5" />
        </StackLayout>
        <StackLayout Grid.Row="3" Orientation="Horizontal">
            <Label x:Name="Label_ColorRamps"  Text="Color Ramp" Margin="10, 5" WidthRequest="80"/>
            <ListView x:Name="ColorRamps" Margin="10,5" />
        </StackLayout>
        <Button Grid.Row="4" x:Name="UpdateRenderer" Clicked="OnUpdateRendererClicked" Text="Update Renderer" IsEnabled="True" Margin="10,10" />
        <esriUI:MapView Grid.Row="5" x:Name="MyMapView" />
    </Grid>
</ContentPage>
See Also
Additional Examples
Hyperlink to ExampleDescription
ChangeBlendRendererBlend a hillshade with a raster by specifying the elevation data. The resulting raster looks similar to the original raster, but with some terrain shading, giving it a textured look.
ListRelatedFeaturesList features related to the selected feature.
ListTransformationsGet a list of suitable transformations for projecting a geometry between two spatial references with different horizontal datums.
MobileMapSearchAndRouteDisplay maps and use locators to enable search and routing offline using a Mobile Map Package.