Skip to content

Commit 9b16aa4

Browse files
committed
Update metadata
1 parent 0efcede commit 9b16aa4

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

download-vector-tiles-to-local-cache/README.metadata.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"formal_name": "DownloadVectorTilesToLocalCache",
55
"ignore": false,
66
"images": [
7-
"export-vector-tiles.png"
7+
"download-vector-tiles-to-local-cache.png"
88
],
99
"keywords": [
1010
"cache",
@@ -19,6 +19,9 @@
1919
"VectorTileCache"
2020
],
2121
"language": "kotlin",
22+
"redirect_from": [
23+
"/android/latest/sample-code/download-vector-tiles-to-local-cache.htm"
24+
],
2225
"relevant_apis": [
2326
"ArcGISVectorTiledLayer",
2427
"ExportVectorTilesJob",
@@ -28,7 +31,7 @@
2831
"VectorTileCache"
2932
],
3033
"snippets": [
31-
"src/main/java/com/esri/arcgisruntime/sample/exportvectortiles/MainActivity.kt"
34+
"/src/main/java/com/esri/com/arcgismaps/sample/downloadvectortilestolocalcache/MainActivity.kt"
3235
],
33-
"title": "Export vector tiles"
36+
"title": "Download vector tiles to local cache"
3437
}

download-vector-tiles-to-local-cache/src/main/java/com/esri/com/arcgismaps/sample/downloadvectortilestolocalcache/MainActivity.kt

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

download-vector-tiles-to-local-cache/src/main/res/layout/activity_main.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
app:layout_constraintRight_toRightOf="parent"
2323
app:layout_constraintTop_toTopOf="parent" />
2424

25+
<com.arcgismaps.mapping.view.MapView
26+
android:id="@+id/previewMapView"
27+
android:layout_width="0dp"
28+
android:layout_height="0dp"
29+
android:visibility="gone"
30+
app:layout_constraintBottom_toTopOf="@id/exportVectorTilesButton"
31+
app:layout_constraintLeft_toLeftOf="parent"
32+
app:layout_constraintRight_toRightOf="parent"
33+
app:layout_constraintTop_toTopOf="parent" />
34+
2535
<Button
2636
android:id="@+id/exportVectorTilesButton"
2737
android:layout_width="match_parent"

0 commit comments

Comments
 (0)