Пример #1
0
        private async void LoadPortalItem(ArcGISPortalItem item)
        {
            try
            {
                if (item == null)
                {
                    WebMapVM = null;
                }
                else
                {
                    StatusMessage   = "Loading Webmap...";
                    IsLoadingWebMap = true;
                    var webmap = await WebMap.FromPortalItemAsync(item);

                    WebMapVM = await WebMapViewModel.LoadAsync(webmap, item.ArcGISPortal);

                    IsLoadingWebMap = false;
                    StatusMessage   = "";
                }
            }
            catch (System.Exception ex)
            {
                StatusMessage   = "Webmap load failed: " + ex.Message;
                IsLoadingWebMap = false;
            }
        }
Пример #2
0
        // 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;
            }
        }
        // Loads the given webmap
        private async Task LoadWebMapAsync(ArcGISPortalItem portalItem)
        {
            try
            {
                IsBusy = true;

                if (_portal == null)
                {
                    _portal = await ArcGISPortal.CreateAsync();
                }

                var webmap = await WebMap.FromPortalItemAsync(portalItem);

                LoadedPortalItem = portalItem;
                CurrentWebMapVM  = await WebMapViewModel.LoadAsync(webmap, _portal);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            finally
            {
                IsBusy = false;
            }
        }
 public ArcGisPortalWebMapItem(ArcGISPortalItem arcGisPortalItem, WebMap webMap, bool isEditable, bool isSyncable)
 {
     _arcGisPortalItem = arcGisPortalItem;
     _webMap = webMap;
     _isEditable = isEditable;
     _isSyncable = isSyncable;
 }
        private async void LoadWebMap()
        {
            try
            {
                ArcGISPortal portal = new ArcGISPortal()
                {
                    Url = "http://www.arcgis.com/sharing/rest"
                };
                ArcGISPortalItem portalItem = new ArcGISPortalItem(portal)
                {
                    Id = "00e5e70929e14055ab686df16c842ec1"
                };

                WebMap webMap = await WebMap.FromPortalItemTaskAsync(portalItem);

                MyWebMapViewModel = await WebMapViewModel.LoadAsync(webMap, portalItem.ArcGISPortal);
            }
            catch (Exception ex)
            {
                if (ex is ServiceException)
                {
                    MessageBox.Show(String.Format("{0}: {1}", (ex as ServiceException).Code.ToString(), (ex as ServiceException).Details[0]), "Error", MessageBoxButton.OK);
                    return;
                }
            }
        }
 private static string ConvertPortalItemToHtmlString(ArcGISPortalItem portalItem)
 {
     if (portalItem != null)
     {
         var sb = new StringBuilder();
         sb.Append("<h2>");
         sb.Append("Description");
         sb.Append("</h2>");
         sb.Append(portalItem.Description);
         sb.Append("<h2>");
         sb.Append("Access and Use Constraints");
         sb.Append("</h2>");
         sb.Append(portalItem.LicenseInfo);
         sb.Append("<h2>");
         sb.Append("Credits");
         sb.Append("</h2>");
         sb.Append(portalItem.AccessInformation);
         sb.Append("<h2>");
         sb.Append("Tags");
         sb.Append("</h2>");
         var index = 0;
         foreach (var tag in portalItem.Tags)
         {
             if (index++ != 0)
             {
                 sb.Append("<span>, </span>");
             }
             sb.AppendFormat("<a href=\"arcgis://search/{0}\" style=\"text-decoration:none\" >{1}</a>", Uri.EscapeDataString(tag), tag);
         }
         return(sb.ToString());
     }
     return(string.Empty);
 }
 private static string ConvertPortalItemToHtmlString(ArcGISPortalItem portalItem)
 {
     if (portalItem != null)
     {
         var sb = new StringBuilder();
         sb.Append("<h2>");
         sb.Append("Description");
         sb.Append("</h2>");
         sb.Append(portalItem.Description);
         sb.Append("<h2>");
         sb.Append("Access and Use Constraints");
         sb.Append("</h2>");
         sb.Append(portalItem.LicenseInfo);
         sb.Append("<h2>");
         sb.Append("Credits");
         sb.Append("</h2>");
         sb.Append(portalItem.AccessInformation);
         sb.Append("<h2>");
         sb.Append("Tags");
         sb.Append("</h2>");
         var index = 0;
         foreach (var tag in portalItem.Tags)
         {
             if (index++ != 0)
                 sb.Append("<span>, </span>");
             sb.AppendFormat("<a href=\"arcgis://search/{0}\" style=\"text-decoration:none\" >{1}</a>", Uri.EscapeDataString(tag), tag);
         }
         return sb.ToString();
     }
     return string.Empty;
 }
Пример #9
0
 internal void OnItemClicked(ArcGISPortalItem arcGISPortalItem)
 {
     if (ItemClick != null)
     {
         ItemClick(this, new ArcGISPortalItemClickEventArgs(arcGISPortalItem));
     }
 }
Пример #10
0
        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;
        }
Пример #11
0
        public bool RemoveFromFavorites(ArcGISPortalItem portalItemViewModel)
        {
            if (portalItemViewModel == null || portalItemViewModel == null)
            {
                return(false);
            }

            string        itemId        = portalItemViewModel.Id;
            List <string> favoriteItems = GetFavoritesIds();

            if (string.IsNullOrEmpty(itemId) || !favoriteItems.Contains(itemId))
            {
                return(false);
            }

            try
            {
                // remove portalItemViewModel from favorites
                Favorites.Remove(portalItemViewModel);
            }
            catch (Exception)
            {
            }

            // remove item id from favoriteItems and persist it
            if (favoriteItems.Remove(itemId))
            {
                SaveFavorites(favoriteItems);
                return(true);
            }
            return(false);
        }
        public void ResultList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            // clear UI controls
            this.ResetUI();
            // store the currently selected portal item
            this.SelectedPortalItem = this.ResultListBox.SelectedItem as ArcGISPortalItem;
            if (this.SelectedPortalItem == null)
            {
                return;
            }

            // show the portal item snippet (brief description) in the UI
            if (!string.IsNullOrEmpty(this.SelectedPortalItem.Snippet))
            {
                this.SnippetTextBlock.Text = this.SelectedPortalItem.Snippet;
            }
            // show a thumbnail for the selected portal item (if there is one)
            if (this.SelectedPortalItem.ThumbnailUri != null)
            {
                var src = new BitmapImage(this.SelectedPortalItem.ThumbnailUri);
                this.ThumbnailImage.Source = src;
            }
            // enable the show map button when a web map portal item is chosen
            this.ShowMapButton.IsEnabled = (this.SelectedPortalItem.Type == ItemType.WebMap);
        }
Пример #13
0
        // 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;
            }
        }
Пример #14
0
 private bool CanExecuteOpenMapCommand(ArcGISPortalItem portalItem)
 {
     if (portalItem != null && portalItem.Type == ItemType.WebMap)
     {
         return(true);
     }
     return(false);
 }
Пример #15
0
        // 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();
            }
        }
Пример #16
0
        private void ExecuteOpenMapCommand(ArcGISPortalItem portalItem)
        {
            if (portalItem == null)
            {
                throw new Exception("ArcGIS Portal Item is null or not selected");
            }

            (new NavigationService()).Navigate(App.MapPageName, portalItem);
        }
Пример #17
0
        public async void CreatePinTile(ArcGISPortalItem portalItem, Rect tileProptRect)
        {
            //string nav = string.Format(@"arcgis://www.arcgis.com/sharing/rest/content/items/{0}/data", portalItem.Id);
            string nav = string.Format(@"arcgis:{0}/sharing/rest/content/items/{1}/data", App.OrganizationUrl, portalItem.Id);

            IsPinningTile = true;
            await TileService.CreateSecondaryTileFromWebImage(portalItem.Title, portalItem.Id,
                                                              portalItem.ThumbnailUri, tileProptRect, nav);

            IsPinningTile = false;
        }
Пример #18
0
        // Click on a graphic in the map and select it.  Scroll to the web map item in the Listbox.
        private void GraphicsLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs e)
        {
            webmapGraphicsLayer.ClearSelection();
            Graphic graphic = e.Graphic;

            graphic.Selected = true;
            ArcGISPortalItem portalitem = graphic.Attributes["PortalItem"] as ArcGISPortalItem;

            WebMapsListBox.SelectedItem = portalitem;
            WebMapsListBox.ScrollIntoView(portalitem);
        }
Пример #19
0
        /// <summary>
        /// AU clic sur une carte de la liste
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void webmapsList_SelectionChanged(object sender, SelectedItemChangedEventArgs e)
        {
            if (webmapsList.SelectedItem != null)
            {
                // on récupère la carte sélectionnée : Un portal item
                ArcGISPortalItem webmap = (ArcGISPortalItem)webmapsList.SelectedItem;

                // on crée une nouvelle carte
                Map myNewMap = new Map(webmap);

                // on assigne la nouvelle carte à la vue
                myView.Map = myNewMap;
            }
        }
Пример #20
0
        private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ArcGISPortalItem portalItem = (sender as Image).DataContext as ArcGISPortalItem;

            var document = new Document();

            document.GetMapCompleted += (a, b) =>
            {
                if (b.Error == null)
                {
                    WebmapContent.Children.Clear();
                    WebmapContent.Children.Add(b.Map);
                    WebmapContentPage.IsOpen = true;
                }
            };
            document.GetMapAsync(portalItem.Id);
        }
        public void AddToFavorites(ArcGISPortalItem portalItemViewModel)
        {
            if (portalItemViewModel == null || portalItemViewModel == null)
                return;

            string itemId = portalItemViewModel.Id;
            List<string> favoriteItems = GetFavoritesIds();
            if (string.IsNullOrEmpty(itemId) || favoriteItems == null || favoriteItems.Contains(itemId))
                return;
            
            //add item to Favorites collection
            Favorites.Add(portalItemViewModel);
            // add item id to favoriteItems
            favoriteItems.Add(itemId);
            // persist favoriteItems
            SaveFavorites(favoriteItems);
        }
Пример #22
0
        private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ArcGISPortalItem portalItem = (sender as Image).DataContext as ArcGISPortalItem;

            BackToResults.Visibility = System.Windows.Visibility.Visible;
            var document = new Document();

            document.GetMapCompleted += (a, b) =>
            {
                if (b.Error == null)
                {
                    WebmapContent.Children.Clear();
                    WebmapContent.Children.Add(b.Map);
                    WebmapContent.Visibility = Visibility.Visible;
                }
            };
            document.GetMapAsync(portalItem.Id);
        }
Пример #23
0
        public void AddToFavorites(ArcGISPortalItem portalItemViewModel)
        {
            if (portalItemViewModel == null || portalItemViewModel == null)
            {
                return;
            }

            string        itemId        = portalItemViewModel.Id;
            List <string> favoriteItems = GetFavoritesIds();

            if (string.IsNullOrEmpty(itemId) || favoriteItems == null || favoriteItems.Contains(itemId))
            {
                return;
            }

            //add item to Favorites collection
            Favorites.Add(portalItemViewModel);
            // add item id to favoriteItems
            favoriteItems.Add(itemId);
            // persist favoriteItems
            SaveFavorites(favoriteItems);
        }
Пример #24
0
		private async void LoadPortalItem(ArcGISPortalItem item)
		{
			try
			{
				if (item == null)
					WebMapVM = null;
				else
				{
					StatusMessage = "Loading Webmap...";
					IsLoadingWebMap = true;
					var webmap = await WebMap.FromPortalItemAsync(item);
					WebMapVM = await WebMapViewModel.LoadAsync(webmap, item.ArcGISPortal);
					IsLoadingWebMap = false;
					StatusMessage = "";
				}
			}
			catch (System.Exception ex)
			{
				StatusMessage = "Webmap load failed: " + ex.Message;
				IsLoadingWebMap = false;
			}
		}
        private async void LoadWebMap()
        {
            try
            {
                ArcGISPortal portal = new ArcGISPortal() 
                    { Url = "http://www.arcgis.com/sharing/rest" };
                ArcGISPortalItem portalItem = new ArcGISPortalItem(portal) 
                    { Id = "00e5e70929e14055ab686df16c842ec1" };

                WebMap webMap = await WebMap.FromPortalItemTaskAsync(portalItem);

                MyWebMapViewModel = await WebMapViewModel.LoadAsync(webMap, portalItem.ArcGISPortal);
            }
            catch (Exception ex)
            {
                if (ex is ServiceException)
                {
                    MessageBox.Show(String.Format("{0}: {1}", (ex as ServiceException).Code.ToString(), (ex as ServiceException).Details[0]), "Error", MessageBoxButton.OK);
                    return;
                }
            }
        }
Пример #26
0
        /// <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);
            }
        }
Пример #27
0
        /// <summary>
        /// Changes used basemap.
        /// </summary>
        /// <param name="item">Item to load</param>
        private async void ChangeBasemap(ArcGISPortalItem item)
        {
            Exception exceptionToHandle = null;

            try
            {
                var webmap = await WebMap.FromPortalItemAsync(item);

                WebMapViewModel = await WebMapViewModel.LoadAsync(webmap, _portal);
            }
            catch (Exception exception)
            {
                exceptionToHandle = exception;
            }

            if (exceptionToHandle != null)
            {
                await MessageService.Instance.ShowMessage(string.Format(
                                                              "Could not create basemap. Error = {0}", exceptionToHandle.ToString()),
                                                          "An error occured");
            }
        }
Пример #28
0
        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";
        }
Пример #29
0
        // Click on a web map item in the Listbox, zoom to and select the respective graphic in the map.
        private void Image_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            webmapGraphicsLayer.ClearSelection();
            ArcGISPortalItem portalItem = (sender as Image).DataContext as ArcGISPortalItem;

            if (portalItem.Extent != null)
            {
                MyMap.ZoomTo(mercator.FromGeographic(portalItem.Extent));
            }

            // Use LINQ to select the graphic where the portal item attribute equals the portal item instance
            // in the Listbox.
            var queryPortalItemGraphics = from g in webmapGraphicsLayer.Graphics
                                          where g.Attributes["PortalItem"] == portalItem
                                          select g;

            // Get the first graphic in the IEnumerable of graphics and set it selected.
            foreach (var graphic in queryPortalItemGraphics)
            {
                graphic.Selected = true;
                return;
            }
        }
        public bool RemoveFromFavorites(ArcGISPortalItem portalItemViewModel)
        {
            if (portalItemViewModel == null || portalItemViewModel == null)
                return false;

            string itemId = portalItemViewModel.Id;
            List<string> favoriteItems = GetFavoritesIds();
            if (string.IsNullOrEmpty(itemId) || !favoriteItems.Contains(itemId))
                return false;

            try
            {
                // remove portalItemViewModel from favorites                
                Favorites.Remove(portalItemViewModel);
            }
            catch (Exception)
            {
            }

            // remove item id from favoriteItems and persist it
            if (favoriteItems.Remove(itemId))
            {
                SaveFavorites(favoriteItems);
                return true;
            }
            return false;
        }
Пример #31
0
 public PortalItem(ArcGISPortalItem item)
 {
     ArcGISPortalItem = item;
 }
			internal ArcGISPortalItemClickEventArgs(ArcGISPortalItem item)
			{
				m_item = item;
			}
		internal void OnItemClicked(ArcGISPortalItem arcGISPortalItem)
		{
			if (ItemClick != null)
				ItemClick(this, new ArcGISPortalItemClickEventArgs(arcGISPortalItem));
		}
Пример #34
0
 private void Grid_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
 {
     SelectedPortalItem = (sender as FrameworkElement).DataContext as ArcGISPortalItem;
     Frame.Navigate(typeof(MapPage), SelectedPortalItem);
 }
Пример #35
0
        public PortalCollectionViewModel(INavigationService navigationService)
        {
            Messenger.Default.Register <ChangeIncremetalCollectionMessage>(this, msg =>
            {
                try
                {
                    PortalItems       = msg.ItemCollection;
                    CollectionTitle   = PortalItems.Title;
                    CurrentCollection = PortalItems;
                }
                catch (Exception ex)
                {
                    var _ = App.ShowExceptionDialog(ex);
                }
            });

            Messenger.Default.Register <ChangePortalItemsCollectionMessage>(this, msg =>
            {
                try
                {
                    MyMapsItems       = msg.ItemCollection;
                    CollectionTitle   = msg.Title;
                    CurrentCollection = MyMapsItems;
                }
                catch (Exception ex)
                {
                    var _ = App.ShowExceptionDialog(ex);
                }
            });

            Messenger.Default.Register <ChangeFavoritesCollectionMessage>(this, msg =>
            {
                try
                {
                    CollectionTitle   = msg.Title;
                    CurrentCollection = FavoritesService.CurrentFavoritesService.Favorites;
                }
                catch (Exception ex)
                {
                    var _ = App.ShowExceptionDialog(ex);
                }
            });

            Messenger.Default.Register <ChangePortalGroupsCollectionMessage>(this, msg =>
            {
                try
                {
                    PortalGroups      = msg.ItemCollection;
                    CollectionTitle   = "Groups";
                    CurrentCollection = PortalGroups;
                }
                catch (Exception ex)
                {
                    var _ = App.ShowExceptionDialog(ex);
                }
            });

            // initialize ItemClick RelayCommand
            ItemClickCommand = new RelayCommand <object>((e) =>
            {
                // handle the type of EventArgs passed
                if (e == null)
                {
                    return;
                }

                ArcGISPortalItem portalItem = null;
                if (e.GetType() == typeof(ArcGISPortalItem))
                {
                    portalItem = e as ArcGISPortalItem;
                }
                // the GridView sends ItemClickEventArgs
                else if (e.GetType() == typeof(ItemClickEventArgs))
                {
                    portalItem = ((ItemClickEventArgs)e).ClickedItem as ArcGISPortalItem;
                }
                else if (e.GetType() == typeof(PointerRoutedEventArgs))
                {
                    portalItem = ((PointerRoutedEventArgs)e).OriginalSource as ArcGISPortalItem;
                }

                if (portalItem != null)
                {
                    //SelectedPortalItem = portalItem;

                    // send clicked item via a message to other ViewModels who
                    // are registered with ChangeItemSelectedMessage
                    Messenger.Default.Send <ChangeItemSelectedMessage>(new ChangeItemSelectedMessage()
                    {
                        Item = portalItem
                    });

                    // use the navigation service to navigate to the page showing the item details
                    navigationService.Navigate(App.ItemPageName, portalItem);
                }
                else // check if it is a PortalGroup
                {
                    ArcGISPortalGroup portalGroup = null;
                    // the GridView sends ItemClickEventArgs
                    if (e.GetType() == typeof(ItemClickEventArgs))
                    {
                        portalGroup = ((ItemClickEventArgs)e).ClickedItem as ArcGISPortalGroup;
                    }

                    if (portalGroup != null)
                    {
                        // send clicked item via a message to other ViewModels who
                        // are registered with ChangeGroupSelectedMessage
                        Messenger.Default.Send <ChangeGroupSelectedMessage>(new ChangeGroupSelectedMessage()
                        {
                            Group = portalGroup
                        });
                        //Use the navigation service to navigate to the page showing the item details
                        navigationService.Navigate(App.GroupPageName);
                    }
                }
            });
        }
Пример #36
0
 internal ArcGISPortalItemClickEventArgs(ArcGISPortalItem item)
 {
     m_item = item;
 }
        public SearchViewModel(INavigationService navigationService)
        {
            // initialize ItemClick RelayCommand
            ItemClickCommand = new RelayCommand <object>((e) =>
            {
                // handle the type of EventArgs passed
                ArcGISPortalItem portalItem = null;
                if (e == null)
                {
                    portalItem = null;
                }
                // the GridView sends ItemClickEventArgs
                else if (e is ItemClickEventArgs)
                {
                    portalItem = ((ItemClickEventArgs)e).ClickedItem as ArcGISPortalItem;
                }

                // send clicked item via a message to other ViewModels who
                // are registered with ChangeItemSelectedMessage
                Messenger.Default.Send <ChangeItemSelectedMessage>(new ChangeItemSelectedMessage()
                {
                    Item = portalItem
                });

                //Use the navigation service to navigate to the page showing the item details
                navigationService.Navigate(App.ItemPageName, portalItem);
            });

            // initialize SelectItemCommand RelayCommand
            SelectItemCommand = new RelayCommand <object>((e) =>
            {
                // handle the type of EventArgs passed
                ArcGISPortalItem portalItem = null;
                if (e == null)
                {
                    portalItem = null;
                }

                // the GridView sends SelectionChangedEventArgs
                else if (e.GetType() == typeof(SelectionChangedEventArgs))
                {
                    portalItem = ((SelectionChangedEventArgs)e).AddedItems.FirstOrDefault() as ArcGISPortalItem;
                }

                SelectedPortalItem = portalItem;
                AppViewModel.CurrentAppViewModel.SelectedPortalItem = SelectedPortalItem;
            });

            // initialise SelectSortFieldCommand RelayCommand
            SelectSortFieldCommand = new RelayCommand <object>((obj) =>
            {
                if (obj != null && obj is ComboBoxItem)
                {
                    var content = ((ComboBoxItem)obj).Content;
                    if (content != null)
                    {
                        CurrentSortField = GetCurrentSortField(content.ToString());
                    }
                    SortResults(CurrentSortField);
                }
            });

            // initialise SelectSearchDomainCommand RelayCommand
            SelectSearchDomainCommand = new RelayCommand <object>((obj) =>
            {
                if (obj is ComboBoxItem)
                {
                    var content = ((ComboBoxItem)obj).Content;
                    if (content == null)
                    {
                        return;
                    }
                    var searchDomain = content.ToString();
                    if (string.IsNullOrEmpty(searchDomain))
                    {
                        return;
                    }
                    PortalService.CurrentPortalService.OrganizationResultsOnly = searchDomain == (string)Application.Current.Resources["SearchOrganization"];
                    if (SearchResults != null && SearchResults.IsEmpty)
                    {
                        SearchResults = null;
                    }
                    // refresh search results
                    UpdateResults();
                }
            });
        }
        private void InitializeCommandAndMessages()
        {
            // initialize ItemClick RelayCommand
            ItemClickCommand = new RelayCommand <object>((e) =>
            {
                // handle the type of EventArgs passed
                if (e == null)
                {
                    return;
                }

                ArcGISPortalItem portalItem = null;
                // the GridView sends ItemClickEventArgs
                if (e.GetType() == typeof(ItemClickEventArgs))
                {
                    portalItem = ((ItemClickEventArgs)e).ClickedItem as ArcGISPortalItem;
                }
                // our GalleryPreviewControl sends TileClickEventArgs
                else if (e.GetType() == typeof(TileClickEventArgs))
                {
                    portalItem = ((TileClickEventArgs)e).ClickedTile as ArcGISPortalItem;
                }

                if (portalItem != null)
                {
                    // send clicked item via a message to other ViewModels who
                    // are registered with ChangeItemSelectedMessage
                    Messenger.Default.Send <ChangeItemSelectedMessage>(new ChangeItemSelectedMessage()
                    {
                        Item = portalItem
                    });
                    //Use the navigation service to navigate to the page showing the item details
                    _navigationService.Navigate(App.ItemPageName, portalItem);
                }
                else // check if it is a PortalGroup
                {
                    ArcGISPortalGroup portalGroup = null;
                    // the GridView sends ItemClickEventArgs
                    if (e.GetType() == typeof(ItemClickEventArgs))
                    {
                        portalGroup = ((ItemClickEventArgs)e).ClickedItem as ArcGISPortalGroup;
                    }
                    // our GalleryPreviewControl sends TileClickEventArgs
                    else if (e.GetType() == typeof(TileClickEventArgs))
                    {
                        portalGroup = ((TileClickEventArgs)e).ClickedTile as ArcGISPortalGroup;
                    }

                    if (portalGroup != null)
                    {
                        // send clicked item via a message to other ViewModels who
                        // are registered with ChangeGroupSelectedMessage
                        Messenger.Default.Send <ChangeGroupSelectedMessage>(new ChangeGroupSelectedMessage()
                        {
                            Group = portalGroup
                        });
                        //Use the navigation service to navigate to the page showing the item details
                        _navigationService.Navigate(App.GroupPageName);
                    }
                }
            });

            // initialize MoreClickCommand RelayCommand
            MoreClickCommand = new RelayCommand <object>((objectCollection) =>
            {
                if (objectCollection == null)
                {
                    return;
                }

                //Use the navigation service to navigate to the page showing the specific collection of portal items
                _navigationService.Navigate(App.CollectionPageName, objectCollection);
            });

            // Register with  PopulateDataMessage
            Messenger.Default.Register <PopulateDataMessage>(this, msg => { var _ = PopulateDataAsync(); });

            // Register with ChangedPortalServiceMessage
            Messenger.Default.Register <ChangedPortalServiceMessage>(this, msg => { var _ = PopulateDataAsync(); });
        }
Пример #39
0
 private void Grid_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
 {
     SelectedPortalItem = (sender as FrameworkElement).DataContext as ArcGISPortalItem;
     Frame.Navigate(typeof(MapPage), SelectedPortalItem);
 }
 private void Grid_Tap(object sender, System.Windows.Input.GestureEventArgs e)
 {
     SelectedPortalItem = (sender as FrameworkElement).DataContext as ArcGISPortalItem;
     NavigationService.Navigate(new Uri("/MapPage.xaml", UriKind.Relative));
 }
        // Loads the given webmap
        private async Task LoadWebMapAsync(ArcGISPortalItem portalItem)
        {
            try
            {
                IsBusy = true;

                if (_portal == null)
                    _portal = await ArcGISPortal.CreateAsync();

                var webmap = await WebMap.FromPortalItemAsync(portalItem);
                LoadedPortalItem = portalItem;
                CurrentWebMapVM = await WebMapViewModel.LoadAsync(webmap, _portal);

            }
            catch (Exception ex)
            {
				var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
            finally
            {
                IsBusy = false;
            }
        }
        private void ExecuteOpenMapCommand(ArcGISPortalItem portalItem)
        {
            if (portalItem == null)
            {
                throw new Exception("ArcGIS Portal Item is null or not selected");
            }

            (new NavigationService()).Navigate(App.MapPageName, portalItem);
        }
 public PortalItem(ArcGISPortalItem item)
 {
     ArcGISPortalItem = item;
 }
 private bool CanExecuteOpenMapCommand(ArcGISPortalItem portalItem)
 {
     if (portalItem != null && portalItem.Type == ItemType.WebMap)
         return true;
     return false;
 }        
 public async void CreatePinTile(ArcGISPortalItem portalItem, Rect tileProptRect)
 {
     //string nav = string.Format(@"arcgis://www.arcgis.com/sharing/rest/content/items/{0}/data", portalItem.Id);
     string nav = string.Format(@"arcgis:{0}/sharing/rest/content/items/{1}/data", App.OrganizationUrl, portalItem.Id);
     IsPinningTile = true;
     await TileService.CreateSecondaryTileFromWebImage(portalItem.Title, portalItem.Id,
             portalItem.ThumbnailUri, tileProptRect, nav);
     IsPinningTile = false;
 }
        /// <summary>
        /// Changes used basemap.
        /// </summary>
        /// <param name="item">Item to load</param>
        private async void ChangeBasemap(ArcGISPortalItem item)
        {
            Exception exceptionToHandle =null;
            try
            {
				var webmap = await WebMap.FromPortalItemAsync(item);
				WebMapViewModel = await WebMapViewModel.LoadAsync(webmap, _portal);
			}
            catch (Exception exception)
            {
                exceptionToHandle = exception;
            }

            if (exceptionToHandle != null)
            {
                await MessageService.Instance.ShowMessage(string.Format(
                    "Could not create basemap. Error = {0}", exceptionToHandle.ToString()),
                    "An error occured");
            }
        }
Пример #47
0
        private void ResultList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // clear UI controls
            this.ResetUI();

            // store the currently selected portal item
            this.selectedPortalItem = this.ResultsLIstBox.SelectedItem as ArcGISPortalItem;
            if (this.selectedPortalItem == null) { return; }

            //show the portal item snippet (brief description) in the UI
            if (!string.IsNullOrEmpty(this.selectedPortalItem.Snippet))
            {
                this.SnippetTextBlock.Text = this.selectedPortalItem.Snippet;
            }

            //show a thumbnail for the selected portal item (if there is one)
            if (this.selectedPortalItem.ThumbnailUri != null)
            {
                var src = new BitmapImage(this.selectedPortalItem.ThumbnailUri);
                this.ThumbnailImage.Source = src;
            }

            // enable the show map button when a web map ortal item is chosen
            this.ShowMapButton.IsEnabled = (this.selectedPortalItem.Type == ItemType.WebMap);
        }