Arcgis runtime for Android 100.5 (九) 空间查询

(八) 业务图层管理

查询方法

  • MapView 的 identifyLayerAsync方法:查询指定图层
  • MapView 的 identifyLayersAsync方法:查询所有图层
  • MapView 的 identifyGraphicsOverlayAsync方法:查询指定图层Graphic
  • MapView 的 identifyGraphicsOverlaysAsync方法:查询所有图层Graphic
  • FeatureTable 的 queryFeaturesAsync 方法
  • FeatureLayer 的 selectFeaturesAsync方法

异步查询指定图层中的GeoElements

identifyLayerAsync (Layer layer,Point screenPoint,double tolerance,boolean returnPopupsOnly,int maximumResults)
参数1:要查询的图层
参数1:屏幕坐标
参数1:以screenPoint为中心的圆的密度无关像素(dp)中的半径,用于识别GeoElements。值0将仅识别screenPoint处物理像素处的GeoElements。允许的最大值为100dp
参数1:如果包含弹出窗口,但识别结果中没有地理元素,则为true; false表示包含地理元素和弹出窗口
参数1:要返回的地理元素和/或弹出窗口的最大数量; 必须大于零,但-1可用于表示无限结果
代码

mapView.onTouchListener = object : DefaultMapViewOnTouchListener(this, mapView)   
   override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
         //点击的位置
         val point =android.graphics.Point(e.x.toInt(), e.y.toInt())
         val listListenableFuture = mapView.identifyLayerAsync(
                operationalLayers[0],
                point,
                15.0,
                false,
                -1
            )
         listListenableFuture.addDoneListener {
            //查询到的  elements 
            val elements = listListenableFuture.get().elements
             for (element in elements) {
                    //打印出element 的所有属性
                    Log.e("test", element.attributes.keys.toString())
                    //打印出element 的所有值
                    Log.e("test", element.attributes.values.toString())
             }
        }
   return super.onSingleTapConfirmed(e)
   }
}

异步查询指定图层中最顶层的可见GeoElement

identifyLayerAsync (Layer layer,Point screenPoint,double tolerance,boolean returnPopupsOnly)

异步查询地图中所有显示图层上的GeoElements

identifyLayersAsync (Point screenPoint,double tolerance,boolean returnPopupsOnly,int maximumResults)

mapView.onTouchListener = object : DefaultMapViewOnTouchListener(this, mapView)   
   override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
         //点击的位置
         val point =android.graphics.Point(e.x.toInt(), e.y.toInt())
         val listListenableFuture = mapView.identifyLayersAsync (
                point,
                15.0,
                false,
                -1
            )
         listListenableFuture.addDoneListener {
            //IdentifyLayerResult:每个图层的返回结果
            List identifyLayerResults = listListenableFuture.get();
            for(identifyLayerResult in identifyLayerResults ){
            val elements = identifyLayerResults[i].elements
                 for (element in elements) {
                    //打印出element 的所有属性
                    Log.e("test", element.attributes.keys.toString())
                    //打印出element 的所有值
                    Log.e("test", element.attributes.values.toString())
                 }
            }
        }
   return super.onSingleTapConfirmed(e)
   }
}

异步查询地图中所有显示图层上最顶部的可见GeoElement

identifyLayersAsync (Point screenPoint,double tolerance,boolean returnPopupsOnly)

查询Graphic

跟上边用法差不多,只不过查询结果中获取到的是graphic

val graphics = listListenableFuture.get().graphics
  1. identifyGraphicsOverlaysAsync(Point screenPoint,double tolerance,boolean returnPopupsOnly,int maximumResults)
    在此视图中的所有图形叠加层中,在给定屏幕点异步识别可见图形。

  2. identifyGraphicsOverlaysAsync(Point screenPoint,double tolerance,boolean returnPopupsOnly)
    在给定的屏幕点,异步识别此视图中每个图形叠加层中最顶部的可见图形。

  3. identifyGraphicsOverlayAsync( GraphicsOverlay graphicsOverlay,Point screenPoint,double tolerance,boolean returnPopupsOnly,int maximumResults)
    在给定的屏幕点,异步识别给定图形叠加层中的可见图形。

  4. identifyGraphicsOverlayAsync( GraphicsOverlay graphicsOverlay,Point screenPoint,double tolerance,boolean returnPopupsOnly)
    在给定的屏幕点,异步识别给定图形叠加层中最顶部的可见图形。

queryFeaturesAsync

queryFeaturesAsync(QueryParameters query)

查询参数
QueryParameters(com.esri.arcgisruntime.data.QueryParameters)是queryFeaturesAsync、selectFeaturesAsync的查询参数

val query = QueryParameters()
setGeometry:进行空间范围查询的Geometry对象
setMaxFeatures:最大返回值
setOutSpatialReference:查询返回结果的空间参考
setReturnGeometry:是否在查询结果中包含结合对象
setSpatialRelationship:进行空间查询的空间关系设置
setWhereClause:查询语句

private fun queryByEnvelope(envelope: Envelope) {
    val queryParameters = QueryParameters()
    queryParameters.geometry = envelope
    //要查询的图层
    val dataFeatureLayer: FeatureLayer = mapView.map.operationalLayers[0] as FeatureLayer
    //获取属性表
    val mTable = dataFeatureLayer.featureTable
    val featureQueryResult = mTable.queryFeaturesAsync(queryParameters)
    featureQueryResult.addDoneListener {
          val featureResult = featureQueryResult.get()
          Toast.makeText(this, "查询到${featureResult.toList().size} 个元素", Toast.LENGTH_LONG)
               .show()
          for (element in featureResult) {
              if(element  is Feature){
                   Log.e("test", "${element.attributes.keys}")
              }
          }
    }
}

selectFeaturesAsync

selectFeaturesAsync(QueryParameters query, FeatureLayer.SelectionMode selectionMode)

FeatureLayer的selectFeaturesAsync方法实际上是要素选择,但从实现结果上来说相当于空间查询。同时,查询的结果会被高亮显示。高亮显示可以通过FeatureLayer设置颜色和宽度(厚度)

setSelectionColor:设置选中要素的颜色
setSelectionWidth:设置选中要素的边缘宽度

private fun queryByEnvelope(envelope: Envelope) {
    val queryParameters = QueryParameters()
    queryParameters.geometry = envelope
    val dataFeatureLayer: FeatureLayer = mapView.map.operationalLayers as FeatureLayer
    val featureQueryResult =
                dataFeatureLayer.selectFeaturesAsync(
                queryParameters,
                FeatureLayer.SelectionMode.NEW
                )
    featureQueryResult.addDoneListener {
          val result = featureQueryResult.get()
          Toast.makeText(this, "查询到${result.toList().size} 个元素", Toast.LENGTH_LONG)
               .show()
          for (element in featureResult) {
              if(element  is Feature){
                   Log.e("test", "${element.attributes.keys}")
              }
         }
    }
}

(十) Callout

你可能感兴趣的:(Arcgis runtime for Android 100.5 (九) 空间查询)