查詢方法
- 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)
參數(shù)1:要查詢的圖層
參數(shù)1:屏幕坐標(biāo)
參數(shù)1:以screenPoint為中心的圓的密度無關(guān)像素(dp)中的半徑,用于識別GeoElements讥蔽。值0將僅識別screenPoint處物理像素處的GeoElements析恋。允許的最大值為100dp
參數(shù)1:如果包含彈出窗口,但識別結(jié)果中沒有地理元素锹引,則為true; false表示包含地理元素和彈出窗口
參數(shù)1:要返回的地理元素和/或彈出窗口的最大數(shù)量; 必須大于零矗钟,但-1可用于表示無限結(jié)果
代碼
mapView.onTouchListener = object : DefaultMapViewOnTouchListener(this, mapView)
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
//點(diǎn)擊的位置
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 {
//點(diǎn)擊的位置
val point =android.graphics.Point(e.x.toInt(), e.y.toInt())
val listListenableFuture = mapView.identifyLayersAsync (
point,
15.0,
false倘待,
-1
)
listListenableFuture.addDoneListener {
//IdentifyLayerResult:每個(gè)圖層的返回結(jié)果
List<IdentifyLayerResult> 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
跟上邊用法差不多凸舵,只不過查詢結(jié)果中獲取到的是graphic
val graphics = listListenableFuture.get().graphics
identifyGraphicsOverlaysAsync(Point screenPoint祖娘,double tolerance,boolean returnPopupsOnly啊奄,int maximumResults)
在此視圖中的所有圖形疊加層中渐苏,在給定屏幕點(diǎn)異步識別可見圖形。identifyGraphicsOverlaysAsync(Point screenPoint菇夸,double tolerance琼富,boolean returnPopupsOnly)
在給定的屏幕點(diǎn),異步識別此視圖中每個(gè)圖形疊加層中最頂部的可見圖形庄新。identifyGraphicsOverlayAsync( GraphicsOverlay graphicsOverlay公黑,Point screenPoint,double tolerance,boolean returnPopupsOnly凡蚜,int maximumResults)
在給定的屏幕點(diǎn)人断,異步識別給定圖形疊加層中的可見圖形。identifyGraphicsOverlayAsync( GraphicsOverlay graphicsOverlay朝蜘,Point screenPoint恶迈,double tolerance,boolean returnPopupsOnly)
在給定的屏幕點(diǎn)谱醇,異步識別給定圖形疊加層中最頂部的可見圖形暇仲。
queryFeaturesAsync
queryFeaturesAsync(QueryParameters query)
查詢參數(shù)
QueryParameters(com.esri.arcgisruntime.data.QueryParameters)是queryFeaturesAsync、selectFeaturesAsync的查詢參數(shù)
val query = QueryParameters()
setGeometry:進(jìn)行空間范圍查詢的Geometry對象
setMaxFeatures:最大返回值
setOutSpatialReference:查詢返回結(jié)果的空間參考
setReturnGeometry:是否在查詢結(jié)果中包含結(jié)合對象
setSpatialRelationship:進(jìn)行空間查詢的空間關(guān)系設(shè)置
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} 個(gè)元素", 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方法實(shí)際上是要素選擇副渴,但從實(shí)現(xiàn)結(jié)果上來說相當(dāng)于空間查詢奈附。同時(shí),查詢的結(jié)果會被高亮顯示煮剧。高亮顯示可以通過FeatureLayer設(shè)置顏色和寬度(厚度)
setSelectionColor:設(shè)置選中要素的顏色
setSelectionWidth:設(shè)置選中要素的邊緣寬度
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} 個(gè)元素", Toast.LENGTH_LONG)
.show()
for (element in featureResult) {
if(element is Feature){
Log.e("test", "${element.attributes.keys}")
}
}
}
}