ArcGISOAuthHybridInitialize
ArcGISOAuthHybridInitializeを使い、OAuth2でサイン・インすることで、ArcGIS Onlineのコンテンツを表示することができます。
Application Credentialで認証を試み、失敗した場合は自動的にユーザーログインにフォールバックします。 認証が完了するまで待機します。
suspend fun ArcGISOAuthHybridInitialize( authenticatorState: AuthenticatorState, portalUrl: String, redirectUrl: String, clientId: String, clientSecret: String? = null,): BooleanauthenticatorState: 認証状態を管理するAuthenticatorStateportalUrl: ArcGIS Portalの URLredirectUrl: OAuth Redirect URIclientId: OAuth Client IDclientSecret: OAuth Client Secret。省略した場合はログインダイアログが表示されます。
ArcGISOAuthHybridInitializeの使用例
Section titled “ArcGISOAuthHybridInitializeの使用例”ClientID, ClientSecretを指定して、Portalで管理するプライベートなコンテンツを表示しています。
@Composablefun BasicMapExample(modifier: Modifier = Modifier) { // 地図のカメラ位置 val mapViewState = rememberArcGISMapViewState( cameraPosition = MapCameraPosition( position = GeoPoint.fromLatLong(35.6812, 139.7671), zoom = 12.0, ), )
// 認証状態と CoroutineScope(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
// 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() // WebSceneの読み込み完了を待つ holder.map.scene = it } } is PortalItemType.WebMap -> error("SceneView は WebScene のみ対応") else -> error("Unknown item type: ${item.type}") }
// 追加レイヤ例(任意) 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) } } } ) {}
// 認証UI(ユーザーログイン用)。ハイブリッド認証のフォールバックで使用されます。 Authenticator(authenticatorState = authenticatorState, modifier = modifier)}