0

下面是我用于在 ServiceFeatureTable 上设置用户凭据的代码。

ServiceFeatureTable featureTablePolygons = new ServiceFeatureTable(polygonUrl);
featureTablePolygons.setCredential(UserCredential.createFromToken(gisToken, referer));


    //query feature from the table
    final ListenableFuture<FeatureQueryResult> queryResultPolygons = featureTablePolygons.queryFeaturesAsync(query);
    queryResultPolygons.addDoneListener(() -> {
        try {
            FeatureCollection featureCollection = new FeatureCollection();
            FeatureQueryResult result = queryResultPolygons.get();
            FeatureCollectionTable featureCollectionTable = new FeatureCollectionTable(result);
            featureCollectionTable.setRenderer(new SimpleRenderer(new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, getResources().getColor(R.color.translucent_red), new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.RED, 1))));
            featureCollection.getTables().add(featureCollectionTable);
            FeatureCollectionLayer featureCollectionLayer = new FeatureCollectionLayer(featureCollection);
       mMapView.getMap().getOperationalLayers().add(featureCollectionLayer);

            if (result.iterator().hasNext()) {
                Feature feature = result.iterator().next();
                Envelope envelope = feature.getGeometry().getExtent();
                mMapView.setViewpointGeometryAsync(envelope);
            } else {
            }
        } catch (InterruptedException | ExecutionException e) {
            Log.e(TAG, "Error in FeatureQueryResult: " + e.getMessage());
        }
    });

但这不起作用。如果我使用的是 AuthenticationManager,那么它工作正常,但我不想在我的代码中使用用户名和密码。

4

1 回答 1

0

如果您手动获取令牌,您可以使用createFromToken()创建一个 UserCredential 对象,并使用setCredential()在 ServiceFeatureTable 上设置它。

但是,许多获取令牌的工作流由运行时处理(例如,用户名 + 密码,或通过门户的 OAuth)。查看AuthenticationManager 文档以开始使用。

最后,我认为您会在ArcGIS Runtime SDK for Android 论坛上更加关注您的问题。

于 2018-09-16T00:53:10.233 回答