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 { // 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); } }