Skip to content

Commit c20f754

Browse files
committed
PR feedback
1 parent 1e0350e commit c20f754

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

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

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class MainActivity : AppCompatActivity() {
5555

5656
private val downloadArea: Graphic = Graphic()
5757
private var dialog: AlertDialog? = null
58-
private var isJobFinished: Boolean = true
58+
private var hasCurrentJobCompleted: Boolean = true
5959

6060
// set up data binding for the activity
6161
private val activityMainBinding: ActivityMainBinding by lazy {
@@ -100,19 +100,23 @@ class MainActivity : AppCompatActivity() {
100100
// set the map to BasemapType navigation night
101101
map = ArcGISMap(BasemapStyle.ArcGISStreetsNight)
102102
// disable rotation
103-
rotation = 0F
103+
interactionOptions.isRotateEnabled = false
104104
// set the viewpoint of the sample to ESRI Redlands, CA campus
105105
setViewpoint(Viewpoint(34.056295, -117.195800, 100000.0))
106106
// add the graphics overlay to the MapView
107107
graphicsOverlays.add(graphicsOverlay)
108108
}
109109

110-
lifecycleScope.apply {
111-
launch {
110+
lifecycleScope.launch {
111+
mapView.map?.load()?.onSuccess {
112+
// enable the export tiles button
113+
exportVectorTilesButton.isEnabled = true
112114
// update the red square whenever the viewpoint changes
113115
mapView.viewpointChanged.collect {
114116
updateDownloadAreaGeometry()
115117
}
118+
}?.onFailure {
119+
showMessage("Error loading map")
116120
}
117121
}
118122
}
@@ -138,6 +142,7 @@ class MainActivity : AppCompatActivity() {
138142
return@launch
139143
}
140144
// set the parameters of the export vector tiles task
145+
// using the geometry of the area to export and it's max scale
141146
val exportVectorTilesParametersResult = exportVectorTilesTask
142147
.createDefaultExportVectorTilesParameters(
143148
geometry,
@@ -149,7 +154,7 @@ class MainActivity : AppCompatActivity() {
149154
showMessage(it.message.toString())
150155
} as ExportVectorTilesParameters
151156

152-
if (isJobFinished) {
157+
if (hasCurrentJobCompleted) {
153158
// create a job to export vector tiles
154159
initiateExportTilesJob(
155160
exportVectorTilesParameters,
@@ -191,10 +196,10 @@ class MainActivity : AppCompatActivity() {
191196
// display the progress dialog
192197
dialog?.show()
193198
// since job is now started, set to false
194-
isJobFinished = false
199+
hasCurrentJobCompleted = false
195200

196201
// set the value of the job's progress
197-
lifecycleScope.apply {
202+
with(lifecycleScope) {
198203
// collect the progress of the job
199204
launch {
200205
exportVectorTilesJob.progress.collect {
@@ -210,7 +215,7 @@ class MainActivity : AppCompatActivity() {
210215
// display the map preview using the result from the completed job
211216
showMapPreview(it)
212217
// set job is completed
213-
isJobFinished = true
218+
hasCurrentJobCompleted = true
214219
// display the path of the saved vector tiles
215220
showMessage(it.vectorTileCache?.path.toString())
216221
// dismiss loading dialog
@@ -225,29 +230,25 @@ class MainActivity : AppCompatActivity() {
225230
}
226231

227232
/**
228-
* Updates the [downloadArea]'s geometry on ViewPoint change
233+
* Updates the [downloadArea]'s geometry when called with viewpoint change
229234
* or when export tiles button is clicked.
230235
*/
231-
private suspend fun updateDownloadAreaGeometry() {
232-
mapView.map?.load()?.onSuccess {
233-
// upper left corner of the downloaded tile cache area
234-
val minScreenPoint = ScreenCoordinate(150.0, 175.0)
235-
// lower right corner of the downloaded tile cache area
236-
val maxScreenPoint = ScreenCoordinate(
237-
mapView.width - 150.0,
238-
mapView.height - 250.0
239-
)
240-
// convert screen points to map points
241-
val minPoint = mapView.screenToLocation(minScreenPoint)
242-
val maxPoint = mapView.screenToLocation(maxScreenPoint)
243-
if (minPoint != null && maxPoint != null) {
244-
// use the points to define and return an envelope
245-
downloadArea.geometry = Envelope(minPoint, maxPoint)
246-
} else {
247-
showMessage("Error getting screen coordinate")
248-
}
249-
}?.onFailure {
250-
showMessage(it.message.toString())
236+
private fun updateDownloadAreaGeometry() {
237+
// upper left corner of the downloaded tile cache area
238+
val minScreenPoint = ScreenCoordinate(150.0, 175.0)
239+
// lower right corner of the downloaded tile cache area
240+
val maxScreenPoint = ScreenCoordinate(
241+
mapView.width - 150.0,
242+
mapView.height - 250.0
243+
)
244+
// convert screen points to map points
245+
val minPoint = mapView.screenToLocation(minScreenPoint)
246+
val maxPoint = mapView.screenToLocation(maxScreenPoint)
247+
if (minPoint != null && maxPoint != null) {
248+
// use the points to define and return an envelope
249+
downloadArea.geometry = Envelope(minPoint, maxPoint)
250+
} else {
251+
showMessage("Error getting screen coordinate")
251252
}
252253
}
253254

@@ -265,7 +266,7 @@ class MainActivity : AppCompatActivity() {
265266
showMessage(it.message.toString())
266267
}
267268
// cancel is completed, so set to true
268-
isJobFinished = true
269+
hasCurrentJobCompleted = true
269270
}
270271
}
271272
setCancelable(false)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
android:onClick="exportButtonClick"
4040
android:padding="16dp"
4141
android:text="@string/export_vector_tiles"
42+
android:enabled="false"
4243
android:textAllCaps="false"
4344
app:layout_constraintBottom_toBottomOf="parent"
4445
app:layout_constraintEnd_toEndOf="parent"

0 commit comments

Comments
 (0)