// Loads the given webmap private async Task LoadWebMapAsync(string wmId) { try { progress.Visibility = Visibility.Visible; var item = await ArcGISPortalItem.CreateAsync(_portal, wmId); var webmap = await WebMap.FromPortalItemAsync(item); var vm = await WebMapViewModel.LoadAsync(webmap, _portal); MyMapView.Map = vm.Map; detailsPanel.DataContext = item; } catch (Exception ex) { infoToggle.IsChecked = false; var _ = new MessageDialog(ex.Message, "Sample Error").ShowAsync(); } finally { progress.Visibility = Visibility.Collapsed; } }
// Initialize the display with a web map and search portal for basemaps private async void MyMapView_Loaded(object sender, RoutedEventArgs e) { try { progress.Visibility = Visibility.Visible; // Load initial webmap var portal = await ArcGISPortal.CreateAsync(); var item = await ArcGISPortalItem.CreateAsync(portal, "3679c136c2694d0b95bb5e6c3f2b480e"); var webmap = await WebMap.FromPortalItemAsync(item); _currentVM = await WebMapViewModel.LoadAsync(webmap, portal); MyMapView.Map = _currentVM.Map; // Load portal basemaps var result = await portal.ArcGISPortalInfo.SearchBasemapGalleryAsync(); basemapList.ItemsSource = result.Results; basemapList.SelectedItem = result.Results.FirstOrDefault(bm => bm.Title == "Topographic"); } catch (Exception ex) { var _ = new MessageDialog(ex.Message, "Sample Error").ShowAsync(); } finally { progress.Visibility = Visibility.Collapsed; } }
private async void MyMapView_Loaded(object sender, RoutedEventArgs e) { // ArcGIS Online への参照を取得 var portal = await ArcGISPortal.CreateAsync(new Uri(PORTAL_URL)); // ID を基にアイテムを取得 var item = await ArcGISPortalItem.CreateAsync(portal, "Web マップ ID"); // アイテムを Web マップとして取得 var webmap = await WebMap.FromPortalItemAsync(item); // Web マップを格納するために WebMapViewModel を作成 var vm = await WebMapViewModel.LoadAsync(webmap, portal); // MapView コントロールの Map プロパティに、WebMap を割り当て MyMapView.Map = vm.Map; // グラフィックス オーバーレイが存在しない場合は、新規に追加 if (MyMapView.GraphicsOverlays.Count == 0) { geocodeResultGraphicsOverlay = new GraphicsOverlay() { Renderer = createGeocoordingSymbol(), }; MyMapView.GraphicsOverlays.Add(geocodeResultGraphicsOverlay); } isMapReady = true; }
// Loads the given webmap private async Task LoadWebMapAsync(string wmId) { try { progress.Visibility = Visibility.Visible; var item = await ArcGISPortalItem.CreateAsync(_portal, wmId); var webmap = await WebMap.FromPortalItemAsync(item); var vm = await WebMapViewModel.LoadAsync(webmap, _portal); mapView.Map = vm.Map; detailsPanel.DataContext = item; detailsPanel.Visibility = Visibility.Visible; } catch (Exception ex) { detailsPanel.Visibility = Visibility.Visible; MessageBox.Show(ex.Message, "Sample Error"); } finally { progress.Visibility = Visibility.Hidden; } }
// Connect to the portal identified by the SecuredPortalUrl variable and load the web map identified by WebMapId private async void LoadSecureMap(object s, EventArgs e) { // Store messages that describe success or errors connecting to the secured portal and opening the web map var messageBuilder = new System.Text.StringBuilder(); try { // See if a credential exists for this portal in the AuthenticationManager // If a credential is not found, the user will be prompted for login info CredentialRequestInfo info = new CredentialRequestInfo { ServiceUri = new Uri(SecuredPortalUrl), AuthenticationType = AuthenticationType.NetworkCredential }; Credential cred = await AuthenticationManager.Current.GetCredentialAsync(info, false); // Create an instance of the IWA-secured portal ArcGISPortal iwaSecuredPortal = await ArcGISPortal.CreateAsync(new Uri(SecuredPortalUrl)); // Report a successful connection messageBuilder.AppendLine("Connected to the portal on " + iwaSecuredPortal.Uri.Host); messageBuilder.AppendLine("Version: " + iwaSecuredPortal.CurrentVersion); // Report the username for this connection if (iwaSecuredPortal.CurrentUser != null) { messageBuilder.AppendLine("Connected as: " + iwaSecuredPortal.CurrentUser.UserName); } else { // This shouldn't happen (if the portal is truly secured)! messageBuilder.AppendLine("Connected anonymously"); } // Get the web map (portal item) to display var webMap = await ArcGISPortalItem.CreateAsync(iwaSecuredPortal, WebMapId); if (webMap != null) { // Create a new map from the portal item and display it in the map view var map = new Map(webMap); _myMapView.Map = map; } } catch (Exception ex) { // Report error messageBuilder.AppendLine("**-Exception: " + ex.Message); } finally { // Show an alert dialog with the status messages var alertBuilder = new AlertDialog.Builder(this); alertBuilder.SetTitle("Status"); alertBuilder.SetMessage(messageBuilder.ToString()); alertBuilder.Show(); } }
/// <summary> /// Load the specified web map. /// </summary> private async void LoadWebMapButtonOnClick(object sender, RoutedEventArgs e) { try { var portal = await ArcGISPortal.CreateAsync(new Uri(MyServerUrl)); var portalItem = await ArcGISPortalItem.CreateAsync(portal, WebMapTextBox.Text); WebMap webMap = await WebMap.FromPortalItemAsync(portalItem); if (webMap != null) { var myWebMapViewModel = await WebMapViewModel.LoadAsync(webMap, portal); MyMapView.Map = myWebMapViewModel.Map; } } catch (Exception ex) { ShowDialog(ex.Message); } }
private async void LoadWebMapButton_Click(object sender, RoutedEventArgs e) { // get a reference to the portal (ArcGIS Online) var arcGISOnline = await ArcGISPortal.CreateAsync(); // get the id of the web map to load var webMapId = WebMapIdTextBox.Text.Trim(); ArcGISPortalItem webMapItem = null; // get a portal item using its ID (ArcGISWebException is thrown if the item is not found) try { webMapItem = await ArcGISPortalItem.CreateAsync(arcGISOnline, webMapId); } catch (ArcGISWebException exp) { MessageBox.Show("Unable to access item '" + webMapId + "'."); return; } // check type: if the item is not a web map, return if (webMapItem.Type != Esri.ArcGISRuntime.Portal.ItemType.WebMap) { return; } // get the web map represented by the portal item var webMap = await Esri.ArcGISRuntime.WebMap.WebMap.FromPortalItemAsync(webMapItem); // create a WebMapViewModel and load the web map var webMapVM = await Esri.ArcGISRuntime.WebMap.WebMapViewModel.LoadAsync(webMap, arcGISOnline); // get the map from the view model; display it in the app's map view this.MyMapView.Map = webMapVM.Map; // get the list of bookmarks for the web map; bind them to the combo box this.BookmarksComboBox.ItemsSource = webMap.Bookmarks; this.BookmarksComboBox.DisplayMemberPath = "Name"; }
/// <summary> /// Get a web map from the selected portal item and display it in the app. /// </summary> private async void AddMapItem_Click(object sender, RoutedEventArgs e) { if (this.MapItemListBox.SelectedItem == null) { return; } // Clear status messages MessagesTextBlock.Text = string.Empty; var sb = new StringBuilder(); try { // Clear the current MapView control from the app MyMapGrid.Children.Clear(); // See if we're using the public or secured portal; get the appropriate object reference ArcGISPortal portal = null; if (_usingPublicPortal) { portal = _publicPortal; } else { portal = _iwaSecuredPortal; } // Throw an exception if the portal is null if (portal == null) { throw new Exception("Portal has not been instantiated."); } // Get the portal item ID from the selected listbox item (read it from the Tag property) var itemId = (this.MapItemListBox.SelectedItem as ListBoxItem).Tag.ToString(); // Use the item ID to create an ArcGISPortalItem from the appropriate portal var portalItem = await ArcGISPortalItem.CreateAsync(portal, itemId); // Create a WebMap from the portal item (all items in the list represent web maps) var webMap = await WebMap.FromPortalItemAsync(portalItem); if (webMap != null) { // Create a WebMapViewModel using the WebMap var myWebMapViewModel = await WebMapViewModel.LoadAsync(webMap, portal); // Create a new MapView control to display the WebMapViewModel's Map; add it to the app var mv = new MapView { Map = myWebMapViewModel.Map }; MyMapGrid.Children.Add(mv); } // Report success sb.AppendLine("Successfully loaded web map from item #" + itemId + " from " + portal.Uri.Host); } catch (Exception ex) { // Add an error message sb.AppendLine("Error accessing web map: " + ex.Message); } finally { // Show messages MessagesTextBlock.Text = sb.ToString(); } }
private async void LoadWebMapButton_TouchUpInside(object sender, EventArgs e) { // Store messages that describe success or errors connecting to the secured portal and opening the web map var messageBuilder = new System.Text.StringBuilder(); try { // See if a credential exists for this portal in the AuthenticationManager // If a credential is not found, the user will be prompted for login info CredentialRequestInfo info = new CredentialRequestInfo { ServiceUri = new Uri(SecuredPortalUrl), AuthenticationType = AuthenticationType.NetworkCredential }; Credential cred = await AuthenticationManager.Current.GetCredentialAsync(info, false); // Create an instance of the IWA-secured portal ArcGISPortal iwaSecuredPortal = await ArcGISPortal.CreateAsync(new Uri(SecuredPortalUrl)); // Report a successful connection messageBuilder.AppendLine("Connected to the portal on " + iwaSecuredPortal.Uri.Host); messageBuilder.AppendLine("Version: " + iwaSecuredPortal.CurrentVersion); // Report the username for this connection if (iwaSecuredPortal.CurrentUser != null) { messageBuilder.AppendLine("Connected as: " + iwaSecuredPortal.CurrentUser.UserName); } else { // This shouldn't happen (if the portal is truly secured)! messageBuilder.AppendLine("Connected anonymously"); } // Get the web map (portal item) to display var webMap = await ArcGISPortalItem.CreateAsync(iwaSecuredPortal, WebMapId); if (webMap != null) { // Create a new map from the portal item and display it in the map view var map = new Map(webMap); _myMapView.Map = map; } } catch (TaskCanceledException) { // Report canceled login messageBuilder.AppendLine("Login was canceled"); } catch (Exception ex) { // Report error messageBuilder.AppendLine("Exception: " + ex.Message); } finally { // Set the task completion source to null so user can attempt another login (if it failed) _loginTaskCompletionSrc = null; // Display the status of the login UIAlertView alert = new UIAlertView("Status", messageBuilder.ToString(), null, "OK"); alert.Show(); } }