示例#1
0
        /// <summary>
        /// Initialize application. Load basemaps from ArcGISPortal and selecte first one.
        /// </summary>
        protected override async Task InitializeAsync()
        {
            Exception exceptionToHandle = null;

            try
            {
                // Store portal instance for later use. Default creates ArcGIS Online portal.
                _portal = await ArcGISPortal.CreateAsync();

                // Get all basemap items that are linked to your portal. Remember that this is dynamic data.
                var items = await _portal.ArcGISPortalInfo.SearchBasemapGalleryAsync();

                Basemaps = new ObservableCollection <ArcGISPortalItem>(items.Results);

                // Load first basemap on initialization
                var webmap = await WebMap.FromPortalItemAsync(Basemaps[0]);

                WebMapViewModel = await WebMapViewModel.LoadAsync(webmap, _portal);

                IsInitialized = true;
            }
            catch (Exception exception)
            {
                exceptionToHandle = exception;
            }

            if (exceptionToHandle != null)
            {
                await MessageService.Instance.ShowMessage(string.Format(
                                                              "Initialization failed. Error = {0}", exceptionToHandle.ToString()),
                                                          "An error occured");
            }
        }
        // Initialize the display with a web map and search portal for basemaps
        private async void mapView_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);
                mapView.Map = _currentVM.Map;

                // Load portal basemaps
                var result = await portal.ArcGISPortalInfo.SearchBasemapGalleryAsync();
                basemapList.ItemsSource = result.Results;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            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;
            }
        }
示例#4
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;
            }
        }
示例#6
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;
        }
        // Switch current maps basemap when the user selects a portal item
        private async void BasemapList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems == null || e.AddedItems.Count <= 0 || progress.Visibility == Visibility.Visible)
            {
                return;
            }

            try
            {
                progress.Visibility = Visibility.Visible;

                var item   = e.AddedItems[0] as ArcGISPortalItem;
                var webmap = await WebMap.FromPortalItemAsync(item);

                var basemapVM = await WebMapViewModel.LoadAsync(webmap, _currentVM.ArcGISPortal);

                _currentVM.Basemap = basemapVM.Basemap;
            }
            catch (Exception ex)
            {
                var _ = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
            finally
            {
                progress.Visibility = Visibility.Collapsed;
            }
        }
        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;
                }
            }
        }
示例#9
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;
            }
        }
示例#10
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;
            }
        }
示例#11
0
        // Loads the given webmap
        private async Task <Map> LoadWebMapAsync(WebMap webmap)
        {
            var portal = await ArcGISPortal.CreateAsync();

            var vm = await WebMapViewModel.LoadAsync(webmap, portal);

            return(vm.Map);
        }
示例#12
0
        private async void MyMapView_Loaded(object sender, RoutedEventArgs e)
        {
            var portal = await ArcGISPortal.CreateAsync();

            _currentVM    = PortalSearch.GetSelectedItem();
            MyMapView.Map = _currentVM.Map;
            var result = await portal.ArcGISPortalInfo.SearchBasemapGalleryAsync();

            basemapList.ItemsSource = result.Results;
        }
        // Loads the given webmap
        private async Task <Map> LoadWebMapAsync(WebMap webmap)
        {
            try
            {
                var portal = await ArcGISPortal.CreateAsync();

                var vm = await WebMapViewModel.LoadAsync(webmap, portal);

                return(vm.Map);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
                return(null);
            }
        }
        private async void ShowMapButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // create a web map from the selected portal item
                var webMap = await WebMap.FromPortalItemAsync(this.SelectedPortalItem);

                // load the web map into a web map view model
                var webMapVM = await WebMapViewModel.LoadAsync(webMap, this.ArcGISOnline);

                // show the web map view model's map in the page's map view control
                this.MyMapView.Map = webMapVM.Map;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private async void ItemButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                BackToResults.IsEnabled = true;

                var item   = ((Button)sender).DataContext as ArcGISPortalItem;
                var webmap = await WebMap.FromPortalItemAsync(item);

                var vm = await WebMapViewModel.LoadAsync(webmap, _portal);

                MyMapView.Map = vm.Map;

                WebmapContent.Visibility = Visibility.Visible;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
        }
示例#16
0
        private async void ItemButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                PortalSearchBottomBar.Visibility = Visibility.Collapsed;
                ResultsListBox.IsEnabled         = false;
                LoadingRing.Visibility           = Visibility.Visible;
                var item   = ((Button)sender).DataContext as ArcGISPortalItem;
                var webmap = await WebMap.FromPortalItemAsync(item);

                SelectedViewModel = await WebMapViewModel.LoadAsync(webmap, _portal);

                HardwareButtons.BackPressed -= HardwareButtons_BackPressed;
                this.Frame.Navigate(typeof(MapPage));
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Error").ShowAsync();
                ResetVisibility();
            }
        }
示例#17
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);
            }
        }
        // Switch current maps basemap when the user selects a portal item
        private async void BaseMapButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                progress.Visibility = Visibility.Visible;

                var item   = ((Button)sender).DataContext as ArcGISPortalItem;
                var webmap = await WebMap.FromPortalItemAsync(item);

                var basemapVM = await WebMapViewModel.LoadAsync(webmap, _currentVM.ArcGISPortal);

                _currentVM.Basemap = basemapVM.Basemap;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            finally
            {
                progress.Visibility = Visibility.Collapsed;
            }
        }
示例#19
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");
            }
        }
        /// <summary>
        /// Initialize application. Load basemaps from ArcGISPortal and selecte first one.
        /// </summary>
        protected override async Task InitializeAsync()
        {
			Exception exceptionToHandle = null;
			try
			{
				// Store portal instance for later use. Default creates ArcGIS Online portal.
				_portal = await ArcGISPortal.CreateAsync();

				// Get all basemap items that are linked to your portal. Remember that this is dynamic data.
				var items = await _portal.ArcGISPortalInfo.SearchBasemapGalleryAsync();
				Basemaps = new ObservableCollection<ArcGISPortalItem>(items.Results);

				// Load first basemap on initialization
				var webmap = await WebMap.FromPortalItemAsync(Basemaps[0]);
				WebMapViewModel = await WebMapViewModel.LoadAsync(webmap, _portal);
				IsInitialized = true;
			}
			catch (Exception exception)
			{
				exceptionToHandle = exception;
			}

			if (exceptionToHandle != null)
			{
				await MessageService.Instance.ShowMessage(string.Format(
					"Initialization failed. Error = {0}", exceptionToHandle.ToString()),
					"An error occured");
			}
        }
        /// <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");
            }
        }
        private async Task <WebMap> UpdateWebMap()
        {
            try
            {
                WebMap = await WebMap.FromPortalItemAsync(PortalItem);

                if (WebMap == null)
                {
                    return(null);
                }

                WebMapVM = await WebMapViewModel.LoadAsync(WebMap, this.PortalItem.ArcGISPortal);

                var errors = WebMapVM.LoadErrors.ToArray();
                if (errors != null && errors.Any())
                {
                    string title   = null;
                    string message = null;
                    if (errors.Count() == 1)
                    {
                        WebMapLayer webMapLayer = errors.First().Key;
                        var         layerName   = webMapLayer.Title ?? webMapLayer.Id ?? webMapLayer.Type;
                        title   = string.Format("Unable to add the layer '{0}' in the map.", layerName);
                        message = errors.First().Value.Message;
                    }
                    else
                    {
                        title = string.Format("Unable to add {0} layers in the map.", errors.Count());
                        foreach (KeyValuePair <WebMapLayer, Exception> error in errors)
                        {
                            WebMapLayer webMapLayer = error.Key;
                            var         layerName   = webMapLayer.Title ?? webMapLayer.Id ?? webMapLayer.Type;
                            message += layerName + ":  " + error.Value.Message + Environment.NewLine;
                        }
                    }
                    var ex = new Exception(message);
                    var _  = App.ShowExceptionDialog(ex, title);
                }

                // <start workaround>
                // This is work around for WebMapViewModel because OutFields is not being set
                // on the GeodatabaseFeatureServiceTable in the API this will be fixed after Beta.
                foreach (var featureLayer in OperationalLayers.OfType <FeatureLayer>())
                {
                    var webMapLayer = WebMap.OperationalLayers.FirstOrDefault(wml => wml.Id == featureLayer.ID);
                    if (webMapLayer != null && webMapLayer.PopupInfo != null && webMapLayer.PopupInfo.FieldInfos != null && webMapLayer.PopupInfo.FieldInfos.Any())
                    {
                        var geodatabaseFeatureServiceTable = featureLayer.FeatureTable as GeodatabaseFeatureServiceTable;
                        if (geodatabaseFeatureServiceTable != null && geodatabaseFeatureServiceTable.OutFields == null)
                        {
                            geodatabaseFeatureServiceTable.OutFields = new OutFields(webMapLayer.PopupInfo.FieldInfos.Where(f => f != null).Select(f => f.FieldName));
                            geodatabaseFeatureServiceTable.RefreshFeatures(false);
                        }
                    }
                }
                // <end workaround>
            }
            catch (Exception ex)
            {
                var _ = App.ShowExceptionDialog(ex, "An exception was caught while trying to open the map.");
            }

            return(WebMap);
        }
        /// <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();
            }
        }