ArcGIS Runtime SDK for Android(100.3)访问ArcGIS Online或Portal中的Item

概述:ArcGIS Rumtime SDK for Android可以加载离线的slpk作为Scence中的Layer,也可以加载Portal(包括ArcGIS Online)中发布的Scene和SceneLayer。本篇博客简要介绍了Android SDK访问Portal或ArcGIS Online中的Item作为ScenceLayer或者Scene。

ArcGIS Runtime 提供了两种认证模式:App login 和 Named user login。本篇博客使用Named user login 认证模式。

使用Named user login认证模式需要使用可登陆Portal(或者ArcGIS Online)的用户名和与其对应的密码。登陆后,操作者可访问该用户的私有内容或者该用户所在组织的分享给该用户的内容,可创建、更新和删除用户内容,可访问高级内容(如:geocoding、routing),可分享内容给所在组织的其他用户。因此,使用这种认证模式需要考虑相应的风险。好了,废物不多说,下面直接上干货。

首先呢,需要先配置AuthenticationManager,主要是为了显示在App中显示出登录界面,这个界面不需要咱们自己写,配置好后,会自动弹出。代码如下:

AuthenticationChallengeHandler authenticationChallengeHandler =
                new DefaultAuthenticationChallengeHandler(this);
AuthenticationManager.setAuthenticationChallengeHandler(authenticationChallengeHandler);

其次,需要设置Portal,并设置监听函数。代码如下:

Portal portal = new Portal("https://www.arcgis.com", true);
portal.addDoneLoadingListener(() -> {
    if (portal.getLoadStatus() == LoadStatus.LOADED) {
        // do something when you login successfully
    } else if (portal.getLoadStatus() == LoadStatus.FAILED_TO_LOAD) {
        // // do something when you login failed
    }
});

portal.loadAsync();

最后,使用Portal中的Item对应的Id创建ScencLayer或者Scene。相应代码如下:

PortalItem portalItem = new PortalItem(portal, "465077bf1afa4d048f2875eba679c4e6");
ArcGISSceneLayer arcGISSceneLayer = new ArcGISSceneLayer(portalItem);
PortalItem portalItem = new PortalItem(portal, "465077bf1afa4d048f2875eba679c4e6");
ArcGISScene arcGISScene = new ArcGISScene(portalItem);

其中,"465077bf1afa4d048f2875eba679c4e6"为Item的Id。在Portal(或者ArcGIS Online)中访问Item时,其对应的URL最后(如:**id=04ca8335c37a4ced90cd829c49b0a900)有该内容对应的ID。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值