Skip to content

ArcGISOAuthHybridInitialize

Usando ArcGISOAuthHybridInitialize, puede mostrar contenido de ArcGIS Online iniciando sesión con OAuth2.

Función ArcGISOAuthHybridInitialize

Intenta la autenticación con Application Credentials y automáticamente recurre al inicio de sesión del usuario si falla. Espera hasta que se complete la autenticación.

suspend fun ArcGISOAuthHybridInitialize(
authenticatorState: AuthenticatorState,
portalUrl: String,
redirectUrl: String,
clientId: String,
clientSecret: String? = null,
): Boolean

Parámetros

  • authenticatorState: AuthenticatorState que gestiona el estado de autenticación
  • portalUrl: URL del Portal de ArcGIS
  • redirectUrl: URI de redirección OAuth
  • clientId: ID de cliente OAuth
  • clientSecret: Secreto de cliente OAuth. Si se omite, se mostrará un diálogo de inicio de sesión.

Ejemplo de uso de ArcGISOAuthHybridInitialize

Mostrando contenido privado administrado en Portal especificando ClientID y ClientSecret.

@Composable
fun BasicMapExample(modifier: Modifier = Modifier) {
// Posición de la cámara del mapa
val mapViewState =
rememberArcGISMapViewState(
cameraPosition =
MapCameraPosition(
position = GeoPoint.fromLatLong(35.6812, 139.7671),
zoom = 12.0,
),
)
// Estado de autenticación y CoroutineScope (para procesamiento secuencial como await)
val authenticatorState = remember { AuthenticatorState() }
val scope = rememberCoroutineScope()
ArcGISMapView(
state = mapViewState,
modifier = modifier.fillMaxSize(),
sdkInitialize = { context ->
ArcGISOAuthHybridInitialize(
authenticatorState = authenticatorState,
portalUrl = "(ArcGIS Portal URL)",
redirectUrl = "(Redirect URL)",
clientId = (APP CLIENT ID),
clientSecret = "(APP CLIENT SECRET)",
)
},
onMapLoaded = {
scope.launch {
val holder = mapViewState.getMapViewHolder() ?: return@launch
// Ejecutar secuencialmente como await
val portal = Portal("https://mkgeeklab.maps.arcgis.com/", Portal.Connection.Authenticated)
portal.load().getOrThrow()
val item = PortalItem(portal, "e0ce06974e3d4c79b37e30d224c585d3")
item.load().getOrThrow()
when (item.type) {
is PortalItemType.WebScene -> {
ArcGISScene(item).also {
it.load().getOrThrow() // Esperar a que termine de cargar WebScene
holder.map.scene = it
}
}
is PortalItemType.WebMap -> error("SceneView solo admite WebScene")
else -> error("Unknown item type: ${item.type}")
}
// Ejemplo de capa adicional (opcional)
val trafficServerUrl = "https://traffic.arcgis.com/arcgis/rest/services/World/Traffic/MapServer"
ArcGISMapImageLayer(trafficServerUrl).also {
it.opacity = 0.6f
holder.map.scene!!.operationalLayers.add(0, it)
}
}
}
) {}
// IU de autenticación (para inicio de sesión de usuario). Se usa como respaldo para autenticación híbrida.
Authenticator(authenticatorState = authenticatorState, modifier = modifier)
}