Skip to content

Commit

Permalink
Changes after PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
01smito01 committed Sep 27, 2024
1 parent c9bcaca commit 36ee8e2
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 253 deletions.
8 changes: 6 additions & 2 deletions create-and-save-map/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Create and save a map as a web map item to an ArcGIS portal.

![Image of create and save map](create-save-map.png)
![Image of create and save map](create-and-save-map.png)

## Use case

Expand All @@ -26,6 +26,10 @@ When you run the sample, you will be challenged for an ArcGIS Online login. Ente
* ArcGISMap
* Portal

## Additional information

This sample uses the GeoViewCompose Toolkit module to be able to implement a Composable MapView.

## Tags

ArcGIS Online, ArcGIS Pro, portal, publish, share, web map
ArcGIS Online, ArcGIS Pro, geoviewcompose, portal, publish, share, web map
Binary file added create-and-save-map/create-and-save-map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed create-and-save-map/create-save-map.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.arcgismaps.mapping.layers.Layer
import com.arcgismaps.portal.Portal
import com.arcgismaps.portal.PortalFolder
import com.arcgismaps.toolkit.authentication.AuthenticatorState
import com.esri.arcgismaps.sample.createandsavemap.R
import com.esri.arcgismaps.sample.sampleslib.components.MessageDialogViewModel

class MapViewModel(application: Application) : AndroidViewModel(application) {
Expand All @@ -47,17 +48,17 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {
// set up authenticator state to handle authentication challenges
val authenticatorState = AuthenticatorState().apply {
oAuthUserConfiguration = OAuthUserConfiguration(
portalUrl = "https://www.arcgis.com",
clientId = "InMihrA8yZXBALCv",
redirectUrl = "create-save-map://auth"
portalUrl = application.getString(R.string.portal_url),
clientId = application.getString(R.string.client_id),
redirectUrl = application.getString(R.string.redirect_url)
)
}

// require use of user credential to load portal
val portal = Portal("https://www.arcgis.com", Portal.Connection.Authenticated)
private val portal = Portal("https://www.arcgis.com", Portal.Connection.Authenticated)

// map only set non-null once user is authenticated
var arcGISMap by mutableStateOf<ArcGISMap?>(null)
// update displayed map once user is authenticated
var arcGISMap by mutableStateOf(ArcGISMap())

// folders on portal associated with the authenticated user
private val _portalFolders = MutableStateFlow<List<PortalFolder>>(listOf())
Expand All @@ -81,21 +82,23 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {

// properties hoisted from UI bottom sheet

var basemapStyle by mutableStateOf("Streets")
var selectedBasemapStyle by mutableStateOf("Streets")
private set

fun updateBasemapStyle(style: String) {
basemapStyle = style
selectedBasemapStyle = style

// style is non-null, as this function is called from dropdown populated from stylesMap
arcGISMap?.setBasemap(Basemap(stylesMap[style]!!))
// update map to display selected basemap style
arcGISMap.setBasemap(Basemap(stylesMap.getValue(selectedBasemapStyle)))
}

fun updateActiveLayers(layer: Layer) {
if (arcGISMap?.operationalLayers?.contains(layer) == true) {
arcGISMap!!.operationalLayers.remove(layer)
} else {
arcGISMap?.operationalLayers?.add(layer)
arcGISMap.operationalLayers.apply {
if (contains(layer)) {
remove(layer)
} else {
add(layer)
}
}
}

Expand Down Expand Up @@ -146,6 +149,12 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {
// load operational layers
worldElevation.load()
usCensus.load()
}.onFailure {
// login was cancelled or failed to authenticate
messageDialogVM.showMessageDialog(
application.getString(R.string.createAndSaveMap_failedToLoadPortal),
it.message.toString()
)
}
}
}
Expand All @@ -154,15 +163,15 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {
* Saves the map to a user's account.
*/
suspend fun save(): Result<Unit> {
return arcGISMap?.saveAs(
return arcGISMap.saveAs(
portal,
description = mapDescription,
folder = portalFolder,
tags = mapTags.split(",").map { str -> str.trim() },
forceSaveToSupportedVersion = false,
thumbnail = null,
title = mapName
) ?: Result.failure(NullPointerException("Can't save a null map."))
)
}


Expand Down
Loading

0 comments on commit 36ee8e2

Please sign in to comment.