@@ -30,55 +30,103 @@ namespace ArcGIS.Samples.OfflineBasemapByReference
3030 description : "Use the `OfflineMapTask` to take a web map offline, but instead of downloading an online basemap, use one which is already on the device." ,
3131 instructions : "1. Use the button to start taking the map offline." ,
3232 tags : new [ ] { "basemap" , "download" , "local" , "offline" , "save" , "web map" } ) ]
33- [ ArcGIS . Samples . Shared . Attributes . OfflineData ( "628e8e3521cf45e9a28a12fe10c02c4d " ) ]
33+ [ ArcGIS . Samples . Shared . Attributes . OfflineData ( "85282f2aaa2844d8935cdb8722e22a93 " ) ]
3434 public partial class OfflineBasemapByReference : ContentPage
3535 {
36- // The job to generate an offline map.
37- private GenerateOfflineMapJob _generateOfflineMapJob ;
36+ // The ID for a web map item hosted on ArcGIS Online (water network map of Naperville IL).
37+ private const string WebMapId = "acc027394bc84c2fb04d1ed317aac674" ;
38+
39+ // The ID for the offline basemap tile package hosted on ArcGIS Online.
40+ private const string BasemapDataId = "85282f2aaa2844d8935cdb8722e22a93" ;
41+
42+ // The filename of the local basemap tile package.
43+ private const string BasemapFilename = "naperville_imagery.tpkx" ;
3844
3945 // The extent of the data to take offline.
4046 private readonly Envelope _areaOfInterest = new Envelope ( - 88.1541 , 41.7690 , - 88.1471 , 41.7720 , SpatialReferences . Wgs84 ) ;
4147
42- // The ID for a web map item hosted on the server (water network map of Naperville IL).
43- private const string WebMapId = "acc027394bc84c2fb04d1ed317aac674" ;
48+ // The job to generate an offline map.
49+ private GenerateOfflineMapJob _generateOfflineMapJob ;
50+
51+ // Task completion source for basemap choice dialog.
52+ private TaskCompletionSource < string > _basemapChoiceCompletion ;
4453
4554 public OfflineBasemapByReference ( )
4655 {
4756 InitializeComponent ( ) ;
4857 _ = Initialize ( ) ;
4958 }
5059
51- private async Task ConfigureOfflineJobForBasemap ( GenerateOfflineMapParameters parameters )
60+ private async Task < bool > ConfigureOfflineJobForBasemap ( GenerateOfflineMapParameters parameters )
5261 {
53- // Don't give the user a choice if there is no basemap specified.
54- if ( String . IsNullOrWhiteSpace ( parameters . ReferenceBasemapFilename ) )
62+ // Get the path to the basemap directory.
63+ string basemapBasePath = DataManager . GetDataFolder ( BasemapDataId ) ;
64+
65+ // Set the reference basemap filename if not already configured.
66+ if ( string . IsNullOrWhiteSpace ( parameters . ReferenceBasemapFilename ) )
5567 {
56- return ;
68+ parameters . ReferenceBasemapFilename = BasemapFilename ;
5769 }
5870
59- // Get the path to the basemap directory.
60- string basemapBasePath = DataManager . GetDataFolder ( "85282f2aaa2844d8935cdb8722e22a93" ) ;
61-
62- // Get the full path to the basemap by combining the name specified in the web map (ReferenceBasemapFilename)
63- // with the offline basemap directory.
71+ // Get the full path to the basemap.
6472 string basemapFullPath = Path . Combine ( basemapBasePath , parameters . ReferenceBasemapFilename ) ;
6573
6674 // If the offline basemap doesn't exist, proceed without it.
6775 if ( ! File . Exists ( basemapFullPath ) )
6876 {
69- return ;
77+ return true ;
7078 }
7179
72- // Wait for the user to choose whether to use the offline basemap .
73- bool useBasemap = await Application . Current . Windows [ 0 ] . Page . DisplayAlert ( "Basemap choice" , "Use the offline basemap?" , "Yes" , "No" ) ;
80+ // Show the dialog and wait for user choice .
81+ string choice = await ShowBasemapChoiceDialog ( parameters . ReferenceBasemapFilename ) ;
7482
75- if ( useBasemap )
83+ switch ( choice )
7684 {
77- // Configure the offline basemap if the user said yes.
78- parameters . ReferenceBasemapDirectory = basemapBasePath ;
85+ case "UseLocal" :
86+ parameters . ReferenceBasemapDirectory = basemapBasePath ;
87+ return true ;
88+
89+ case "Download" :
90+ return true ;
91+
92+ default :
93+ return false ;
7994 }
8095 }
8196
97+ private async Task < string > ShowBasemapChoiceDialog ( string basemapFilename )
98+ {
99+ // Update the message with the basemap filename.
100+ BasemapChoiceMessage . Text = $ "This web map references a local basemap '{ basemapFilename } '.\n \n You can use the basemap already on disk or download the basemap again.";
101+
102+ BasemapChoicePanel . IsVisible = true ;
103+
104+ // Show the dialog and wait for user choice.
105+ _basemapChoiceCompletion = new TaskCompletionSource < string > ( ) ;
106+
107+ string choice = await _basemapChoiceCompletion . Task ;
108+
109+ // Hide dialog.
110+ BasemapChoicePanel . IsVisible = false ;
111+
112+ return choice ;
113+ }
114+
115+ private void UseLocalBasemapButton_Click ( object sender , EventArgs e )
116+ {
117+ _basemapChoiceCompletion ? . TrySetResult ( "UseLocal" ) ;
118+ }
119+
120+ private void DownloadBasemapButton_Click ( object sender , EventArgs e )
121+ {
122+ _basemapChoiceCompletion ? . TrySetResult ( "Download" ) ;
123+ }
124+
125+ private void CancelBasemapChoiceButton_Click ( object sender , EventArgs e )
126+ {
127+ _basemapChoiceCompletion ? . TrySetResult ( "Cancel" ) ;
128+ }
129+
82130 // Note: all code below (except call to ConfigureOfflineJobForBasemap) is identical to code in the Generate offline map sample.
83131
84132 #region Generate offline map
@@ -160,17 +208,23 @@ private async void TakeMapOfflineButton_Click(object sender, EventArgs e)
160208
161209 try
162210 {
163- // Show the progress indicator while the job is running.
164- BusyIndicator . IsVisible = true ;
165-
166211 // Create an offline map task with the current (online) map.
167212 OfflineMapTask takeMapOfflineTask = await OfflineMapTask . CreateAsync ( MyMapView . Map ) ;
168213
169214 // Create the default parameters for the task, pass in the area of interest.
170215 GenerateOfflineMapParameters parameters = await takeMapOfflineTask . CreateDefaultGenerateOfflineMapParametersAsync ( _areaOfInterest ) ;
171216
172217 // Configure basemap settings for the job.
173- await ConfigureOfflineJobForBasemap ( parameters ) ;
218+ bool proceed = await ConfigureOfflineJobForBasemap ( parameters ) ;
219+
220+ // Exit if user cancelled.
221+ if ( ! proceed )
222+ {
223+ return ;
224+ }
225+
226+ // Show the progress indicator while the job is running.
227+ BusyIndicator . IsVisible = true ;
174228
175229 // Create the job with the parameters and output location.
176230 _generateOfflineMapJob = takeMapOfflineTask . GenerateOfflineMap ( parameters , packagePath ) ;
@@ -212,7 +266,7 @@ private async void TakeMapOfflineButton_Click(object sender, EventArgs e)
212266 // Enable map interaction so the user can explore the offline data.
213267 MyMapView . InteractionOptions . IsEnabled = true ;
214268
215- // Hide the "Take map offline" button .
269+ // Disable the button since map is now offline .
216270 TakeMapOfflineButton . IsEnabled = false ;
217271
218272 // Show a message that the map is offline.
0 commit comments