Example #1
0
        private async Task <string> QueryImpl()
        {
            var portal = ArcGISPortalManager.Current.GetActivePortal();

            string userName = ArcGISPortalManager.Current.GetActivePortal().GetSignOnUsername();

            //Searching for Vector tile packages in the current user's content
            var pqp = PortalQueryParameters.CreateForItemsOfTypeWithOwner(PortalItemType.VectorTilePackage, userName, "tags: UploadVtpkToAgol Demo");

            //Execute to return a result set
            PortalQueryResultSet <PortalItem> results = await ArcGISPortalExtensions.SearchForContentAsync(portal, pqp);


            if (results.Results.Count == 0)
            {
                return($@"Unable to find uploaded item with query: {pqp.Query}");
            }

            // Create an item from the search results
            string itemId      = results.Results[0].ID;
            var    currentItem = ItemFactory.Instance.Create(itemId, ItemFactory.ItemType.PortalItem);

            // Finally add the feature service to the map
            // if we have an item that can be turned into a layer
            // add it to the map
            if (LayerFactory.Instance.CanCreateLayerFrom(currentItem))
            {
                LayerFactory.Instance.CreateLayer(currentItem, MapView.Active.Map);
            }
            return($@"Downloaded this item: {results.Results[0].Name} [Type: {results.Results[0].Type}] to ArcGIS Online and added the item to the Map");
        }
Example #2
0
        private async Task <string> UploadImpl()
        {
            // Create EsriHttpClient object
            var httpClient = new EsriHttpClient();

            // Upload vtpk file to the currently active portal
            var itemToUpload = ItemFactory.Instance.Create(FilePath);
            var tags         = new string[] { "ArcGIS Pro", "SDK", "UploadVtpkToAgol Demo" };
            var portalUrl    = ArcGISPortalManager.Current.GetActivePortal().PortalUri.ToString();

            var uploadDefn = new UploadDefinition(portalUrl, itemToUpload, tags);

            var result = httpClient.Upload(uploadDefn);

            if (result.Item1 == false)
            {
                return($@"Unable to upload this item: {FilePath} to ArcGIS Online");
            }

            // Once uploaded make another REST call to search for the uploaded data
            var    portal   = ArcGISPortalManager.Current.GetActivePortal();
            string userName = ArcGISPortalManager.Current.GetActivePortal().GetSignOnUsername();

            //Searching for Vector tile packages in the current user's content
            var pqp = PortalQueryParameters.CreateForItemsOfTypeWithOwner(PortalItemType.VectorTilePackage, userName, "tags: UploadVtpkToAgol Demo");

            //Execute to return a result set
            PortalQueryResultSet <PortalItem> results = await ArcGISPortalExtensions.SearchForContentAsync(portal, pqp);

            if (results.Results.Count == 0)
            {
                return($@"Unable to find uploaded item with query: {pqp.Query}");
            }

            // Create an item from the search results
            string itemId      = results.Results[0].ID;
            var    currentItem = ItemFactory.Instance.Create(itemId, ItemFactory.ItemType.PortalItem);
            var    lyrParams   = new LayerCreationParams(currentItem);

            // Finally add the feature service to the map
            // if we have an item that can be turned into a layer
            // add it to the map
            if (LayerFactory.Instance.CanCreateLayerFrom(currentItem))
            {
                LayerFactory.Instance.CreateLayer <FeatureLayer>(lyrParams, MapView.Active.Map);
            }
            return($@"Uploaded this item: {results.Results[0].Name} [Type: {results.Results[0].Type}] to ArcGIS Online and added the item to the Map");
        }