2016-12-08 40 views
0

我在android中使用arcgis庫100.0.0來顯示地圖內的地圖和信息。如何在ArcGIS中從ServiceFeatureTable中獲取所有字段

我正在使用以下代碼使用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); 
      } 
     }); 

回答

0

嘗試更換你的代碼

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

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

這對我的作品!

相關問題