如何从arcgis中的ServiceFeatureTable获取所有字段

时间:2016-12-08 13:54:32

标签: arcgis

我在android中使用arcgis库100.0.0在地图中显示地图和信息。

我使用以下代码使用arcGis提供的URL填充ServiceFeaturetable。我能够将要素图层成功加载到mapview中。我编写的代码可以监听地图上符号的点击,这样我就可以获得有关地图上特定功能的一些信息。我能够获得OnClick的特定功能。

在调查特定功能的GetAttributes()结果后,我意识到它没有所有字段。在互联网上进行调查后,我发现FeatureTable.QueryFeaturesAsync可用于获取该功能的所有字段。即使我已经编写了代码来获取所有字段,我也不知道如何将此结果与要素图层链接,因此该要素具有我需要的所有字段。这是代码

final ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable("some URL");



        ListenableFuture<FeatureQueryResult>  queryresult =  serviceFeatureTable.queryFeaturesAsync(null, ServiceFeatureTable.QueryFeatureFields.LOAD_ALL);


        // create the feature layer using the service feature table
        final FeatureLayer featureLayer = new FeatureLayer(serviceFeatureTable);

        featureLayer.setSelectionColor(Color.YELLOW);
        featureLayer.setSelectionWidth(10);

        // add the layer to the map
        mapView.getMap().getOperationalLayers().add(featureLayer);

        // set an on touch listener to listen for click events
        mapView.setOnTouchListener(new DefaultMapViewOnTouchListener(getContext(), mapView) {
            @Override
            public boolean onSingleTapConfirmed(MotionEvent e) {
                // get the point that was clicked and convert it to a point in map coordinates
                Point clickPoint = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY())));
                int tolerance = 10;
                double mapTolerance = tolerance * mMapView.getUnitsPerDensityIndependentPixel();
                // create objects required to do a selection with a query

                Envelope envelope = new Envelope(clickPoint.getX() - mapTolerance, clickPoint.getY() - mapTolerance, clickPoint.getX() + mapTolerance, clickPoint.getY() + mapTolerance, mapView.getMap().getSpatialReference());
                QueryParameters query = new QueryParameters();

                query.setGeometry(envelope);


                // call select features
                final ListenableFuture<FeatureQueryResult> future = featureLayer.selectFeaturesAsync(query, FeatureLayer.SelectionMode.NEW);

                // add done loading listener to fire when the selection returns
                future.addDoneListener(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            //call get on the future to get the result
                            FeatureQueryResult result = future.get();
                            // create an Iterator
                            Iterator<Feature> iterator = result.iterator();
                            Feature feature;
                            // cycle through selections
                            int counter = 0;
                            while (iterator.hasNext()){
                                feature = iterator.next();
                                counter++;
                                String name = feature.getAttributes().get(Constants.FIELD_NAME).toString();
                                Log.d(getResources().getString(R.string.app_name), "Selection #: " + counter + " Table name: " + feature.getFeatureTable().getTableName());
                            }
                            //Toast.makeText(getApplicationContext(), counter + " features selected", Toast.LENGTH_SHORT).show();
                        } catch (Exception e) {
                            Log.e(getResources().getString(R.string.app_name), "Select feature failed: " + e.getMessage());
                        }
                    }
                });
                return super.onSingleTapConfirmed(e);
            }
        });

1 个答案:

答案 0 :(得分:1)

尝试替换您的代码

final ListenableFuture<FeatureQueryResult> future = featureLayer.selectFeaturesAsync(query, FeatureLayer.SelectionMode.NEW);

final ListenableFuture<FeatureQueryResult> future = serviceFeatureTable.queryFeaturesAsync(query, ServiceFeatureTable.QueryFeatureFields.LOAD_ALL);

对我有用!