AnsweredAssumed Answered

How do access data attributes from sceneLayer in ArcGIS Runtime SDK for Android (Version 100.2.0)?

Question asked by lwh0734 on Jan 3, 2018

How to achieve the access layer attribute data and highlight, here is my code.


/**
* initialize
*
* @param promise
*/
@ReactMethod
public void initializeSDK(final Promise promise) {
    try {
        ArcGISScene scene = new ArcGISScene();
        scene.setBasemap(Basemap.createImagery());
        mSceneView.setScene(scene);
            
        mSceneView.setOnTouchListener(new DefaultSceneViewOnTouchListener(mSceneView) {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {

                float x = motionEvent.getX();
                float y = motionEvent.getY();

                double tolerance = 20.0;
                android.graphics.Point point = new android.graphics.Point(Math.round(x), Math.round(y));
                final ListenableFuture<List<IdentifyLayerResult>> featureResult = mSceneView.identifyLayersAsync(point, tolerance, true);
                featureResult.addDoneListener(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            List<IdentifyLayerResult> lstfeature = featureResult.get();
                            Log.i(REACT_CLASS, "feature length:" + lstfeature.size());

                            for (int i = 0; i < lstfeature.size(); i++) {
                                IdentifyLayerResult feature = lstfeature.get(i);
                                List<GeoElement> lstGeo = feature.getElements();

                                Log.i(REACT_CLASS, "layer:" + feature.getLayerContent().getName());
                                Log.i(REACT_CLASS, "Geo length:" + lstGeo.size());

                                for (int j = 0; j < lstGeo.size(); j++) {
                                    Map<String, Object> mapFeature = lstGeo.get(j).getAttributes();
                                }
                            }

                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        } catch (ExecutionException e) {
                            e.printStackTrace();
                        }
                    }
                });

                return super.onTouch(view, motionEvent);
            }
        });

        // 成功回调
        WritableMap params = Arguments.createMap();
        params.putString("status", "success");
        promise.resolve(params);
    } catch (Exception ex) {
        Log.e(REACT_CLASS, ex.toString());
        promise.reject(ex.getMessage());
    }
}

/***
* openProject
*
* @param mapParams
* @param successCallback
* @param errorCallback
*/
@ReactMethod
public void openProject(ReadableMap mapParams, final Callback successCallback, final Callback errorCallback) {
    try {

        // DOM
        ReadableArray arr_RMX_DOM = mapParams.getArray("RMX_DOM");
        for (int i = 0; i < arr_RMX_DOM.size(); i++) {
            ReadableMap map_DOM = arr_RMX_DOM.getMap(i);
            ArcGISTiledLayer layer_DOM = new ArcGISTiledLayer(map_DOM.getString("url"));
            layer_DOM.setName(map_DOM.getString("title"));
            mSceneView.getScene().getOperationalLayers().add(layer_DOM);
        }

        // Terrain
        ReadableArray arr_Terrain = mapParams.getArray("Terrain");
        for (int j = 0; j < arr_Terrain.size(); j++) {
            ReadableMap map_Terrain = arr_Terrain.getMap(j);
            ArcGISTiledElevationSource elevationSource_Terrain = new ArcGISTiledElevationSource(map_Terrain.getString("url"));
            mSceneView.getScene().getBaseSurface().getElevationSources().add(elevationSource_Terrain);
        }

        // Model
        ReadableArray arr_Model = mapParams.getArray("Model");
        for (int j = 0; j < arr_Model.size(); j++) {
            ReadableMap map_Model = arr_Model.getMap(j);
            ArcGISSceneLayer sceneLayer = new ArcGISSceneLayer(map_Model.getString("url"));
            sceneLayer.setName(map_Model.getString("title"));
            mSceneView.getScene().getOperationalLayers().add(sceneLayer);
        }

        // initialize camera
        Camera camera = new Camera(29.011088139925707, 103.88570908840268, 457.09098537638783, 325.8343841906436, 59.5289549838569, 0.0);
        mSceneView.setViewpointCamera(camera);

        // success
        successCallback.invoke("success");
    } catch (Exception ex) {
        Log.e(REACT_CLASS, ex.toString());
        // error
        errorCallback.invoke(ex.toString());
    }
}

Outcomes