protected void LoadSections() { this.Root.Clear (); List<Section> sections = new List<Section> (10); sections.Add (new Section ("Browse Available Maps") { new StyledStringElement("Browse Continents", () => { SKMapUtilOfflineMapInfoViewController vc = new SKMapUtilOfflineMapInfoViewController(OfflineMapInfo.World); this.NavigationController.PushViewController(vc, true); }), new StyledStringElement("Search Countries/States", () => { SKMapUtilOfflineMapSearchViewController vc = new SKMapUtilOfflineMapSearchViewController((OfflineMapInfo.PackageType packageType) => { return packageType != OfflineMapInfo.PackageType.City; }); this.NavigationController.PushViewController(vc, true); }), new StyledStringElement("Search Cities", () => { SKMapUtilOfflineMapSearchViewController vc = new SKMapUtilOfflineMapSearchViewController((OfflineMapInfo.PackageType packageType) => { return packageType == OfflineMapInfo.PackageType.City; }); this.NavigationController.PushViewController(vc, true); }), }); // TODO: Drive based on location from device... CLLocationCoordinate2D nearby = new CLLocationCoordinate2D (0, -80); this._nearbyMapsSection = new NearbyOfflineMapsSection (this, nearby); this._installedMapsSection = new InstalledMapsSection (this); sections.Add( this._nearbyMapsSection ); sections.Add (this._installedMapsSection); this.Root.Add (sections); }
protected async void CellTapped() { Console.WriteLine ("Selected {0}", this._mapInfo.LocalizedName); switch (this._mapInfo.State) { case OfflineMapInfo.PackageState.NotInstalled: { if (this._mapInfo.children.Count > 0) { SKMapUtilOfflineMapInfoViewController vc = new SKMapUtilOfflineMapInfoViewController (this._mapInfo); this.ParentVC.NavigationController.PushViewController (vc, true); } else { string message = string.Format ("Would you like to install {0}?", this._mapInfo.LocalizedName); nint button = await DialogExtensions.ShowAlertAsync ("", message, "OK", "Cancel"); if (button == 0) { this._mapInfo.DownloadAndInstallPackage (); } } break; } case OfflineMapInfo.PackageState.Installing: { string message = string.Format ("Would you like to cancel installation of {0}?", this._mapInfo.LocalizedName); nint button = await DialogExtensions.ShowAlertAsync ("", message, "OK", "Cancel"); if (button == 0) { this._mapInfo.CancelInstall (); } break; } case OfflineMapInfo.PackageState.Installed: { string message = string.Format ("Would you like to uninstall {0}?", this._mapInfo.LocalizedName); nint button = await DialogExtensions.ShowAlertAsync ("", message, "OK", "Cancel"); if (button == 0) { bool uninstalled = this._mapInfo.UninstallMapPackage (); Console.WriteLine ("{0} - uninstalled map {1}", uninstalled, this._mapInfo.LocalizedName); } break; } case OfflineMapInfo.PackageState.InstallError: { string message = string.Format ("There was an error installing the map {0}. Would you like to try again?", this._mapInfo.LocalizedName); nint button = await DialogExtensions.ShowAlertAsync ("", message, "OK", "Error Details", "Cancel"); if (button == 0) { this._mapInfo.DownloadAndInstallPackage (); } else if (button == 1) { string errordetails; if (this._mapInfo.LastError is System.Net.WebException) { System.Net.WebException webError = this._mapInfo.LastError as System.Net.WebException; errordetails = string.Format ("Network Error: {0}. Check your internet connection and try again.\n\n{1}", webError.Status.ToString(), this._mapInfo.LastError.StackTrace); } else { errordetails = string.Format ("{0}\n\n{1}", this._mapInfo.LastError.Message, this._mapInfo.LastError.StackTrace); } DialogExtensions.ShowAlert ("", errordetails, "OK"); } else { this._mapInfo.SetState (OfflineMapInfo.PackageState.NotInstalled); } break; } case OfflineMapInfo.PackageState.InstallCancelled: { string message = string.Format ("Would you like to install {0}?", this._mapInfo.LocalizedName); nint button = await DialogExtensions.ShowAlertAsync ("", message, "OK", "Cancel"); if (button == 0) { this._mapInfo.DownloadAndInstallPackage (); } else { this._mapInfo.SetState (OfflineMapInfo.PackageState.NotInstalled); } break; } } }