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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LENOVOJXN/article/details/88548090

概述: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。

猜你喜欢

转载自blog.csdn.net/LENOVOJXN/article/details/88548090