@@ -66,6 +66,10 @@ class MainActivity : AppCompatActivity() {
6666 activityMainBinding.mapView
6767 }
6868
69+ private val previewMapView by lazy {
70+ activityMainBinding.previewMapView
71+ }
72+
6973 private val exportVectorTilesButton: Button by lazy {
7074 activityMainBinding.exportVectorTilesButton
7175 }
@@ -82,6 +86,7 @@ class MainActivity : AppCompatActivity() {
8286 ArcGISEnvironment .apiKey = ApiKey .create(BuildConfig .API_KEY )
8387 // add mapView to the lifecycle
8488 lifecycle.addObserver(mapView)
89+ lifecycle.addObserver(previewMapView)
8590
8691 // create a graphic to show a red outline square around the vector tiles to be downloaded
8792 downloadArea.symbol = SimpleLineSymbol (SimpleLineSymbolStyle .Solid , Color .red, 2F )
@@ -130,7 +135,7 @@ class MainActivity : AppCompatActivity() {
130135 val exportVectorTilesTask = ExportVectorTilesTask (vectorTiledLayer.uri.toString())
131136 val geometry = (downloadArea.geometry)
132137 if (geometry == null ) {
133- showError (" Error retrieving download area geometry" )
138+ showMessage (" Error retrieving download area geometry" )
134139 return @launch
135140 }
136141 // set the parameters of the export vector tiles task
@@ -142,7 +147,7 @@ class MainActivity : AppCompatActivity() {
142147
143148 // get the loaded vector tile parameters
144149 val exportVectorTilesParameters = exportVectorTilesParametersResult.getOrElse {
145- showError (it.message.toString())
150+ showMessage (it.message.toString())
146151 } as ExportVectorTilesParameters
147152
148153 if (isJobFinished) {
@@ -152,7 +157,7 @@ class MainActivity : AppCompatActivity() {
152157 exportVectorTilesTask
153158 )
154159 } else {
155- showError (" Previous job is cancelling asynchronously" )
160+ showMessage (" Previous job is cancelling asynchronously" )
156161 }
157162 }
158163
@@ -205,9 +210,15 @@ class MainActivity : AppCompatActivity() {
205210 exportVectorTilesJob.result().onSuccess {
206211 // display the map preview using the result from the completed job
207212 showMapPreview(it)
213+ // set job is completed
208214 isJobFinished = true
215+ // display the path of the saved vector tiles
216+ showMessage(it.vectorTileCache?.path.toString())
217+ // dismiss loading dialog
218+ dialog?.dismiss()
209219 }.onFailure {
210- showError(it.message.toString())
220+ showMessage(it.message.toString())
221+ dialog?.dismiss()
211222 }
212223 }
213224
@@ -234,10 +245,10 @@ class MainActivity : AppCompatActivity() {
234245 // use the points to define and return an envelope
235246 downloadArea.geometry = Envelope (minPoint, maxPoint)
236247 } else {
237- showError (" Error getting screen coordinate" )
248+ showMessage (" Error getting screen coordinate" )
238249 }
239250 }?.onFailure {
240- showError (it.message.toString())
251+ showMessage (it.message.toString())
241252 }
242253 }
243254
@@ -252,7 +263,7 @@ class MainActivity : AppCompatActivity() {
252263 lifecycleScope.launch {
253264 // cancels the export job asynchronously
254265 exportVectorTilesJob.cancel().getOrElse {
255- showError (it.message.toString())
266+ showMessage (it.message.toString())
256267 }
257268 // cancel is completed, so set to true
258269 isJobFinished = true
@@ -272,36 +283,43 @@ class MainActivity : AppCompatActivity() {
272283 private fun showMapPreview (vectorTilesResult : ExportVectorTilesResult ) {
273284 val vectorTileCache = vectorTilesResult.vectorTileCache
274285 if (vectorTileCache == null ) {
275- showError (" Cannot find tile cache" )
286+ showMessage (" Cannot find tile cache" )
276287 return
277288 }
278289 // get the layer exported for the preview MapView
279290 val vectorTiledLayer = ArcGISVectorTiledLayer (
280291 vectorTileCache,
281292 vectorTilesResult.itemResourceCache
282293 )
294+
295+ // control UI visibility
296+ previewMapVisibility(true )
297+
283298 // set up the preview MapView
284- mapView .apply {
299+ previewMapView .apply {
285300 map = ArcGISMap (Basemap (vectorTiledLayer))
286301 mapView.getCurrentViewpoint(ViewpointType .CenterAndScale )?.let { setViewpoint(it) }
287302 }
288- // control UI visibility
289- previewMapVisibility(true )
290303 closePreviewButton.setOnClickListener {
291304 previewMapVisibility(false )
292305 }
293306
294307 }
295308
309+ /* *
310+ * Controls the visibility of the preview map and the export buttons.
311+ */
296312 private fun previewMapVisibility (isVisible : Boolean ) = if (isVisible) {
297313 exportVectorTilesButton.visibility = View .INVISIBLE
298314 closePreviewButton.visibility = View .VISIBLE
315+ previewMapView.visibility = View .VISIBLE
299316 } else {
300317 exportVectorTilesButton.visibility = View .VISIBLE
301318 closePreviewButton.visibility = View .INVISIBLE
319+ previewMapView.visibility = View .GONE
302320 }
303321
304- private fun showError (message : String ) {
322+ private fun showMessage (message : String ) {
305323 Log .e(TAG , message)
306324 Snackbar .make(mapView, message, Snackbar .LENGTH_SHORT ).show()
307325 }
0 commit comments