private async void OnSearchMapsClicked(object sender, OnSearchMapEventArgs e)
        {
            try
            {
                // Get web map portal items from a keyword search
                IEnumerable <PortalItem> mapItems = null;

                // Connect to the portal (anonymously)
                ArcGISPortal portal = await ArcGISPortal.CreateAsync(new Uri(ServerUrl));

                // Create a query expression that will get public items of type 'web map' with the keyword(s) in the items tags
                string queryExpression = $"tags:\"{e.SearchText}\" access:public type: (\"web map\" NOT \"web mapping application\")";

                // Create a query parameters object with the expression and a limit of 10 results
                PortalQueryParameters queryParams = new PortalQueryParameters(queryExpression, 10);

                // Search the portal using the query parameters and await the results
                PortalQueryResultSet <PortalItem> findResult = await portal.FindItemsAsync(queryParams);

                // Get the items from the query results
                mapItems = findResult.Results;

                // Show the map results
                ShowMapList(mapItems);
            }
            catch (Exception ex)
            {
                new AlertDialog.Builder(this).SetMessage(ex.ToString()).SetTitle("Error").Show();
            }
        }
Exemplo n.º 2
0
        private async void SearchPublicMaps(string searchText)
        {
            try
            {
                // Get web map portal items from a keyword search
                IEnumerable <PortalItem> mapItems;

                // Connect to the portal (anonymously)
                ArcGISPortal portal = await ArcGISPortal.CreateAsync(new Uri(ArcGISOnlineUrl));

                // Create a query expression that will get public items of type 'web map' with the keyword(s) in the items tags
                string queryExpression = $"tags:\"{searchText}\" access:public type: (\"web map\" NOT \"web mapping application\")";

                // Create a query parameters object with the expression and a limit of 10 results
                PortalQueryParameters queryParams = new PortalQueryParameters(queryExpression, 10);

                // Search the portal using the query parameters and await the results
                PortalQueryResultSet <PortalItem> findResult = await portal.FindItemsAsync(queryParams);

                // Get the items from the query results
                mapItems = findResult.Results;

                // Hide the search controls
                SearchMapsUI.IsVisible = false;

                // Show the list of web maps
                MapsListView.ItemsSource = mapItems.ToList(); // Explicit ToList() needed to avoid Xamarin.Forms UWP ListView bug.
                MapsListView.IsVisible   = true;
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert("Error", e.ToString(), "OK");
            }
        }
Exemplo n.º 3
0
        private async void SearchPublicMaps(string searchText)
        {
            // Get web map portal items from a keyword search
            IEnumerable <PortalItem> mapItems = null;

            // Connect to the portal (anonymously)
            ArcGISPortal portal = await ArcGISPortal.CreateAsync(new Uri(ArcGISOnlineUrl));

            // Create a query expression that will get public items of type 'web map' with the keyword(s) in the items tags
            string queryExpression = $"tags:\"{searchText}\" access:public type: (\"web map\" NOT \"web mapping application\")";

            // Create a query parameters object with the expression and a limit of 10 results
            PortalQueryParameters queryParams = new PortalQueryParameters(queryExpression, 10);

            // Search the portal using the query parameters and await the results
            PortalQueryResultSet <PortalItem> findResult = await portal.FindItemsAsync(queryParams);

            // Get the items from the query results
            mapItems = findResult.Results;

            // Hide the search controls
            SearchMapsUI.IsVisible = false;

            // Show the list of web maps
            MapsListView.ItemsSource = mapItems;
            MapsListView.IsVisible   = true;
        }
Exemplo n.º 4
0
        // Handle the SearchTextEntered event from the search input UI.
        // SearchMapsEventArgs contains the search text that was entered.
        private async void SearchTextEntered(string searchText)
        {
            try
            {
                // Connect to the portal (anonymously).
                ArcGISPortal portal = await ArcGISPortal.CreateAsync(new Uri(ServerUrl));

                // Create a query expression that will get public items of type 'web map' with the keyword(s) in the items tags.
                string queryExpression =
                    $"tags:\"{searchText}\" access:public type: (\"web map\" NOT \"web mapping application\")";

                // Create a query parameters object with the expression and a limit of 10 results.
                PortalQueryParameters queryParams = new PortalQueryParameters(queryExpression, 10);

                // Search the portal using the query parameters and await the results.
                PortalQueryResultSet <PortalItem> findResult = await portal.FindItemsAsync(queryParams);

                // Get the items from the query results.
                IEnumerable <PortalItem> mapItems = findResult.Results;

                // Show the map results.
                ShowMapList(mapItems);
            }
            catch (Exception ex)
            {
                // Report search error.
                UIAlertController alert = UIAlertController.Create("Error", ex.Message, UIAlertControllerStyle.Alert);
                alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
                PresentViewController(alert, true, null);
            }
        }
        private async void SearchPortal(ArcGISPortal currentPortal)
        {
            // Remove any existing results from the list.
            MapItemListBox.Items.Clear();

            // Show a status message and progress bar.
            MessagesTextBlock.Text    = "Searching for web map items on the portal at " + currentPortal.Uri.AbsoluteUri;
            ProgressStatus.Visibility = Visibility.Visible;
            var messageBuilder = new StringBuilder();

            try
            {
                // Report connection info.
                messageBuilder.AppendLine("Connected to the portal on " + currentPortal.Uri.Host);

                // Report the user name used for this connection.
                if (currentPortal.User != null)
                {
                    messageBuilder.AppendLine("Connected as: " + currentPortal.User.UserName);
                }
                else
                {
                    // Note: This shouldn't happen for a secure portal!
                    messageBuilder.AppendLine("Anonymous");
                }

                // Search the portal for web maps.
                var items = await currentPortal.FindItemsAsync(new PortalQueryParameters("type:(\"web map\" NOT \"web mapping application\")"));

                // Build a list of items from the results that shows the map name and stores the item ID (with the Tag property).
                var resultItems = from r in items.Results select new ListBoxItem {
                    Tag = r.ItemId, Content = r.Title
                };

                // Add the items to the list box.
                foreach (var itm in resultItems)
                {
                    MapItemListBox.Items.Add(itm);
                }

                // Enable the button for adding a web map.
                AddMapItem.IsEnabled = true;
            }
            catch (Exception ex)
            {
                // Report errors searching the portal.
                messageBuilder.AppendLine(ex.Message);
            }
            finally
            {
                // Show messages, hide the progress bar.
                MessagesTextBlock.Text    = messageBuilder.ToString();
                ProgressStatus.Visibility = Visibility.Hidden;
            }
        }
Exemplo n.º 6
0
        private async void SearchPortal(ArcGISPortal currentPortal)
        {
            // Clear any existing results.
            WebMapListView.ItemsSource = null;

            // Show status message.
            MessagesTextBlock.Text = "Searching for web map items on the portal at " + currentPortal.Uri.AbsoluteUri;
            var messageBuilder = new StringBuilder();

            try
            {
                // Report connection info
                messageBuilder.AppendLine("Connected to the portal on " + currentPortal.Uri.Host);

                // Report the user name used for this connection.
                if (currentPortal.User != null)
                {
                    messageBuilder.AppendLine("Connected as: " + currentPortal.User.UserName);
                }
                else
                {
                    // Note: This shouldn't happen for a secure portal!
                    messageBuilder.AppendLine("Anonymous");
                }

                // Search the portal for web maps.
                var items = await currentPortal.FindItemsAsync(new PortalQueryParameters("type:(\"web map\" NOT \"web mapping application\")"));

                // Build a list of items from the results that shows the map name and stores the item ID (with the Tag property).
                var resultItems = from r in items.Results select new KeyValuePair <string, PortalItem>(r.Title, r);

                // Add the items to a dictionary.
                _webMapPortalItems = new Dictionary <string, PortalItem>();
                foreach (var itm in resultItems)
                {
                    _webMapPortalItems.Add(itm.Key, itm.Value);
                }

                // Show the portal item titles in the list view.
                WebMapListView.ItemsSource = _webMapPortalItems.Keys;

                // Enable the button to load a selected web map item.
                LoadWebMapButton.IsEnabled = true;
            }
            catch (Exception ex)
            {
                // Report errors searching the portal.
                messageBuilder.AppendLine(ex.Message);
            }
            finally
            {
                // Show messages.
                MessagesTextBlock.Text = messageBuilder.ToString();
            }
        }
Exemplo n.º 7
0
        private async void SearchPortal(ArcGISPortal currentPortal)
        {
            // Show status message.
            _messagesTextView.Text = "Searching for web map items on the portal at " + currentPortal.Uri.AbsoluteUri;
            var messageBuilder = new StringBuilder();

            try
            {
                // Report connection info.
                messageBuilder.AppendLine("Connected to the portal on " + currentPortal.Uri.Host);

                // Report the user name used for this connection.
                if (currentPortal.User != null)
                {
                    messageBuilder.AppendLine("Connected as: " + currentPortal.User.UserName);
                }
                else
                {
                    // Note: This shouldn't happen for a secure portal!
                    messageBuilder.AppendLine("Anonymous");
                }

                // Search the portal for web maps.
                var items = await currentPortal.FindItemsAsync(new PortalQueryParameters("type:(\"web map\" NOT \"web mapping application\")"));

                // Build a list of items from the results.
                var resultItems = from r in items.Results select new KeyValuePair <string, PortalItem>(r.Title, r);

                // Add the items to a dictionary.
                List <PortalItem> webMapItems = new List <PortalItem>();
                foreach (var itm in resultItems)
                {
                    webMapItems.Add(itm.Value);
                }

                // Create an array adapter for the result list.
                PortalItemAdapter adapter = new PortalItemAdapter(this, webMapItems);

                // Apply the adapter to the list view to show the results.
                _webMapListView.Adapter = adapter;
            }
            catch (Exception ex)
            {
                // Report errors searching the portal.
                messageBuilder.AppendLine(ex.Message);
            }
            finally
            {
                // Show messages.
                _messagesTextView.Text = messageBuilder.ToString();
            }
        }
        private async void SearchPortal(ArcGISPortal currentPortal)
        {
            // Show status message.
            _messagesLabel.Text = "Searching for web map items on the portal at " + currentPortal.Uri.AbsoluteUri;
            var messageBuilder = new StringBuilder();

            try
            {
                // Report connection info.
                messageBuilder.AppendLine("Connected to the portal on " + currentPortal.Uri.Host);

                // Report the user name used for this connection.
                if (currentPortal.User != null)
                {
                    messageBuilder.AppendLine("Connected as: " + currentPortal.User.UserName);
                }
                else
                {
                    // Note: This shouldn't happen for a secure portal!
                    messageBuilder.AppendLine("Anonymous");
                }

                // Search the portal for web maps.
                var items = await currentPortal.FindItemsAsync(new PortalQueryParameters("type:(\"web map\" NOT \"web mapping application\")"));

                // Build a list of items from the results that stores the map name as a key for the item.
                var resultItems = from r in items.Results select new KeyValuePair <string, PortalItem>(r.Title, r);

                // Add the items to a dictionary.
                List <PortalItem> webMapItems = new List <PortalItem>();
                foreach (var itm in resultItems)
                {
                    webMapItems.Add(itm.Value);
                }

                // Show the portal item titles in the list view.
                PortalItemListSource webMapTableSource = new PortalItemListSource(webMapItems);
                webMapTableSource.OnWebMapSelected += WebMapTableSource_OnWebMapSelected;
                _webMapTableView.Source             = webMapTableSource;
                _webMapTableView.ReloadData();
            }
            catch (Exception ex)
            {
                // Report errors searching the portal.
                messageBuilder.AppendLine(ex.Message);
            }
            finally
            {
                // Show messages.
                _messagesLabel.Text = messageBuilder.ToString();
            }
        }
Exemplo n.º 9
0
        private async Task LoadItemsAsync(ArcGISPortal portal)
        {
            var results = await portal.FindItemsAsync(new PortalQueryParameters(@"type:'web map' AND  NOT(type:'Web Mapping Application')")
            {
                CanSearchPublic = false,  // Find only items from used portal
                Limit           = 20,
                SortField       = "relevance"
            });

            foreach (var item in results.Results)
            {
                WebMaps.Add(item);
            }
        }
Exemplo n.º 10
0
        private async void addProtal()
        {
            ArcGISPortal portal = await ArcGISPortal.CreateAsync(new Uri("http://esrichina3d.arcgisonline.cn/arcgis/sharing/rest"));

            PortalQueryParameters para = PortalQueryParameters.CreateForItemsOfType(PortalItemType.WebScene);

            para.Limit = 20;
            PortalQueryResultSet <PortalItem> items = await portal.FindItemsAsync(para);

            int sum = 0;

            productList = new List <Product>();
            try
            {
                OpenFileActivity.item = items.Results.First();
                foreach (PortalItem item in items.Results)
                {
                    System.IO.Stream st = await item.GetDataAsync();

                    System.IO.StreamReader reader = new StreamReader(st);
                    st.Position = 0;
                    string json = reader.ReadToEnd();
                    reader.Close();
                    st.Close();
                    productList.Add(new Product(item.ThumbnailUri.ToString(), item.Title, json));
                }
            }
            catch
            { }

            RecyclerView recyclerView = (RecyclerView)FindViewById(Resource.Id.recyclerView);

            //设置layoutManager 布局模式
            recyclerView.SetLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.Vertical));

            //  recyclerView.SetLayoutManager(new LinearLayoutManager(this));
            //设置adapter

            Context        context = this.BaseContext;
            MasonryAdapter WebSceneItemsAdapter = new MasonryAdapter(productList, context);

            WebSceneItemsAdapter.ItemClick += WebSceneItemsAdapter_ItemClick;
            recyclerView.SetAdapter(WebSceneItemsAdapter);

            //设置item之间的间隔
            SpacesItemDecoration decoration = new SpacesItemDecoration(16);

            recyclerView.AddItemDecoration(decoration);
        }
Exemplo n.º 11
0
        private async void SearchMapsClicked(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Get web map portal items in the current user's folder or from a keyword search
            IEnumerable <PortalItem> mapItems = null;

            // Connect to the portal (anonymously)
            ArcGISPortal portal = await ArcGISPortal.CreateAsync();

            // Create a query expression that will get public items of type 'web map' with the keyword(s) in the items tags
            string queryExpression = $"tags:\"{SearchText.Text}\" access:public type: (\"web map\" NOT \"web mapping application\")";

            // Create a query parameters object with the expression and a limit of 10 results
            PortalQueryParameters queryParams = new PortalQueryParameters(queryExpression, 10);

            // Search the portal using the query parameters and await the results
            PortalQueryResultSet <PortalItem> findResult = await portal.FindItemsAsync(queryParams);

            // Get the items from the query results
            mapItems = findResult.Results;

            // Show the search result items in the list
            SearchMapsList.ItemsSource = mapItems;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Async task to load maps from the portal instance and put them in groups
        /// </summary>
        /// <param name="portal">Portal instance</param>
        /// <returns></returns>
        private async Task LoadMaps(ArcGISPortal portal)
        {
            StatusMessage = "Loading maps...";

            var task1 = portal.GetBasemapsAsync();
            var items = await task1;

            Basemaps = items.Select(b => b.Item).OfType <PortalItem>();
            var groups = new ObservableCollection <MapGroup>();

            Groups = groups;
            groups.Add(new MapGroup()
            {
                Name = "Base maps", Items = Basemaps
            });
            IsLoadingBasemaps = false;
            StatusMessage     = string.Format("Connected to {0} ({1})", portal.PortalInfo.PortalName, portal.PortalInfo.PortalName);
            foreach (var item in await portal.GetFeaturedGroupsAsync())
            {
                var query = PortalQueryParameters.CreateForItemsOfTypeInGroup(PortalItemType.WebMap, item.GroupId);
                query.Limit = 20;
                var result = await portal.FindItemsAsync(query);

                if (result.TotalResultsCount > 0)
                {
                    groups.Add(new MapGroup()
                    {
                        Name = item.Title, Items = result.Results
                    });
                    if (Featured == null)
                    {
                        Featured = result.Results;
                    }
                }
            }
        }