Click or drag to resize

PortalItemCreateAsync Method (ArcGISPortal, String)

Initializes a new instance of the PortalItem class from the specified item ID.

Namespace:  Esri.ArcGISRuntime.Portal
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.11.0
Syntax
public static Task<PortalItem> CreateAsync(
	ArcGISPortal portal,
	string itemId
)

Parameters

portal
Type: Esri.ArcGISRuntime.PortalArcGISPortal
The ArcGIS portal.
itemId
Type: SystemString
The item Id.

Return Value

Type: TaskPortalItem
The task object representing the asynchronous create operation. The value of the task result is a PortalItem object.
Remarks
The portal itemId can be determined from the URL of the item details web page or the map viewer URL (for maps only) in your portal. The item details page has the following format (http://www.arcgis.com/home/item.html?id=[item_id]). The webmap viewer has the following format (http://www.arcgis.com/home/webmap/viewer.html?webmap=[item_id]). In both cases, the [item_id] can be used as the ID to instantiate a portal item.
Examples

WPF

Example Name: MapReferenceScale

Set the map's reference scale and which feature layers should honor the reference 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 Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Portal;
using System;

namespace ArcGISRuntime.WPF.Samples.MapReferenceScale
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        name: "Map reference scale",
        category: "Map",
        description: "Set the map's reference scale and which feature layers should honor the reference scale.",
        instructions: "Use the control at the top to set the map's reference scale (1:500,000 1:250,000 1:100,000 1:50,000). Use the menu checkboxes in the layer menu to set which feature layers should honor the reference scale.",
        tags: new[] { "map", "reference scale", "scene" })]
    public partial class MapReferenceScale
    {
        // List of reference scale options.
        private readonly double[] _referenceScales =
        {
            50000,
            100000,
            250000,
            500000
        };

        public MapReferenceScale()
        {
            InitializeComponent();
            Initialize();
        }

        private async void Initialize()
        {
            // Populate the reference scale choices.
            ReferenceScaleBox.ItemsSource = _referenceScales;

            // 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);

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

            // NOTE: this sample uses binding, so explicit control of reference scale isn't seen here.
            // See the iOS or Android samples for an implementation that does not rely on data binding.
        }
    }
}
XAML
<UserControl
    x:Class="ArcGISRuntime.WPF.Samples.MapReferenceScale.MapReferenceScale"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid>
        <esri:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}">
            <StackPanel>
                <TextBlock FontWeight="SemiBold" Text="Choose a map reference scale:" />
                <!--  When the user's selection changes, the SelectedItem binding will apply the value to the Map's ReferenceScale property.  -->
                <ComboBox
                    x:Name="ReferenceScaleBox"
                    Margin="0,5,0,5"
                    SelectedItem="{Binding ElementName=MyMapView, Path=Map.ReferenceScale}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock>
                                <!--  Runs are used to format a plain double to match the convention for writing map scales.  -->
                                <Run Text="1:" />
                                <Run Text="{Binding Path=., StringFormat=n0}" />
                            </TextBlock>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <TextBlock FontWeight="SemiBold" Text="Choose layers to apply scale to:" />
                <!--  Binding is used to display the operational layers for the map view's map, no code behind needed.  -->
                <ListView Margin="0,5,0,5" ItemsSource="{Binding ElementName=MyMapView, Path=Map.OperationalLayers}">
                    <ListView.ItemTemplate>
                        <DataTemplate DataType="esri:FeatureLayer">
                            <!--
                                When the user interacts with the checkbox,
                                the two-way binding will update the ScaleSymbols (bool) property automatically.
                            -->
                            <CheckBox Content="{Binding Name}" IsChecked="{Binding ScaleSymbols}" />
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
                <TextBlock>
                    <!--  A run is used to format the label.  -->
                    <Run Text="Current map scale: " />
                    <Run Text="1:" />
                    <Run Text="{Binding ElementName=MyMapView, Path=MapScale, Mode=OneWay, StringFormat=n0}" />
                </TextBlock>
            </StackPanel>
        </Border>
    </Grid>
</UserControl>
See Also
Additional Examples
Hyperlink to ExampleDescription
DisplayKmlDisplay KML from a URL, portal item, or local KML file.
DownloadPreplannedMapTake a map offline using a preplanned map area.
FeatureCollectionLayerFromPortalCreate a feature collection layer from a portal item.
GenerateOfflineMapTake a web map offline.
GenerateOfflineMapWithOverridesTake a web map offline with additional options for each layer.
IntegratedWindowsAuthConnect to an IWA secured Portal and search for maps.
MapReferenceScaleSet the map's reference scale and which feature layers should honor the reference scale.
OAuthAuthenticate with ArcGIS Online (or your own portal) using OAuth2 to access secured resources (such as private web maps or layers).
OfflineBasemapByReferenceUse the `OfflineMapTask` to take a web map offline, but instead of downloading an online basemap, use one which is already on the device.
OpenScenePortalItemOpen a web scene from a portal item.
ViewContentBeneathSurfaceSee through terrain in a scene and move the camera underground.