private async void Initialize()
        {
            try
            {
                // Get the offline data folder.
                _offlineDataFolder = Path.Combine(GetDataFolder(),
                                                  "SampleData", "DownloadPreplannedMapAreas");

                // If the temporary data folder doesn't exist, create it.
                if (!Directory.Exists(_offlineDataFolder))
                {
                    Directory.CreateDirectory(_offlineDataFolder);
                }

                // Create a portal that contains the portal item.
                ArcGISPortal portal = await ArcGISPortal.CreateAsync();

                // Create the webmap based on the id.
                PortalItem webmapItem = await PortalItem.CreateAsync(portal, PortalItemId);

                // Create the offline task and load it.
                _offlineMapTask = await OfflineMapTask.CreateAsync(webmapItem);

                // Query related preplanned areas.
                IReadOnlyList <PreplannedMapArea> preplannedAreas = await _offlineMapTask.GetPreplannedMapAreasAsync();

                // Load each preplanned map area and add it to the flyout list.
                foreach (PreplannedMapArea area in preplannedAreas)
                {
                    await area.LoadAsync();

                    // Add item to the flyout list (for mobile).
                    MenuFlyoutItem menuItem = new MenuFlyoutItem {
                        Text = area.PortalItem.Title, DataContext = area
                    };
                    menuItem.Click += OnMenuDownloadMapAreaClicked;
                    MapAreaFlyout.Items?.Add(menuItem);
                }

                // Show the areas in the UI. The code to make this look nice in the UI is defined
                //    in the ListView's ItemTemplate in the XAML.
                PreplannedAreasList.ItemsSource = preplannedAreas;

                // Remove loading indicators from UI.
                DownloadNotificationText.Visibility = Visibility.Visible;
                BusyIndicator.Visibility            = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                // Something unexpected happened, show the error message.
                MessageDialog message = new MessageDialog(ex.Message, "An error occurred");
                await message.ShowAsync();
            }
        }
        private async void Initialize()
        {
            try
            {
                // The data manager provides a method to get a suitable offline data folder.
                _offlineDataFolder = Path.Combine(DataManager.GetDataFolder(), "SampleData", "DownloadPreplannedMapAreas");

                // If temporary data folder doesn't exists, create it.
                if (!Directory.Exists(_offlineDataFolder))
                {
                    Directory.CreateDirectory(_offlineDataFolder);
                }

                // Create a portal to enable access to the portal item.
                ArcGISPortal portal = await ArcGISPortal.CreateAsync();

                // Create the portal item from the portal item ID.
                PortalItem webMapItem = await PortalItem.CreateAsync(portal, PortalItemId);

                // Show the map.
                _originalMap   = new Map(webMapItem);
                _myMapView.Map = _originalMap;

                // Create an offline map task for the web map item.
                _offlineMapTask = await OfflineMapTask.CreateAsync(webMapItem);

                // Find the available preplanned map areas.
                IReadOnlyList <PreplannedMapArea> preplannedAreas = await _offlineMapTask.GetPreplannedMapAreasAsync();

                // Load each item, then add it to the list of areas.
                foreach (PreplannedMapArea area in preplannedAreas)
                {
                    await area.LoadAsync();

                    _mapAreas.Add(area);
                }

                // Configure the table view for showing map areas.
                _mapAreaViewModel              = new MapAreaViewModel(_mapAreas);
                _mapAreaViewModel.MapSelected += _mapAreaViewModel_MapSelected;

                _tableController = new UITableViewController(UITableViewStyle.Plain);
                _tableController.TableView.Source = _mapAreaViewModel;

                // Hide the loading indicator.
                _activityIndicator.StopAnimating();
            }
            catch (Exception ex)
            {
                // Something unexpected happened, show the error message.
                Debug.WriteLine(ex);
                new UIAlertView("There was an error", ex.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show();
            }
        }
        private async void Initialize()
        {
            try
            {
                // The data manager provides a method to get a suitable offline data folder.
                _offlineDataFolder = Path.Combine(DataManager.GetDataFolder(), "SampleData", "DownloadPreplannedMapAreas");



                // If temporary data folder doesn't exists, create it.
                if (!Directory.Exists(_offlineDataFolder))
                {
                    Directory.CreateDirectory(_offlineDataFolder);
                }

                // Create a portal to enable access to the portal item.
                ArcGISPortal portal = await ArcGISPortal.CreateAsync();

                // Create the portal item from the portal item ID.
                PortalItem webMapItem = await PortalItem.CreateAsync(portal, PortalItemId);

                // Show the map.
                _originalMap   = new Map(webMapItem);
                _myMapView.Map = _originalMap;

                // Create an offline map task for the web map item.
                _offlineMapTask = await OfflineMapTask.CreateAsync(webMapItem);

                // Find the available preplanned map areas.
                IReadOnlyList <PreplannedMapArea> preplannedAreas = await _offlineMapTask.GetPreplannedMapAreasAsync();

                // Load each item, then add it to the list of areas.
                foreach (PreplannedMapArea area in preplannedAreas)
                {
                    await area.LoadAsync();

                    _mapAreas.Add(area);
                }

                // Show the map areas in the UI.
                ConfigureMapsButtons();

                // Hide the loading indicator.
                _progressView.Dismiss();
            }
            catch (Exception ex)
            {
                // Something unexpected happened, show the error message.
                Debug.WriteLine(ex);
                new AlertDialog.Builder(this).SetMessage(ex.ToString()).SetTitle("There was an error.").Show();
            }
        }
        private async void Initialize()
        {
            try
            {
                // Close the current mobile package when the sample closes.
                Unloaded += (s, e) => { _mobileMapPackage?.Close(); };

                // The data manager provides a method to get a suitable offline data folder.
                _offlineDataFolder = Path.Combine(DataManager.GetDataFolder(), "SampleData", "DownloadPreplannedMapAreas");

                // If temporary data folder doesn't exists, create it.
                if (!Directory.Exists(_offlineDataFolder))
                {
                    Directory.CreateDirectory(_offlineDataFolder);
                }

                // Create a portal to enable access to the portal item.
                ArcGISPortal portal = await ArcGISPortal.CreateAsync();

                // Create the portal item from the portal item ID.
                PortalItem webMapItem = await PortalItem.CreateAsync(portal, PortalItemId);

                // Show the map.
                _originalMap  = new Map(webMapItem);
                MyMapView.Map = _originalMap;

                // Create an offline map task for the web map item.
                _offlineMapTask = await OfflineMapTask.CreateAsync(webMapItem);

                // Find the available preplanned map areas.
                IReadOnlyList <PreplannedMapArea> preplannedAreas = await _offlineMapTask.GetPreplannedMapAreasAsync();

                // Load each item, then add it to the UI.
                foreach (PreplannedMapArea area in preplannedAreas)
                {
                    await area.LoadAsync();

                    AreasList.Items.Add(area);
                }

                // Hide the loading indicator.
                BusyIndicator.Visibility = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                // Something unexpected happened, show the error message.
                Debug.WriteLine(ex);
                await new MessageDialog(ex.Message, "There was an error.").ShowAsync();
            }
        }
        private async void Initialize()
        {
            try
            {
                // The data manager provides a method to get a suitable offline data folder.
                _offlineDataFolder = Path.Combine(DataManager.GetDataFolder(), "SampleData", "DownloadPreplannedMapAreas");

                // If temporary data folder doesn't exists, create it.
                if (!Directory.Exists(_offlineDataFolder))
                {
                    Directory.CreateDirectory(_offlineDataFolder);
                }

                // Create a portal to enable access to the portal item.
                ArcGISPortal portal = await ArcGISPortal.CreateAsync();

                // Create the portal item from the portal item ID.
                PortalItem webMapItem = await PortalItem.CreateAsync(portal, PortalItemId);

                // Show the map.
                _originalMap  = new Map(webMapItem);
                MyMapView.Map = _originalMap;

                // Create an offline map task for the web map item.
                _offlineMapTask = await OfflineMapTask.CreateAsync(webMapItem);

                // Find the available preplanned map areas.
                IReadOnlyList <PreplannedMapArea> preplannedAreas = await _offlineMapTask.GetPreplannedMapAreasAsync();

                // Load each item, then add it to the list of areas.
                foreach (PreplannedMapArea area in preplannedAreas)
                {
                    await area.LoadAsync();

                    _mapAreas.Add(area);
                }

                // Show the map areas in the UI.
                AreasList.ItemsSource = _mapAreas;

                // Hide the loading indicator.
                BusyIndicator.IsVisible = false;
            }
            catch (Exception ex)
            {
                // Something unexpected happened, show the error message.
                Debug.WriteLine(ex);
                await Application.Current.MainPage.DisplayAlert("There was an error.", ex.Message, "OK");
            }
        }
        private async void Initialize()
        {
            try
            {
                // Show a loading indicator.
                View.AddSubview(_progressIndicator);
                _progressIndicator.UpdateMessageAndProgress("Loading list of available map areas.", -1);

                // Get the offline data folder.
                _offlineDataFolder = Path.Combine(GetDataFolder(),
                                                  "SampleData", "DownloadPreplannedMapAreas");

                // If the temporary data folder doesn't exist, create it.
                if (!Directory.Exists(_offlineDataFolder))
                {
                    Directory.CreateDirectory(_offlineDataFolder);
                }

                // Create a portal that contains the portal item.
                ArcGISPortal portal = await ArcGISPortal.CreateAsync();

                // Create the webmap based on the id.
                PortalItem webmapItem = await PortalItem.CreateAsync(portal, PortalItemId);

                // Create the offline map task and load it.
                _offlineMapTask = await OfflineMapTask.CreateAsync(webmapItem);

                // Query related preplanned areas.
                _preplannedMapAreas = await _offlineMapTask.GetPreplannedMapAreasAsync();

                // Load each preplanned map area.
                foreach (var area in _preplannedMapAreas)
                {
                    await area.LoadAsync();
                }

                // Show a popup menu of available areas when the download button is clicked.
                _downloadButton.TouchUpInside += DownloadButton_Click;

                // Remove loading indicators from UI.
                _progressIndicator.RemoveFromSuperview();
            }
            catch (Exception ex)
            {
                // Something unexpected happened, show the error message.
                UIAlertController alertController = UIAlertController.Create("An error occurred.", ex.Message, UIAlertControllerStyle.Alert);
                alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
                PresentViewController(alertController, true, null);
            }
        }
        private async void Initialize()
        {
            try
            {
                // Get the offline data folder.
                _offlineDataFolder = Path.Combine(GetDataFolder(),
                                                  "SampleData", "DownloadPreplannedMapAreas");

                // If the temporary data folder doesn't exist, create it.
                if (!Directory.Exists(_offlineDataFolder))
                {
                    Directory.CreateDirectory(_offlineDataFolder);
                }

                // Create a portal that contains the portal item.
                ArcGISPortal portal = await ArcGISPortal.CreateAsync();

                // Create webmap based on the ID.
                PortalItem webmapItem = await PortalItem.CreateAsync(portal, PortalItemId);

                // Create the offline map task and load it.
                _offlineMapTask = await OfflineMapTask.CreateAsync(webmapItem);

                // Query related preplanned areas.
                IReadOnlyList <PreplannedMapArea> preplannedAreas = await _offlineMapTask.GetPreplannedMapAreasAsync();

                // Load each preplanned map area.
                foreach (PreplannedMapArea area in preplannedAreas)
                {
                    await area.LoadAsync();
                }

                // Show the areas in the UI.
                PreplannedAreasList.ItemsSource = preplannedAreas;

                // Remove loading indicators from UI.
                BusyIndicator.IsVisible = false;
            }
            catch (Exception ex)
            {
                // Something unexpected happened, show the error message.
                await((Page)Parent).DisplayAlert("An error occurred", ex.Message, "OK");
            }
        }
        private async void Initialize()
        {
            try
            {
                // Show a loading indicator.
                View.AddSubview(_progressIndicator);
                _progressIndicator.UpdateMessageAndProgress("Loading list of available map areas.", -1);

                // Get the offline data folder.
                _offlineDataFolder = Path.Combine(GetDataFolder(),
                                                  "SampleData", "DownloadPreplannedMapAreas");

                // If the temporary data folder doesn't exist, create it.
                if (!Directory.Exists(_offlineDataFolder))
                {
                    Directory.CreateDirectory(_offlineDataFolder);
                }

                // Create a portal that contains the portal item.
                ArcGISPortal portal = await ArcGISPortal.CreateAsync();

                // Create the webmap based on the id.
                PortalItem webmapItem = await PortalItem.CreateAsync(portal, PortalItemId);

                // Create the offline map task and load it.
                _offlineMapTask = await OfflineMapTask.CreateAsync(webmapItem);

                // Query related preplanned areas.
                _preplannedMapAreas = await _offlineMapTask.GetPreplannedMapAreasAsync();

                // Load each preplanned map area.
                foreach (var area in _preplannedMapAreas)
                {
                    await area.LoadAsync();
                }

                // Show a popup menu of available areas when the download button is clicked.
                _downloadButton.TouchUpInside += (s, e) =>
                {
                    // Create the alert controller.
                    UIAlertController mapAreaSelectionAlertController = UIAlertController.Create("Map Area Selection",
                                                                                                 "Select a map area to download and show.", UIAlertControllerStyle.ActionSheet);

                    // Add one action per map area.
                    foreach (PreplannedMapArea area in _preplannedMapAreas)
                    {
                        mapAreaSelectionAlertController.AddAction(UIAlertAction.Create(area.PortalItem.Title, UIAlertActionStyle.Default,
                                                                                       action =>
                        {
                            // Download and show the selected map area.
                            OnDownloadMapAreaClicked(action.Title);
                        }));
                    }

                    // Needed to prevent a crash on iPad.
                    UIPopoverPresentationController presentationPopover = mapAreaSelectionAlertController.PopoverPresentationController;
                    if (presentationPopover != null)
                    {
                        presentationPopover.SourceView = View;
                        presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Up;
                    }

                    // Display the alert.
                    PresentViewController(mapAreaSelectionAlertController, true, null);

                    // Remove the startup prompt if it hasn't been removed already.
                    if (_initialPrompt != null)
                    {
                        _initialPrompt.RemoveFromSuperview();
                        _initialPrompt = null;
                    }
                };

                // Remove loading indicators from UI.
                _progressIndicator.RemoveFromSuperview();
            }
            catch (Exception ex)
            {
                // Something unexpected happened, show the error message.
                UIAlertController alertController = UIAlertController.Create("An error occurred.", ex.Message, UIAlertControllerStyle.Alert);
                alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
                PresentViewController(alertController, true, null);
            }
        }
        private async void GeneratePreplannedMap()
        {
            ArcGISPortal portal = await ArcGISPortal.CreateAsync();

            string itemID = "a9081e4d02dc49f68c6202f03bfe302f";

            // Get a web map item using its ID.
            PortalItem webmapItem = await PortalItem.CreateAsync(portal, itemID);

            // Create a map from the web map item.
            Map onlineMap = new Map(webmapItem);

            // Create an OfflineMapTask from the map ...
            OfflineMapTask takeMapOfflineTask = await OfflineMapTask.CreateAsync(onlineMap);

            // ... or a web map portal item.
            //takeMapOfflineTask = await OfflineMapTask.CreateAsync(webmapItem);

            // Get a list of the available preplanned map areas.
            IReadOnlyList <PreplannedMapArea> preplannedMapAreaList = await takeMapOfflineTask.GetPreplannedMapAreasAsync();

            // Loop through all preplanned map areas.
            foreach (PreplannedMapArea mapArea in preplannedMapAreaList)
            {
                // Load the preplanned map area so property values can be read.
                await mapArea.LoadAsync();

                // Get the area of interest (geometry) for this area.
                Geometry aoi = mapArea.AreaOfInterest;

                // Get the portal item for this area, read the title and thumbnail image.
                PortalItem   preplannedMapItem = mapArea.PortalItem;
                string       mapTitle          = preplannedMapItem.Title;
                RuntimeImage areaThumbnail     = preplannedMapItem.Thumbnail;
            }


            PreplannedMapArea downloadMapArea = preplannedMapAreaList.First();

            string pathToOutputPackage = @"C:\LaurenCDrive\TL\Readiness\Trainings\RT_Offline_Workflows\PrePlannedMap";

            DownloadPreplannedOfflineMapJob preplannedMapJob = takeMapOfflineTask.DownloadPreplannedOfflineMap(downloadMapArea, pathToOutputPackage);

            // Generate the offline map and download it.
            DownloadPreplannedOfflineMapResult preplannedMapResult = await preplannedMapJob.GetResultAsync();

            if (!preplannedMapResult.HasErrors)
            {
                // Job completed successfully and all content was generated.
                Debug.WriteLine("Map " +
                                preplannedMapResult.MobileMapPackage.Item.Title +
                                " was saved to " +
                                preplannedMapResult.MobileMapPackage.Path);

                // Show the offline map in a MapView.
                MyMapView.Map = preplannedMapResult.OfflineMap;
            }
            else
            {
                // Job is finished but one or more layers or tables had errors.
                if (preplannedMapResult.LayerErrors.Count > 0)
                {
                    // Show layer errors.
                    foreach (var layerError in preplannedMapResult.LayerErrors)
                    {
                        Debug.WriteLine("Error occurred when taking " +
                                        layerError.Key.Name +
                                        " offline. Error : " +
                                        layerError.Value.Message);
                    }
                }
                if (preplannedMapResult.TableErrors.Count > 0)
                {
                    // Show table errors.
                    foreach (var tableError in preplannedMapResult.TableErrors)
                    {
                        Debug.WriteLine("Error occurred when taking " +
                                        tableError.Key.TableName +
                                        " offline. Error : " +
                                        tableError.Value.Message);
                    }
                }
            }
        }
Пример #10
0
        private async void Initialize()
        {
            try
            {
                // Show a loading indicator.
                _progressIndicator.SetTitle("Loading");
                _progressIndicator.SetMessage("Loading the available map areas.");
                _progressIndicator.SetCancelable(false);
                _progressIndicator.Show();

                // Get the offline data folder.
                _offlineDataFolder = Path.Combine(GetDataFolder(),
                                                  "SampleData", "DownloadPreplannedMapAreas");

                // If the temporary data folder doesn't exist, create it.
                if (!Directory.Exists(_offlineDataFolder))
                {
                    Directory.CreateDirectory(_offlineDataFolder);
                }

                // Create a portal that contains the portal item.
                ArcGISPortal portal = await ArcGISPortal.CreateAsync();

                // Create a webmap based on the id.
                PortalItem webmapItem = await PortalItem.CreateAsync(portal, PortalItemId);

                // Create the offline task and load it.
                _offlineMapTask = await OfflineMapTask.CreateAsync(webmapItem);

                // Query related preplanned areas.
                _preplannedMapAreas = await _offlineMapTask.GetPreplannedMapAreasAsync();

                // Load each preplanned map area.
                foreach (PreplannedMapArea area in _preplannedMapAreas)
                {
                    await area.LoadAsync();
                }

                // Show a popup menu of available areas when the download button is clicked.
                _downloadButton.Click += (s, e) =>
                {
                    // Create a menu to show the available map areas.
                    PopupMenu areaMenu = new PopupMenu(this, _downloadButton);
                    areaMenu.MenuItemClick += (sndr, evt) =>
                    {
                        // Get the name of the selected area.
                        string selectedArea = evt.Item.TitleCondensedFormatted.ToString();

                        // Download and show the map.
                        OnDownloadMapAreaClicked(selectedArea);
                    };

                    // Create the menu options.
                    foreach (PreplannedMapArea area in _preplannedMapAreas)
                    {
                        areaMenu.Menu.Add(area.PortalItem.Title.ToString());
                    }

                    // Show the menu in the view.
                    areaMenu.Show();
                };

                // Remove loading indicators from the UI.
                _progressIndicator.Dismiss();
            }
            catch (Exception ex)
            {
                // Something unexpected happened, show error message.
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.SetMessage(ex.Message).SetTitle("An error occurred").Show();
            }
        }